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