MediaWiki master
NaiveForeignTitleFactory.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Title;
22
23use Language;
24
30
32 private $contentLanguage;
33
37 public function __construct( Language $contentLanguage ) {
38 $this->contentLanguage = $contentLanguage;
39 }
40
59 public function createForeignTitle( $title, $ns = null ) {
60 $pieces = explode( ':', $title, 2 );
61
74 $isNamespacePartValid = $ns === null
75 ? $this->contentLanguage->getNsIndex( $pieces[0] ) !== false
76 : $ns != 0;
77
78 if ( count( $pieces ) === 2 && $isNamespacePartValid ) {
79 [ $namespaceName, $pageName ] = $pieces;
80 } else {
81 $namespaceName = '';
82 $pageName = $title;
83 }
84
85 return new ForeignTitle( $ns, $namespaceName, $pageName );
86 }
87}
88
90class_alias( NaiveForeignTitleFactory::class, 'NaiveForeignTitleFactory' );
Base class for language-specific code.
Definition Language.php:63
A simple, immutable structure to hold the title of a page on a foreign MediaWiki installation.
A parser that translates page titles on a foreign wiki into ForeignTitle objects, with no knowledge o...
createForeignTitle( $title, $ns=null)
Create a ForeignTitle object.
A parser that translates page titles into ForeignTitle objects.