diff --git a/MultimediaViewer.php b/MultimediaViewer.php index 2211f7d02..43b9f8716 100644 --- a/MultimediaViewer.php +++ b/MultimediaViewer.php @@ -127,7 +127,8 @@ foreach ( $licenses as $license ) { $wgAutoloadClasses['MultimediaViewerHooks'] = __DIR__ . '/MultimediaViewerHooks.php'; $wgHooks['GetBetaFeaturePreferences'][] = 'MultimediaViewerHooks::getBetaPreferences'; -$wgHooks['BeforePageDisplay'][] = 'MultimediaViewerHooks::getModules'; +$wgHooks['BeforePageDisplay'][] = 'MultimediaViewerHooks::getModulesForArticle'; +$wgHooks['CategoryPageView'][] = 'MultimediaViewerHooks::getModulesForCategory'; $wgHooks['ResourceLoaderGetConfigVars'][] = 'MultimediaViewerHooks::resourceLoaderGetConfigVars'; $wgExtensionCredits['other'][] = array( diff --git a/MultimediaViewerHooks.php b/MultimediaViewerHooks.php index ef0132569..3429489ce 100644 --- a/MultimediaViewerHooks.php +++ b/MultimediaViewerHooks.php @@ -28,7 +28,24 @@ class MultimediaViewerHooks { /** Link to a page where this module can be discussed */ protected static $discussionLink = '//mediawiki.org/wiki/Special:MyLanguage/Talk:Multimedia/About_Media_Viewer'; - /* + /** + * Handler for all places where we add the modules + * Could be on article pages or on Category pages + * @param OutputPage $out + * @return bool + */ + protected static function getModules( &$out ) { + if ( class_exists( 'BetaFeatures') + && !BetaFeatures::isFeatureEnabled( $out->getUser(), 'multimedia-viewer' ) ) { + return true; + } + + $out->addModules( array( 'ext.multimediaViewer' ) ); + + return true; + } + + /** * Handler for BeforePageDisplay hook * Add JavaScript to the page when an image is on it * and the user has enabled the feature if BetaFeatures is installed @@ -36,13 +53,26 @@ class MultimediaViewerHooks { * @param Skin $skin * @return bool */ - public static function getModules( &$out, &$skin ) { - if ( class_exists( 'BetaFeatures') - && !BetaFeatures::isFeatureEnabled( $out->getUser(), 'multimedia-viewer' ) ) { - return true; - } + public static function getModulesForArticle( &$out, &$skin ) { if ( count( $out->getFileSearchOptions() ) > 0 ) { - $out->addModules( array( 'ext.multimediaViewer' ) ); + return self::getModules( $out ); + } + + return true; + } + + /** + * Handler for CategoryPageView hook + * Add JavaScript to the page if there are images in the category + * @param CategoryPage $catPage + * @return bool + */ + public static function getModulesForCategory( &$catPage ) { + $title = $catPage->getTitle(); + $cat = Category::newFromTitle( $title ); + if ( $cat->getFileCount() > 0 ) { + $out = $catPage->getContext()->getOutput(); + return self::getModules( $out ); } return true; diff --git a/js/ext.multimediaViewer.js b/js/ext.multimediaViewer.js index 9ec901d02..5e694ac90 100755 --- a/js/ext.multimediaViewer.js +++ b/js/ext.multimediaViewer.js @@ -50,7 +50,7 @@ }; function MultimediaViewer() { - var $thumbs = $( '.thumbimage' ), + var $thumbs = $( '.gallery .image img, a.image img' ), urls = [], viewer = this; @@ -90,11 +90,18 @@ viewer.lightbox.currentIndex = index; + if ( $thumbContain.length === 0 ) { + // This isn't a thumbnail! Just use the link. + $thumbContain = $link; + } else if ( $thumbContain.is( '.thumb' ) ) { + $thumbContain = $thumbContain.find( '.image' ); + } + // Open with the already-loaded thumbnail // Avoids trying to load /wiki/Undefined and doesn't // cost any network time - the library currently needs // some src attribute to work. Will fix. - viewer.lightbox.images[index].src = $this.closest( '.thumb' ).find( '.image img' ).prop( 'src' ); + viewer.lightbox.images[index].src = $thumbContain.find( 'img' ).prop( 'src' ); viewer.lightbox.open(); viewer.lightbox.iface.$imageDiv.append( $.createSpinner( { id: 'mw-mlb-loading-spinner',