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