diff --git "a/include/class-mw\\CompleteTitle.php" "b/include/class-mw\\CompleteTitle.php" index 77b8af9..5d59ead 100644 --- "a/include/class-mw\\CompleteTitle.php" +++ "b/include/class-mw\\CompleteTitle.php" @@ -1,135 +1,135 @@ . # MediaWiki namespace mw; /** * A MediaWiki complete title (with namespace) */ class CompleteTitle { /** * Which MediaWiki site * * @var object */ private $wiki; /** * @var object */ private $ns; /** * @var object */ private $title; /** * Constructor * * @param $wiki object * @param $ns object * @param $title object */ public function __construct( $wiki, $ns, $title ) { $this->wiki = $wiki; $this->ns = $ns; $this->title = $title; } /** * Get the namespace object * * @return object */ public function getNs() { return $this->ns; } /** * Get the title object * * @return object */ public function getTitle() { return $this->title; } /** * Get the regex able to match this complete title * * @param $args array * ns-group-name: Name of the capturing group for the namespace * title-group-name: Name of the capturing group for the title * @return string */ public function getRegex( $args = [] ) { // default options $args = array_replace( [ 'ns-group-name' => null, 'title-group-name' => null, ], $args ); // single regexes $ns = $this->getNs()->getRegex(); $title = $this->title->getRegex(); // eventually group $ns = \regex\Generic::groupNamed( $ns, $args[ 'ns-group-name' ] ); $title = \regex\Generic::groupNamed( $title, $args[ 'title-group-name' ] ); return $ns . '[ _]*' . $title; } /** * Static constructor parsing a string * * @param $wiki object * @param $s string e.g. ' Mediawiki: test ' * @return self */ public static function createParsingTitle( $wiki, $s ) { // split namespace and title $ns_raw = ''; $tokens = explode( ':', $s, 2 ); if( count( $tokens ) === 2 ) { $ns_raw = $tokens[ 0 ]; $title_raw = $tokens[ 1 ]; } else { // no namespace? that's the main namespace! $ns_raw = ''; $title_raw = $tokens[ 0 ]; } // validate namespace $ns = $wiki->findNamespace( $ns_raw ); if( ! $ns ) { // that was the main namespace with a ':' in the title $ns = $wiki->getNamespace( 0 ); - $title_raw = "$ns_raw:$title"; + $title_raw = "$ns_raw:$title_raw"; } $title = new Title( $title_raw, $wiki ); return new self( $wiki, $ns, $title ); } }