MediaWiki REL1_32
MultimediaViewerHooks.php
Go to the documentation of this file.
1<?php
26 protected static $infoLink =
27 'https://mediawiki.org/wiki/Special:MyLanguage/Extension:Media_Viewer/About';
28
30 protected static $discussionLink =
31 'https://mediawiki.org/wiki/Special:MyLanguage/Extension_talk:Media_Viewer/About';
32
34 protected static $helpLink =
35 'https://mediawiki.org/wiki/Special:MyLanguage/Help:Extension:Media_Viewer';
36
37 public static function onUserGetDefaultOptions( &$defaultOptions ) {
39
41 $defaultOptions['multimediaviewer-enable'] = 1;
42 }
43
44 return true;
45 }
46
52 protected static function shouldHandleClicks( $user ) {
55
56 if ( $wgMediaViewerIsInBeta && class_exists( 'BetaFeatures' ) ) {
57 return BetaFeatures::isFeatureEnabled( $user, 'multimedia-viewer' );
58 }
59
61 $enableByDefaultForAnons = $wgMediaViewerEnableByDefault;
62 } else {
63 $enableByDefaultForAnons = $wgMediaViewerEnableByDefaultForAnonymous;
64 }
65
66 if ( !$user->isLoggedIn() ) {
67 return (bool)$enableByDefaultForAnons;
68 } else {
69 return (bool)$user->getOption( 'multimediaviewer-enable' );
70 }
71 }
72
79 protected static function getModules( &$out ) {
80 $out->addModules( [ 'mmv.head', 'mmv.bootstrap.autostart' ] );
81
82 return true;
83 }
84
93 public static function getModulesForArticle( &$out, &$skin ) {
94 $pageHasThumbnails = count( $out->getFileSearchOptions() ) > 0;
95 $pageIsFilePage = $out->getTitle()->inNamespace( NS_FILE );
96 $fileRelatedSpecialPages = [ 'NewFiles', 'ListFiles', 'MostLinkedFiles',
97 'MostGloballyLinkedFiles', 'UncategorizedFiles', 'UnusedFiles', 'Search' ];
98 $pageIsFileRelatedSpecialPage = $out->getTitle()->inNamespace( NS_SPECIAL )
99 && in_array( $out->getTitle()->getText(), $fileRelatedSpecialPages );
100
101 if ( $pageHasThumbnails || $pageIsFilePage || $pageIsFileRelatedSpecialPage ) {
102 return self::getModules( $out );
103 }
104
105 return true;
106 }
107
114 public static function getModulesForCategory( &$catPage ) {
115 $title = $catPage->getTitle();
116 $cat = Category::newFromTitle( $title );
117 if ( $cat->getFileCount() > 0 ) {
118 $out = $catPage->getContext()->getOutput();
119 return self::getModules( $out );
120 }
121
122 return true;
123 }
124
131 public static function getBetaPreferences( $user, &$prefs ) {
133
134 if ( !$wgMediaViewerIsInBeta ) {
135 return true;
136 }
137
138 $prefs['multimedia-viewer'] = [
139 'label-message' => 'multimediaviewer-pref',
140 'desc-message' => 'multimediaviewer-pref-desc',
141 'info-link' => self::$infoLink,
142 'discussion-link' => self::$discussionLink,
143 'help-link' => self::$helpLink,
144 'screenshot' => [
145 'ltr' => "$wgExtensionAssetsPath/MultimediaViewer/viewer-ltr.svg",
146 'rtl' => "$wgExtensionAssetsPath/MultimediaViewer/viewer-rtl.svg",
147 ],
148 ];
149
150 return true;
151 }
152
159 public static function getPreferences( $user, &$prefs ) {
161
162 if ( !$wgMediaViewerIsInBeta ) {
163 $prefs['multimediaviewer-enable'] = [
164 'type' => 'toggle',
165 'label-message' => 'multimediaviewer-optin-pref',
166 'section' => 'rendering/files',
167 ];
168 }
169
170 return true;
171 }
172
178 public static function resourceLoaderGetConfigVars( &$vars ) {
187
188 $vars['wgMultimediaViewer'] = [
189 'infoLink' => self::$infoLink,
190 'discussionLink' => self::$discussionLink,
191 'helpLink' => self::$helpLink,
192 'useThumbnailGuessing' => (bool)$wgMediaViewerUseThumbnailGuessing,
193 'durationSamplingFactor' => $wgMediaViewerDurationLoggingSamplingFactor,
194 'durationSamplingFactorLoggedin' => $wgMediaViewerDurationLoggingLoggedinSamplingFactor,
195 'networkPerformanceSamplingFactor' => $wgMediaViewerNetworkPerformanceSamplingFactor,
196 'actionLoggingSamplingFactorMap' => $wgMediaViewerActionLoggingSamplingFactorMap,
197 'attributionSamplingFactor' => $wgMediaViewerAttributionLoggingSamplingFactor,
198 'dimensionSamplingFactor' => $wgMediaViewerDimensionLoggingSamplingFactor,
199 'imageQueryParameter' => $wgMediaViewerImageQueryParameter,
200 'recordVirtualViewBeaconURI' => $wgMediaViewerRecordVirtualViewBeaconURI,
201 'tooltipDelay' => 1000,
202 'extensions' => $wgMediaViewerExtensions,
203 ];
204 $vars['wgMediaViewer'] = true;
205 $vars['wgMediaViewerIsInBeta'] = $wgMediaViewerIsInBeta;
206
207 return true;
208 }
209
215 public static function makeGlobalVariablesScript( &$vars, OutputPage $out ) {
216 $defaultUserOptions = User::getDefaultOptions();
217
218 $user = $out->getUser();
219 $vars['wgMediaViewerOnClick'] = self::shouldHandleClicks( $user );
220 // needed because of bug 69942; could be different for anon and logged-in
221 $vars['wgMediaViewerEnabledByDefault'] =
222 !empty( $defaultUserOptions['multimediaviewer-enable'] );
223 }
224
231 public static function getTestModules( array &$testModules, ResourceLoader &$resourceLoader ) {
232 $testModules['qunit']['mmv.tests'] = [
233 'scripts' => [
234 'tests/qunit/mmv/mmv.bootstrap.test.js',
235 'tests/qunit/mmv/mmv.test.js',
236 'tests/qunit/mmv/mmv.lightboxinterface.test.js',
237 'tests/qunit/mmv/mmv.lightboximage.test.js',
238 'tests/qunit/mmv/mmv.ThumbnailWidthCalculator.test.js',
239 'tests/qunit/mmv/mmv.EmbedFileFormatter.test.js',
240 'tests/qunit/mmv/mmv.Config.test.js',
241 'tests/qunit/mmv/mmv.HtmlUtils.test.js',
242 'tests/qunit/mmv/logging/mmv.logging.DurationLogger.test.js',
243 'tests/qunit/mmv/logging/mmv.logging.PerformanceLogger.test.js',
244 'tests/qunit/mmv/logging/mmv.logging.ActionLogger.test.js',
245 'tests/qunit/mmv/logging/mmv.logging.AttributionLogger.test.js',
246 'tests/qunit/mmv/logging/mmv.logging.DimensionLogger.test.js',
247 'tests/qunit/mmv/logging/mmv.logging.ViewLogger.test.js',
248 'tests/qunit/mmv/model/mmv.model.test.js',
249 'tests/qunit/mmv/model/mmv.model.IwTitle.test.js',
250 'tests/qunit/mmv/model/mmv.model.TaskQueue.test.js',
251 'tests/qunit/mmv/model/mmv.model.License.test.js',
252 'tests/qunit/mmv/model/mmv.model.Image.test.js',
253 'tests/qunit/mmv/model/mmv.model.Repo.test.js',
254 'tests/qunit/mmv/model/mmv.model.EmbedFileInfo.test.js',
255 'tests/qunit/mmv/provider/mmv.provider.Api.test.js',
256 'tests/qunit/mmv/provider/mmv.provider.ImageInfo.test.js',
257 'tests/qunit/mmv/provider/mmv.provider.FileRepoInfo.test.js',
258 'tests/qunit/mmv/provider/mmv.provider.ThumbnailInfo.test.js',
259 'tests/qunit/mmv/provider/mmv.provider.GuessedThumbnailInfo.test.js',
260 'tests/qunit/mmv/provider/mmv.provider.Image.test.js',
261 'tests/qunit/mmv/routing/mmv.routing.MainFileRoute.test.js',
262 'tests/qunit/mmv/routing/mmv.routing.ThumbnailRoute.test.js',
263 'tests/qunit/mmv/routing/mmv.routing.Router.test.js',
264 'tests/qunit/mmv/ui/mmv.ui.test.js',
265 'tests/qunit/mmv/ui/mmv.ui.canvas.test.js',
266 'tests/qunit/mmv/ui/mmv.ui.canvasButtons.test.js',
267 'tests/qunit/mmv/ui/mmv.ui.description.test.js',
268 'tests/qunit/mmv/ui/mmv.ui.download.pane.test.js',
269 'tests/qunit/mmv/ui/mmv.ui.metadataPanel.test.js',
270 'tests/qunit/mmv/ui/mmv.ui.metadataPanelScroller.test.js',
271 'tests/qunit/mmv/ui/mmv.ui.progressBar.test.js',
272 'tests/qunit/mmv/ui/mmv.ui.permission.test.js',
273 'tests/qunit/mmv/ui/mmv.ui.stripeButtons.test.js',
274 'tests/qunit/mmv/ui/mmv.ui.reuse.dialog.test.js',
275 'tests/qunit/mmv/ui/mmv.ui.reuse.embed.test.js',
276 'tests/qunit/mmv/ui/mmv.ui.reuse.share.test.js',
277 'tests/qunit/mmv/ui/mmv.ui.reuse.tab.test.js',
278 'tests/qunit/mmv/ui/mmv.ui.reuse.utils.test.js',
279 'tests/qunit/mmv/ui/mmv.ui.tipsyDialog.test.js',
280 'tests/qunit/mmv/ui/mmv.ui.truncatableTextField.test.js',
281 'tests/qunit/mmv/ui/mmv.ui.viewingOptions.test.js',
282 'tests/qunit/mmv/mmv.testhelpers.js',
283 ],
284 'dependencies' => [
285 'mmv.head',
286 'mmv.bootstrap',
287 'mmv',
288 'mmv.ui.ondemandshareddependencies',
289 'mmv.ui.reuse.shareembed',
290 'mmv.ui.download.pane',
291 'mmv.ui.tipsyDialog',
292 'moment',
293 ],
294 'localBasePath' => dirname( __DIR__ ),
295 'remoteExtPath' => 'MultimediaViewer',
296 ];
297
298 return true;
299 }
300
308 public static function thumbnailBeforeProduceHTML( ThumbnailImage $thumbnail, array &$attribs,
309 &$linkAttribs
310 ) {
311 $file = $thumbnail->getFile();
312
313 if ( $file ) {
314 // At the moment all classes that extend File have getWidth() and getHeight()
315 // but since the File class doesn't have these methods defined, this check
316 // is more future-proof
317
318 if ( method_exists( $file, 'getWidth' ) ) {
319 $attribs['data-file-width'] = $file->getWidth();
320 }
321
322 if ( method_exists( $file, 'getHeight' ) ) {
323 $attribs['data-file-height'] = $file->getHeight();
324 }
325 }
326
327 return true;
328 }
329}
$wgExtensionAssetsPath
The URL path of the extensions directory.
int bool $wgMediaViewerDurationLoggingSamplingFactor
If set, records loading times via EventLogging.
int bool $wgMediaViewerAttributionLoggingSamplingFactor
If set, records whether image attribution data was available.
bool $wgMediaViewerEnableByDefault
If trueish, and $wgMediaViewerIsInBeta is unset, Media Viewer will be turned on by default.
bool null $wgMediaViewerEnableByDefaultForAnonymous
Overrides $wgMediaViewerEnableByDefault for anonymous users.
int bool $wgMediaViewerDurationLoggingLoggedinSamplingFactor
If set, records loading times via EventLogging with factor specific to loggedin users.
bool $wgMediaViewerUseThumbnailGuessing
When this is enabled, MediaViewer will try to guess image URLs instead of making an imageinfo API to ...
int bool $wgMediaViewerNetworkPerformanceSamplingFactor
If set, records image load network performance via EventLogging once per this many requests.
bool $wgMediaViewerIsInBeta
If set, Media Viewer will try to use BetaFeatures.
array bool $wgMediaViewerActionLoggingSamplingFactorMap
If set, records user actions via EventLogging and applies a sampling factor according to the map.
string bool $wgMediaViewerImageQueryParameter
If set, adds a query parameter to image requests made by Media Viewer.
string bool $wgMediaViewerRecordVirtualViewBeaconURI
If set, records a virtual view via the provided beacon URI.
int bool $wgMediaViewerDimensionLoggingSamplingFactor
If set, records whether image dimension data was available.
static onUserGetDefaultOptions(&$defaultOptions)
static $helpLink
Link to help about this module.
static getModulesForArticle(&$out, &$skin)
Handler for BeforePageDisplay hook Add JavaScript to the page when an image is on it and the user has...
static makeGlobalVariablesScript(&$vars, OutputPage $out)
Export variables which depend on the current user.
static shouldHandleClicks( $user)
Checks the context for whether to load the viewer.
static getModulesForCategory(&$catPage)
Handler for CategoryPageView hook Add JavaScript to the page if there are images in the category.
static $discussionLink
Link to a page where this module can be discussed.
static getPreferences( $user, &$prefs)
Adds a default-enabled preference to gate the feature on non-beta sites.
static getTestModules(array &$testModules, ResourceLoader &$resourceLoader)
Get modules for testing our JavaScript.
static thumbnailBeforeProduceHTML(ThumbnailImage $thumbnail, array &$attribs, &$linkAttribs)
Modify thumbnail DOM.
static getModules(&$out)
Handler for all places where we add the modules Could be on article pages or on Category pages.
static resourceLoaderGetConfigVars(&$vars)
Export variables used in both PHP and JS to keep DRY.
static getBetaPreferences( $user, &$prefs)
Add a beta preference to gate the feature.
static $infoLink
Link to more information about this module.
This class should be covered by a general architecture document which does not exist as of January 20...
Dynamic JavaScript and CSS resource loading system.
Media transform output for images.
static getDefaultOptions()
Combine the language default options with any site-specific options and add the default language vari...
Definition User.php:1773
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
Definition hooks.txt:2278
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition hooks.txt:894
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing & $attribs
Definition hooks.txt:2063
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext such as when responding to a resource loader request or generating HTML output & $resourceLoader
Definition hooks.txt:2892
const NS_FILE
Definition Defines.php:70
const NS_SPECIAL
Definition Defines.php:53
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))