MediaWiki master
SubpageImportTitleFactory.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Title;
8
9use InvalidArgumentException;
10
17 private TitleFactory $titleFactory;
18 private Title $rootPage;
19
25 public function __construct(
26 NamespaceInfo $namespaceInfo,
27 TitleFactory $titleFactory,
28 Title $rootPage
29 ) {
30 if ( !$namespaceInfo->hasSubpages( $rootPage->getNamespace() ) ) {
31 throw new InvalidArgumentException( "The root page you specified, $rootPage, is in a " .
32 "namespace where subpages are not allowed" );
33 }
34 $this->titleFactory = $titleFactory;
35 $this->rootPage = $rootPage;
36 }
37
46 public function createTitleFromForeignTitle( ForeignTitle $foreignTitle ) {
47 return $this->titleFactory->newFromText(
48 $this->rootPage->getPrefixedDBkey() . '/' . $foreignTitle->getFullText()
49 );
50 }
51}
52
54class_alias( SubpageImportTitleFactory::class, 'SubpageImportTitleFactory' );
A simple, immutable structure to hold the title of a page on a foreign MediaWiki installation.
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...
hasSubpages( $index)
Does the namespace allow subpages? Note that this refers to structured handling of subpages,...
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.
__construct(NamespaceInfo $namespaceInfo, TitleFactory $titleFactory, Title $rootPage)
Creates Title objects.
Represents a title within MediaWiki.
Definition Title.php:69
getNamespace()
Get the namespace index, i.e.
Definition Title.php:1037
Represents an object that can convert page titles on a foreign wiki (ForeignTitle objects) into page ...