MediaWiki
REL1_23
|
00001 <?php 00028 class ImagePage extends Article { 00029 00033 private $displayImg; 00037 private $repo; 00038 private $fileLoaded; 00039 00040 var $mExtraDescription = false; 00041 00046 protected function newPage( Title $title ) { 00047 // Overload mPage with a file-specific page 00048 return new WikiFilePage( $title ); 00049 } 00050 00056 public static function newFromID( $id ) { 00057 $t = Title::newFromID( $id ); 00058 # @todo FIXME: Doesn't inherit right 00059 return $t == null ? null : new self( $t ); 00060 # return $t == null ? null : new static( $t ); // PHP 5.3 00061 } 00062 00067 public function setFile( $file ) { 00068 $this->mPage->setFile( $file ); 00069 $this->displayImg = $file; 00070 $this->fileLoaded = true; 00071 } 00072 00073 protected function loadFile() { 00074 if ( $this->fileLoaded ) { 00075 return; 00076 } 00077 $this->fileLoaded = true; 00078 00079 $this->displayImg = $img = false; 00080 wfRunHooks( 'ImagePageFindFile', array( $this, &$img, &$this->displayImg ) ); 00081 if ( !$img ) { // not set by hook? 00082 $img = wfFindFile( $this->getTitle() ); 00083 if ( !$img ) { 00084 $img = wfLocalFile( $this->getTitle() ); 00085 } 00086 } 00087 $this->mPage->setFile( $img ); 00088 if ( !$this->displayImg ) { // not set by hook? 00089 $this->displayImg = $img; 00090 } 00091 $this->repo = $img->getRepo(); 00092 } 00093 00098 public function render() { 00099 $this->getContext()->getOutput()->setArticleBodyOnly( true ); 00100 parent::view(); 00101 } 00102 00103 public function view() { 00104 global $wgShowEXIF; 00105 00106 $out = $this->getContext()->getOutput(); 00107 $request = $this->getContext()->getRequest(); 00108 $diff = $request->getVal( 'diff' ); 00109 $diffOnly = $request->getBool( 'diffonly', $this->getContext()->getUser()->getOption( 'diffonly' ) ); 00110 00111 if ( $this->getTitle()->getNamespace() != NS_FILE || ( $diff !== null && $diffOnly ) ) { 00112 parent::view(); 00113 return; 00114 } 00115 00116 $this->loadFile(); 00117 00118 if ( $this->getTitle()->getNamespace() == NS_FILE && $this->mPage->getFile()->getRedirected() ) { 00119 if ( $this->getTitle()->getDBkey() == $this->mPage->getFile()->getName() || $diff !== null ) { 00120 // mTitle is the same as the redirect target so ask Article 00121 // to perform the redirect for us. 00122 $request->setVal( 'diffonly', 'true' ); 00123 parent::view(); 00124 return; 00125 } else { 00126 // mTitle is not the same as the redirect target so it is 00127 // probably the redirect page itself. Fake the redirect symbol 00128 $out->setPageTitle( $this->getTitle()->getPrefixedText() ); 00129 $out->addHTML( $this->viewRedirect( Title::makeTitle( NS_FILE, $this->mPage->getFile()->getName() ), 00130 /* $appendSubtitle */ true, /* $forceKnown */ true ) ); 00131 $this->mPage->doViewUpdates( $this->getContext()->getUser(), $this->getOldID() ); 00132 return; 00133 } 00134 } 00135 00136 if ( $wgShowEXIF && $this->displayImg->exists() ) { 00137 // @todo FIXME: Bad interface, see note on MediaHandler::formatMetadata(). 00138 $formattedMetadata = $this->displayImg->formatMetadata(); 00139 $showmeta = $formattedMetadata !== false; 00140 } else { 00141 $showmeta = false; 00142 } 00143 00144 if ( !$diff && $this->displayImg->exists() ) { 00145 $out->addHTML( $this->showTOC( $showmeta ) ); 00146 } 00147 00148 if ( !$diff ) { 00149 $this->openShowImage(); 00150 } 00151 00152 # No need to display noarticletext, we use our own message, output in openShowImage() 00153 if ( $this->mPage->getID() ) { 00154 # NS_FILE is in the user language, but this section (the actual wikitext) 00155 # should be in page content language 00156 $pageLang = $this->getTitle()->getPageViewLanguage(); 00157 $out->addHTML( Xml::openElement( 'div', array( 'id' => 'mw-imagepage-content', 00158 'lang' => $pageLang->getHtmlCode(), 'dir' => $pageLang->getDir(), 00159 'class' => 'mw-content-' . $pageLang->getDir() ) ) ); 00160 00161 parent::view(); 00162 00163 $out->addHTML( Xml::closeElement( 'div' ) ); 00164 } else { 00165 # Just need to set the right headers 00166 $out->setArticleFlag( true ); 00167 $out->setPageTitle( $this->getTitle()->getPrefixedText() ); 00168 $this->mPage->doViewUpdates( $this->getContext()->getUser(), $this->getOldID() ); 00169 } 00170 00171 # Show shared description, if needed 00172 if ( $this->mExtraDescription ) { 00173 $fol = wfMessage( 'shareddescriptionfollows' ); 00174 if ( !$fol->isDisabled() ) { 00175 $out->addWikiText( $fol->plain() ); 00176 } 00177 $out->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription . "</div>\n" ); 00178 } 00179 00180 $this->closeShowImage(); 00181 $this->imageHistory(); 00182 // TODO: Cleanup the following 00183 00184 $out->addHTML( Xml::element( 'h2', 00185 array( 'id' => 'filelinks' ), 00186 wfMessage( 'imagelinks' )->text() ) . "\n" ); 00187 $this->imageDupes(); 00188 # @todo FIXME: For some freaky reason, we can't redirect to foreign images. 00189 # Yet we return metadata about the target. Definitely an issue in the FileRepo 00190 $this->imageLinks(); 00191 00192 # Allow extensions to add something after the image links 00193 $html = ''; 00194 wfRunHooks( 'ImagePageAfterImageLinks', array( $this, &$html ) ); 00195 if ( $html ) { 00196 $out->addHTML( $html ); 00197 } 00198 00199 if ( $showmeta ) { 00200 $out->addHTML( Xml::element( 00201 'h2', 00202 array( 'id' => 'metadata' ), 00203 wfMessage( 'metadata' )->text() ) . "\n" ); 00204 $out->addWikiText( $this->makeMetadataTable( $formattedMetadata ) ); 00205 $out->addModules( array( 'mediawiki.action.view.metadata' ) ); 00206 } 00207 00208 // Add remote Filepage.css 00209 if ( !$this->repo->isLocal() ) { 00210 $css = $this->repo->getDescriptionStylesheetUrl(); 00211 if ( $css ) { 00212 $out->addStyle( $css ); 00213 } 00214 } 00215 // always show the local local Filepage.css, bug 29277 00216 $out->addModuleStyles( 'filepage' ); 00217 } 00218 00222 public function getDisplayedFile() { 00223 $this->loadFile(); 00224 return $this->displayImg; 00225 } 00226 00233 protected function showTOC( $metadata ) { 00234 $r = array( 00235 '<li><a href="#file">' . wfMessage( 'file-anchor-link' )->escaped() . '</a></li>', 00236 '<li><a href="#filehistory">' . wfMessage( 'filehist' )->escaped() . '</a></li>', 00237 '<li><a href="#filelinks">' . wfMessage( 'imagelinks' )->escaped() . '</a></li>', 00238 ); 00239 if ( $metadata ) { 00240 $r[] = '<li><a href="#metadata">' . wfMessage( 'metadata' )->escaped() . '</a></li>'; 00241 } 00242 00243 wfRunHooks( 'ImagePageShowTOC', array( $this, &$r ) ); 00244 00245 return '<ul id="filetoc">' . implode( "\n", $r ) . '</ul>'; 00246 } 00247 00256 protected function makeMetadataTable( $metadata ) { 00257 $r = "<div class=\"mw-imagepage-section-metadata\">"; 00258 $r .= wfMessage( 'metadata-help' )->plain(); 00259 $r .= "<table id=\"mw_metadata\" class=\"mw_metadata\">\n"; 00260 foreach ( $metadata as $type => $stuff ) { 00261 foreach ( $stuff as $v ) { 00262 # @todo FIXME: Why is this using escapeId for a class?! 00263 $class = Sanitizer::escapeId( $v['id'] ); 00264 if ( $type == 'collapsed' ) { 00265 // Handled by mediawiki.action.view.metadata module 00266 // and skins/common/shared.css. 00267 $class .= ' collapsable'; 00268 } 00269 $r .= "<tr class=\"$class\">\n"; 00270 $r .= "<th>{$v['name']}</th>\n"; 00271 $r .= "<td>{$v['value']}</td>\n</tr>"; 00272 } 00273 } 00274 $r .= "</table>\n</div>\n"; 00275 return $r; 00276 } 00277 00285 public function getContentObject() { 00286 $this->loadFile(); 00287 if ( $this->mPage->getFile() && !$this->mPage->getFile()->isLocal() && 0 == $this->getID() ) { 00288 return null; 00289 } 00290 return parent::getContentObject(); 00291 } 00292 00293 protected function openShowImage() { 00294 global $wgImageLimits, $wgEnableUploads, $wgSend404Code; 00295 00296 $this->loadFile(); 00297 $out = $this->getContext()->getOutput(); 00298 $user = $this->getContext()->getUser(); 00299 $lang = $this->getContext()->getLanguage(); 00300 $dirmark = $lang->getDirMarkEntity(); 00301 $request = $this->getContext()->getRequest(); 00302 00303 $max = $this->getImageLimitsFromOption( $user, 'imagesize' ); 00304 $maxWidth = $max[0]; 00305 $maxHeight = $max[1]; 00306 00307 if ( $this->displayImg->exists() ) { 00308 # image 00309 $page = $request->getIntOrNull( 'page' ); 00310 if ( is_null( $page ) ) { 00311 $params = array(); 00312 $page = 1; 00313 } else { 00314 $params = array( 'page' => $page ); 00315 } 00316 00317 $renderLang = $request->getVal( 'lang' ); 00318 if ( !is_null( $renderLang ) ) { 00319 $handler = $this->displayImg->getHandler(); 00320 if ( $handler && $handler->validateParam( 'lang', $renderLang ) ) { 00321 $params['lang'] = $renderLang; 00322 } else { 00323 $renderLang = null; 00324 } 00325 } 00326 00327 $width_orig = $this->displayImg->getWidth( $page ); 00328 $width = $width_orig; 00329 $height_orig = $this->displayImg->getHeight( $page ); 00330 $height = $height_orig; 00331 00332 $filename = wfEscapeWikiText( $this->displayImg->getName() ); 00333 $linktext = $filename; 00334 00335 wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this, &$out ) ); 00336 00337 if ( $this->displayImg->allowInlineDisplay() ) { 00338 # image 00339 00340 # "Download high res version" link below the image 00341 # $msgsize = wfMessage( 'file-info-size', $width_orig, $height_orig, Linker::formatSize( $this->displayImg->getSize() ), $mime )->escaped(); 00342 # We'll show a thumbnail of this image 00343 if ( $width > $maxWidth || $height > $maxHeight ) { 00344 # Calculate the thumbnail size. 00345 # First case, the limiting factor is the width, not the height. 00346 if ( $width / $height >= $maxWidth / $maxHeight ) { // FIXME: Possible division by 0. bug 36911 00347 $height = round( $height * $maxWidth / $width ); // FIXME: Possible division by 0. bug 36911 00348 $width = $maxWidth; 00349 # Note that $height <= $maxHeight now. 00350 } else { 00351 $newwidth = floor( $width * $maxHeight / $height ); // FIXME: Possible division by 0. bug 36911 00352 $height = round( $height * $newwidth / $width ); // FIXME: Possible division by 0. bug 36911 00353 $width = $newwidth; 00354 # Note that $height <= $maxHeight now, but might not be identical 00355 # because of rounding. 00356 } 00357 $linktext = wfMessage( 'show-big-image' )->escaped(); 00358 if ( $this->displayImg->getRepo()->canTransformVia404() ) { 00359 $thumbSizes = $wgImageLimits; 00360 // Also include the full sized resolution in the list, so 00361 // that users know they can get it. This will link to the 00362 // original file asset if mustRender() === false. In the case 00363 // that we mustRender, some users have indicated that they would 00364 // find it useful to have the full size image in the rendered 00365 // image format. 00366 $thumbSizes[] = array( $width_orig, $height_orig ); 00367 } else { 00368 # Creating thumb links triggers thumbnail generation. 00369 # Just generate the thumb for the current users prefs. 00370 $thumbSizes = array( $this->getImageLimitsFromOption( $user, 'thumbsize' ) ); 00371 if ( !$this->displayImg->mustRender() ) { 00372 // We can safely include a link to the "full-size" preview, 00373 // without actually rendering. 00374 $thumbSizes[] = array( $width_orig, $height_orig ); 00375 } 00376 } 00377 # Generate thumbnails or thumbnail links as needed... 00378 $otherSizes = array(); 00379 foreach ( $thumbSizes as $size ) { 00380 // We include a thumbnail size in the list, if it is 00381 // less than or equal to the original size of the image 00382 // asset ($width_orig/$height_orig). We also exclude 00383 // the current thumbnail's size ($width/$height) 00384 // since that is added to the message separately, so 00385 // it can be denoted as the current size being shown. 00386 if ( $size[0] <= $width_orig && $size[1] <= $height_orig 00387 && $size[0] != $width && $size[1] != $height 00388 ) { 00389 $sizeLink = $this->makeSizeLink( $params, $size[0], $size[1] ); 00390 if ( $sizeLink ) { 00391 $otherSizes[] = $sizeLink; 00392 } 00393 } 00394 } 00395 $otherSizes = array_unique( $otherSizes ); 00396 $msgsmall = ''; 00397 $sizeLinkBigImagePreview = $this->makeSizeLink( $params, $width, $height ); 00398 if ( $sizeLinkBigImagePreview ) { 00399 $msgsmall .= wfMessage( 'show-big-image-preview' )-> 00400 rawParams( $sizeLinkBigImagePreview )-> 00401 parse(); 00402 } 00403 if ( count( $otherSizes ) ) { 00404 $msgsmall .= ' ' . 00405 Html::rawElement( 'span', array( 'class' => 'mw-filepage-other-resolutions' ), 00406 wfMessage( 'show-big-image-other' )->rawParams( $lang->pipeList( $otherSizes ) )-> 00407 params( count( $otherSizes ) )->parse() 00408 ); 00409 } 00410 } elseif ( $width == 0 && $height == 0 ) { 00411 # Some sort of audio file that doesn't have dimensions 00412 # Don't output a no hi res message for such a file 00413 $msgsmall = ''; 00414 } elseif ( $this->displayImg->isVectorized() ) { 00415 # For vectorized images, full size is just the frame size 00416 $msgsmall = ''; 00417 } else { 00418 # Image is small enough to show full size on image page 00419 $msgsmall = wfMessage( 'file-nohires' )->parse(); 00420 } 00421 00422 $params['width'] = $width; 00423 $params['height'] = $height; 00424 $thumbnail = $this->displayImg->transform( $params ); 00425 Linker::processResponsiveImages( $this->displayImg, $thumbnail, $params ); 00426 00427 $anchorclose = Html::rawElement( 'div', array( 'class' => 'mw-filepage-resolutioninfo' ), $msgsmall ); 00428 00429 $isMulti = $this->displayImg->isMultipage() && $this->displayImg->pageCount() > 1; 00430 if ( $isMulti ) { 00431 $out->addModules( 'mediawiki.page.image.pagination' ); 00432 $out->addHTML( '<table class="multipageimage"><tr><td>' ); 00433 } 00434 00435 if ( $thumbnail ) { 00436 $options = array( 00437 'alt' => $this->displayImg->getTitle()->getPrefixedText(), 00438 'file-link' => true, 00439 ); 00440 $out->addHTML( '<div class="fullImageLink" id="file">' . 00441 $thumbnail->toHtml( $options ) . 00442 $anchorclose . "</div>\n" ); 00443 } 00444 00445 if ( $isMulti ) { 00446 $count = $this->displayImg->pageCount(); 00447 00448 if ( $page > 1 ) { 00449 $label = $out->parse( wfMessage( 'imgmultipageprev' )->text(), false ); 00450 // on the client side, this link is generated in ajaxifyPageNavigation() 00451 // in the mediawiki.page.image.pagination module 00452 $link = Linker::linkKnown( 00453 $this->getTitle(), 00454 $label, 00455 array(), 00456 array( 'page' => $page - 1 ) 00457 ); 00458 $thumb1 = Linker::makeThumbLinkObj( $this->getTitle(), $this->displayImg, $link, $label, 'none', 00459 array( 'page' => $page - 1 ) ); 00460 } else { 00461 $thumb1 = ''; 00462 } 00463 00464 if ( $page < $count ) { 00465 $label = wfMessage( 'imgmultipagenext' )->text(); 00466 $link = Linker::linkKnown( 00467 $this->getTitle(), 00468 $label, 00469 array(), 00470 array( 'page' => $page + 1 ) 00471 ); 00472 $thumb2 = Linker::makeThumbLinkObj( $this->getTitle(), $this->displayImg, $link, $label, 'none', 00473 array( 'page' => $page + 1 ) ); 00474 } else { 00475 $thumb2 = ''; 00476 } 00477 00478 global $wgScript; 00479 00480 $formParams = array( 00481 'name' => 'pageselector', 00482 'action' => $wgScript, 00483 ); 00484 $options = array(); 00485 for ( $i = 1; $i <= $count; $i++ ) { 00486 $options[] = Xml::option( $lang->formatNum( $i ), $i, $i == $page ); 00487 } 00488 $select = Xml::tags( 'select', 00489 array( 'id' => 'pageselector', 'name' => 'page' ), 00490 implode( "\n", $options ) ); 00491 00492 $out->addHTML( 00493 '</td><td><div class="multipageimagenavbox">' . 00494 Xml::openElement( 'form', $formParams ) . 00495 Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . 00496 wfMessage( 'imgmultigoto' )->rawParams( $select )->parse() . 00497 Xml::submitButton( wfMessage( 'imgmultigo' )->text() ) . 00498 Xml::closeElement( 'form' ) . 00499 "<hr />$thumb1\n$thumb2<br style=\"clear: both\" /></div></td></tr></table>" 00500 ); 00501 } 00502 } elseif ( $this->displayImg->isSafeFile() ) { 00503 # if direct link is allowed but it's not a renderable image, show an icon. 00504 $icon = $this->displayImg->iconThumb(); 00505 00506 $out->addHTML( '<div class="fullImageLink" id="file">' . 00507 $icon->toHtml( array( 'file-link' => true ) ) . 00508 "</div>\n" ); 00509 } 00510 00511 $longDesc = wfMessage( 'parentheses', $this->displayImg->getLongDesc() )->text(); 00512 00513 $medialink = "[[Media:$filename|$linktext]]"; 00514 00515 if ( !$this->displayImg->isSafeFile() ) { 00516 $warning = wfMessage( 'mediawarning' )->plain(); 00517 // dirmark is needed here to separate the file name, which 00518 // most likely ends in Latin characters, from the description, 00519 // which may begin with the file type. In RTL environment 00520 // this will get messy. 00521 // The dirmark, however, must not be immediately adjacent 00522 // to the filename, because it can get copied with it. 00523 // See bug 25277. 00524 $out->addWikiText( <<<EOT 00525 <div class="fullMedia"><span class="dangerousLink">{$medialink}</span> $dirmark<span class="fileInfo">$longDesc</span></div> 00526 <div class="mediaWarning">$warning</div> 00527 EOT 00528 ); 00529 } else { 00530 $out->addWikiText( <<<EOT 00531 <div class="fullMedia">{$medialink} {$dirmark}<span class="fileInfo">$longDesc</span> 00532 </div> 00533 EOT 00534 ); 00535 } 00536 00537 $renderLangOptions = $this->displayImg->getAvailableLanguages(); 00538 if ( count( $renderLangOptions ) >= 1 ) { 00539 $currentLanguage = $renderLang; 00540 $defaultLang = $this->displayImg->getDefaultRenderLanguage(); 00541 if ( is_null( $currentLanguage ) ) { 00542 $currentLanguage = $defaultLang; 00543 } 00544 $out->addHtml( $this->doRenderLangOpt( $renderLangOptions, $currentLanguage, $defaultLang ) ); 00545 } 00546 00547 // Add cannot animate thumbnail warning 00548 if ( !$this->displayImg->canAnimateThumbIfAppropriate() ) { 00549 // Include the extension so wiki admins can 00550 // customize it on a per file-type basis 00551 // (aka say things like use format X instead). 00552 // additionally have a specific message for 00553 // file-no-thumb-animation-gif 00554 $ext = $this->displayImg->getExtension(); 00555 $noAnimMesg = wfMessageFallback( 00556 'file-no-thumb-animation-' . $ext, 00557 'file-no-thumb-animation' 00558 )->plain(); 00559 00560 $out->addWikiText( <<<EOT 00561 <div class="mw-noanimatethumb">{$noAnimMesg}</div> 00562 EOT 00563 ); 00564 } 00565 00566 if ( !$this->displayImg->isLocal() ) { 00567 $this->printSharedImageText(); 00568 } 00569 } else { 00570 # Image does not exist 00571 if ( !$this->getID() ) { 00572 # No article exists either 00573 # Show deletion log to be consistent with normal articles 00574 LogEventsList::showLogExtract( 00575 $out, 00576 array( 'delete', 'move' ), 00577 $this->getTitle()->getPrefixedText(), 00578 '', 00579 array( 'lim' => 10, 00580 'conds' => array( "log_action != 'revision'" ), 00581 'showIfEmpty' => false, 00582 'msgKey' => array( 'moveddeleted-notice' ) 00583 ) 00584 ); 00585 } 00586 00587 if ( $wgEnableUploads && $user->isAllowed( 'upload' ) ) { 00588 // Only show an upload link if the user can upload 00589 $uploadTitle = SpecialPage::getTitleFor( 'Upload' ); 00590 $nofile = array( 00591 'filepage-nofile-link', 00592 $uploadTitle->getFullURL( array( 'wpDestFile' => $this->mPage->getFile()->getName() ) ) 00593 ); 00594 } else { 00595 $nofile = 'filepage-nofile'; 00596 } 00597 // Note, if there is an image description page, but 00598 // no image, then this setRobotPolicy is overridden 00599 // by Article::View(). 00600 $out->setRobotPolicy( 'noindex,nofollow' ); 00601 $out->wrapWikiMsg( "<div id='mw-imagepage-nofile' class='plainlinks'>\n$1\n</div>", $nofile ); 00602 if ( !$this->getID() && $wgSend404Code ) { 00603 // If there is no image, no shared image, and no description page, 00604 // output a 404, to be consistent with articles. 00605 $request->response()->header( 'HTTP/1.1 404 Not Found' ); 00606 } 00607 } 00608 $out->setFileVersion( $this->displayImg ); 00609 } 00610 00618 private function makeSizeLink( $params, $width, $height ) { 00619 $params['width'] = $width; 00620 $params['height'] = $height; 00621 $thumbnail = $this->displayImg->transform( $params ); 00622 if ( $thumbnail && !$thumbnail->isError() ) { 00623 return Html::rawElement( 'a', array( 00624 'href' => $thumbnail->getUrl(), 00625 'class' => 'mw-thumbnail-link' 00626 ), wfMessage( 'show-big-image-size' )->numParams( 00627 $thumbnail->getWidth(), $thumbnail->getHeight() 00628 )->parse() ); 00629 } else { 00630 return ''; 00631 } 00632 } 00633 00637 protected function printSharedImageText() { 00638 $out = $this->getContext()->getOutput(); 00639 $this->loadFile(); 00640 00641 $descUrl = $this->mPage->getFile()->getDescriptionUrl(); 00642 $descText = $this->mPage->getFile()->getDescriptionText( $this->getContext()->getLanguage() ); 00643 00644 /* Add canonical to head if there is no local page for this shared file */ 00645 if ( $descUrl && $this->mPage->getID() == 0 ) { 00646 $out->setCanonicalUrl( $descUrl ); 00647 } 00648 00649 $wrap = "<div class=\"sharedUploadNotice\">\n$1\n</div>\n"; 00650 $repo = $this->mPage->getFile()->getRepo()->getDisplayName(); 00651 00652 if ( $descUrl && $descText && wfMessage( 'sharedupload-desc-here' )->plain() !== '-' ) { 00653 $out->wrapWikiMsg( $wrap, array( 'sharedupload-desc-here', $repo, $descUrl ) ); 00654 } elseif ( $descUrl && wfMessage( 'sharedupload-desc-there' )->plain() !== '-' ) { 00655 $out->wrapWikiMsg( $wrap, array( 'sharedupload-desc-there', $repo, $descUrl ) ); 00656 } else { 00657 $out->wrapWikiMsg( $wrap, array( 'sharedupload', $repo ), ''/*BACKCOMPAT*/ ); 00658 } 00659 00660 if ( $descText ) { 00661 $this->mExtraDescription = $descText; 00662 } 00663 } 00664 00665 public function getUploadUrl() { 00666 $this->loadFile(); 00667 $uploadTitle = SpecialPage::getTitleFor( 'Upload' ); 00668 return $uploadTitle->getFullURL( array( 00669 'wpDestFile' => $this->mPage->getFile()->getName(), 00670 'wpForReUpload' => 1 00671 ) ); 00672 } 00673 00678 protected function uploadLinksBox() { 00679 global $wgEnableUploads; 00680 00681 if ( !$wgEnableUploads ) { 00682 return; 00683 } 00684 00685 $this->loadFile(); 00686 if ( !$this->mPage->getFile()->isLocal() ) { 00687 return; 00688 } 00689 00690 $out = $this->getContext()->getOutput(); 00691 $out->addHTML( "<ul>\n" ); 00692 00693 # "Upload a new version of this file" link 00694 $canUpload = $this->getTitle()->userCan( 'upload', $this->getContext()->getUser() ); 00695 if ( $canUpload && UploadBase::userCanReUpload( $this->getContext()->getUser(), $this->mPage->getFile()->name ) ) { 00696 $ulink = Linker::makeExternalLink( $this->getUploadUrl(), wfMessage( 'uploadnewversion-linktext' )->text() ); 00697 $out->addHTML( "<li id=\"mw-imagepage-reupload-link\"><div class=\"plainlinks\">{$ulink}</div></li>\n" ); 00698 } else { 00699 $out->addHTML( "<li id=\"mw-imagepage-upload-disallowed\">" . $this->getContext()->msg( 'upload-disallowed-here' )->escaped() . "</li>\n" ); 00700 } 00701 00702 $out->addHTML( "</ul>\n" ); 00703 } 00704 00705 protected function closeShowImage() { } # For overloading 00706 00711 protected function imageHistory() { 00712 $this->loadFile(); 00713 $out = $this->getContext()->getOutput(); 00714 $pager = new ImageHistoryPseudoPager( $this ); 00715 $out->addHTML( $pager->getBody() ); 00716 $out->preventClickjacking( $pager->getPreventClickjacking() ); 00717 00718 $this->mPage->getFile()->resetHistory(); // free db resources 00719 00720 # Exist check because we don't want to show this on pages where an image 00721 # doesn't exist along with the noimage message, that would suck. -ævar 00722 if ( $this->mPage->getFile()->exists() ) { 00723 $this->uploadLinksBox(); 00724 } 00725 } 00726 00732 protected function queryImageLinks( $target, $limit ) { 00733 $dbr = wfGetDB( DB_SLAVE ); 00734 00735 return $dbr->select( 00736 array( 'imagelinks', 'page' ), 00737 array( 'page_namespace', 'page_title', 'page_is_redirect', 'il_to' ), 00738 array( 'il_to' => $target, 'il_from = page_id' ), 00739 __METHOD__, 00740 array( 'LIMIT' => $limit + 1, 'ORDER BY' => 'il_from', ) 00741 ); 00742 } 00743 00744 protected function imageLinks() { 00745 $limit = 100; 00746 00747 $out = $this->getContext()->getOutput(); 00748 $res = $this->queryImageLinks( $this->getTitle()->getDBkey(), $limit + 1 ); 00749 $rows = array(); 00750 $redirects = array(); 00751 foreach ( $res as $row ) { 00752 if ( $row->page_is_redirect ) { 00753 $redirects[$row->page_title] = array(); 00754 } 00755 $rows[] = $row; 00756 } 00757 $count = count( $rows ); 00758 00759 $hasMore = $count > $limit; 00760 if ( !$hasMore && count( $redirects ) ) { 00761 $res = $this->queryImageLinks( array_keys( $redirects ), 00762 $limit - count( $rows ) + 1 ); 00763 foreach ( $res as $row ) { 00764 $redirects[$row->il_to][] = $row; 00765 $count++; 00766 } 00767 $hasMore = ( $res->numRows() + count( $rows ) ) > $limit; 00768 } 00769 00770 if ( $count == 0 ) { 00771 $out->wrapWikiMsg( 00772 Html::rawElement( 'div', 00773 array( 'id' => 'mw-imagepage-nolinkstoimage' ), "\n$1\n" ), 00774 'nolinkstoimage' 00775 ); 00776 return; 00777 } 00778 00779 $out->addHTML( "<div id='mw-imagepage-section-linkstoimage'>\n" ); 00780 if ( !$hasMore ) { 00781 $out->addWikiMsg( 'linkstoimage', $count ); 00782 } else { 00783 // More links than the limit. Add a link to [[Special:Whatlinkshere]] 00784 $out->addWikiMsg( 'linkstoimage-more', 00785 $this->getContext()->getLanguage()->formatNum( $limit ), 00786 $this->getTitle()->getPrefixedDBkey() 00787 ); 00788 } 00789 00790 $out->addHTML( 00791 Html::openElement( 'ul', 00792 array( 'class' => 'mw-imagepage-linkstoimage' ) ) . "\n" 00793 ); 00794 $count = 0; 00795 00796 // Sort the list by namespace:title 00797 usort( $rows, array( $this, 'compare' ) ); 00798 00799 // Create links for every element 00800 $currentCount = 0; 00801 foreach ( $rows as $element ) { 00802 $currentCount++; 00803 if ( $currentCount > $limit ) { 00804 break; 00805 } 00806 00807 $query = array(); 00808 # Add a redirect=no to make redirect pages reachable 00809 if ( isset( $redirects[$element->page_title] ) ) { 00810 $query['redirect'] = 'no'; 00811 } 00812 $link = Linker::linkKnown( 00813 Title::makeTitle( $element->page_namespace, $element->page_title ), 00814 null, array(), $query 00815 ); 00816 if ( !isset( $redirects[$element->page_title] ) ) { 00817 # No redirects 00818 $liContents = $link; 00819 } elseif ( count( $redirects[$element->page_title] ) === 0 ) { 00820 # Redirect without usages 00821 $liContents = wfMessage( 'linkstoimage-redirect' )->rawParams( $link, '' )->parse(); 00822 } else { 00823 # Redirect with usages 00824 $li = ''; 00825 foreach ( $redirects[$element->page_title] as $row ) { 00826 $currentCount++; 00827 if ( $currentCount > $limit ) { 00828 break; 00829 } 00830 00831 $link2 = Linker::linkKnown( Title::makeTitle( $row->page_namespace, $row->page_title ) ); 00832 $li .= Html::rawElement( 00833 'li', 00834 array( 'class' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace ), 00835 $link2 00836 ) . "\n"; 00837 } 00838 00839 $ul = Html::rawElement( 00840 'ul', 00841 array( 'class' => 'mw-imagepage-redirectstofile' ), 00842 $li 00843 ) . "\n"; 00844 $liContents = wfMessage( 'linkstoimage-redirect' )->rawParams( 00845 $link, $ul )->parse(); 00846 } 00847 $out->addHTML( Html::rawElement( 00848 'li', 00849 array( 'class' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace ), 00850 $liContents 00851 ) . "\n" 00852 ); 00853 00854 }; 00855 $out->addHTML( Html::closeElement( 'ul' ) . "\n" ); 00856 $res->free(); 00857 00858 // Add a links to [[Special:Whatlinkshere]] 00859 if ( $count > $limit ) { 00860 $out->addWikiMsg( 'morelinkstoimage', $this->getTitle()->getPrefixedDBkey() ); 00861 } 00862 $out->addHTML( Html::closeElement( 'div' ) . "\n" ); 00863 } 00864 00865 protected function imageDupes() { 00866 $this->loadFile(); 00867 $out = $this->getContext()->getOutput(); 00868 00869 $dupes = $this->mPage->getDuplicates(); 00870 if ( count( $dupes ) == 0 ) { 00871 return; 00872 } 00873 00874 $out->addHTML( "<div id='mw-imagepage-section-duplicates'>\n" ); 00875 $out->addWikiMsg( 'duplicatesoffile', 00876 $this->getContext()->getLanguage()->formatNum( count( $dupes ) ), $this->getTitle()->getDBkey() 00877 ); 00878 $out->addHTML( "<ul class='mw-imagepage-duplicates'>\n" ); 00879 00883 foreach ( $dupes as $file ) { 00884 $fromSrc = ''; 00885 if ( $file->isLocal() ) { 00886 $link = Linker::linkKnown( $file->getTitle() ); 00887 } else { 00888 $link = Linker::makeExternalLink( $file->getDescriptionUrl(), 00889 $file->getTitle()->getPrefixedText() ); 00890 $fromSrc = wfMessage( 'shared-repo-from', $file->getRepo()->getDisplayName() )->text(); 00891 } 00892 $out->addHTML( "<li>{$link} {$fromSrc}</li>\n" ); 00893 } 00894 $out->addHTML( "</ul></div>\n" ); 00895 } 00896 00900 public function delete() { 00901 $file = $this->mPage->getFile(); 00902 if ( !$file->exists() || !$file->isLocal() || $file->getRedirected() ) { 00903 // Standard article deletion 00904 parent::delete(); 00905 return; 00906 } 00907 00908 $deleter = new FileDeleteForm( $file ); 00909 $deleter->execute(); 00910 } 00911 00917 function showError( $description ) { 00918 $out = $this->getContext()->getOutput(); 00919 $out->setPageTitle( wfMessage( 'internalerror' ) ); 00920 $out->setRobotPolicy( 'noindex,nofollow' ); 00921 $out->setArticleRelated( false ); 00922 $out->enableClientCache( false ); 00923 $out->addWikiText( $description ); 00924 } 00925 00934 protected function compare( $a, $b ) { 00935 if ( $a->page_namespace == $b->page_namespace ) { 00936 return strcmp( $a->page_title, $b->page_title ); 00937 } else { 00938 return $a->page_namespace - $b->page_namespace; 00939 } 00940 } 00941 00950 public function getImageLimitsFromOption( $user, $optionName ) { 00951 global $wgImageLimits; 00952 00953 $option = $user->getIntOption( $optionName ); 00954 if ( !isset( $wgImageLimits[$option] ) ) { 00955 $option = User::getDefaultOption( $optionName ); 00956 } 00957 00958 // The user offset might still be incorrect, specially if 00959 // $wgImageLimits got changed (see bug #8858). 00960 if ( !isset( $wgImageLimits[$option] ) ) { 00961 // Default to the first offset in $wgImageLimits 00962 $option = 0; 00963 } 00964 00965 return isset( $wgImageLimits[$option] ) 00966 ? $wgImageLimits[$option] 00967 : array( 800, 600 ); // if nothing is set, fallback to a hardcoded default 00968 } 00969 00978 protected function doRenderLangOpt( array $langChoices, $curLang, $defaultLang ) { 00979 global $wgScript; 00980 sort( $langChoices ); 00981 $curLang = wfBCP47( $curLang ); 00982 $defaultLang = wfBCP47( $defaultLang ); 00983 $opts = ''; 00984 $haveCurrentLang = false; 00985 $haveDefaultLang = false; 00986 00987 // We make a list of all the language choices in the file. 00988 // Additionally if the default language to render this file 00989 // is not included as being in this file (for example, in svgs 00990 // usually the fallback content is the english content) also 00991 // include a choice for that. Last of all, if we're viewing 00992 // the file in a language not on the list, add it as a choice. 00993 foreach ( $langChoices as $lang ) { 00994 $code = wfBCP47( $lang ); 00995 $name = Language::fetchLanguageName( $code, $this->getContext()->getLanguage()->getCode() ); 00996 if ( $name !== '' ) { 00997 $display = wfMessage( 'img-lang-opt', $code, $name )->text(); 00998 } else { 00999 $display = $code; 01000 } 01001 $opts .= "\n" . Xml::option( $display, $code, $curLang === $code ); 01002 if ( $curLang === $code ) { 01003 $haveCurrentLang = true; 01004 } 01005 if ( $defaultLang === $code ) { 01006 $haveDefaultLang = true; 01007 } 01008 } 01009 if ( !$haveDefaultLang ) { 01010 // Its hard to know if the content is really in the default language, or 01011 // if its just unmarked content that could be in any language. 01012 $opts = Xml::option( wfMessage( 'img-lang-default' )->text(), $defaultLang, $defaultLang === $curLang ) . $opts; 01013 } 01014 if ( !$haveCurrentLang && $defaultLang !== $curLang ) { 01015 $name = Language::fetchLanguageName( $curLang, $this->getContext()->getLanguage()->getCode() ); 01016 if ( $name !== '' ) { 01017 $display = wfMessage( 'img-lang-opt', $curLang, $name )->text(); 01018 } else { 01019 $display = $curLang; 01020 } 01021 $opts = Xml::option( $display, $curLang, true ) . $opts; 01022 } 01023 01024 $select = Html::rawElement( 'select', array( 'id' => 'mw-imglangselector', 'name' => 'lang' ), $opts ); 01025 $submit = Xml::submitButton( wfMessage( 'img-lang-go' )->text() ); 01026 01027 $formContents = wfMessage( 'img-lang-info' )->rawParams( $select, $submit )->parse() 01028 . Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ); 01029 01030 $langSelectLine = Html::rawElement( 'div', array( 'id' => 'mw-imglangselector-line' ), 01031 Html::rawElement( 'form', array( 'action' => $wgScript ), $formContents ) 01032 ); 01033 return $langSelectLine; 01034 } 01035 } 01036 01042 class ImageHistoryList extends ContextSource { 01043 01047 protected $title; 01048 01052 protected $img; 01053 01057 protected $imagePage; 01058 01062 protected $current; 01063 01064 protected $repo, $showThumb; 01065 protected $preventClickjacking = false; 01066 01070 public function __construct( $imagePage ) { 01071 global $wgShowArchiveThumbnails; 01072 $this->current = $imagePage->getFile(); 01073 $this->img = $imagePage->getDisplayedFile(); 01074 $this->title = $imagePage->getTitle(); 01075 $this->imagePage = $imagePage; 01076 $this->showThumb = $wgShowArchiveThumbnails && $this->img->canRender(); 01077 $this->setContext( $imagePage->getContext() ); 01078 } 01079 01083 public function getImagePage() { 01084 return $this->imagePage; 01085 } 01086 01090 public function getFile() { 01091 return $this->img; 01092 } 01093 01098 public function beginImageHistoryList( $navLinks = '' ) { 01099 return Xml::element( 'h2', array( 'id' => 'filehistory' ), $this->msg( 'filehist' )->text() ) . "\n" 01100 . "<div id=\"mw-imagepage-section-filehistory\">\n" 01101 . $this->msg( 'filehist-help' )->parseAsBlock() 01102 . $navLinks . "\n" 01103 . Xml::openElement( 'table', array( 'class' => 'wikitable filehistory' ) ) . "\n" 01104 . '<tr><td></td>' 01105 . ( $this->current->isLocal() && ( $this->getUser()->isAllowedAny( 'delete', 'deletedhistory' ) ) ? '<td></td>' : '' ) 01106 . '<th>' . $this->msg( 'filehist-datetime' )->escaped() . '</th>' 01107 . ( $this->showThumb ? '<th>' . $this->msg( 'filehist-thumb' )->escaped() . '</th>' : '' ) 01108 . '<th>' . $this->msg( 'filehist-dimensions' )->escaped() . '</th>' 01109 . '<th>' . $this->msg( 'filehist-user' )->escaped() . '</th>' 01110 . '<th>' . $this->msg( 'filehist-comment' )->escaped() . '</th>' 01111 . "</tr>\n"; 01112 } 01113 01118 public function endImageHistoryList( $navLinks = '' ) { 01119 return "</table>\n$navLinks\n</div>\n"; 01120 } 01121 01127 public function imageHistoryLine( $iscur, $file ) { 01128 global $wgContLang; 01129 01130 $user = $this->getUser(); 01131 $lang = $this->getLanguage(); 01132 $timestamp = wfTimestamp( TS_MW, $file->getTimestamp() ); 01133 $img = $iscur ? $file->getName() : $file->getArchiveName(); 01134 $userId = $file->getUser( 'id' ); 01135 $userText = $file->getUser( 'text' ); 01136 $description = $file->getDescription( File::FOR_THIS_USER, $user ); 01137 01138 $local = $this->current->isLocal(); 01139 $row = $selected = ''; 01140 01141 // Deletion link 01142 if ( $local && ( $user->isAllowedAny( 'delete', 'deletedhistory' ) ) ) { 01143 $row .= '<td>'; 01144 # Link to remove from history 01145 if ( $user->isAllowed( 'delete' ) ) { 01146 $q = array( 'action' => 'delete' ); 01147 if ( !$iscur ) { 01148 $q['oldimage'] = $img; 01149 } 01150 $row .= Linker::linkKnown( 01151 $this->title, 01152 $this->msg( $iscur ? 'filehist-deleteall' : 'filehist-deleteone' )->escaped(), 01153 array(), $q 01154 ); 01155 } 01156 # Link to hide content. Don't show useless link to people who cannot hide revisions. 01157 $canHide = $user->isAllowed( 'deleterevision' ); 01158 if ( $canHide || ( $user->isAllowed( 'deletedhistory' ) && $file->getVisibility() ) ) { 01159 if ( $user->isAllowed( 'delete' ) ) { 01160 $row .= '<br />'; 01161 } 01162 // If file is top revision or locked from this user, don't link 01163 if ( $iscur || !$file->userCan( File::DELETED_RESTRICTED, $user ) ) { 01164 $del = Linker::revDeleteLinkDisabled( $canHide ); 01165 } else { 01166 list( $ts, ) = explode( '!', $img, 2 ); 01167 $query = array( 01168 'type' => 'oldimage', 01169 'target' => $this->title->getPrefixedText(), 01170 'ids' => $ts, 01171 ); 01172 $del = Linker::revDeleteLink( $query, 01173 $file->isDeleted( File::DELETED_RESTRICTED ), $canHide ); 01174 } 01175 $row .= $del; 01176 } 01177 $row .= '</td>'; 01178 } 01179 01180 // Reversion link/current indicator 01181 $row .= '<td>'; 01182 if ( $iscur ) { 01183 $row .= $this->msg( 'filehist-current' )->escaped(); 01184 } elseif ( $local && $this->title->quickUserCan( 'edit', $user ) 01185 && $this->title->quickUserCan( 'upload', $user ) 01186 ) { 01187 if ( $file->isDeleted( File::DELETED_FILE ) ) { 01188 $row .= $this->msg( 'filehist-revert' )->escaped(); 01189 } else { 01190 $row .= Linker::linkKnown( 01191 $this->title, 01192 $this->msg( 'filehist-revert' )->escaped(), 01193 array(), 01194 array( 01195 'action' => 'revert', 01196 'oldimage' => $img, 01197 'wpEditToken' => $user->getEditToken( $img ) 01198 ) 01199 ); 01200 } 01201 } 01202 $row .= '</td>'; 01203 01204 // Date/time and image link 01205 if ( $file->getTimestamp() === $this->img->getTimestamp() ) { 01206 $selected = "class='filehistory-selected'"; 01207 } 01208 $row .= "<td $selected style='white-space: nowrap;'>"; 01209 if ( !$file->userCan( File::DELETED_FILE, $user ) ) { 01210 # Don't link to unviewable files 01211 $row .= '<span class="history-deleted">' . $lang->userTimeAndDate( $timestamp, $user ) . '</span>'; 01212 } elseif ( $file->isDeleted( File::DELETED_FILE ) ) { 01213 if ( $local ) { 01214 $this->preventClickjacking(); 01215 $revdel = SpecialPage::getTitleFor( 'Revisiondelete' ); 01216 # Make a link to review the image 01217 $url = Linker::linkKnown( 01218 $revdel, 01219 $lang->userTimeAndDate( $timestamp, $user ), 01220 array(), 01221 array( 01222 'target' => $this->title->getPrefixedText(), 01223 'file' => $img, 01224 'token' => $user->getEditToken( $img ) 01225 ) 01226 ); 01227 } else { 01228 $url = $lang->userTimeAndDate( $timestamp, $user ); 01229 } 01230 $row .= '<span class="history-deleted">' . $url . '</span>'; 01231 } else { 01232 $url = $iscur ? $this->current->getUrl() : $this->current->getArchiveUrl( $img ); 01233 $row .= Xml::element( 'a', array( 'href' => $url ), $lang->userTimeAndDate( $timestamp, $user ) ); 01234 } 01235 $row .= "</td>"; 01236 01237 // Thumbnail 01238 if ( $this->showThumb ) { 01239 $row .= '<td>' . $this->getThumbForLine( $file ) . '</td>'; 01240 } 01241 01242 // Image dimensions + size 01243 $row .= '<td>'; 01244 $row .= htmlspecialchars( $file->getDimensionsString() ); 01245 $row .= $this->msg( 'word-separator' )->plain(); 01246 $row .= '<span style="white-space: nowrap;">'; 01247 $row .= $this->msg( 'parentheses' )->rawParams( Linker::formatSize( $file->getSize() ) )->plain(); 01248 $row .= '</span>'; 01249 $row .= '</td>'; 01250 01251 // Uploading user 01252 $row .= '<td>'; 01253 // Hide deleted usernames 01254 if ( $file->isDeleted( File::DELETED_USER ) ) { 01255 $row .= '<span class="history-deleted">' . $this->msg( 'rev-deleted-user' )->escaped() . '</span>'; 01256 } else { 01257 if ( $local ) { 01258 $row .= Linker::userLink( $userId, $userText ); 01259 $row .= $this->msg( 'word-separator' )->plain(); 01260 $row .= '<span style="white-space: nowrap;">'; 01261 $row .= Linker::userToolLinks( $userId, $userText ); 01262 $row .= '</span>'; 01263 } else { 01264 $row .= htmlspecialchars( $userText ); 01265 } 01266 } 01267 $row .= '</td>'; 01268 01269 // Don't show deleted descriptions 01270 if ( $file->isDeleted( File::DELETED_COMMENT ) ) { 01271 $row .= '<td><span class="history-deleted">' . $this->msg( 'rev-deleted-comment' )->escaped() . '</span></td>'; 01272 } else { 01273 $row .= '<td dir="' . $wgContLang->getDir() . '">' . Linker::formatComment( $description, $this->title ) . '</td>'; 01274 } 01275 01276 $rowClass = null; 01277 wfRunHooks( 'ImagePageFileHistoryLine', array( $this, $file, &$row, &$rowClass ) ); 01278 $classAttr = $rowClass ? " class='$rowClass'" : ''; 01279 01280 return "<tr{$classAttr}>{$row}</tr>\n"; 01281 } 01282 01287 protected function getThumbForLine( $file ) { 01288 $lang = $this->getLanguage(); 01289 $user = $this->getUser(); 01290 if ( $file->allowInlineDisplay() && $file->userCan( File::DELETED_FILE, $user ) 01291 && !$file->isDeleted( File::DELETED_FILE ) 01292 ) { 01293 $params = array( 01294 'width' => '120', 01295 'height' => '120', 01296 ); 01297 $timestamp = wfTimestamp( TS_MW, $file->getTimestamp() ); 01298 01299 $thumbnail = $file->transform( $params ); 01300 $options = array( 01301 'alt' => $this->msg( 'filehist-thumbtext', 01302 $lang->userTimeAndDate( $timestamp, $user ), 01303 $lang->userDate( $timestamp, $user ), 01304 $lang->userTime( $timestamp, $user ) )->text(), 01305 'file-link' => true, 01306 ); 01307 01308 if ( !$thumbnail ) { 01309 return $this->msg( 'filehist-nothumb' )->escaped(); 01310 } 01311 01312 return $thumbnail->toHtml( $options ); 01313 } else { 01314 return $this->msg( 'filehist-nothumb' )->escaped(); 01315 } 01316 } 01317 01321 protected function preventClickjacking( $enable = true ) { 01322 $this->preventClickjacking = $enable; 01323 } 01324 01328 public function getPreventClickjacking() { 01329 return $this->preventClickjacking; 01330 } 01331 } 01332 01333 class ImageHistoryPseudoPager extends ReverseChronologicalPager { 01334 protected $preventClickjacking = false; 01335 01339 protected $mImg; 01340 01344 protected $mTitle; 01345 01349 function __construct( $imagePage ) { 01350 parent::__construct( $imagePage->getContext() ); 01351 $this->mImagePage = $imagePage; 01352 $this->mTitle = clone ( $imagePage->getTitle() ); 01353 $this->mTitle->setFragment( '#filehistory' ); 01354 $this->mImg = null; 01355 $this->mHist = array(); 01356 $this->mRange = array( 0, 0 ); // display range 01357 } 01358 01362 function getTitle() { 01363 return $this->mTitle; 01364 } 01365 01366 function getQueryInfo() { 01367 return false; 01368 } 01369 01373 function getIndexField() { 01374 return ''; 01375 } 01376 01381 function formatRow( $row ) { 01382 return ''; 01383 } 01384 01388 function getBody() { 01389 $s = ''; 01390 $this->doQuery(); 01391 if ( count( $this->mHist ) ) { 01392 $list = new ImageHistoryList( $this->mImagePage ); 01393 # Generate prev/next links 01394 $navLink = $this->getNavigationBar(); 01395 $s = $list->beginImageHistoryList( $navLink ); 01396 // Skip rows there just for paging links 01397 for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) { 01398 $file = $this->mHist[$i]; 01399 $s .= $list->imageHistoryLine( !$file->isOld(), $file ); 01400 } 01401 $s .= $list->endImageHistoryList( $navLink ); 01402 01403 if ( $list->getPreventClickjacking() ) { 01404 $this->preventClickjacking(); 01405 } 01406 } 01407 return $s; 01408 } 01409 01410 function doQuery() { 01411 if ( $this->mQueryDone ) { 01412 return; 01413 } 01414 $this->mImg = $this->mImagePage->getFile(); // ensure loading 01415 if ( !$this->mImg->exists() ) { 01416 return; 01417 } 01418 $queryLimit = $this->mLimit + 1; // limit plus extra row 01419 if ( $this->mIsBackwards ) { 01420 // Fetch the file history 01421 $this->mHist = $this->mImg->getHistory( $queryLimit, null, $this->mOffset, false ); 01422 // The current rev may not meet the offset/limit 01423 $numRows = count( $this->mHist ); 01424 if ( $numRows <= $this->mLimit && $this->mImg->getTimestamp() > $this->mOffset ) { 01425 $this->mHist = array_merge( array( $this->mImg ), $this->mHist ); 01426 } 01427 } else { 01428 // The current rev may not meet the offset 01429 if ( !$this->mOffset || $this->mImg->getTimestamp() < $this->mOffset ) { 01430 $this->mHist[] = $this->mImg; 01431 } 01432 // Old image versions (fetch extra row for nav links) 01433 $oiLimit = count( $this->mHist ) ? $this->mLimit : $this->mLimit + 1; 01434 // Fetch the file history 01435 $this->mHist = array_merge( $this->mHist, 01436 $this->mImg->getHistory( $oiLimit, $this->mOffset, null, false ) ); 01437 } 01438 $numRows = count( $this->mHist ); // Total number of query results 01439 if ( $numRows ) { 01440 # Index value of top item in the list 01441 $firstIndex = $this->mIsBackwards ? 01442 $this->mHist[$numRows - 1]->getTimestamp() : $this->mHist[0]->getTimestamp(); 01443 # Discard the extra result row if there is one 01444 if ( $numRows > $this->mLimit && $numRows > 1 ) { 01445 if ( $this->mIsBackwards ) { 01446 # Index value of item past the index 01447 $this->mPastTheEndIndex = $this->mHist[0]->getTimestamp(); 01448 # Index value of bottom item in the list 01449 $lastIndex = $this->mHist[1]->getTimestamp(); 01450 # Display range 01451 $this->mRange = array( 1, $numRows - 1 ); 01452 } else { 01453 # Index value of item past the index 01454 $this->mPastTheEndIndex = $this->mHist[$numRows - 1]->getTimestamp(); 01455 # Index value of bottom item in the list 01456 $lastIndex = $this->mHist[$numRows - 2]->getTimestamp(); 01457 # Display range 01458 $this->mRange = array( 0, $numRows - 2 ); 01459 } 01460 } else { 01461 # Setting indexes to an empty string means that they will be 01462 # omitted if they would otherwise appear in URLs. It just so 01463 # happens that this is the right thing to do in the standard 01464 # UI, in all the relevant cases. 01465 $this->mPastTheEndIndex = ''; 01466 # Index value of bottom item in the list 01467 $lastIndex = $this->mIsBackwards ? 01468 $this->mHist[0]->getTimestamp() : $this->mHist[$numRows - 1]->getTimestamp(); 01469 # Display range 01470 $this->mRange = array( 0, $numRows - 1 ); 01471 } 01472 } else { 01473 $firstIndex = ''; 01474 $lastIndex = ''; 01475 $this->mPastTheEndIndex = ''; 01476 } 01477 if ( $this->mIsBackwards ) { 01478 $this->mIsFirst = ( $numRows < $queryLimit ); 01479 $this->mIsLast = ( $this->mOffset == '' ); 01480 $this->mLastShown = $firstIndex; 01481 $this->mFirstShown = $lastIndex; 01482 } else { 01483 $this->mIsFirst = ( $this->mOffset == '' ); 01484 $this->mIsLast = ( $numRows < $queryLimit ); 01485 $this->mLastShown = $lastIndex; 01486 $this->mFirstShown = $firstIndex; 01487 } 01488 $this->mQueryDone = true; 01489 } 01490 01494 protected function preventClickjacking( $enable = true ) { 01495 $this->preventClickjacking = $enable; 01496 } 01497 01501 public function getPreventClickjacking() { 01502 return $this->preventClickjacking; 01503 } 01504 01505 }