Support for all manner of images

Thumbnails still supported, but we also do categories and galleries,
now!

https://mingle.corp.wikimedia.org/projects/multimedia/cards/57

Change-Id: Ieee973eb165eec3e4cff1f0d387e2c20369e126b
This commit is contained in:
Mark Holmquist 2013-11-04 13:40:31 -08:00
parent 5cb29c2e3a
commit 32a1c2e194
3 changed files with 48 additions and 10 deletions

View file

@ -127,7 +127,8 @@ foreach ( $licenses as $license ) {
$wgAutoloadClasses['MultimediaViewerHooks'] = __DIR__ . '/MultimediaViewerHooks.php'; $wgAutoloadClasses['MultimediaViewerHooks'] = __DIR__ . '/MultimediaViewerHooks.php';
$wgHooks['GetBetaFeaturePreferences'][] = 'MultimediaViewerHooks::getBetaPreferences'; $wgHooks['GetBetaFeaturePreferences'][] = 'MultimediaViewerHooks::getBetaPreferences';
$wgHooks['BeforePageDisplay'][] = 'MultimediaViewerHooks::getModules'; $wgHooks['BeforePageDisplay'][] = 'MultimediaViewerHooks::getModulesForArticle';
$wgHooks['CategoryPageView'][] = 'MultimediaViewerHooks::getModulesForCategory';
$wgHooks['ResourceLoaderGetConfigVars'][] = 'MultimediaViewerHooks::resourceLoaderGetConfigVars'; $wgHooks['ResourceLoaderGetConfigVars'][] = 'MultimediaViewerHooks::resourceLoaderGetConfigVars';
$wgExtensionCredits['other'][] = array( $wgExtensionCredits['other'][] = array(

View file

@ -28,7 +28,24 @@ class MultimediaViewerHooks {
/** Link to a page where this module can be discussed */ /** Link to a page where this module can be discussed */
protected static $discussionLink = '//mediawiki.org/wiki/Special:MyLanguage/Talk:Multimedia/About_Media_Viewer'; 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 * Handler for BeforePageDisplay hook
* Add JavaScript to the page when an image is on it * Add JavaScript to the page when an image is on it
* and the user has enabled the feature if BetaFeatures is installed * and the user has enabled the feature if BetaFeatures is installed
@ -36,13 +53,26 @@ class MultimediaViewerHooks {
* @param Skin $skin * @param Skin $skin
* @return bool * @return bool
*/ */
public static function getModules( &$out, &$skin ) { public static function getModulesForArticle( &$out, &$skin ) {
if ( class_exists( 'BetaFeatures')
&& !BetaFeatures::isFeatureEnabled( $out->getUser(), 'multimedia-viewer' ) ) {
return true;
}
if ( count( $out->getFileSearchOptions() ) > 0 ) { 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; return true;

View file

@ -50,7 +50,7 @@
}; };
function MultimediaViewer() { function MultimediaViewer() {
var $thumbs = $( '.thumbimage' ), var $thumbs = $( '.gallery .image img, a.image img' ),
urls = [], urls = [],
viewer = this; viewer = this;
@ -90,11 +90,18 @@
viewer.lightbox.currentIndex = index; 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 // Open with the already-loaded thumbnail
// Avoids trying to load /wiki/Undefined and doesn't // Avoids trying to load /wiki/Undefined and doesn't
// cost any network time - the library currently needs // cost any network time - the library currently needs
// some src attribute to work. Will fix. // 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.open();
viewer.lightbox.iface.$imageDiv.append( $.createSpinner( { viewer.lightbox.iface.$imageDiv.append( $.createSpinner( {
id: 'mw-mlb-loading-spinner', id: 'mw-mlb-loading-spinner',