diff --git a/extension.json b/extension.json index 3093b7f..a8aa738 100644 --- a/extension.json +++ b/extension.json @@ -37,7 +37,7 @@ "LinkTitles\\Linker": "includes/Linker.php", "LinkTitles\\Target": "includes/Target.php", "LinkTitles\\Targets": "includes/Targets.php", - "LinkTitles\\Delimiters": "includes/Delimiters.php", + "LinkTitles\\Splitter": "includes/Splitter.php", "LinkTitles\\Config": "includes/Config.php", "LinkTitles\\Special": "includes/Special.php", "LinkTitles\\TestCase": "tests/phpunit/TestCase.php" diff --git a/includes/Linker.php b/includes/Linker.php index 9e4806a..aae6570 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -72,7 +72,7 @@ class Linker { $limitReached = false; $newText = $text; - $delimiters = Delimiters::default( $this->config ); + $splitter = Splitter::default( $this->config ); $targets = Targets::default( $title, $this->config ); // Iterate through the target page titles @@ -89,7 +89,7 @@ class Linker { // Split the page content by non-linkable sections. // Credits to inhan @ StackOverflow for suggesting preg_split. // See http://stackoverflow.com/questions/10672286 - $arr = $delimiters->split( $newText ); + $arr = $splitter->split( $newText ); $count = 0; // Cache the target title text for the regex callbacks @@ -113,7 +113,7 @@ class Linker { if ( $this->config->smartMode && !$limitReached ) { if ( $count > 0 ) { // Split the text again because it was changed in the first pass. - $arr = $delimiters->split( $newText ); + $arr = $splitter->split( $newText ); } for ( $i = 0; $i < count( $arr ); $i+=2 ) { diff --git a/includes/Delimiters.php b/includes/Splitter.php similarity index 92% rename from includes/Delimiters.php rename to includes/Splitter.php index 0338325..ace409f 100644 --- a/includes/Delimiters.php +++ b/includes/Splitter.php @@ -1,6 +1,6 @@ ('bovender') * @@ -26,7 +26,7 @@ namespace LinkTitles; /** * Caches a regular expression that delimits text to be parsed. */ -class Delimiters { +class Splitter { /** * The splitting expression that separates text to be parsed from text that * must not be parsed. @@ -35,7 +35,7 @@ class Delimiters { public $splitter; /** - * The LinkTitles configuration for this Delimiters instance. + * The LinkTitles configuration for this Splitter instance. * @var Config $config */ public $config; @@ -43,12 +43,12 @@ class Delimiters { private static $instance; /** - * Gets the Delimiters singleton; may build one with the given config or the + * Gets the Splitter singleton; may build one with the given config or the * default config if none is given. * * If the instance was already created, it does not matter what Config this * method is called with. To re-create an instance with a different Config, - * call Delimiters::invalidate() first. + * call Splitter::invalidate() first. * * @param Config|null $config LinkTitles configuration. */ @@ -57,7 +57,7 @@ class Delimiters { if ( $config === null ) { $config = new Config(); } - self::$instance = new Delimiters( $config ); + self::$instance = new Splitter( $config ); } return self::$instance; } @@ -73,7 +73,7 @@ class Delimiters { protected function __construct( Config $config) { $this->config = $config; - $this->buildDelimiters(); + $this->buildSplitter(); } /** @@ -92,7 +92,7 @@ class Delimiters { * text that should be parsed from text that should not be * parsed (e.g. inside existing links etc.) */ - private function buildDelimiters() { + private function buildSplitter() { if ( $this->config->skipTemplates ) { // Use recursive regex to balance curly braces; diff --git a/tests/phpunit/DelimitersTest.php b/tests/phpunit/DelimitersTest.php deleted file mode 100644 index 23d4910..0000000 --- a/tests/phpunit/DelimitersTest.php +++ /dev/null @@ -1,21 +0,0 @@ -assertSame( $expectedOutput, $splitter->split( $input ) ); + } + + // TODO: Add more examples. + public static function provideSplitData() { + return [ + [ + 'this may be linked [[this may not be linked]]', + [ 'this may be linked ', '[[this may not be linked]]', '' ] + ], + [ + 'this may be linked this may not be linked', + [ 'this may be linked ', 'this may not be linked', '' ] + ], + [ + 'this may be linked {{mytemplate|param={{transcluded}}}}', + [ 'this may be linked ', '{{mytemplate|param={{transcluded}}}}', '' ] + ], + ]; + } +}