diff --git "a/include/class-mw\\TitlePart.php" "b/include/class-mw\\TitlePart.php" index faa851a..36fa118 100644 --- "a/include/class-mw\\TitlePart.php" +++ "b/include/class-mw\\TitlePart.php" @@ -1,73 +1,81 @@ . # MediaWiki namespace mw; /** * A string part of a wikilink, a namespace, etc. */ class TitlePart { private $s; public function __construct( $s ) { $this->set( $s ); } public static function factory( $s ) { return new static( $s ); } public function get() { return $this->s; } public function set( $s ) { $this->s = static::normalize( $s ); return $this; } public function isEmpty() { return '' === $this->get(); } public function getRegex( $delimiter = null ) { return self::regex( $this->get(), $delimiter ); } public static function normalize( $s ) { $s = trim( $s ); $s = self::underscore2space( $s ); return $s; } public static function underscore2space( $s ) { return str_replace('_', ' ', $s); } - public static function regex( $s, $delimiter ) { + /** + * Create a regex matching this title + * + * Spaces will be converted into optional tabs/spaces. + * + * @param $s string + * @param $delimiter string + * @return string + */ + public static function regex( $s, $delimiter = null ) { $s = preg_quote( $s, $delimiter ); // These are all valids // [[Main page]] - // [[Main page]] - // [[Main______page]] - // [[Main_ _ _ page]] - return str_replace( ' ', '[ _]*', $s ); + // [[Main _ page]] + // [[_ _ Main_ _ _ page _ _ ]] + return str_replace( ' ', '[ _]+', $s ); } }