MediaWiki
1.34.0
NaiveImportTitleFactory.php
Go to the documentation of this file.
1
<?php
21
use
MediaWiki\MediaWikiServices
;
22
34
class
NaiveImportTitleFactory
implements
ImportTitleFactory
{
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
}
NaiveImportTitleFactory
A class to convert page titles on a foreign wiki (ForeignTitle objects) into page titles on the local...
Definition:
NaiveImportTitleFactory.php:34
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition:
MediaWikiServices.php:117
ForeignTitle\getText
getText()
Definition:
ForeignTitle.php:84
ForeignTitle\getFullText
getFullText()
Definition:
ForeignTitle.php:89
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
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition:
Title.php:613
NaiveImportTitleFactory\createTitleFromForeignTitle
createTitleFromForeignTitle(ForeignTitle $foreignTitle)
Determines which local title best corresponds to the given foreign title.
Definition:
NaiveImportTitleFactory.php:43
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
includes
title
NaiveImportTitleFactory.php
Generated on Thu Dec 19 2019 14:55:03 for MediaWiki by
1.8.16