Add a parameter to deactivate OpenGraph meta tags

This can conflict with other extensions like SemanticMetaTags or
OpenGraphMeta.

Bug: T217307
Change-Id: Idfb006583edda8545b95609f047b2f301a9caa33
This commit is contained in:
Sébastien Beyou 2022-07-28 17:27:15 +02:00
parent 8adbbf5b8c
commit 3ab47c1061
3 changed files with 21 additions and 0 deletions

View file

@ -86,6 +86,11 @@
}
]
},
"PageImagesOpenGraph": {
"description": "Enable the OpenGraph meta tags",
"public": true,
"value": true
},
"PageImagesDenylistExpiry": {
"value": 900
},

View file

@ -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' );

View file

@ -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() )