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