merged master (2012-09-11)
[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 $longDesc = wfMessage( 'parentheses', $this->displayImg->getLongDesc() )->text();
331
332 wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this, &$out ) );
333
334 if ( $this->displayImg->allowInlineDisplay() ) {
335 # image
336
337 # "Download high res version" link below the image
338 # $msgsize = wfMessage( 'file-info-size', $width_orig, $height_orig, Linker::formatSize( $this->displayImg->getSize() ), $mime )->escaped();
339 # We'll show a thumbnail of this image
340 if ( $width > $maxWidth || $height > $maxHeight ) {
341 # Calculate the thumbnail size.
342 # First case, the limiting factor is the width, not the height.
343 if ( $width / $height >= $maxWidth / $maxHeight ) {
344 $height = round( $height * $maxWidth / $width );
345 $width = $maxWidth;
346 # Note that $height <= $maxHeight now.
347 } else {
348 $newwidth = floor( $width * $maxHeight / $height );
349 $height = round( $height * $newwidth / $width );
350 $width = $newwidth;
351 # Note that $height <= $maxHeight now, but might not be identical
352 # because of rounding.
353 }
354 $msgbig = wfMessage( 'show-big-image' )->escaped();
355 if ( $this->displayImg->getRepo()->canTransformVia404() ) {
356 $thumbSizes = $wgImageLimits;
357 } else {
358 # Creating thumb links triggers thumbnail generation.
359 # Just generate the thumb for the current users prefs.
360 $thumbOption = $user->getOption( 'thumbsize' );
361 $thumbSizes = array( isset( $wgImageLimits[$thumbOption] )
362 ? $wgImageLimits[$thumbOption]
363 : $wgImageLimits[User::getDefaultOption( 'thumbsize' )] );
364 }
365 # Generate thumbnails or thumbnail links as needed...
366 $otherSizes = array();
367 foreach ( $thumbSizes as $size ) {
368 if ( $size[0] < $width_orig && $size[1] < $height_orig
369 && $size[0] != $width && $size[1] != $height )
370 {
371 $otherSizes[] = $this->makeSizeLink( $params, $size[0], $size[1] );
372 }
373 }
374 $msgsmall = wfMessage( 'show-big-image-preview' )->
375 rawParams( $this->makeSizeLink( $params, $width, $height ) )->
376 parse();
377 if ( count( $otherSizes ) ) {
378 $msgsmall .= ' ' .
379 Html::rawElement( 'span', array( 'class' => 'mw-filepage-other-resolutions' ),
380 wfMessage( 'show-big-image-other' )->rawParams( $lang->pipeList( $otherSizes ) )->
381 params( count( $otherSizes ) )->parse()
382 );
383 }
384 } elseif ( $width == 0 && $height == 0 ){
385 # Some sort of audio file that doesn't have dimensions
386 # Don't output a no hi res message for such a file
387 $msgsmall = '';
388 } else {
389 # Image is small enough to show full size on image page
390 $msgsmall = wfMessage( 'file-nohires' )->parse();
391 }
392
393 $params['width'] = $width;
394 $params['height'] = $height;
395 $thumbnail = $this->displayImg->transform( $params );
396
397 $showLink = true;
398 $anchorclose = Html::rawElement( 'div', array( 'class' => 'mw-filepage-resolutioninfo' ), $msgsmall );
399
400 $isMulti = $this->displayImg->isMultipage() && $this->displayImg->pageCount() > 1;
401 if ( $isMulti ) {
402 $out->addHTML( '<table class="multipageimage"><tr><td>' );
403 }
404
405 if ( $thumbnail ) {
406 $options = array(
407 'alt' => $this->displayImg->getTitle()->getPrefixedText(),
408 'file-link' => true,
409 );
410 $out->addHTML( '<div class="fullImageLink" id="file">' .
411 $thumbnail->toHtml( $options ) .
412 $anchorclose . "</div>\n" );
413 }
414
415 if ( $isMulti ) {
416 $count = $this->displayImg->pageCount();
417
418 if ( $page > 1 ) {
419 $label = $out->parse( wfMessage( 'imgmultipageprev' )->text(), false );
420 $link = Linker::linkKnown(
421 $this->getTitle(),
422 $label,
423 array(),
424 array( 'page' => $page - 1 )
425 );
426 $thumb1 = Linker::makeThumbLinkObj( $this->getTitle(), $this->displayImg, $link, $label, 'none',
427 array( 'page' => $page - 1 ) );
428 } else {
429 $thumb1 = '';
430 }
431
432 if ( $page < $count ) {
433 $label = wfMessage( 'imgmultipagenext' )->text();
434 $link = Linker::linkKnown(
435 $this->getTitle(),
436 $label,
437 array(),
438 array( 'page' => $page + 1 )
439 );
440 $thumb2 = Linker::makeThumbLinkObj( $this->getTitle(), $this->displayImg, $link, $label, 'none',
441 array( 'page' => $page + 1 ) );
442 } else {
443 $thumb2 = '';
444 }
445
446 global $wgScript;
447
448 $formParams = array(
449 'name' => 'pageselector',
450 'action' => $wgScript,
451 'onchange' => 'document.pageselector.submit();',
452 );
453 $options = array();
454 for ( $i = 1; $i <= $count; $i++ ) {
455 $options[] = Xml::option( $lang->formatNum( $i ), $i, $i == $page );
456 }
457 $select = Xml::tags( 'select',
458 array( 'id' => 'pageselector', 'name' => 'page' ),
459 implode( "\n", $options ) );
460
461 $out->addHTML(
462 '</td><td><div class="multipageimagenavbox">' .
463 Xml::openElement( 'form', $formParams ) .
464 Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) .
465 wfMessage( 'imgmultigoto' )->rawParams( $select )->parse() .
466 Xml::submitButton( wfMessage( 'imgmultigo' )->text() ) .
467 Xml::closeElement( 'form' ) .
468 "<hr />$thumb1\n$thumb2<br style=\"clear: both\" /></div></td></tr></table>"
469 );
470 }
471 } else {
472 # if direct link is allowed but it's not a renderable image, show an icon.
473 if ( $this->displayImg->isSafeFile() ) {
474 $icon = $this->displayImg->iconThumb();
475
476 $out->addHTML( '<div class="fullImageLink" id="file">' .
477 $icon->toHtml( array( 'file-link' => true ) ) .
478 "</div>\n" );
479 }
480
481 $showLink = true;
482 }
483
484 if ( $showLink ) {
485 $filename = wfEscapeWikiText( $this->displayImg->getName() );
486 $linktext = $filename;
487 if ( isset( $msgbig ) ) {
488 $linktext = wfEscapeWikiText( $msgbig );
489 }
490 $medialink = "[[Media:$filename|$linktext]]";
491
492 if ( !$this->displayImg->isSafeFile() ) {
493 $warning = wfMessage( 'mediawarning' )->plain();
494 // dirmark is needed here to separate the file name, which
495 // most likely ends in Latin characters, from the description,
496 // which may begin with the file type. In RTL environment
497 // this will get messy.
498 // The dirmark, however, must not be immediately adjacent
499 // to the filename, because it can get copied with it.
500 // See bug 25277.
501 $out->addWikiText( <<<EOT
502 <div class="fullMedia"><span class="dangerousLink">{$medialink}</span> $dirmark<span class="fileInfo">$longDesc</span></div>
503 <div class="mediaWarning">$warning</div>
504 EOT
505 );
506 } else {
507 $out->addWikiText( <<<EOT
508 <div class="fullMedia">{$medialink} {$dirmark}<span class="fileInfo">$longDesc</span>
509 </div>
510 EOT
511 );
512 }
513 }
514
515 // Add cannot animate thumbnail warning
516 if ( !$this->displayImg->canAnimateThumbIfAppropriate() ) {
517 // Include the extension so wiki admins can
518 // customize it on a per file-type basis
519 // (aka say things like use format X instead).
520 // additionally have a specific message for
521 // file-no-thumb-animation-gif
522 $ext = $this->displayImg->getExtension();
523 $noAnimMesg = wfMessageFallback(
524 'file-no-thumb-animation-' . $ext,
525 'file-no-thumb-animation'
526 )->plain();
527
528 $out->addWikiText( <<<EOT
529 <div class="mw-noanimatethumb">{$noAnimMesg}</div>
530 EOT
531 );
532 }
533
534 if ( !$this->displayImg->isLocal() ) {
535 $this->printSharedImageText();
536 }
537 } else {
538 # Image does not exist
539 if ( !$this->getID() ) {
540 # No article exists either
541 # Show deletion log to be consistent with normal articles
542 LogEventsList::showLogExtract(
543 $out,
544 array( 'delete', 'move' ),
545 $this->getTitle()->getPrefixedText(),
546 '',
547 array( 'lim' => 10,
548 'conds' => array( "log_action != 'revision'" ),
549 'showIfEmpty' => false,
550 'msgKey' => array( 'moveddeleted-notice' )
551 )
552 );
553 }
554
555 if ( $wgEnableUploads && $user->isAllowed( 'upload' ) ) {
556 // Only show an upload link if the user can upload
557 $uploadTitle = SpecialPage::getTitleFor( 'Upload' );
558 $nofile = array(
559 'filepage-nofile-link',
560 $uploadTitle->getFullURL( array( 'wpDestFile' => $this->mPage->getFile()->getName() ) )
561 );
562 } else {
563 $nofile = 'filepage-nofile';
564 }
565 // Note, if there is an image description page, but
566 // no image, then this setRobotPolicy is overriden
567 // by Article::View().
568 $out->setRobotPolicy( 'noindex,nofollow' );
569 $out->wrapWikiMsg( "<div id='mw-imagepage-nofile' class='plainlinks'>\n$1\n</div>", $nofile );
570 if ( !$this->getID() && $wgSend404Code ) {
571 // If there is no image, no shared image, and no description page,
572 // output a 404, to be consistent with articles.
573 $request->response()->header( 'HTTP/1.1 404 Not Found' );
574 }
575 }
576 $out->setFileVersion( $this->displayImg );
577 }
578
579 /**
580 * Creates an thumbnail of specified size and returns an HTML link to it
581 * @param $params array Scaler parameters
582 * @param $width int
583 * @param $height int
584 * @return string
585 */
586 private function makeSizeLink( $params, $width, $height ) {
587 $params['width'] = $width;
588 $params['height'] = $height;
589 $thumbnail = $this->displayImg->transform( $params );
590 if ( $thumbnail && !$thumbnail->isError() ) {
591 return Html::rawElement( 'a', array(
592 'href' => $thumbnail->getUrl(),
593 'class' => 'mw-thumbnail-link'
594 ), wfMessage( 'show-big-image-size' )->numParams(
595 $thumbnail->getWidth(), $thumbnail->getHeight()
596 )->parse() );
597 } else {
598 return '';
599 }
600 }
601
602 /**
603 * Show a notice that the file is from a shared repository
604 */
605 protected function printSharedImageText() {
606 $out = $this->getContext()->getOutput();
607 $this->loadFile();
608
609 $descUrl = $this->mPage->getFile()->getDescriptionUrl();
610 $descText = $this->mPage->getFile()->getDescriptionText();
611
612 /* Add canonical to head if there is no local page for this shared file */
613 if( $descUrl && $this->mPage->getID() == 0 ) {
614 $out->addLink( array( 'rel' => 'canonical', 'href' => $descUrl ) );
615 }
616
617 $wrap = "<div class=\"sharedUploadNotice\">\n$1\n</div>\n";
618 $repo = $this->mPage->getFile()->getRepo()->getDisplayName();
619
620 if ( $descUrl && $descText && wfMessage( 'sharedupload-desc-here' )->plain() !== '-' ) {
621 $out->wrapWikiMsg( $wrap, array( 'sharedupload-desc-here', $repo, $descUrl ) );
622 } elseif ( $descUrl && wfMessage( 'sharedupload-desc-there' )->plain() !== '-' ) {
623 $out->wrapWikiMsg( $wrap, array( 'sharedupload-desc-there', $repo, $descUrl ) );
624 } else {
625 $out->wrapWikiMsg( $wrap, array( 'sharedupload', $repo ), ''/*BACKCOMPAT*/ );
626 }
627
628 if ( $descText ) {
629 $this->mExtraDescription = $descText;
630 }
631 }
632
633 public function getUploadUrl() {
634 $this->loadFile();
635 $uploadTitle = SpecialPage::getTitleFor( 'Upload' );
636 return $uploadTitle->getFullURL( array(
637 'wpDestFile' => $this->mPage->getFile()->getName(),
638 'wpForReUpload' => 1
639 ) );
640 }
641
642 /**
643 * Print out the various links at the bottom of the image page, e.g. reupload,
644 * external editing (and instructions link) etc.
645 */
646 protected function uploadLinksBox() {
647 global $wgEnableUploads, $wgUseExternalEditor;
648
649 if ( !$wgEnableUploads ) {
650 return;
651 }
652
653 $this->loadFile();
654 if ( !$this->mPage->getFile()->isLocal() ) {
655 return;
656 }
657
658 $out = $this->getContext()->getOutput();
659 $out->addHTML( "<ul>\n" );
660
661 # "Upload a new version of this file" link
662 $canUpload = $this->getTitle()->userCan( 'upload', $this->getContext()->getUser() );
663 if ( $canUpload && UploadBase::userCanReUpload( $this->getContext()->getUser(), $this->mPage->getFile()->name ) ) {
664 $ulink = Linker::makeExternalLink( $this->getUploadUrl(), wfMessage( 'uploadnewversion-linktext' )->text() );
665 $out->addHTML( "<li id=\"mw-imagepage-reupload-link\"><div class=\"plainlinks\">{$ulink}</div></li>\n" );
666 } else {
667 $out->addHTML( "<li id=\"mw-imagepage-upload-disallowed\">" . $this->getContext()->msg( 'upload-disallowed-here' )->escaped() . "</li>\n" );
668 }
669
670 # External editing link
671 if ( $wgUseExternalEditor ) {
672 $elink = Linker::linkKnown(
673 $this->getTitle(),
674 wfMessage( 'edit-externally' )->escaped(),
675 array(),
676 array(
677 'action' => 'edit',
678 'externaledit' => 'true',
679 'mode' => 'file'
680 )
681 );
682 $out->addHTML(
683 '<li id="mw-imagepage-edit-external">' . $elink . ' <small>' .
684 wfMessage( 'edit-externally-help' )->parse() .
685 "</small></li>\n"
686 );
687 }
688
689 $out->addHTML( "</ul>\n" );
690 }
691
692 protected function closeShowImage() { } # For overloading
693
694 /**
695 * If the page we've just displayed is in the "Image" namespace,
696 * we follow it with an upload history of the image and its usage.
697 */
698 protected function imageHistory() {
699 $this->loadFile();
700 $out = $this->getContext()->getOutput();
701 $pager = new ImageHistoryPseudoPager( $this );
702 $out->addHTML( $pager->getBody() );
703 $out->preventClickjacking( $pager->getPreventClickjacking() );
704
705 $this->mPage->getFile()->resetHistory(); // free db resources
706
707 # Exist check because we don't want to show this on pages where an image
708 # doesn't exist along with the noimage message, that would suck. -ævar
709 if ( $this->mPage->getFile()->exists() ) {
710 $this->uploadLinksBox();
711 }
712 }
713
714 /**
715 * @param $target
716 * @param $limit
717 * @return ResultWrapper
718 */
719 protected function queryImageLinks( $target, $limit ) {
720 $dbr = wfGetDB( DB_SLAVE );
721
722 return $dbr->select(
723 array( 'imagelinks', 'page' ),
724 array( 'page_namespace', 'page_title', 'page_is_redirect', 'il_to' ),
725 array( 'il_to' => $target, 'il_from = page_id' ),
726 __METHOD__,
727 array( 'LIMIT' => $limit + 1, 'ORDER BY' => 'il_from', )
728 );
729 }
730
731 protected function imageLinks() {
732 $limit = 100;
733
734 $out = $this->getContext()->getOutput();
735 $res = $this->queryImageLinks( $this->getTitle()->getDbKey(), $limit + 1);
736 $rows = array();
737 $redirects = array();
738 foreach ( $res as $row ) {
739 if ( $row->page_is_redirect ) {
740 $redirects[$row->page_title] = array();
741 }
742 $rows[] = $row;
743 }
744 $count = count( $rows );
745
746 $hasMore = $count > $limit;
747 if ( !$hasMore && count( $redirects ) ) {
748 $res = $this->queryImageLinks( array_keys( $redirects ),
749 $limit - count( $rows ) + 1 );
750 foreach ( $res as $row ) {
751 $redirects[$row->il_to][] = $row;
752 $count++;
753 }
754 $hasMore = ( $res->numRows() + count( $rows ) ) > $limit;
755 }
756
757 if ( $count == 0 ) {
758 $out->wrapWikiMsg(
759 Html::rawElement( 'div',
760 array( 'id' => 'mw-imagepage-nolinkstoimage' ), "\n$1\n" ),
761 'nolinkstoimage'
762 );
763 return;
764 }
765
766 $out->addHTML( "<div id='mw-imagepage-section-linkstoimage'>\n" );
767 if ( !$hasMore ) {
768 $out->addWikiMsg( 'linkstoimage', $count );
769 } else {
770 // More links than the limit. Add a link to [[Special:Whatlinkshere]]
771 $out->addWikiMsg( 'linkstoimage-more',
772 $this->getContext()->getLanguage()->formatNum( $limit ),
773 $this->getTitle()->getPrefixedDBkey()
774 );
775 }
776
777 $out->addHTML(
778 Html::openElement( 'ul',
779 array( 'class' => 'mw-imagepage-linkstoimage' ) ) . "\n"
780 );
781 $count = 0;
782
783 // Sort the list by namespace:title
784 usort( $rows, array( $this, 'compare' ) );
785
786 // Create links for every element
787 $currentCount = 0;
788 foreach( $rows as $element ) {
789 $currentCount++;
790 if ( $currentCount > $limit ) {
791 break;
792 }
793
794 $link = Linker::linkKnown( Title::makeTitle( $element->page_namespace, $element->page_title ) );
795 if ( !isset( $redirects[$element->page_title] ) ) {
796 $liContents = $link;
797 } else {
798 $ul = "<ul class='mw-imagepage-redirectstofile'>\n";
799 foreach ( $redirects[$element->page_title] as $row ) {
800 $currentCount++;
801 if ( $currentCount > $limit ) {
802 break;
803 }
804
805 $link2 = Linker::linkKnown( Title::makeTitle( $row->page_namespace, $row->page_title ) );
806 $ul .= Html::rawElement(
807 'li',
808 array( 'class' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace ),
809 $link2
810 ) . "\n";
811 }
812 $ul .= '</ul>';
813 $liContents = wfMessage( 'linkstoimage-redirect' )->rawParams(
814 $link, $ul )->parse();
815 }
816 $out->addHTML( Html::rawElement(
817 'li',
818 array( 'class' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace ),
819 $liContents
820 ) . "\n"
821 );
822
823 };
824 $out->addHTML( Html::closeElement( 'ul' ) . "\n" );
825 $res->free();
826
827 // Add a links to [[Special:Whatlinkshere]]
828 if ( $count > $limit ) {
829 $out->addWikiMsg( 'morelinkstoimage', $this->getTitle()->getPrefixedDBkey() );
830 }
831 $out->addHTML( Html::closeElement( 'div' ) . "\n" );
832 }
833
834 protected function imageDupes() {
835 $this->loadFile();
836 $out = $this->getContext()->getOutput();
837
838 $dupes = $this->mPage->getDuplicates();
839 if ( count( $dupes ) == 0 ) {
840 return;
841 }
842
843 $out->addHTML( "<div id='mw-imagepage-section-duplicates'>\n" );
844 $out->addWikiMsg( 'duplicatesoffile',
845 $this->getContext()->getLanguage()->formatNum( count( $dupes ) ), $this->getTitle()->getDBkey()
846 );
847 $out->addHTML( "<ul class='mw-imagepage-duplicates'>\n" );
848
849 /**
850 * @var $file File
851 */
852 foreach ( $dupes as $file ) {
853 $fromSrc = '';
854 if ( $file->isLocal() ) {
855 $link = Linker::linkKnown( $file->getTitle() );
856 } else {
857 $link = Linker::makeExternalLink( $file->getDescriptionUrl(),
858 $file->getTitle()->getPrefixedText() );
859 $fromSrc = wfMessage( 'shared-repo-from', $file->getRepo()->getDisplayName() )->text();
860 }
861 $out->addHTML( "<li>{$link} {$fromSrc}</li>\n" );
862 }
863 $out->addHTML( "</ul></div>\n" );
864 }
865
866 /**
867 * Delete the file, or an earlier version of it
868 */
869 public function delete() {
870 $file = $this->mPage->getFile();
871 if ( !$file->exists() || !$file->isLocal() || $file->getRedirected() ) {
872 // Standard article deletion
873 parent::delete();
874 return;
875 }
876
877 $deleter = new FileDeleteForm( $file );
878 $deleter->execute();
879 }
880
881 /**
882 * Display an error with a wikitext description
883 *
884 * @param $description String
885 */
886 function showError( $description ) {
887 $out = $this->getContext()->getOutput();
888 $out->setPageTitle( wfMessage( 'internalerror' ) );
889 $out->setRobotPolicy( 'noindex,nofollow' );
890 $out->setArticleRelated( false );
891 $out->enableClientCache( false );
892 $out->addWikiText( $description );
893 }
894
895 /**
896 * Callback for usort() to do link sorts by (namespace, title)
897 * Function copied from Title::compare()
898 *
899 * @param $a object page to compare with
900 * @param $b object page to compare with
901 * @return Integer: result of string comparison, or namespace comparison
902 */
903 protected function compare( $a, $b ) {
904 if ( $a->page_namespace == $b->page_namespace ) {
905 return strcmp( $a->page_title, $b->page_title );
906 } else {
907 return $a->page_namespace - $b->page_namespace;
908 }
909 }
910 }
911
912 /**
913 * Builds the image revision log shown on image pages
914 *
915 * @ingroup Media
916 */
917 class ImageHistoryList extends ContextSource {
918
919 /**
920 * @var Title
921 */
922 protected $title;
923
924 /**
925 * @var File
926 */
927 protected $img;
928
929 /**
930 * @var ImagePage
931 */
932 protected $imagePage;
933
934 /**
935 * @var File
936 */
937 protected $current;
938
939 protected $repo, $showThumb;
940 protected $preventClickjacking = false;
941
942 /**
943 * @param ImagePage $imagePage
944 */
945 public function __construct( $imagePage ) {
946 global $wgShowArchiveThumbnails;
947 $this->current = $imagePage->getFile();
948 $this->img = $imagePage->getDisplayedFile();
949 $this->title = $imagePage->getTitle();
950 $this->imagePage = $imagePage;
951 $this->showThumb = $wgShowArchiveThumbnails && $this->img->canRender();
952 $this->setContext( $imagePage->getContext() );
953 }
954
955 /**
956 * @return ImagePage
957 */
958 public function getImagePage() {
959 return $this->imagePage;
960 }
961
962 /**
963 * @return File
964 */
965 public function getFile() {
966 return $this->img;
967 }
968
969 /**
970 * @param $navLinks string
971 * @return string
972 */
973 public function beginImageHistoryList( $navLinks = '' ) {
974 return Xml::element( 'h2', array( 'id' => 'filehistory' ), $this->msg( 'filehist' )->text() ) . "\n"
975 . "<div id=\"mw-imagepage-section-filehistory\">\n"
976 . $this->msg( 'filehist-help' )->parseAsBlock()
977 . $navLinks . "\n"
978 . Xml::openElement( 'table', array( 'class' => 'wikitable filehistory' ) ) . "\n"
979 . '<tr><td></td>'
980 . ( $this->current->isLocal() && ( $this->getUser()->isAllowedAny( 'delete', 'deletedhistory' ) ) ? '<td></td>' : '' )
981 . '<th>' . $this->msg( 'filehist-datetime' )->escaped() . '</th>'
982 . ( $this->showThumb ? '<th>' . $this->msg( 'filehist-thumb' )->escaped() . '</th>' : '' )
983 . '<th>' . $this->msg( 'filehist-dimensions' )->escaped() . '</th>'
984 . '<th>' . $this->msg( 'filehist-user' )->escaped() . '</th>'
985 . '<th>' . $this->msg( 'filehist-comment' )->escaped() . '</th>'
986 . "</tr>\n";
987 }
988
989 /**
990 * @param $navLinks string
991 * @return string
992 */
993 public function endImageHistoryList( $navLinks = '' ) {
994 return "</table>\n$navLinks\n</div>\n";
995 }
996
997 /**
998 * @param $iscur
999 * @param $file File
1000 * @return string
1001 */
1002 public function imageHistoryLine( $iscur, $file ) {
1003 global $wgContLang;
1004
1005 $user = $this->getUser();
1006 $lang = $this->getLanguage();
1007 $timestamp = wfTimestamp( TS_MW, $file->getTimestamp() );
1008 $img = $iscur ? $file->getName() : $file->getArchiveName();
1009 $userId = $file->getUser( 'id' );
1010 $userText = $file->getUser( 'text' );
1011 $description = $file->getDescription( File::FOR_THIS_USER, $user );
1012
1013 $local = $this->current->isLocal();
1014 $row = $selected = '';
1015
1016 // Deletion link
1017 if ( $local && ( $user->isAllowedAny( 'delete', 'deletedhistory' ) ) ) {
1018 $row .= '<td>';
1019 # Link to remove from history
1020 if ( $user->isAllowed( 'delete' ) ) {
1021 $q = array( 'action' => 'delete' );
1022 if ( !$iscur ) {
1023 $q['oldimage'] = $img;
1024 }
1025 $row .= Linker::linkKnown(
1026 $this->title,
1027 $this->msg( $iscur ? 'filehist-deleteall' : 'filehist-deleteone' )->escaped(),
1028 array(), $q
1029 );
1030 }
1031 # Link to hide content. Don't show useless link to people who cannot hide revisions.
1032 $canHide = $user->isAllowed( 'deleterevision' );
1033 if ( $canHide || ( $user->isAllowed( 'deletedhistory' ) && $file->getVisibility() ) ) {
1034 if ( $user->isAllowed( 'delete' ) ) {
1035 $row .= '<br />';
1036 }
1037 // If file is top revision or locked from this user, don't link
1038 if ( $iscur || !$file->userCan( File::DELETED_RESTRICTED, $user ) ) {
1039 $del = Linker::revDeleteLinkDisabled( $canHide );
1040 } else {
1041 list( $ts, ) = explode( '!', $img, 2 );
1042 $query = array(
1043 'type' => 'oldimage',
1044 'target' => $this->title->getPrefixedText(),
1045 'ids' => $ts,
1046 );
1047 $del = Linker::revDeleteLink( $query,
1048 $file->isDeleted( File::DELETED_RESTRICTED ), $canHide );
1049 }
1050 $row .= $del;
1051 }
1052 $row .= '</td>';
1053 }
1054
1055 // Reversion link/current indicator
1056 $row .= '<td>';
1057 if ( $iscur ) {
1058 $row .= $this->msg( 'filehist-current' )->escaped();
1059 } elseif ( $local && $this->title->quickUserCan( 'edit', $user )
1060 && $this->title->quickUserCan( 'upload', $user )
1061 ) {
1062 if ( $file->isDeleted( File::DELETED_FILE ) ) {
1063 $row .= $this->msg( 'filehist-revert' )->escaped();
1064 } else {
1065 $row .= Linker::linkKnown(
1066 $this->title,
1067 $this->msg( 'filehist-revert' )->escaped(),
1068 array(),
1069 array(
1070 'action' => 'revert',
1071 'oldimage' => $img,
1072 'wpEditToken' => $user->getEditToken( $img )
1073 )
1074 );
1075 }
1076 }
1077 $row .= '</td>';
1078
1079 // Date/time and image link
1080 if ( $file->getTimestamp() === $this->img->getTimestamp() ) {
1081 $selected = "class='filehistory-selected'";
1082 }
1083 $row .= "<td $selected style='white-space: nowrap;'>";
1084 if ( !$file->userCan( File::DELETED_FILE, $user ) ) {
1085 # Don't link to unviewable files
1086 $row .= '<span class="history-deleted">' . $lang->userTimeAndDate( $timestamp, $user ) . '</span>';
1087 } elseif ( $file->isDeleted( File::DELETED_FILE ) ) {
1088 if ( $local ) {
1089 $this->preventClickjacking();
1090 $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
1091 # Make a link to review the image
1092 $url = Linker::linkKnown(
1093 $revdel,
1094 $lang->userTimeAndDate( $timestamp, $user ),
1095 array(),
1096 array(
1097 'target' => $this->title->getPrefixedText(),
1098 'file' => $img,
1099 'token' => $user->getEditToken( $img )
1100 )
1101 );
1102 } else {
1103 $url = $lang->userTimeAndDate( $timestamp, $user );
1104 }
1105 $row .= '<span class="history-deleted">' . $url . '</span>';
1106 } else {
1107 $url = $iscur ? $this->current->getUrl() : $this->current->getArchiveUrl( $img );
1108 $row .= Xml::element( 'a', array( 'href' => $url ), $lang->userTimeAndDate( $timestamp, $user ) );
1109 }
1110 $row .= "</td>";
1111
1112 // Thumbnail
1113 if ( $this->showThumb ) {
1114 $row .= '<td>' . $this->getThumbForLine( $file ) . '</td>';
1115 }
1116
1117 // Image dimensions + size
1118 $row .= '<td>';
1119 $row .= htmlspecialchars( $file->getDimensionsString() );
1120 $row .= $this->msg( 'word-separator' )->plain();
1121 $row .= '<span style="white-space: nowrap;">';
1122 $row .= $this->msg( 'parentheses' )->rawParams( Linker::formatSize( $file->getSize() ) )->plain();
1123 $row .= '</span>';
1124 $row .= '</td>';
1125
1126 // Uploading user
1127 $row .= '<td>';
1128 // Hide deleted usernames
1129 if ( $file->isDeleted( File::DELETED_USER ) ) {
1130 $row .= '<span class="history-deleted">' . $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
1131 } else {
1132 if ( $local ) {
1133 $row .= Linker::userLink( $userId, $userText );
1134 $row .= $this->msg( 'word-separator' )->plain();
1135 $row .= '<span style="white-space: nowrap;">';
1136 $row .= Linker::userToolLinks( $userId, $userText );
1137 $row .= '</span>';
1138 } else {
1139 $row .= htmlspecialchars( $userText );
1140 }
1141 }
1142 $row .= '</td>';
1143
1144 // Don't show deleted descriptions
1145 if ( $file->isDeleted( File::DELETED_COMMENT ) ) {
1146 $row .= '<td><span class="history-deleted">' . $this->msg( 'rev-deleted-comment' )->escaped() . '</span></td>';
1147 } else {
1148 $row .= '<td dir="' . $wgContLang->getDir() . '">' . Linker::formatComment( $description, $this->title ) . '</td>';
1149 }
1150
1151 $rowClass = null;
1152 wfRunHooks( 'ImagePageFileHistoryLine', array( $this, $file, &$row, &$rowClass ) );
1153 $classAttr = $rowClass ? " class='$rowClass'" : '';
1154
1155 return "<tr{$classAttr}>{$row}</tr>\n";
1156 }
1157
1158 /**
1159 * @param $file File
1160 * @return string
1161 */
1162 protected function getThumbForLine( $file ) {
1163 $lang = $this->getLanguage();
1164 $user = $this->getUser();
1165 if ( $file->allowInlineDisplay() && $file->userCan( File::DELETED_FILE,$user )
1166 && !$file->isDeleted( File::DELETED_FILE ) )
1167 {
1168 $params = array(
1169 'width' => '120',
1170 'height' => '120',
1171 );
1172 $timestamp = wfTimestamp( TS_MW, $file->getTimestamp() );
1173
1174 $thumbnail = $file->transform( $params );
1175 $options = array(
1176 'alt' => $this->msg( 'filehist-thumbtext',
1177 $lang->userTimeAndDate( $timestamp, $user ),
1178 $lang->userDate( $timestamp, $user ),
1179 $lang->userTime( $timestamp, $user ) )->text(),
1180 'file-link' => true,
1181 );
1182
1183 if ( !$thumbnail ) {
1184 return $this->msg( 'filehist-nothumb' )->escaped();
1185 }
1186
1187 return $thumbnail->toHtml( $options );
1188 } else {
1189 return $this->msg( 'filehist-nothumb' )->escaped();
1190 }
1191 }
1192
1193 /**
1194 * @param $enable bool
1195 */
1196 protected function preventClickjacking( $enable = true ) {
1197 $this->preventClickjacking = $enable;
1198 }
1199
1200 /**
1201 * @return bool
1202 */
1203 public function getPreventClickjacking() {
1204 return $this->preventClickjacking;
1205 }
1206 }
1207
1208 class ImageHistoryPseudoPager extends ReverseChronologicalPager {
1209 protected $preventClickjacking = false;
1210
1211 /**
1212 * @var File
1213 */
1214 protected $mImg;
1215
1216 /**
1217 * @var Title
1218 */
1219 protected $mTitle;
1220
1221 /**
1222 * @param ImagePage $imagePage
1223 */
1224 function __construct( $imagePage ) {
1225 parent::__construct();
1226 $this->mImagePage = $imagePage;
1227 $this->mTitle = clone ( $imagePage->getTitle() );
1228 $this->mTitle->setFragment( '#filehistory' );
1229 $this->mImg = null;
1230 $this->mHist = array();
1231 $this->mRange = array( 0, 0 ); // display range
1232 }
1233
1234 /**
1235 * @return Title
1236 */
1237 function getTitle() {
1238 return $this->mTitle;
1239 }
1240
1241 function getQueryInfo() {
1242 return false;
1243 }
1244
1245 /**
1246 * @return string
1247 */
1248 function getIndexField() {
1249 return '';
1250 }
1251
1252 /**
1253 * @param $row object
1254 * @return string
1255 */
1256 function formatRow( $row ) {
1257 return '';
1258 }
1259
1260 /**
1261 * @return string
1262 */
1263 function getBody() {
1264 $s = '';
1265 $this->doQuery();
1266 if ( count( $this->mHist ) ) {
1267 $list = new ImageHistoryList( $this->mImagePage );
1268 # Generate prev/next links
1269 $navLink = $this->getNavigationBar();
1270 $s = $list->beginImageHistoryList( $navLink );
1271 // Skip rows there just for paging links
1272 for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
1273 $file = $this->mHist[$i];
1274 $s .= $list->imageHistoryLine( !$file->isOld(), $file );
1275 }
1276 $s .= $list->endImageHistoryList( $navLink );
1277
1278 if ( $list->getPreventClickjacking() ) {
1279 $this->preventClickjacking();
1280 }
1281 }
1282 return $s;
1283 }
1284
1285 function doQuery() {
1286 if ( $this->mQueryDone ) {
1287 return;
1288 }
1289 $this->mImg = $this->mImagePage->getFile(); // ensure loading
1290 if ( !$this->mImg->exists() ) {
1291 return;
1292 }
1293 $queryLimit = $this->mLimit + 1; // limit plus extra row
1294 if ( $this->mIsBackwards ) {
1295 // Fetch the file history
1296 $this->mHist = $this->mImg->getHistory( $queryLimit, null, $this->mOffset, false );
1297 // The current rev may not meet the offset/limit
1298 $numRows = count( $this->mHist );
1299 if ( $numRows <= $this->mLimit && $this->mImg->getTimestamp() > $this->mOffset ) {
1300 $this->mHist = array_merge( array( $this->mImg ), $this->mHist );
1301 }
1302 } else {
1303 // The current rev may not meet the offset
1304 if ( !$this->mOffset || $this->mImg->getTimestamp() < $this->mOffset ) {
1305 $this->mHist[] = $this->mImg;
1306 }
1307 // Old image versions (fetch extra row for nav links)
1308 $oiLimit = count( $this->mHist ) ? $this->mLimit : $this->mLimit + 1;
1309 // Fetch the file history
1310 $this->mHist = array_merge( $this->mHist,
1311 $this->mImg->getHistory( $oiLimit, $this->mOffset, null, false ) );
1312 }
1313 $numRows = count( $this->mHist ); // Total number of query results
1314 if ( $numRows ) {
1315 # Index value of top item in the list
1316 $firstIndex = $this->mIsBackwards ?
1317 $this->mHist[$numRows - 1]->getTimestamp() : $this->mHist[0]->getTimestamp();
1318 # Discard the extra result row if there is one
1319 if ( $numRows > $this->mLimit && $numRows > 1 ) {
1320 if ( $this->mIsBackwards ) {
1321 # Index value of item past the index
1322 $this->mPastTheEndIndex = $this->mHist[0]->getTimestamp();
1323 # Index value of bottom item in the list
1324 $lastIndex = $this->mHist[1]->getTimestamp();
1325 # Display range
1326 $this->mRange = array( 1, $numRows - 1 );
1327 } else {
1328 # Index value of item past the index
1329 $this->mPastTheEndIndex = $this->mHist[$numRows - 1]->getTimestamp();
1330 # Index value of bottom item in the list
1331 $lastIndex = $this->mHist[$numRows - 2]->getTimestamp();
1332 # Display range
1333 $this->mRange = array( 0, $numRows - 2 );
1334 }
1335 } else {
1336 # Setting indexes to an empty string means that they will be
1337 # omitted if they would otherwise appear in URLs. It just so
1338 # happens that this is the right thing to do in the standard
1339 # UI, in all the relevant cases.
1340 $this->mPastTheEndIndex = '';
1341 # Index value of bottom item in the list
1342 $lastIndex = $this->mIsBackwards ?
1343 $this->mHist[0]->getTimestamp() : $this->mHist[$numRows - 1]->getTimestamp();
1344 # Display range
1345 $this->mRange = array( 0, $numRows - 1 );
1346 }
1347 } else {
1348 $firstIndex = '';
1349 $lastIndex = '';
1350 $this->mPastTheEndIndex = '';
1351 }
1352 if ( $this->mIsBackwards ) {
1353 $this->mIsFirst = ( $numRows < $queryLimit );
1354 $this->mIsLast = ( $this->mOffset == '' );
1355 $this->mLastShown = $firstIndex;
1356 $this->mFirstShown = $lastIndex;
1357 } else {
1358 $this->mIsFirst = ( $this->mOffset == '' );
1359 $this->mIsLast = ( $numRows < $queryLimit );
1360 $this->mLastShown = $lastIndex;
1361 $this->mFirstShown = $firstIndex;
1362 }
1363 $this->mQueryDone = true;
1364 }
1365
1366 /**
1367 * @param $enable bool
1368 */
1369 protected function preventClickjacking( $enable = true ) {
1370 $this->preventClickjacking = $enable;
1371 }
1372
1373 /**
1374 * @return bool
1375 */
1376 public function getPreventClickjacking() {
1377 return $this->preventClickjacking;
1378 }
1379
1380 }