MediaWiki  master
NaiveImportTitleFactory.php
Go to the documentation of this file.
1 <?php
35 
37  private $namespaceInfo;
38 
40  private $titleFactory;
41 
47  public function __construct(
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 }
NaiveImportTitleFactory
A class to convert page titles on a foreign wiki (ForeignTitle objects) into page titles on the local...
Definition: NaiveImportTitleFactory.php:32
NaiveImportTitleFactory\__construct
__construct(Language $contentLanguage, NamespaceInfo $namespaceInfo, TitleFactory $titleFactory)
Definition: NaiveImportTitleFactory.php:47
ForeignTitle\getText
getText()
Definition: ForeignTitle.php:84
ForeignTitle\getFullText
getFullText()
Definition: ForeignTitle.php:89
NaiveImportTitleFactory\$contentLanguage
Language $contentLanguage
Definition: NaiveImportTitleFactory.php:34
ImportTitleFactory
Represents an object that can convert page titles on a foreign wiki (ForeignTitle objects) into page ...
Definition: ImportTitleFactory.php:25
ForeignTitle\getNamespaceName
getNamespaceName()
Definition: ForeignTitle.php:79
ForeignTitle\getNamespaceId
getNamespaceId()
Definition: ForeignTitle.php:70
NaiveImportTitleFactory\$titleFactory
TitleFactory $titleFactory
Definition: NaiveImportTitleFactory.php:40
NaiveImportTitleFactory\$namespaceInfo
NamespaceInfo $namespaceInfo
Definition: NaiveImportTitleFactory.php:37
NaiveImportTitleFactory\createTitleFromForeignTitle
createTitleFromForeignTitle(ForeignTitle $foreignTitle)
Determines which local title best corresponds to the given foreign title.
Definition: NaiveImportTitleFactory.php:65
TitleFactory
Creates Title objects.
Definition: TitleFactory.php:35
NamespaceInfo
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...
Definition: NamespaceInfo.php:35
ForeignTitle
A simple, immutable structure to hold the title of a page on a foreign MediaWiki installation.
Definition: ForeignTitle.php:28
ForeignTitle\isNamespaceIdKnown
isNamespaceIdKnown()
Do we know the namespace ID of the page on the foreign wiki?
Definition: ForeignTitle.php:61
Language
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
Definition: Language.php:42