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