Cleanup to ImagePage::openShowImage()
[lhc/web/wiklou.git] / includes / ImagePage.php
1 <?php
2 /**
3 * Special handling for file description pages.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 */
22
23 /**
24 * Class for viewing MediaWiki file description pages
25 *
26 * @ingroup Media
27 */
28 class ImagePage extends Article {
29
30 /**
31 * @var File
32 */
33 private $displayImg;
34 /**
35 * @var FileRepo
36 */
37 private $repo;
38 private $fileLoaded;
39
40 var $mExtraDescription = false;
41
42 /**
43 * @param $title Title
44 * @return WikiFilePage
45 */
46 protected function newPage( Title $title ) {
47 // Overload mPage with a file-specific page
48 return new WikiFilePage( $title );
49 }
50
51 /**
52 * Constructor from a page id
53 * @param $id Int article ID to load
54 * @return ImagePage|null
55 */
56 public static function newFromID( $id ) {
57 $t = Title::newFromID( $id );
58 # @todo FIXME: Doesn't inherit right
59 return $t == null ? null : new self( $t );
60 # return $t == null ? null : new static( $t ); // PHP 5.3
61 }
62
63 /**
64 * @param $file File:
65 * @return void
66 */
67 public function setFile( $file ) {
68 $this->mPage->setFile( $file );
69 $this->displayImg = $file;
70 $this->fileLoaded = true;
71 }
72
73 protected function loadFile() {
74 if ( $this->fileLoaded ) {
75 return;
76 }
77 $this->fileLoaded = true;
78
79 $this->displayImg = $img = false;
80 wfRunHooks( 'ImagePageFindFile', array( $this, &$img, &$this->displayImg ) );
81 if ( !$img ) { // not set by hook?
82 $img = wfFindFile( $this->getTitle() );
83 if ( !$img ) {
84 $img = wfLocalFile( $this->getTitle() );
85 }
86 }
87 $this->mPage->setFile( $img );
88 if ( !$this->displayImg ) { // not set by hook?
89 $this->displayImg = $img;
90 }
91 $this->repo = $img->getRepo();
92 }
93
94 /**
95 * Handler for action=render
96 * Include body text only; none of the image extras
97 */
98 public function render() {
99 $this->getContext()->getOutput()->setArticleBodyOnly( true );
100 parent::view();
101 }
102
103 public function view() {
104 global $wgShowEXIF;
105
106 $out = $this->getContext()->getOutput();
107 $request = $this->getContext()->getRequest();
108 $diff = $request->getVal( 'diff' );
109 $diffOnly = $request->getBool( 'diffonly', $this->getContext()->getUser()->getOption( 'diffonly' ) );
110
111 if ( $this->getTitle()->getNamespace() != NS_FILE || ( isset( $diff ) && $diffOnly ) ) {
112 parent::view();
113 return;
114 }
115
116 $this->loadFile();
117
118 if ( $this->getTitle()->getNamespace() == NS_FILE && $this->mPage->getFile()->getRedirected() ) {
119 if ( $this->getTitle()->getDBkey() == $this->mPage->getFile()->getName() || isset( $diff ) ) {
120 // mTitle is the same as the redirect target so ask Article
121 // to perform the redirect for us.
122 $request->setVal( 'diffonly', 'true' );
123 parent::view();
124 return;
125 } else {
126 // mTitle is not the same as the redirect target so it is
127 // probably the redirect page itself. Fake the redirect symbol
128 $out->setPageTitle( $this->getTitle()->getPrefixedText() );
129 $out->addHTML( $this->viewRedirect( Title::makeTitle( NS_FILE, $this->mPage->getFile()->getName() ),
130 /* $appendSubtitle */ true, /* $forceKnown */ true ) );
131 $this->mPage->doViewUpdates( $this->getContext()->getUser() );
132 return;
133 }
134 }
135
136 if ( $wgShowEXIF && $this->displayImg->exists() ) {
137 // @todo FIXME: Bad interface, see note on MediaHandler::formatMetadata().
138 $formattedMetadata = $this->displayImg->formatMetadata();
139 $showmeta = $formattedMetadata !== false;
140 } else {
141 $showmeta = false;
142 }
143
144 if ( !$diff && $this->displayImg->exists() ) {
145 $out->addHTML( $this->showTOC( $showmeta ) );
146 }
147
148 if ( !$diff ) {
149 $this->openShowImage();
150 }
151
152 # No need to display noarticletext, we use our own message, output in openShowImage()
153 if ( $this->mPage->getID() ) {
154 # NS_FILE is in the user language, but this section (the actual wikitext)
155 # should be in page content language
156 $pageLang = $this->getTitle()->getPageViewLanguage();
157 $out->addHTML( Xml::openElement( 'div', array( 'id' => 'mw-imagepage-content',
158 'lang' => $pageLang->getHtmlCode(), 'dir' => $pageLang->getDir(),
159 'class' => 'mw-content-'.$pageLang->getDir() ) ) );
160
161 parent::view();
162
163 $out->addHTML( Xml::closeElement( 'div' ) );
164 } else {
165 # Just need to set the right headers
166 $out->setArticleFlag( true );
167 $out->setPageTitle( $this->getTitle()->getPrefixedText() );
168 $this->mPage->doViewUpdates( $this->getContext()->getUser() );
169 }
170
171 # Show shared description, if needed
172 if ( $this->mExtraDescription ) {
173 $fol = wfMessage( 'shareddescriptionfollows' );
174 if ( !$fol->isDisabled() ) {
175 $out->addWikiText( $fol->plain() );
176 }
177 $out->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription . "</div>\n" );
178 }
179
180 $this->closeShowImage();
181 $this->imageHistory();
182 // TODO: Cleanup the following
183
184 $out->addHTML( Xml::element( 'h2',
185 array( 'id' => 'filelinks' ),
186 wfMessage( 'imagelinks' )->text() ) . "\n" );
187 $this->imageDupes();
188 # @todo FIXME: For some freaky reason, we can't redirect to foreign images.
189 # Yet we return metadata about the target. Definitely an issue in the FileRepo
190 $this->imageLinks();
191
192 # Allow extensions to add something after the image links
193 $html = '';
194 wfRunHooks( 'ImagePageAfterImageLinks', array( $this, &$html ) );
195 if ( $html ) {
196 $out->addHTML( $html );
197 }
198
199 if ( $showmeta ) {
200 $out->addHTML( Xml::element(
201 'h2',
202 array( 'id' => 'metadata' ),
203 wfMessage( 'metadata' )->text() ) . "\n" );
204 $out->addWikiText( $this->makeMetadataTable( $formattedMetadata ) );
205 $out->addModules( array( 'mediawiki.action.view.metadata' ) );
206 }
207
208 // Add remote Filepage.css
209 if( !$this->repo->isLocal() ) {
210 $css = $this->repo->getDescriptionStylesheetUrl();
211 if ( $css ) {
212 $out->addStyle( $css );
213 }
214 }
215 // always show the local local Filepage.css, bug 29277
216 $out->addModuleStyles( 'filepage' );
217 }
218
219 /**
220 * @return File
221 */
222 public function getDisplayedFile() {
223 $this->loadFile();
224 return $this->displayImg;
225 }
226
227 /**
228 * Create the TOC
229 *
230 * @param $metadata Boolean: whether or not to show the metadata link
231 * @return String
232 */
233 protected function showTOC( $metadata ) {
234 $r = array(
235 '<li><a href="#file">' . wfMessage( 'file-anchor-link' )->escaped() . '</a></li>',
236 '<li><a href="#filehistory">' . wfMessage( 'filehist' )->escaped() . '</a></li>',
237 '<li><a href="#filelinks">' . wfMessage( 'imagelinks' )->escaped() . '</a></li>',
238 );
239 if ( $metadata ) {
240 $r[] = '<li><a href="#metadata">' . wfMessage( 'metadata' )->escaped() . '</a></li>';
241 }
242
243 wfRunHooks( 'ImagePageShowTOC', array( $this, &$r ) );
244
245 return '<ul id="filetoc">' . implode( "\n", $r ) . '</ul>';
246 }
247
248 /**
249 * Make a table with metadata to be shown in the output page.
250 *
251 * @todo FIXME: Bad interface, see note on MediaHandler::formatMetadata().
252 *
253 * @param $metadata Array: the array containing the EXIF data
254 * @return String The metadata table. This is treated as Wikitext (!)
255 */
256 protected function makeMetadataTable( $metadata ) {
257 $r = "<div class=\"mw-imagepage-section-metadata\">";
258 $r .= wfMessage( 'metadata-help' )->plain();
259 $r .= "<table id=\"mw_metadata\" class=\"mw_metadata\">\n";
260 foreach ( $metadata as $type => $stuff ) {
261 foreach ( $stuff as $v ) {
262 # @todo FIXME: Why is this using escapeId for a class?!
263 $class = Sanitizer::escapeId( $v['id'] );
264 if ( $type == 'collapsed' ) {
265 $class .= ' collapsable';
266 }
267 $r .= "<tr class=\"$class\">\n";
268 $r .= "<th>{$v['name']}</th>\n";
269 $r .= "<td>{$v['value']}</td>\n</tr>";
270 }
271 }
272 $r .= "</table>\n</div>\n";
273 return $r;
274 }
275
276 /**
277 * Overloading Article's getContentObject method.
278 *
279 * Omit noarticletext if sharedupload; text will be fetched from the
280 * shared upload server if possible.
281 * @return string
282 */
283 public function getContentObject() {
284 $this->loadFile();
285 if ( $this->mPage->getFile() && !$this->mPage->getFile()->isLocal() && 0 == $this->getID() ) {
286 return null;
287 }
288 return parent::getContentObject();
289 }
290
291 protected function openShowImage() {
292 global $wgImageLimits, $wgEnableUploads, $wgSend404Code;
293
294 $this->loadFile();
295 $out = $this->getContext()->getOutput();
296 $user = $this->getContext()->getUser();
297 $lang = $this->getContext()->getLanguage();
298 $dirmark = $lang->getDirMarkEntity();
299 $request = $this->getContext()->getRequest();
300
301 $sizeSel = intval( $user->getOption( 'imagesize' ) );
302 if ( !isset( $wgImageLimits[$sizeSel] ) ) {
303 $sizeSel = User::getDefaultOption( 'imagesize' );
304
305 // The user offset might still be incorrect, specially if
306 // $wgImageLimits got changed (see bug #8858).
307 if ( !isset( $wgImageLimits[$sizeSel] ) ) {
308 // Default to the first offset in $wgImageLimits
309 $sizeSel = 0;
310 }
311 }
312 $max = $wgImageLimits[$sizeSel];
313 $maxWidth = $max[0];
314 $maxHeight = $max[1];
315
316 if ( $this->displayImg->exists() ) {
317 # image
318 $page = $request->getIntOrNull( 'page' );
319 if ( is_null( $page ) ) {
320 $params = array();
321 $page = 1;
322 } else {
323 $params = array( 'page' => $page );
324 }
325 $width_orig = $this->displayImg->getWidth( $page );
326 $width = $width_orig;
327 $height_orig = $this->displayImg->getHeight( $page );
328 $height = $height_orig;
329
330 $filename = wfEscapeWikiText( $this->displayImg->getName() );
331 $linktext = $filename;
332
333 wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this, &$out ) );
334
335 if ( $this->displayImg->allowInlineDisplay() ) {
336 # image
337
338 # "Download high res version" link below the image
339 # $msgsize = wfMessage( 'file-info-size', $width_orig, $height_orig, Linker::formatSize( $this->displayImg->getSize() ), $mime )->escaped();
340 # We'll show a thumbnail of this image
341 if ( $width > $maxWidth || $height > $maxHeight ) {
342 # Calculate the thumbnail size.
343 # First case, the limiting factor is the width, not the height.
344 if ( $width / $height >= $maxWidth / $maxHeight ) { // FIXME: Possible divison by 0. bug 36911
345 $height = round( $height * $maxWidth / $width ); // FIXME: Possible divison by 0. bug 36911
346 $width = $maxWidth;
347 # Note that $height <= $maxHeight now.
348 } else {
349 $newwidth = floor( $width * $maxHeight / $height ); // FIXME: Possible divison by 0. bug 36911
350 $height = round( $height * $newwidth / $width ); // FIXME: Possible divison by 0. bug 36911
351 $width = $newwidth;
352 # Note that $height <= $maxHeight now, but might not be identical
353 # because of rounding.
354 }
355 $linktext = wfMessage( 'show-big-image' )->escaped();
356 if ( $this->displayImg->getRepo()->canTransformVia404() ) {
357 $thumbSizes = $wgImageLimits;
358 } else {
359 # Creating thumb links triggers thumbnail generation.
360 # Just generate the thumb for the current users prefs.
361 $thumbOption = $user->getOption( 'thumbsize' );
362 $thumbSizes = array( isset( $wgImageLimits[$thumbOption] )
363 ? $wgImageLimits[$thumbOption]
364 : $wgImageLimits[User::getDefaultOption( 'thumbsize' )] );
365 }
366 # Generate thumbnails or thumbnail links as needed...
367 $otherSizes = array();
368 foreach ( $thumbSizes as $size ) {
369 if ( $size[0] < $width_orig && $size[1] < $height_orig
370 && $size[0] != $width && $size[1] != $height )
371 {
372 $otherSizes[] = $this->makeSizeLink( $params, $size[0], $size[1] );
373 }
374 }
375 $msgsmall = wfMessage( 'show-big-image-preview' )->
376 rawParams( $this->makeSizeLink( $params, $width, $height ) )->
377 parse();
378 if ( count( $otherSizes ) ) {
379 $msgsmall .= ' ' .
380 Html::rawElement( 'span', array( 'class' => 'mw-filepage-other-resolutions' ),
381 wfMessage( 'show-big-image-other' )->rawParams( $lang->pipeList( $otherSizes ) )->
382 params( count( $otherSizes ) )->parse()
383 );
384 }
385 } elseif ( $width == 0 && $height == 0 ){
386 # Some sort of audio file that doesn't have dimensions
387 # Don't output a no hi res message for such a file
388 $msgsmall = '';
389 } elseif ( $this->displayImg->isVectorized() ) {
390 # For vectorized images, full size is just the frame size
391 $msgsmall = '';
392 } else {
393 # Image is small enough to show full size on image page
394 $msgsmall = wfMessage( 'file-nohires' )->parse();
395 }
396
397 $params['width'] = $width;
398 $params['height'] = $height;
399 $thumbnail = $this->displayImg->transform( $params );
400
401 $anchorclose = Html::rawElement( 'div', array( 'class' => 'mw-filepage-resolutioninfo' ), $msgsmall );
402
403 $isMulti = $this->displayImg->isMultipage() && $this->displayImg->pageCount() > 1;
404 if ( $isMulti ) {
405 $out->addHTML( '<table class="multipageimage"><tr><td>' );
406 }
407
408 if ( $thumbnail ) {
409 $options = array(
410 'alt' => $this->displayImg->getTitle()->getPrefixedText(),
411 'file-link' => true,
412 );
413 $out->addHTML( '<div class="fullImageLink" id="file">' .
414 $thumbnail->toHtml( $options ) .
415 $anchorclose . "</div>\n" );
416 }
417
418 if ( $isMulti ) {
419 $count = $this->displayImg->pageCount();
420
421 if ( $page > 1 ) {
422 $label = $out->parse( wfMessage( 'imgmultipageprev' )->text(), false );
423 $link = Linker::linkKnown(
424 $this->getTitle(),
425 $label,
426 array(),
427 array( 'page' => $page - 1 )
428 );
429 $thumb1 = Linker::makeThumbLinkObj( $this->getTitle(), $this->displayImg, $link, $label, 'none',
430 array( 'page' => $page - 1 ) );
431 } else {
432 $thumb1 = '';
433 }
434
435 if ( $page < $count ) {
436 $label = wfMessage( 'imgmultipagenext' )->text();
437 $link = Linker::linkKnown(
438 $this->getTitle(),
439 $label,
440 array(),
441 array( 'page' => $page + 1 )
442 );
443 $thumb2 = Linker::makeThumbLinkObj( $this->getTitle(), $this->displayImg, $link, $label, 'none',
444 array( 'page' => $page + 1 ) );
445 } else {
446 $thumb2 = '';
447 }
448
449 global $wgScript;
450
451 $formParams = array(
452 'name' => 'pageselector',
453 'action' => $wgScript,
454 'onchange' => 'document.pageselector.submit();',
455 );
456 $options = array();
457 for ( $i = 1; $i <= $count; $i++ ) {
458 $options[] = Xml::option( $lang->formatNum( $i ), $i, $i == $page );
459 }
460 $select = Xml::tags( 'select',
461 array( 'id' => 'pageselector', 'name' => 'page' ),
462 implode( "\n", $options ) );
463
464 $out->addHTML(
465 '</td><td><div class="multipageimagenavbox">' .
466 Xml::openElement( 'form', $formParams ) .
467 Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) .
468 wfMessage( 'imgmultigoto' )->rawParams( $select )->parse() .
469 Xml::submitButton( wfMessage( 'imgmultigo' )->text() ) .
470 Xml::closeElement( 'form' ) .
471 "<hr />$thumb1\n$thumb2<br style=\"clear: both\" /></div></td></tr></table>"
472 );
473 }
474 } elseif ( $this->displayImg->isSafeFile() ) {
475 # if direct link is allowed but it's not a renderable image, show an icon.
476 $icon = $this->displayImg->iconThumb();
477
478 $out->addHTML( '<div class="fullImageLink" id="file">' .
479 $icon->toHtml( array( 'file-link' => true ) ) .
480 "</div>\n" );
481 }
482
483 $longDesc = wfMessage( 'parentheses', $this->displayImg->getLongDesc() )->text();
484
485 $medialink = "[[Media:$filename|$linktext]]";
486
487 if ( !$this->displayImg->isSafeFile() ) {
488 $warning = wfMessage( 'mediawarning' )->plain();
489 // dirmark is needed here to separate the file name, which
490 // most likely ends in Latin characters, from the description,
491 // which may begin with the file type. In RTL environment
492 // this will get messy.
493 // The dirmark, however, must not be immediately adjacent
494 // to the filename, because it can get copied with it.
495 // See bug 25277.
496 $out->addWikiText( <<<EOT
497 <div class="fullMedia"><span class="dangerousLink">{$medialink}</span> $dirmark<span class="fileInfo">$longDesc</span></div>
498 <div class="mediaWarning">$warning</div>
499 EOT
500 );
501 } else {
502 $out->addWikiText( <<<EOT
503 <div class="fullMedia">{$medialink} {$dirmark}<span class="fileInfo">$longDesc</span>
504 </div>
505 EOT
506 );
507 }
508
509 // Add cannot animate thumbnail warning
510 if ( !$this->displayImg->canAnimateThumbIfAppropriate() ) {
511 // Include the extension so wiki admins can
512 // customize it on a per file-type basis
513 // (aka say things like use format X instead).
514 // additionally have a specific message for
515 // file-no-thumb-animation-gif
516 $ext = $this->displayImg->getExtension();
517 $noAnimMesg = wfMessageFallback(
518 'file-no-thumb-animation-' . $ext,
519 'file-no-thumb-animation'
520 )->plain();
521
522 $out->addWikiText( <<<EOT
523 <div class="mw-noanimatethumb">{$noAnimMesg}</div>
524 EOT
525 );
526 }
527
528 if ( !$this->displayImg->isLocal() ) {
529 $this->printSharedImageText();
530 }
531 } else {
532 # Image does not exist
533 if ( !$this->getID() ) {
534 # No article exists either
535 # Show deletion log to be consistent with normal articles
536 LogEventsList::showLogExtract(
537 $out,
538 array( 'delete', 'move' ),
539 $this->getTitle()->getPrefixedText(),
540 '',
541 array( 'lim' => 10,
542 'conds' => array( "log_action != 'revision'" ),
543 'showIfEmpty' => false,
544 'msgKey' => array( 'moveddeleted-notice' )
545 )
546 );
547 }
548
549 if ( $wgEnableUploads && $user->isAllowed( 'upload' ) ) {
550 // Only show an upload link if the user can upload
551 $uploadTitle = SpecialPage::getTitleFor( 'Upload' );
552 $nofile = array(
553 'filepage-nofile-link',
554 $uploadTitle->getFullURL( array( 'wpDestFile' => $this->mPage->getFile()->getName() ) )
555 );
556 } else {
557 $nofile = 'filepage-nofile';
558 }
559 // Note, if there is an image description page, but
560 // no image, then this setRobotPolicy is overriden
561 // by Article::View().
562 $out->setRobotPolicy( 'noindex,nofollow' );
563 $out->wrapWikiMsg( "<div id='mw-imagepage-nofile' class='plainlinks'>\n$1\n</div>", $nofile );
564 if ( !$this->getID() && $wgSend404Code ) {
565 // If there is no image, no shared image, and no description page,
566 // output a 404, to be consistent with articles.
567 $request->response()->header( 'HTTP/1.1 404 Not Found' );
568 }
569 }
570 $out->setFileVersion( $this->displayImg );
571 }
572
573 /**
574 * Creates an thumbnail of specified size and returns an HTML link to it
575 * @param $params array Scaler parameters
576 * @param $width int
577 * @param $height int
578 * @return string
579 */
580 private function makeSizeLink( $params, $width, $height ) {
581 $params['width'] = $width;
582 $params['height'] = $height;
583 $thumbnail = $this->displayImg->transform( $params );
584 if ( $thumbnail && !$thumbnail->isError() ) {
585 return Html::rawElement( 'a', array(
586 'href' => $thumbnail->getUrl(),
587 'class' => 'mw-thumbnail-link'
588 ), wfMessage( 'show-big-image-size' )->numParams(
589 $thumbnail->getWidth(), $thumbnail->getHeight()
590 )->parse() );
591 } else {
592 return '';
593 }
594 }
595
596 /**
597 * Show a notice that the file is from a shared repository
598 */
599 protected function printSharedImageText() {
600 $out = $this->getContext()->getOutput();
601 $this->loadFile();
602
603 $descUrl = $this->mPage->getFile()->getDescriptionUrl();
604 $descText = $this->mPage->getFile()->getDescriptionText();
605
606 /* Add canonical to head if there is no local page for this shared file */
607 if( $descUrl && $this->mPage->getID() == 0 ) {
608 $out->addLink( array( 'rel' => 'canonical', 'href' => $descUrl ) );
609 }
610
611 $wrap = "<div class=\"sharedUploadNotice\">\n$1\n</div>\n";
612 $repo = $this->mPage->getFile()->getRepo()->getDisplayName();
613
614 if ( $descUrl && $descText && wfMessage( 'sharedupload-desc-here' )->plain() !== '-' ) {
615 $out->wrapWikiMsg( $wrap, array( 'sharedupload-desc-here', $repo, $descUrl ) );
616 } elseif ( $descUrl && wfMessage( 'sharedupload-desc-there' )->plain() !== '-' ) {
617 $out->wrapWikiMsg( $wrap, array( 'sharedupload-desc-there', $repo, $descUrl ) );
618 } else {
619 $out->wrapWikiMsg( $wrap, array( 'sharedupload', $repo ), ''/*BACKCOMPAT*/ );
620 }
621
622 if ( $descText ) {
623 $this->mExtraDescription = $descText;
624 }
625 }
626
627 public function getUploadUrl() {
628 $this->loadFile();
629 $uploadTitle = SpecialPage::getTitleFor( 'Upload' );
630 return $uploadTitle->getFullURL( array(
631 'wpDestFile' => $this->mPage->getFile()->getName(),
632 'wpForReUpload' => 1
633 ) );
634 }
635
636 /**
637 * Print out the various links at the bottom of the image page, e.g. reupload,
638 * external editing (and instructions link) etc.
639 */
640 protected function uploadLinksBox() {
641 global $wgEnableUploads, $wgUseExternalEditor;
642
643 if ( !$wgEnableUploads ) {
644 return;
645 }
646
647 $this->loadFile();
648 if ( !$this->mPage->getFile()->isLocal() ) {
649 return;
650 }
651
652 $out = $this->getContext()->getOutput();
653 $out->addHTML( "<ul>\n" );
654
655 # "Upload a new version of this file" link
656 $canUpload = $this->getTitle()->userCan( 'upload', $this->getContext()->getUser() );
657 if ( $canUpload && UploadBase::userCanReUpload( $this->getContext()->getUser(), $this->mPage->getFile()->name ) ) {
658 $ulink = Linker::makeExternalLink( $this->getUploadUrl(), wfMessage( 'uploadnewversion-linktext' )->text() );
659 $out->addHTML( "<li id=\"mw-imagepage-reupload-link\"><div class=\"plainlinks\">{$ulink}</div></li>\n" );
660 } else {
661 $out->addHTML( "<li id=\"mw-imagepage-upload-disallowed\">" . $this->getContext()->msg( 'upload-disallowed-here' )->escaped() . "</li>\n" );
662 }
663
664 # External editing link
665 if ( $wgUseExternalEditor ) {
666 $elink = Linker::linkKnown(
667 $this->getTitle(),
668 wfMessage( 'edit-externally' )->escaped(),
669 array(),
670 array(
671 'action' => 'edit',
672 'externaledit' => 'true',
673 'mode' => 'file'
674 )
675 );
676 $out->addHTML(
677 '<li id="mw-imagepage-edit-external">' . $elink . ' <small>' .
678 wfMessage( 'edit-externally-help' )->parse() .
679 "</small></li>\n"
680 );
681 }
682
683 $out->addHTML( "</ul>\n" );
684 }
685
686 protected function closeShowImage() { } # For overloading
687
688 /**
689 * If the page we've just displayed is in the "Image" namespace,
690 * we follow it with an upload history of the image and its usage.
691 */
692 protected function imageHistory() {
693 $this->loadFile();
694 $out = $this->getContext()->getOutput();
695 $pager = new ImageHistoryPseudoPager( $this );
696 $out->addHTML( $pager->getBody() );
697 $out->preventClickjacking( $pager->getPreventClickjacking() );
698
699 $this->mPage->getFile()->resetHistory(); // free db resources
700
701 # Exist check because we don't want to show this on pages where an image
702 # doesn't exist along with the noimage message, that would suck. -ævar
703 if ( $this->mPage->getFile()->exists() ) {
704 $this->uploadLinksBox();
705 }
706 }
707
708 /**
709 * @param $target
710 * @param $limit
711 * @return ResultWrapper
712 */
713 protected function queryImageLinks( $target, $limit ) {
714 $dbr = wfGetDB( DB_SLAVE );
715
716 return $dbr->select(
717 array( 'imagelinks', 'page' ),
718 array( 'page_namespace', 'page_title', 'page_is_redirect', 'il_to' ),
719 array( 'il_to' => $target, 'il_from = page_id' ),
720 __METHOD__,
721 array( 'LIMIT' => $limit + 1, 'ORDER BY' => 'il_from', )
722 );
723 }
724
725 protected function imageLinks() {
726 $limit = 100;
727
728 $out = $this->getContext()->getOutput();
729 $res = $this->queryImageLinks( $this->getTitle()->getDbKey(), $limit + 1);
730 $rows = array();
731 $redirects = array();
732 foreach ( $res as $row ) {
733 if ( $row->page_is_redirect ) {
734 $redirects[$row->page_title] = array();
735 }
736 $rows[] = $row;
737 }
738 $count = count( $rows );
739
740 $hasMore = $count > $limit;
741 if ( !$hasMore && count( $redirects ) ) {
742 $res = $this->queryImageLinks( array_keys( $redirects ),
743 $limit - count( $rows ) + 1 );
744 foreach ( $res as $row ) {
745 $redirects[$row->il_to][] = $row;
746 $count++;
747 }
748 $hasMore = ( $res->numRows() + count( $rows ) ) > $limit;
749 }
750
751 if ( $count == 0 ) {
752 $out->wrapWikiMsg(
753 Html::rawElement( 'div',
754 array( 'id' => 'mw-imagepage-nolinkstoimage' ), "\n$1\n" ),
755 'nolinkstoimage'
756 );
757 return;
758 }
759
760 $out->addHTML( "<div id='mw-imagepage-section-linkstoimage'>\n" );
761 if ( !$hasMore ) {
762 $out->addWikiMsg( 'linkstoimage', $count );
763 } else {
764 // More links than the limit. Add a link to [[Special:Whatlinkshere]]
765 $out->addWikiMsg( 'linkstoimage-more',
766 $this->getContext()->getLanguage()->formatNum( $limit ),
767 $this->getTitle()->getPrefixedDBkey()
768 );
769 }
770
771 $out->addHTML(
772 Html::openElement( 'ul',
773 array( 'class' => 'mw-imagepage-linkstoimage' ) ) . "\n"
774 );
775 $count = 0;
776
777 // Sort the list by namespace:title
778 usort( $rows, array( $this, 'compare' ) );
779
780 // Create links for every element
781 $currentCount = 0;
782 foreach( $rows as $element ) {
783 $currentCount++;
784 if ( $currentCount > $limit ) {
785 break;
786 }
787
788 $link = Linker::linkKnown( Title::makeTitle( $element->page_namespace, $element->page_title ) );
789 if ( !isset( $redirects[$element->page_title] ) ) {
790 $liContents = $link;
791 } else {
792 $ul = "<ul class='mw-imagepage-redirectstofile'>\n";
793 foreach ( $redirects[$element->page_title] as $row ) {
794 $currentCount++;
795 if ( $currentCount > $limit ) {
796 break;
797 }
798
799 $link2 = Linker::linkKnown( Title::makeTitle( $row->page_namespace, $row->page_title ) );
800 $ul .= Html::rawElement(
801 'li',
802 array( 'class' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace ),
803 $link2
804 ) . "\n";
805 }
806 $ul .= '</ul>';
807 $liContents = wfMessage( 'linkstoimage-redirect' )->rawParams(
808 $link, $ul )->parse();
809 }
810 $out->addHTML( Html::rawElement(
811 'li',
812 array( 'class' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace ),
813 $liContents
814 ) . "\n"
815 );
816
817 };
818 $out->addHTML( Html::closeElement( 'ul' ) . "\n" );
819 $res->free();
820
821 // Add a links to [[Special:Whatlinkshere]]
822 if ( $count > $limit ) {
823 $out->addWikiMsg( 'morelinkstoimage', $this->getTitle()->getPrefixedDBkey() );
824 }
825 $out->addHTML( Html::closeElement( 'div' ) . "\n" );
826 }
827
828 protected function imageDupes() {
829 $this->loadFile();
830 $out = $this->getContext()->getOutput();
831
832 $dupes = $this->mPage->getDuplicates();
833 if ( count( $dupes ) == 0 ) {
834 return;
835 }
836
837 $out->addHTML( "<div id='mw-imagepage-section-duplicates'>\n" );
838 $out->addWikiMsg( 'duplicatesoffile',
839 $this->getContext()->getLanguage()->formatNum( count( $dupes ) ), $this->getTitle()->getDBkey()
840 );
841 $out->addHTML( "<ul class='mw-imagepage-duplicates'>\n" );
842
843 /**
844 * @var $file File
845 */
846 foreach ( $dupes as $file ) {
847 $fromSrc = '';
848 if ( $file->isLocal() ) {
849 $link = Linker::linkKnown( $file->getTitle() );
850 } else {
851 $link = Linker::makeExternalLink( $file->getDescriptionUrl(),
852 $file->getTitle()->getPrefixedText() );
853 $fromSrc = wfMessage( 'shared-repo-from', $file->getRepo()->getDisplayName() )->text();
854 }
855 $out->addHTML( "<li>{$link} {$fromSrc}</li>\n" );
856 }
857 $out->addHTML( "</ul></div>\n" );
858 }
859
860 /**
861 * Delete the file, or an earlier version of it
862 */
863 public function delete() {
864 $file = $this->mPage->getFile();
865 if ( !$file->exists() || !$file->isLocal() || $file->getRedirected() ) {
866 // Standard article deletion
867 parent::delete();
868 return;
869 }
870
871 $deleter = new FileDeleteForm( $file );
872 $deleter->execute();
873 }
874
875 /**
876 * Display an error with a wikitext description
877 *
878 * @param $description String
879 */
880 function showError( $description ) {
881 $out = $this->getContext()->getOutput();
882 $out->setPageTitle( wfMessage( 'internalerror' ) );
883 $out->setRobotPolicy( 'noindex,nofollow' );
884 $out->setArticleRelated( false );
885 $out->enableClientCache( false );
886 $out->addWikiText( $description );
887 }
888
889 /**
890 * Callback for usort() to do link sorts by (namespace, title)
891 * Function copied from Title::compare()
892 *
893 * @param $a object page to compare with
894 * @param $b object page to compare with
895 * @return Integer: result of string comparison, or namespace comparison
896 */
897 protected function compare( $a, $b ) {
898 if ( $a->page_namespace == $b->page_namespace ) {
899 return strcmp( $a->page_title, $b->page_title );
900 } else {
901 return $a->page_namespace - $b->page_namespace;
902 }
903 }
904 }
905
906 /**
907 * Builds the image revision log shown on image pages
908 *
909 * @ingroup Media
910 */
911 class ImageHistoryList extends ContextSource {
912
913 /**
914 * @var Title
915 */
916 protected $title;
917
918 /**
919 * @var File
920 */
921 protected $img;
922
923 /**
924 * @var ImagePage
925 */
926 protected $imagePage;
927
928 /**
929 * @var File
930 */
931 protected $current;
932
933 protected $repo, $showThumb;
934 protected $preventClickjacking = false;
935
936 /**
937 * @param ImagePage $imagePage
938 */
939 public function __construct( $imagePage ) {
940 global $wgShowArchiveThumbnails;
941 $this->current = $imagePage->getFile();
942 $this->img = $imagePage->getDisplayedFile();
943 $this->title = $imagePage->getTitle();
944 $this->imagePage = $imagePage;
945 $this->showThumb = $wgShowArchiveThumbnails && $this->img->canRender();
946 $this->setContext( $imagePage->getContext() );
947 }
948
949 /**
950 * @return ImagePage
951 */
952 public function getImagePage() {
953 return $this->imagePage;
954 }
955
956 /**
957 * @return File
958 */
959 public function getFile() {
960 return $this->img;
961 }
962
963 /**
964 * @param $navLinks string
965 * @return string
966 */
967 public function beginImageHistoryList( $navLinks = '' ) {
968 return Xml::element( 'h2', array( 'id' => 'filehistory' ), $this->msg( 'filehist' )->text() ) . "\n"
969 . "<div id=\"mw-imagepage-section-filehistory\">\n"
970 . $this->msg( 'filehist-help' )->parseAsBlock()
971 . $navLinks . "\n"
972 . Xml::openElement( 'table', array( 'class' => 'wikitable filehistory' ) ) . "\n"
973 . '<tr><td></td>'
974 . ( $this->current->isLocal() && ( $this->getUser()->isAllowedAny( 'delete', 'deletedhistory' ) ) ? '<td></td>' : '' )
975 . '<th>' . $this->msg( 'filehist-datetime' )->escaped() . '</th>'
976 . ( $this->showThumb ? '<th>' . $this->msg( 'filehist-thumb' )->escaped() . '</th>' : '' )
977 . '<th>' . $this->msg( 'filehist-dimensions' )->escaped() . '</th>'
978 . '<th>' . $this->msg( 'filehist-user' )->escaped() . '</th>'
979 . '<th>' . $this->msg( 'filehist-comment' )->escaped() . '</th>'
980 . "</tr>\n";
981 }
982
983 /**
984 * @param $navLinks string
985 * @return string
986 */
987 public function endImageHistoryList( $navLinks = '' ) {
988 return "</table>\n$navLinks\n</div>\n";
989 }
990
991 /**
992 * @param $iscur
993 * @param $file File
994 * @return string
995 */
996 public function imageHistoryLine( $iscur, $file ) {
997 global $wgContLang;
998
999 $user = $this->getUser();
1000 $lang = $this->getLanguage();
1001 $timestamp = wfTimestamp( TS_MW, $file->getTimestamp() );
1002 $img = $iscur ? $file->getName() : $file->getArchiveName();
1003 $userId = $file->getUser( 'id' );
1004 $userText = $file->getUser( 'text' );
1005 $description = $file->getDescription( File::FOR_THIS_USER, $user );
1006
1007 $local = $this->current->isLocal();
1008 $row = $selected = '';
1009
1010 // Deletion link
1011 if ( $local && ( $user->isAllowedAny( 'delete', 'deletedhistory' ) ) ) {
1012 $row .= '<td>';
1013 # Link to remove from history
1014 if ( $user->isAllowed( 'delete' ) ) {
1015 $q = array( 'action' => 'delete' );
1016 if ( !$iscur ) {
1017 $q['oldimage'] = $img;
1018 }
1019 $row .= Linker::linkKnown(
1020 $this->title,
1021 $this->msg( $iscur ? 'filehist-deleteall' : 'filehist-deleteone' )->escaped(),
1022 array(), $q
1023 );
1024 }
1025 # Link to hide content. Don't show useless link to people who cannot hide revisions.
1026 $canHide = $user->isAllowed( 'deleterevision' );
1027 if ( $canHide || ( $user->isAllowed( 'deletedhistory' ) && $file->getVisibility() ) ) {
1028 if ( $user->isAllowed( 'delete' ) ) {
1029 $row .= '<br />';
1030 }
1031 // If file is top revision or locked from this user, don't link
1032 if ( $iscur || !$file->userCan( File::DELETED_RESTRICTED, $user ) ) {
1033 $del = Linker::revDeleteLinkDisabled( $canHide );
1034 } else {
1035 list( $ts, ) = explode( '!', $img, 2 );
1036 $query = array(
1037 'type' => 'oldimage',
1038 'target' => $this->title->getPrefixedText(),
1039 'ids' => $ts,
1040 );
1041 $del = Linker::revDeleteLink( $query,
1042 $file->isDeleted( File::DELETED_RESTRICTED ), $canHide );
1043 }
1044 $row .= $del;
1045 }
1046 $row .= '</td>';
1047 }
1048
1049 // Reversion link/current indicator
1050 $row .= '<td>';
1051 if ( $iscur ) {
1052 $row .= $this->msg( 'filehist-current' )->escaped();
1053 } elseif ( $local && $this->title->quickUserCan( 'edit', $user )
1054 && $this->title->quickUserCan( 'upload', $user )
1055 ) {
1056 if ( $file->isDeleted( File::DELETED_FILE ) ) {
1057 $row .= $this->msg( 'filehist-revert' )->escaped();
1058 } else {
1059 $row .= Linker::linkKnown(
1060 $this->title,
1061 $this->msg( 'filehist-revert' )->escaped(),
1062 array(),
1063 array(
1064 'action' => 'revert',
1065 'oldimage' => $img,
1066 'wpEditToken' => $user->getEditToken( $img )
1067 )
1068 );
1069 }
1070 }
1071 $row .= '</td>';
1072
1073 // Date/time and image link
1074 if ( $file->getTimestamp() === $this->img->getTimestamp() ) {
1075 $selected = "class='filehistory-selected'";
1076 }
1077 $row .= "<td $selected style='white-space: nowrap;'>";
1078 if ( !$file->userCan( File::DELETED_FILE, $user ) ) {
1079 # Don't link to unviewable files
1080 $row .= '<span class="history-deleted">' . $lang->userTimeAndDate( $timestamp, $user ) . '</span>';
1081 } elseif ( $file->isDeleted( File::DELETED_FILE ) ) {
1082 if ( $local ) {
1083 $this->preventClickjacking();
1084 $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
1085 # Make a link to review the image
1086 $url = Linker::linkKnown(
1087 $revdel,
1088 $lang->userTimeAndDate( $timestamp, $user ),
1089 array(),
1090 array(
1091 'target' => $this->title->getPrefixedText(),
1092 'file' => $img,
1093 'token' => $user->getEditToken( $img )
1094 )
1095 );
1096 } else {
1097 $url = $lang->userTimeAndDate( $timestamp, $user );
1098 }
1099 $row .= '<span class="history-deleted">' . $url . '</span>';
1100 } else {
1101 $url = $iscur ? $this->current->getUrl() : $this->current->getArchiveUrl( $img );
1102 $row .= Xml::element( 'a', array( 'href' => $url ), $lang->userTimeAndDate( $timestamp, $user ) );
1103 }
1104 $row .= "</td>";
1105
1106 // Thumbnail
1107 if ( $this->showThumb ) {
1108 $row .= '<td>' . $this->getThumbForLine( $file ) . '</td>';
1109 }
1110
1111 // Image dimensions + size
1112 $row .= '<td>';
1113 $row .= htmlspecialchars( $file->getDimensionsString() );
1114 $row .= $this->msg( 'word-separator' )->plain();
1115 $row .= '<span style="white-space: nowrap;">';
1116 $row .= $this->msg( 'parentheses' )->rawParams( Linker::formatSize( $file->getSize() ) )->plain();
1117 $row .= '</span>';
1118 $row .= '</td>';
1119
1120 // Uploading user
1121 $row .= '<td>';
1122 // Hide deleted usernames
1123 if ( $file->isDeleted( File::DELETED_USER ) ) {
1124 $row .= '<span class="history-deleted">' . $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
1125 } else {
1126 if ( $local ) {
1127 $row .= Linker::userLink( $userId, $userText );
1128 $row .= $this->msg( 'word-separator' )->plain();
1129 $row .= '<span style="white-space: nowrap;">';
1130 $row .= Linker::userToolLinks( $userId, $userText );
1131 $row .= '</span>';
1132 } else {
1133 $row .= htmlspecialchars( $userText );
1134 }
1135 }
1136 $row .= '</td>';
1137
1138 // Don't show deleted descriptions
1139 if ( $file->isDeleted( File::DELETED_COMMENT ) ) {
1140 $row .= '<td><span class="history-deleted">' . $this->msg( 'rev-deleted-comment' )->escaped() . '</span></td>';
1141 } else {
1142 $row .= '<td dir="' . $wgContLang->getDir() . '">' . Linker::formatComment( $description, $this->title ) . '</td>';
1143 }
1144
1145 $rowClass = null;
1146 wfRunHooks( 'ImagePageFileHistoryLine', array( $this, $file, &$row, &$rowClass ) );
1147 $classAttr = $rowClass ? " class='$rowClass'" : '';
1148
1149 return "<tr{$classAttr}>{$row}</tr>\n";
1150 }
1151
1152 /**
1153 * @param $file File
1154 * @return string
1155 */
1156 protected function getThumbForLine( $file ) {
1157 $lang = $this->getLanguage();
1158 $user = $this->getUser();
1159 if ( $file->allowInlineDisplay() && $file->userCan( File::DELETED_FILE,$user )
1160 && !$file->isDeleted( File::DELETED_FILE ) )
1161 {
1162 $params = array(
1163 'width' => '120',
1164 'height' => '120',
1165 );
1166 $timestamp = wfTimestamp( TS_MW, $file->getTimestamp() );
1167
1168 $thumbnail = $file->transform( $params );
1169 $options = array(
1170 'alt' => $this->msg( 'filehist-thumbtext',
1171 $lang->userTimeAndDate( $timestamp, $user ),
1172 $lang->userDate( $timestamp, $user ),
1173 $lang->userTime( $timestamp, $user ) )->text(),
1174 'file-link' => true,
1175 );
1176
1177 if ( !$thumbnail ) {
1178 return $this->msg( 'filehist-nothumb' )->escaped();
1179 }
1180
1181 return $thumbnail->toHtml( $options );
1182 } else {
1183 return $this->msg( 'filehist-nothumb' )->escaped();
1184 }
1185 }
1186
1187 /**
1188 * @param $enable bool
1189 */
1190 protected function preventClickjacking( $enable = true ) {
1191 $this->preventClickjacking = $enable;
1192 }
1193
1194 /**
1195 * @return bool
1196 */
1197 public function getPreventClickjacking() {
1198 return $this->preventClickjacking;
1199 }
1200 }
1201
1202 class ImageHistoryPseudoPager extends ReverseChronologicalPager {
1203 protected $preventClickjacking = false;
1204
1205 /**
1206 * @var File
1207 */
1208 protected $mImg;
1209
1210 /**
1211 * @var Title
1212 */
1213 protected $mTitle;
1214
1215 /**
1216 * @param ImagePage $imagePage
1217 */
1218 function __construct( $imagePage ) {
1219 parent::__construct( $imagePage->getContext() );
1220 $this->mImagePage = $imagePage;
1221 $this->mTitle = clone ( $imagePage->getTitle() );
1222 $this->mTitle->setFragment( '#filehistory' );
1223 $this->mImg = null;
1224 $this->mHist = array();
1225 $this->mRange = array( 0, 0 ); // display range
1226 }
1227
1228 /**
1229 * @return Title
1230 */
1231 function getTitle() {
1232 return $this->mTitle;
1233 }
1234
1235 function getQueryInfo() {
1236 return false;
1237 }
1238
1239 /**
1240 * @return string
1241 */
1242 function getIndexField() {
1243 return '';
1244 }
1245
1246 /**
1247 * @param $row object
1248 * @return string
1249 */
1250 function formatRow( $row ) {
1251 return '';
1252 }
1253
1254 /**
1255 * @return string
1256 */
1257 function getBody() {
1258 $s = '';
1259 $this->doQuery();
1260 if ( count( $this->mHist ) ) {
1261 $list = new ImageHistoryList( $this->mImagePage );
1262 # Generate prev/next links
1263 $navLink = $this->getNavigationBar();
1264 $s = $list->beginImageHistoryList( $navLink );
1265 // Skip rows there just for paging links
1266 for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
1267 $file = $this->mHist[$i];
1268 $s .= $list->imageHistoryLine( !$file->isOld(), $file );
1269 }
1270 $s .= $list->endImageHistoryList( $navLink );
1271
1272 if ( $list->getPreventClickjacking() ) {
1273 $this->preventClickjacking();
1274 }
1275 }
1276 return $s;
1277 }
1278
1279 function doQuery() {
1280 if ( $this->mQueryDone ) {
1281 return;
1282 }
1283 $this->mImg = $this->mImagePage->getFile(); // ensure loading
1284 if ( !$this->mImg->exists() ) {
1285 return;
1286 }
1287 $queryLimit = $this->mLimit + 1; // limit plus extra row
1288 if ( $this->mIsBackwards ) {
1289 // Fetch the file history
1290 $this->mHist = $this->mImg->getHistory( $queryLimit, null, $this->mOffset, false );
1291 // The current rev may not meet the offset/limit
1292 $numRows = count( $this->mHist );
1293 if ( $numRows <= $this->mLimit && $this->mImg->getTimestamp() > $this->mOffset ) {
1294 $this->mHist = array_merge( array( $this->mImg ), $this->mHist );
1295 }
1296 } else {
1297 // The current rev may not meet the offset
1298 if ( !$this->mOffset || $this->mImg->getTimestamp() < $this->mOffset ) {
1299 $this->mHist[] = $this->mImg;
1300 }
1301 // Old image versions (fetch extra row for nav links)
1302 $oiLimit = count( $this->mHist ) ? $this->mLimit : $this->mLimit + 1;
1303 // Fetch the file history
1304 $this->mHist = array_merge( $this->mHist,
1305 $this->mImg->getHistory( $oiLimit, $this->mOffset, null, false ) );
1306 }
1307 $numRows = count( $this->mHist ); // Total number of query results
1308 if ( $numRows ) {
1309 # Index value of top item in the list
1310 $firstIndex = $this->mIsBackwards ?
1311 $this->mHist[$numRows - 1]->getTimestamp() : $this->mHist[0]->getTimestamp();
1312 # Discard the extra result row if there is one
1313 if ( $numRows > $this->mLimit && $numRows > 1 ) {
1314 if ( $this->mIsBackwards ) {
1315 # Index value of item past the index
1316 $this->mPastTheEndIndex = $this->mHist[0]->getTimestamp();
1317 # Index value of bottom item in the list
1318 $lastIndex = $this->mHist[1]->getTimestamp();
1319 # Display range
1320 $this->mRange = array( 1, $numRows - 1 );
1321 } else {
1322 # Index value of item past the index
1323 $this->mPastTheEndIndex = $this->mHist[$numRows - 1]->getTimestamp();
1324 # Index value of bottom item in the list
1325 $lastIndex = $this->mHist[$numRows - 2]->getTimestamp();
1326 # Display range
1327 $this->mRange = array( 0, $numRows - 2 );
1328 }
1329 } else {
1330 # Setting indexes to an empty string means that they will be
1331 # omitted if they would otherwise appear in URLs. It just so
1332 # happens that this is the right thing to do in the standard
1333 # UI, in all the relevant cases.
1334 $this->mPastTheEndIndex = '';
1335 # Index value of bottom item in the list
1336 $lastIndex = $this->mIsBackwards ?
1337 $this->mHist[0]->getTimestamp() : $this->mHist[$numRows - 1]->getTimestamp();
1338 # Display range
1339 $this->mRange = array( 0, $numRows - 1 );
1340 }
1341 } else {
1342 $firstIndex = '';
1343 $lastIndex = '';
1344 $this->mPastTheEndIndex = '';
1345 }
1346 if ( $this->mIsBackwards ) {
1347 $this->mIsFirst = ( $numRows < $queryLimit );
1348 $this->mIsLast = ( $this->mOffset == '' );
1349 $this->mLastShown = $firstIndex;
1350 $this->mFirstShown = $lastIndex;
1351 } else {
1352 $this->mIsFirst = ( $this->mOffset == '' );
1353 $this->mIsLast = ( $numRows < $queryLimit );
1354 $this->mLastShown = $lastIndex;
1355 $this->mFirstShown = $firstIndex;
1356 }
1357 $this->mQueryDone = true;
1358 }
1359
1360 /**
1361 * @param $enable bool
1362 */
1363 protected function preventClickjacking( $enable = true ) {
1364 $this->preventClickjacking = $enable;
1365 }
1366
1367 /**
1368 * @return bool
1369 */
1370 public function getPreventClickjacking() {
1371 return $this->preventClickjacking;
1372 }
1373
1374 }