MediaWiki
REL1_24
|
00001 <?php 00023 class TraditionalImageGallery extends ImageGalleryBase { 00035 function toHTML() { 00036 if ( $this->mPerRow > 0 ) { 00037 $maxwidth = $this->mPerRow * ( $this->mWidths + $this->getAllPadding() ); 00038 $oldStyle = isset( $this->mAttribs['style'] ) ? $this->mAttribs['style'] : ''; 00039 # _width is ignored by any sane browser. IE6 doesn't know max-width 00040 # so it uses _width instead 00041 $this->mAttribs['style'] = "max-width: {$maxwidth}px;_width: {$maxwidth}px;" . 00042 $oldStyle; 00043 } 00044 00045 $attribs = Sanitizer::mergeAttributes( 00046 array( 'class' => 'gallery mw-gallery-' . $this->mMode ), $this->mAttribs ); 00047 00048 $modules = $this->getModules(); 00049 00050 if ( $this->mParser ) { 00051 $this->mParser->getOutput()->addModules( $modules ); 00052 } else { 00053 $this->getOutput()->addModules( $modules ); 00054 } 00055 $output = Xml::openElement( 'ul', $attribs ); 00056 if ( $this->mCaption ) { 00057 $output .= "\n\t<li class='gallerycaption'>{$this->mCaption}</li>"; 00058 } 00059 00060 $lang = $this->getRenderLang(); 00061 # Output each image... 00062 foreach ( $this->mImages as $pair ) { 00064 $nt = $pair[0]; 00065 $text = $pair[1]; # "text" means "caption" here 00066 $alt = $pair[2]; 00067 $link = $pair[3]; 00068 00069 $descQuery = false; 00070 if ( $nt->getNamespace() === NS_FILE ) { 00071 # Get the file... 00072 if ( $this->mParser instanceof Parser ) { 00073 # Give extensions a chance to select the file revision for us 00074 $options = array(); 00075 wfRunHooks( 'BeforeParserFetchFileAndTitle', 00076 array( $this->mParser, $nt, &$options, &$descQuery ) ); 00077 # Fetch and register the file (file title may be different via hooks) 00078 list( $img, $nt ) = $this->mParser->fetchFileAndTitle( $nt, $options ); 00079 } else { 00080 $img = wfFindFile( $nt ); 00081 } 00082 } else { 00083 $img = false; 00084 } 00085 00086 $params = $this->getThumbParams( $img ); 00087 // $pair[4] is per image handler options 00088 $transformOptions = $params + $pair[4]; 00089 00090 $thumb = false; 00091 00092 if ( !$img ) { 00093 # We're dealing with a non-image, spit out the name and be done with it. 00094 $thumbhtml = "\n\t\t\t" . '<div class="thumb" style="height: ' 00095 . ( $this->getThumbPadding() + $this->mHeights ) . 'px;">' 00096 . htmlspecialchars( $nt->getText() ) . '</div>'; 00097 00098 if ( $this->mParser instanceof Parser ) { 00099 $this->mParser->addTrackingCategory( 'broken-file-category' ); 00100 } 00101 } elseif ( $this->mHideBadImages 00102 && wfIsBadImage( $nt->getDBkey(), $this->getContextTitle() ) 00103 ) { 00104 # The image is blacklisted, just show it as a text link. 00105 $thumbhtml = "\n\t\t\t" . '<div class="thumb" style="height: ' . 00106 ( $this->getThumbPadding() + $this->mHeights ) . 'px;">' . 00107 Linker::linkKnown( 00108 $nt, 00109 htmlspecialchars( $nt->getText() ) 00110 ) . 00111 '</div>'; 00112 } elseif ( !( $thumb = $img->transform( $transformOptions ) ) ) { 00113 # Error generating thumbnail. 00114 $thumbhtml = "\n\t\t\t" . '<div class="thumb" style="height: ' 00115 . ( $this->getThumbPadding() + $this->mHeights ) . 'px;">' 00116 . htmlspecialchars( $img->getLastError() ) . '</div>'; 00117 } else { 00119 $vpad = $this->getVPad( $this->mHeights, $thumb->getHeight() ); 00120 00121 $imageParameters = array( 00122 'desc-link' => true, 00123 'desc-query' => $descQuery, 00124 'alt' => $alt, 00125 'custom-url-link' => $link 00126 ); 00127 00128 // In the absence of both alt text and caption, fall back on 00129 // providing screen readers with the filename as alt text 00130 if ( $alt == '' && $text == '' ) { 00131 $imageParameters['alt'] = $nt->getText(); 00132 } 00133 00134 $this->adjustImageParameters( $thumb, $imageParameters ); 00135 00136 # Set both fixed width and min-height. 00137 $thumbhtml = "\n\t\t\t" 00138 . '<div class="thumb" style="width: ' 00139 . $this->getThumbDivWidth( $thumb->getWidth() ) . 'px;">' 00140 # Auto-margin centering for block-level elements. Needed 00141 # now that we have video handlers since they may emit block- 00142 # level elements as opposed to simple <img> tags. ref 00143 # http://css-discuss.incutio.com/?page=CenteringBlockElement 00144 . '<div style="margin:' . $vpad . 'px auto;">' 00145 . $thumb->toHtml( $imageParameters ) . '</div></div>'; 00146 00147 // Call parser transform hook 00149 $handler = $img->getHandler(); 00150 if ( $this->mParser && $handler ) { 00151 $handler->parserTransformHook( $this->mParser, $img ); 00152 } 00153 } 00154 00155 // @todo Code is incomplete. 00156 // $linkTarget = Title::newFromText( $wgContLang->getNsText( MWNamespace::getUser() ) . 00157 // ":{$ut}" ); 00158 // $ul = Linker::link( $linkTarget, $ut ); 00159 00160 if ( $this->mShowBytes ) { 00161 if ( $img ) { 00162 $fileSize = htmlspecialchars( $lang->formatSize( $img->getSize() ) ); 00163 } else { 00164 $fileSize = $this->msg( 'filemissing' )->escaped(); 00165 } 00166 $fileSize = "$fileSize<br />\n"; 00167 } else { 00168 $fileSize = ''; 00169 } 00170 00171 $textlink = $this->mShowFilename ? 00172 Linker::linkKnown( 00173 $nt, 00174 htmlspecialchars( $lang->truncate( $nt->getText(), $this->mCaptionLength ) ) 00175 ) . "<br />\n" : 00176 ''; 00177 00178 $galleryText = $textlink . $text . $fileSize; 00179 $galleryText = $this->wrapGalleryText( $galleryText, $thumb ); 00180 00181 # Weird double wrapping (the extra div inside the li) needed due to FF2 bug 00182 # Can be safely removed if FF2 falls completely out of existence 00183 $output .= "\n\t\t" . '<li class="gallerybox" style="width: ' 00184 . $this->getGBWidth( $thumb ) . 'px">' 00185 . '<div style="width: ' . $this->getGBWidth( $thumb ) . 'px">' 00186 . $thumbhtml 00187 . $galleryText 00188 . "\n\t\t</div></li>"; 00189 } 00190 $output .= "\n</ul>"; 00191 00192 return $output; 00193 } 00194 00203 protected function wrapGalleryText( $galleryText, $thumb ) { 00204 # ATTENTION: The newline after <div class="gallerytext"> is needed to 00205 # accommodate htmltidy which in version 4.8.6 generated crackpot html in 00206 # its absence, see: http://bugzilla.wikimedia.org/show_bug.cgi?id=1765 00207 # -Ævar 00208 00209 return "\n\t\t\t" . '<div class="gallerytext">' . "\n" 00210 . $galleryText 00211 . "\n\t\t\t</div>"; 00212 } 00213 00220 protected function getThumbPadding() { 00221 return 30; 00222 } 00223 00229 protected function getGBPadding() { 00230 return 5; 00231 } 00232 00240 protected function getGBBorders() { 00241 return 8; 00242 } 00243 00249 protected function getAllPadding() { 00250 return $this->getThumbPadding() + $this->getGBPadding() + $this->getGBBorders(); 00251 } 00252 00262 protected function getVPad( $boxHeight, $thumbHeight ) { 00263 return ( $this->getThumbPadding() + $boxHeight - $thumbHeight ) / 2; 00264 } 00265 00272 protected function getThumbParams( $img ) { 00273 return array( 00274 'width' => $this->mWidths, 00275 'height' => $this->mHeights 00276 ); 00277 } 00278 00286 protected function getThumbDivWidth( $thumbWidth ) { 00287 return $this->mWidths + $this->getThumbPadding(); 00288 } 00289 00300 protected function getGBWidth( $thumb ) { 00301 return $this->mWidths + $this->getThumbPadding() + $this->getGBPadding(); 00302 } 00303 00311 protected function getModules() { 00312 return array(); 00313 } 00314 00322 protected function adjustImageParameters( $thumb, &$imageParameters ) { 00323 } 00324 } 00325 00333 class ImageGallery extends TraditionalImageGallery { 00334 function __construct( $mode = 'traditional' ) { 00335 wfDeprecated( __METHOD__, '1.22' ); 00336 parent::__construct( $mode ); 00337 } 00338 }