MediaWiki REL1_40
NaiveImportTitleFactory.php
Go to the documentation of this file.
1<?php
23
37 private $contentLanguage;
38
40 private $namespaceInfo;
41
43 private $titleFactory;
44
50 public function __construct(
51 Language $contentLanguage,
52 NamespaceInfo $namespaceInfo,
53 TitleFactory $titleFactory
54 ) {
55 $this->contentLanguage = $contentLanguage;
56 $this->namespaceInfo = $namespaceInfo;
57 $this->titleFactory = $titleFactory;
58 }
59
68 public function createTitleFromForeignTitle( ForeignTitle $foreignTitle ) {
69 if ( $foreignTitle->isNamespaceIdKnown() ) {
70 $foreignNs = $foreignTitle->getNamespaceId();
71
72 // For built-in namespaces (0 <= ID < 100), we try to find a local NS with
73 // the same namespace ID
74 if (
75 $foreignNs < 100 &&
76 $this->namespaceInfo->exists( $foreignNs )
77 ) {
78 return $this->titleFactory->makeTitleSafe( $foreignNs, $foreignTitle->getText() );
79 }
80 }
81
82 // Do we have a local namespace by the same name as the foreign
83 // namespace?
84 $targetNs = $this->contentLanguage->getNsIndex( $foreignTitle->getNamespaceName() );
85 if ( $targetNs !== false ) {
86 return $this->titleFactory->makeTitleSafe( $targetNs, $foreignTitle->getText() );
87 }
88
89 // Otherwise, just fall back to main namespace
90 return $this->titleFactory->makeTitleSafe( 0, $foreignTitle->getFullText() );
91 }
92}
A simple, immutable structure to hold the title of a page on a foreign MediaWiki installation.
isNamespaceIdKnown()
Do we know the namespace ID of the page on the foreign wiki?
Base class for language-specific code.
Definition Language.php:56
Creates Title objects.
Represents a title within MediaWiki.
Definition Title.php:82
A class to convert page titles on a foreign wiki (ForeignTitle objects) into page titles on the local...
__construct(Language $contentLanguage, NamespaceInfo $namespaceInfo, TitleFactory $titleFactory)
createTitleFromForeignTitle(ForeignTitle $foreignTitle)
Determines which local title best corresponds to the given foreign title.
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...
Represents an object that can convert page titles on a foreign wiki (ForeignTitle objects) into page ...