From 2b5b1d4613a2059ace298bda5699a3621c06114e Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Thu, 24 Aug 2017 13:46:36 +0200 Subject: [PATCH 1/6] Add support for tag. - New: Mark sections that are not to be automatically linked with the new `..` tag. Addresses #29. --- extension.json | 3 +++ includes/LinkTitles_Extension.php | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/extension.json b/extension.json index e732b07..1991dd0 100644 --- a/extension.json +++ b/extension.json @@ -56,6 +56,9 @@ ], "GetDoubleUnderscoreIDs": [ "LinkTitles\\Extension::onGetDoubleUnderscoreIDs" + ], + "ParserFirstCallInit": [ + "LinkTitles\\Extension::onParserFirstCallInit" ] }, "callback": "LinkTitles\\Extension::setup", diff --git a/includes/LinkTitles_Extension.php b/includes/LinkTitles_Extension.php index 5fffa3e..9fe74b6 100644 --- a/includes/LinkTitles_Extension.php +++ b/includes/LinkTitles_Extension.php @@ -247,6 +247,17 @@ class Extension { return true; } + public static function onParserFirstCallInit( \Parser $parser ) { + $parser->setHook( 'noautolinks', 'LinkTitles\Extension::removeExtraTags' ); + } + + /// Removes the extra tag that this extension provides () + /// by simply returning the text between the tags (if any). + /// See https://www.mediawiki.org/wiki/Manual:Tag_extensions#Example + public static function removeExtraTags( $input, array $args, \Parser $parser, \PPFrame $frame ) { + return htmlspecialchars( $input ); + } + // Fetches the page titles from the database. // @param $currentNamespace String holding the namespace of the page currently being processed. private static function fetchPageTitles( $currentNamespace ) { @@ -478,6 +489,7 @@ private static function BuildDelimiters() { '|<\/span>|' . // attributes of span elements '[^<]*<\/file>|' . // stuff inside file elements 'style=".+?"|class=".+?"|' . // styles and classes (e.g. of wikitables) + '.*?<\/noautolinks>|' . // custom tag 'noautolinks' '\[' . $urlPattern . '\s.+?\]|'. $urlPattern . '(?=\s|$)|' . // urls '(?<=\b)\S+\@(?:\S+\.)+\S+(?=\b)' . // email addresses ')/ismS'; From d49acce467842a37d571e3a958ec12fa84618ce9 Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Thu, 24 Aug 2017 13:58:08 +0200 Subject: [PATCH 2/6] Fix indentation. --- includes/LinkTitles_Extension.php | 42 +++++++++++++++---------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/includes/LinkTitles_Extension.php b/includes/LinkTitles_Extension.php index 9fe74b6..f953375 100644 --- a/includes/LinkTitles_Extension.php +++ b/includes/LinkTitles_Extension.php @@ -435,10 +435,10 @@ class Extension { return true; } -/// Builds the delimiter that is used in a regexp to separate -/// text that should be parsed from text that should not be -/// parsed (e.g. inside existing links etc.) -private static function BuildDelimiters() { + /// Builds the delimiter that is used in a regexp to separate + /// text that should be parsed from text that should not be + /// parsed (e.g. inside existing links etc.) + private static function BuildDelimiters() { // Configuration variables need to be defined here as globals. global $wgLinkTitlesParseHeadings; global $wgLinkTitlesSkipTemplates; @@ -493,25 +493,25 @@ private static function BuildDelimiters() { '\[' . $urlPattern . '\s.+?\]|'. $urlPattern . '(?=\s|$)|' . // urls '(?<=\b)\S+\@(?:\S+\.)+\S+(?=\b)' . // email addresses ')/ismS'; - } + } - /// Local Debugging output function which can send output to console as well - public static function ltDebugLog($text) { - if (self::$ltConsoleOutputDebug) - { - print $text . "\n"; - } - wfDebugLog('LinkTitles', $text , 'private'); - } + /// Local Debugging output function which can send output to console as well + public static function ltDebugLog($text) { + if (self::$ltConsoleOutputDebug) + { + print $text . "\n"; + } + wfDebugLog('LinkTitles', $text , 'private'); + } - /// Local Logging output function which can send output to console as well - public static function ltLog($text) { - if (self::$ltConsoleOutput) - { - print $text . "\n"; - } - wfDebugLog('LinkTitles', $text , 'private'); - } + /// Local Logging output function which can send output to console as well + public static function ltLog($text) { + if (self::$ltConsoleOutput) + { + print $text . "\n"; + } + wfDebugLog('LinkTitles', $text , 'private'); + } } // vim: ts=2:sw=2:noet:comments^=\:/// From 8f16e00952320487821d0af1a86dc777a66b36a5 Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Thu, 24 Aug 2017 14:03:05 +0200 Subject: [PATCH 3/6] Spaces to tabs. --- includes/LinkTitles_Extension.php | 40 +++++++++++++++---------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/includes/LinkTitles_Extension.php b/includes/LinkTitles_Extension.php index f953375..ded80ae 100644 --- a/includes/LinkTitles_Extension.php +++ b/includes/LinkTitles_Extension.php @@ -45,8 +45,8 @@ 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; + // The TitleValue object of the target page + private static $targetTitleValue; /// The content object for the currently processed target page. /// This variable is necessary to be able to prevent loading the target @@ -153,10 +153,10 @@ class Extension { // Escape certain special characters in the page title to prevent // regexp compilation errors self::$targetTitleText = self::$targetTitle->getText(); - $quotedTitle = preg_quote(self::$targetTitleText, '/'); + $quotedTitle = preg_quote( self::$targetTitleText, '/' ); - self::ltDebugLog('TargetTitle='. self::$targetTitleText,"private"); - self::ltDebugLog('TargetTitleQuoted='. $quotedTitle,"private"); + self::ltDebugLog( 'TargetTitle='. self::$targetTitleText, 'private' ); + self::ltDebugLog( 'TargetTitleQuoted='. $quotedTitle, 'private' ); // Depending on the global configuration setting $wgCapitalLinks, // the title has to be searched for either in a strictly case-sensitive @@ -495,23 +495,21 @@ class Extension { ')/ismS'; } - /// Local Debugging output function which can send output to console as well - public static function ltDebugLog($text) { - if (self::$ltConsoleOutputDebug) - { - print $text . "\n"; - } - wfDebugLog('LinkTitles', $text , 'private'); - } + /// Local Debugging output function which can send output to console as well + public static function ltDebugLog($text) { + if ( self::$ltConsoleOutputDebug ) { + print $text . "\n"; + } + wfDebugLog( 'LinkTitles', $text , 'private' ); + } - /// Local Logging output function which can send output to console as well - public static function ltLog($text) { - if (self::$ltConsoleOutput) - { - print $text . "\n"; - } - wfDebugLog('LinkTitles', $text , 'private'); - } + /// Local Logging output function which can send output to console as well + public static function ltLog($text) { + if (self::$ltConsoleOutput) { + print $text . "\n"; + } + wfDebugLog( 'LinkTitles', $text , 'private' ); + } } // vim: ts=2:sw=2:noet:comments^=\:/// From 9d11c5b2703b32da65272418d0d22de56e94e7b2 Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Thu, 24 Aug 2017 14:18:10 +0200 Subject: [PATCH 4/6] Implement tag. - New: Mark sections that are to be automatically linked with the new `..` tag. This tag only makes sense on pages with the `__NOAUTOLINKS__` magic word, or if both `$wgLinkTitlesParseOnEdit` and `$wgLinkTitlesParseOnRender` are set to false. Note that this tag is parsed when a page is rendered, not when it is saved. Therefore, the links will not appear in the page source. Addresses #29. --- includes/LinkTitles_Extension.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/includes/LinkTitles_Extension.php b/includes/LinkTitles_Extension.php index ded80ae..ea02bad 100644 --- a/includes/LinkTitles_Extension.php +++ b/includes/LinkTitles_Extension.php @@ -248,16 +248,26 @@ class Extension { } public static function onParserFirstCallInit( \Parser $parser ) { - $parser->setHook( 'noautolinks', 'LinkTitles\Extension::removeExtraTags' ); + $parser->setHook( 'noautolinks', 'LinkTitles\Extension::doNoautolinksTag' ); + $parser->setHook( 'autolinks', 'LinkTitles\Extension::doAutolinksTag' ); } /// Removes the extra tag that this extension provides () /// by simply returning the text between the tags (if any). /// See https://www.mediawiki.org/wiki/Manual:Tag_extensions#Example - public static function removeExtraTags( $input, array $args, \Parser $parser, \PPFrame $frame ) { + public static function doNoautolinksTag( $input, array $args, \Parser $parser, \PPFrame $frame ) { return htmlspecialchars( $input ); } + /// Removes the extra tag that this extension provides () + /// by simply returning the text between the tags (if any). + /// See https://www.mediawiki.org/wiki/Manual:Tag_extensions#How_do_I_render_wikitext_in_my_extension.3F + public static function doAutolinksTag( $input, array $args, \Parser $parser, \PPFrame $frame ) { + $withLinks = self::parseContent( $parser->getTitle(), $input ); + $output = $parser->recursiveTagParse( $withLinks, $frame ); + return $output; + } + // Fetches the page titles from the database. // @param $currentNamespace String holding the namespace of the page currently being processed. private static function fetchPageTitles( $currentNamespace ) { From 0dbddc795ace088a0fe93ebe8fd4520271bd131a Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Thu, 24 Aug 2017 19:10:29 +0200 Subject: [PATCH 5/6] Use recursive regex to deal with nested braces. - Fix: Properly handle templates that include other templates. Addresses #29. --- includes/LinkTitles_Extension.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/includes/LinkTitles_Extension.php b/includes/LinkTitles_Extension.php index ea02bad..31e4c72 100644 --- a/includes/LinkTitles_Extension.php +++ b/includes/LinkTitles_Extension.php @@ -464,7 +464,9 @@ class Extension { if ( $wgLinkTitlesSkipTemplates ) { - $templatesDelimiter = '{{[^}]+}}|'; + // Use recursive regex to balance curly braces; + // see http://www.regular-expressions.info/recurse.html + $templatesDelimiter = '{{(?>[^{}]|(?R))*}}|'; } else { // Match template names (ignoring any piped [[]] links in them) // along with the trailing pipe and parameter name or closing From 5e821ef1a93fa85bcabe5e397a6d7b7311530e72 Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Fri, 25 Aug 2017 19:31:30 +0200 Subject: [PATCH 6/6] Prepare release. --- NEWS | 32 +++++++++++++++++++++----------- README.md | 9 ++++++--- extension.json | 2 +- gh-pages | 2 +- 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/NEWS b/NEWS index 07892fa..0c1d448 100644 --- a/NEWS +++ b/NEWS @@ -1,9 +1,19 @@ +Version 7.1.0 (2017-08-24) +------------------------------------------------------------------------ + +- New: Mark sections that are not to be automatically linked with the new `..` tag. +- New: Mark sections that are to be automatically linked with the new `..` tag. This tag only makes sense on pages with the `__NOAUTOLINKS__` magic word, or if both `$wgLinkTitlesParseOnEdit` and `$wgLinkTitlesParseOnRender` are set to false. Note that this tag is parsed when a page is rendered, not when it is saved. Therefore, the links will not appear in the page source. +- Fix: Properly handle templates that include other templates. + +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + + Version 4.0.9 (2017-03-21) ------------------------------------------------------------------------ - Fix: __NOAUTOLINKS__ was not respected during rendering. -* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Version 4.0.8 (2017-02-16) @@ -13,7 +23,7 @@ Version 4.0.8 (2017-02-16) - Fix: The special page and the maintenance script did not work in MW 1.28. - Fix: The special page did not work. -* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Version 4.0.7 (2017-01-02) @@ -21,7 +31,7 @@ Version 4.0.7 (2017-01-02) - Improvement: Increase performance of special page and maintenance script. -* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Version 4.0.6 (2016-12-28) @@ -30,7 +40,7 @@ Version 4.0.6 (2016-12-28) - Fix: Bug fixes. - Fix: Custom namespace weights were not respected. -* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Version 4.0.5 (2016-12-14) @@ -40,7 +50,7 @@ Version 4.0.5 (2016-12-14) - Fix: Remove leftover error log call. - Improvement: Refactored maintenance script, improving user interaction. -* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Version 4.0.4 (2016-11-30) @@ -48,7 +58,7 @@ Version 4.0.4 (2016-11-30) - Fix: Do not link titles twice if $wgLinkTitlesFirstOnly and $wgLinkTitlesSmartMode are both true. -* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Version 4.0.3 (2016-11-22) @@ -56,7 +66,7 @@ Version 4.0.3 (2016-11-22) - Fix: __NOAUTOLINKS__ magic word would not be respected when saving an edited page. -* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Version 4.0.2 (2016-11-09) @@ -65,7 +75,7 @@ Version 4.0.2 (2016-11-09) - FIX: Removed a fatal bug in the LinkTitles_Maintenance script. - FIX: Repaired severely broken namespaces support. -* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Version 4.0.1 (2016-11-08) @@ -73,7 +83,7 @@ Version 4.0.1 (2016-11-08) - FIX: Prevent syntax error when accessing special page. -* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Version 4.0.0 (2016-11-05) @@ -85,7 +95,7 @@ Version 4.0.0 (2016-11-05) - NEW: Support namespaces. - NEW: Use the new extension format introduced by MediaWiki 1.25; the extension will no longer run with older MediaWiki versions. -* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Version 3.1.0. (2015-02-05) @@ -93,7 +103,7 @@ Version 3.1.0. (2015-02-05) - IMPROVEMENT: Do not link inside ... tags. -* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * diff --git a/README.md b/README.md index 603bd95..bc4847a 100644 --- a/README.md +++ b/README.md @@ -16,11 +16,14 @@ This extension is [semantically versioned](http://semver.org). 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 +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)). +The `master` branch contains stable releases only, so it is safe to pull the +master branch if you want to install the extension for your own wiki. + Contributors ------------ diff --git a/extension.json b/extension.json index 1991dd0..fe3ee4a 100644 --- a/extension.json +++ b/extension.json @@ -7,7 +7,7 @@ ], "type": "parserhook", "url": "https://www.mediawiki.org/wiki/Extension:LinkTitles", - "version": "4.0.9", + "version": "4.1.0", "license-name": "GPL-2.0+", "descriptionmsg": "linktitles-desc", "requires": { diff --git a/gh-pages b/gh-pages index 2dec0ce..076be77 160000 --- a/gh-pages +++ b/gh-pages @@ -1 +1 @@ -Subproject commit 2dec0ce8a6864c2c1169710fe206175c4c58b940 +Subproject commit 076be774a2dcf5d625adf292c7fd97bddc4bfddd