MediaWiki master
NaiveForeignTitleFactory.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Title;
22
24
30
31 private Language $contentLanguage;
32
33 public function __construct( Language $contentLanguage ) {
34 $this->contentLanguage = $contentLanguage;
35 }
36
55 public function createForeignTitle( $title, $ns = null ) {
56 $pieces = explode( ':', $title, 2 );
57
70 $isNamespacePartValid = $ns === null
71 ? $this->contentLanguage->getNsIndex( $pieces[0] ) !== false
72 : $ns != 0;
73
74 if ( count( $pieces ) === 2 && $isNamespacePartValid ) {
75 [ $namespaceName, $pageName ] = $pieces;
76 } else {
77 $namespaceName = '';
78 $pageName = $title;
79 }
80
81 return new ForeignTitle( $ns, $namespaceName, $pageName );
82 }
83}
84
86class_alias( NaiveForeignTitleFactory::class, 'NaiveForeignTitleFactory' );
Base class for language-specific code.
Definition Language.php:80
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.