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