diff --git a/extension.json b/extension.json index 7e153ad..9248460 100644 --- a/extension.json +++ b/extension.json @@ -86,6 +86,11 @@ } ] }, + "PageImagesOpenGraph": { + "description": "Enable the OpenGraph meta tags", + "public": true, + "value": true + }, "PageImagesDenylistExpiry": { "value": 900 }, diff --git a/includes/PageImages.php b/includes/PageImages.php index 25cc7a3..3777c91 100644 --- a/includes/PageImages.php +++ b/includes/PageImages.php @@ -257,6 +257,9 @@ class PageImages implements * @param Skin $skin Skin object used to generate the page. Ignored */ public function onBeforePageDisplay( $out, $skin ): void { + if ( !$out->getConfig()->get( 'PageImagesOpenGraph' ) ) { + return; + } $imageFile = self::getPageImage( $out->getContext()->getTitle() ); if ( !$imageFile ) { $fallback = $out->getConfig()->get( 'PageImagesOpenGraphFallbackImage' ); diff --git a/tests/phpunit/PageImagesTest.php b/tests/phpunit/PageImagesTest.php index a1a4ceb..c921cba 100644 --- a/tests/phpunit/PageImagesTest.php +++ b/tests/phpunit/PageImagesTest.php @@ -51,8 +51,20 @@ class PageImagesTest extends MediaWikiIntegrationTestCase { ); } + public function testGivenDeactivedOpenGraphOnBeforePageDisplayDoesNotAddMeta() { + $outputPage = $this->mockOutputPage( [ + 'PageImagesOpenGraph' => false, + ] ); + $outputPage->expects( $this->never() ) + ->method( 'addMeta' ); + + $skinTemplate = new SkinTemplate(); + ( new PageImages() )->onBeforePageDisplay( $outputPage, $skinTemplate ); + } + public function testGivenNonExistingPageOnBeforePageDisplayDoesNotAddMeta() { $outputPage = $this->mockOutputPage( [ + 'PageImagesOpenGraph' => true, 'PageImagesOpenGraphFallbackImage' => false ] ); $outputPage->expects( $this->never() ) @@ -76,6 +88,7 @@ class PageImagesTest extends MediaWikiIntegrationTestCase { public function testGivenFallbackImageOnBeforePageDisplayAddMeta( $expected, $fallback ) { $this->setMwGlobals( [ 'wgCanonicalServer' => 'http://wiki.test' ] ); $outputPage = $this->mockOutputPage( [ + 'PageImagesOpenGraph' => true, 'PageImagesOpenGraphFallbackImage' => $fallback ] ); $outputPage->expects( $this->once() )