MediaWiki  1.23.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  array( '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  } else {
53  $this->getOutput()->addModules( $modules );
54  }
56  if ( $this->mCaption ) {
57  $output .= "\n\t<li class='gallerycaption'>{$this->mCaption}</li>";
58  }
59 
60  $lang = $this->getRenderLang();
61  # Output each image...
62  foreach ( $this->mImages as $pair ) {
64  $nt = $pair[0];
65  $text = $pair[1]; # "text" means "caption" here
66  $alt = $pair[2];
67  $link = $pair[3];
68 
69  $descQuery = false;
70  if ( $nt->getNamespace() === NS_FILE ) {
71  # Get the file...
72  if ( $this->mParser instanceof Parser ) {
73  # Give extensions a chance to select the file revision for us
74  $options = array();
75  wfRunHooks( 'BeforeParserFetchFileAndTitle',
76  array( $this->mParser, $nt, &$options, &$descQuery ) );
77  # Fetch and register the file (file title may be different via hooks)
78  list( $img, $nt ) = $this->mParser->fetchFileAndTitle( $nt, $options );
79  } else {
80  $img = wfFindFile( $nt );
81  }
82  } else {
83  $img = false;
84  }
85 
86  $params = $this->getThumbParams( $img );
87  // $pair[4] is per image handler options
88  $transformOptions = $params + $pair[4];
89 
90  $thumb = false;
91 
92  if ( !$img ) {
93  # We're dealing with a non-image, spit out the name and be done with it.
94  $thumbhtml = "\n\t\t\t" . '<div class="thumb" style="height: '
95  . ( $this->getThumbPadding() + $this->mHeights ) . 'px;">'
96  . htmlspecialchars( $nt->getText() ) . '</div>';
97 
98  if ( $this->mParser instanceof Parser ) {
99  $this->mParser->addTrackingCategory( 'broken-file-category' );
100  }
101  } elseif ( $this->mHideBadImages
102  && wfIsBadImage( $nt->getDBkey(), $this->getContextTitle() )
103  ) {
104  # The image is blacklisted, just show it as a text link.
105  $thumbhtml = "\n\t\t\t" . '<div class="thumb" style="height: ' .
106  ( $this->getThumbPadding() + $this->mHeights ) . 'px;">' .
108  $nt,
109  htmlspecialchars( $nt->getText() )
110  ) .
111  '</div>';
112  } elseif ( !( $thumb = $img->transform( $transformOptions ) ) ) {
113  # Error generating thumbnail.
114  $thumbhtml = "\n\t\t\t" . '<div class="thumb" style="height: '
115  . ( $this->getThumbPadding() + $this->mHeights ) . 'px;">'
116  . htmlspecialchars( $img->getLastError() ) . '</div>';
117  } else {
119  $vpad = $this->getVPad( $this->mHeights, $thumb->getHeight() );
120 
121  $imageParameters = array(
122  'desc-link' => true,
123  'desc-query' => $descQuery,
124  'alt' => $alt,
125  'custom-url-link' => $link
126  );
127 
128  // In the absence of both alt text and caption, fall back on
129  // providing screen readers with the filename as alt text
130  if ( $alt == '' && $text == '' ) {
131  $imageParameters['alt'] = $nt->getText();
132  }
133 
134  $this->adjustImageParameters( $thumb, $imageParameters );
135 
136  # Set both fixed width and min-height.
137  $thumbhtml = "\n\t\t\t"
138  . '<div class="thumb" style="width: '
139  . $this->getThumbDivWidth( $thumb->getWidth() ) . 'px;">'
140  # Auto-margin centering for block-level elements. Needed
141  # now that we have video handlers since they may emit block-
142  # level elements as opposed to simple <img> tags. ref
143  # http://css-discuss.incutio.com/?page=CenteringBlockElement
144  . '<div style="margin:' . $vpad . 'px auto;">'
145  . $thumb->toHtml( $imageParameters ) . '</div></div>';
146 
147  // Call parser transform hook
149  $handler = $img->getHandler();
150  if ( $this->mParser && $handler ) {
151  $handler->parserTransformHook( $this->mParser, $img );
152  }
153  }
154 
155  // @todo Code is incomplete.
156  // $linkTarget = Title::newFromText( $wgContLang->getNsText( MWNamespace::getUser() ) .
157  // ":{$ut}" );
158  // $ul = Linker::link( $linkTarget, $ut );
159 
160  if ( $this->mShowBytes ) {
161  if ( $img ) {
162  $fileSize = htmlspecialchars( $lang->formatSize( $img->getSize() ) );
163  } else {
164  $fileSize = $this->msg( 'filemissing' )->escaped();
165  }
166  $fileSize = "$fileSize<br />\n";
167  } else {
168  $fileSize = '';
169  }
170 
171  $textlink = $this->mShowFilename ?
173  $nt,
174  htmlspecialchars( $lang->truncate( $nt->getText(), $this->mCaptionLength ) )
175  ) . "<br />\n" :
176  '';
177 
178  $galleryText = $textlink . $text . $fileSize;
179  $galleryText = $this->wrapGalleryText( $galleryText, $thumb );
180 
181  # Weird double wrapping (the extra div inside the li) needed due to FF2 bug
182  # Can be safely removed if FF2 falls completely out of existence
183  $output .= "\n\t\t" . '<li class="gallerybox" style="width: '
184  . $this->getGBWidth( $thumb ) . 'px">'
185  . '<div style="width: ' . $this->getGBWidth( $thumb ) . 'px">'
186  . $thumbhtml
187  . $galleryText
188  . "\n\t\t</div></li>";
189  }
190  $output .= "\n</ul>";
191 
192  return $output;
193  }
194 
203  protected function wrapGalleryText( $galleryText, $thumb ) {
204  # ATTENTION: The newline after <div class="gallerytext"> is needed to
205  # accommodate htmltidy which in version 4.8.6 generated crackpot html in
206  # its absence, see: http://bugzilla.wikimedia.org/show_bug.cgi?id=1765
207  # -Ævar
208 
209  return "\n\t\t\t" . '<div class="gallerytext">' . "\n"
210  . $galleryText
211  . "\n\t\t\t</div>";
212  }
213 
220  protected function getThumbPadding() {
221  return 30;
222  }
223 
229  protected function getGBPadding() {
230  return 5;
231  }
232 
240  protected function getGBBorders() {
241  return 8;
242  }
243 
249  protected function getAllPadding() {
250  return $this->getThumbPadding() + $this->getGBPadding() + $this->getGBBorders();
251  }
252 
262  protected function getVPad( $boxHeight, $thumbHeight ) {
263  return ( $this->getThumbPadding() + $boxHeight - $thumbHeight ) / 2;
264  }
265 
272  protected function getThumbParams( $img ) {
273  return array(
274  'width' => $this->mWidths,
275  'height' => $this->mHeights
276  );
277  }
278 
286  protected function getThumbDivWidth( $thumbWidth ) {
287  return $this->mWidths + $this->getThumbPadding();
288  }
289 
300  protected function getGBWidth( $thumb ) {
301  return $this->mWidths + $this->getThumbPadding() + $this->getGBPadding();
302  }
303 
311  protected function getModules() {
312  return array();
313  }
314 
322  protected function adjustImageParameters( $thumb, &$imageParameters ) {
323  }
324 }
325 
334  function __construct( $mode = 'traditional' ) {
335  wfDeprecated( __METHOD__, '1.22' );
336  parent::__construct( $mode );
337  }
338 }
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
ContextSource\msg
msg()
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:175
TraditionalImageGallery\getThumbParams
getThumbParams( $img)
Get the transform parameters for a thumbnail.
Definition: TraditionalImageGallery.php:272
ImageGalleryBase
Image gallery.
Definition: ImageGalleryBase.php:30
TraditionalImageGallery\toHTML
toHTML()
Return a HTML representation of the image gallery.
Definition: TraditionalImageGallery.php:35
Sanitizer\mergeAttributes
static mergeAttributes( $a, $b)
Merge two sets of HTML attributes.
Definition: Sanitizer.php:807
ImageGalleryBase\getContextTitle
getContextTitle()
Get the contextual title, if applicable.
Definition: ImageGalleryBase.php:316
NS_FILE
const NS_FILE
Definition: Defines.php:85
$params
$params
Definition: styleTest.css.php:40
$link
set to $title object and return false for a match for latest after cache objects are set use the ContentHandler facility to handle CSS and JavaScript for highlighting & $link
Definition: hooks.txt:2149
ImageGallery\__construct
__construct( $mode='traditional')
Create a new image gallery object.
Definition: TraditionalImageGallery.php:334
Xml\openElement
static openElement( $element, $attribs=null)
This opens an XML element.
Definition: Xml.php:109
Linker\linkKnown
static linkKnown( $target, $html=null, $customAttribs=array(), $query=array(), $options=array( 'known', 'noclasses'))
Identical to link(), except $options defaults to 'known'.
Definition: Linker.php:264
TraditionalImageGallery\getGBBorders
getGBBorders()
Get how much extra space the borders around the image takes up.
Definition: TraditionalImageGallery.php:240
TraditionalImageGallery\getVPad
getVPad( $boxHeight, $thumbHeight)
Get vertical padding for a thumbnail.
Definition: TraditionalImageGallery.php:262
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Definition: GlobalFunctions.php:1127
TraditionalImageGallery
Definition: TraditionalImageGallery.php:23
ContextSource\getOutput
getOutput()
Get the OutputPage object.
Definition: ContextSource.php:122
wfRunHooks
wfRunHooks( $event, array $args=array(), $deprecatedVersion=null)
Call hook functions defined in $wgHooks.
Definition: GlobalFunctions.php:4001
TraditionalImageGallery\wrapGalleryText
wrapGalleryText( $galleryText, $thumb)
Add the wrapper html around the thumb's caption.
Definition: TraditionalImageGallery.php:203
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
TraditionalImageGallery\getModules
getModules()
Get a list of modules to include in the page.
Definition: TraditionalImageGallery.php:311
TraditionalImageGallery\getGBWidth
getGBWidth( $thumb)
Width of gallerybox .
Definition: TraditionalImageGallery.php:300
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
$options
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 & $options
Definition: hooks.txt:1530
wfIsBadImage
wfIsBadImage( $name, $contextTitle=false, $blacklist=null)
Determine if an image exists on the 'bad image list'.
Definition: GlobalFunctions.php:4055
TraditionalImageGallery\adjustImageParameters
adjustImageParameters( $thumb, &$imageParameters)
Adjust the image parameters for a thumbnail.
Definition: TraditionalImageGallery.php:322
TraditionalImageGallery\getGBPadding
getGBPadding()
Definition: TraditionalImageGallery.php:229
TraditionalImageGallery\getAllPadding
getAllPadding()
Get total padding.
Definition: TraditionalImageGallery.php:249
block
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LoginAuthenticateAudit' this hook is for auditing only etc block
Definition: hooks.txt:1632
tags
pre inside other HTML tags(bug 54946) !! wikitext a< div >< pre > foo</pre ></div >< pre ></pre > !! html< p >a</p >< div >< pre > foo</pre ></div >< pre ></pre > !! end !! test HTML pre followed by indent-pre !! wikitext< pre >foo</pre > bar !! html< pre >foo</pre >< pre >bar</pre > !! end !!test Block tag pre !!options parsoid !! wikitext< p >< pre >foo</pre ></p > !! html< p data-parsoid
ImageGalleryBase\getRenderLang
getRenderLang()
Determines the correct language to be used for this image gallery.
Definition: ImageGalleryBase.php:326
TraditionalImageGallery\getThumbPadding
getThumbPadding()
How much padding such the thumb have between image and inner div that that contains the border.
Definition: TraditionalImageGallery.php:220
$output
& $output
Definition: hooks.txt:375
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
wfFindFile
wfFindFile( $title, $options=array())
Find a file.
Definition: GlobalFunctions.php:3693
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
$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:1530
TraditionalImageGallery\getThumbDivWidth
getThumbDivWidth( $thumbWidth)
Get the width of the inner div that contains the thumbnail in question.
Definition: TraditionalImageGallery.php:286
ImageGallery
Backwards compatibility.
Definition: TraditionalImageGallery.php:333