MediaWiki REL1_33
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 && ExtensionRegistry::getInstance()->isLoaded( '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 // TODO: Have Flow work out if there are any images on the page
97 $pageIsFlowPage = ExtensionRegistry::getInstance()->isLoaded( 'Flow' ) &&
98 // CONTENT_MODEL_FLOW_BOARD
99 $out->getTitle()->getContentModel() === 'flow-board';
100 $fileRelatedSpecialPages = [ 'NewFiles', 'ListFiles', 'MostLinkedFiles',
101 'MostGloballyLinkedFiles', 'UncategorizedFiles', 'UnusedFiles', 'Search' ];
102 $pageIsFileRelatedSpecialPage = $out->getTitle()->inNamespace( NS_SPECIAL )
103 && in_array( $out->getTitle()->getText(), $fileRelatedSpecialPages );
104
105 if ( $pageHasThumbnails || $pageIsFilePage || $pageIsFileRelatedSpecialPage || $pageIsFlowPage ) {
106 return self::getModules( $out );
107 }
108
109 return true;
110 }
111
118 public static function getModulesForCategory( &$catPage ) {
119 $title = $catPage->getTitle();
120 $cat = Category::newFromTitle( $title );
121 if ( $cat->getFileCount() > 0 ) {
122 $out = $catPage->getContext()->getOutput();
123 return self::getModules( $out );
124 }
125
126 return true;
127 }
128
135 public static function getBetaPreferences( $user, &$prefs ) {
137
138 if ( !$wgMediaViewerIsInBeta ) {
139 return true;
140 }
141
142 $prefs['multimedia-viewer'] = [
143 'label-message' => 'multimediaviewer-pref',
144 'desc-message' => 'multimediaviewer-pref-desc',
145 'info-link' => self::$infoLink,
146 'discussion-link' => self::$discussionLink,
147 'help-link' => self::$helpLink,
148 'screenshot' => [
149 'ltr' => "$wgExtensionAssetsPath/MultimediaViewer/viewer-ltr.svg",
150 'rtl' => "$wgExtensionAssetsPath/MultimediaViewer/viewer-rtl.svg",
151 ],
152 ];
153
154 return true;
155 }
156
163 public static function getPreferences( $user, &$prefs ) {
165
166 if ( !$wgMediaViewerIsInBeta ) {
167 $prefs['multimediaviewer-enable'] = [
168 'type' => 'toggle',
169 'label-message' => 'multimediaviewer-optin-pref',
170 'section' => 'rendering/files',
171 ];
172 }
173
174 return true;
175 }
176
182 public static function resourceLoaderGetConfigVars( &$vars ) {
191
192 $vars['wgMultimediaViewer'] = [
193 'infoLink' => self::$infoLink,
194 'discussionLink' => self::$discussionLink,
195 'helpLink' => self::$helpLink,
196 'useThumbnailGuessing' => (bool)$wgMediaViewerUseThumbnailGuessing,
197 'durationSamplingFactor' => $wgMediaViewerDurationLoggingSamplingFactor,
198 'durationSamplingFactorLoggedin' => $wgMediaViewerDurationLoggingLoggedinSamplingFactor,
199 'networkPerformanceSamplingFactor' => $wgMediaViewerNetworkPerformanceSamplingFactor,
200 'actionLoggingSamplingFactorMap' => $wgMediaViewerActionLoggingSamplingFactorMap,
201 'attributionSamplingFactor' => $wgMediaViewerAttributionLoggingSamplingFactor,
202 'dimensionSamplingFactor' => $wgMediaViewerDimensionLoggingSamplingFactor,
203 'imageQueryParameter' => $wgMediaViewerImageQueryParameter,
204 'recordVirtualViewBeaconURI' => $wgMediaViewerRecordVirtualViewBeaconURI,
205 'tooltipDelay' => 1000,
206 'extensions' => $wgMediaViewerExtensions,
207 ];
208 $vars['wgMediaViewer'] = true;
209 $vars['wgMediaViewerIsInBeta'] = $wgMediaViewerIsInBeta;
210
211 return true;
212 }
213
219 public static function makeGlobalVariablesScript( &$vars, OutputPage $out ) {
220 $defaultUserOptions = User::getDefaultOptions();
221
222 $user = $out->getUser();
223 $vars['wgMediaViewerOnClick'] = self::shouldHandleClicks( $user );
224 // needed because of bug 69942; could be different for anon and logged-in
225 $vars['wgMediaViewerEnabledByDefault'] =
226 !empty( $defaultUserOptions['multimediaviewer-enable'] );
227 }
228
236 public static function thumbnailBeforeProduceHTML( ThumbnailImage $thumbnail, array &$attribs,
237 &$linkAttribs
238 ) {
239 $file = $thumbnail->getFile();
240
241 if ( $file ) {
242 // At the moment all classes that extend File have getWidth() and getHeight()
243 // but since the File class doesn't have these methods defined, this check
244 // is more future-proof
245
246 if ( method_exists( $file, 'getWidth' ) ) {
247 $attribs['data-file-width'] = $file->getWidth();
248 }
249
250 if ( method_exists( $file, 'getHeight' ) ) {
251 $attribs['data-file-height'] = $file->getHeight();
252 }
253 }
254
255 return true;
256 }
257}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
$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 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...
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:1776
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 When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password 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:855
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:2012
const NS_FILE
Definition Defines.php:79
const NS_SPECIAL
Definition Defines.php:62
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))