mirror of
				https://github.com/diocloid/LinkTitles.git
				synced 2025-10-22 05:42:32 +02:00 
			
		
		
		
	Change nameSpace to all lowercase everywhere.
Makes it consistent with MW's spelling of the term.
This commit is contained in:
		@@ -70,9 +70,9 @@ class Config {
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Array of those name spaces (integer constants) whose pages may be linked.
 | 
			
		||||
	 * @var Array $nameSpaces
 | 
			
		||||
	 * @var Array $namespaces
 | 
			
		||||
	 */
 | 
			
		||||
	public $nameSpaces;
 | 
			
		||||
	public $namespaces;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Indicates whether to add a link to the first occurrence of a page title
 | 
			
		||||
@@ -186,7 +186,7 @@ class Config {
 | 
			
		||||
		$this->preferShortTitles = $wgLinkTitlesPreferShortTitles;
 | 
			
		||||
		$this->minimumTitleLength = $wgLinkTitlesMinimumTitleLength;
 | 
			
		||||
		$this->blackList = $wgLinkTitlesBlackList;
 | 
			
		||||
		$this->nameSpaces = $wgLinkTitlesNamespaces;
 | 
			
		||||
		$this->namespaces = $wgLinkTitlesNamespaces;
 | 
			
		||||
		$this->firstOnly = $wgLinkTitlesFirstOnly;
 | 
			
		||||
		$this->smartMode = $wgLinkTitlesSmartMode;
 | 
			
		||||
		$this->capitalLinks = $wgCapitalLinks; // MediaWiki global variable
 | 
			
		||||
 
 | 
			
		||||
@@ -39,7 +39,7 @@ class Extension {
 | 
			
		||||
 | 
			
		||||
		// Only process if page is in one of our namespaces we want to link
 | 
			
		||||
		// Fixes ugly autolinking of sidebar pages
 | 
			
		||||
		if ( in_array( $title->getNamespace(), $config->nameSpaces )) {
 | 
			
		||||
		if ( in_array( $title->getNamespace(), $config->namespaces )) {
 | 
			
		||||
			$text = $content->getContentHandler()->serializeContent( $content );
 | 
			
		||||
			if ( !\MagicWord::get( 'MAG_LINKTITLES_NOAUTOLINKS' )->match( $text ) ) {
 | 
			
		||||
				$linker = new Linker( $config );
 | 
			
		||||
@@ -65,7 +65,7 @@ class Extension {
 | 
			
		||||
		// If the page contains the magic word '__NOAUTOLINKS__', do not parse it.
 | 
			
		||||
		// Only process if page is in one of our namespaces we want to link
 | 
			
		||||
		if ( !\MagicWord::get( 'MAG_LINKTITLES_NOAUTOLINKS' )->match( $text ) &&
 | 
			
		||||
				in_array( $title->getNamespace(), $config->nameSpaces ) ) {
 | 
			
		||||
				in_array( $title->getNamespace(), $config->namespaces ) ) {
 | 
			
		||||
			$linker = new Linker( $config );
 | 
			
		||||
			$text = $linker->linkContent( $title, $text );
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
@@ -97,7 +97,7 @@ class Special extends \SpecialPage {
 | 
			
		||||
	 */
 | 
			
		||||
	private function process( \WebRequest &$request, \OutputPage &$output) {
 | 
			
		||||
		// get our Namespaces
 | 
			
		||||
		$namespacesClause = str_replace( '_', ' ','(' . implode( ', ',$this->config->nameSpaces ) . ')' );
 | 
			
		||||
		$namespacesClause = str_replace( '_', ' ','(' . implode( ', ',$this->config->namespaces ) . ')' );
 | 
			
		||||
 | 
			
		||||
		// Start the stopwatch
 | 
			
		||||
		$startTime = microtime( true );
 | 
			
		||||
 
 | 
			
		||||
@@ -69,12 +69,12 @@ class Target {
 | 
			
		||||
	 *
 | 
			
		||||
	 * The parameters may be taken from database rows, for example.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param Int $nameSpace Name space of the target page
 | 
			
		||||
	 * @param Int $namespace Name space of the target page
 | 
			
		||||
	 * @param String &$title Title of the target page
 | 
			
		||||
	 */
 | 
			
		||||
	public function __construct( $nameSpace, $title, Config &$config ) {
 | 
			
		||||
		// print "\n>>>nameSpace=$nameSpace;title=$title<<<\n";
 | 
			
		||||
		$this->title = \Title::makeTitleSafe( $nameSpace, $title );
 | 
			
		||||
	public function __construct( $namespace, $title, Config &$config ) {
 | 
			
		||||
		// print "\n>>>namespace=$namespace;title=$title<<<\n";
 | 
			
		||||
		$this->title = \Title::makeTitleSafe( $namespace, $title );
 | 
			
		||||
		$this->titleValue = $this->title->getTitleValue();
 | 
			
		||||
		$this->config = $config;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -34,14 +34,14 @@ class Targets {
 | 
			
		||||
	 * potential target page titles.
 | 
			
		||||
	 *
 | 
			
		||||
	 * The subset of pages that may serve as target pages depends on the
 | 
			
		||||
	 * name space of the source page. Therefore, if the $nameSpace differs from
 | 
			
		||||
	 * name space of the source page. Therefore, if the $namespace differs from
 | 
			
		||||
	 * the cached name space, the database is queried again.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param  String $nameSpace The namespace of the current page.
 | 
			
		||||
	 * @param  String $namespace The namespace of the current page.
 | 
			
		||||
	 * @param  Config $config    LinkTitles configuration.
 | 
			
		||||
	 */
 | 
			
		||||
	public static function default( \Title $title, Config $config ) {
 | 
			
		||||
		if ( ( self::$instance === null ) || ( self::$instance->nameSpace != $title->getNamespace() ) ) {
 | 
			
		||||
		if ( ( self::$instance === null ) || ( self::$instance->namespace != $title->getNamespace() ) ) {
 | 
			
		||||
			self::$instance = new Targets( $title, $config );
 | 
			
		||||
		}
 | 
			
		||||
		return self::$instance;
 | 
			
		||||
@@ -67,9 +67,9 @@ class Targets {
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Holds the name space (integer) for which the list of target pages was built.
 | 
			
		||||
	 * @var Int $nameSpace
 | 
			
		||||
	 * @var Int $namespace
 | 
			
		||||
	 */
 | 
			
		||||
	public $nameSpace;
 | 
			
		||||
	public $namespace;
 | 
			
		||||
 | 
			
		||||
	private $config;
 | 
			
		||||
 | 
			
		||||
@@ -79,7 +79,7 @@ class Targets {
 | 
			
		||||
	 */
 | 
			
		||||
	private function __construct( \Title $title, Config $config) {
 | 
			
		||||
		$this->config = $config;
 | 
			
		||||
		$this->nameSpace = $title->getNameSpace();
 | 
			
		||||
		$this->namespace = $title->getNamespace();
 | 
			
		||||
		$this->fetch();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -101,18 +101,18 @@ class Targets {
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// Build our weight list. Make sure current namespace is first element
 | 
			
		||||
		$nameSpaces = array_diff( $this->config->nameSpaces, [ $this->nameSpace ] );
 | 
			
		||||
		array_unshift( $nameSpaces,  $this->nameSpace );
 | 
			
		||||
		$namespaces = array_diff( $this->config->namespaces, [ $this->namespace ] );
 | 
			
		||||
		array_unshift( $namespaces,  $this->namespace );
 | 
			
		||||
 | 
			
		||||
		// No need for sanitiy check. we are sure that we have at least one element in the array
 | 
			
		||||
		$weightSelect = "CASE page_namespace ";
 | 
			
		||||
		$currentWeight = 0;
 | 
			
		||||
		foreach ($nameSpaces as &$nameSpaceValue) {
 | 
			
		||||
		foreach ($namespaces as &$namespaceValue) {
 | 
			
		||||
				$currentWeight = $currentWeight + 100;
 | 
			
		||||
				$weightSelect = $weightSelect . " WHEN " . $nameSpaceValue . " THEN " . $currentWeight . PHP_EOL;
 | 
			
		||||
				$weightSelect = $weightSelect . " WHEN " . $namespaceValue . " THEN " . $currentWeight . PHP_EOL;
 | 
			
		||||
		}
 | 
			
		||||
		$weightSelect = $weightSelect . " END ";
 | 
			
		||||
		$nameSpacesClause = '(' . implode( ', ', $nameSpaces ) . ')';
 | 
			
		||||
		$namespacesClause = '(' . implode( ', ', $namespaces ) . ')';
 | 
			
		||||
 | 
			
		||||
		// Build an SQL query and fetch all page titles ordered by length from
 | 
			
		||||
		// shortest to longest. Only titles from 'normal' pages (namespace uid
 | 
			
		||||
@@ -125,7 +125,7 @@ class Targets {
 | 
			
		||||
				array( 'page_title', 'page_namespace' , "weight" => $weightSelect),
 | 
			
		||||
				array_filter(
 | 
			
		||||
					array(
 | 
			
		||||
						'page_namespace IN ' . $nameSpacesClause,
 | 
			
		||||
						'page_namespace IN ' . $namespacesClause,
 | 
			
		||||
						'CHAR_LENGTH(page_title) >= ' . $this->config->minimumTitleLength,
 | 
			
		||||
						$blackList,
 | 
			
		||||
					)
 | 
			
		||||
@@ -139,7 +139,7 @@ class Targets {
 | 
			
		||||
				array( 'page_title', 'page_namespace' , "weight" => $weightSelect ),
 | 
			
		||||
				array_filter(
 | 
			
		||||
					array(
 | 
			
		||||
						'page_namespace IN ' . $nameSpacesClause,
 | 
			
		||||
						'page_namespace IN ' . $namespacesClause,
 | 
			
		||||
						'LENGTH(page_title) >= ' . $this->config->minimumTitleLength,
 | 
			
		||||
						$blackList,
 | 
			
		||||
					)
 | 
			
		||||
 
 | 
			
		||||
@@ -155,12 +155,12 @@ class Cli extends \Maintenance {
 | 
			
		||||
 | 
			
		||||
		// Retrieve page names from the database.
 | 
			
		||||
		$dbr = $this->getDB( DB_SLAVE );
 | 
			
		||||
		$nameSpacesClause = str_replace( '_', ' ','(' . implode( ', ', $config->nameSpaces ) . ')' );
 | 
			
		||||
		$namespacesClause = str_replace( '_', ' ','(' . implode( ', ', $config->namespaces ) . ')' );
 | 
			
		||||
		$res = $dbr->select(
 | 
			
		||||
			'page',
 | 
			
		||||
			array( 'page_title', 'page_namespace' ),
 | 
			
		||||
			array(
 | 
			
		||||
				'page_namespace IN ' . $nameSpacesClause,
 | 
			
		||||
				'page_namespace IN ' . $namespacesClause,
 | 
			
		||||
			),
 | 
			
		||||
			__METHOD__,
 | 
			
		||||
			array(
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user