MediaWiki  1.29.2
TraditionalImageGallery.php
Go to the documentation of this file.
1 <?php
35  function toHTML() {
36  if ( $this->mPerRow > 0 ) {
37  $maxwidth = $this->mPerRow * ( $this->mWidths + $this->getAllPadding() );
38  $oldStyle = isset( $this->mAttribs['style'] ) ? $this->mAttribs['style'] : '';
39  # _width is ignored by any sane browser. IE6 doesn't know max-width
40  # so it uses _width instead
41  $this->mAttribs['style'] = "max-width: {$maxwidth}px;_width: {$maxwidth}px;" .
42  $oldStyle;
43  }
44 
45  $attribs = Sanitizer::mergeAttributes(
46  [ 'class' => 'gallery mw-gallery-' . $this->mMode ], $this->mAttribs );
47 
48  $modules = $this->getModules();
49 
50  if ( $this->mParser ) {
51  $this->mParser->getOutput()->addModules( $modules );
52  $this->mParser->getOutput()->addModuleStyles( 'mediawiki.page.gallery.styles' );
53  } else {
54  $this->getOutput()->addModules( $modules );
55  $this->getOutput()->addModuleStyles( 'mediawiki.page.gallery.styles' );
56  }
58  if ( $this->mCaption ) {
59  $output .= "\n\t<li class='gallerycaption'>{$this->mCaption}</li>";
60  }
61 
62  if ( $this->mShowFilename ) {
63  // Preload LinkCache info for when generating links
64  // of the filename below
65  $lb = new LinkBatch();
66  foreach ( $this->mImages as $img ) {
67  $lb->addObj( $img[0] );
68  }
69  $lb->execute();
70  }
71 
72  $lang = $this->getRenderLang();
73  # Output each image...
74  foreach ( $this->mImages as $pair ) {
76  $nt = $pair[0];
77  $text = $pair[1]; # "text" means "caption" here
78  $alt = $pair[2];
79  $link = $pair[3];
80 
81  $descQuery = false;
82  if ( $nt->getNamespace() === NS_FILE ) {
83  # Get the file...
84  if ( $this->mParser instanceof Parser ) {
85  # Give extensions a chance to select the file revision for us
86  $options = [];
87  Hooks::run( 'BeforeParserFetchFileAndTitle',
88  [ $this->mParser, $nt, &$options, &$descQuery ] );
89  # Fetch and register the file (file title may be different via hooks)
90  list( $img, $nt ) = $this->mParser->fetchFileAndTitle( $nt, $options );
91  } else {
92  $img = wfFindFile( $nt );
93  }
94  } else {
95  $img = false;
96  }
97 
98  $params = $this->getThumbParams( $img );
99  // $pair[4] is per image handler options
100  $transformOptions = $params + $pair[4];
101 
102  $thumb = false;
103 
104  if ( !$img ) {
105  # We're dealing with a non-image, spit out the name and be done with it.
106  $thumbhtml = "\n\t\t\t" . '<div class="thumb" style="height: '
107  . ( $this->getThumbPadding() + $this->mHeights ) . 'px;">'
108  . htmlspecialchars( $nt->getText() ) . '</div>';
109 
110  if ( $this->mParser instanceof Parser ) {
111  $this->mParser->addTrackingCategory( 'broken-file-category' );
112  }
113  } elseif ( $this->mHideBadImages
114  && wfIsBadImage( $nt->getDBkey(), $this->getContextTitle() )
115  ) {
116  # The image is blacklisted, just show it as a text link.
117  $thumbhtml = "\n\t\t\t" . '<div class="thumb" style="height: ' .
118  ( $this->getThumbPadding() + $this->mHeights ) . 'px;">' .
120  $nt,
121  htmlspecialchars( $nt->getText() )
122  ) .
123  '</div>';
124  } else {
125  $thumb = $img->transform( $transformOptions );
126  if ( !$thumb ) {
127  # Error generating thumbnail.
128  $thumbhtml = "\n\t\t\t" . '<div class="thumb" style="height: '
129  . ( $this->getThumbPadding() + $this->mHeights ) . 'px;">'
130  . htmlspecialchars( $img->getLastError() ) . '</div>';
131  } else {
133  $vpad = $this->getVPad( $this->mHeights, $thumb->getHeight() );
134 
135  $imageParameters = [
136  'desc-link' => true,
137  'desc-query' => $descQuery,
138  'alt' => $alt,
139  'custom-url-link' => $link
140  ];
141 
142  // In the absence of both alt text and caption, fall back on
143  // providing screen readers with the filename as alt text
144  if ( $alt == '' && $text == '' ) {
145  $imageParameters['alt'] = $nt->getText();
146  }
147 
148  $this->adjustImageParameters( $thumb, $imageParameters );
149 
150  Linker::processResponsiveImages( $img, $thumb, $transformOptions );
151 
152  # Set both fixed width and min-height.
153  $thumbhtml = "\n\t\t\t"
154  . '<div class="thumb" style="width: '
155  . $this->getThumbDivWidth( $thumb->getWidth() ) . 'px;">'
156  # Auto-margin centering for block-level elements. Needed
157  # now that we have video handlers since they may emit block-
158  # level elements as opposed to simple <img> tags. ref
159  # http://css-discuss.incutio.com/?page=CenteringBlockElement
160  . '<div style="margin:' . $vpad . 'px auto;">'
161  . $thumb->toHtml( $imageParameters ) . '</div></div>';
162 
163  // Call parser transform hook
165  $handler = $img->getHandler();
166  if ( $this->mParser && $handler ) {
167  $handler->parserTransformHook( $this->mParser, $img );
168  }
169  }
170  }
171 
172  // @todo Code is incomplete.
173  // $linkTarget = Title::newFromText( $wgContLang->getNsText( MWNamespace::getUser() ) .
174  // ":{$ut}" );
175  // $ul = Linker::link( $linkTarget, $ut );
176 
177  if ( $this->mShowBytes ) {
178  if ( $img ) {
179  $fileSize = htmlspecialchars( $lang->formatSize( $img->getSize() ) );
180  } else {
181  $fileSize = $this->msg( 'filemissing' )->escaped();
182  }
183  $fileSize = "$fileSize<br />\n";
184  } else {
185  $fileSize = '';
186  }
187 
188  $textlink = $this->mShowFilename ?
189  // Preloaded into LinkCache above
191  $nt,
192  htmlspecialchars(
193  $this->mCaptionLength !== true ?
194  $lang->truncate( $nt->getText(), $this->mCaptionLength ) :
195  $nt->getText()
196  ),
197  [
198  'class' => 'galleryfilename' .
199  ( $this->mCaptionLength === true ? ' galleryfilename-truncate' : '' )
200  ]
201  ) . "\n" :
202  '';
203 
204  $galleryText = $textlink . $text . $fileSize;
205  $galleryText = $this->wrapGalleryText( $galleryText, $thumb );
206 
207  # Weird double wrapping (the extra div inside the li) needed due to FF2 bug
208  # Can be safely removed if FF2 falls completely out of existence
209  $output .= "\n\t\t" . '<li class="gallerybox" style="width: '
210  . $this->getGBWidth( $thumb ) . 'px">'
211  . '<div style="width: ' . $this->getGBWidth( $thumb ) . 'px">'
212  . $thumbhtml
213  . $galleryText
214  . "\n\t\t</div></li>";
215  }
216  $output .= "\n</ul>";
217 
218  return $output;
219  }
220 
229  protected function wrapGalleryText( $galleryText, $thumb ) {
230  # ATTENTION: The newline after <div class="gallerytext"> is needed to
231  # accommodate htmltidy which in version 4.8.6 generated crackpot html in
232  # its absence, see: https://phabricator.wikimedia.org/T3765
233  # -Ævar
234 
235  return "\n\t\t\t" . '<div class="gallerytext">' . "\n"
236  . $galleryText
237  . "\n\t\t\t</div>";
238  }
239 
246  protected function getThumbPadding() {
247  return 30;
248  }
249 
255  protected function getGBPadding() {
256  return 5;
257  }
258 
266  protected function getGBBorders() {
267  return 8;
268  }
269 
275  protected function getAllPadding() {
276  return $this->getThumbPadding() + $this->getGBPadding() + $this->getGBBorders();
277  }
278 
288  protected function getVPad( $boxHeight, $thumbHeight ) {
289  return ( $this->getThumbPadding() + $boxHeight - $thumbHeight ) / 2;
290  }
291 
298  protected function getThumbParams( $img ) {
299  return [
300  'width' => $this->mWidths,
301  'height' => $this->mHeights
302  ];
303  }
304 
312  protected function getThumbDivWidth( $thumbWidth ) {
313  return $this->mWidths + $this->getThumbPadding();
314  }
315 
326  protected function getGBWidth( $thumb ) {
327  return $this->mWidths + $this->getThumbPadding() + $this->getGBPadding();
328  }
329 
337  protected function getModules() {
338  return [];
339  }
340 
348  protected function adjustImageParameters( $thumb, &$imageParameters ) {
349  }
350 }
ContextSource\msg
msg()
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:187
LinkBatch
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition: LinkBatch.php:34
TraditionalImageGallery\getThumbParams
getThumbParams( $img)
Get the transform parameters for a thumbnail.
Definition: TraditionalImageGallery.php:298
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
ImageGalleryBase
Image gallery.
Definition: ImageGalleryBase.php:30
TraditionalImageGallery\toHTML
toHTML()
Return a HTML representation of the image gallery.
Definition: TraditionalImageGallery.php:35
ImageGalleryBase\getContextTitle
getContextTitle()
Get the contextual title, if applicable.
Definition: ImageGalleryBase.php:347
NS_FILE
const NS_FILE
Definition: Defines.php:68
$params
$params
Definition: styleTest.css.php:40
Linker\linkKnown
static linkKnown( $target, $html=null, $customAttribs=[], $query=[], $options=[ 'known'])
Identical to link(), except $options defaults to 'known'.
Definition: Linker.php:159
Linker\processResponsiveImages
static processResponsiveImages( $file, $thumb, $hp)
Process responsive images: add 1.5x and 2x subimages to the thumbnail, where applicable.
Definition: Linker.php:650
http
Apache License January http
Definition: APACHE-LICENSE-2.0.txt:3
block
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging a wrapping ErrorException instead of letting the login form give the generic error message that the account does not exist For when the account has been renamed or deleted or an array to pass a message key and parameters block
Definition: hooks.txt:2122
Xml\openElement
static openElement( $element, $attribs=null)
This opens an XML element.
Definition: Xml.php:109
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
means
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control means(i) the power
TraditionalImageGallery\getGBBorders
getGBBorders()
Get how much extra space the borders around the image takes up.
Definition: TraditionalImageGallery.php:266
TraditionalImageGallery\getVPad
getVPad( $boxHeight, $thumbHeight)
Get vertical padding for a thumbnail.
Definition: TraditionalImageGallery.php:288
they
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 they
Definition: COPYING.txt:28
TraditionalImageGallery
Definition: TraditionalImageGallery.php:23
ContextSource\getOutput
getOutput()
Get the OutputPage object.
Definition: ContextSource.php:123
$attribs
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:1956
$modules
$modules
Definition: HTMLFormElement.php:12
TraditionalImageGallery\wrapGalleryText
wrapGalleryText( $galleryText, $thumb)
Add the wrapper html around the thumb's caption.
Definition: TraditionalImageGallery.php:229
$output
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object & $output
Definition: hooks.txt:1049
TraditionalImageGallery\getModules
getModules()
Get a list of modules to include in the page.
Definition: TraditionalImageGallery.php:337
TraditionalImageGallery\getGBWidth
getGBWidth( $thumb)
Width of gallerybox .
Definition: TraditionalImageGallery.php:326
list
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
wfIsBadImage
wfIsBadImage( $name, $contextTitle=false, $blacklist=null)
Determine if an image exists on the 'bad image list'.
Definition: GlobalFunctions.php:3496
TraditionalImageGallery\adjustImageParameters
adjustImageParameters( $thumb, &$imageParameters)
Adjust the image parameters for a thumbnail.
Definition: TraditionalImageGallery.php:348
TraditionalImageGallery\getGBPadding
getGBPadding()
Definition: TraditionalImageGallery.php:255
TraditionalImageGallery\getAllPadding
getAllPadding()
Get total padding.
Definition: TraditionalImageGallery.php:275
$handler
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 modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves $handler
Definition: hooks.txt:783
wfFindFile
wfFindFile( $title, $options=[])
Find a file.
Definition: GlobalFunctions.php:3101
ImageGalleryBase\getRenderLang
getRenderLang()
Determines the correct language to be used for this image gallery.
Definition: ImageGalleryBase.php:357
TraditionalImageGallery\getThumbPadding
getThumbPadding()
How much padding the thumb has between the image and the inner div that contains the border.
Definition: TraditionalImageGallery.php:246
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
$link
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition: hooks.txt:2929
that
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global then executing the whole list after the page is displayed We don t do anything smart like collating updates to the same table or such because the list is almost always going to have just one item on if that
Definition: deferred.txt:11
TraditionalImageGallery\getThumbDivWidth
getThumbDivWidth( $thumbWidth)
Get the width of the inner div that contains the thumbnail in question.
Definition: TraditionalImageGallery.php:312
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:131
$options
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
Definition: hooks.txt:1049