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