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