3 * Special handling for file description pages.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 * Class for viewing MediaWiki file description pages
28 class ImagePage
extends Article
{
39 protected $mExtraDescription = false;
43 * @return WikiFilePage
45 protected function newPage( Title
$title ) {
46 // Overload mPage with a file-specific page
47 return new WikiFilePage( $title );
51 * Constructor from a page id
52 * @param int $id Article ID to load
53 * @return ImagePage|null
55 public static function newFromID( $id ) {
56 $t = Title
::newFromID( $id );
57 # @todo FIXME: Doesn't inherit right
58 return $t == null ?
null : new self( $t );
59 # return $t == null ? null : new static( $t ); // PHP 5.3
66 public function setFile( $file ) {
67 $this->mPage
->setFile( $file );
68 $this->displayImg
= $file;
69 $this->fileLoaded
= true;
72 protected function loadFile() {
73 if ( $this->fileLoaded
) {
76 $this->fileLoaded
= true;
78 $this->displayImg
= $img = false;
79 Hooks
::run( 'ImagePageFindFile', array( $this, &$img, &$this->displayImg
) );
80 if ( !$img ) { // not set by hook?
81 $img = wfFindFile( $this->getTitle() );
83 $img = wfLocalFile( $this->getTitle() );
86 $this->mPage
->setFile( $img );
87 if ( !$this->displayImg
) { // not set by hook?
88 $this->displayImg
= $img;
90 $this->repo
= $img->getRepo();
94 * Handler for action=render
95 * Include body text only; none of the image extras
97 public function render() {
98 $this->getContext()->getOutput()->setArticleBodyOnly( true );
102 public function view() {
105 $out = $this->getContext()->getOutput();
106 $request = $this->getContext()->getRequest();
107 $diff = $request->getVal( 'diff' );
108 $diffOnly = $request->getBool(
110 $this->getContext()->getUser()->getOption( 'diffonly' )
113 if ( $this->getTitle()->getNamespace() != NS_FILE ||
( $diff !== null && $diffOnly ) ) {
120 if ( $this->getTitle()->getNamespace() == NS_FILE
&& $this->mPage
->getFile()->getRedirected() ) {
121 if ( $this->getTitle()->getDBkey() == $this->mPage
->getFile()->getName() ||
$diff !== null ) {
122 // mTitle is the same as the redirect target so ask Article
123 // to perform the redirect for us.
124 $request->setVal( 'diffonly', 'true' );
128 // mTitle is not the same as the redirect target so it is
129 // probably the redirect page itself. Fake the redirect symbol
130 $out->setPageTitle( $this->getTitle()->getPrefixedText() );
131 $out->addHTML( $this->viewRedirect(
132 Title
::makeTitle( NS_FILE
, $this->mPage
->getFile()->getName() ),
133 /* $appendSubtitle */ true,
134 /* $forceKnown */ true )
136 $this->mPage
->doViewUpdates( $this->getContext()->getUser(), $this->getOldID() );
141 if ( $wgShowEXIF && $this->displayImg
->exists() ) {
142 // @todo FIXME: Bad interface, see note on MediaHandler::formatMetadata().
143 $formattedMetadata = $this->displayImg
->formatMetadata( $this->getContext() );
144 $showmeta = $formattedMetadata !== false;
149 if ( !$diff && $this->displayImg
->exists() ) {
150 $out->addHTML( $this->showTOC( $showmeta ) );
154 $this->openShowImage();
157 # No need to display noarticletext, we use our own message, output in openShowImage()
158 if ( $this->mPage
->getID() ) {
159 # NS_FILE is in the user language, but this section (the actual wikitext)
160 # should be in page content language
161 $pageLang = $this->getTitle()->getPageViewLanguage();
162 $out->addHTML( Xml
::openElement( 'div', array( 'id' => 'mw-imagepage-content',
163 'lang' => $pageLang->getHtmlCode(), 'dir' => $pageLang->getDir(),
164 'class' => 'mw-content-' . $pageLang->getDir() ) ) );
168 $out->addHTML( Xml
::closeElement( 'div' ) );
170 # Just need to set the right headers
171 $out->setArticleFlag( true );
172 $out->setPageTitle( $this->getTitle()->getPrefixedText() );
173 $this->mPage
->doViewUpdates( $this->getContext()->getUser(), $this->getOldID() );
176 # Show shared description, if needed
177 if ( $this->mExtraDescription
) {
178 $fol = $this->getContext()->msg( 'shareddescriptionfollows' );
179 if ( !$fol->isDisabled() ) {
180 $out->addWikiText( $fol->plain() );
182 $out->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription
. "</div>\n" );
185 $this->closeShowImage();
186 $this->imageHistory();
187 // TODO: Cleanup the following
189 $out->addHTML( Xml
::element( 'h2',
190 array( 'id' => 'filelinks' ),
191 $this->getContext()->msg( 'imagelinks' )->text() ) . "\n" );
193 # @todo FIXME: For some freaky reason, we can't redirect to foreign images.
194 # Yet we return metadata about the target. Definitely an issue in the FileRepo
197 # Allow extensions to add something after the image links
199 Hooks
::run( 'ImagePageAfterImageLinks', array( $this, &$html ) );
201 $out->addHTML( $html );
205 $out->addHTML( Xml
::element(
207 array( 'id' => 'metadata' ),
208 $this->getContext()->msg( 'metadata' )->text() ) . "\n" );
209 $out->addWikiText( $this->makeMetadataTable( $formattedMetadata ) );
210 $out->addModules( array( 'mediawiki.action.view.metadata' ) );
213 // Add remote Filepage.css
214 if ( !$this->repo
->isLocal() ) {
215 $css = $this->repo
->getDescriptionStylesheetUrl();
217 $out->addStyle( $css );
220 // always show the local local Filepage.css, bug 29277
221 $out->addModuleStyles( 'filepage' );
223 // Add MediaWiki styles for a file page
224 $out->addModuleStyles( 'mediawiki.action.view.filepage' );
230 public function getDisplayedFile() {
232 return $this->displayImg
;
238 * @param bool $metadata Whether or not to show the metadata link
241 protected function showTOC( $metadata ) {
243 '<li><a href="#file">' . $this->getContext()->msg( 'file-anchor-link' )->escaped() . '</a></li>',
244 '<li><a href="#filehistory">' . $this->getContext()->msg( 'filehist' )->escaped() . '</a></li>',
245 '<li><a href="#filelinks">' . $this->getContext()->msg( 'imagelinks' )->escaped() . '</a></li>',
248 Hooks
::run( 'ImagePageShowTOC', array( $this, &$r ) );
251 $r[] = '<li><a href="#metadata">' .
252 $this->getContext()->msg( 'metadata' )->escaped() .
256 return '<ul id="filetoc">' . implode( "\n", $r ) . '</ul>';
260 * Make a table with metadata to be shown in the output page.
262 * @todo FIXME: Bad interface, see note on MediaHandler::formatMetadata().
264 * @param array $metadata The array containing the Exif data
265 * @return string The metadata table. This is treated as Wikitext (!)
267 protected function makeMetadataTable( $metadata ) {
268 $r = "<div class=\"mw-imagepage-section-metadata\">";
269 $r .= $this->getContext()->msg( 'metadata-help' )->plain();
270 $r .= "<table id=\"mw_metadata\" class=\"mw_metadata\">\n";
271 foreach ( $metadata as $type => $stuff ) {
272 foreach ( $stuff as $v ) {
273 # @todo FIXME: Why is this using escapeId for a class?!
274 $class = Sanitizer
::escapeId( $v['id'] );
275 if ( $type == 'collapsed' ) {
276 // Handled by mediawiki.action.view.metadata module.
277 $class .= ' collapsable';
279 $r .= "<tr class=\"$class\">\n";
280 $r .= "<th>{$v['name']}</th>\n";
281 $r .= "<td>{$v['value']}</td>\n</tr>";
284 $r .= "</table>\n</div>\n";
289 * Overloading Article's getContentObject method.
291 * Omit noarticletext if sharedupload; text will be fetched from the
292 * shared upload server if possible.
295 public function getContentObject() {
297 if ( $this->mPage
->getFile() && !$this->mPage
->getFile()->isLocal() && 0 == $this->getID() ) {
300 return parent
::getContentObject();
303 protected function openShowImage() {
304 global $wgEnableUploads, $wgSend404Code, $wgSVGMaxSize;
307 $out = $this->getContext()->getOutput();
308 $user = $this->getContext()->getUser();
309 $lang = $this->getContext()->getLanguage();
310 $dirmark = $lang->getDirMarkEntity();
311 $request = $this->getContext()->getRequest();
313 $max = $this->getImageLimitsFromOption( $user, 'imagesize' );
315 $maxHeight = $max[1];
317 if ( $this->displayImg
->exists() ) {
319 $page = $request->getIntOrNull( 'page' );
320 if ( is_null( $page ) ) {
324 $params = array( 'page' => $page );
327 $renderLang = $request->getVal( 'lang' );
328 if ( !is_null( $renderLang ) ) {
329 $handler = $this->displayImg
->getHandler();
330 if ( $handler && $handler->validateParam( 'lang', $renderLang ) ) {
331 $params['lang'] = $renderLang;
337 $width_orig = $this->displayImg
->getWidth( $page );
338 $width = $width_orig;
339 $height_orig = $this->displayImg
->getHeight( $page );
340 $height = $height_orig;
342 $filename = wfEscapeWikiText( $this->displayImg
->getName() );
343 $linktext = $filename;
345 Hooks
::run( 'ImageOpenShowImageInlineBefore', array( &$this, &$out ) );
347 if ( $this->displayImg
->allowInlineDisplay() ) {
349 # "Download high res version" link below the image
350 # $msgsize = $this->getContext()->msg( 'file-info-size', $width_orig, $height_orig,
351 # Linker::formatSize( $this->displayImg->getSize() ), $mime )->escaped();
352 # We'll show a thumbnail of this image
353 if ( $width > $maxWidth ||
$height > $maxHeight ||
$this->displayImg
->isVectorized() ) {
354 list( $width, $height ) = $this->getDisplayWidthHeight(
355 $maxWidth, $maxHeight, $width, $height
357 $linktext = $this->getContext()->msg( 'show-big-image' )->escaped();
359 $thumbSizes = $this->getThumbSizes( $width_orig, $height_orig );
360 # Generate thumbnails or thumbnail links as needed...
361 $otherSizes = array();
362 foreach ( $thumbSizes as $size ) {
363 // We include a thumbnail size in the list, if it is
364 // less than or equal to the original size of the image
365 // asset ($width_orig/$height_orig). We also exclude
366 // the current thumbnail's size ($width/$height)
367 // since that is added to the message separately, so
368 // it can be denoted as the current size being shown.
369 // Vectorized images are limited by $wgSVGMaxSize big,
370 // so all thumbs less than or equal that are shown.
371 if ( ( ( $size[0] <= $width_orig && $size[1] <= $height_orig )
372 ||
( $this->displayImg
->isVectorized()
373 && max( $size[0], $size[1] ) <= $wgSVGMaxSize )
375 && $size[0] != $width && $size[1] != $height
377 $sizeLink = $this->makeSizeLink( $params, $size[0], $size[1] );
379 $otherSizes[] = $sizeLink;
383 $otherSizes = array_unique( $otherSizes );
385 $sizeLinkBigImagePreview = $this->makeSizeLink( $params, $width, $height );
386 $msgsmall = $this->getThumbPrevText( $params, $sizeLinkBigImagePreview );
387 if ( count( $otherSizes ) ) {
391 array( 'class' => 'mw-filepage-other-resolutions' ),
392 $this->getContext()->msg( 'show-big-image-other' )
393 ->rawParams( $lang->pipeList( $otherSizes ) )
394 ->params( count( $otherSizes ) )
398 } elseif ( $width == 0 && $height == 0 ) {
399 # Some sort of audio file that doesn't have dimensions
400 # Don't output a no hi res message for such a file
403 # Image is small enough to show full size on image page
404 $msgsmall = $this->getContext()->msg( 'file-nohires' )->parse();
407 $params['width'] = $width;
408 $params['height'] = $height;
409 $thumbnail = $this->displayImg
->transform( $params );
410 Linker
::processResponsiveImages( $this->displayImg
, $thumbnail, $params );
412 $anchorclose = Html
::rawElement(
414 array( 'class' => 'mw-filepage-resolutioninfo' ),
418 $isMulti = $this->displayImg
->isMultipage() && $this->displayImg
->pageCount() > 1;
420 $out->addModules( 'mediawiki.page.image.pagination' );
421 $out->addHTML( '<table class="multipageimage"><tr><td>' );
426 'alt' => $this->displayImg
->getTitle()->getPrefixedText(),
429 $out->addHTML( '<div class="fullImageLink" id="file">' .
430 $thumbnail->toHtml( $options ) .
431 $anchorclose . "</div>\n" );
435 $count = $this->displayImg
->pageCount();
438 $label = $out->parse( $this->getContext()->msg( 'imgmultipageprev' )->text(), false );
439 // on the client side, this link is generated in ajaxifyPageNavigation()
440 // in the mediawiki.page.image.pagination module
441 $link = Linker
::linkKnown(
445 array( 'page' => $page - 1 )
447 $thumb1 = Linker
::makeThumbLinkObj(
453 array( 'page' => $page - 1 )
459 if ( $page < $count ) {
460 $label = $this->getContext()->msg( 'imgmultipagenext' )->text();
461 $link = Linker
::linkKnown(
465 array( 'page' => $page +
1 )
467 $thumb2 = Linker
::makeThumbLinkObj(
473 array( 'page' => $page +
1 )
482 'name' => 'pageselector',
483 'action' => $wgScript,
486 for ( $i = 1; $i <= $count; $i++
) {
487 $options[] = Xml
::option( $lang->formatNum( $i ), $i, $i == $page );
489 $select = Xml
::tags( 'select',
490 array( 'id' => 'pageselector', 'name' => 'page' ),
491 implode( "\n", $options ) );
494 '</td><td><div class="multipageimagenavbox">' .
495 Xml
::openElement( 'form', $formParams ) .
496 Html
::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) .
497 $this->getContext()->msg( 'imgmultigoto' )->rawParams( $select )->parse() .
498 Xml
::submitButton( $this->getContext()->msg( 'imgmultigo' )->text() ) .
499 Xml
::closeElement( 'form' ) .
500 "<hr />$thumb1\n$thumb2<br style=\"clear: both\" /></div></td></tr></table>"
503 } elseif ( $this->displayImg
->isSafeFile() ) {
504 # if direct link is allowed but it's not a renderable image, show an icon.
505 $icon = $this->displayImg
->iconThumb();
507 $out->addHTML( '<div class="fullImageLink" id="file">' .
508 $icon->toHtml( array( 'file-link' => true ) ) .
512 $longDesc = $this->getContext()->msg( 'parentheses', $this->displayImg
->getLongDesc() )->text();
514 $handler = $this->displayImg
->getHandler();
516 // If this is a filetype with potential issues, warn the user.
518 $warningConfig = $handler->getWarningConfig( $this->displayImg
);
520 if ( $warningConfig !== null ) {
521 // The warning will be displayed via CSS and JavaScript.
522 // We just need to tell the client side what message to use.
523 $output = $this->getContext()->getOutput();
524 $output->addJsConfigVars( 'wgFileWarning', $warningConfig );
525 $output->addModules( $warningConfig['module'] );
526 $output->addModules( 'mediawiki.filewarning' );
530 $medialink = "[[Media:$filename|$linktext]]";
532 if ( !$this->displayImg
->isSafeFile() ) {
533 $warning = $this->getContext()->msg( 'mediawarning' )->plain();
534 // dirmark is needed here to separate the file name, which
535 // most likely ends in Latin characters, from the description,
536 // which may begin with the file type. In RTL environment
537 // this will get messy.
538 // The dirmark, however, must not be immediately adjacent
539 // to the filename, because it can get copied with it.
541 // @codingStandardsIgnoreStart Ignore long line
542 $out->addWikiText( <<<EOT
543 <div class="fullMedia"><span class="dangerousLink">{$medialink}</span> $dirmark<span class="fileInfo">$longDesc</span></div>
544 <div class="mediaWarning">$warning</div>
547 // @codingStandardsIgnoreEnd
549 $out->addWikiText( <<<EOT
550 <div class="fullMedia">{$medialink} {$dirmark}<span class="fileInfo">$longDesc</span>
556 $renderLangOptions = $this->displayImg
->getAvailableLanguages();
557 if ( count( $renderLangOptions ) >= 1 ) {
558 $currentLanguage = $renderLang;
559 $defaultLang = $this->displayImg
->getDefaultRenderLanguage();
560 if ( is_null( $currentLanguage ) ) {
561 $currentLanguage = $defaultLang;
563 $out->addHtml( $this->doRenderLangOpt( $renderLangOptions, $currentLanguage, $defaultLang ) );
566 // Add cannot animate thumbnail warning
567 if ( !$this->displayImg
->canAnimateThumbIfAppropriate() ) {
568 // Include the extension so wiki admins can
569 // customize it on a per file-type basis
570 // (aka say things like use format X instead).
571 // additionally have a specific message for
572 // file-no-thumb-animation-gif
573 $ext = $this->displayImg
->getExtension();
574 $noAnimMesg = wfMessageFallback(
575 'file-no-thumb-animation-' . $ext,
576 'file-no-thumb-animation'
579 $out->addWikiText( <<<EOT
580 <div class="mw-noanimatethumb">{$noAnimMesg}</div>
585 if ( !$this->displayImg
->isLocal() ) {
586 $this->printSharedImageText();
589 # Image does not exist
590 if ( !$this->getID() ) {
591 # No article exists either
592 # Show deletion log to be consistent with normal articles
593 LogEventsList
::showLogExtract(
595 array( 'delete', 'move' ),
596 $this->getTitle()->getPrefixedText(),
599 'conds' => array( "log_action != 'revision'" ),
600 'showIfEmpty' => false,
601 'msgKey' => array( 'moveddeleted-notice' )
606 if ( $wgEnableUploads && $user->isAllowed( 'upload' ) ) {
607 // Only show an upload link if the user can upload
608 $uploadTitle = SpecialPage
::getTitleFor( 'Upload' );
610 'filepage-nofile-link',
611 $uploadTitle->getFullURL( array( 'wpDestFile' => $this->mPage
->getFile()->getName() ) )
614 $nofile = 'filepage-nofile';
616 // Note, if there is an image description page, but
617 // no image, then this setRobotPolicy is overridden
618 // by Article::View().
619 $out->setRobotPolicy( 'noindex,nofollow' );
620 $out->wrapWikiMsg( "<div id='mw-imagepage-nofile' class='plainlinks'>\n$1\n</div>", $nofile );
621 if ( !$this->getID() && $wgSend404Code ) {
622 // If there is no image, no shared image, and no description page,
623 // output a 404, to be consistent with Article::showMissingArticle.
624 $request->response()->statusHeader( 404 );
627 $out->setFileVersion( $this->displayImg
);
631 * Make the text under the image to say what size preview
633 * @param $params Array parameters for thumbnail
634 * @param $sizeLinkBigImagePreview HTML for the current size
635 * @return string HTML output
637 private function getThumbPrevText( $params, $sizeLinkBigImagePreview ) {
638 if ( $sizeLinkBigImagePreview ) {
639 // Show a different message of preview is different format from original.
640 $previewTypeDiffers = false;
641 $origExt = $thumbExt = $this->displayImg
->getExtension();
642 if ( $this->displayImg
->getHandler() ) {
643 $origMime = $this->displayImg
->getMimeType();
644 $typeParams = $params;
645 $this->displayImg
->getHandler()->normaliseParams( $this->displayImg
, $typeParams );
646 list( $thumbExt, $thumbMime ) = $this->displayImg
->getHandler()->getThumbType(
647 $origExt, $origMime, $typeParams );
648 if ( $thumbMime !== $origMime ) {
649 $previewTypeDiffers = true;
652 if ( $previewTypeDiffers ) {
653 return $this->getContext()->msg( 'show-big-image-preview-differ' )->
654 rawParams( $sizeLinkBigImagePreview )->
655 params( strtoupper( $origExt ) )->
656 params( strtoupper( $thumbExt ) )->
659 return $this->getContext()->msg( 'show-big-image-preview' )->
660 rawParams( $sizeLinkBigImagePreview )->
669 * Creates an thumbnail of specified size and returns an HTML link to it
670 * @param array $params Scaler parameters
675 private function makeSizeLink( $params, $width, $height ) {
676 $params['width'] = $width;
677 $params['height'] = $height;
678 $thumbnail = $this->displayImg
->transform( $params );
679 if ( $thumbnail && !$thumbnail->isError() ) {
680 return Html
::rawElement( 'a', array(
681 'href' => $thumbnail->getUrl(),
682 'class' => 'mw-thumbnail-link'
683 ), $this->getContext()->msg( 'show-big-image-size' )->numParams(
684 $thumbnail->getWidth(), $thumbnail->getHeight()
692 * Show a notice that the file is from a shared repository
694 protected function printSharedImageText() {
695 $out = $this->getContext()->getOutput();
698 $descUrl = $this->mPage
->getFile()->getDescriptionUrl();
699 $descText = $this->mPage
->getFile()->getDescriptionText( $this->getContext()->getLanguage() );
701 /* Add canonical to head if there is no local page for this shared file */
702 if ( $descUrl && $this->mPage
->getID() == 0 ) {
703 $out->setCanonicalUrl( $descUrl );
706 $wrap = "<div class=\"sharedUploadNotice\">\n$1\n</div>\n";
707 $repo = $this->mPage
->getFile()->getRepo()->getDisplayName();
711 $this->getContext()->msg( 'sharedupload-desc-here' )->plain() !== '-'
713 $out->wrapWikiMsg( $wrap, array( 'sharedupload-desc-here', $repo, $descUrl ) );
714 } elseif ( $descUrl &&
715 $this->getContext()->msg( 'sharedupload-desc-there' )->plain() !== '-'
717 $out->wrapWikiMsg( $wrap, array( 'sharedupload-desc-there', $repo, $descUrl ) );
719 $out->wrapWikiMsg( $wrap, array( 'sharedupload', $repo ), ''/*BACKCOMPAT*/ );
723 $this->mExtraDescription
= $descText;
727 public function getUploadUrl() {
729 $uploadTitle = SpecialPage
::getTitleFor( 'Upload' );
730 return $uploadTitle->getFullURL( array(
731 'wpDestFile' => $this->mPage
->getFile()->getName(),
737 * Print out the various links at the bottom of the image page, e.g. reupload,
738 * external editing (and instructions link) etc.
740 protected function uploadLinksBox() {
741 global $wgEnableUploads;
743 if ( !$wgEnableUploads ) {
748 if ( !$this->mPage
->getFile()->isLocal() ) {
752 $out = $this->getContext()->getOutput();
753 $out->addHTML( "<ul>\n" );
755 # "Upload a new version of this file" link
756 $canUpload = $this->getTitle()->quickUserCan( 'upload', $this->getContext()->getUser() );
757 if ( $canUpload && UploadBase
::userCanReUpload(
758 $this->getContext()->getUser(),
759 $this->mPage
->getFile() )
761 $ulink = Linker
::makeExternalLink(
762 $this->getUploadUrl(),
763 $this->getContext()->msg( 'uploadnewversion-linktext' )->text()
765 $out->addHTML( "<li id=\"mw-imagepage-reupload-link\">"
766 . "<div class=\"plainlinks\">{$ulink}</div></li>\n" );
768 $out->addHTML( "<li id=\"mw-imagepage-upload-disallowed\">"
769 . $this->getContext()->msg( 'upload-disallowed-here' )->escaped() . "</li>\n" );
772 $out->addHTML( "</ul>\n" );
778 protected function closeShowImage() {
782 * If the page we've just displayed is in the "Image" namespace,
783 * we follow it with an upload history of the image and its usage.
785 protected function imageHistory() {
787 $out = $this->getContext()->getOutput();
788 $pager = new ImageHistoryPseudoPager( $this );
789 $out->addHTML( $pager->getBody() );
790 $out->preventClickjacking( $pager->getPreventClickjacking() );
792 $this->mPage
->getFile()->resetHistory(); // free db resources
794 # Exist check because we don't want to show this on pages where an image
795 # doesn't exist along with the noimage message, that would suck. -ævar
796 if ( $this->mPage
->getFile()->exists() ) {
797 $this->uploadLinksBox();
802 * @param string $target
804 * @return ResultWrapper
806 protected function queryImageLinks( $target, $limit ) {
807 $dbr = wfGetDB( DB_SLAVE
);
810 array( 'imagelinks', 'page' ),
811 array( 'page_namespace', 'page_title', 'il_to' ),
812 array( 'il_to' => $target, 'il_from = page_id' ),
814 array( 'LIMIT' => $limit +
1, 'ORDER BY' => 'il_from', )
818 protected function imageLinks() {
821 $out = $this->getContext()->getOutput();
824 $redirects = array();
825 foreach ( $this->getTitle()->getRedirectsHere( NS_FILE
) as $redir ) {
826 $redirects[$redir->getDBkey()] = array();
827 $rows[] = (object)array(
828 'page_namespace' => NS_FILE
,
829 'page_title' => $redir->getDBkey(),
833 $res = $this->queryImageLinks( $this->getTitle()->getDBkey(), $limit +
1 );
834 foreach ( $res as $row ) {
837 $count = count( $rows );
839 $hasMore = $count > $limit;
840 if ( !$hasMore && count( $redirects ) ) {
841 $res = $this->queryImageLinks( array_keys( $redirects ),
842 $limit - count( $rows ) +
1 );
843 foreach ( $res as $row ) {
844 $redirects[$row->il_to
][] = $row;
847 $hasMore = ( $res->numRows() +
count( $rows ) ) > $limit;
852 Html
::rawElement( 'div',
853 array( 'id' => 'mw-imagepage-nolinkstoimage' ), "\n$1\n" ),
859 $out->addHTML( "<div id='mw-imagepage-section-linkstoimage'>\n" );
861 $out->addWikiMsg( 'linkstoimage', $count );
863 // More links than the limit. Add a link to [[Special:Whatlinkshere]]
864 $out->addWikiMsg( 'linkstoimage-more',
865 $this->getContext()->getLanguage()->formatNum( $limit ),
866 $this->getTitle()->getPrefixedDBkey()
871 Html
::openElement( 'ul',
872 array( 'class' => 'mw-imagepage-linkstoimage' ) ) . "\n"
876 // Sort the list by namespace:title
877 usort( $rows, array( $this, 'compare' ) );
879 // Create links for every element
881 foreach ( $rows as $element ) {
883 if ( $currentCount > $limit ) {
888 # Add a redirect=no to make redirect pages reachable
889 if ( isset( $redirects[$element->page_title
] ) ) {
890 $query['redirect'] = 'no';
892 $link = Linker
::linkKnown(
893 Title
::makeTitle( $element->page_namespace
, $element->page_title
),
894 null, array(), $query
896 if ( !isset( $redirects[$element->page_title
] ) ) {
899 } elseif ( count( $redirects[$element->page_title
] ) === 0 ) {
900 # Redirect without usages
901 $liContents = $this->getContext()->msg( 'linkstoimage-redirect' )
902 ->rawParams( $link, '' )
905 # Redirect with usages
907 foreach ( $redirects[$element->page_title
] as $row ) {
909 if ( $currentCount > $limit ) {
913 $link2 = Linker
::linkKnown( Title
::makeTitle( $row->page_namespace
, $row->page_title
) );
914 $li .= Html
::rawElement(
916 array( 'class' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace
),
921 $ul = Html
::rawElement(
923 array( 'class' => 'mw-imagepage-redirectstofile' ),
926 $liContents = $this->getContext()->msg( 'linkstoimage-redirect' )->rawParams(
927 $link, $ul )->parse();
929 $out->addHTML( Html
::rawElement(
931 array( 'class' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace
),
937 $out->addHTML( Html
::closeElement( 'ul' ) . "\n" );
940 // Add a links to [[Special:Whatlinkshere]]
941 if ( $count > $limit ) {
942 $out->addWikiMsg( 'morelinkstoimage', $this->getTitle()->getPrefixedDBkey() );
944 $out->addHTML( Html
::closeElement( 'div' ) . "\n" );
947 protected function imageDupes() {
949 $out = $this->getContext()->getOutput();
951 $dupes = $this->mPage
->getDuplicates();
952 if ( count( $dupes ) == 0 ) {
956 $out->addHTML( "<div id='mw-imagepage-section-duplicates'>\n" );
957 $out->addWikiMsg( 'duplicatesoffile',
958 $this->getContext()->getLanguage()->formatNum( count( $dupes ) ), $this->getTitle()->getDBkey()
960 $out->addHTML( "<ul class='mw-imagepage-duplicates'>\n" );
965 foreach ( $dupes as $file ) {
967 if ( $file->isLocal() ) {
968 $link = Linker
::linkKnown( $file->getTitle() );
970 $link = Linker
::makeExternalLink( $file->getDescriptionUrl(),
971 $file->getTitle()->getPrefixedText() );
972 $fromSrc = $this->getContext()->msg(
974 $file->getRepo()->getDisplayName()
977 $out->addHTML( "<li>{$link} {$fromSrc}</li>\n" );
979 $out->addHTML( "</ul></div>\n" );
983 * Delete the file, or an earlier version of it
985 public function delete() {
986 $file = $this->mPage
->getFile();
987 if ( !$file->exists() ||
!$file->isLocal() ||
$file->getRedirected() ) {
988 // Standard article deletion
993 $deleter = new FileDeleteForm( $file );
998 * Display an error with a wikitext description
1000 * @param string $description
1002 function showError( $description ) {
1003 $out = $this->getContext()->getOutput();
1004 $out->setPageTitle( $this->getContext()->msg( 'internalerror' ) );
1005 $out->setRobotPolicy( 'noindex,nofollow' );
1006 $out->setArticleRelated( false );
1007 $out->enableClientCache( false );
1008 $out->addWikiText( $description );
1012 * Callback for usort() to do link sorts by (namespace, title)
1013 * Function copied from Title::compare()
1015 * @param object $a Object page to compare with
1016 * @param object $b Object page to compare with
1017 * @return int Result of string comparison, or namespace comparison
1019 protected function compare( $a, $b ) {
1020 if ( $a->page_namespace
== $b->page_namespace
) {
1021 return strcmp( $a->page_title
, $b->page_title
);
1023 return $a->page_namespace
- $b->page_namespace
;
1028 * Returns the corresponding $wgImageLimits entry for the selected user option
1031 * @param string $optionName Name of a option to check, typically imagesize or thumbsize
1035 public function getImageLimitsFromOption( $user, $optionName ) {
1036 global $wgImageLimits;
1038 $option = $user->getIntOption( $optionName );
1039 if ( !isset( $wgImageLimits[$option] ) ) {
1040 $option = User
::getDefaultOption( $optionName );
1043 // The user offset might still be incorrect, specially if
1044 // $wgImageLimits got changed (see bug #8858).
1045 if ( !isset( $wgImageLimits[$option] ) ) {
1046 // Default to the first offset in $wgImageLimits
1050 return isset( $wgImageLimits[$option] )
1051 ?
$wgImageLimits[$option]
1052 : array( 800, 600 ); // if nothing is set, fallback to a hardcoded default
1056 * Output a drop-down box for language options for the file
1058 * @param array $langChoices Array of string language codes
1059 * @param string $curLang Language code file is being viewed in.
1060 * @param string $defaultLang Language code that image is rendered in by default
1061 * @return string HTML to insert underneath image.
1063 protected function doRenderLangOpt( array $langChoices, $curLang, $defaultLang ) {
1065 sort( $langChoices );
1066 $curLang = wfBCP47( $curLang );
1067 $defaultLang = wfBCP47( $defaultLang );
1069 $haveCurrentLang = false;
1070 $haveDefaultLang = false;
1072 // We make a list of all the language choices in the file.
1073 // Additionally if the default language to render this file
1074 // is not included as being in this file (for example, in svgs
1075 // usually the fallback content is the english content) also
1076 // include a choice for that. Last of all, if we're viewing
1077 // the file in a language not on the list, add it as a choice.
1078 foreach ( $langChoices as $lang ) {
1079 $code = wfBCP47( $lang );
1080 $name = Language
::fetchLanguageName( $code, $this->getContext()->getLanguage()->getCode() );
1081 if ( $name !== '' ) {
1082 $display = $this->getContext()->msg( 'img-lang-opt', $code, $name )->text();
1086 $opts .= "\n" . Xml
::option( $display, $code, $curLang === $code );
1087 if ( $curLang === $code ) {
1088 $haveCurrentLang = true;
1090 if ( $defaultLang === $code ) {
1091 $haveDefaultLang = true;
1094 if ( !$haveDefaultLang ) {
1095 // Its hard to know if the content is really in the default language, or
1096 // if its just unmarked content that could be in any language.
1097 $opts = Xml
::option(
1098 $this->getContext()->msg( 'img-lang-default' )->text(),
1100 $defaultLang === $curLang
1103 if ( !$haveCurrentLang && $defaultLang !== $curLang ) {
1104 $name = Language
::fetchLanguageName( $curLang, $this->getContext()->getLanguage()->getCode() );
1105 if ( $name !== '' ) {
1106 $display = $this->getContext()->msg( 'img-lang-opt', $curLang, $name )->text();
1108 $display = $curLang;
1110 $opts = Xml
::option( $display, $curLang, true ) . $opts;
1113 $select = Html
::rawElement(
1115 array( 'id' => 'mw-imglangselector', 'name' => 'lang' ),
1118 $submit = Xml
::submitButton( $this->getContext()->msg( 'img-lang-go' )->text() );
1120 $formContents = $this->getContext()->msg( 'img-lang-info' )
1121 ->rawParams( $select, $submit )
1123 $formContents .= Html
::hidden( 'title', $this->getTitle()->getPrefixedDBkey() );
1125 $langSelectLine = Html
::rawElement( 'div', array( 'id' => 'mw-imglangselector-line' ),
1126 Html
::rawElement( 'form', array( 'action' => $wgScript ), $formContents )
1128 return $langSelectLine;
1132 * Get the width and height to display image at.
1134 * @note This method assumes that it is only called if one
1135 * of the dimensions are bigger than the max, or if the
1136 * image is vectorized.
1138 * @param int $maxWidth Max width to display at
1139 * @param int $maxHeight Max height to display at
1140 * @param int $width Actual width of the image
1141 * @param int $height Actual height of the image
1142 * @throws MWException
1143 * @return array Array (width, height)
1145 protected function getDisplayWidthHeight( $maxWidth, $maxHeight, $width, $height ) {
1146 if ( !$maxWidth ||
!$maxHeight ) {
1147 // should never happen
1148 throw new MWException( 'Using a choice from $wgImageLimits that is 0x0' );
1151 if ( !$width ||
!$height ) {
1152 return array( 0, 0 );
1155 # Calculate the thumbnail size.
1156 if ( $width <= $maxWidth && $height <= $maxHeight ) {
1157 // Vectorized image, do nothing.
1158 } elseif ( $width / $height >= $maxWidth / $maxHeight ) {
1159 # The limiting factor is the width, not the height.
1160 $height = round( $height * $maxWidth / $width );
1162 # Note that $height <= $maxHeight now.
1164 $newwidth = floor( $width * $maxHeight / $height );
1165 $height = round( $height * $newwidth / $width );
1167 # Note that $height <= $maxHeight now, but might not be identical
1168 # because of rounding.
1170 return array( $width, $height );
1174 * Get alternative thumbnail sizes.
1176 * @note This will only list several alternatives if thumbnails are rendered on 404
1177 * @param int $origWidth Actual width of image
1178 * @param int $origHeight Actual height of image
1179 * @return array An array of [width, height] pairs.
1181 protected function getThumbSizes( $origWidth, $origHeight ) {
1182 global $wgImageLimits;
1183 if ( $this->displayImg
->getRepo()->canTransformVia404() ) {
1184 $thumbSizes = $wgImageLimits;
1185 // Also include the full sized resolution in the list, so
1186 // that users know they can get it. This will link to the
1187 // original file asset if mustRender() === false. In the case
1188 // that we mustRender, some users have indicated that they would
1189 // find it useful to have the full size image in the rendered
1191 $thumbSizes[] = array( $origWidth, $origHeight );
1193 # Creating thumb links triggers thumbnail generation.
1194 # Just generate the thumb for the current users prefs.
1195 $thumbSizes = array(
1196 $this->getImageLimitsFromOption( $this->getContext()->getUser(), 'thumbsize' )
1198 if ( !$this->displayImg
->mustRender() ) {
1199 // We can safely include a link to the "full-size" preview,
1200 // without actually rendering.
1201 $thumbSizes[] = array( $origWidth, $origHeight );
1210 * Builds the image revision log shown on image pages
1214 class ImageHistoryList
extends ContextSource
{
1229 protected $imagePage;
1236 protected $repo, $showThumb;
1237 protected $preventClickjacking = false;
1240 * @param ImagePage $imagePage
1242 public function __construct( $imagePage ) {
1243 global $wgShowArchiveThumbnails;
1244 $this->current
= $imagePage->getFile();
1245 $this->img
= $imagePage->getDisplayedFile();
1246 $this->title
= $imagePage->getTitle();
1247 $this->imagePage
= $imagePage;
1248 $this->showThumb
= $wgShowArchiveThumbnails && $this->img
->canRender();
1249 $this->setContext( $imagePage->getContext() );
1255 public function getImagePage() {
1256 return $this->imagePage
;
1262 public function getFile() {
1267 * @param string $navLinks
1270 public function beginImageHistoryList( $navLinks = '' ) {
1271 return Xml
::element( 'h2', array( 'id' => 'filehistory' ), $this->msg( 'filehist' )->text() )
1273 . "<div id=\"mw-imagepage-section-filehistory\">\n"
1274 . $this->msg( 'filehist-help' )->parseAsBlock()
1276 . Xml
::openElement( 'table', array( 'class' => 'wikitable filehistory' ) ) . "\n"
1278 . ( $this->current
->isLocal()
1279 && ( $this->getUser()->isAllowedAny( 'delete', 'deletedhistory' ) ) ?
'<th></th>' : '' )
1280 . '<th>' . $this->msg( 'filehist-datetime' )->escaped() . '</th>'
1281 . ( $this->showThumb ?
'<th>' . $this->msg( 'filehist-thumb' )->escaped() . '</th>' : '' )
1282 . '<th>' . $this->msg( 'filehist-dimensions' )->escaped() . '</th>'
1283 . '<th>' . $this->msg( 'filehist-user' )->escaped() . '</th>'
1284 . '<th>' . $this->msg( 'filehist-comment' )->escaped() . '</th>'
1289 * @param string $navLinks
1292 public function endImageHistoryList( $navLinks = '' ) {
1293 return "</table>\n$navLinks\n</div>\n";
1297 * @param bool $iscur
1301 public function imageHistoryLine( $iscur, $file ) {
1304 $user = $this->getUser();
1305 $lang = $this->getLanguage();
1306 $timestamp = wfTimestamp( TS_MW
, $file->getTimestamp() );
1307 $img = $iscur ?
$file->getName() : $file->getArchiveName();
1308 $userId = $file->getUser( 'id' );
1309 $userText = $file->getUser( 'text' );
1310 $description = $file->getDescription( File
::FOR_THIS_USER
, $user );
1312 $local = $this->current
->isLocal();
1313 $row = $selected = '';
1316 if ( $local && ( $user->isAllowedAny( 'delete', 'deletedhistory' ) ) ) {
1318 # Link to remove from history
1319 if ( $user->isAllowed( 'delete' ) ) {
1320 $q = array( 'action' => 'delete' );
1322 $q['oldimage'] = $img;
1324 $row .= Linker
::linkKnown(
1326 $this->msg( $iscur ?
'filehist-deleteall' : 'filehist-deleteone' )->escaped(),
1330 # Link to hide content. Don't show useless link to people who cannot hide revisions.
1331 $canHide = $user->isAllowed( 'deleterevision' );
1332 if ( $canHide ||
( $user->isAllowed( 'deletedhistory' ) && $file->getVisibility() ) ) {
1333 if ( $user->isAllowed( 'delete' ) ) {
1336 // If file is top revision or locked from this user, don't link
1337 if ( $iscur ||
!$file->userCan( File
::DELETED_RESTRICTED
, $user ) ) {
1338 $del = Linker
::revDeleteLinkDisabled( $canHide );
1340 list( $ts, ) = explode( '!', $img, 2 );
1342 'type' => 'oldimage',
1343 'target' => $this->title
->getPrefixedText(),
1346 $del = Linker
::revDeleteLink( $query,
1347 $file->isDeleted( File
::DELETED_RESTRICTED
), $canHide );
1354 // Reversion link/current indicator
1357 $row .= $this->msg( 'filehist-current' )->escaped();
1358 } elseif ( $local && $this->title
->quickUserCan( 'edit', $user )
1359 && $this->title
->quickUserCan( 'upload', $user )
1361 if ( $file->isDeleted( File
::DELETED_FILE
) ) {
1362 $row .= $this->msg( 'filehist-revert' )->escaped();
1364 $row .= Linker
::linkKnown(
1366 $this->msg( 'filehist-revert' )->escaped(),
1369 'action' => 'revert',
1371 'wpEditToken' => $user->getEditToken( $img )
1378 // Date/time and image link
1379 if ( $file->getTimestamp() === $this->img
->getTimestamp() ) {
1380 $selected = "class='filehistory-selected'";
1382 $row .= "<td $selected style='white-space: nowrap;'>";
1383 if ( !$file->userCan( File
::DELETED_FILE
, $user ) ) {
1384 # Don't link to unviewable files
1385 $row .= '<span class="history-deleted">'
1386 . $lang->userTimeAndDate( $timestamp, $user ) . '</span>';
1387 } elseif ( $file->isDeleted( File
::DELETED_FILE
) ) {
1389 $this->preventClickjacking();
1390 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
1391 # Make a link to review the image
1392 $url = Linker
::linkKnown(
1394 $lang->userTimeAndDate( $timestamp, $user ),
1397 'target' => $this->title
->getPrefixedText(),
1399 'token' => $user->getEditToken( $img )
1403 $url = $lang->userTimeAndDate( $timestamp, $user );
1405 $row .= '<span class="history-deleted">' . $url . '</span>';
1406 } elseif ( !$file->exists() ) {
1407 $row .= '<span class="mw-file-missing">'
1408 . $lang->userTimeAndDate( $timestamp, $user ) . '</span>';
1410 $url = $iscur ?
$this->current
->getUrl() : $this->current
->getArchiveUrl( $img );
1411 $row .= Xml
::element(
1413 array( 'href' => $url ),
1414 $lang->userTimeAndDate( $timestamp, $user )
1420 if ( $this->showThumb
) {
1421 $row .= '<td>' . $this->getThumbForLine( $file ) . '</td>';
1424 // Image dimensions + size
1426 $row .= htmlspecialchars( $file->getDimensionsString() );
1427 $row .= $this->msg( 'word-separator' )->escaped();
1428 $row .= '<span style="white-space: nowrap;">';
1429 $row .= $this->msg( 'parentheses' )->sizeParams( $file->getSize() )->escaped();
1435 // Hide deleted usernames
1436 if ( $file->isDeleted( File
::DELETED_USER
) ) {
1437 $row .= '<span class="history-deleted">'
1438 . $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
1441 $row .= Linker
::userLink( $userId, $userText );
1442 $row .= '<span style="white-space: nowrap;">';
1443 $row .= Linker
::userToolLinks( $userId, $userText );
1446 $row .= htmlspecialchars( $userText );
1451 // Don't show deleted descriptions
1452 if ( $file->isDeleted( File
::DELETED_COMMENT
) ) {
1453 $row .= '<td><span class="history-deleted">' .
1454 $this->msg( 'rev-deleted-comment' )->escaped() . '</span></td>';
1456 $row .= '<td dir="' . $wgContLang->getDir() . '">' .
1457 Linker
::formatComment( $description, $this->title
) . '</td>';
1461 Hooks
::run( 'ImagePageFileHistoryLine', array( $this, $file, &$row, &$rowClass ) );
1462 $classAttr = $rowClass ?
" class='$rowClass'" : '';
1464 return "<tr{$classAttr}>{$row}</tr>\n";
1471 protected function getThumbForLine( $file ) {
1472 $lang = $this->getLanguage();
1473 $user = $this->getUser();
1474 if ( $file->allowInlineDisplay() && $file->userCan( File
::DELETED_FILE
, $user )
1475 && !$file->isDeleted( File
::DELETED_FILE
)
1481 $timestamp = wfTimestamp( TS_MW
, $file->getTimestamp() );
1483 $thumbnail = $file->transform( $params );
1485 'alt' => $this->msg( 'filehist-thumbtext',
1486 $lang->userTimeAndDate( $timestamp, $user ),
1487 $lang->userDate( $timestamp, $user ),
1488 $lang->userTime( $timestamp, $user ) )->text(),
1489 'file-link' => true,
1492 if ( !$thumbnail ) {
1493 return $this->msg( 'filehist-nothumb' )->escaped();
1496 return $thumbnail->toHtml( $options );
1498 return $this->msg( 'filehist-nothumb' )->escaped();
1503 * @param bool $enable
1505 protected function preventClickjacking( $enable = true ) {
1506 $this->preventClickjacking
= $enable;
1512 public function getPreventClickjacking() {
1513 return $this->preventClickjacking
;
1517 class ImageHistoryPseudoPager
extends ReverseChronologicalPager
{
1518 protected $preventClickjacking = false;
1531 * @param ImagePage $imagePage
1533 function __construct( $imagePage ) {
1534 parent
::__construct( $imagePage->getContext() );
1535 $this->mImagePage
= $imagePage;
1536 $this->mTitle
= clone $imagePage->getTitle();
1537 $this->mTitle
->setFragment( '#filehistory' );
1539 $this->mHist
= array();
1540 $this->mRange
= array( 0, 0 ); // display range
1546 function getTitle() {
1547 return $this->mTitle
;
1550 function getQueryInfo() {
1557 function getIndexField() {
1562 * @param object $row
1565 function formatRow( $row ) {
1572 function getBody() {
1575 if ( count( $this->mHist
) ) {
1576 if ( $this->mImg
->isLocal() ) {
1577 // Do a batch existence check for user pages and talkpages
1578 $linkBatch = new LinkBatch();
1579 for ( $i = $this->mRange
[0]; $i <= $this->mRange
[1]; $i++
) {
1580 $file = $this->mHist
[$i];
1581 $user = $file->getUser( 'text' );
1582 $linkBatch->add( NS_USER
, $user );
1583 $linkBatch->add( NS_USER_TALK
, $user );
1585 $linkBatch->execute();
1588 $list = new ImageHistoryList( $this->mImagePage
);
1589 # Generate prev/next links
1590 $navLink = $this->getNavigationBar();
1591 $s = $list->beginImageHistoryList( $navLink );
1592 // Skip rows there just for paging links
1593 for ( $i = $this->mRange
[0]; $i <= $this->mRange
[1]; $i++
) {
1594 $file = $this->mHist
[$i];
1595 $s .= $list->imageHistoryLine( !$file->isOld(), $file );
1597 $s .= $list->endImageHistoryList( $navLink );
1599 if ( $list->getPreventClickjacking() ) {
1600 $this->preventClickjacking();
1606 function doQuery() {
1607 if ( $this->mQueryDone
) {
1610 $this->mImg
= $this->mImagePage
->getFile(); // ensure loading
1611 if ( !$this->mImg
->exists() ) {
1614 $queryLimit = $this->mLimit +
1; // limit plus extra row
1615 if ( $this->mIsBackwards
) {
1616 // Fetch the file history
1617 $this->mHist
= $this->mImg
->getHistory( $queryLimit, null, $this->mOffset
, false );
1618 // The current rev may not meet the offset/limit
1619 $numRows = count( $this->mHist
);
1620 if ( $numRows <= $this->mLimit
&& $this->mImg
->getTimestamp() > $this->mOffset
) {
1621 $this->mHist
= array_merge( array( $this->mImg
), $this->mHist
);
1624 // The current rev may not meet the offset
1625 if ( !$this->mOffset ||
$this->mImg
->getTimestamp() < $this->mOffset
) {
1626 $this->mHist
[] = $this->mImg
;
1628 // Old image versions (fetch extra row for nav links)
1629 $oiLimit = count( $this->mHist
) ?
$this->mLimit
: $this->mLimit +
1;
1630 // Fetch the file history
1631 $this->mHist
= array_merge( $this->mHist
,
1632 $this->mImg
->getHistory( $oiLimit, $this->mOffset
, null, false ) );
1634 $numRows = count( $this->mHist
); // Total number of query results
1636 # Index value of top item in the list
1637 $firstIndex = $this->mIsBackwards ?
1638 $this->mHist
[$numRows - 1]->getTimestamp() : $this->mHist
[0]->getTimestamp();
1639 # Discard the extra result row if there is one
1640 if ( $numRows > $this->mLimit
&& $numRows > 1 ) {
1641 if ( $this->mIsBackwards
) {
1642 # Index value of item past the index
1643 $this->mPastTheEndIndex
= $this->mHist
[0]->getTimestamp();
1644 # Index value of bottom item in the list
1645 $lastIndex = $this->mHist
[1]->getTimestamp();
1647 $this->mRange
= array( 1, $numRows - 1 );
1649 # Index value of item past the index
1650 $this->mPastTheEndIndex
= $this->mHist
[$numRows - 1]->getTimestamp();
1651 # Index value of bottom item in the list
1652 $lastIndex = $this->mHist
[$numRows - 2]->getTimestamp();
1654 $this->mRange
= array( 0, $numRows - 2 );
1657 # Setting indexes to an empty string means that they will be
1658 # omitted if they would otherwise appear in URLs. It just so
1659 # happens that this is the right thing to do in the standard
1660 # UI, in all the relevant cases.
1661 $this->mPastTheEndIndex
= '';
1662 # Index value of bottom item in the list
1663 $lastIndex = $this->mIsBackwards ?
1664 $this->mHist
[0]->getTimestamp() : $this->mHist
[$numRows - 1]->getTimestamp();
1666 $this->mRange
= array( 0, $numRows - 1 );
1671 $this->mPastTheEndIndex
= '';
1673 if ( $this->mIsBackwards
) {
1674 $this->mIsFirst
= ( $numRows < $queryLimit );
1675 $this->mIsLast
= ( $this->mOffset
== '' );
1676 $this->mLastShown
= $firstIndex;
1677 $this->mFirstShown
= $lastIndex;
1679 $this->mIsFirst
= ( $this->mOffset
== '' );
1680 $this->mIsLast
= ( $numRows < $queryLimit );
1681 $this->mLastShown
= $lastIndex;
1682 $this->mFirstShown
= $firstIndex;
1684 $this->mQueryDone
= true;
1688 * @param bool $enable
1690 protected function preventClickjacking( $enable = true ) {
1691 $this->preventClickjacking
= $enable;
1697 public function getPreventClickjacking() {
1698 return $this->preventClickjacking
;