22 private NamespaceInfo $namespaceInfo;
24 private Title $targetPage;
25 private TitleFactory $titleFactory;
26 private ForeignTitle $sourcePage;
28 public function __construct( NamespaceInfo $namespaceInfo, TitleFactory $titleFactory, Title $targetPage ) {
29 $this->namespaceInfo = $namespaceInfo;
30 $this->targetPage = $targetPage;
31 $this->titleFactory = $titleFactory;
34 public function createTitleFromForeignTitle( ForeignTitle $foreignTitle ): Title {
35 if ( !$foreignTitle->isNamespaceIdKnown() ) {
36 throw new InvalidArgumentException(
37 "Unable to determine namespace for foreign title {$foreignTitle}"
41 $foreignTitleNamespaceId = $foreignTitle->getNamespaceId();
42 $foreignTitleText = $foreignTitle->getText();
44 if ( !$this->namespaceInfo->exists( $foreignTitleNamespaceId ) ) {
45 throw new InvalidArgumentException(
46 "The foreign title $foreignTitle has a namespace that does not exist in the current wiki.\n" .
47 __CLASS__ .
" does not support this functionality yet."
51 $titleFromForeignTitle = $this->titleFactory->makeTitle( $foreignTitleNamespaceId, $foreignTitleText );
53 $this->sourcePage ??= $foreignTitle;
54 $this->pageTitleRenamer ??=
new PageTitleRenamer( $titleFromForeignTitle, $this->targetPage );
56 return $this->pageTitleRenamer->getNewTitle( $titleFromForeignTitle );