mirror of
https://github.com/diocloid/LinkTitles.git
synced 2025-07-13 09:49:31 +02:00
Add $wgLinkTitlesSameNamespace option.
This commit is contained in:
@ -30,7 +30,8 @@
|
|||||||
"LinkTitlesWordEndOnly": true,
|
"LinkTitlesWordEndOnly": true,
|
||||||
"LinkTitlesSpecialPageReloadAfter": 1,
|
"LinkTitlesSpecialPageReloadAfter": 1,
|
||||||
"LinkTitlesSourceNamespaces": [],
|
"LinkTitlesSourceNamespaces": [],
|
||||||
"LinkTitlesTargetNamespaces": []
|
"LinkTitlesTargetNamespaces": [],
|
||||||
|
"LinkTitlesSameNamespace": true
|
||||||
},
|
},
|
||||||
"AutoloadClasses": {
|
"AutoloadClasses": {
|
||||||
"LinkTitles\\Extension": "includes/Extension.php",
|
"LinkTitles\\Extension": "includes/Extension.php",
|
||||||
|
@ -163,6 +163,12 @@ class Config {
|
|||||||
*/
|
*/
|
||||||
public $specialPageReloadAfter;
|
public $specialPageReloadAfter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to link to pages in the same namespace (default is true).
|
||||||
|
* @var bool $sameNamespace;
|
||||||
|
*/
|
||||||
|
public $sameNamespace;
|
||||||
|
|
||||||
public $enableConsoleOutput;
|
public $enableConsoleOutput;
|
||||||
public $enableDebugConsoleOutput;
|
public $enableDebugConsoleOutput;
|
||||||
|
|
||||||
@ -180,6 +186,7 @@ class Config {
|
|||||||
global $wgLinkTitlesBlackList;
|
global $wgLinkTitlesBlackList;
|
||||||
global $wgLinkTitlesSourceNamespaces;
|
global $wgLinkTitlesSourceNamespaces;
|
||||||
global $wgLinkTitlesTargetNamespaces;
|
global $wgLinkTitlesTargetNamespaces;
|
||||||
|
global $wgLinkTitlesSameNamespace;
|
||||||
global $wgLinkTitlesFirstOnly;
|
global $wgLinkTitlesFirstOnly;
|
||||||
global $wgLinkTitlesSmartMode;
|
global $wgLinkTitlesSmartMode;
|
||||||
global $wgCapitalLinks;
|
global $wgCapitalLinks;
|
||||||
@ -197,6 +204,7 @@ class Config {
|
|||||||
$this->blackList = $wgLinkTitlesBlackList;
|
$this->blackList = $wgLinkTitlesBlackList;
|
||||||
$this->sourceNamespaces = $wgLinkTitlesSourceNamespaces ? $wgLinkTitlesSourceNamespaces : [ NS_MAIN ];
|
$this->sourceNamespaces = $wgLinkTitlesSourceNamespaces ? $wgLinkTitlesSourceNamespaces : [ NS_MAIN ];
|
||||||
$this->targetNamespaces = $wgLinkTitlesTargetNamespaces;
|
$this->targetNamespaces = $wgLinkTitlesTargetNamespaces;
|
||||||
|
$this->sameNamespace = $wgLinkTitlesSameNamespace;
|
||||||
$this->firstOnly = $wgLinkTitlesFirstOnly;
|
$this->firstOnly = $wgLinkTitlesFirstOnly;
|
||||||
$this->smartMode = $wgLinkTitlesSmartMode;
|
$this->smartMode = $wgLinkTitlesSmartMode;
|
||||||
$this->capitalLinks = $wgCapitalLinks; // MediaWiki global variable
|
$this->capitalLinks = $wgCapitalLinks; // MediaWiki global variable
|
||||||
@ -210,5 +218,4 @@ class Config {
|
|||||||
$this->enableConsoleOutput = false;
|
$this->enableConsoleOutput = false;
|
||||||
$this->enableDebugConsoleOutput = false;
|
$this->enableDebugConsoleOutput = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,6 @@ class Targets {
|
|||||||
* Fetches the page titles from the database.
|
* Fetches the page titles from the database.
|
||||||
*/
|
*/
|
||||||
private function fetch() {
|
private function fetch() {
|
||||||
|
|
||||||
( $this->config->preferShortTitles ) ? $sortOrder = 'ASC' : $sortOrder = 'DESC';
|
( $this->config->preferShortTitles ) ? $sortOrder = 'ASC' : $sortOrder = 'DESC';
|
||||||
|
|
||||||
// Build a blacklist of pages that are not supposed to be link
|
// Build a blacklist of pages that are not supposed to be link
|
||||||
@ -101,9 +100,19 @@ class Targets {
|
|||||||
$blackList = null;
|
$blackList = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( $this->config->sameNamespace ) {
|
||||||
// Build our weight list. Make sure current namespace is first element
|
// Build our weight list. Make sure current namespace is first element
|
||||||
$namespaces = array_diff( $this->config->targetNamespaces, [ $this->sourceNamespace ] );
|
$namespaces = array_diff( $this->config->targetNamespaces, [ $this->sourceNamespace ] );
|
||||||
array_unshift( $namespaces, $this->sourceNamespace );
|
array_unshift( $namespaces, $this->sourceNamespace );
|
||||||
|
} else {
|
||||||
|
$namespaces = $this->config->targetNamespaces;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !$namespaces) {
|
||||||
|
// If there are absolutely no target namespaces (not even the one of the
|
||||||
|
// source page), we can just return.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// No need for sanitiy check. we are sure that we have at least one element in the array
|
// No need for sanitiy check. we are sure that we have at least one element in the array
|
||||||
$weightSelect = "CASE page_namespace ";
|
$weightSelect = "CASE page_namespace ";
|
||||||
|
Reference in New Issue
Block a user