TheDJ has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/272422

Change subject: Improve dynamic resource module registration
......................................................................

Improve dynamic resource module registration

Instead of messing with the variable in the register hook, instead,
let's use ResourceLoaderRegisterModules to dynamically register the
modules depending on the config var $wgTmhWebPlayer.

Bug: T87981
Change-Id: I7d751562684e18475885a5acb59963b2f4a5e1d5
---
M TimedMediaHandler.hooks.php
M TimedMediaHandler.php
2 files changed, 149 insertions(+), 128 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TimedMediaHandler 
refs/changes/22/272422/1

diff --git a/TimedMediaHandler.hooks.php b/TimedMediaHandler.hooks.php
index c07ff86..c26db8a 100644
--- a/TimedMediaHandler.hooks.php
+++ b/TimedMediaHandler.hooks.php
@@ -28,6 +28,150 @@
                return true;
        }
 
+       // At some point these should be registered in extension.json
+       // But for now we register them dynamically, because they are config 
dependent,
+       // while we have two players
+       public static function resourceLoaderRegisterModules( &$resourceLoader 
) {
+               global $wgTmhWebPlayer;
+
+               $baseExtensionResource = array(
+                       'localBasePath' => __DIR__,
+                       'remoteExtPath' => 'TimedMediaHandler',
+               );
+
+               if ( $wgTmhWebPlayer === 'mwembed' ) {
+                       $resourceModules = array(
+                               'mw.PopUpMediaTransform' => 
$baseExtensionResource + array(
+                                               'scripts' => 
'resources/mw.PopUpThumbVideo.js',
+                                               'dependencies' => array(
+                                                       'mw.MwEmbedSupport',
+                                                       'mediawiki.Title',
+                                                       
'mw.PopUpMediaTransform.styles'
+                                               ),
+                                               'position' => 'top',
+                                       ),
+                               'mw.PopUpMediaTransform.styles' => 
$baseExtensionResource + array(
+                                               'position' => 'top',
+                                               'styles' => 
'resources/PopUpThumbVideo.css',
+                                       ),
+                               'mw.TMHGalleryHook.js' => 
$baseExtensionResource + array(
+                                               'scripts' => 
'resources/mw.TMHGalleryHook.js',
+                                               // position top needed as it 
needs to load before mediawiki.page.gallery
+                                               'position' => 'top',
+                                       ),
+                               'embedPlayerIframeStyle'=> 
$baseExtensionResource + array(
+                                               'styles' => 
'resources/embedPlayerIframe.css',
+                                               'position' => 'bottom',
+                                       ),
+                               'ext.tmh.embedPlayerIframe' => 
$baseExtensionResource + array(
+                                               'scripts' => 
'resources/ext.tmh.embedPlayerIframe.js',
+                                               'dependencies' => array(
+                                                       'jquery.embedPlayer',
+                                                       'mw.MwEmbedSupport',
+                                               ),
+                                       ),
+                               "mw.MediaWikiPlayerSupport" =>  
$baseExtensionResource + array(
+                                               'scripts' => 
'resources/mw.MediaWikiPlayerSupport.js',
+                                               'dependencies'=> array(
+                                                       'mw.Api',
+                                                       'mw.MwEmbedSupport',
+                                               ),
+                                       ),
+                               // adds support MediaWikiPlayerSupport player 
bindings
+                               "mw.MediaWikiPlayer.loader" => 
$baseExtensionResource + array(
+                                               'scripts' => 
'resources/mw.MediaWikiPlayer.loader.js',
+                                               'dependencies' => array(
+                                                       "mw.EmbedPlayer.loader",
+                                                       "mw.TimedText.loader",
+                                               ),
+                                               'position' => 'top',
+                                       ),
+                       );
+                       // Add OgvJs-related modules for Safari/IE/Edge Ogg 
playback
+                       $resourceModules += array(
+                               'ext.tmh.OgvJsSupport' => 
$baseExtensionResource + array(
+                                               'scripts' => array(
+                                                       
'MwEmbedModules/EmbedPlayer/binPlayers/ogv.js/ogv-support.js',
+                                                       
'resources/ext.tmh.OgvJsSupport.js',
+                                               ),
+                                               'targets' => array( 'mobile', 
'desktop' ),
+                                       ),
+                               'ext.tmh.OgvJs' => $baseExtensionResource + 
array(
+                                               'scripts' => array(
+                                                       
'MwEmbedModules/EmbedPlayer/binPlayers/ogv.js/ogv.js',
+                                               ),
+                                               'dependencies' => 
'ext.tmh.OgvJsSupport',
+                                               'targets' => array( 'mobile', 
'desktop' ),
+                                       ),
+                       );
+               } elseif ( $wgTmhWebPlayer === 'videojs' ) {
+                       $resourceModules = array(
+                               'ext.tmh.video-js' => $baseExtensionResource + 
array(
+                                               'scripts' => 
'resources/videojs/video.js',
+                                               'styles' => 
'resources/videojs/video-js.css',
+                                               'targets' => array( 'mobile', 
'desktop' ),
+                                               'languageScripts' => array(
+                                                       'ar' => 
'resources/videojs/lang/ar.js',
+                                                       'ba' => 
'resources/videojs/lang/ba.js',
+                                                       'bg' => 
'resources/videojs/lang/bg.js',
+                                                       'ca' => 
'resources/videojs/lang/ca.js',
+                                                       'cs' => 
'resources/videojs/lang/cs.js',
+                                                       'da' => 
'resources/videojs/lang/da.js',
+                                                       'de' => 
'resources/videojs/lang/de.js',
+                                                       'es' => 
'resources/videojs/lang/es.js',
+                                                       'fi' => 
'resources/videojs/lang/fi.js',
+                                                       'fr' => 
'resources/videojs/lang/fr.js',
+                                                       'hr' => 
'resources/videojs/lang/hr.js',
+                                                       'hu' => 
'resources/videojs/lang/hu.js',
+                                                       'it' => 
'resources/videojs/lang/it.js',
+                                                       'ja' => 
'resources/videojs/lang/ja.js',
+                                                       'ko' => 
'resources/videojs/lang/ko.js',
+                                                       'nl' => 
'resources/videojs/lang/nl.js',
+                                                       'pt-BR' => 
'resources/videojs/lang/pt-BR.js',
+                                                       'ru' => 
'resources/videojs/lang/ru.js',
+                                                       'sr' => 
'resources/videojs/lang/sr.js',
+                                                       'sv' => 
'resources/videojs/lang/sv.js',
+                                                       'tr' => 
'resources/videojs/lang/tr.js',
+                                                       'uk' => 
'resources/videojs/lang/uk.js',
+                                                       'vi' => 
'resources/videojs/lang/vi.js',
+                                                       'zh-CN' => 
'resources/videojs/lang/zh-CN.js',
+                                                       'zh-TW' => 
'resources/videojs/lang/zh-TW.js',
+                                               ),
+                                       ),
+                               // 'ext.tmh.videojs-offset' => 
$baseExtensionResource + array(
+                               // 'scripts' => 
'resources/videojs-offset/videojs-offset.js',
+                               // 'targets' => array( 'mobile', 'desktop' ),
+                               // 'dependencies' => array(
+                               // 'ext.tmh.video-js',
+                               // ),
+                               // ),
+                               'ext.tmh.videojs-resolution-switcher' => 
$baseExtensionResource + array(
+                                               'scripts' => 
'resources/videojs-resolution-switcher/videojs-resolution-switcher.js',
+                                               'styles' => 
'resources/videojs-resolution-switcher/videojs-resolution-switcher.css',
+                                               'targets' => array( 'mobile', 
'desktop' ),
+                                               'dependencies' => array(
+                                                       'ext.tmh.video-js',
+                                               ),
+                                       ),
+                               'ext.tmh.player' => $baseExtensionResource + 
array(
+                                               'scripts' => 
'resources/ext.tmh.player.js',
+                                               'targets' => array( 'mobile', 
'desktop' ),
+                                               'dependencies' => array(
+                                                       'ext.tmh.video-js',
+                                                       
'ext.tmh.videojs-resolution-switcher',
+                                                       // 
'ext.tmh.videojs-offset',
+                                               ),
+                                       ),
+                               'ext.tmh.player.styles' => 
$baseExtensionResource + array(
+                                               'styles' => 
'resources/ext.tmh.player.styles.less',
+                                       )
+                       );
+               }
+
+               $resourceLoader->register( $resourceModules );
+               return true;
+       }
+
        // Register TimedMediaHandler Hooks
        public static function register() {
                global $wgHooks, $wgJobClasses, 
$wgJobTypesExcludedFromDefaultQueue, $wgMediaHandlers,
@@ -115,134 +259,7 @@
                        )
                );
 
