Merge "Show no size links on image pages with errors"
[lhc/web/wiklou.git] / includes / ImagePage.php
1 <?php
2 /**
3 * Special handling for file description pages.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 */
22
23 /**
24 * Class for viewing MediaWiki file description pages
25 *
26 * @ingroup Media
27 */
28 class ImagePage extends Article {
29
30 /**
31 * @var File
32 */
33 private $displayImg;
34 /**
35 * @var FileRepo
36 */
37 private $repo;
38 private $fileLoaded;
39
40 var $mExtraDescription = false;
41
42 /**
43 * @param $title Title
44 * @return WikiFilePage
45 */
46 protected function newPage( Title $title ) {
47 // Overload mPage with a file-specific page
48 return new WikiFilePage( $title );
49 }
50
51 /**
52 * Constructor from a page id
53 * @param $id Int article ID to load
54 * @return ImagePage|null
55 */
56 public static function newFromID( $id ) {
57 $t = Title::newFromID( $id );
58 # @todo FIXME: Doesn't inherit right
59 return $t == null ? null : new self( $t );
60 # return $t == null ? null : new static( $t ); // PHP 5.3
61 }
62
63 /**
64 * @param $file File:
65 * @return void
66 */
67 public function setFile( $file ) {
68 $this->mPage->setFile( $file );
69 $this->displayImg = $file;
70 $this->fileLoaded = true;
71 }
72
73 protected function loadFile() {
74 if ( $this->fileLoaded ) {
75 return;
76 }
77 $this->fileLoaded = true;
78
79 $this->displayImg = $img = false;
80 wfRunHooks( 'ImagePageFindFile', array( $this, &$img, &$this->displayImg ) );
81 if ( !$img ) { // not set by hook?
82 $img = wfFindFile( $this->getTitle() );
83 if ( !$img ) {
84 $img = wfLocalFile( $this->getTitle() );
85 }
86 }
87 $this->mPage->setFile( $img );
88 if ( !$this->displayImg ) { // not set by hook?
89 $this->displayImg = $img;
90 }
91 $this->repo = $img->getRepo();
92 }
93
94 /**
95 * Handler for action=render
96 * Include body text only; none of the image extras
97 */
98 public function render() {
99 $this->getContext()->getOutput()->setArticleBodyOnly( true );
100 parent::view();
101 }
102
103 public function view() {
104 global $wgShowEXIF;
105
106 $out = $this->getContext()->getOutput();
107 $request = $this->getContext()->getRequest();
108 $diff = $request->getVal( 'diff' );
109 $diffOnly = $request->getBool( 'diffonly', $this->getContext()->getUser()->getOption( 'diffonly' ) );
110
111 if ( $this->getTitle()->getNamespace() != NS_FILE || ( isset( $diff ) && $diffOnly ) ) {
112 parent::view();
113 return;
114 }
115
116 $this->loadFile();
117
118 if ( $this->getTitle()->getNamespace() == NS_FILE && $this->mPage->getFile()->getRedirected() ) {
119 if ( $this->getTitle()->getDBkey() == $this->mPage->getFile()->getName() || isset( $diff ) ) {
120 // mTitle is the same as the redirect target so ask Article
121 // to perform the redirect for us.
122 $request->setVal( 'diffonly', 'true' );
123 parent::view();
124 return;
125 } else {
126 // mTitle is not the same as the redirect target so it is
127 // probably the redirect page itself. Fake the redirect symbol
128 $out->setPageTitle( $this->getTitle()->getPrefixedText() );
129 $out->addHTML( $this->viewRedirect( Title::makeTitle( NS_FILE, $this->mPage->getFile()->getName() ),
130 /* $appendSubtitle */ true, /* $forceKnown */ true ) );
131 $this->mPage->doViewUpdates( $this->getContext()->getUser() );
132 return;
133 }
134 }
135
136 if ( $wgShowEXIF && $this->displayImg->exists() ) {
137 // @todo FIXME: Bad interface, see note on MediaHandler::formatMetadata().
138 $formattedMetadata = $this->displayImg->formatMetadata();
139 $showmeta = $formattedMetadata !== false;
140 } else {
141 $showmeta = false;
142 }
143
144 if ( !$diff && $this->displayImg->exists() ) {
145 $out->addHTML( $this->showTOC( $showmeta ) );
146 }
147
148 if ( !$diff ) {
149 $this->openShowImage();
150 }
151
152 # No need to display noarticletext, we use our own message, output in openShowImage()
153 if ( $this->mPage->getID() ) {
154 # NS_FILE is in the user language, but this section (the actual wikitext)
155 # should be in page content language
156 $pageLang = $this->getTitle()->getPageViewLanguage();
157 $out->addHTML( Xml::openElement( 'div', array( 'id' => 'mw-imagepage-content',
158 'lang' => $pageLang->getHtmlCode(), 'dir' => $pageLang->getDir(),
159 'class' => 'mw-content-' . $pageLang->getDir() ) ) );
160
161 parent::view();
162
163 $out->addHTML( Xml::closeElement( 'div' ) );
164 } else {
165 # Just need to set the right headers
166 $out->setArticleFlag( true );
167 $out->setPageTitle( $this->getTitle()->getPrefixedText() );
168 $this->mPage->doViewUpdates( $this->getContext()->getUser() );
169 }
170
171 # Show shared description, if needed
172 if ( $this->mExtraDescription ) {
173 $fol = wfMessage( 'shareddescriptionfollows' );
174 if ( !$fol->isDisabled() ) {
175 $out->addWikiText( $fol->plain() );
176 }
177 $out->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription . "</div>\n" );
178 }
179
180 $this->closeShowImage();
181 $this->imageHistory();
182 // TODO: Cleanup the following
183
184 $out->addHTML( Xml::element( 'h2',
185 array( 'id' => 'filelinks' ),
186 wfMessage( 'imagelinks' )->text() ) . "\n" );
187 $this->imageDupes();
188 # @todo FIXME: For some freaky reason, we can't redirect to foreign images.
189 # Yet we return metadata about the target. Definitely an issue in the FileRepo
190 $this->imageLinks();
191
192 # Allow extensions to add something after the image links
193 $html = '';
194 wfRunHooks( 'ImagePageAfterImageLinks', array( $this, &$html ) );
195 if ( $html ) {
196 $out->addHTML( $html );
197 }
198
199 if ( $showmeta ) {
200 $out->addHTML( Xml::element(
201 'h2',
202 array( 'id' => 'metadata' ),
203 wfMessage( 'metadata' )->text() ) . "\n" );
204 $out->addWikiText( $this->makeMetadataTable( $formattedMetadata ) );
205 $out->addModules( array( 'mediawiki.action.view.metadata' ) );
206 }
207
208 // Add remote Filepage.css
209 if( !$this->repo->isLocal() ) {
210 $css = $this->repo->getDescriptionStylesheetUrl();
211 if ( $css ) {
212 $out->addStyle( $css );
213 }
214 }
215 // always show the local local Filepage.css, bug 29277
216 $out->addModuleStyles( 'filepage' );
217 }
218
219 /**
220 * @return File
221 */
222 public function getDisplayedFile() {
223 $this->loadFile();
224 return $this->displayImg;
225 }
226
227 /**
228 * Create the TOC
229 *
230 * @param $metadata Boolean: whether or not to show the metadata link
231 * @return String
232 */
233 protected function showTOC( $metadata ) {
234 $r = array(
235 '<li><a href="#file">' . wfMessage( 'file-anchor-link' )->escaped() . '</a></li>',
236 '<li><a href="#filehistory">' . wfMessage( 'filehist' )->escaped() . '</a></li>',
237 '<li><a href="#filelinks">' . wfMessage( 'imagelinks' )->escaped() . '</a></li>',
238 );
239 if ( $metadata ) {
240 $r[] = '<li><a href="#metadata">' . wfMessage( 'metadata' )->escaped() . '</a></li>';
241 }
242
243 wfRunHooks( 'ImagePageShowTOC', array( $this, &$r ) );
244
245 return '<ul id="filetoc">' . implode( "\n", $r ) . '</ul>';
246 }
247
248 /**
249 * Make a table with metadata to be shown in the output page.
250 *
251 * @todo FIXME: Bad interface, see note on MediaHandler::formatMetadata().
252 *
253 * @param $metadata Array: the array containing the EXIF data
254 * @return String The metadata table. This is treated as Wikitext (!)
255 */
256 protected function makeMetadataTable( $metadata ) {
257 $r = "<div class=\"mw-imagepage-section-metadata\">";
258 $r .= wfMessage( 'metadata-help' )->plain();
259 $r .= "<table id=\"mw_metadata\" class=\"mw_metadata\">\n";
260 foreach ( $metadata as $type => $stuff ) {
261 foreach ( $stuff as $v ) {
262 # @todo FIXME: Why is this using escapeId for a class?!
263 $class = Sanitizer::escapeId( $v['id'] );
264 if ( $type == 'collapsed' ) {
265 $class .= ' collapsable';
266 }
267 $r .= "<tr class=\"$class\">\n";
268 $r .= "<th>{$v['name']}</th>\n";
269 $r .= "<td>{$v['value']}</td>\n</tr>";
270 }
271 }
272 $r .= "</table>\n</div>\n";
273 return $r;
274 }
275
276 /**
277 * Overloading Article's getContentObject method.
278 *
279 * Omit noarticletext if sharedupload; text will be fetched from the
280 * shared upload server if possible.
281 * @return string
282 */
283 public function getContentObject() {
284 $this->loadFile();
285 if ( $this->mPage->getFile() && !$this->mPage->getFile()->isLocal() && 0 == $this->getID() ) {
286 return null;
287 }
288 return parent::getContentObject();
289 }
290
291 protected function openShowImage() {
292 global $wgImageLimits, $wgEnableUploads, $wgSend404Code;
293
294 $this->loadFile();
295 $out = $this->getContext()->getOutput();
296 $user = $this->getContext()->getUser();
297 $lang = $this->getContext()->getLanguage();
298 $dirmark = $lang->getDirMarkEntity();
299 $request = $this->getContext()->getRequest();
300
301 $sizeSel = intval( $user->getOption( 'imagesize' ) );
302 if ( !isset( $wgImageLimits[$sizeSel] ) ) {
303 $sizeSel = User::getDefaultOption( 'imagesize' );
304
305 // The user offset might still be incorrect, specially if
306 // $wgImageLimits got changed (see bug #8858).
307 if ( !isset( $wgImageLimits[$sizeSel] ) ) {
308 // Default to the first offset in $wgImageLimits
309 $sizeSel = 0;
310 }
311 }
312 $max = $wgImageLimits[$sizeSel];
313 $maxWidth = $max[0];
314 $maxHeight = $max[1];
315
316 if ( $this->displayImg->exists() ) {
317 # image
318 $page = $request->getIntOrNull( 'page' );
319 if ( is_null( $page ) ) {
320 $params = array();
321 $page = 1;
322 } else {
323 $params = array( 'page' => $page );
324 }
325 $width_orig = $this->displayImg->getWidth( $page );
326 $width = $width_orig;
327 $height_orig = $this->displayImg->getHeight( $page );
328 $height = $height_orig;
329
330 $filename = wfEscapeWikiText( $this->displayImg->getName() );
331 $linktext = $filename;
332
333 wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this, &$out ) );
334
335 if ( $this->displayImg->allowInlineDisplay() ) {
336 # image
337
338 # "Download high res version" link below the image
339 # $msgsize = wfMessage( 'file-info-size', $width_orig, $height_orig, Linker::formatSize( $this->displayImg->getSize() ), $mime )->escaped();
340 # We'll show a thumbnail of this image
341 if ( $width > $maxWidth || $height > $maxHeight ) {
342 # Calculate the thumbnail size.
343 # First case, the limiting factor is the width, not the height.
344 if ( $width / $height >= $maxWidth / $maxHeight ) { // FIXME: Possible divison by 0. bug 36911
345 $height = round( $height * $maxWidth / $width ); // FIXME: Possible divison by 0. bug 36911
346 $width = $maxWidth;
347 # Note that $height <= $maxHeight now.
348 } else {
349 $newwidth = floor( $width * $maxHeight / $height ); // FIXME: Possible divison by 0. bug 36911
350 $height = round( $height * $newwidth / $width ); // FIXME: Possible divison by 0. bug 36911
351 $width = $newwidth;
352 # Note that $height <= $maxHeight now, but might not be identical
353 # because of rounding.
354 }
355 $linktext = wfMessage( 'show-big-image' )->escaped();
356 if ( $this->displayImg->getRepo()->canTransformVia404() ) {
357 $thumbSizes = $wgImageLimits;
358 } else {
359 # Creating thumb links triggers thumbnail generation.
360 # Just generate the thumb for the current users prefs.
361 $thumbOption = $user->getOption( 'thumbsize' );
362 $thumbSizes = array( isset( $wgImageLimits[$thumbOption] )
363 ? $wgImageLimits[$thumbOption]
364 : $wgImageLimits[User::getDefaultOption( 'thumbsize' )] );
365 }
366 # Generate thumbnails or thumbnail links as needed...
367 $otherSizes = array();
368 foreach ( $thumbSizes as $size ) {
369 if ( $size[0] < $width_orig && $size[1] < $height_orig
370 && $size[0] != $width && $size[1] != $height )
371 {
372 $sizeLink = $this->makeSizeLink( $params, $size[0], $size[1] );
373 if ( $sizeLink ) {
374 $otherSizes[] = $sizeLink;
375 }
376 }
377 }
378 $msgsmall = '';
379 $sizeLinkBigImagePreview = $this->makeSizeLink( $params, $width, $height );
380 if ( $sizeLinkBigImagePreview ) {
381 $msgsmall .= wfMessage( 'show-big-image-preview' )->
382 rawParams( $sizeLinkBigImagePreview )->
383 parse();
384 }
385 if ( count( $otherSizes ) ) {
386 $msgsmall .= ' ' .
387 Html::rawElement( 'span', array( 'class' => 'mw-filepage-other-resolutions' ),
388 wfMessage( 'show-big-image-other' )->rawParams( $lang->pipeList( $otherSizes ) )->
389 params( count( $otherSizes ) )->parse()
390 );
391 }
392 } elseif ( $width == 0 && $height == 0 ) {
393 # Some sort of audio file that doesn't have dimensions
394 # Don't output a no hi res message for such a file
395 $msgsmall = '';
396 } elseif ( $this->displayImg->isVectorized() ) {
397 # For vectorized images, full size is just the frame size
398 $msgsmall = '';
399 } else {
400 # Image is small enough to show full size on image page
401 $msgsmall = wfMessage( 'file-nohires' )->parse();
402 }
403
404 $params['width'] = $width;
405 $params['height'] = $height;
406 $thumbnail = $this->displayImg->transform( $params );
407
408 $anchorclose = Html::rawElement( 'div', array( 'class' => 'mw-filepage-resolutioninfo' ), $msgsmall );
409
410 $isMulti = $this->displayImg->isMultipage() && $this->displayImg->pageCount() > 1;
411 if ( $isMulti ) {
412 $out->addHTML( '<table class="multipageimage"><tr><td>' );
413 }
414
415 if ( $thumbnail ) {
416 $options = array(
417 'alt' => $this->displayImg->getTitle()->getPrefixedText(),
418 'file-link' => true,
419 );
420 $out->addHTML( '<div class="fullImageLink" id="file">' .
421 $thumbnail->toHtml( $options ) .
422 $anchorclose . "</div>\n" );
423 }
424
425 if ( $isMulti ) {
426 $count = $this->displayImg->pageCount();
427
428 if ( $page > 1 ) {
429 $label = $out->parse( wfMessage( 'imgmultipageprev' )->text(), false );
430 $link = Linker::linkKnown(
431 $this->getTitle(),
432 $label,
433 array(),
434 array( 'page' => $page - 1 )
435 );
436 $thumb1 = Linker::makeThumbLinkObj( $this->getTitle(), $this->displayImg, $link, $label, 'none',
437 array( 'page' => $page - 1 ) );
438 } else {
439 $thumb1 = '';
440 }
441
442 if ( $page < $count ) {
443 $label = wfMessage( 'imgmultipagenext' )->text();
444 $link = Linker::linkKnown(
445 $this->getTitle(),
446 $label,
447 array(),
448 array( 'page' => $page + 1 )
449 );
450 $thumb2 = Linker::makeThumbLinkObj( $this->getTitle(), $this->displayImg, $link, $label, 'none',
451 array( 'page' => $page + 1 ) );
452 } else {
453 $thumb2 = '';
454 }
455
456 global $wgScript;
457
458 $formParams = array(
459 'name' => 'pageselector',
460 'action' => $wgScript,
461 'onchange' => 'document.pageselector.submit();',
462 );
463 $options = array();
464 for ( $i = 1; $i <= $count; $i++ ) {
465 $options[] = Xml::option( $lang->formatNum( $i ), $i, $i == $page );
466 }
467 $select = Xml::tags( 'select',
468 array( 'id' => 'pageselector', 'name' => 'page' ),
469 implode( "\n", $options ) );
470
471 $out->addHTML(
472 '</td><td><div class="multipageimagenavbox">' .
473 Xml::openElement( 'form', $formParams ) .
474 Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) .
475 wfMessage( 'imgmultigoto' )->rawParams( $select )->parse() .
476 Xml::submitButton( wfMessage( 'imgmultigo' )->text() ) .
477 Xml::closeElement( 'form' ) .
478 "<hr />$thumb1\n$thumb2<br style=\"clear: both\" /></div></td></tr></table>"
479 );
480 }
481 } elseif ( $this->displayImg->isSafeFile() ) {
482 # if direct link is allowed but it's not a renderable image, show an icon.
483 $icon = $this->displayImg->iconThumb();
484
485 $out->addHTML( '<div class="fullImageLink" id="file">' .
486 $icon->toHtml( array( 'file-link' => true ) ) .
487 "</div>\n" );
488 }
489
490 $longDesc = wfMessage( 'parentheses', $this->displayImg->getLongDesc() )->text();
491
492 $medialink = "[[Media:$filename|$linktext]]";
493
494 if ( !$this->displayImg->isSafeFile() ) {
495 $warning = wfMessage( 'mediawarning' )->plain();
496 // dirmark is needed here to separate the file name, which
497 // most likely ends in Latin characters, from the description,
498 // which may begin with the file type. In RTL environment
499 // this will get messy.
500 // The dirmark, however, must not be immediately adjacent
501 // to the filename, because it can get copied with it.
502 // See bug 25277.
503 $out->addWikiText( <<<EOT
504 <div class="fullMedia"><span class="dangerousLink">{$medialink}</span> $dirmark<span class="fileInfo">$longDesc</span></div>
505 <div class="mediaWarning">$warning</div>
506 EOT
507 );
508 } else {
509 $out->addWikiText( <<<EOT
510 <div class="fullMedia">{$medialink} {$dirmark}<span class="fileInfo">$longDesc</span>
511 </div>
512 EOT
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->setCanonicalUrl( $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 # No redirects
798 $liContents = $link;
799 } elseif ( count( $redirects[$element->page_title] ) === 0 ) {
800 # Redirect without usages
801 $liContents = wfMessage( 'linkstoimage-redirect' )->rawParams( $link, '' )->parse();
802 } else {
803 # Redirect with usages
804 $li = '';
805 foreach ( $redirects[$element->page_title] as $row ) {
806 $currentCount++;
807 if ( $currentCount > $limit ) {
808 break;
809 }
810
811 $link2 = Linker::linkKnown( Title::makeTitle( $row->page_namespace, $row->page_title ) );
812 $li .= Html::rawElement(
813 'li',
814 array( 'class' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace ),
815 $link2
816 ) . "\n";
817 }
818
819 $ul = Html::rawElement(
820 'ul',
821 array( 'class' => 'mw-imagepage-redirectstofile'),
822 $li
823 ) . "\n";
824 $liContents = wfMessage( 'linkstoimage-redirect' )->rawParams(
825 $link, $ul )->parse();
826 }
827 $out->addHTML( Html::rawElement(
828 'li',
829 array( 'class' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace ),
830 $liContents
831 ) . "\n"
832 );
833
834 };
835 $out->addHTML( Html::closeElement( 'ul' ) . "\n" );
836 $res->free();
837
838 // Add a links to [[Special:Whatlinkshere]]
839 if ( $count > $limit ) {
840 $out->addWikiMsg( 'morelinkstoimage', $this->getTitle()->getPrefixedDBkey() );
841 }
842 $out->addHTML( Html::closeElement( 'div' ) . "\n" );
843 }
844
845 protected function imageDupes() {
846 $this->loadFile();
847 $out = $this->getContext()->getOutput();
848
849 $dupes = $this->mPage->getDuplicates();
850 if ( count( $dupes ) == 0 ) {
851 return;
852 }
853
854 $out->addHTML( "<div id='mw-imagepage-section-duplicates'>\n" );
855 $out->addWikiMsg( 'duplicatesoffile',
856 $this->getContext()->getLanguage()->formatNum( count( $dupes ) ), $this->getTitle()->getDBkey()
857 );
858 $out->addHTML( "<ul class='mw-imagepage-duplicates'>\n" );
859
860 /**
861 * @var $file File
862 */
863 foreach ( $dupes as $file ) {
864 $fromSrc = '';
865 if ( $file->isLocal() ) {
866 $link = Linker::linkKnown( $file->getTitle() );
867 } else {
868 $link = Linker::makeExternalLink( $file->getDescriptionUrl(),
869 $file->getTitle()->getPrefixedText() );
870 $fromSrc = wfMessage( 'shared-repo-from', $file->getRepo()->getDisplayName() )->text();
871 }
872 $out->addHTML( "<li>{$link} {$fromSrc}</li>\n" );
873 }
874 $out->addHTML( "</ul></div>\n" );
875 }
876
877 /**
878 * Delete the file, or an earlier version of it
879 */
880 public function delete() {
881 $file = $this->mPage->getFile();
882 if ( !$file->exists() || !$file->isLocal() || $file->getRedirected() ) {
883 // Standard article deletion
884 parent::delete();
885 return;
886 }
887
888 $deleter = new FileDeleteForm( $file );
889 $deleter->execute();
890 }
891
892 /**
893 * Display an error with a wikitext description
894 *
895 * @param $description String
896 */
897 function showError( $description ) {
898 $out = $this->getContext()->getOutput();
899 $out->setPageTitle( wfMessage( 'internalerror' ) );
900 $out->setRobotPolicy( 'noindex,nofollow' );
901 $out->setArticleRelated( false );
902 $out->enableClientCache( false );
903 $out->addWikiText( $description );
904 }
905
906 /**
907 * Callback for usort() to do link sorts by (namespace, title)
908 * Function copied from Title::compare()
909 *
910 * @param $a object page to compare with
911 * @param $b object page to compare with
912 * @return Integer: result of string comparison, or namespace comparison
913 */
914 protected function compare( $a, $b ) {
915 if ( $a->page_namespace == $b->page_namespace ) {
916 return strcmp( $a->page_title, $b->page_title );
917 } else {
918 return $a->page_namespace - $b->page_namespace;
919 }
920 }
921 }
922
923 /**
924 * Builds the image revision log shown on image pages
925 *
926 * @ingroup Media
927 */
928 class ImageHistoryList extends ContextSource {
929
930 /**
931 * @var Title
932 */
933 protected $title;
934
935 /**
936 * @var File
937 */
938 protected $img;
939
940 /**
941 * @var ImagePage
942 */
943 protected $imagePage;
944
945 /**
946 * @var File
947 */
948 protected $current;
949
950 protected $repo, $showThumb;
951 protected $preventClickjacking = false;
952
953 /**
954 * @param ImagePage $imagePage
955 */
956 public function __construct( $imagePage ) {
957 global $wgShowArchiveThumbnails;
958 $this->current = $imagePage->getFile();
959 $this->img = $imagePage->getDisplayedFile();
960 $this->title = $imagePage->getTitle();
961 $this->imagePage = $imagePage;
962 $this->showThumb = $wgShowArchiveThumbnails && $this->img->canRender();
963 $this->setContext( $imagePage->getContext() );
964 }
965
966 /**
967 * @return ImagePage
968 */
969 public function getImagePage() {
970 return $this->imagePage;
971 }
972
973 /**
974 * @return File
975 */
976 public function getFile() {
977 return $this->img;
978 }
979
980 /**
981 * @param $navLinks string
982 * @return string
983 */
984 public function beginImageHistoryList( $navLinks = '' ) {
985 return Xml::element( 'h2', array( 'id' => 'filehistory' ), $this->msg( 'filehist' )->text() ) . "\n"
986 . "<div id=\"mw-imagepage-section-filehistory\">\n"
987 . $this->msg( 'filehist-help' )->parseAsBlock()
988 . $navLinks . "\n"
989 . Xml::openElement( 'table', array( 'class' => 'wikitable filehistory' ) ) . "\n"
990 . '<tr><td></td>'
991 . ( $this->current->isLocal() && ( $this->getUser()->isAllowedAny( 'delete', 'deletedhistory' ) ) ? '<td></td>' : '' )
992 . '<th>' . $this->msg( 'filehist-datetime' )->escaped() . '</th>'
993 . ( $this->showThumb ? '<th>' . $this->msg( 'filehist-thumb' )->escaped() . '</th>' : '' )
994 . '<th>' . $this->msg( 'filehist-dimensions' )->escaped() . '</th>'
995 . '<th>' . $this->msg( 'filehist-user' )->escaped() . '</th>'
996 . '<th>' . $this->msg( 'filehist-comment' )->escaped() . '</th>'
997 . "</tr>\n";
998 }
999
1000 /**
1001 * @param $navLinks string
1002 * @return string
1003 */
1004 public function endImageHistoryList( $navLinks = '' ) {
1005 return "</table>\n$navLinks\n</div>\n";
1006 }
1007
1008 /**
1009 * @param $iscur
1010 * @param $file File
1011 * @return string
1012 */
1013 public function imageHistoryLine( $iscur, $file ) {
1014 global $wgContLang;
1015
1016 $user = $this->getUser();
1017 $lang = $this->getLanguage();
1018 $timestamp = wfTimestamp( TS_MW, $file->getTimestamp() );
1019 $img = $iscur ? $file->getName() : $file->getArchiveName();
1020 $userId = $file->getUser( 'id' );
1021 $userText = $file->getUser( 'text' );
1022 $description = $file->getDescription( File::FOR_THIS_USER, $user );
1023
1024 $local = $this->current->isLocal();
1025 $row = $selected = '';
1026
1027 // Deletion link
1028 if ( $local && ( $user->isAllowedAny( 'delete', 'deletedhistory' ) ) ) {
1029 $row .= '<td>';
1030 # Link to remove from history
1031 if ( $user->isAllowed( 'delete' ) ) {
1032 $q = array( 'action' => 'delete' );
1033 if ( !$iscur ) {
1034 $q['oldimage'] = $img;
1035 }
1036 $row .= Linker::linkKnown(
1037 $this->title,
1038 $this->msg( $iscur ? 'filehist-deleteall' : 'filehist-deleteone' )->escaped(),
1039 array(), $q
1040 );
1041 }
1042 # Link to hide content. Don't show useless link to people who cannot hide revisions.
1043 $canHide = $user->isAllowed( 'deleterevision' );
1044 if ( $canHide || ( $user->isAllowed( 'deletedhistory' ) && $file->getVisibility() ) ) {
1045 if ( $user->isAllowed( 'delete' ) ) {
1046 $row .= '<br />';
1047 }
1048 // If file is top revision or locked from this user, don't link
1049 if ( $iscur || !$file->userCan( File::DELETED_RESTRICTED, $user ) ) {
1050 $del = Linker::revDeleteLinkDisabled( $canHide );
1051 } else {
1052 list( $ts, ) = explode( '!', $img, 2 );
1053 $query = array(
1054 'type' => 'oldimage',
1055 'target' => $this->title->getPrefixedText(),
1056 'ids' => $ts,
1057 );
1058 $del = Linker::revDeleteLink( $query,
1059 $file->isDeleted( File::DELETED_RESTRICTED ), $canHide );
1060 }
1061 $row .= $del;
1062 }
1063 $row .= '</td>';
1064 }
1065
1066 // Reversion link/current indicator
1067 $row .= '<td>';
1068 if ( $iscur ) {
1069 $row .= $this->msg( 'filehist-current' )->escaped();
1070 } elseif ( $local && $this->title->quickUserCan( 'edit', $user )
1071 && $this->title->quickUserCan( 'upload', $user )
1072 ) {
1073 if ( $file->isDeleted( File::DELETED_FILE ) ) {
1074 $row .= $this->msg( 'filehist-revert' )->escaped();
1075 } else {
1076 $row .= Linker::linkKnown(
1077 $this->title,
1078 $this->msg( 'filehist-revert' )->escaped(),
1079 array(),
1080 array(
1081 'action' => 'revert',
1082 'oldimage' => $img,
1083 'wpEditToken' => $user->getEditToken( $img )
1084 )
1085 );
1086 }
1087 }
1088 $row .= '</td>';
1089
1090 // Date/time and image link
1091 if ( $file->getTimestamp() === $this->img->getTimestamp() ) {
1092 $selected = "class='filehistory-selected'";
1093 }
1094 $row .= "<td $selected style='white-space: nowrap;'>";
1095 if ( !$file->userCan( File::DELETED_FILE, $user ) ) {
1096 # Don't link to unviewable files
1097 $row .= '<span class="history-deleted">' . $lang->userTimeAndDate( $timestamp, $user ) . '</span>';
1098 } elseif ( $file->isDeleted( File::DELETED_FILE ) ) {
1099 if ( $local ) {
1100 $this->preventClickjacking();
1101 $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
1102 # Make a link to review the image
1103 $url = Linker::linkKnown(
1104 $revdel,
1105 $lang->userTimeAndDate( $timestamp, $user ),
1106 array(),
1107 array(
1108 'target' => $this->title->getPrefixedText(),
1109 'file' => $img,
1110 'token' => $user->getEditToken( $img )
1111 )
1112 );
1113 } else {
1114 $url = $lang->userTimeAndDate( $timestamp, $user );
1115 }
1116 $row .= '<span class="history-deleted">' . $url . '</span>';
1117 } else {
1118 $url = $iscur ? $this->current->getUrl() : $this->current->getArchiveUrl( $img );
1119 $row .= Xml::element( 'a', array( 'href' => $url ), $lang->userTimeAndDate( $timestamp, $user ) );
1120 }
1121 $row .= "</td>";
1122
1123 // Thumbnail
1124 if ( $this->showThumb ) {
1125 $row .= '<td>' . $this->getThumbForLine( $file ) . '</td>';
1126 }
1127
1128 // Image dimensions + size
1129 $row .= '<td>';
1130 $row .= htmlspecialchars( $file->getDimensionsString() );
1131 $row .= $this->msg( 'word-separator' )->plain();
1132 $row .= '<span style="white-space: nowrap;">';
1133 $row .= $this->msg( 'parentheses' )->rawParams( Linker::formatSize( $file->getSize() ) )->plain();
1134 $row .= '</span>';
1135 $row .= '</td>';
1136
1137 // Uploading user
1138 $row .= '<td>';
1139 // Hide deleted usernames
1140 if ( $file->isDeleted( File::DELETED_USER ) ) {
1141 $row .= '<span class="history-deleted">' . $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
1142 } else {
1143 if ( $local ) {
1144 $row .= Linker::userLink( $userId, $userText );
1145 $row .= $this->msg( 'word-separator' )->plain();
1146 $row .= '<span style="white-space: nowrap;">';
1147 $row .= Linker::userToolLinks( $userId, $userText );
1148 $row .= '</span>';
1149 } else {
1150 $row .= htmlspecialchars( $userText );
1151 }
1152 }
1153 $row .= '</td>';
1154
1155 // Don't show deleted descriptions
1156 if ( $file->isDeleted( File::DELETED_COMMENT ) ) {
1157 $row .= '<td><span class="history-deleted">' . $this->msg( 'rev-deleted-comment' )->escaped() . '</span></td>';
1158 } else {
1159 $row .= '<td dir="' . $wgContLang->getDir() . '">' . Linker::formatComment( $description, $this->title ) . '</td>';
1160 }
1161
1162 $rowClass = null;
1163 wfRunHooks( 'ImagePageFileHistoryLine', array( $this, $file, &$row, &$rowClass ) );
1164 $classAttr = $rowClass ? " class='$rowClass'" : '';
1165
1166 return "<tr{$classAttr}>{$row}</tr>\n";
1167 }
1168
1169 /**
1170 * @param $file File
1171 * @return string
1172 */
1173 protected function getThumbForLine( $file ) {
1174 $lang = $this->getLanguage();
1175 $user = $this->getUser();
1176 if ( $file->allowInlineDisplay() && $file->userCan( File::DELETED_FILE, $user )
1177 && !$file->isDeleted( File::DELETED_FILE ) )
1178 {
1179 $params = array(
1180 'width' => '120',
1181 'height' => '120',
1182 );
1183 $timestamp = wfTimestamp( TS_MW, $file->getTimestamp() );
1184
1185 $thumbnail = $file->transform( $params );
1186 $options = array(
1187 'alt' => $this->msg( 'filehist-thumbtext',
1188 $lang->userTimeAndDate( $timestamp, $user ),
1189 $lang->userDate( $timestamp, $user ),
1190 $lang->userTime( $timestamp, $user ) )->text(),
1191 'file-link' => true,
1192 );
1193
1194 if ( !$thumbnail ) {
1195 return $this->msg( 'filehist-nothumb' )->escaped();
1196 }
1197
1198 return $thumbnail->toHtml( $options );
1199 } else {
1200 return $this->msg( 'filehist-nothumb' )->escaped();
1201 }
1202 }
1203
1204 /**
1205 * @param $enable bool
1206 */
1207 protected function preventClickjacking( $enable = true ) {
1208 $this->preventClickjacking = $enable;
1209 }
1210
1211 /**
1212 * @return bool
1213 */
1214 public function getPreventClickjacking() {
1215 return $this->preventClickjacking;
1216 }
1217 }
1218
1219 class ImageHistoryPseudoPager extends ReverseChronologicalPager {
1220 protected $preventClickjacking = false;
1221
1222 /**
1223 * @var File
1224 */
1225 protected $mImg;
1226
1227 /**
1228 * @var Title
1229 */
1230 protected $mTitle;
1231
1232 /**
1233 * @param ImagePage $imagePage
1234 */
1235 function __construct( $imagePage ) {
1236 parent::__construct( $imagePage->getContext() );
1237 $this->mImagePage = $imagePage;
1238 $this->mTitle = clone ( $imagePage->getTitle() );
1239 $this->mTitle->setFragment( '#filehistory' );
1240 $this->mImg = null;
1241 $this->mHist = array();
1242 $this->mRange = array( 0, 0 ); // display range
1243 }
1244
1245 /**
1246 * @return Title
1247 */
1248 function getTitle() {
1249 return $this->mTitle;
1250 }
1251
1252 function getQueryInfo() {
1253 return false;
1254 }
1255
1256 /**
1257 * @return string
1258 */
1259 function getIndexField() {
1260 return '';
1261 }
1262
1263 /**
1264 * @param $row object
1265 * @return string
1266 */
1267 function formatRow( $row ) {
1268 return '';
1269 }
1270
1271 /**
1272 * @return string
1273 */
1274 function getBody() {
1275 $s = '';
1276 $this->doQuery();
1277 if ( count( $this->mHist ) ) {
1278 $list = new ImageHistoryList( $this->mImagePage );
1279 # Generate prev/next links
1280 $navLink = $this->getNavigationBar();
1281 $s = $list->beginImageHistoryList( $navLink );
1282 // Skip rows there just for paging links
1283 for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
1284 $file = $this->mHist[$i];
1285 $s .= $list->imageHistoryLine( !$file->isOld(), $file );
1286 }
1287 $s .= $list->endImageHistoryList( $navLink );
1288
1289 if ( $list->getPreventClickjacking() ) {
1290 $this->preventClickjacking();
1291 }
1292 }
1293 return $s;
1294 }
1295
1296 function doQuery() {
1297 if ( $this->mQueryDone ) {
1298 return;
1299 }
1300 $this->mImg = $this->mImagePage->getFile(); // ensure loading
1301 if ( !$this->mImg->exists() ) {
1302 return;
1303 }
1304 $queryLimit = $this->mLimit + 1; // limit plus extra row
1305 if ( $this->mIsBackwards ) {
1306 // Fetch the file history
1307 $this->mHist = $this->mImg->getHistory( $queryLimit, null, $this->mOffset, false );
1308 // The current rev may not meet the offset/limit
1309 $numRows = count( $this->mHist );
1310 if ( $numRows <= $this->mLimit && $this->mImg->getTimestamp() > $this->mOffset ) {
1311 $this->mHist = array_merge( array( $this->mImg ), $this->mHist );
1312 }
1313 } else {
1314 // The current rev may not meet the offset
1315 if ( !$this->mOffset || $this->mImg->getTimestamp() < $this->mOffset ) {
1316 $this->mHist[] = $this->mImg;
1317 }
1318 // Old image versions (fetch extra row for nav links)
1319 $oiLimit = count( $this->mHist ) ? $this->mLimit : $this->mLimit + 1;
1320 // Fetch the file history
1321 $this->mHist = array_merge( $this->mHist,
1322 $this->mImg->getHistory( $oiLimit, $this->mOffset, null, false ) );
1323 }
1324 $numRows = count( $this->mHist ); // Total number of query results
1325 if ( $numRows ) {
1326 # Index value of top item in the list
1327 $firstIndex = $this->mIsBackwards ?
1328 $this->mHist[$numRows - 1]->getTimestamp() : $this->mHist[0]->getTimestamp();
1329 # Discard the extra result row if there is one
1330 if ( $numRows > $this->mLimit && $numRows > 1 ) {
1331 if ( $this->mIsBackwards ) {
1332 # Index value of item past the index
1333 $this->mPastTheEndIndex = $this->mHist[0]->getTimestamp();
1334 # Index value of bottom item in the list
1335 $lastIndex = $this->mHist[1]->getTimestamp();
1336 # Display range
1337 $this->mRange = array( 1, $numRows - 1 );
1338 } else {
1339 # Index value of item past the index
1340 $this->mPastTheEndIndex = $this->mHist[$numRows - 1]->getTimestamp();
1341 # Index value of bottom item in the list
1342 $lastIndex = $this->mHist[$numRows - 2]->getTimestamp();
1343 # Display range
1344 $this->mRange = array( 0, $numRows - 2 );
1345 }
1346 } else {
1347 # Setting indexes to an empty string means that they will be
1348 # omitted if they would otherwise appear in URLs. It just so
1349 # happens that this is the right thing to do in the standard
1350 # UI, in all the relevant cases.
1351 $this->mPastTheEndIndex = '';
1352 # Index value of bottom item in the list
1353 $lastIndex = $this->mIsBackwards ?
1354 $this->mHist[0]->getTimestamp() : $this->mHist[$numRows - 1]->getTimestamp();
1355 # Display range
1356 $this->mRange = array( 0, $numRows - 1 );
1357 }
1358 } else {
1359 $firstIndex = '';
1360 $lastIndex = '';
1361 $this->mPastTheEndIndex = '';
1362 }
1363 if ( $this->mIsBackwards ) {
1364 $this->mIsFirst = ( $numRows < $queryLimit );
1365 $this->mIsLast = ( $this->mOffset == '' );
1366 $this->mLastShown = $firstIndex;
1367 $this->mFirstShown = $lastIndex;
1368 } else {
1369 $this->mIsFirst = ( $this->mOffset == '' );
1370 $this->mIsLast = ( $numRows < $queryLimit );
1371 $this->mLastShown = $lastIndex;
1372 $this->mFirstShown = $firstIndex;
1373 }
1374 $this->mQueryDone = true;
1375 }
1376
1377 /**
1378 * @param $enable bool
1379 */
1380 protected function preventClickjacking( $enable = true ) {
1381 $this->preventClickjacking = $enable;
1382 }
1383
1384 /**
1385 * @return bool
1386 */
1387 public function getPreventClickjacking() {
1388 return $this->preventClickjacking;
1389 }
1390
1391 }