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