From 500d441b4b2760a41664bb33f658ea2e178b9b7a Mon Sep 17 00:00:00 2001 From: Brent Laabs Date: Tue, 27 Dec 2016 19:07:38 -0800 Subject: [PATCH 1/6] Use underscores when searching the page table, not spaces The old code replaced underscores with spaces, which was backwards. Also we don't need to look for underscores or spaces in namespaces, because they are all integers. --- includes/LinkTitles_Extension.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/includes/LinkTitles_Extension.php b/includes/LinkTitles_Extension.php index 60eaa44..e84da03 100644 --- a/includes/LinkTitles_Extension.php +++ b/includes/LinkTitles_Extension.php @@ -35,7 +35,7 @@ class Extension { /// A Title object for the target page currently being examined. private static $targetTitle; - + // The TitleValue object of the target page private static $targetTitleValue; @@ -55,7 +55,7 @@ class Extension { private static $wordStartDelim; private static $wordEndDelim; - + public static $ltConsoleOutput; public static $ltConsoleOutputDebug; @@ -130,16 +130,16 @@ private static function parseContent( $title, &$text ) { // Build a blacklist of pages that are not supposed to be link // targets. This includes the current page. - $blackList = str_replace( '_', ' ', - '("' . implode( '", "',$wgLinkTitlesBlackList ) . '", "' . + $blackList = str_replace( ' ', '_', + '("' . implode( '","',$wgLinkTitlesBlackList ) . '","' . addslashes( self::$currentTitle->getDbKey() ) . '")' ); $currentNamespace[] = $title->getNamespace(); - + // Build our weight list. Make sure current namespace is first element $namespaces = array_diff($wgLinkTitlesNamespaces, $currentNamespace); array_unshift($namespaces, $currentNamespace[0] ); - + // No need for sanitiy check. we are sure that we have at least one element in the array $weightSelect = "CASE page_namespace "; $currentWeight = 0; @@ -148,7 +148,7 @@ private static function parseContent( $title, &$text ) { $weightSelect = $weightSelect . " WHEN " . $namspacevalue . " THEN " . $currentWeight . PHP_EOL; } $weightSelect = $weightSelect . " END "; - $namespacesClause = str_replace( '_', ' ','(' . 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 @@ -194,7 +194,7 @@ private static function parseContent( $title, &$text ) { // regexp compilation errors self::$targetTitleText = self::$targetTitle->getText(); $quotedTitle = preg_quote(self::$targetTitleText, '/'); - + self::ltDebugLog('TargetTitle='. self::$targetTitleText,"private"); self::ltDebugLog('TargetTitleQuoted='. $quotedTitle,"private"); @@ -243,7 +243,7 @@ private static function parseContent( $title, &$text ) { }; // foreach $res as $row return $newText; } - + /// Automatically processes a single page, given a $title Title object. /// This function is called by the SpecialLinkTitles class and the /// LinkTitlesJob class. @@ -349,9 +349,9 @@ private static function smartModeCallback( array $matches ) { /// Sets member variables for the current target page. private static function newTarget( $ns, $title ) { - self::$targetTitle = \Title::makeTitleSafe( $ns, $title ); - self::ltDebugLog( 'newtarget='. self::$targetTitle->getText(), "private" ); - self::$targetTitleValue = self::$targetTitle->getTitleValue(); + self::$targetTitle = \Title::makeTitleSafe( $ns, $title ); + self::ltDebugLog( 'newtarget='. self::$targetTitle->getText(), "private" ); + self::$targetTitleValue = self::$targetTitle->getTitleValue(); self::ltDebugLog( 'altTarget='. self::$targetTitleValue->getText(), "private" ); self::$targetContent = null; } @@ -477,6 +477,6 @@ public static function ltLog($text) { } wfDebugLog('LinkTitles', $text , 'private'); } - } +} // vim: ts=2:sw=2:noet:comments^=\:/// From 8104ce66ffa84b2e1fb44216bb6589aaa4a5289b Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Wed, 28 Dec 2016 12:19:40 +0100 Subject: [PATCH 2/6] Use namespace weight in page query. - Fix: Custom namespace weights were not respected. Closes #15. --- includes/LinkTitles_Extension.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/LinkTitles_Extension.php b/includes/LinkTitles_Extension.php index 60eaa44..e3951af 100644 --- a/includes/LinkTitles_Extension.php +++ b/includes/LinkTitles_Extension.php @@ -165,7 +165,7 @@ private static function parseContent( $title, &$text ) { 'page_title NOT IN ' . $blackList, ), __METHOD__, - array( 'ORDER BY' => 'CHAR_LENGTH(page_title) ' . $sort_order ) + array( 'ORDER BY' => 'weight ASC, CHAR_LENGTH(page_title) ' . $sort_order ) ); } catch (Exception $e) { $res = $dbr->select( @@ -177,7 +177,7 @@ private static function parseContent( $title, &$text ) { 'page_title NOT IN ' . $blackList, ), __METHOD__, - array( 'ORDER BY' => 'LENGTH(page_title) ' . $sort_order ) + array( 'ORDER BY' => 'weight ASC, LENGTH(page_title) ' . $sort_order ) ); } From dec716ed563c2efaf0941a0916c8afcdcfd2a021 Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Wed, 28 Dec 2016 12:40:05 +0100 Subject: [PATCH 3/6] Explain branching model in readme. --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d2ac176..484c0a1 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,14 @@ pages](http://bovender.github.io/LinkTitles). This extension is [semantically versioned](http://semver.org). -If you wish to contribute, please issue pull requests against the `develop` branch. + +Contributing +------------ + +If you wish to contribute, please issue pull requests against the `develop` +branch, as I follow Vincent Driessen's advice on [A successful Git branching +model](http://nvie.com/git-model) (knowing that there are [alternative +workflows](http://scottchacon.com/2011/08/31/github-flow.html)). Contributors From 7cbe0cd89c8dba38831892c1ac6d29e14f79af51 Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Wed, 28 Dec 2016 12:55:12 +0100 Subject: [PATCH 4/6] Bump version, update contributors. --- README.md | 1 + extension.json | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 484c0a1..4f51bd3 100644 --- a/README.md +++ b/README.md @@ -27,3 +27,4 @@ Contributors - Daniel Kraus (@bovender), main developer - Ulrich Strauss (@c0nnex), namespaces +- Brent Laabs (@labster), bug fixes diff --git a/extension.json b/extension.json index adb9513..52f25fe 100644 --- a/extension.json +++ b/extension.json @@ -2,11 +2,12 @@ "name": "LinkTitles", "author": [ "[https://www.mediawiki.org/wiki/User:Bovender Daniel Kraus (bovender)]", - "Ulrich Strauss (c0nnex)" + "Ulrich Strauss (c0nnex)", + "Brent Laabs (labster)" ], "type": "parserhook", "url": "https://www.mediawiki.org/wiki/Extension:LinkTitles", - "version": "4.0.5", + "version": "4.0.6", "license-name": "GPL-2.0+", "descriptionmsg": "linktitles-desc", "requires": { From b542bac99cb26c9041c57d5470da258181118e3b Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Wed, 28 Dec 2016 12:56:51 +0100 Subject: [PATCH 5/6] Update NEWS. --- NEWS | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/NEWS b/NEWS index 7f5a77a..74e833d 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,11 @@ +Version 4.0.6 (2016-12-28) +------------------------------------------------------------------------ + +- Fix: Custom namespace weights were not respected. + +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + + Version 4.0.5 (2016-12-14) ------------------------------------------------------------------------ From 20937c20d02b5337068e9fde9d2752513b6d3e4b Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Wed, 28 Dec 2016 12:57:35 +0100 Subject: [PATCH 6/6] Update documentation. --- gh-pages | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gh-pages b/gh-pages index fe99cf4..4735662 160000 --- a/gh-pages +++ b/gh-pages @@ -1 +1 @@ -Subproject commit fe99cf4e039c3066c018fdf5973caee1cf4cef09 +Subproject commit 47356620d1eafbadd1f77ea89c24b0141519eddc