Pmiazga has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/346927 )
Change subject: Log infobxes being wrapped in containers ...................................................................... Log infobxes being wrapped in containers Lets log all page titles and revisions where infoboxes are wrapped in any containers (the infobox parent node is not a lead section body) Feature can be disabled by changing `MFLogWrappedInfoboxes` to false Bug: T149884 Change-Id: If8ff2eb8d46bb3a53997038c5a17037591af4520 --- M extension.json M includes/MobileFormatter.php M tests/phpunit/MobileFormatterTest.php 3 files changed, 49 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend refs/changes/27/346927/1 diff --git a/extension.json b/extension.json index f2ceecd..212b435 100644 --- a/extension.json +++ b/extension.json @@ -1847,7 +1847,8 @@ ], "MFEnableManifest": true, "MFManifestThemeColor": "#252525", - "MFManifestBackgroundColor": "#FFFFFF" + "MFManifestBackgroundColor": "#FFFFFF", + "MFLogWrappedInfoboxes": false }, "manifest_version": 1 } diff --git a/includes/MobileFormatter.php b/includes/MobileFormatter.php index 3d9d171..a88eaab 100644 --- a/includes/MobileFormatter.php +++ b/includes/MobileFormatter.php @@ -245,8 +245,23 @@ $leadSectionBody->insertBefore( $firstP, $infoboxAndParagraphs->item( 0 ) ); } } + /** + * @see https://phabricator.wikimedia.org/T149884 + * @todo remove after research is done + */ + if ( MobileContext::singleton()->getMFConfig()->get( 'MFLogWrappedInfoboxes' ) ) { + $this->logInfoboxesWrappedInContainers( $leadSectionBody, $xPath ); + } } + private function logInfoboxesWrappedInContainers( $leadSectionBody, DOMXPath $xPath ) { + $infoboxes = $xPath->query( './/table[contains(@class,"infobox")]', $leadSectionBody ); + if ( $infoboxes->length > 0 ) { + \MediaWiki\Logger\LoggerFactory::getInstance( 'MobileFrontend' )->debug( + "Found infobox wrapped with container on {$this->title} (rev:{$this->revId})" + ); + } + } /** * Replaces any references links with a link to Special:MobileCite * diff --git a/tests/phpunit/MobileFormatterTest.php b/tests/phpunit/MobileFormatterTest.php index d0bb5db..8fb7eaf 100644 --- a/tests/phpunit/MobileFormatterTest.php +++ b/tests/phpunit/MobileFormatterTest.php @@ -817,4 +817,36 @@ $formatter = new MobileFormatter( $input, Title::newFromText( 'Special:Foo' ) ); $formatter->filterContent( false, true, false ); } + + /** + * @see https://phabricator.wikimedia.org/T149884 + * @covers MobileFormatter::filterContent() + */ + public function testLoggingOfInfoboxesBeingWrappedInContainers() { + $this->setMwGlobals( [ + 'wgMFLogWrappedInfoboxes' => true + ] ); + + $input = + '<div><table class="' . self::INFOBOX_CLASSNAME . '"><tr><td>infobox</td></tr></table></div>' . + '<p>paragraph 1</p>'; + $title = 'Special:T149884'; + + $formatter = new MobileFormatter( MobileFormatter::wrapHTML( $input ), + Title::newFromText( $title ) ); + $formatter->enableExpandableSections(); + + $loggerMock = $this->getMock( \Psr\Log\LoggerInterface::class ); + $loggerMock->expects( $this->once() ) + ->method( 'debug' ) + ->will( $this->returnCallback( function( $message ) use ( $title ) { + // Debug message contains Page title + $this->assertContains( $title, $message ); + // and contains revision id which is 0 by default + $this->assertContains( '0', $message ); + } ) ); + + $this->setLogger( 'MobileFrontend', $loggerMock ); + $formatter->filterContent( false, false, false, true ); + } } -- To view, visit https://gerrit.wikimedia.org/r/346927 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If8ff2eb8d46bb3a53997038c5a17037591af4520 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MobileFrontend Gerrit-Branch: master Gerrit-Owner: Pmiazga <pmia...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits