MediaWiki fundraising/REL1_35
NaiveImportTitleFactory.php
Go to the documentation of this file.
1<?php
22
43 public function createTitleFromForeignTitle( ForeignTitle $foreignTitle ) {
44 if ( $foreignTitle->isNamespaceIdKnown() ) {
45 $foreignNs = $foreignTitle->getNamespaceId();
46
47 // For built-in namespaces (0 <= ID < 100), we try to find a local NS with
48 // the same namespace ID
49 if (
50 $foreignNs < 100 &&
51 MediaWikiServices::getInstance()->getNamespaceInfo()->exists( $foreignNs )
52 ) {
53 return Title::makeTitleSafe( $foreignNs, $foreignTitle->getText() );
54 }
55 }
56
57 // Do we have a local namespace by the same name as the foreign
58 // namespace?
59 $targetNs = MediaWikiServices::getInstance()->getContentLanguage()->getNsIndex(
60 $foreignTitle->getNamespaceName() );
61 if ( $targetNs !== false ) {
62 return Title::makeTitleSafe( $targetNs, $foreignTitle->getText() );
63 }
64
65 // Otherwise, just fall back to main namespace
66 return Title::makeTitleSafe( 0, $foreignTitle->getFullText() );
67 }
68}
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?
MediaWikiServices is the service locator for the application scope of MediaWiki.
A class to convert page titles on a foreign wiki (ForeignTitle objects) into page titles on the local...
createTitleFromForeignTitle(ForeignTitle $foreignTitle)
Determines which local title best corresponds to the given foreign title.
Represents an object that can convert page titles on a foreign wiki (ForeignTitle objects) into page ...