35 private $foreignNamespacesFlipped;
42 private function normalizeNamespaceName( $name ) {
43 return strtolower( str_replace(
' ',
'_', $name ) );
56 $this->foreignNamespacesFlipped = [];
58 $newKey = self::normalizeNamespaceName( $name );
59 $this->foreignNamespacesFlipped[$newKey] = $id;
92 $pieces = explode(
':', $title, 2 );
93 $key = self::normalizeNamespaceName( $pieces[0] );
97 $isNamespacePartValid = isset( $this->foreignNamespacesFlipped[$key] );
99 if ( count( $pieces ) === 2 && $isNamespacePartValid ) {
100 [ $namespaceName, $pageName ] = $pieces;
101 $ns = $this->foreignNamespacesFlipped[$key];
108 return new ForeignTitle( $ns, $namespaceName, $pageName );
119 $pieces = explode(
':', $title, 2 );
122 $titleIncludesNamespace = ( $ns !=
'0' && count( $pieces ) === 2 );
124 if ( isset( $this->foreignNamespaces[$ns] ) ) {
125 $namespaceName = $this->foreignNamespaces[$ns];
132 $namespaceName = $titleIncludesNamespace ? $pieces[0] :
"Ns$ns";
137 if ( $titleIncludesNamespace ) {
138 $pageName = $pieces[1];
143 return new ForeignTitle( $ns, $namespaceName, $pageName );
148class_alias( NamespaceAwareForeignTitleFactory::class,
'NamespaceAwareForeignTitleFactory' );