MediaWiki REL1_39
NaiveImportTitleFactory.php
Go to the documentation of this file.
1<?php
34 private $contentLanguage;
35
37 private $namespaceInfo;
38
40 private $titleFactory;
41
47 public function __construct(
48 Language $contentLanguage,
49 NamespaceInfo $namespaceInfo,
50 TitleFactory $titleFactory
51 ) {
52 $this->contentLanguage = $contentLanguage;
53 $this->namespaceInfo = $namespaceInfo;
54 $this->titleFactory = $titleFactory;
55 }
56
65 public function createTitleFromForeignTitle( ForeignTitle $foreignTitle ) {
66 if ( $foreignTitle->isNamespaceIdKnown() ) {
67 $foreignNs = $foreignTitle->getNamespaceId();
68
69 // For built-in namespaces (0 <= ID < 100), we try to find a local NS with
70 // the same namespace ID
71 if (
72 $foreignNs < 100 &&
73 $this->namespaceInfo->exists( $foreignNs )
74 ) {
75 return $this->titleFactory->makeTitleSafe( $foreignNs, $foreignTitle->getText() );
76 }
77 }
78
79 // Do we have a local namespace by the same name as the foreign
80 // namespace?
81 $targetNs = $this->contentLanguage->getNsIndex( $foreignTitle->getNamespaceName() );
82 if ( $targetNs !== false ) {
83 return $this->titleFactory->makeTitleSafe( $targetNs, $foreignTitle->getText() );
84 }
85
86 // Otherwise, just fall back to main namespace
87 return $this->titleFactory->makeTitleSafe( 0, $foreignTitle->getFullText() );
88 }
89}
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:53
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...
Creates Title objects.
Represents an object that can convert page titles on a foreign wiki (ForeignTitle objects) into page ...