MediaWiki
REL1_22
|
00001 <?php 00023 class TraditionalImageGallery extends ImageGalleryBase { 00024 00025 00037 function toHTML() { 00038 if ( $this->mPerRow > 0 ) { 00039 $maxwidth = $this->mPerRow * ( $this->mWidths + $this->getAllPadding() ); 00040 $oldStyle = isset( $this->mAttribs['style'] ) ? $this->mAttribs['style'] : ''; 00041 # _width is ignored by any sane browser. IE6 doesn't know max-width so it uses _width instead 00042 $this->mAttribs['style'] = "max-width: {$maxwidth}px;_width: {$maxwidth}px;" . $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 ) { 00063 $nt = $pair[0]; 00064 $text = $pair[1]; # "text" means "caption" here 00065 $alt = $pair[2]; 00066 $link = $pair[3]; 00067 00068 $descQuery = false; 00069 if ( $nt->getNamespace() === NS_FILE ) { 00070 # Get the file... 00071 if ( $this->mParser instanceof Parser ) { 00072 # Give extensions a chance to select the file revision for us 00073 $options = array(); 00074 wfRunHooks( 'BeforeParserFetchFileAndTitle', 00075 array( $this->mParser, $nt, &$options, &$descQuery ) ); 00076 # Fetch and register the file (file title may be different via hooks) 00077 list( $img, $nt ) = $this->mParser->fetchFileAndTitle( $nt, $options ); 00078 } else { 00079 $img = wfFindFile( $nt ); 00080 } 00081 } else { 00082 $img = false; 00083 } 00084 00085 $params = $this->getThumbParams( $img ); 00086 // $pair[4] is per image handler options 00087 $transformOptions = $params + $pair[4]; 00088 00089 $thumb = false; 00090 00091 if ( !$img ) { 00092 # We're dealing with a non-image, spit out the name and be done with it. 00093 $thumbhtml = "\n\t\t\t" . '<div class="thumb" style="height: ' . ( $this->getThumbPadding() + $this->mHeights ) . 'px;">' 00094 . htmlspecialchars( $nt->getText() ) . '</div>'; 00095 00096 if ( $this->mParser instanceof Parser ) { 00097 $this->mParser->addTrackingCategory( 'broken-file-category' ); 00098 } 00099 } elseif ( $this->mHideBadImages && wfIsBadImage( $nt->getDBkey(), $this->getContextTitle() ) ) { 00100 # The image is blacklisted, just show it as a text link. 00101 $thumbhtml = "\n\t\t\t" . '<div class="thumb" style="height: ' . ( $this->getThumbPadding() + $this->mHeights ) . 'px;">' . 00102 Linker::link( 00103 $nt, 00104 htmlspecialchars( $nt->getText() ), 00105 array(), 00106 array(), 00107 array( 'known', 'noclasses' ) 00108 ) . 00109 '</div>'; 00110 } elseif ( !( $thumb = $img->transform( $transformOptions ) ) ) { 00111 # Error generating thumbnail. 00112 $thumbhtml = "\n\t\t\t" . '<div class="thumb" style="height: ' . ( $this->getThumbPadding() + $this->mHeights ) . 'px;">' 00113 . htmlspecialchars( $img->getLastError() ) . '</div>'; 00114 } else { 00115 $vpad = $this->getVPad( $this->mHeights, $thumb->getHeight() ); 00116 00117 $imageParameters = array( 00118 'desc-link' => true, 00119 'desc-query' => $descQuery, 00120 'alt' => $alt, 00121 'custom-url-link' => $link 00122 ); 00123 # In the absence of both alt text and caption, fall back on providing screen readers with the filename as alt text 00124 if ( $alt == '' && $text == '' ) { 00125 $imageParameters['alt'] = $nt->getText(); 00126 } 00127 00128 $this->adjustImageParameters( $thumb, $imageParameters ); 00129 00130 # Set both fixed width and min-height. 00131 $thumbhtml = "\n\t\t\t" . 00132 '<div class="thumb" style="width: ' . $this->getThumbDivWidth( $thumb->getWidth() ) . 'px;">' 00133 # Auto-margin centering for block-level elements. Needed now that we have video 00134 # handlers since they may emit block-level elements as opposed to simple <img> tags. 00135 # ref http://css-discuss.incutio.com/?page=CenteringBlockElement 00136 . '<div style="margin:' . $vpad . 'px auto;">' 00137 . $thumb->toHtml( $imageParameters ) . '</div></div>'; 00138 00139 // Call parser transform hook 00140 if ( $this->mParser && $img->getHandler() ) { 00141 $img->getHandler()->parserTransformHook( $this->mParser, $img ); 00142 } 00143 } 00144 00145 //TODO 00146 // $linkTarget = Title::newFromText( $wgContLang->getNsText( MWNamespace::getUser() ) . ":{$ut}" ); 00147 // $ul = Linker::link( $linkTarget, $ut ); 00148 00149 if ( $this->mShowBytes ) { 00150 if ( $img ) { 00151 $fileSize = htmlspecialchars( $lang->formatSize( $img->getSize() ) ); 00152 } else { 00153 $fileSize = $this->msg( 'filemissing' )->escaped(); 00154 } 00155 $fileSize = "$fileSize<br />\n"; 00156 } else { 00157 $fileSize = ''; 00158 } 00159 00160 $textlink = $this->mShowFilename ? 00161 Linker::link( 00162 $nt, 00163 htmlspecialchars( $lang->truncate( $nt->getText(), $this->mCaptionLength ) ), 00164 array(), 00165 array(), 00166 array( 'known', 'noclasses' ) 00167 ) . "<br />\n" : 00168 ''; 00169 00170 00171 $galleryText = $textlink . $text . $fileSize; 00172 $galleryText = $this->wrapGalleryText( $galleryText, $thumb ); 00173 00174 # Weird double wrapping (the extra div inside the li) needed due to FF2 bug 00175 # Can be safely removed if FF2 falls completely out of existence 00176 $output .= 00177 "\n\t\t" . '<li class="gallerybox" style="width: ' . $this->getGBWidth( $thumb ) . 'px">' 00178 . '<div style="width: ' . $this->getGBWidth( $thumb ) . 'px">' 00179 . $thumbhtml 00180 . $galleryText 00181 . "\n\t\t</div></li>"; 00182 } 00183 $output .= "\n</ul>"; 00184 00185 return $output; 00186 } 00187 00188 00195 protected function wrapGalleryText( $galleryText, $thumb ) { 00196 # ATTENTION: The newline after <div class="gallerytext"> is needed to accommodate htmltidy which 00197 # in version 4.8.6 generated crackpot html in its absence, see: 00198 # http://bugzilla.wikimedia.org/show_bug.cgi?id=1765 -Ævar 00199 00200 return "\n\t\t\t" . '<div class="gallerytext">' . "\n" 00201 . $galleryText 00202 . "\n\t\t\t</div>"; 00203 } 00204 00211 protected function getThumbPadding() { 00212 return 30; 00213 } 00214 00221 protected function getGBPadding() { 00222 return 5; 00223 } 00224 00232 protected function getGBBorders() { 00233 return 8; 00234 } 00235 00241 protected function getAllPadding() { 00242 return $this->getThumbPadding() + $this->getGBPadding() + $this->getGBBorders(); 00243 } 00244 00254 protected function getVPad( $boxHeight, $thumbHeight ) { 00255 return ( $this->getThumbPadding() + $boxHeight - $thumbHeight ) / 2; 00256 } 00257 00263 protected function getThumbParams( $img ) { 00264 return array( 00265 'width' => $this->mWidths, 00266 'height' => $this->mHeights 00267 ); 00268 } 00269 00277 protected function getThumbDivWidth( $thumbWidth ) { 00278 return $this->mWidths + $this->getThumbPadding(); 00279 } 00280 00291 protected function getGBWidth( $thumb ) { 00292 return $this->mWidths + $this->getThumbPadding() + $this->getGBPadding(); 00293 } 00294 00302 protected function getModules() { 00303 return array(); 00304 } 00305 00313 protected function adjustImageParameters( $thumb, &$imageParameters ) { } 00314 } 00315 00323 class ImageGallery extends TraditionalImageGallery { 00324 function __construct( $mode = 'traditional' ) { 00325 wfDeprecated( __METHOD__, '1.22' ); 00326 parent::__construct( $mode ); 00327 } 00328 }