mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/MultimediaViewer
synced 2024-11-11 17:00:23 +00:00
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:
parent
5cb29c2e3a
commit
32a1c2e194
|
@ -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(
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in a new issue