From db42a48c079d9721bd0540e8823d5682e9ac1770 Mon Sep 17 00:00:00 2001 From: paladox Date: Wed, 29 Nov 2023 13:34:10 -0500 Subject: [PATCH 1/6] Fix "Call to undefined method WikiPage::factory()" --- includes/Target.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/includes/Target.php b/includes/Target.php index 8fa99b5..a6bfe45 100644 --- a/includes/Target.php +++ b/includes/Target.php @@ -24,6 +24,8 @@ */ namespace LinkTitles; +use MediaWiki\MediaWikiServices; + /** * Represents a page that is a potential link target. */ @@ -189,7 +191,13 @@ class Target { */ public function getContent() { if ( $this->content === null ) { - $this->content = \WikiPage::factory( $this->title )->getContent(); + // MW 1.36+ + if ( method_exists( MediaWikiServices::class, 'getWikiPageFactory' ) ) { + $wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory(); + $this->content = $wikiPageFactory->newFromTitle( $this->title )->getContent(); + } else { + $this->content = WikiPage::factory( $this->title ); + } }; return $this->content; } From 503fdfbbbf03921c0b8f4bfd9bb6eeb49979eb31 Mon Sep 17 00:00:00 2001 From: paladox Date: Wed, 29 Nov 2023 13:34:42 -0500 Subject: [PATCH 2/6] Update Target.php --- includes/Target.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Target.php b/includes/Target.php index a6bfe45..46d4a35 100644 --- a/includes/Target.php +++ b/includes/Target.php @@ -196,7 +196,7 @@ class Target { $wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory(); $this->content = $wikiPageFactory->newFromTitle( $this->title )->getContent(); } else { - $this->content = WikiPage::factory( $this->title ); + $this->content = \WikiPage::factory( $this->title ); } }; return $this->content; From 733b0e967de7094a94b9b657513e9e705e91060a Mon Sep 17 00:00:00 2001 From: paladox Date: Wed, 29 Nov 2023 13:35:51 -0500 Subject: [PATCH 3/6] Update Source.php --- includes/Source.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/includes/Source.php b/includes/Source.php index ee8d1c4..e999098 100644 --- a/includes/Source.php +++ b/includes/Source.php @@ -238,7 +238,13 @@ class Source { if ( $this->page === null ) { // Access the property directly to avoid an infinite loop. if ( $this->title != null) { - $this->page = \WikiPage::factory( $this->title ); + // MW 1.36+ + if ( method_exists( MediaWikiServices::class, 'getWikiPageFactory' ) ) { + $wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory(); + $this->page = $wikiPageFactory->newFromTitle( $this->title ); + } else { + $this->page = \WikiPage::factory( $this->title ); + } } else { throw new Exception( 'Unable to create Page for this Source because Title is null.' ); } From ffaf50cdd9d8c27e1730ee776029bb517a8861df Mon Sep 17 00:00:00 2001 From: paladox Date: Wed, 29 Nov 2023 13:39:06 -0500 Subject: [PATCH 4/6] Update Target.php --- includes/Target.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Target.php b/includes/Target.php index 46d4a35..1943317 100644 --- a/includes/Target.php +++ b/includes/Target.php @@ -196,7 +196,7 @@ class Target { $wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory(); $this->content = $wikiPageFactory->newFromTitle( $this->title )->getContent(); } else { - $this->content = \WikiPage::factory( $this->title ); + $this->content = \WikiPage::factory( $this->title )->getContent(); } }; return $this->content; From 2a1e3a05e9a517733a7f495bb8da7c5e62d0f9de Mon Sep 17 00:00:00 2001 From: paladox Date: Fri, 22 Dec 2023 17:02:54 +0000 Subject: [PATCH 5/6] Update Source.php --- includes/Source.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/includes/Source.php b/includes/Source.php index e999098..a119cae 100644 --- a/includes/Source.php +++ b/includes/Source.php @@ -238,17 +238,25 @@ class Source { if ( $this->page === null ) { // Access the property directly to avoid an infinite loop. if ( $this->title != null) { - // MW 1.36+ - if ( method_exists( MediaWikiServices::class, 'getWikiPageFactory' ) ) { - $wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory(); - $this->page = $wikiPageFactory->newFromTitle( $this->title ); - } else { - $this->page = \WikiPage::factory( $this->title ); - } + $this->page = static::getPage(); } else { throw new Exception( 'Unable to create Page for this Source because Title is null.' ); } } return $this->page; } + + /** + * Obtain a WikiPage object. + * Workaround for MediaWiki 1.36+ which deprecated Wikipage::factory. + * @return WikiPage object + */ + private static function getPage() { + if ( method_exists( MediaWikiServices::class, 'getWikiPageFactory' ) ) { + $wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory(); + return $wikiPageFactory->newFromTitle( $this->title ); + } + + return \WikiPage::factory( $this->title ); + } } From 4fc414be8bfa2e99c1298736450ed7abff3bc04b Mon Sep 17 00:00:00 2001 From: paladox Date: Fri, 22 Dec 2023 17:04:58 +0000 Subject: [PATCH 6/6] Update Target.php --- includes/Target.php | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/includes/Target.php b/includes/Target.php index 1943317..f9afcd5 100644 --- a/includes/Target.php +++ b/includes/Target.php @@ -191,13 +191,7 @@ class Target { */ public function getContent() { if ( $this->content === null ) { - // MW 1.36+ - if ( method_exists( MediaWikiServices::class, 'getWikiPageFactory' ) ) { - $wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory(); - $this->content = $wikiPageFactory->newFromTitle( $this->title )->getContent(); - } else { - $this->content = \WikiPage::factory( $this->title )->getContent(); - } + $this->content = static::getPage(); }; return $this->content; } @@ -250,4 +244,19 @@ class Target { return $redirectTitle && $redirectTitle->equals( $source->getTitle() ); } } + + /** + * Obtain a page's content. + * Workaround for MediaWiki 1.36+ which deprecated Wikipage::factory. + * @return Content content object of the page + */ + private static function getPage() { + if ( method_exists( MediaWikiServices::class, 'getWikiPageFactory' ) ) { + $wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory(); + $page = $wikiPageFactory->newFromTitle( $this->title ); + } else { + $page = \WikiPage::factory( $this->title ); + } + return $page->getContent(); + } }