MediaWiki  1.27.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 
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  $lang = $this->getRenderLang();
63  # Output each image...
64  foreach ( $this->mImages as $pair ) {
66  $nt = $pair[0];
67  $text = $pair[1]; # "text" means "caption" here
68  $alt = $pair[2];
69  $link = $pair[3];
70 
71  $descQuery = false;
72  if ( $nt->getNamespace() === NS_FILE ) {
73  # Get the file...
74  if ( $this->mParser instanceof Parser ) {
75  # Give extensions a chance to select the file revision for us
76  $options = [];
77  Hooks::run( 'BeforeParserFetchFileAndTitle',
78  [ $this->mParser, $nt, &$options, &$descQuery ] );
79  # Fetch and register the file (file title may be different via hooks)
80  list( $img, $nt ) = $this->mParser->fetchFileAndTitle( $nt, $options );
81  } else {
82  $img = wfFindFile( $nt );
83  }
84  } else {
85  $img = false;
86  }
87 
88  $params = $this->getThumbParams( $img );
89  // $pair[4] is per image handler options
90  $transformOptions = $params + $pair[4];
91 
92  $thumb = false;
93 
94  if ( !$img ) {
95  # We're dealing with a non-image, spit out the name and be done with it.
96  $thumbhtml = "\n\t\t\t" . '<div class="thumb" style="height: '
97  . ( $this->getThumbPadding() + $this->mHeights ) . 'px;">'
98  . htmlspecialchars( $nt->getText() ) . '</div>';
99 
100  if ( $this->mParser instanceof Parser ) {
101  $this->mParser->addTrackingCategory( 'broken-file-category' );
102  }
103  } elseif ( $this->mHideBadImages
104  && wfIsBadImage( $nt->getDBkey(), $this->getContextTitle() )
105  ) {
106  # The image is blacklisted, just show it as a text link.
107  $thumbhtml = "\n\t\t\t" . '<div class="thumb" style="height: ' .
108  ( $this->getThumbPadding() + $this->mHeights ) . 'px;">' .
110  $nt,
111  htmlspecialchars( $nt->getText() )
112  ) .
113  '</div>';
114  } else {
115  $thumb = $img->transform( $transformOptions );
116  if ( !$thumb ) {
117  # Error generating thumbnail.
118  $thumbhtml = "\n\t\t\t" . '<div class="thumb" style="height: '
119  . ( $this->getThumbPadding() + $this->mHeights ) . 'px;">'
120  . htmlspecialchars( $img->getLastError() ) . '</div>';
121  } else {
123  $vpad = $this->getVPad( $this->mHeights, $thumb->getHeight() );
124 
125  $imageParameters = [
126  'desc-link' => true,
127  'desc-query' => $descQuery,
128  'alt' => $alt,
129  'custom-url-link' => $link
130  ];
131 
132  // In the absence of both alt text and caption, fall back on
133  // providing screen readers with the filename as alt text
134  if ( $alt == '' && $text == '' ) {
135  $imageParameters['alt'] = $nt->getText();
136  }
137 
138  $this->adjustImageParameters( $thumb, $imageParameters );
139 
140  Linker::processResponsiveImages( $img, $thumb, $transformOptions );
141 
142  # Set both fixed width and min-height.
143  $thumbhtml = "\n\t\t\t"
144  . '<div class="thumb" style="width: '
145  . $this->getThumbDivWidth( $thumb->getWidth() ) . 'px;">'
146  # Auto-margin centering for block-level elements. Needed
147  # now that we have video handlers since they may emit block-
148  # level elements as opposed to simple <img> tags. ref
149  # http://css-discuss.incutio.com/?page=CenteringBlockElement
150  . '<div style="margin:' . $vpad . 'px auto;">'
151  . $thumb->toHtml( $imageParameters ) . '</div></div>';
152 
153  // Call parser transform hook
155  $handler = $img->getHandler();
156  if ( $this->mParser && $handler ) {
157  $handler->parserTransformHook( $this->mParser, $img );
158  }
159  }
160  }
161 
162  // @todo Code is incomplete.
163  // $linkTarget = Title::newFromText( $wgContLang->getNsText( MWNamespace::getUser() ) .
164  // ":{$ut}" );
165  // $ul = Linker::link( $linkTarget, $ut );
166 
167  if ( $this->mShowBytes ) {
168  if ( $img ) {
169  $fileSize = htmlspecialchars( $lang->formatSize( $img->getSize() ) );
170  } else {
171  $fileSize = $this->msg( 'filemissing' )->escaped();
172  }
173  $fileSize = "$fileSize<br />\n";
174  } else {
175  $fileSize = '';
176  }
177 
178  $textlink = $this->mShowFilename ?
180  $nt,
181  htmlspecialchars( $lang->truncate( $nt->getText(), $this->mCaptionLength ) )
182  ) . "<br />\n" :
183  '';
184 
185  $galleryText = $textlink . $text . $fileSize;
186  $galleryText = $this->wrapGalleryText( $galleryText, $thumb );
187 
188  # Weird double wrapping (the extra div inside the li) needed due to FF2 bug
189  # Can be safely removed if FF2 falls completely out of existence
190  $output .= "\n\t\t" . '<li class="gallerybox" style="width: '
191  . $this->getGBWidth( $thumb ) . 'px">'
192  . '<div style="width: ' . $this->getGBWidth( $thumb ) . 'px">'
193  . $thumbhtml
194  . $galleryText
195  . "\n\t\t</div></li>";
196  }
197  $output .= "\n</ul>";
198 
199  return $output;
200  }
201 
210  protected function wrapGalleryText( $galleryText, $thumb ) {
211  # ATTENTION: The newline after <div class="gallerytext"> is needed to
212  # accommodate htmltidy which in version 4.8.6 generated crackpot html in
213  # its absence, see: https://phabricator.wikimedia.org/T3765
214  # -Ævar
215 
216  return "\n\t\t\t" . '<div class="gallerytext">' . "\n"
217  . $galleryText
218  . "\n\t\t\t</div>";
219  }
220 
227  protected function getThumbPadding() {
228  return 30;
229  }
230 
236  protected function getGBPadding() {
237  return 5;
238  }
239 
247  protected function getGBBorders() {
248  return 8;
249  }
250 
256  protected function getAllPadding() {
257  return $this->getThumbPadding() + $this->getGBPadding() + $this->getGBBorders();
258  }
259 
269  protected function getVPad( $boxHeight, $thumbHeight ) {
270  return ( $this->getThumbPadding() + $boxHeight - $thumbHeight ) / 2;
271  }
272 
279  protected function getThumbParams( $img ) {
280  return [
281  'width' => $this->mWidths,
282  'height' => $this->mHeights
283  ];
284  }
285 
293  protected function getThumbDivWidth( $thumbWidth ) {
294  return $this->mWidths + $this->getThumbPadding();
295  }
296 
307  protected function getGBWidth( $thumb ) {
308  return $this->mWidths + $this->getThumbPadding() + $this->getGBPadding();
309  }
310 
318  protected function getModules() {
319  return [];
320  }
321 
329  protected function adjustImageParameters( $thumb, &$imageParameters ) {
330  }
331 }
332 
341  function __construct( $mode = 'traditional' ) {
342  wfDeprecated( __METHOD__, '1.22' );
343  parent::__construct( $mode );
344  }
345 }
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
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
Backwards compatibility.
static processResponsiveImages($file, $thumb, $hp)
Process responsive images: add 1.5x and 2x subimages to the thumbnail, where applicable.
Definition: Linker.php:878
static linkKnown($target, $html=null, $customAttribs=[], $query=[], $options=[ 'known', 'noclasses'])
Identical to link(), except $options defaults to 'known'.
Definition: Linker.php:264
getThumbDivWidth($thumbWidth)
Get the width of the inner div that contains the thumbnail in question.
if(!isset($args[0])) $lang
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
getGBBorders()
Get how much extra space the borders around the image takes up.
wfIsBadImage($name, $contextTitle=false, $blacklist=null)
Determine if an image exists on the 'bad image list'.
toHTML()
Return a HTML representation of the image gallery.
Apache License January http
the value to return A Title object or null for latest to be modified or replaced by the hook handler or if authentication is not possible after cache objects are set for highlighting & $link
Definition: hooks.txt:2581
__construct($mode= 'traditional')
adjustImageParameters($thumb, &$imageParameters)
Adjust the image parameters for a thumbnail.
msg()
Get a Message object with context set Parameters are the same as wfMessage()
getRenderLang()
Determines the correct language to be used for this image gallery.
wrapGalleryText($galleryText, $thumb)
Add the wrapper html around the thumb's caption.
getVPad($boxHeight, $thumbHeight)
Get vertical padding for a thumbnail.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist 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:1004
getModules()
Get a list of modules to include in the page.
static mergeAttributes($a, $b)
Merge two sets of HTML attributes.
Definition: Sanitizer.php:839
static openElement($element, $attribs=null)
This opens an XML element.
Definition: Xml.php:109
$params
wfDeprecated($function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
getAllPadding()
Get total padding.
static run($event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:131
const NS_FILE
Definition: Defines.php:75
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
getContextTitle()
Get the contextual title, if applicable.
getThumbPadding()
How much padding such the thumb have between image and inner div that that contains the border...
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist 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:1004
Image gallery.
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
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:762
getGBWidth($thumb)
Width of gallerybox .
wfFindFile($title, $options=[])
Find a file.
this hook is for auditing only etc 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:1946
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:1798
getThumbParams($img)
Get the transform parameters for a thumbnail.
getOutput()
Get the OutputPage object.