Merge branch 'release-5.0.8'

This commit is contained in:
Daniel Kraus
2019-03-12 11:33:47 +01:00
8 changed files with 134 additions and 123 deletions

4
.gitmodules vendored
View File

@ -1,4 +0,0 @@
[submodule "gh-pages"]
path = gh-pages
url = git@github.com:bovender/LinkTitles.git
branch = gh-pages

View File

@ -452,6 +452,7 @@ master branch if you want to install the extension for your own Wiki.
- @tetsuya-zama, bug fix - @tetsuya-zama, bug fix
- @yoshida3669, namespace-related bug fixes - @yoshida3669, namespace-related bug fixes
- Caleb Mingle (@dentafrice), bug fix - Caleb Mingle (@dentafrice), bug fix
- @paladox, bug fixes
### Testing ### Testing

Submodule gh-pages deleted from 48501118d1

View File

@ -146,7 +146,7 @@ class Special extends \SpecialPage {
$start += 1; $start += 1;
// Check if the time limit is exceeded // Check if the time limit is exceeded
if ( microtime( true ) - $startTime > $config->specialPageReloadAfter ) if ( microtime( true ) - $startTime > $this->config->specialPageReloadAfter )
{ {
break; break;
} }

View File

@ -29,13 +29,13 @@
*/ */
class ConfigTest extends LinkTitles\TestCase { class ConfigTest extends LinkTitles\TestCase {
public function testParseOnEdit() { public function testParseOnEdit() {
$this->setMwGlobals( [ $this->setMwGlobals( [
'wgLinkTitlesParseOnEdit' => true, 'wgLinkTitlesParseOnEdit' => true,
'wgLinkTitlesParseOnRender' => false 'wgLinkTitlesParseOnRender' => false
] ); ] );
$config = new LinkTitles\Config(); $config = new LinkTitles\Config();
global $wgLinkTitlesParseOnEdit; global $wgLinkTitlesParseOnEdit;
$this->assertSame( $config->parseOnEdit, $wgLinkTitlesParseOnEdit ); $this->assertSame( $config->parseOnEdit, $wgLinkTitlesParseOnEdit );
} }
} }

View File

@ -26,87 +26,87 @@
*/ */
class ExtensionTest extends LinkTitles\TestCase { class ExtensionTest extends LinkTitles\TestCase {
/** /**
* @dataProvider provideParseOnEditData * @dataProvider provideParseOnEditData
*/ */
public function testParseOnEdit( $parseOnEdit, $input, $expectedOutput) { public function testParseOnEdit( $parseOnEdit, $input, $expectedOutput) {
$this->setMwGlobals( [ $this->setMwGlobals( [
'wgLinkTitlesParseOnEdit' => $parseOnEdit, 'wgLinkTitlesParseOnEdit' => $parseOnEdit,
'wgLinkTitlesParseOnRender' => !$parseOnEdit 'wgLinkTitlesParseOnRender' => !$parseOnEdit
] ); ] );
$pageId = $this->insertPage( 'test page', $input )['id']; $pageId = $this->insertPage( 'test page', $input )['id'];
$page = WikiPage::newFromId( $pageId ); $page = WikiPage::newFromId( $pageId );
$this->assertSame( $expectedOutput, self::getPageText( $page ) ); $this->assertSame( $expectedOutput, self::getPageText( $page ) );
} }
public function provideParseOnEditData() { public function provideParseOnEditData() {
return [ return [
[ [
true, // parseOnEdit 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',
'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 false, // parseOnEdit
'This page should *not* link to the link target', 'This page should *not* link to the link target',
'This page should *not* link to the link target' 'This page should *not* link to the link target'
], ],
[ [
true, // parseOnEdit true, // parseOnEdit
'With __NOAUTOLINKS__, this page should not link to the link target', 'With __NOAUTOLINKS__, this page should not link to the link target',
'With __NOAUTOLINKS__, this page should not link to the link target' 'With __NOAUTOLINKS__, this page should not link to the link target'
], ],
]; ];
} }
/** /**
* @dataProvider provideParseOnRenderData * @dataProvider provideParseOnRenderData
*/ */
public function testParseOnRender( $parseOnRender, $input, $expectedOutput) { public function testParseOnRender( $parseOnRender, $input, $expectedOutput) {
$this->setMwGlobals( [ $this->setMwGlobals( [
'wgLinkTitlesParseOnEdit' => false, // do not modify the page as we create it 'wgLinkTitlesParseOnEdit' => false, // do not modify the page as we create it
'wgLinkTitlesParseOnRender' => $parseOnRender 'wgLinkTitlesParseOnRender' => $parseOnRender
] ); ] );
$title = $this->insertPage( 'test page', $input )['title']; $title = $this->insertPage( 'test page', $input )['title'];
$page = new WikiPage( $title ); $page = new WikiPage( $title );
$output = $page->getParserOutput( new ParserOptions(), null, true ); $output = $page->getParserOutput( new ParserOptions(), null, true );
$lines = explode( "\n", $output->getText() ); $lines = explode( "\n", $output->getText() );
$this->assertRegexp( $expectedOutput, $lines[0] ); $this->assertRegexp( $expectedOutput, $lines[0] );
} }
public function provideParseOnRenderData() { public function provideParseOnRenderData() {
return [ return [
[ [
true, // parseOnRender true, // parseOnRender
'This page should link to the link target but not to the test page', '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_' '_This page should link to the <a href=[^>]+>link target</a> but not to the test page_'
], ],
[ [
false, // parseOnRender false, // parseOnRender
'This page should not link to the link target', 'This page should not link to the link target',
'_This page should not link to the link target_' '_This page should not link to the link target_'
], ],
[ [
true, // parseOnRender true, // parseOnRender
'__NOAUTOLINKS__With noautolinks magic word, this page should not link to the link target', '__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_' '_With noautolinks magic word, this page should not link to the link target_'
], ],
[ [
true, // parseOnRender true, // parseOnRender
'__NOAUTOLINKS__With noautolinks magic word, <autolinks>link target in autolinks tag</autolinks> should be linked', '__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_' '_With noautolinks magic word, <a href=[^>]+>link target</a> in autolinks tag should be linked_'
], ],
[ [
true, // parseOnRender true, // parseOnRender
'<noautolinks>In a noautolinks tag, link target should NOT be linked</noautolinks>', '<noautolinks>In a noautolinks tag, link target should NOT be linked</noautolinks>',
'_In a noautolinks tag, link target should NOT be linked_' '_In a noautolinks tag, link target should NOT be linked_'
], ],
[ [
true, // parseOnRender true, // parseOnRender
'<noautolinks>In a noautolinks tag, <autolinks>link target in autolinks tag</autolinks> should be linked</noautolinks>', '<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_' '_In a noautolinks tag, <a href=[^>]+>link target</a> in autolinks tag should be linked_'
], ],
]; ];
} }
} }

View File

@ -41,11 +41,11 @@ class LinkTitlesLinkerTest extends LinkTitles\TestCase {
parent::setUp(); // call last to have the Targets object invalidated after inserting the page parent::setUp(); // call last to have the Targets object invalidated after inserting the page
} }
public function addDBData() { public function addDBData() {
$this->title = $this->insertPage( 'source page', 'This page is the test page' )['title']; $this->title = $this->insertPage( 'source page', 'This page is the test page' )['title'];
$this->insertPage( 'link target', 'This page serves as a link target' ); $this->insertPage( 'link target', 'This page serves as a link target' );
parent::addDBDataOnce(); // call parent after adding page to have targets invalidated parent::addDBDataOnce(); // call parent after adding page to have targets invalidated
} }
/** /**
* @dataProvider provideTestTitleWithNumberData * @dataProvider provideTestTitleWithNumberData
@ -54,8 +54,8 @@ class LinkTitlesLinkerTest extends LinkTitles\TestCase {
$config = new LinkTitles\Config(); $config = new LinkTitles\Config();
$config->wordStartOnly = true; $config->wordStartOnly = true;
$config->wordEndOnly = true; $config->wordEndOnly = true;
$this->insertPage( 'numbered-1', 'This page serves as a link target with a numbered title' ); $this->insertPage( 'numbered-1', 'This page serves as a link target with a numbered title' );
$this->insertPage( 'numbered-101', 'This page serves as a link target with a numbered title' ); $this->insertPage( 'numbered-101', 'This page serves as a link target with a numbered title' );
parent::addDBDataOnce(); // call parent after adding page to have targets invalidated parent::addDBDataOnce(); // call parent after adding page to have targets invalidated
$source = LinkTitles\Source::createFromTitleAndText( $this->title, $input, $config ); $source = LinkTitles\Source::createFromTitleAndText( $this->title, $input, $config );
$linker = new LinkTitles\Linker( $config ); $linker = new LinkTitles\Linker( $config );
@ -85,6 +85,21 @@ class LinkTitlesLinkerTest extends LinkTitles\TestCase {
]; ];
} }
/**
* Test issue #39, https://github.com/bovender/LinkTitles/issues/39
*/
public function testNoautolinks() {
$config = new LinkTitles\Config();
$config->firstOnly = false;
LinkTitles\Splitter::invalidate();
$input = 'This is a text with <noautolinks><nowiki>link target</nowiki></noautolinks>';
$source = LinkTitles\Source::createFromTitleAndText( $this->title, $input, $config );
$linker = new LinkTitles\Linker( $config );
$result = $linker->linkContent( $source );
if ( !$result ) { $result = $input; }
$this->assertSame( $input, $result );
}
/** /**
* @dataProvider provideLinkContentTemplatesData * @dataProvider provideLinkContentTemplatesData
*/ */
@ -294,7 +309,7 @@ class LinkTitlesLinkerTest extends LinkTitles\TestCase {
$config = new LinkTitles\Config(); $config = new LinkTitles\Config();
$config->targetNamespaces = $namespaces; $config->targetNamespaces = $namespaces;
$ns = 4000; $ns = 4000;
$nsText = 'customnamespace'; $nsText = 'customnamespace';
$this->mergeMwGlobalArrayValue( 'wgExtraNamespaces', [ $ns => $nsText ] ); $this->mergeMwGlobalArrayValue( 'wgExtraNamespaces', [ $ns => $nsText ] );
@ -316,16 +331,16 @@ class LinkTitlesLinkerTest extends LinkTitles\TestCase {
public function provideLinkContentNamespacesData() { public function provideLinkContentNamespacesData() {
return [ return [
[ [
[], // namespaces [], // namespaces
'With targetNamespaces = [], page in custom namespace should not be linked', 'With targetNamespaces = [], page in custom namespace should not be linked',
'With targetNamespaces = [], page in custom namespace should not be linked' 'With targetNamespaces = [], page in custom namespace should not be linked'
], ],
[ [
[ 4000 ], // namespaces [ 4000 ], // namespaces
'With targetNamespaces = [ 4000 ], page in custom namespace should be linked', 'With targetNamespaces = [ 4000 ], page in custom namespace should be linked',
'With targetNamespaces = [ 4000 ], page [[customnamespace:In custom namespace|in custom namespace]] should be linked' 'With targetNamespaces = [ 4000 ], page [[customnamespace:In custom namespace|in custom namespace]] should be linked'
], ],
]; ];
} }
} }

View File

@ -22,22 +22,22 @@
namespace LinkTitles; namespace LinkTitles;
abstract class TestCase extends \MediaWikiTestCase { abstract class TestCase extends \MediaWikiTestCase {
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
} }
protected function tearDown() { protected function tearDown() {
parent::tearDown(); parent::tearDown();
} }
public function addDBDataOnce() { public function addDBDataOnce() {
parent::addDBDataOnce(); parent::addDBDataOnce();
$this->insertPage( 'link target', 'This page serves as a link target' ); $this->insertPage( 'link target', 'This page serves as a link target' );
Targets::invalidate(); // force re-querying the pages table Targets::invalidate(); // force re-querying the pages table
} }
protected function getPageText( \WikiPage $page ) { protected function getPageText( \WikiPage $page ) {
$content = $page->getContent(); $content = $page->getContent();
return $page->getContentHandler()->serializeContent( $content ); return $page->getContentHandler()->serializeContent( $content );
} }
} }