2013-08-07 08:59:08 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* This file is part of the MediaWiki extension MultimediaViewer.
|
|
|
|
*
|
|
|
|
* MultimediaViewer is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MultimediaViewer is distributed in the hope that it will be useful,
|
2013-11-23 01:18:25 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2013-08-07 08:59:08 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with MultimediaViewer. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @ingroup extensions
|
|
|
|
* @author Mark Holmquist <mtraceur@member.fsf.org>
|
|
|
|
* @copyright Copyright © 2013, Mark Holmquist
|
|
|
|
*/
|
|
|
|
|
|
|
|
class MultimediaViewerHooks {
|
2013-10-29 20:26:07 +00:00
|
|
|
/** Link to more information about this module */
|
|
|
|
protected static $infoLink = '//mediawiki.org/wiki/Special:MyLanguage/Multimedia/About_Media_Viewer';
|
|
|
|
|
|
|
|
/** Link to a page where this module can be discussed */
|
|
|
|
protected static $discussionLink = '//mediawiki.org/wiki/Special:MyLanguage/Talk:Multimedia/About_Media_Viewer';
|
2013-08-07 08:59:08 +00:00
|
|
|
|
2014-03-24 13:35:34 +00:00
|
|
|
/** Link to help about this module */
|
|
|
|
protected static $helpLink = '//mediawiki.org/wiki/Special:MyLanguage/Multimedia/Media_Viewer/Help';
|
|
|
|
|
2014-03-07 01:56:56 +00:00
|
|
|
/**
|
|
|
|
* Checks the context for whether to load the viewer.
|
|
|
|
* @param User $user
|
|
|
|
* @return bool
|
|
|
|
*/
|
2014-03-25 00:09:07 +00:00
|
|
|
protected static function shouldHandleClicks( $user ) {
|
2014-03-14 22:19:26 +00:00
|
|
|
global $wgMediaViewerIsInBeta, $wgEnableMediaViewerForLoggedInUsersOnly;
|
2014-03-07 01:56:56 +00:00
|
|
|
|
|
|
|
if ( $wgMediaViewerIsInBeta && class_exists( 'BetaFeatures' ) ) {
|
|
|
|
return BetaFeatures::isFeatureEnabled( $user, 'multimedia-viewer' );
|
|
|
|
}
|
2014-03-14 00:25:33 +00:00
|
|
|
|
|
|
|
if ( $user->getOption( 'multimediaviewer-enable' ) ) {
|
|
|
|
if ( $wgEnableMediaViewerForLoggedInUsersOnly ) {
|
|
|
|
return $user->isLoggedIn();
|
|
|
|
} else {
|
|
|
|
// Default to enabling for everyone.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2014-03-07 01:56:56 +00:00
|
|
|
}
|
|
|
|
|
2013-11-04 21:40:31 +00:00
|
|
|
/**
|
|
|
|
* Handler for all places where we add the modules
|
|
|
|
* Could be on article pages or on Category pages
|
2013-10-25 23:27:01 +00:00
|
|
|
* @param OutputPage $out
|
|
|
|
* @return bool
|
|
|
|
*/
|
2013-11-04 21:40:31 +00:00
|
|
|
protected static function getModules( &$out ) {
|
2014-03-04 11:53:53 +00:00
|
|
|
$out->addModules( array( 'mmv.bootstrap.autostart' ) );
|
2013-11-04 21:40:31 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
* @param OutputPage $out
|
|
|
|
* @param Skin $skin
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function getModulesForArticle( &$out, &$skin ) {
|
2013-10-25 23:27:01 +00:00
|
|
|
if ( count( $out->getFileSearchOptions() ) > 0 ) {
|
2013-11-04 21:40:31 +00:00
|
|
|
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 );
|
2013-08-07 08:59:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add a beta preference to gate the feature
|
2013-10-29 20:26:07 +00:00
|
|
|
public static function getBetaPreferences( $user, &$prefs ) {
|
2014-03-27 21:01:56 +00:00
|
|
|
global $wgExtensionAssetsPath, $wgMediaViewerIsInBeta;
|
|
|
|
|
|
|
|
if ( !$wgMediaViewerIsInBeta ) {
|
|
|
|
return true;
|
|
|
|
}
|
2013-08-07 08:59:08 +00:00
|
|
|
|
|
|
|
$prefs['multimedia-viewer'] = array(
|
|
|
|
'label-message' => 'multimediaviewer-pref',
|
|
|
|
'desc-message' => 'multimediaviewer-pref-desc',
|
2013-10-29 20:26:07 +00:00
|
|
|
'info-link' => self::$infoLink,
|
|
|
|
'discussion-link' => self::$discussionLink,
|
2014-03-24 13:35:34 +00:00
|
|
|
'help-link' => self::$helpLink,
|
2014-03-27 09:48:59 +00:00
|
|
|
'screenshot' => array(
|
|
|
|
'ltr' => "$wgExtensionAssetsPath/MultimediaViewer/viewer-ltr.svg",
|
|
|
|
'rtl' => "$wgExtensionAssetsPath/MultimediaViewer/viewer-rtl.svg",
|
|
|
|
),
|
2013-08-07 08:59:08 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2013-10-29 20:26:07 +00:00
|
|
|
|
2014-03-14 00:25:33 +00:00
|
|
|
// Adds a default-enabled preference to gate the feature on non-beta sites
|
|
|
|
public static function getPreferences( $user, &$prefs ) {
|
2014-03-27 21:42:22 +00:00
|
|
|
global $wgMediaViewerIsInBeta;
|
|
|
|
|
|
|
|
if ( !$wgMediaViewerIsInBeta ) {
|
|
|
|
$prefs['multimediaviewer-enable'] = array(
|
|
|
|
'type' => 'toggle',
|
|
|
|
'label-message' => 'multimediaviewer-optin-pref',
|
|
|
|
'section' => 'rendering/files',
|
|
|
|
);
|
|
|
|
}
|
2014-03-14 00:25:33 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-10-29 20:26:07 +00:00
|
|
|
/**
|
|
|
|
* Export variables used in both PHP and JS to keep DRY
|
|
|
|
* @param array $vars
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function resourceLoaderGetConfigVars( &$vars ) {
|
2014-02-06 16:17:38 +00:00
|
|
|
global $wgAPIPropModules, $wgNetworkPerformanceSamplingFactor;
|
2013-10-29 20:26:07 +00:00
|
|
|
$vars['wgMultimediaViewer'] = array(
|
|
|
|
'infoLink' => self::$infoLink,
|
|
|
|
'discussionLink' => self::$discussionLink,
|
2014-03-24 13:35:34 +00:00
|
|
|
'helpLink' => self::$helpLink,
|
2014-01-30 11:28:43 +00:00
|
|
|
'globalUsageAvailable' => isset( $wgAPIPropModules['globalusage'] ),
|
2013-10-29 20:26:07 +00:00
|
|
|
);
|
2014-02-06 16:17:38 +00:00
|
|
|
$vars['wgNetworkPerformanceSamplingFactor'] = $wgNetworkPerformanceSamplingFactor;
|
2014-03-14 22:19:26 +00:00
|
|
|
$vars['wgMediaViewer'] = true;
|
|
|
|
|
2013-10-29 20:26:07 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-11-27 21:57:45 +00:00
|
|
|
|
2014-03-27 22:46:51 +00:00
|
|
|
/**
|
|
|
|
* Export variables which depend on the current user
|
|
|
|
* @param $vars
|
|
|
|
* @param OutputPage $out
|
|
|
|
*/
|
|
|
|
public static function makeGlobalVariablesScript( &$vars, OutputPage $out ) {
|
|
|
|
$user = $out->getUser();
|
|
|
|
$vars['wgMediaViewerOnClick'] = self::shouldHandleClicks( $user );
|
|
|
|
}
|
|
|
|
|
2013-11-27 21:57:45 +00:00
|
|
|
/**
|
|
|
|
* Get modules for testing our JavaScript
|
|
|
|
* @param array $testModules
|
|
|
|
* @param ResourceLoader resourceLoader
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function getTestModules( array &$testModules, ResourceLoader &$resourceLoader ) {
|
2014-01-23 21:44:26 +00:00
|
|
|
$testModules['qunit']['mmv.tests'] = array(
|
2013-11-27 21:57:45 +00:00
|
|
|
'scripts' => array(
|
2014-02-25 01:54:05 +00:00
|
|
|
'tests/qunit/mmv/mmv.bootstrap.test.js',
|
|
|
|
'tests/qunit/mmv/mmv.test.js',
|
|
|
|
'tests/qunit/mmv/mmv.lightboxinterface.test.js',
|
|
|
|
'tests/qunit/mmv/mmv.lightboximage.test.js',
|
|
|
|
'tests/qunit/mmv/mmv.ThumbnailWidthCalculator.test.js',
|
2014-03-19 02:00:26 +00:00
|
|
|
'tests/qunit/mmv/mmv.EmbedFileFormatter.test.js',
|
2014-02-25 01:54:05 +00:00
|
|
|
'tests/qunit/mmv/mmv.performance.test.js',
|
|
|
|
'tests/qunit/mmv/mmv.logger.test.js',
|
|
|
|
'tests/qunit/mmv/model/mmv.model.test.js',
|
2014-02-10 21:24:19 +00:00
|
|
|
'tests/qunit/mmv/model/mmv.model.TaskQueue.test.js',
|
2014-03-20 01:19:54 +00:00
|
|
|
'tests/qunit/mmv/model/mmv.model.License.test.js',
|
2014-03-21 01:17:45 +00:00
|
|
|
'tests/qunit/mmv/model/mmv.model.Repo.test.js',
|
2014-02-25 01:54:05 +00:00
|
|
|
'tests/qunit/mmv/provider/mmv.provider.Api.test.js',
|
|
|
|
'tests/qunit/mmv/provider/mmv.provider.ImageUsage.test.js',
|
|
|
|
'tests/qunit/mmv/provider/mmv.provider.GlobalUsage.test.js',
|
|
|
|
'tests/qunit/mmv/provider/mmv.provider.ImageInfo.test.js',
|
|
|
|
'tests/qunit/mmv/provider/mmv.provider.FileRepoInfo.test.js',
|
|
|
|
'tests/qunit/mmv/provider/mmv.provider.ThumbnailInfo.test.js',
|
|
|
|
'tests/qunit/mmv/provider/mmv.provider.UserInfo.test.js',
|
|
|
|
'tests/qunit/mmv/provider/mmv.provider.Image.test.js',
|
|
|
|
'tests/qunit/mmv/ui/mmv.ui.test.js',
|
2014-02-28 11:50:06 +00:00
|
|
|
'tests/qunit/mmv/ui/mmv.ui.buttons.test.js',
|
2014-02-26 20:09:37 +00:00
|
|
|
'tests/qunit/mmv/ui/mmv.ui.canvas.test.js',
|
2014-02-25 01:54:05 +00:00
|
|
|
'tests/qunit/mmv/ui/mmv.ui.categories.test.js',
|
|
|
|
'tests/qunit/mmv/ui/mmv.ui.description.test.js',
|
|
|
|
'tests/qunit/mmv/ui/mmv.ui.fileUsage.test.js',
|
|
|
|
'tests/qunit/mmv/ui/mmv.ui.metadataPanel.test.js',
|
|
|
|
'tests/qunit/mmv/ui/mmv.ui.permission.test.js',
|
2014-03-17 08:07:53 +00:00
|
|
|
'tests/qunit/mmv/ui/mmv.ui.reuse.dialog.test.js',
|
2014-03-19 02:00:26 +00:00
|
|
|
'tests/qunit/mmv/ui/mmv.ui.reuse.embed.test.js',
|
2014-03-17 08:07:53 +00:00
|
|
|
'tests/qunit/mmv/ui/mmv.ui.reuse.share.test.js',
|
|
|
|
'tests/qunit/mmv/ui/mmv.ui.reuse.tab.test.js',
|
2014-02-25 01:54:05 +00:00
|
|
|
'tests/qunit/mmv/mmv.testhelpers.js',
|
2013-11-27 21:57:45 +00:00
|
|
|
),
|
|
|
|
'dependencies' => array(
|
2014-01-23 21:44:26 +00:00
|
|
|
'mmv',
|
2014-02-17 15:09:23 +00:00
|
|
|
'mmv.bootstrap',
|
2013-11-27 21:57:45 +00:00
|
|
|
),
|
|
|
|
'localBasePath' => __DIR__,
|
|
|
|
'remoteExtPath' => 'MultimediaViewer',
|
|
|
|
);
|
|
|
|
|
|
|
|
return true;
|
2014-01-31 00:06:33 +00:00
|
|
|
}
|
2013-08-07 08:59:08 +00:00
|
|
|
}
|