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