jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/323989 )
Change subject: Restrict page images to lead section ...................................................................... Restrict page images to lead section When $wgPageImagesLeadSectionOnly is true restrict the scoring of page images to images in the lead section. This results in an additional parse of the lead section of the content, but this should only happen once after an edit has occurred and is deferred. If false all images will be considered as candidates for the page image choice. Note that the choice between modes is per site not by request. This is intentional to avoid having to store 4 different properties respecting license and article position. As a result when enabling or disabling this switch on existing setups, there will be a transitional period where pages previously parsed will show pageimages as calculated by the previous value of this config variable. Bug: T87336 Change-Id: I09bdae82515f6e93f5606553259f10b3a10e9eaa --- M extension.json M includes/LinksUpdateHookHandler.php 2 files changed, 36 insertions(+), 1 deletion(-) Approvals: jenkins-bot: Verified Phuedx: Looks good to me, approved diff --git a/extension.json b/extension.json index 4e74d66..a909e2b 100644 --- a/extension.json +++ b/extension.json @@ -79,6 +79,11 @@ 0 ] }, + "PageImagesLeadSectionOnly": { + "@doc": "Temporary feature flag - Whether page images should be restricted to those in section id 0.", + "@fixme": "Please remove a month after it has defaulted to true on the cluster (T152115)", + "value": false + }, "PageImagesUseGalleries": { "value": false } diff --git a/includes/LinksUpdateHookHandler.php b/includes/LinksUpdateHookHandler.php index 5d73f7a..da6de5f 100644 --- a/includes/LinksUpdateHookHandler.php +++ b/includes/LinksUpdateHookHandler.php @@ -33,10 +33,40 @@ } /** + * Returns a list of page image candidates for consideration + * for scoring algorithm. + * @param LinksUpdate $linksUpdate + * @return array $image Associative array describing an image + */ + public function getPageImageCandidates( LinksUpdate $linksUpdate ) { + global $wgPageImagesLeadSectionOnly; + $po = false; + + if ( $wgPageImagesLeadSectionOnly ) { + $rev = $linksUpdate->getRevision(); + if ( $rev ) { + $content = $rev->getContent(); + if ( $content ) { + $section = $content->getSection( 0 ); + + // Certain content types e.g. AbstractContent return null if sections do not apply + if ( $section ) { + $po = $section->getParserOutput( $linksUpdate->getTitle() ); + } + } + } + } else { + $po = $linksUpdate->getParserOutput(); + } + + return $po ? $po->getExtensionData( 'pageImages' ) : []; + } + + /** * @param LinksUpdate $linksUpdate */ public function doLinksUpdate( LinksUpdate $linksUpdate ) { - $images = $linksUpdate->getParserOutput()->getExtensionData( 'pageImages' ); + $images = $this->getPageImageCandidates( $linksUpdate ); if ( $images === null ) { return; -- To view, visit https://gerrit.wikimedia.org/r/323989 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I09bdae82515f6e93f5606553259f10b3a10e9eaa Gerrit-PatchSet: 8 Gerrit-Project: mediawiki/extensions/PageImages Gerrit-Branch: master Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org> Gerrit-Reviewer: Bmansurov <bmansu...@wikimedia.org> Gerrit-Reviewer: Gergő Tisza <gti...@wikimedia.org> Gerrit-Reviewer: Jdlrobson <jrob...@wikimedia.org> Gerrit-Reviewer: MaxSem <maxsem.w...@gmail.com> Gerrit-Reviewer: Phuedx <samsm...@wikimedia.org> Gerrit-Reviewer: Pmiazga <pmia...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits