Skip to content

Commit

Permalink
Merge branch 'release-5.0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
bovender committed Sep 6, 2017
2 parents e78d1d7 + 7bf2883 commit ebab186
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 16 deletions.
9 changes: 9 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
Version 5.0.3 (2017-09-06)
------------------------------------------------------------------------

- Fix: <autolinks> tag was broken.
- Fix: <noautolinks> tag did not work in parse-on-render mode.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


Version 5.0.2 (2017-09-05)
------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
],
"type": "parserhook",
"url": "https://www.mediawiki.org/wiki/Extension:LinkTitles",
"version": "5.0.2",
"version": "5.0.3",
"license-name": "GPL-2.0+",
"descriptionmsg": "linktitles-desc",
"requires": {
Expand Down
2 changes: 1 addition & 1 deletion gh-pages
Submodule gh-pages updated 77 files
+1 −1 ConfigTest_8php_source.html
+1 −1 Config_8php_source.html
+4 −2 ExtensionTest_8php_source.html
+2 −2 Extension_8php_source.html
+1 −1 LinkTitles_8php_source.html
+1 −1 LinkerTest_8php_source.html
+7 −5 Linker_8php_source.html
+1 −1 Magic_8php_source.html
+1 −1 README__DOC_8md_source.html
+1 −1 Source_8php_source.html
+1 −1 Special_8php_source.html
+2 −2 SplitterTest_8php_source.html
+1 −1 Splitter_8php_source.html
+1 −1 TargetTest_8php_source.html
+1 −1 Target_8php_source.html
+1 −1 TargetsTest_8php_source.html
+1 −1 Targets_8php_source.html
+1 −1 TestCase_8php_source.html
+1 −1 annotated.html
+1 −1 classConfigTest-members.html
+1 −1 classConfigTest.html
+5 −3 classExtensionTest-members.html
+15 −7 classExtensionTest.html
+4 −2 classExtensionTest.js
+1 −1 classLinkTitlesLinkerTest-members.html
+1 −1 classLinkTitlesLinkerTest.html
+1 −1 classLinkTitles_1_1Cli-members.html
+1 −1 classLinkTitles_1_1Cli.html
+1 −1 classLinkTitles_1_1Config-members.html
+1 −1 classLinkTitles_1_1Config.html
+1 −1 classLinkTitles_1_1Extension-members.html
+1 −1 classLinkTitles_1_1Extension.html
+6 −3 classLinkTitles_1_1Linker-members.html
+82 −5 classLinkTitles_1_1Linker.html
+1 −1 classLinkTitles_1_1Source-members.html
+1 −1 classLinkTitles_1_1Source.html
+1 −1 classLinkTitles_1_1Special-members.html
+1 −1 classLinkTitles_1_1Special.html
+1 −1 classLinkTitles_1_1Splitter-members.html
+1 −1 classLinkTitles_1_1Splitter.html
+1 −1 classLinkTitles_1_1Target-members.html
+1 −1 classLinkTitles_1_1Target.html
+1 −1 classLinkTitles_1_1Targets-members.html
+1 −1 classLinkTitles_1_1Targets.html
+1 −1 classLinkTitles_1_1TestCase-members.html
+1 −1 classLinkTitles_1_1TestCase.html
+1 −1 classSplitterTest-members.html
+1 −1 classSplitterTest.html
+1 −1 classTargetTest-members.html
+1 −1 classTargetTest.html
+1 −1 classTargetsTest-members.html
+1 −1 classTargetsTest.html
+1 −1 classes.html
+1 −1 dir_09e761304027c904456130627fd4dcf5.html
+1 −1 dir_59425e443f801f1f2fd8bbe4959a3ccf.html
+1 −1 dir_ebb08f7be6050538c7d96337c81c340e.html
+1 −1 files.html
+17 −1 functions.html
+17 −1 functions_func.html
+1 −1 functions_vars.html
+1 −1 group__batch.html
+1 −1 hierarchy.html
+1 −1 index.html
+1 −1 linktitles-cli_8php_source.html
+1 −1 modules.html
+1 −1 namespaceLinkTitles.html
+1 −1 namespaces.html
+4 −2 navtreeindex0.js
+2 −0 search/all_10.js
+1 −1 search/all_11.html
+1 −4 search/all_11.js
+2 −1 search/all_a.js
+1 −1 search/functions_10.html
+1 −534 search/functions_10.js
+2 −1 search/functions_9.js
+2 −0 search/functions_f.js
+2 −2 search/searchdata.js
9 changes: 7 additions & 2 deletions includes/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ public static function onParserFirstCallInit( \Parser $parser ) {
* See https://www.mediawiki.org/wiki/Manual:Tag_extensions#Example
*/
public static function doNoautolinksTag( $input, array $args, \Parser $parser, \PPFrame $frame ) {
return $parser->recursiveTagParse( $input, $frame );
Linker::lock();
$result = $parser->recursiveTagParse( $input, $frame );
Linker::unlock();
return $result;
}

/*
Expand All @@ -137,8 +140,10 @@ public static function doNoautolinksTag( $input, array $args, \Parser $parser, \
public static function doAutolinksTag( $input, array $args, \Parser $parser, \PPFrame $frame ) {
$config = new Config();
$linker = new Linker( $config );
$source = Source::createFromParser( $parser, $config );
$source = Source::createFromParserAndText( $parser, $input, $config );
Linker::unlock();
$result = $linker->linkContent( $source );
Linker::lock();
if ( $result ) {
return $parser->recursiveTagParse( $result, $frame );
} else {
Expand Down
26 changes: 25 additions & 1 deletion includes/Linker.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class Linker {
*/
private $linkValue;

private static $locked = 0;

/**
* Constructs a new instance of the Linker class.
*
Expand All @@ -68,7 +70,7 @@ public function __construct( Config &$config ) {
* @return String|null Source page text with links to target pages, or null if no links were added
*/
public function linkContent( Source $source ) {
if ( !$source->canBeLinked() ) {
if ( self::$locked > 0 || !$source->canBeLinked() ) {
return;
}

Expand Down Expand Up @@ -197,6 +199,28 @@ private function smartModeCallback( array $matches ) {
return '[[' . $matches[ 0 ] . ']]';
}
}

/**
* Increases an internal static lock counter by 1.
*
* If the Linker class is locked (counter > 0), linkContent() will be a no-op.
* Locking is necessary to enable nested <noautolinks> and <autolinks> tags in
* parseOnRender mode.
*/
public static function lock() {
self::$locked += 1;
}

/**
* Decreases an internal static lock counter by 1.
*
* If the Linker class is locked (counter > 0), linkContent() will be a no-op.
* Locking is necessary to enable nested <noautolinks> and <autolinks> tags in
* parseOnRender mode.
*/
public static function unlock() {
self::$locked -= 1;
}
}

// vim: ts=2:sw=2:noet:comments^=\:///
86 changes: 75 additions & 11 deletions tests/phpunit/ExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,87 @@
*/
class ExtensionTest extends LinkTitles\TestCase {

public function testParseOnEdit() {
/**
* @dataProvider provideParseOnEditData
*/
public function testParseOnEdit( $parseOnEdit, $input, $expectedOutput) {
$this->setMwGlobals( [
'wgLinkTitlesParseOnEdit' => true,
'wgLinkTitlesParseOnRender' => false
'wgLinkTitlesParseOnEdit' => $parseOnEdit,
'wgLinkTitlesParseOnRender' => !$parseOnEdit
] );
$pageId = $this->insertPage( 'test page', 'This page should link to the link target but not to test page' )['id'];
$pageId = $this->insertPage( 'test page', $input )['id'];
$page = WikiPage::newFromId( $pageId );
$this->assertSame( 'This page should link to the [[link target]] but not to test page', self::getPageText( $page ) );
$this->assertSame( $expectedOutput, self::getPageText( $page ) );
}

public function testDoNotParseOnEdit() {
public function provideParseOnEditData() {
return [
[
true, // parseOnEdit
'This page should link to the link target but not to test page',
'This page should link to the [[link target]] but not to test page'
],
[
false, // parseOnEdit
'This page should *not* link to the link target',
'This page should *not* link to the link target'
],
[
true, // parseOnEdit
'With __NOAUTOLINKS__, this page should not link to the link target',
'With __NOAUTOLINKS__, this page should not link to the link target'
],
];
}


/**
* @dataProvider provideParseOnRenderData
*/
public function testParseOnRender( $parseOnRender, $input, $expectedOutput) {
$this->setMwGlobals( [
'wgLinkTitlesParseOnEdit' => false,
'wgLinkTitlesParseOnRender' => false
'wgLinkTitlesParseOnEdit' => false, // do not modify the page as we create it
'wgLinkTitlesParseOnRender' => $parseOnRender
] );
$pageId = $this->insertPage( 'test page', 'This page should not link to the link target' )['id'];
$page = WikiPage::newFromId( $pageId );
$this->assertSame( 'This page should not link to the link target', self::getPageText( $page ) );
$title = $this->insertPage( 'test page', $input )['title'];
$page = new WikiPage( $title );
$output = $page->getParserOutput( new ParserOptions(), null, true );
$lines = explode( "\n", $output->getText() );
$this->assertRegexp( $expectedOutput, $lines[0] );
}

public function provideParseOnRenderData() {
return [
[
true, // parseOnRender
'This page should link to the link target but not to the test page',
'_This page should link to the <a href=[^>]+>link target</a> but not to the test page_'
],
[
false, // parseOnRender
'This page should not link to the link target',
'_This page should not link to the link target_'
],
[
true, // parseOnRender
'__NOAUTOLINKS__With noautolinks magic word, this page should not link to the link target',
'_With noautolinks magic word, this page should not link to the link target_'
],
[
true, // parseOnRender
'__NOAUTOLINKS__With noautolinks magic word, <autolinks>link target in autolinks tag</autolinks> should be linked',
'_With noautolinks magic word, <a href=[^>]+>link target</a> in autolinks tag should be linked_'
],
[
true, // parseOnRender
'<noautolinks>In a noautolinks tag, link target should NOT be linked</noautolinks>',
'_In a noautolinks tag, link target should NOT be linked_'
],
[
true, // parseOnRender
'<noautolinks>In a noautolinks tag, <autolinks>link target in autolinks tag</autolinks> should be linked</noautolinks>',
'_In a noautolinks tag, <a href=[^>]+>link target</a> in autolinks tag should be linked_'
],
];
}
}
6 changes: 6 additions & 0 deletions tests/phpunit/SplitterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ public static function provideSplitData() {
// "With parseHeadings = false,\n==an improperly formatted heading may be linked=\n",
// [ "With parseHeadings = false,\n==an improperly formatted heading may be linked=\n" ]
// ],
[
true, // skipTemplates
true, // parseHeadings
"Text <noautolinks>in noautolinks tag</noautolinks>should be excluded",
[ "Text ", "<noautolinks>in noautolinks tag</noautolinks>", "should be excluded" ]
],
];
}
}

0 comments on commit ebab186

Please sign in to comment.