MediaWiki REL1_31
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
47 public static function onExtensionFunctions() {
48 global $wgResourceModules;
49
50 if ( isset( $wgResourceModules['ext.eventLogging'] ) ) {
51 $wgResourceModules['mmv.lightboxinterface']['dependencies'][] = 'ext.eventLogging';
52 $wgResourceModules['mmv']['dependencies'][] = 'ext.eventLogging';
53 $wgResourceModules['mmv.bootstrap.autostart']['dependencies'][] = 'ext.eventLogging';
54 }
55 }
56
57 public static function onEventLoggingRegisterSchemas( array &$schemas ) {
58 $schemas += [
59 'MediaViewer' => 10867062,
60 'MultimediaViewerNetworkPerformance' => 15573630,
61 'MultimediaViewerDuration' => 10427980,
62 'MultimediaViewerAttribution' => 9758179,
63 'MultimediaViewerDimensions' => 10014238,
64 ];
65 }
66
72 protected static function shouldHandleClicks( $user ) {
75
76 if ( $wgMediaViewerIsInBeta && class_exists( 'BetaFeatures' ) ) {
77 return BetaFeatures::isFeatureEnabled( $user, 'multimedia-viewer' );
78 }
79
81 $enableByDefaultForAnons = $wgMediaViewerEnableByDefault;
82 } else {
83 $enableByDefaultForAnons = $wgMediaViewerEnableByDefaultForAnonymous;
84 }
85
86 if ( !$user->isLoggedIn() ) {
87 return (bool)$enableByDefaultForAnons;
88 } else {
89 return (bool)$user->getOption( 'multimediaviewer-enable' );
90 }
91 }
92
99 protected static function getModules( &$out ) {
100 $out->addModules( [ 'mmv.head', 'mmv.bootstrap.autostart' ] );
101
102 return true;
103 }
104
113 public static function getModulesForArticle( &$out, &$skin ) {
114 $pageHasThumbnails = count( $out->getFileSearchOptions() ) > 0;
115 $pageIsFilePage = $out->getTitle()->inNamespace( NS_FILE );
116 $fileRelatedSpecialPages = [ 'NewFiles', 'ListFiles', 'MostLinkedFiles',
117 'MostGloballyLinkedFiles', 'UncategorizedFiles', 'UnusedFiles', 'Search' ];
118 $pageIsFileRelatedSpecialPage = $out->getTitle()->inNamespace( NS_SPECIAL )
119 && in_array( $out->getTitle()->getText(), $fileRelatedSpecialPages );
120
121 if ( $pageHasThumbnails || $pageIsFilePage || $pageIsFileRelatedSpecialPage ) {
122 return self::getModules( $out );
123 }
124
125 return true;
126 }
127
134 public static function getModulesForCategory( &$catPage ) {
135 $title = $catPage->getTitle();
136 $cat = Category::newFromTitle( $title );
137 if ( $cat->getFileCount() > 0 ) {
138 $out = $catPage->getContext()->getOutput();
139 return self::getModules( $out );
140 }
141
142 return true;
143 }
144
151 public static function getBetaPreferences( $user, &$prefs ) {
153
154 if ( !$wgMediaViewerIsInBeta ) {
155 return true;
156 }
157
158 $prefs['multimedia-viewer'] = [
159 'label-message' => 'multimediaviewer-pref',
160 'desc-message' => 'multimediaviewer-pref-desc',
161 'info-link' => self::$infoLink,
162 'discussion-link' => self::$discussionLink,
163 'help-link' => self::$helpLink,
164 'screenshot' => [
165 'ltr' => "$wgExtensionAssetsPath/MultimediaViewer/viewer-ltr.svg",
166 'rtl' => "$wgExtensionAssetsPath/MultimediaViewer/viewer-rtl.svg",
167 ],
168 ];
169
170 return true;
171 }
172
179 public static function getPreferences( $user, &$prefs ) {
181
182 if ( !$wgMediaViewerIsInBeta ) {
183 $prefs['multimediaviewer-enable'] = [
184 'type' => 'toggle',
185 'label-message' => 'multimediaviewer-optin-pref',
186 'section' => 'rendering/files',
187 ];
188 }
189
190 return true;
191 }
192
198 public static function resourceLoaderGetConfigVars( &$vars ) {
207
208 $vars['wgMultimediaViewer'] = [
209 'infoLink' => self::$infoLink,
210 'discussionLink' => self::$discussionLink,
211 'helpLink' => self::$helpLink,
212 'useThumbnailGuessing' => (bool)$wgMediaViewerUseThumbnailGuessing,
213 'durationSamplingFactor' => $wgMediaViewerDurationLoggingSamplingFactor,
214 'durationSamplingFactorLoggedin' => $wgMediaViewerDurationLoggingLoggedinSamplingFactor,
215 'networkPerformanceSamplingFactor' => $wgMediaViewerNetworkPerformanceSamplingFactor,
216 'actionLoggingSamplingFactorMap' => $wgMediaViewerActionLoggingSamplingFactorMap,
217 'attributionSamplingFactor' => $wgMediaViewerAttributionLoggingSamplingFactor,
218 'dimensionSamplingFactor' => $wgMediaViewerDimensionLoggingSamplingFactor,
219 'imageQueryParameter' => $wgMediaViewerImageQueryParameter,
220 'recordVirtualViewBeaconURI' => $wgMediaViewerRecordVirtualViewBeaconURI,
221 'tooltipDelay' => 1000,
222 'extensions' => $wgMediaViewerExtensions,
223 ];
224 $vars['wgMediaViewer'] = true;
225 $vars['wgMediaViewerIsInBeta'] = $wgMediaViewerIsInBeta;
226
227 return true;
228 }
229
235 public static function makeGlobalVariablesScript( &$vars, OutputPage $out ) {
236 $defaultUserOptions = User::getDefaultOptions();
237
238 $user = $out->getUser();
239 $vars['wgMediaViewerOnClick'] = self::shouldHandleClicks( $user );
240 // needed because of bug 69942; could be different for anon and logged-in
241 $vars['wgMediaViewerEnabledByDefault'] =
242 !empty( $defaultUserOptions['multimediaviewer-enable'] );
243 }
244
251 public static function getTestModules( array &$testModules, ResourceLoader &$resourceLoader ) {
252 $testModules['qunit']['mmv.tests'] = [
253 'scripts' => [
254 'tests/qunit/mmv/mmv.bootstrap.test.js',
255 'tests/qunit/mmv/mmv.test.js',
256 'tests/qunit/mmv/mmv.lightboxinterface.test.js',
257 'tests/qunit/mmv/mmv.lightboximage.test.js',
258 'tests/qunit/mmv/mmv.ThumbnailWidthCalculator.test.js',
259 'tests/qunit/mmv/mmv.EmbedFileFormatter.test.js',
260 'tests/qunit/mmv/mmv.Config.test.js',
261 'tests/qunit/mmv/mmv.HtmlUtils.test.js',
262 'tests/qunit/mmv/logging/mmv.logging.DurationLogger.test.js',
263 'tests/qunit/mmv/logging/mmv.logging.PerformanceLogger.test.js',
264 'tests/qunit/mmv/logging/mmv.logging.ActionLogger.test.js',
265 'tests/qunit/mmv/logging/mmv.logging.AttributionLogger.test.js',
266 'tests/qunit/mmv/logging/mmv.logging.DimensionLogger.test.js',
267 'tests/qunit/mmv/logging/mmv.logging.ViewLogger.test.js',
268 'tests/qunit/mmv/model/mmv.model.test.js',
269 'tests/qunit/mmv/model/mmv.model.IwTitle.test.js',
270 'tests/qunit/mmv/model/mmv.model.TaskQueue.test.js',
271 'tests/qunit/mmv/model/mmv.model.License.test.js',
272 'tests/qunit/mmv/model/mmv.model.Image.test.js',
273 'tests/qunit/mmv/model/mmv.model.Repo.test.js',
274 'tests/qunit/mmv/model/mmv.model.EmbedFileInfo.test.js',
275 'tests/qunit/mmv/provider/mmv.provider.Api.test.js',
276 'tests/qunit/mmv/provider/mmv.provider.ImageInfo.test.js',
277 'tests/qunit/mmv/provider/mmv.provider.FileRepoInfo.test.js',
278 'tests/qunit/mmv/provider/mmv.provider.ThumbnailInfo.test.js',
279 'tests/qunit/mmv/provider/mmv.provider.GuessedThumbnailInfo.test.js',
280 'tests/qunit/mmv/provider/mmv.provider.Image.test.js',
281 'tests/qunit/mmv/routing/mmv.routing.MainFileRoute.test.js',
282 'tests/qunit/mmv/routing/mmv.routing.ThumbnailRoute.test.js',
283 'tests/qunit/mmv/routing/mmv.routing.Router.test.js',
284 'tests/qunit/mmv/ui/mmv.ui.test.js',
285 'tests/qunit/mmv/ui/mmv.ui.canvas.test.js',
286 'tests/qunit/mmv/ui/mmv.ui.canvasButtons.test.js',
287 'tests/qunit/mmv/ui/mmv.ui.description.test.js',
288 'tests/qunit/mmv/ui/mmv.ui.download.pane.test.js',
289 'tests/qunit/mmv/ui/mmv.ui.metadataPanel.test.js',
290 'tests/qunit/mmv/ui/mmv.ui.metadataPanelScroller.test.js',
291 'tests/qunit/mmv/ui/mmv.ui.progressBar.test.js',
292 'tests/qunit/mmv/ui/mmv.ui.permission.test.js',
293 'tests/qunit/mmv/ui/mmv.ui.stripeButtons.test.js',
294 'tests/qunit/mmv/ui/mmv.ui.reuse.dialog.test.js',
295 'tests/qunit/mmv/ui/mmv.ui.reuse.embed.test.js',
296 'tests/qunit/mmv/ui/mmv.ui.reuse.share.test.js',
297 'tests/qunit/mmv/ui/mmv.ui.reuse.tab.test.js',
298 'tests/qunit/mmv/ui/mmv.ui.reuse.utils.test.js',
299 'tests/qunit/mmv/ui/mmv.ui.tipsyDialog.test.js',
300 'tests/qunit/mmv/ui/mmv.ui.truncatableTextField.test.js',
301 'tests/qunit/mmv/ui/mmv.ui.viewingOptions.test.js',
302 'tests/qunit/mmv/mmv.testhelpers.js',
303 ],
304 'dependencies' => [
305 'mmv.head',
306 'mmv.bootstrap',
307 'mmv',
308 'mmv.ui.ondemandshareddependencies',
309 'mmv.ui.reuse.shareembed',
310 'mmv.ui.download.pane',
311 'mmv.ui.tipsyDialog',
312 'moment',
313 ],
314 'localBasePath' => dirname( __DIR__ ),
315 'remoteExtPath' => 'MultimediaViewer',
316 ];
317
318 return true;
319 }
320
328 public static function thumbnailBeforeProduceHTML( ThumbnailImage $thumbnail, array &$attribs,
329 &$linkAttribs
330 ) {
331 $file = $thumbnail->getFile();
332
333 if ( $file ) {
334 // At the moment all classes that extend File have getWidth() and getHeight()
335 // but since the File class doesn't have these methods defined, this check
336 // is more future-proof
337
338 if ( method_exists( $file, 'getWidth' ) ) {
339 $attribs['data-file-width'] = $file->getWidth();
340 }
341
342 if ( method_exists( $file, 'getHeight' ) ) {
343 $attribs['data-file-height'] = $file->getHeight();
344 }
345 }
346
347 return true;
348 }
349}
$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.
$wgResourceModules['ext.ReplaceText']
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 onEventLoggingRegisterSchemas(array &$schemas)
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:1722
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
Definition hooks.txt:2228
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:864
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:2014
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:2818
const NS_FILE
Definition Defines.php:80
const NS_SPECIAL
Definition Defines.php:63