diff --git a/LinkTitles_Maintenance.php b/LinkTitles_Maintenance.php index b04273f..7cdaae3 100755 --- a/LinkTitles_Maintenance.php +++ b/LinkTitles_Maintenance.php @@ -1,6 +1,6 @@ @bovender + * Copyright 2012-2017 Daniel Kraus @bovender * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -49,7 +49,7 @@ require_once( __DIR__ . "/includes/LinkTitles_Extension.php" ); /// Core class of the maintanance script. /// @note Note that the execution of maintenance scripts is prohibited for /// an Apache web server due to a `.htaccess` file that declares `deny from -/// all`. Other webservers may exhibit different behavior. Be aware that +/// all`. Other webservers may exhibit different behavior. Be aware that /// anybody who is able to execute this script may place a high load on the /// server. /// @ingroup batch @@ -116,7 +116,7 @@ class Cli extends \Maintenance { $this->allPages( $startIndex); } } - + private function singlePage() { $pageName = strval( $this->getOption( 'page' ) ); $this->output( "Processing single page: '$pageName'\n" ); @@ -130,7 +130,7 @@ class Cli extends \Maintenance { } return $success; } - + private function allPages( $index = 0 ) { global $wgLinkTitlesNamespaces; diff --git a/README_DOC.md b/README_DOC.md index 990d74f..b176db0 100644 --- a/README_DOC.md +++ b/README_DOC.md @@ -1,6 +1,6 @@ @mainpage LinkTitles @author [Daniel Kraus (bovender)](http://www.mediawiki.org/wiki/User:Bovender) -@date 2012-2016 +@date 2012-2017 @copyright [GNU GPL v2+](http://www.gnu.org/licenses/gpl-2.0.html) %LinkTitles source code documentation diff --git a/includes/LinkTitles_Extension.php b/includes/LinkTitles_Extension.php index c4419f9..5fffa3e 100644 --- a/includes/LinkTitles_Extension.php +++ b/includes/LinkTitles_Extension.php @@ -1,17 +1,17 @@ ('bovender') - * + * Copyright 2012-2017 Daniel Kraus ('bovender') + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, @@ -49,7 +49,7 @@ class Extension { private static $targetTitleValue; /// The content object for the currently processed target page. - /// This variable is necessary to be able to prevent loading the target + /// This variable is necessary to be able to prevent loading the target /// content twice. private static $targetContent; @@ -84,7 +84,7 @@ class Extension { $title = $wikiPage->getTitle(); // Only process if page is in one of our namespaces we want to link - // Fixes ugly autolinking of sidebar pages + // Fixes ugly autolinking of sidebar pages if ( in_array( $title->getNamespace(), $wgLinkTitlesNamespaces )) { $text = $content->getContentHandler()->serializeContent( $content ); if ( !\MagicWord::get( 'MAG_LINKTITLES_NOAUTOLINKS' )->match( $text ) ) { @@ -163,13 +163,13 @@ class Extension { // way, or in a 'fuzzy' way where the first letter of the title may // be either case. if ( $wgCapitalLinks && ( $quotedTitle[0] != '\\' )) { - $searchTerm = '((?i)' . $quotedTitle[0] . '(?-i)' . + $searchTerm = '((?i)' . $quotedTitle[0] . '(?-i)' . substr($quotedTitle, 1) . ')'; } else { $searchTerm = '(' . $quotedTitle . ')'; } - $regex = '/(? 0 ) ) { $limitReached = true; - break; + break; }; }; $newText = implode( '', $arr ); @@ -191,11 +191,11 @@ class Extension { for ( $i = 0; $i < count( $arr ); $i+=2 ) { // even indexes will point to text that is not enclosed by brackets $arr[$i] = preg_replace_callback( '/(? 0 )) { - break; + break; }; }; $newText = implode( '', $arr ); @@ -205,10 +205,10 @@ class Extension { } /// Automatically processes a single page, given a $title Title object. - /// This function is called by the SpecialLinkTitles class and the + /// This function is called by the SpecialLinkTitles class and the /// LinkTitlesJob class. /// @param Title $title Title object. - /// @param RequestContext $context Current request context. + /// @param RequestContext $context Current request context. /// If in doubt, call MediaWiki's `RequestContext::getMain()` /// to obtain such an object. /// @returns boolean True if the page exists, false if the page does not exist @@ -236,8 +236,8 @@ class Extension { } } - /// Adds the two magic words defined by this extension to the list of - /// 'double-underscore' terms that are automatically removed before a + /// Adds the two magic words defined by this extension to the list of + /// 'double-underscore' terms that are automatically removed before a /// page is displayed. /// @param $doubleUnderscoreIDs Array of magic word IDs. /// @return true @@ -256,7 +256,7 @@ class Extension { global $wgLinkTitlesNamespaces; ( $wgLinkTitlesPreferShortTitles ) ? $sort_order = 'ASC' : $sort_order = '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 // targets. This includes the current page. $blackList = str_replace( ' ', '_', '("' . implode( '","',$wgLinkTitlesBlackList ) . '")' ); @@ -274,33 +274,33 @@ class Extension { $weightSelect = $weightSelect . " END "; $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 - // = 0) are returned. Since the db may be sqlite, we need a try..catch + // Build an SQL query and fetch all page titles ordered by length from + // shortest to longest. Only titles from 'normal' pages (namespace uid + // = 0) are returned. Since the db may be sqlite, we need a try..catch // structure because sqlite does not support the CHAR_LENGTH function. $dbr = wfGetDB( DB_SLAVE ); try { - $res = $dbr->select( - 'page', + $res = $dbr->select( + 'page', array( 'page_title', 'page_namespace' , "weight" => $weightSelect), - array( - 'page_namespace IN ' . $namespacesClause, + array( + 'page_namespace IN ' . $namespacesClause, 'CHAR_LENGTH(page_title) >= ' . $wgLinkTitlesMinimumTitleLength, 'page_title NOT IN ' . $blackList, - ), - __METHOD__, + ), + __METHOD__, array( 'ORDER BY' => 'weight ASC, CHAR_LENGTH(page_title) ' . $sort_order ) ); } catch (Exception $e) { - $res = $dbr->select( - 'page', + $res = $dbr->select( + 'page', array( 'page_title', 'page_namespace' , "weight" => $weightSelect ), - array( - 'page_namespace IN ' . $namespacesClause, + array( + 'page_namespace IN ' . $namespacesClause, 'LENGTH(page_title) >= ' . $wgLinkTitlesMinimumTitleLength, 'page_title NOT IN ' . $blackList, - ), - __METHOD__, + ), + __METHOD__, array( 'ORDER BY' => 'weight ASC, LENGTH(page_title) ' . $sort_order ) ); } @@ -321,19 +321,19 @@ class Extension { } // Callback function for use with preg_replace_callback. - // This essentially performs a case-sensitive comparison of the - // current page title and the occurrence found on the page; if + // This essentially performs a case-sensitive comparison of the + // current page title and the occurrence found on the page; if // the cases do not match, it builds an aliased (piped) link. - // If $wgCapitalLinks is set to true, the case of the first - // letter is ignored by MediaWiki and we don't need to build a + // If $wgCapitalLinks is set to true, the case of the first + // letter is ignored by MediaWiki and we don't need to build a // piped link if only the case of the first letter is different. private static function smartModeCallback( array $matches ) { global $wgCapitalLinks; if ( $wgCapitalLinks ) { - // With $wgCapitalLinks set to true we have a slightly more - // complicated version of the callback than if it were false; - // we need to ignore the first letter of the page titles, as + // With $wgCapitalLinks set to true we have a slightly more + // complicated version of the callback than if it were false; + // we need to ignore the first letter of the page titles, as // it does not matter for linking. if ( self::checkTargetPage() ) { self::ltLog( "Linking (smart) '$matches[0]' to '" . self::$targetTitle . "'" ); @@ -350,7 +350,7 @@ class Extension { return $matches[0]; } } else { - // If $wgCapitalLinks is false, we can use the simple variant + // If $wgCapitalLinks is false, we can use the simple variant // of the callback function. if ( self::checkTargetPage() ) { self::ltLog( "Linking (smart) '$matches[0]' to '" . self::$targetTitle . "'" ); @@ -379,10 +379,10 @@ class Extension { } /// Returns the content of the current target page. - /// This function serves to be used in preg_replace_callback callback - /// functions, in order to load the target page content from the + /// This function serves to be used in preg_replace_callback callback + /// functions, in order to load the target page content from the /// database only when needed. - /// @note It is absolutely necessary that the newTarget() + /// @note It is absolutely necessary that the newTarget() /// function is called for every new page. private static function getTargetContent() { if ( ! isset( $targetContent ) ) { @@ -392,18 +392,18 @@ class Extension { return self::$targetContent; } - /// Examines the current target page. Returns true if it may be linked; - /// false if not. This depends on the settings - /// $wgLinkTitlesCheckRedirect and $wgLinkTitlesEnableNoTargetMagicWord - /// and whether the target page is a redirect or contains the + /// Examines the current target page. Returns true if it may be linked; + /// false if not. This depends on the settings + /// $wgLinkTitlesCheckRedirect and $wgLinkTitlesEnableNoTargetMagicWord + /// and whether the target page is a redirect or contains the /// __NOAUTOLINKTARGET__ magic word. /// @returns boolean private static function checkTargetPage() { global $wgLinkTitlesEnableNoTargetMagicWord; global $wgLinkTitlesCheckRedirect; - // If checking for redirects is enabled and the target page does - // indeed redirect to the current page, return the page title as-is + // If checking for redirects is enabled and the target page does + // indeed redirect to the current page, return the page title as-is // (unlinked). if ( $wgLinkTitlesCheckRedirect ) { $redirectTitle = self::getTargetContent()->getUltimateRedirectTarget(); @@ -412,8 +412,8 @@ class Extension { } }; - // If the magic word __NOAUTOLINKTARGET__ is enabled and the target - // page does indeed contain this magic word, return the page title + // If the magic word __NOAUTOLINKTARGET__ is enabled and the target + // page does indeed contain this magic word, return the page title // as-is (unlinked). if ( $wgLinkTitlesEnableNoTargetMagicWord ) { if ( self::getTargetContent()->matchMagicWord( @@ -436,7 +436,7 @@ private static function BuildDelimiters() { // Use unicode character properties rather than \b escape sequences // to detect whole words containing non-ASCII characters as well. - // Note that this requires a PCRE library that was compiled with + // Note that this requires a PCRE library that was compiled with // --enable-unicode-properties ( $wgLinkTitlesWordStartOnly ) ? self::$wordStartDelim = '(? ('bovender') + * Copyright 2012-2017 Daniel Kraus ('bovender') * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/includes/LinkTitles_Special.php b/includes/LinkTitles_Special.php index 388a8dd..96607a2 100644 --- a/includes/LinkTitles_Special.php +++ b/includes/LinkTitles_Special.php @@ -1,6 +1,6 @@ ('bovender') + * Copyright 2012-2017 Daniel Kraus ('bovender') * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by