MediaWiki  master
ImagePage.php
Go to the documentation of this file.
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 || ( isset( $diff ) && $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() || isset( $diff ) ) {
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() );
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() );
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                                         $class .= ' collapsable';
00266                                 }
00267                                 $r .= "<tr class=\"$class\">\n";
00268                                 $r .= "<th>{$v['name']}</th>\n";
00269                                 $r .= "<td>{$v['value']}</td>\n</tr>";
00270                         }
00271                 }
00272                 $r .= "</table>\n</div>\n";
00273                 return $r;
00274         }
00275 
00283         public function getContentObject() {
00284                 $this->loadFile();
00285                 if ( $this->mPage->getFile() && !$this->mPage->getFile()->isLocal() && 0 == $this->getID() ) {
00286                         return null;
00287                 }
00288                 return parent::getContentObject();
00289         }
00290 
00291         protected function openShowImage() {
00292                 global $wgImageLimits, $wgEnableUploads, $wgSend404Code;
00293 
00294                 $this->loadFile();
00295                 $out = $this->getContext()->getOutput();
00296                 $user = $this->getContext()->getUser();
00297                 $lang = $this->getContext()->getLanguage();
00298                 $dirmark = $lang->getDirMarkEntity();
00299                 $request = $this->getContext()->getRequest();
00300 
00301                 $sizeSel = intval( $user->getOption( 'imagesize' ) );
00302                 if ( !isset( $wgImageLimits[$sizeSel] ) ) {
00303                         $sizeSel = User::getDefaultOption( 'imagesize' );
00304 
00305                         // The user offset might still be incorrect, specially if
00306                         // $wgImageLimits got changed (see bug #8858).
00307                         if ( !isset( $wgImageLimits[$sizeSel] ) ) {
00308                                 // Default to the first offset in $wgImageLimits
00309                                 $sizeSel = 0;
00310                         }
00311                 }
00312                 $max = $wgImageLimits[$sizeSel];
00313                 $maxWidth = $max[0];
00314                 $maxHeight = $max[1];
00315 
00316                 if ( $this->displayImg->exists() ) {
00317                         # image
00318                         $page = $request->getIntOrNull( 'page' );
00319                         if ( is_null( $page ) ) {
00320                                 $params = array();
00321                                 $page = 1;
00322                         } else {
00323                                 $params = array( 'page' => $page );
00324                         }
00325                         $width_orig = $this->displayImg->getWidth( $page );
00326                         $width = $width_orig;
00327                         $height_orig = $this->displayImg->getHeight( $page );
00328                         $height = $height_orig;
00329 
00330                         $longDesc = wfMessage( 'parentheses', $this->displayImg->getLongDesc() )->text();
00331 
00332                         wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this, &$out ) );
00333 
00334                         if ( $this->displayImg->allowInlineDisplay() ) {
00335                                 # image
00336 
00337                                 # "Download high res version" link below the image
00338                                 # $msgsize = wfMessage( 'file-info-size', $width_orig, $height_orig, Linker::formatSize( $this->displayImg->getSize() ), $mime )->escaped();
00339                                 # We'll show a thumbnail of this image
00340                                 if ( $width > $maxWidth || $height > $maxHeight ) {
00341                                         # Calculate the thumbnail size.
00342                                         # First case, the limiting factor is the width, not the height.
00343                                         if ( $width / $height >= $maxWidth / $maxHeight ) {
00344                                                 $height = round( $height * $maxWidth / $width );
00345                                                 $width = $maxWidth;
00346                                                 # Note that $height <= $maxHeight now.
00347                                         } else {
00348                                                 $newwidth = floor( $width * $maxHeight / $height );
00349                                                 $height = round( $height * $newwidth / $width );
00350                                                 $width = $newwidth;
00351                                                 # Note that $height <= $maxHeight now, but might not be identical
00352                                                 # because of rounding.
00353                                         }
00354                                         $msgbig = wfMessage( 'show-big-image' )->escaped();
00355                                         if ( $this->displayImg->getRepo()->canTransformVia404() ) {
00356                                                 $thumbSizes = $wgImageLimits;
00357                                         } else {
00358                                                 # Creating thumb links triggers thumbnail generation.
00359                                                 # Just generate the thumb for the current users prefs.
00360                                                 $thumbOption = $user->getOption( 'thumbsize' );
00361                                                 $thumbSizes = array( isset( $wgImageLimits[$thumbOption] )
00362                                                         ? $wgImageLimits[$thumbOption]
00363                                                         : $wgImageLimits[User::getDefaultOption( 'thumbsize' )] );
00364                                         }
00365                                         # Generate thumbnails or thumbnail links as needed...
00366                                         $otherSizes = array();
00367                                         foreach ( $thumbSizes as $size ) {
00368                                                 if ( $size[0] < $width_orig && $size[1] < $height_orig
00369                                                         && $size[0] != $width && $size[1] != $height )
00370                                                 {
00371                                                         $otherSizes[] = $this->makeSizeLink( $params, $size[0], $size[1] );
00372                                                 }
00373                                         }
00374                                         $msgsmall = wfMessage( 'show-big-image-preview' )->
00375                                                 rawParams( $this->makeSizeLink( $params, $width, $height ) )->
00376                                                 parse();
00377                                         if ( count( $otherSizes ) ) {
00378                                                 $msgsmall .= ' ' .
00379                                                 Html::rawElement( 'span', array( 'class' => 'mw-filepage-other-resolutions' ),
00380                                                         wfMessage( 'show-big-image-other' )->rawParams( $lang->pipeList( $otherSizes ) )->
00381                                                         params( count( $otherSizes ) )->parse()
00382                                                 );
00383                                         }
00384                                 } elseif ( $width == 0 && $height == 0 ){
00385                                         # Some sort of audio file that doesn't have dimensions
00386                                         # Don't output a no hi res message for such a file
00387                                         $msgsmall = '';
00388                                 } elseif ( $this->displayImg->isVectorized() ) {
00389                                         # For vectorized images, full size is just the frame size
00390                                         $msgsmall = '';
00391                                 } else {
00392                                         # Image is small enough to show full size on image page
00393                                         $msgsmall = wfMessage( 'file-nohires' )->parse();
00394                                 }
00395 
00396                                 $params['width'] = $width;
00397                                 $params['height'] = $height;
00398                                 $thumbnail = $this->displayImg->transform( $params );
00399 
00400                                 $showLink = true;
00401                                 $anchorclose = Html::rawElement( 'div', array( 'class' => 'mw-filepage-resolutioninfo' ), $msgsmall );
00402 
00403                                 $isMulti = $this->displayImg->isMultipage() && $this->displayImg->pageCount() > 1;
00404                                 if ( $isMulti ) {
00405                                         $out->addHTML( '<table class="multipageimage"><tr><td>' );
00406                                 }
00407 
00408                                 if ( $thumbnail ) {
00409                                         $options = array(
00410                                                 'alt' => $this->displayImg->getTitle()->getPrefixedText(),
00411                                                 'file-link' => true,
00412                                         );
00413                                         $out->addHTML( '<div class="fullImageLink" id="file">' .
00414                                                 $thumbnail->toHtml( $options ) .
00415                                                 $anchorclose . "</div>\n" );
00416                                 }
00417 
00418                                 if ( $isMulti ) {
00419                                         $count = $this->displayImg->pageCount();
00420 
00421                                         if ( $page > 1 ) {
00422                                                 $label = $out->parse( wfMessage( 'imgmultipageprev' )->text(), false );
00423                                                 $link = Linker::linkKnown(
00424                                                         $this->getTitle(),
00425                                                         $label,
00426                                                         array(),
00427                                                         array( 'page' => $page - 1 )
00428                                                 );
00429                                                 $thumb1 = Linker::makeThumbLinkObj( $this->getTitle(), $this->displayImg, $link, $label, 'none',
00430                                                         array( 'page' => $page - 1 ) );
00431                                         } else {
00432                                                 $thumb1 = '';
00433                                         }
00434 
00435                                         if ( $page < $count ) {
00436                                                 $label = wfMessage( 'imgmultipagenext' )->text();
00437                                                 $link = Linker::linkKnown(
00438                                                         $this->getTitle(),
00439                                                         $label,
00440                                                         array(),
00441                                                         array( 'page' => $page + 1 )
00442                                                 );
00443                                                 $thumb2 = Linker::makeThumbLinkObj( $this->getTitle(), $this->displayImg, $link, $label, 'none',
00444                                                         array( 'page' => $page + 1 ) );
00445                                         } else {
00446                                                 $thumb2 = '';
00447                                         }
00448 
00449                                         global $wgScript;
00450 
00451                                         $formParams = array(
00452                                                 'name' => 'pageselector',
00453                                                 'action' => $wgScript,
00454                                                 'onchange' => 'document.pageselector.submit();',
00455                                         );
00456                                         $options = array();
00457                                         for ( $i = 1; $i <= $count; $i++ ) {
00458                                                 $options[] = Xml::option( $lang->formatNum( $i ), $i, $i == $page );
00459                                         }
00460                                         $select = Xml::tags( 'select',
00461                                                 array( 'id' => 'pageselector', 'name' => 'page' ),
00462                                                 implode( "\n", $options ) );
00463 
00464                                         $out->addHTML(
00465                                                 '</td><td><div class="multipageimagenavbox">' .
00466                                                 Xml::openElement( 'form', $formParams ) .
00467                                                 Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) .
00468                                                         wfMessage( 'imgmultigoto' )->rawParams( $select )->parse() .
00469                                                 Xml::submitButton( wfMessage( 'imgmultigo' )->text() ) .
00470                                                 Xml::closeElement( 'form' ) .
00471                                                 "<hr />$thumb1\n$thumb2<br style=\"clear: both\" /></div></td></tr></table>"
00472                                         );
00473                                 }
00474                         } else {
00475                                 # if direct link is allowed but it's not a renderable image, show an icon.
00476                                 if ( $this->displayImg->isSafeFile() ) {
00477                                         $icon = $this->displayImg->iconThumb();
00478 
00479                                         $out->addHTML( '<div class="fullImageLink" id="file">' .
00480                                                 $icon->toHtml( array( 'file-link' => true ) ) .
00481                                                 "</div>\n" );
00482                                 }
00483 
00484                                 $showLink = true;
00485                         }
00486 
00487                         if ( $showLink ) {
00488                                 $filename = wfEscapeWikiText( $this->displayImg->getName() );
00489                                 $linktext = $filename;
00490                                 if ( isset( $msgbig ) ) {
00491                                         $linktext = wfEscapeWikiText( $msgbig );
00492                                 }
00493                                 $medialink = "[[Media:$filename|$linktext]]";
00494 
00495                                 if ( !$this->displayImg->isSafeFile() ) {
00496                                         $warning = wfMessage( 'mediawarning' )->plain();
00497                                         // dirmark is needed here to separate the file name, which
00498                                         // most likely ends in Latin characters, from the description,
00499                                         // which may begin with the file type. In RTL environment
00500                                         // this will get messy.
00501                                         // The dirmark, however, must not be immediately adjacent
00502                                         // to the filename, because it can get copied with it.
00503                                         // See bug 25277.
00504                                         $out->addWikiText( <<<EOT
00505 <div class="fullMedia"><span class="dangerousLink">{$medialink}</span> $dirmark<span class="fileInfo">$longDesc</span></div>
00506 <div class="mediaWarning">$warning</div>
00507 EOT
00508                                                 );
00509                                 } else {
00510                                         $out->addWikiText( <<<EOT
00511 <div class="fullMedia">{$medialink} {$dirmark}<span class="fileInfo">$longDesc</span>
00512 </div>
00513 EOT
00514                                         );
00515                                 }
00516                         }
00517 
00518                         // Add cannot animate thumbnail warning
00519                         if ( !$this->displayImg->canAnimateThumbIfAppropriate() ) {
00520                                 // Include the extension so wiki admins can
00521                                 // customize it on a per file-type basis
00522                                 // (aka say things like use format X instead).
00523                                 // additionally have a specific message for
00524                                 // file-no-thumb-animation-gif
00525                                 $ext = $this->displayImg->getExtension();
00526                                 $noAnimMesg = wfMessageFallback(
00527                                         'file-no-thumb-animation-' . $ext,
00528                                         'file-no-thumb-animation'
00529                                 )->plain();
00530 
00531                                 $out->addWikiText( <<<EOT
00532 <div class="mw-noanimatethumb">{$noAnimMesg}</div>
00533 EOT
00534                                 );
00535                         }
00536 
00537                         if ( !$this->displayImg->isLocal() ) {
00538                                 $this->printSharedImageText();
00539                         }
00540                 } else {
00541                         # Image does not exist
00542                         if ( !$this->getID() ) {
00543                                 # No article exists either
00544                                 # Show deletion log to be consistent with normal articles
00545                                 LogEventsList::showLogExtract(
00546                                         $out,
00547                                         array( 'delete', 'move' ),
00548                                         $this->getTitle()->getPrefixedText(),
00549                                         '',
00550                                         array(  'lim' => 10,
00551                                                 'conds' => array( "log_action != 'revision'" ),
00552                                                 'showIfEmpty' => false,
00553                                                 'msgKey' => array( 'moveddeleted-notice' )
00554                                         )
00555                                 );
00556                         }
00557 
00558                         if ( $wgEnableUploads && $user->isAllowed( 'upload' ) ) {
00559                                 // Only show an upload link if the user can upload
00560                                 $uploadTitle = SpecialPage::getTitleFor( 'Upload' );
00561                                 $nofile = array(
00562                                         'filepage-nofile-link',
00563                                         $uploadTitle->getFullURL( array( 'wpDestFile' => $this->mPage->getFile()->getName() ) )
00564                                 );
00565                         } else {
00566                                 $nofile = 'filepage-nofile';
00567                         }
00568                         // Note, if there is an image description page, but
00569                         // no image, then this setRobotPolicy is overriden
00570                         // by Article::View().
00571                         $out->setRobotPolicy( 'noindex,nofollow' );
00572                         $out->wrapWikiMsg( "<div id='mw-imagepage-nofile' class='plainlinks'>\n$1\n</div>", $nofile );
00573                         if ( !$this->getID() && $wgSend404Code ) {
00574                                 // If there is no image, no shared image, and no description page,
00575                                 // output a 404, to be consistent with articles.
00576                                 $request->response()->header( 'HTTP/1.1 404 Not Found' );
00577                         }
00578                 }
00579                 $out->setFileVersion( $this->displayImg );
00580         }
00581 
00589         private function makeSizeLink( $params, $width, $height ) {
00590                 $params['width'] = $width;
00591                 $params['height'] = $height;
00592                 $thumbnail = $this->displayImg->transform( $params );
00593                 if ( $thumbnail && !$thumbnail->isError() ) {
00594                         return Html::rawElement( 'a', array(
00595                                 'href' => $thumbnail->getUrl(),
00596                                 'class' => 'mw-thumbnail-link'
00597                                 ), wfMessage( 'show-big-image-size' )->numParams(
00598                                         $thumbnail->getWidth(), $thumbnail->getHeight()
00599                                 )->parse() );
00600                 } else {
00601                         return '';
00602                 }
00603         }
00604 
00608         protected function printSharedImageText() {
00609                 $out = $this->getContext()->getOutput();
00610                 $this->loadFile();
00611 
00612                 $descUrl = $this->mPage->getFile()->getDescriptionUrl();
00613                 $descText = $this->mPage->getFile()->getDescriptionText();
00614 
00615                 /* Add canonical to head if there is no local page for this shared file */
00616                 if( $descUrl && $this->mPage->getID() == 0 ) {
00617                         $out->addLink( array( 'rel' => 'canonical', 'href' => $descUrl ) );
00618                 }
00619 
00620                 $wrap = "<div class=\"sharedUploadNotice\">\n$1\n</div>\n";
00621                 $repo = $this->mPage->getFile()->getRepo()->getDisplayName();
00622 
00623                 if ( $descUrl && $descText && wfMessage( 'sharedupload-desc-here' )->plain() !== '-'  ) {
00624                         $out->wrapWikiMsg( $wrap, array( 'sharedupload-desc-here', $repo, $descUrl ) );
00625                 } elseif ( $descUrl && wfMessage( 'sharedupload-desc-there' )->plain() !== '-' ) {
00626                         $out->wrapWikiMsg( $wrap, array( 'sharedupload-desc-there', $repo, $descUrl ) );
00627                 } else {
00628                         $out->wrapWikiMsg( $wrap, array( 'sharedupload', $repo ), ''/*BACKCOMPAT*/ );
00629                 }
00630 
00631                 if ( $descText ) {
00632                         $this->mExtraDescription = $descText;
00633                 }
00634         }
00635 
00636         public function getUploadUrl() {
00637                 $this->loadFile();
00638                 $uploadTitle = SpecialPage::getTitleFor( 'Upload' );
00639                 return $uploadTitle->getFullURL( array(
00640                         'wpDestFile' => $this->mPage->getFile()->getName(),
00641                         'wpForReUpload' => 1
00642                  ) );
00643         }
00644 
00649         protected function uploadLinksBox() {
00650                 global $wgEnableUploads, $wgUseExternalEditor;
00651 
00652                 if ( !$wgEnableUploads ) {
00653                         return;
00654                 }
00655 
00656                 $this->loadFile();
00657                 if ( !$this->mPage->getFile()->isLocal() ) {
00658                         return;
00659                 }
00660 
00661                 $out = $this->getContext()->getOutput();
00662                 $out->addHTML( "<ul>\n" );
00663 
00664                 # "Upload a new version of this file" link
00665                 $canUpload = $this->getTitle()->userCan( 'upload', $this->getContext()->getUser() );
00666                 if ( $canUpload && UploadBase::userCanReUpload( $this->getContext()->getUser(), $this->mPage->getFile()->name ) ) {
00667                         $ulink = Linker::makeExternalLink( $this->getUploadUrl(), wfMessage( 'uploadnewversion-linktext' )->text() );
00668                         $out->addHTML( "<li id=\"mw-imagepage-reupload-link\"><div class=\"plainlinks\">{$ulink}</div></li>\n" );
00669                 } else {
00670                         $out->addHTML( "<li id=\"mw-imagepage-upload-disallowed\">" . $this->getContext()->msg( 'upload-disallowed-here' )->escaped() . "</li>\n" );
00671                 }
00672 
00673                 # External editing link
00674                 if ( $wgUseExternalEditor ) {
00675                         $elink = Linker::linkKnown(
00676                                 $this->getTitle(),
00677                                 wfMessage( 'edit-externally' )->escaped(),
00678                                 array(),
00679                                 array(
00680                                         'action' => 'edit',
00681                                         'externaledit' => 'true',
00682                                         'mode' => 'file'
00683                                 )
00684                         );
00685                         $out->addHTML(
00686                                 '<li id="mw-imagepage-edit-external">' . $elink . ' <small>' .
00687                                         wfMessage( 'edit-externally-help' )->parse() .
00688                                         "</small></li>\n"
00689                         );
00690                 }
00691 
00692                 $out->addHTML( "</ul>\n" );
00693         }
00694 
00695         protected function closeShowImage() { } # For overloading
00696 
00701         protected function imageHistory() {
00702                 $this->loadFile();
00703                 $out = $this->getContext()->getOutput();
00704                 $pager = new ImageHistoryPseudoPager( $this );
00705                 $out->addHTML( $pager->getBody() );
00706                 $out->preventClickjacking( $pager->getPreventClickjacking() );
00707 
00708                 $this->mPage->getFile()->resetHistory(); // free db resources
00709 
00710                 # Exist check because we don't want to show this on pages where an image
00711                 # doesn't exist along with the noimage message, that would suck. -ævar
00712                 if ( $this->mPage->getFile()->exists() ) {
00713                         $this->uploadLinksBox();
00714                 }
00715         }
00716 
00722         protected function queryImageLinks( $target, $limit ) {
00723                 $dbr = wfGetDB( DB_SLAVE );
00724 
00725                 return $dbr->select(
00726                         array( 'imagelinks', 'page' ),
00727                         array( 'page_namespace', 'page_title', 'page_is_redirect', 'il_to' ),
00728                         array( 'il_to' => $target, 'il_from = page_id' ),
00729                         __METHOD__,
00730                         array( 'LIMIT' => $limit + 1, 'ORDER BY' => 'il_from', )
00731                 );
00732         }
00733 
00734         protected function imageLinks() {
00735                 $limit = 100;
00736 
00737                 $out = $this->getContext()->getOutput();
00738                 $res = $this->queryImageLinks( $this->getTitle()->getDbKey(), $limit + 1);
00739                 $rows = array();
00740                 $redirects = array();
00741                 foreach ( $res as $row ) {
00742                         if ( $row->page_is_redirect ) {
00743                                 $redirects[$row->page_title] = array();
00744                         }
00745                         $rows[] = $row;
00746                 }
00747                 $count = count( $rows );
00748 
00749                 $hasMore = $count > $limit;
00750                 if ( !$hasMore && count( $redirects ) ) {
00751                         $res = $this->queryImageLinks( array_keys( $redirects ),
00752                                 $limit - count( $rows ) + 1 );
00753                         foreach ( $res as $row ) {
00754                                 $redirects[$row->il_to][] = $row;
00755                                 $count++;
00756                         }
00757                         $hasMore = ( $res->numRows() + count( $rows ) ) > $limit;
00758                 }
00759 
00760                 if ( $count == 0 ) {
00761                         $out->wrapWikiMsg(
00762                                 Html::rawElement( 'div',
00763                                         array( 'id' => 'mw-imagepage-nolinkstoimage' ), "\n$1\n" ),
00764                                 'nolinkstoimage'
00765                         );
00766                         return;
00767                 }
00768 
00769                 $out->addHTML( "<div id='mw-imagepage-section-linkstoimage'>\n" );
00770                 if ( !$hasMore ) {
00771                         $out->addWikiMsg( 'linkstoimage', $count );
00772                 } else {
00773                         // More links than the limit. Add a link to [[Special:Whatlinkshere]]
00774                         $out->addWikiMsg( 'linkstoimage-more',
00775                                 $this->getContext()->getLanguage()->formatNum( $limit ),
00776                                 $this->getTitle()->getPrefixedDBkey()
00777                         );
00778                 }
00779 
00780                 $out->addHTML(
00781                         Html::openElement( 'ul',
00782                                 array( 'class' => 'mw-imagepage-linkstoimage' ) ) . "\n"
00783                 );
00784                 $count = 0;
00785 
00786                 // Sort the list by namespace:title
00787                 usort( $rows, array( $this, 'compare' ) );
00788 
00789                 // Create links for every element
00790                 $currentCount = 0;
00791                 foreach( $rows as $element ) {
00792                         $currentCount++;
00793                         if ( $currentCount > $limit ) {
00794                                 break;
00795                         }
00796 
00797                         $link = Linker::linkKnown( Title::makeTitle( $element->page_namespace, $element->page_title ) );
00798                         if ( !isset( $redirects[$element->page_title] ) ) {
00799                                 $liContents = $link;
00800                         } else {
00801                                 $ul = "<ul class='mw-imagepage-redirectstofile'>\n";
00802                                 foreach ( $redirects[$element->page_title] as $row ) {
00803                                         $currentCount++;
00804                                         if ( $currentCount > $limit ) {
00805                                                 break;
00806                                         }
00807 
00808                                         $link2 = Linker::linkKnown( Title::makeTitle( $row->page_namespace, $row->page_title ) );
00809                                         $ul .= Html::rawElement(
00810                                                 'li',
00811                                                 array( 'class' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace ),
00812                                                 $link2
00813                                                 ) . "\n";
00814                                 }
00815                                 $ul .= '</ul>';
00816                                 $liContents = wfMessage( 'linkstoimage-redirect' )->rawParams(
00817                                         $link, $ul )->parse();
00818                         }
00819                         $out->addHTML( Html::rawElement(
00820                                         'li',
00821                                         array( 'class' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace ),
00822                                         $liContents
00823                                 ) . "\n"
00824                         );
00825 
00826                 };
00827                 $out->addHTML( Html::closeElement( 'ul' ) . "\n" );
00828                 $res->free();
00829 
00830                 // Add a links to [[Special:Whatlinkshere]]
00831                 if ( $count > $limit ) {
00832                         $out->addWikiMsg( 'morelinkstoimage', $this->getTitle()->getPrefixedDBkey() );
00833                 }
00834                 $out->addHTML( Html::closeElement( 'div' ) . "\n" );
00835         }
00836 
00837         protected function imageDupes() {
00838                 $this->loadFile();
00839                 $out = $this->getContext()->getOutput();
00840 
00841                 $dupes = $this->mPage->getDuplicates();
00842                 if ( count( $dupes ) == 0 ) {
00843                         return;
00844                 }
00845 
00846                 $out->addHTML( "<div id='mw-imagepage-section-duplicates'>\n" );
00847                 $out->addWikiMsg( 'duplicatesoffile',
00848                         $this->getContext()->getLanguage()->formatNum( count( $dupes ) ), $this->getTitle()->getDBkey()
00849                 );
00850                 $out->addHTML( "<ul class='mw-imagepage-duplicates'>\n" );
00851 
00855                 foreach ( $dupes as $file ) {
00856                         $fromSrc = '';
00857                         if ( $file->isLocal() ) {
00858                                 $link = Linker::linkKnown( $file->getTitle() );
00859                         } else {
00860                                 $link = Linker::makeExternalLink( $file->getDescriptionUrl(),
00861                                         $file->getTitle()->getPrefixedText() );
00862                                 $fromSrc = wfMessage( 'shared-repo-from', $file->getRepo()->getDisplayName() )->text();
00863                         }
00864                         $out->addHTML( "<li>{$link} {$fromSrc}</li>\n" );
00865                 }
00866                 $out->addHTML( "</ul></div>\n" );
00867         }
00868 
00872         public function delete() {
00873                 $file = $this->mPage->getFile();
00874                 if ( !$file->exists() || !$file->isLocal() || $file->getRedirected() ) {
00875                         // Standard article deletion
00876                         parent::delete();
00877                         return;
00878                 }
00879 
00880                 $deleter = new FileDeleteForm( $file );
00881                 $deleter->execute();
00882         }
00883 
00889         function showError( $description ) {
00890                 $out = $this->getContext()->getOutput();
00891                 $out->setPageTitle( wfMessage( 'internalerror' ) );
00892                 $out->setRobotPolicy( 'noindex,nofollow' );
00893                 $out->setArticleRelated( false );
00894                 $out->enableClientCache( false );
00895                 $out->addWikiText( $description );
00896         }
00897 
00906         protected function compare( $a, $b ) {
00907                 if ( $a->page_namespace == $b->page_namespace ) {
00908                         return strcmp( $a->page_title, $b->page_title );
00909                 } else {
00910                         return $a->page_namespace - $b->page_namespace;
00911                 }
00912         }
00913 }
00914 
00920 class ImageHistoryList extends ContextSource {
00921 
00925         protected $title;
00926 
00930         protected $img;
00931 
00935         protected $imagePage;
00936 
00940         protected $current;
00941 
00942         protected $repo, $showThumb;
00943         protected $preventClickjacking = false;
00944 
00948         public function __construct( $imagePage ) {
00949                 global $wgShowArchiveThumbnails;
00950                 $this->current = $imagePage->getFile();
00951                 $this->img = $imagePage->getDisplayedFile();
00952                 $this->title = $imagePage->getTitle();
00953                 $this->imagePage = $imagePage;
00954                 $this->showThumb = $wgShowArchiveThumbnails && $this->img->canRender();
00955                 $this->setContext( $imagePage->getContext() );
00956         }
00957 
00961         public function getImagePage() {
00962                 return $this->imagePage;
00963         }
00964 
00968         public function getFile() {
00969                 return $this->img;
00970         }
00971 
00976         public function beginImageHistoryList( $navLinks = '' ) {
00977                 return Xml::element( 'h2', array( 'id' => 'filehistory' ), $this->msg( 'filehist' )->text() ) . "\n"
00978                         . "<div id=\"mw-imagepage-section-filehistory\">\n"
00979                         . $this->msg( 'filehist-help' )->parseAsBlock()
00980                         . $navLinks . "\n"
00981                         . Xml::openElement( 'table', array( 'class' => 'wikitable filehistory' ) ) . "\n"
00982                         . '<tr><td></td>'
00983                         . ( $this->current->isLocal() && ( $this->getUser()->isAllowedAny( 'delete', 'deletedhistory' ) ) ? '<td></td>' : '' )
00984                         . '<th>' . $this->msg( 'filehist-datetime' )->escaped() . '</th>'
00985                         . ( $this->showThumb ? '<th>' . $this->msg( 'filehist-thumb' )->escaped() . '</th>' : '' )
00986                         . '<th>' . $this->msg( 'filehist-dimensions' )->escaped() . '</th>'
00987                         . '<th>' . $this->msg( 'filehist-user' )->escaped() . '</th>'
00988                         . '<th>' . $this->msg( 'filehist-comment' )->escaped() . '</th>'
00989                         . "</tr>\n";
00990         }
00991 
00996         public function endImageHistoryList( $navLinks = '' ) {
00997                 return "</table>\n$navLinks\n</div>\n";
00998         }
00999 
01005         public function imageHistoryLine( $iscur, $file ) {
01006                 global $wgContLang;
01007 
01008                 $user = $this->getUser();
01009                 $lang = $this->getLanguage();
01010                 $timestamp = wfTimestamp( TS_MW, $file->getTimestamp() );
01011                 $img = $iscur ? $file->getName() : $file->getArchiveName();
01012                 $userId = $file->getUser( 'id' );
01013                 $userText = $file->getUser( 'text' );
01014                 $description = $file->getDescription( File::FOR_THIS_USER, $user );
01015 
01016                 $local = $this->current->isLocal();
01017                 $row = $selected = '';
01018 
01019                 // Deletion link
01020                 if ( $local && ( $user->isAllowedAny( 'delete', 'deletedhistory' ) ) ) {
01021                         $row .= '<td>';
01022                         # Link to remove from history
01023                         if ( $user->isAllowed( 'delete' ) ) {
01024                                 $q = array( 'action' => 'delete' );
01025                                 if ( !$iscur ) {
01026                                         $q['oldimage'] = $img;
01027                                 }
01028                                 $row .= Linker::linkKnown(
01029                                         $this->title,
01030                                         $this->msg( $iscur ? 'filehist-deleteall' : 'filehist-deleteone' )->escaped(),
01031                                         array(), $q
01032                                 );
01033                         }
01034                         # Link to hide content. Don't show useless link to people who cannot hide revisions.
01035                         $canHide = $user->isAllowed( 'deleterevision' );
01036                         if ( $canHide || ( $user->isAllowed( 'deletedhistory' ) && $file->getVisibility() ) ) {
01037                                 if ( $user->isAllowed( 'delete' ) ) {
01038                                         $row .= '<br />';
01039                                 }
01040                                 // If file is top revision or locked from this user, don't link
01041                                 if ( $iscur || !$file->userCan( File::DELETED_RESTRICTED, $user ) ) {
01042                                         $del = Linker::revDeleteLinkDisabled( $canHide );
01043                                 } else {
01044                                         list( $ts, ) = explode( '!', $img, 2 );
01045                                         $query = array(
01046                                                 'type'   => 'oldimage',
01047                                                 'target' => $this->title->getPrefixedText(),
01048                                                 'ids'    => $ts,
01049                                         );
01050                                         $del = Linker::revDeleteLink( $query,
01051                                                 $file->isDeleted( File::DELETED_RESTRICTED ), $canHide );
01052                                 }
01053                                 $row .= $del;
01054                         }
01055                         $row .= '</td>';
01056                 }
01057 
01058                 // Reversion link/current indicator
01059                 $row .= '<td>';
01060                 if ( $iscur ) {
01061                         $row .= $this->msg( 'filehist-current' )->escaped();
01062                 } elseif ( $local && $this->title->quickUserCan( 'edit', $user )
01063                         && $this->title->quickUserCan( 'upload', $user )
01064                 ) {
01065                         if ( $file->isDeleted( File::DELETED_FILE ) ) {
01066                                 $row .= $this->msg( 'filehist-revert' )->escaped();
01067                         } else {
01068                                 $row .= Linker::linkKnown(
01069                                         $this->title,
01070                                         $this->msg( 'filehist-revert' )->escaped(),
01071                                         array(),
01072                                         array(
01073                                                 'action' => 'revert',
01074                                                 'oldimage' => $img,
01075                                                 'wpEditToken' => $user->getEditToken( $img )
01076                                         )
01077                                 );
01078                         }
01079                 }
01080                 $row .= '</td>';
01081 
01082                 // Date/time and image link
01083                 if ( $file->getTimestamp() === $this->img->getTimestamp() ) {
01084                         $selected = "class='filehistory-selected'";
01085                 }
01086                 $row .= "<td $selected style='white-space: nowrap;'>";
01087                 if ( !$file->userCan( File::DELETED_FILE, $user ) ) {
01088                         # Don't link to unviewable files
01089                         $row .= '<span class="history-deleted">' . $lang->userTimeAndDate( $timestamp, $user ) . '</span>';
01090                 } elseif ( $file->isDeleted( File::DELETED_FILE ) ) {
01091                         if ( $local ) {
01092                                 $this->preventClickjacking();
01093                                 $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
01094                                 # Make a link to review the image
01095                                 $url = Linker::linkKnown(
01096                                         $revdel,
01097                                         $lang->userTimeAndDate( $timestamp, $user ),
01098                                         array(),
01099                                         array(
01100                                                 'target' => $this->title->getPrefixedText(),
01101                                                 'file' => $img,
01102                                                 'token' => $user->getEditToken( $img )
01103                                         )
01104                                 );
01105                         } else {
01106                                 $url = $lang->userTimeAndDate( $timestamp, $user );
01107                         }
01108                         $row .= '<span class="history-deleted">' . $url . '</span>';
01109                 } else {
01110                         $url = $iscur ? $this->current->getUrl() : $this->current->getArchiveUrl( $img );
01111                         $row .= Xml::element( 'a', array( 'href' => $url ), $lang->userTimeAndDate( $timestamp, $user ) );
01112                 }
01113                 $row .= "</td>";
01114 
01115                 // Thumbnail
01116                 if ( $this->showThumb ) {
01117                         $row .= '<td>' . $this->getThumbForLine( $file ) . '</td>';
01118                 }
01119 
01120                 // Image dimensions + size
01121                 $row .= '<td>';
01122                 $row .= htmlspecialchars( $file->getDimensionsString() );
01123                 $row .= $this->msg( 'word-separator' )->plain();
01124                 $row .= '<span style="white-space: nowrap;">';
01125                 $row .= $this->msg( 'parentheses' )->rawParams( Linker::formatSize( $file->getSize() ) )->plain();
01126                 $row .= '</span>';
01127                 $row .= '</td>';
01128 
01129                 // Uploading user
01130                 $row .= '<td>';
01131                 // Hide deleted usernames
01132                 if ( $file->isDeleted( File::DELETED_USER ) ) {
01133                         $row .= '<span class="history-deleted">' . $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
01134                 } else {
01135                         if ( $local ) {
01136                                 $row .= Linker::userLink( $userId, $userText );
01137                                 $row .= $this->msg( 'word-separator' )->plain();
01138                                 $row .= '<span style="white-space: nowrap;">';
01139                                 $row .= Linker::userToolLinks( $userId, $userText );
01140                                 $row .= '</span>';
01141                         } else {
01142                                 $row .= htmlspecialchars( $userText );
01143                         }
01144                 }
01145                 $row .= '</td>';
01146 
01147                 // Don't show deleted descriptions
01148                 if ( $file->isDeleted( File::DELETED_COMMENT ) ) {
01149                         $row .= '<td><span class="history-deleted">' . $this->msg( 'rev-deleted-comment' )->escaped() . '</span></td>';
01150                 } else {
01151                         $row .= '<td dir="' . $wgContLang->getDir() . '">' . Linker::formatComment( $description, $this->title ) . '</td>';
01152                 }
01153 
01154                 $rowClass = null;
01155                 wfRunHooks( 'ImagePageFileHistoryLine', array( $this, $file, &$row, &$rowClass ) );
01156                 $classAttr = $rowClass ? " class='$rowClass'" : '';
01157 
01158                 return "<tr{$classAttr}>{$row}</tr>\n";
01159         }
01160 
01165         protected function getThumbForLine( $file ) {
01166                 $lang = $this->getLanguage();
01167                 $user = $this->getUser();
01168                 if ( $file->allowInlineDisplay() && $file->userCan( File::DELETED_FILE,$user )
01169                         && !$file->isDeleted( File::DELETED_FILE ) )
01170                 {
01171                         $params = array(
01172                                 'width' => '120',
01173                                 'height' => '120',
01174                         );
01175                         $timestamp = wfTimestamp( TS_MW, $file->getTimestamp() );
01176 
01177                         $thumbnail = $file->transform( $params );
01178                         $options = array(
01179                                 'alt' => $this->msg( 'filehist-thumbtext',
01180                                         $lang->userTimeAndDate( $timestamp, $user ),
01181                                         $lang->userDate( $timestamp, $user ),
01182                                         $lang->userTime( $timestamp, $user ) )->text(),
01183                                 'file-link' => true,
01184                         );
01185 
01186                         if ( !$thumbnail ) {
01187                                 return $this->msg( 'filehist-nothumb' )->escaped();
01188                         }
01189 
01190                         return $thumbnail->toHtml( $options );
01191                 } else {
01192                         return $this->msg( 'filehist-nothumb' )->escaped();
01193                 }
01194         }
01195 
01199         protected function preventClickjacking( $enable = true ) {
01200                 $this->preventClickjacking = $enable;
01201         }
01202 
01206         public function getPreventClickjacking() {
01207                 return $this->preventClickjacking;
01208         }
01209 }
01210 
01211 class ImageHistoryPseudoPager extends ReverseChronologicalPager {
01212         protected $preventClickjacking = false;
01213 
01217         protected $mImg;
01218 
01222         protected $mTitle;
01223 
01227         function __construct( $imagePage ) {
01228                 parent::__construct();
01229                 $this->mImagePage = $imagePage;
01230                 $this->mTitle = clone ( $imagePage->getTitle() );
01231                 $this->mTitle->setFragment( '#filehistory' );
01232                 $this->mImg = null;
01233                 $this->mHist = array();
01234                 $this->mRange = array( 0, 0 ); // display range
01235         }
01236 
01240         function getTitle() {
01241                 return $this->mTitle;
01242         }
01243 
01244         function getQueryInfo() {
01245                 return false;
01246         }
01247 
01251         function getIndexField() {
01252                 return '';
01253         }
01254 
01259         function formatRow( $row ) {
01260                 return '';
01261         }
01262 
01266         function getBody() {
01267                 $s = '';
01268                 $this->doQuery();
01269                 if ( count( $this->mHist ) ) {
01270                         $list = new ImageHistoryList( $this->mImagePage );
01271                         # Generate prev/next links
01272                         $navLink = $this->getNavigationBar();
01273                         $s = $list->beginImageHistoryList( $navLink );
01274                         // Skip rows there just for paging links
01275                         for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
01276                                 $file = $this->mHist[$i];
01277                                 $s .= $list->imageHistoryLine( !$file->isOld(), $file );
01278                         }
01279                         $s .= $list->endImageHistoryList( $navLink );
01280 
01281                         if ( $list->getPreventClickjacking() ) {
01282                                 $this->preventClickjacking();
01283                         }
01284                 }
01285                 return $s;
01286         }
01287 
01288         function doQuery() {
01289                 if ( $this->mQueryDone ) {
01290                         return;
01291                 }
01292                 $this->mImg = $this->mImagePage->getFile(); // ensure loading
01293                 if ( !$this->mImg->exists() ) {
01294                         return;
01295                 }
01296                 $queryLimit = $this->mLimit + 1; // limit plus extra row
01297                 if ( $this->mIsBackwards ) {
01298                         // Fetch the file history
01299                         $this->mHist = $this->mImg->getHistory( $queryLimit, null, $this->mOffset, false );
01300                         // The current rev may not meet the offset/limit
01301                         $numRows = count( $this->mHist );
01302                         if ( $numRows <= $this->mLimit && $this->mImg->getTimestamp() > $this->mOffset ) {
01303                                 $this->mHist = array_merge( array( $this->mImg ), $this->mHist );
01304                         }
01305                 } else {
01306                         // The current rev may not meet the offset
01307                         if ( !$this->mOffset || $this->mImg->getTimestamp() < $this->mOffset ) {
01308                                 $this->mHist[] = $this->mImg;
01309                         }
01310                         // Old image versions (fetch extra row for nav links)
01311                         $oiLimit = count( $this->mHist ) ? $this->mLimit : $this->mLimit + 1;
01312                         // Fetch the file history
01313                         $this->mHist = array_merge( $this->mHist,
01314                                 $this->mImg->getHistory( $oiLimit, $this->mOffset, null, false ) );
01315                 }
01316                 $numRows = count( $this->mHist ); // Total number of query results
01317                 if ( $numRows ) {
01318                         # Index value of top item in the list
01319                         $firstIndex = $this->mIsBackwards ?
01320                                 $this->mHist[$numRows - 1]->getTimestamp() : $this->mHist[0]->getTimestamp();
01321                         # Discard the extra result row if there is one
01322                         if ( $numRows > $this->mLimit && $numRows > 1 ) {
01323                                 if ( $this->mIsBackwards ) {
01324                                         # Index value of item past the index
01325                                         $this->mPastTheEndIndex = $this->mHist[0]->getTimestamp();
01326                                         # Index value of bottom item in the list
01327                                         $lastIndex = $this->mHist[1]->getTimestamp();
01328                                         # Display range
01329                                         $this->mRange = array( 1, $numRows - 1 );
01330                                 } else {
01331                                         # Index value of item past the index
01332                                         $this->mPastTheEndIndex = $this->mHist[$numRows - 1]->getTimestamp();
01333                                         # Index value of bottom item in the list
01334                                         $lastIndex = $this->mHist[$numRows - 2]->getTimestamp();
01335                                         # Display range
01336                                         $this->mRange = array( 0, $numRows - 2 );
01337                                 }
01338                         } else {
01339                                 # Setting indexes to an empty string means that they will be
01340                                 # omitted if they would otherwise appear in URLs. It just so
01341                                 # happens that this  is the right thing to do in the standard
01342                                 # UI, in all the relevant cases.
01343                                 $this->mPastTheEndIndex = '';
01344                                 # Index value of bottom item in the list
01345                                 $lastIndex = $this->mIsBackwards ?
01346                                         $this->mHist[0]->getTimestamp() : $this->mHist[$numRows - 1]->getTimestamp();
01347                                 # Display range
01348                                 $this->mRange = array( 0, $numRows - 1 );
01349                         }
01350                 } else {
01351                         $firstIndex = '';
01352                         $lastIndex = '';
01353                         $this->mPastTheEndIndex = '';
01354                 }
01355                 if ( $this->mIsBackwards ) {
01356                         $this->mIsFirst = ( $numRows < $queryLimit );
01357                         $this->mIsLast = ( $this->mOffset == '' );
01358                         $this->mLastShown = $firstIndex;
01359                         $this->mFirstShown = $lastIndex;
01360                 } else {
01361                         $this->mIsFirst = ( $this->mOffset == '' );
01362                         $this->mIsLast = ( $numRows < $queryLimit );
01363                         $this->mLastShown = $lastIndex;
01364                         $this->mFirstShown = $firstIndex;
01365                 }
01366                 $this->mQueryDone = true;
01367         }
01368 
01372         protected function preventClickjacking( $enable = true ) {
01373                 $this->preventClickjacking = $enable;
01374         }
01375 
01379         public function getPreventClickjacking() {
01380                 return $this->preventClickjacking;
01381         }
01382 
01383 }