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