jenkins-bot has submitted this change and it was merged. Change subject: Only load mw.PopUpMediaTransform on pages that plausibly need it ......................................................................
Only load mw.PopUpMediaTransform on pages that plausibly need it Rather than load mw.PopUpMediaTransform unconditionally, rely on the parser hook to cover most cases, and use TimedMediaHandlerHooks::pageOutputHook to cover the rest: namely, special pages that are liable to include timed media. Bug: 55550 Change-Id: I7a6da6c62ceae1dae2feb05b57b2df91b482ad8b --- M TimedMediaHandler.hooks.php 1 file changed, 45 insertions(+), 4 deletions(-) Approvals: Ori.livneh: Looks good to me, approved jenkins-bot: Verified diff --git a/TimedMediaHandler.hooks.php b/TimedMediaHandler.hooks.php index 47a7f6e..7777064 100644 --- a/TimedMediaHandler.hooks.php +++ b/TimedMediaHandler.hooks.php @@ -104,9 +104,12 @@ // Add parser hook $wgParserOutputHooks['TimedMediaHandler'] = array( 'TimedMediaHandler', 'outputHook' ); - // We should probably move this script output to a parser function but not working correctly in - // dynamic contexts ( for example in special upload, when there is an "existing file" warning. ) + // Use a BeforePageDisplay hook to load the styles in pages that pull in media dynamically. + // (Special:Upload, for example, when there is an "existing file" warning.) $wgHooks['BeforePageDisplay'][] = 'TimedMediaHandlerHooks::pageOutputHook'; + + // Make sure modules are loaded on image pages that don't have a media file in the wikitext. + $wgHooks['ImageOpenShowImageInlineBefore'][] = 'TimedMediaHandlerHooks::onImageOpenShowImageInlineBefore'; // Exclude transcoded assets from normal thumbnail purging // ( a maintenance script could handle transcode asset purging) @@ -146,6 +149,19 @@ $wgHooks[ 'NewRevisionFromEditComplete' ][] = 'TimedMediaHandlerHooks::onNewRevisionFromEditComplete'; $wgHooks['LoadExtensionSchemaUpdates'][] = 'TimedMediaHandlerHooks::checkSchemaUpdates'; + return true; + } + + /** + * @param $imagePage ImagePage + * @param $wgOut OutputPage + * @return bool + */ + public static function onImageOpenShowImageInlineBefore( $imagePage, $out ) { + $handler = $imagePage->getDisplayedFile()->getHandler(); + if ( $handler !== false && $handler instanceof TimedMediaHandler ) { + TimedMediaHandler::outputHook( $out, null, null ); + } return true; } @@ -342,13 +358,38 @@ } /** + * Add JavaScript and CSS for special pages that may include timed media + * but which will not fire the parser hook. + * + * FIXME: There ought to be a better interface for determining whether the + * page is liable to contain timed media. + * * @param $out OutputPage * @param $sk * @return bool */ static function pageOutputHook( &$out, &$sk ){ - $out->addModules( 'mw.PopUpMediaTransform' ); - $out->addModuleStyles( 'mw.PopUpMediaTransform' ); + $title = $out->getTitle(); + $namespace = $title->getNamespace(); + $addModules = false; + + if ( $namespace === NS_CATEGORY || $namespace === NS_TIMEDTEXT ) { + $addModules = true; + } + + if ( $title->isSpecialPage() ) { + list( $name, /* subpage */ ) = SpecialPageFactory::resolveAlias( $title->getDBkey() ); + if ( stripos( $name, 'file' ) !== false || stripos( $name, 'image' ) !== false + || $name === 'Search' || $name === 'GlobalUsage' ) { + $addModules = true; + } + } + + if ( $addModules ) { + $out->addModules( 'mw.PopUpMediaTransform' ); + $out->addModuleStyles( 'mw.PopUpMediaTransform' ); + } + return true; } -- To view, visit https://gerrit.wikimedia.org/r/108649 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I7a6da6c62ceae1dae2feb05b57b2df91b482ad8b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/TimedMediaHandler Gerrit-Branch: wmf/1.23wmf10 Gerrit-Owner: Ori.livneh <o...@wikimedia.org> Gerrit-Reviewer: Ori.livneh <o...@wikimedia.org> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits