33 private $foreignNamespacesFlipped;
40 private function normalizeNamespaceName( $name ) {
41 return strtolower( str_replace(
' ',
'_', $name ) );
54 $this->foreignNamespacesFlipped = [];
56 $newKey = self::normalizeNamespaceName( $name );
57 $this->foreignNamespacesFlipped[$newKey] = $id;
90 $pieces = explode(
':',
$title, 2 );
91 $key = self::normalizeNamespaceName( $pieces[0] );
95 $isNamespacePartValid = isset( $this->foreignNamespacesFlipped[$key] );
97 if ( count( $pieces ) === 2 && $isNamespacePartValid ) {
98 list( $namespaceName, $pageName ) = $pieces;
99 $ns = $this->foreignNamespacesFlipped[$key];
106 return new ForeignTitle( $ns, $namespaceName, $pageName );
117 $pieces = explode(
':',
$title, 2 );
120 $titleIncludesNamespace = ( $ns !=
'0' && count( $pieces ) === 2 );
122 if ( isset( $this->foreignNamespaces[$ns] ) ) {
123 $namespaceName = $this->foreignNamespaces[$ns];
130 $namespaceName = $titleIncludesNamespace ? $pieces[0] :
"Ns$ns";
135 if ( $titleIncludesNamespace ) {
136 $pageName = $pieces[1];
141 return new ForeignTitle( $ns, $namespaceName, $pageName );
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, using information a...
parseTitleWithNs( $title, $ns)
Helper function to parse the title when the namespace value is known.
parseTitleNoNs( $title)
Helper function to parse the title when the namespace ID is not specified.
createForeignTitle( $title, $ns=null)
Create a ForeignTitle object.
__construct( $foreignNamespaces)
A parser that translates page titles into ForeignTitle objects.