-               if ( $wgTmhWebPlayer === 'mwembed' ) {
-                       $wgResourceModules += array(
-                               'mw.PopUpMediaTransform' => 
$baseExtensionResource + array(
-                                       'scripts' => 
'resources/mw.PopUpThumbVideo.js',
-                                       'dependencies' => array(
-                                               'mw.MwEmbedSupport',
-                                               'mediawiki.Title',
-                                               'mw.PopUpMediaTransform.styles'
-                                       ),
-                                       'position' => 'top',
-                               ),
-                               'mw.PopUpMediaTransform.styles' => 
$baseExtensionResource + array(
-                                       'position' => 'top',
-                                       'styles' => 
'resources/PopUpThumbVideo.css',
-                               ),
-                               'mw.TMHGalleryHook.js' => 
$baseExtensionResource + array(
-                                       'scripts' => 
'resources/mw.TMHGalleryHook.js',
-                                       // position top needed as it needs to 
load before mediawiki.page.gallery
-                                       'position' => 'top',
-                               ),
-                               'embedPlayerIframeStyle'=> 
$baseExtensionResource + array(
-                                       'styles' => 
'resources/embedPlayerIframe.css',
-                                       'position' => 'bottom',
-                               ),
-                               'ext.tmh.embedPlayerIframe' => 
$baseExtensionResource + array(
-                                       'scripts' => 
'resources/ext.tmh.embedPlayerIframe.js',
-                                       'dependencies' => array(
-                                               'jquery.embedPlayer',
-                                               'mw.MwEmbedSupport',
-                                       ),
-                               ),
-                               "mw.MediaWikiPlayerSupport" =>  
$baseExtensionResource + array(
-                                       'scripts' => 
'resources/mw.MediaWikiPlayerSupport.js',
-                                       'dependencies'=> array(
-                                               'mw.Api',
-                                               'mw.MwEmbedSupport',
-                                       ),
-                               ),
-                               // adds support MediaWikiPlayerSupport player 
bindings
-                               "mw.MediaWikiPlayer.loader" => 
$baseExtensionResource + array(
-                                       'scripts' => 
'resources/mw.MediaWikiPlayer.loader.js',
-                                       'dependencies' => array(
-                                               "mw.EmbedPlayer.loader",
-                                               "mw.TimedText.loader",
-                                       ),
-                                       'position' => 'top',
-                               ),
-                       );
-                       // Add OgvJs-related modules for Safari/IE/Edge Ogg 
playback
-                       $wgResourceModules += array(
-                               'ext.tmh.OgvJsSupport' => 
$baseExtensionResource + array(
-                                       'scripts' => array(
-                                               
'MwEmbedModules/EmbedPlayer/binPlayers/ogv.js/ogv-support.js',
-                                               
'resources/ext.tmh.OgvJsSupport.js',
-                                       ),
-                                       'targets' => array( 'mobile', 'desktop' 
),
-                               ),
-                               'ext.tmh.OgvJs' => $baseExtensionResource + 
array(
-                                       'scripts' => array(
-                                               
'MwEmbedModules/EmbedPlayer/binPlayers/ogv.js/ogv.js',
-                                       ),
-                                       'dependencies' => 
'ext.tmh.OgvJsSupport',
-                                       'targets' => array( 'mobile', 'desktop' 
),
-                               ),
-                       );
-               } elseif ( $wgTmhWebPlayer === 'videojs' ) {
-                       $wgResourceModules += array(
-                               'ext.tmh.video-js' => $baseExtensionResource + 
array(
-                                       'scripts' => 
'resources/videojs/video.js',
-                                       'styles' => 
'resources/videojs/video-js.css',
-                                       'targets' => array( 'mobile', 'desktop' 
),
-                                       'languageScripts' => array(
-                                               'ar' => 
'resources/videojs/lang/ar.js',
-                                               'ba' => 
'resources/videojs/lang/ba.js',
-                                               'bg' => 
'resources/videojs/lang/bg.js',
-                                               'ca' => 
'resources/videojs/lang/ca.js',
-                                               'cs' => 
'resources/videojs/lang/cs.js',
-                                               'da' => 
'resources/videojs/lang/da.js',
-                                               'de' => 
'resources/videojs/lang/de.js',
-                                               'es' => 
'resources/videojs/lang/es.js',
-                                               'fi' => 
'resources/videojs/lang/fi.js',
-                                               'fr' => 
'resources/videojs/lang/fr.js',
-                                               'hr' => 
'resources/videojs/lang/hr.js',
-                                               'hu' => 
'resources/videojs/lang/hu.js',
-                                               'it' => 
'resources/videojs/lang/it.js',
-                                               'ja' => 
'resources/videojs/lang/ja.js',
-                                               'ko' => 
'resources/videojs/lang/ko.js',
-                                               'nl' => 
'resources/videojs/lang/nl.js',
-                                               'pt-BR' => 
'resources/videojs/lang/pt-BR.js',
-                                               'ru' => 
'resources/videojs/lang/ru.js',
-                                               'sr' => 
'resources/videojs/lang/sr.js',
-                                               'sv' => 
'resources/videojs/lang/sv.js',
-                                               'tr' => 
'resources/videojs/lang/tr.js',
-                                               'uk' => 
'resources/videojs/lang/uk.js',
-                                               'vi' => 
'resources/videojs/lang/vi.js',
-                                               'zh-CN' => 
'resources/videojs/lang/zh-CN.js',
-                                               'zh-TW' => 
'resources/videojs/lang/zh-TW.js',
-                                       ),
-                               ),
-                               // 'ext.tmh.videojs-offset' => 
$baseExtensionResource + array(
-                                       // 'scripts' => 
'resources/videojs-offset/videojs-offset.js',
-                                       // 'targets' => array( 'mobile', 
'desktop' ),
-                                       // 'dependencies' => array(
-                                               // 'ext.tmh.video-js',
-                                       // ),
-                               // ),
-                               'ext.tmh.videojs-resolution-switcher' => 
$baseExtensionResource + array(
-                                       'scripts' => 
'resources/videojs-resolution-switcher/videojs-resolution-switcher.js',
-                                       'styles' => 
'resources/videojs-resolution-switcher/videojs-resolution-switcher.css',
-                                       'targets' => array( 'mobile', 'desktop' 
),
-                                       'dependencies' => array(
-                                               'ext.tmh.video-js',
-                                       ),
-                                ),
-                               'ext.tmh.player' => $baseExtensionResource + 
array(
-                                       'scripts' => 
'resources/ext.tmh.player.js',
-                                       'targets' => array( 'mobile', 'desktop' 
),
-                                       'dependencies' => array(
-                                               'ext.tmh.video-js',
-                                               
'ext.tmh.videojs-resolution-switcher',
-                                               // 'ext.tmh.videojs-offset',
-                                       ),
-                               ),
-                               'ext.tmh.player.styles' => 
$baseExtensionResource + array(
-                                       'styles' => 
'resources/ext.tmh.player.styles.less',
-                               )
-                       );
-               }
+
 
                // Setup a hook for iframe embed handling:
                $wgHooks['ArticleFromTitle'][] = 
'TimedMediaIframeOutput::iframeHook';
diff --git a/TimedMediaHandler.php b/TimedMediaHandler.php
index c278541..8e86d69 100644
--- a/TimedMediaHandler.php
+++ b/TimedMediaHandler.php
@@ -309,6 +309,10 @@
 // See also T123695 and T123823
 $wgHooks['CanonicalNamespaces'][] = 
'TimedMediaHandlerHooks::addCanonicalNamespaces';
 
+// We register some modules dynamically, since they depend on the configuration
+$wgHooks['ResourceLoaderRegisterModules'][] =
+       'TimedMediaHandlerHooks::resourceLoaderRegisterModules';
+
 // Register remaining Timed Media Handler hooks right after initial setup
 $wgExtensionFunctions[] = 'TimedMediaHandlerHooks::register';
 

-- 
To view, visit https://gerrit.wikimedia.org/r/272422
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7d751562684e18475885a5acb59963b2f4a5e1d5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TimedMediaHandler
Gerrit-Branch: master
Gerrit-Owner: TheDJ <hartman.w...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to