diff --git a/includes/Targets.php b/includes/Targets.php index 29a11d9..305fade 100644 --- a/includes/Targets.php +++ b/includes/Targets.php @@ -90,9 +90,15 @@ class Targets { private function fetch() { ( $this->config->preferShortTitles ) ? $sortOrder = 'ASC' : $sortOrder = 'DESC'; + // Build a blacklist of pages that are not supposed to be link // targets. This includes the current page. - $blackList = str_replace( ' ', '_', '("' . implode( '","',$this->config->blackList ) . '")' ); + if ( $this->config->blackList ) { + $blackList = 'page_title NOT IN ' . + str_replace( ' ', '_', '("' . implode( '","', str_replace( '"', '\"', $this->config->blackList ) ) . '")' ); + } else { + $blackList = null; + } // Build our weight list. Make sure current namespace is first element $nameSpaces = array_diff( $this->config->nameSpaces, [ $this->nameSpace ] ); @@ -117,10 +123,12 @@ class Targets { $this->queryResult = $dbr->select( 'page', array( 'page_title', 'page_namespace' , "weight" => $weightSelect), - array( - 'page_namespace IN ' . $nameSpacesClause, - 'CHAR_LENGTH(page_title) >= ' . $this->config->minimumTitleLength, - 'page_title NOT IN ' . $blackList, + array_filter( + array( + 'page_namespace IN ' . $nameSpacesClause, + 'CHAR_LENGTH(page_title) >= ' . $this->config->minimumTitleLength, + $blackList, + ) ), __METHOD__, array( 'ORDER BY' => 'weight ASC, CHAR_LENGTH(page_title) ' . $sortOrder ) @@ -129,10 +137,12 @@ class Targets { $this->queryResult = $dbr->select( 'page', array( 'page_title', 'page_namespace' , "weight" => $weightSelect ), - array( - 'page_namespace IN ' . $nameSpacesClause, - 'LENGTH(page_title) >= ' . $this->config->minimumTitleLength, - 'page_title NOT IN ' . $blackList, + array_filter( + array( + 'page_namespace IN ' . $nameSpacesClause, + 'LENGTH(page_title) >= ' . $this->config->minimumTitleLength, + $blackList, + ) ), __METHOD__, array( 'ORDER BY' => 'weight ASC, LENGTH(page_title) ' . $sortOrder ) diff --git a/tests/phpunit/LinkerTest.php b/tests/phpunit/LinkerTest.php index c53333c..bf02764 100644 --- a/tests/phpunit/LinkerTest.php +++ b/tests/phpunit/LinkerTest.php @@ -31,6 +31,7 @@ * (Ideally the test classes should be namespaced, but when you do that, they * will no longer be automatically discovered.) * + * @group bovender * @group Database */ class LinkTitlesLinkerTest extends LinkTitles\TestCase { @@ -49,12 +50,13 @@ class LinkTitlesLinkerTest extends LinkTitles\TestCase { /** - * @dataProvider provideLinkContentData + * @dataProvider provideLinkContentTemplatesData */ public function testLinkContentTemplates( $skipTemplates, $input, $expectedOutput ) { $config = new LinkTitles\Config(); $config->firstOnly = false; $config->skipTemplates = $skipTemplates; + LinkTitles\Splitter::invalidate(); $linker = new LinkTitles\Linker( $config ); $this->assertSame( $expectedOutput, $linker->linkContent( $this->title, $input )); } @@ -145,8 +147,8 @@ class LinkTitlesLinkerTest extends LinkTitles\TestCase { [ false, // wgCapitalLinks true, // smartMode - 'With smart mode on and $wgCapitalLinks = false, this page should link to Link Target', - 'With smart mode on and $wgCapitalLinks = false, this page should link to [[Link target|Link Target]]' + 'With smart mode on and $wgCapitalLinks = false, this page should link to Link target', + 'With smart mode on and $wgCapitalLinks = false, this page should link to [[Link target]]' ], [ false, // wgCapitalLinks @@ -194,7 +196,8 @@ class LinkTitlesLinkerTest extends LinkTitles\TestCase { public function testLinkContentBlackList() { $config = new LinkTitles\Config(); - $config->blackList = [ 'Foo', 'link target', 'Bar' ]; + $config->blackList = [ 'Foo', 'Link target', 'Bar' ]; + LinkTitles\Targets::invalidate(); $linker = new LinkTitles\Linker( $config ); $text = 'If the link target is blacklisted, it should not be linked'; $this->assertSame( $text, $linker->linkContent( $this->title, $text ) ); @@ -220,12 +223,12 @@ class LinkTitlesLinkerTest extends LinkTitles\TestCase { [ [], // nameSpaces 'With nameSpaces = [], page in custom namespace should not be linked', - 'With firstOnly = [], page in custom namespace should not be linked' + 'With nameSpaces = [], page in custom namespace should not be linked' ], [ [ 3000 ], // nameSpaces - 'With nameSpaces = [], page in custom namespace should be linked', - 'With firstOnly = [], page [[in custom namespace]] should be linked' + 'With nameSpaces = 3000, page in custom namespace should be linked', + 'With nameSpaces = 3000, page [[custom_namespace:in custom namespace]] should be linked' ], ]; }