MediaWiki master
NaiveForeignTitleFactory.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Title;
8
10
16
17 private Language $contentLanguage;
18
19 public function __construct( Language $contentLanguage ) {
20 $this->contentLanguage = $contentLanguage;
21 }
22
41 public function createForeignTitle( $title, $ns = null ) {
42 $pieces = explode( ':', $title, 2 );
43
56 $isNamespacePartValid = $ns === null
57 ? $this->contentLanguage->getNsIndex( $pieces[0] ) !== false
58 : $ns != 0;
59
60 if ( count( $pieces ) === 2 && $isNamespacePartValid ) {
61 [ $namespaceName, $pageName ] = $pieces;
62 } else {
63 $namespaceName = '';
64 $pageName = $title;
65 }
66
67 return new ForeignTitle( $ns, $namespaceName, $pageName );
68 }
69}
70
72class_alias( NaiveForeignTitleFactory::class, 'NaiveForeignTitleFactory' );
Base class for language-specific code.
Definition Language.php:65
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.