(bug 14212) Undefined variable $retval in Skin::subPageSubtitle()
[mediawiki.git] / includes / ImagePage.php
blobc309d446a352a1a2e7d86d94815a3e7cad30d555
1 <?php
3 if( !defined( 'MEDIAWIKI' ) )
4 die( 1 );
6 /**
7 * Special handling for image description pages
9 * @ingroup Media
11 class ImagePage extends Article {
13 /* private */ var $img; // Image object this page is shown for
14 /* private */ var $current;
15 /* private */ var $repo;
16 /* private */ var $time;
17 /* private */ var $fileLoaded;
18 var $mExtraDescription = false;
19 var $dupes;
21 function __construct( $title, $time = null ) {
22 parent::__construct( $title );
24 global $wgRequest;
25 $this->time = is_null($time) ? $wgRequest->getVal( 'filetimestamp' ) : $time;
26 $this->dupes = null;
27 $this->repo = null;
30 protected function loadFile() {
31 if( $this->fileLoaded ) {
32 return true;
34 $this->img = wfFindFile( $this->mTitle, $this->time );
35 if ( !$this->img ) {
36 $this->img = wfLocalFile( $this->mTitle );
37 $this->current = $this->img;
38 } else {
39 $this->current = $this->time ? wfLocalFile( $this->mTitle ) : $this->img;
41 $this->repo = $this->img->getRepo();
42 $this->fileLoaded = true;
45 /**
46 * Handler for action=render
47 * Include body text only; none of the image extras
49 function render() {
50 global $wgOut;
51 $wgOut->setArticleBodyOnly( true );
52 parent::view();
55 function view() {
56 global $wgOut, $wgShowEXIF, $wgRequest, $wgUser;
57 $this->loadFile();
59 if ( $this->mTitle->getNamespace() == NS_IMAGE && $this->img->getRedirected() ) {
60 if ( $this->mTitle->getDBkey() == $this->img->getName() ) {
61 // mTitle is the same as the redirect target so ask Article
62 // to perform the redirect for us.
63 return Article::view();
64 } else {
65 // mTitle is not the same as the redirect target so it is
66 // probably the redirect page itself. Fake the redirect symbol
67 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
68 $this->viewRedirect( Title::makeTitle( NS_IMAGE, $this->img->getName() ),
69 /* $overwriteSubtitle */ true, /* $forceKnown */ true );
70 $this->viewUpdates();
71 return;
75 $diff = $wgRequest->getVal( 'diff' );
76 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
78 if ( $this->mTitle->getNamespace() != NS_IMAGE || ( isset( $diff ) && $diffOnly ) )
79 return Article::view();
81 if ($wgShowEXIF && $this->img->exists()) {
82 // FIXME: bad interface, see note on MediaHandler::formatMetadata().
83 $formattedMetadata = $this->img->formatMetadata();
84 $showmeta = $formattedMetadata !== false;
85 } else {
86 $showmeta = false;
89 if ($this->img->exists())
90 $wgOut->addHTML($this->showTOC($showmeta));
92 $this->openShowImage();
94 # No need to display noarticletext, we use our own message, output in openShowImage()
95 if ( $this->getID() ) {
96 Article::view();
97 } else {
98 # Just need to set the right headers
99 $wgOut->setArticleFlag( true );
100 $wgOut->setRobotpolicy( 'noindex,nofollow' );
101 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
102 $this->viewUpdates();
105 # Show shared description, if needed
106 if ( $this->mExtraDescription ) {
107 $fol = wfMsgNoTrans( 'shareddescriptionfollows' );
108 if( $fol != '-' && !wfEmptyMsg( 'shareddescriptionfollows', $fol ) ) {
109 $wgOut->addWikiText( $fol );
111 $wgOut->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription . '</div>' );
112 } else {
113 $this->checkSharedConflict();
116 $this->closeShowImage();
117 $this->imageHistory();
118 // TODO: Cleanup the following
120 $wgOut->addHTML( Xml::element( 'h2',
121 array( 'id' => 'filelinks' ),
122 wfMsg( 'imagelinks' ) ) . "\n" );
123 $this->imageDupes();
124 // TODO: We may want to find local images redirecting to a foreign
125 // file: "The following local files redirect to this file"
126 if ( $this->img->isLocal() ) $this->imageRedirects();
127 $this->imageLinks();
129 if ( $showmeta ) {
130 global $wgStylePath, $wgStyleVersion;
131 $expand = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-expand' ) ) );
132 $collapse = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-collapse' ) ) );
133 $wgOut->addHTML( Xml::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ). "\n" );
134 $wgOut->addWikiText( $this->makeMetadataTable( $formattedMetadata ) );
135 $wgOut->addScriptFile( 'metadata.js' );
136 $wgOut->addHTML(
137 "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
141 public function getRedirectTarget() {
142 $this->loadFile();
143 if ( $this->img->isLocal() ) {
144 return parent::getRedirectTarget();
146 // Foreign image page
147 $from = $this->img->getRedirected();
148 $to = $this->img->getName();
149 if ( $from == $to ) {
150 return null;
152 return $this->mRedirectTarget = Title::makeTitle( NS_IMAGE, $to );
154 public function followRedirect() {
155 $this->loadFile();
156 if ( $this->img->isLocal() ) {
157 return parent::followRedirect();
159 $from = $this->img->getRedirected();
160 $to = $this->img->getName();
161 if ( $from == $to ) {
162 return false;
164 return Title::makeTitle( NS_IMAGE, $to );
166 public function isRedirect( $text = false ) {
167 $this->loadFile();
168 if ( $this->img->isLocal() )
169 return parent::isRedirect( $text );
171 return (bool)$this->img->getRedirected();
174 public function isLocal() {
175 $this->loadFile();
176 return $this->img->isLocal();
179 public function getFile() {
180 $this->loadFile();
181 return $this->img;
184 public function getDuplicates() {
185 $this->loadFile();
186 if ( !is_null($this->dupes) ) {
187 return $this->dupes;
189 if ( !( $hash = $this->img->getSha1() ) ) {
190 return $this->dupes = array();
192 $dupes = RepoGroup::singleton()->findBySha1( $hash );
193 // Remove duplicates with self and non matching file sizes
194 $self = $this->img->getRepoName().':'.$this->img->getName();
195 $size = $this->img->getSize();
196 foreach ( $dupes as $index => $file ) {
197 $key = $file->getRepoName().':'.$file->getName();
198 if ( $key == $self )
199 unset( $dupes[$index] );
200 if ( $file->getSize() != $size )
201 unset( $dupes[$index] );
203 return $this->dupes = $dupes;
209 * Create the TOC
211 * @access private
213 * @param bool $metadata Whether or not to show the metadata link
214 * @return string
216 function showTOC( $metadata ) {
217 global $wgLang;
218 $r = '<ul id="filetoc">
219 <li><a href="#file">' . $wgLang->getNsText( NS_IMAGE ) . '</a></li>
220 <li><a href="#filehistory">' . wfMsgHtml( 'filehist' ) . '</a></li>
221 <li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . '</a></li>' .
222 ($metadata ? ' <li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>' : '') . '
223 </ul>';
224 return $r;
228 * Make a table with metadata to be shown in the output page.
230 * FIXME: bad interface, see note on MediaHandler::formatMetadata().
232 * @access private
234 * @param array $exif The array containing the EXIF data
235 * @return string
237 function makeMetadataTable( $metadata ) {
238 $r = wfMsg( 'metadata-help' ) . "\n\n";
239 $r .= "{| id=mw_metadata class=mw_metadata\n";
240 foreach ( $metadata as $type => $stuff ) {
241 foreach ( $stuff as $v ) {
242 $class = Sanitizer::escapeId( $v['id'] );
243 if( $type == 'collapsed' ) {
244 $class .= ' collapsable';
246 $r .= "|- class=\"$class\"\n";
247 $r .= "!| {$v['name']}\n";
248 $r .= "|| {$v['value']}\n";
251 $r .= '|}';
252 return $r;
256 * Overloading Article's getContent method.
258 * Omit noarticletext if sharedupload; text will be fetched from the
259 * shared upload server if possible.
261 function getContent() {
262 $this->loadFile();
263 if( $this->img && !$this->img->isLocal() && 0 == $this->getID() ) {
264 return '';
266 return Article::getContent();
269 function openShowImage() {
270 global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgLang, $wgContLang;
272 $this->loadFile();
274 $full_url = $this->img->getURL();
275 $linkAttribs = false;
276 $sizeSel = intval( $wgUser->getOption( 'imagesize') );
277 if( !isset( $wgImageLimits[$sizeSel] ) ) {
278 $sizeSel = User::getDefaultOption( 'imagesize' );
280 // The user offset might still be incorrect, specially if
281 // $wgImageLimits got changed (see bug #8858).
282 if( !isset( $wgImageLimits[$sizeSel] ) ) {
283 // Default to the first offset in $wgImageLimits
284 $sizeSel = 0;
287 $max = $wgImageLimits[$sizeSel];
288 $maxWidth = $max[0];
289 $maxHeight = $max[1];
290 $sk = $wgUser->getSkin();
291 $dirmark = $wgContLang->getDirMark();
293 if ( $this->img->exists() ) {
294 # image
295 $page = $wgRequest->getIntOrNull( 'page' );
296 if ( is_null( $page ) ) {
297 $params = array();
298 $page = 1;
299 } else {
300 $params = array( 'page' => $page );
302 $width_orig = $this->img->getWidth();
303 $width = $width_orig;
304 $height_orig = $this->img->getHeight();
305 $height = $height_orig;
306 $mime = $this->img->getMimeType();
307 $showLink = false;
308 $linkAttribs = array( 'href' => $full_url );
309 $longDesc = $this->img->getLongDesc();
311 wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this , &$wgOut ) ) ;
313 if ( $this->img->allowInlineDisplay() ) {
314 # image
316 # "Download high res version" link below the image
317 #$msgsize = wfMsgHtml('file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->img->getSize() ), $mime );
318 # We'll show a thumbnail of this image
319 if ( $width > $maxWidth || $height > $maxHeight ) {
320 # Calculate the thumbnail size.
321 # First case, the limiting factor is the width, not the height.
322 if ( $width / $height >= $maxWidth / $maxHeight ) {
323 $height = round( $height * $maxWidth / $width);
324 $width = $maxWidth;
325 # Note that $height <= $maxHeight now.
326 } else {
327 $newwidth = floor( $width * $maxHeight / $height);
328 $height = round( $height * $newwidth / $width );
329 $width = $newwidth;
330 # Note that $height <= $maxHeight now, but might not be identical
331 # because of rounding.
333 $msgbig = wfMsgHtml( 'show-big-image' );
334 $msgsmall = wfMsgExt( 'show-big-image-thumb',
335 array( 'parseinline' ), $wgLang->formatNum( $width ), $wgLang->formatNum( $height ) );
336 } else {
337 # Image is small enough to show full size on image page
338 $msgbig = htmlspecialchars( $this->img->getName() );
339 $msgsmall = wfMsgExt( 'file-nohires', array( 'parseinline' ) );
342 $params['width'] = $width;
343 $thumbnail = $this->img->transform( $params );
345 $anchorclose = "<br />";
346 if( $this->img->mustRender() ) {
347 $showLink = true;
348 } else {
349 $anchorclose .=
350 $msgsmall .
351 '<br />' . Xml::tags( 'a', $linkAttribs, $msgbig ) . "$dirmark " . $longDesc;
354 if ( $this->img->isMultipage() ) {
355 $wgOut->addHTML( '<table class="multipageimage"><tr><td>' );
358 if ( $thumbnail ) {
359 $options = array(
360 'alt' => $this->img->getTitle()->getPrefixedText(),
361 'file-link' => true,
363 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
364 $thumbnail->toHtml( $options ) .
365 $anchorclose . '</div>' );
368 if ( $this->img->isMultipage() ) {
369 $count = $this->img->pageCount();
371 if ( $page > 1 ) {
372 $label = $wgOut->parse( wfMsg( 'imgmultipageprev' ), false );
373 $link = $sk->makeKnownLinkObj( $this->mTitle, $label, 'page='. ($page-1) );
374 $thumb1 = $sk->makeThumbLinkObj( $this->mTitle, $this->img, $link, $label, 'none',
375 array( 'page' => $page - 1 ) );
376 } else {
377 $thumb1 = '';
380 if ( $page < $count ) {
381 $label = wfMsg( 'imgmultipagenext' );
382 $link = $sk->makeKnownLinkObj( $this->mTitle, $label, 'page='. ($page+1) );
383 $thumb2 = $sk->makeThumbLinkObj( $this->mTitle, $this->img, $link, $label, 'none',
384 array( 'page' => $page + 1 ) );
385 } else {
386 $thumb2 = '';
389 global $wgScript;
391 $formParams = array(
392 'name' => 'pageselector',
393 'action' => $wgScript,
394 'onchange' => 'document.pageselector.submit();',
397 $option = array();
398 for ( $i=1; $i <= $count; $i++ ) {
399 $options[] = Xml::option( $wgLang->formatNum($i), $i, $i == $page );
401 $select = Xml::tags( 'select',
402 array( 'id' => 'pageselector', 'name' => 'page' ),
403 implode( "\n", $options ) );
405 $wgOut->addHTML(
406 '</td><td><div class="multipageimagenavbox">' .
407 Xml::openElement( 'form', $formParams ) .
408 Xml::hidden( 'title', $this->getTitle()->getPrefixedDbKey() ) .
409 wfMsgExt( 'imgmultigoto', array( 'parseinline', 'replaceafter' ), $select ) .
410 Xml::submitButton( wfMsg( 'imgmultigo' ) ) .
411 Xml::closeElement( 'form' ) .
412 "<hr />$thumb1\n$thumb2<br clear=\"all\" /></div></td></tr></table>"
415 } else {
416 #if direct link is allowed but it's not a renderable image, show an icon.
417 if ($this->img->isSafeFile()) {
418 $icon= $this->img->iconThumb();
420 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
421 $icon->toHtml( array( 'desc-link' => true ) ) .
422 '</div>' );
425 $showLink = true;
429 if ($showLink) {
430 $filename = wfEscapeWikiText( $this->img->getName() );
432 if (!$this->img->isSafeFile()) {
433 $warning = wfMsgNoTrans( 'mediawarning' );
434 $wgOut->addWikiText( <<<EOT
435 <div class="fullMedia">
436 <span class="dangerousLink">[[Media:$filename|$filename]]</span>$dirmark
437 <span class="fileInfo"> $longDesc</span>
438 </div>
440 <div class="mediaWarning">$warning</div>
443 } else {
444 $wgOut->addWikiText( <<<EOT
445 <div class="fullMedia">
446 [[Media:$filename|$filename]]$dirmark <span class="fileInfo"> $longDesc</span>
447 </div>
453 if(!$this->img->isLocal()) {
454 $this->printSharedImageText();
456 } else {
457 # Image does not exist
459 $title = SpecialPage::getTitleFor( 'Upload' );
460 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),
461 'wpDestFile=' . urlencode( $this->img->getName() ) );
462 $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
467 * Show a notice that the file is from a shared repository
469 function printSharedImageText() {
470 global $wgOut, $wgUser;
472 $this->loadFile();
474 $descUrl = $this->img->getDescriptionUrl();
475 $descText = $this->img->getDescriptionText();
476 $s = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml( 'sharedupload' );
477 if ( $descUrl ) {
478 $sk = $wgUser->getSkin();
479 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadwiki-linktext' ) );
480 $msg = ( $descText ) ? 'shareduploadwiki-desc' : 'shareduploadwiki';
481 $msg = wfMsgExt( $msg, array( 'parseinline', 'replaceafter' ), $link );
482 if ( $msg != '-' ) {
483 # Show message only if not voided by local sysops
484 $s .= $msg;
487 $s .= "</div>";
488 $wgOut->addHTML( $s );
490 if ( $descText ) {
491 $this->mExtraDescription = $descText;
496 * Check for files with the same name on the foreign repos.
498 function checkSharedConflict() {
499 global $wgOut, $wgUser;
501 $repoGroup = RepoGroup::singleton();
502 if( !$repoGroup->hasForeignRepos() ) {
503 return;
506 $this->loadFile();
507 if( !$this->img->isLocal() ) {
508 return;
511 $this->dupFile = null;
512 $repoGroup->forEachForeignRepo( array( $this, 'checkSharedConflictCallback' ) );
514 if( !$this->dupFile )
515 return;
516 $dupfile = $this->dupFile;
517 $same = (
518 ($this->img->getSha1() == $dupfile->getSha1()) &&
519 ($this->img->getSize() == $dupfile->getSize())
522 $sk = $wgUser->getSkin();
523 $descUrl = $dupfile->getDescriptionUrl();
524 if( $same ) {
525 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadduplicate-linktext' ) );
526 $wgOut->addHTML( '<div id="shared-image-dup">' . wfMsgWikiHtml( 'shareduploadduplicate', $link ) . '</div>' );
527 } else {
528 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadconflict-linktext' ) );
529 $wgOut->addHTML( '<div id="shared-image-conflict">' . wfMsgWikiHtml( 'shareduploadconflict', $link ) . '</div>' );
533 function checkSharedConflictCallback( $repo ) {
534 $this->loadFile();
535 $dupfile = $repo->newFile( $this->img->getTitle() );
536 if( $dupfile->exists() ) {
537 $this->dupFile = $dupfile;
539 return $dupfile->exists();
542 function getUploadUrl() {
543 $this->loadFile();
544 $uploadTitle = SpecialPage::getTitleFor( 'Upload' );
545 return $uploadTitle->getFullUrl( 'wpDestFile=' . urlencode( $this->img->getName() ) );
549 * Print out the various links at the bottom of the image page, e.g. reupload,
550 * external editing (and instructions link) etc.
552 function uploadLinksBox() {
553 global $wgUser, $wgOut;
555 $this->loadFile();
556 if( !$this->img->isLocal() )
557 return;
559 $sk = $wgUser->getSkin();
561 $wgOut->addHtml( '<br /><ul>' );
563 # "Upload a new version of this file" link
564 if( UploadForm::userCanReUpload($wgUser,$this->img->name) ) {
565 $ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
566 $wgOut->addHtml( "<li><div class='plainlinks'>{$ulink}</div></li>" );
569 # Link to Special:FileDuplicateSearch
570 $dupeLink = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'FileDuplicateSearch', $this->mTitle->getDBkey() ), wfMsgHtml( 'imagepage-searchdupe' ) );
571 $wgOut->addHtml( "<li>{$dupeLink}</li>" );
573 # External editing link
574 $elink = $sk->makeKnownLinkObj( $this->mTitle, wfMsgHtml( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
575 $wgOut->addHtml( '<li>' . $elink . '<div>' . wfMsgWikiHtml( 'edit-externally-help' ) . '</div></li>' );
577 $wgOut->addHtml( '</ul>' );
580 function closeShowImage()
582 # For overloading
587 * If the page we've just displayed is in the "Image" namespace,
588 * we follow it with an upload history of the image and its usage.
590 function imageHistory()
592 global $wgUser, $wgOut, $wgUseExternalEditor;
594 $sk = $wgUser->getSkin();
596 $this->loadFile();
597 if ( $this->img->exists() ) {
598 $list = new ImageHistoryList( $sk, $this->current, $this->img );
599 $file = $this->current;
600 $dims = $file->getDimensionsString();
601 $s = $list->beginImageHistoryList();
602 $s .= $list->imageHistoryLine( true, $file );
603 // old image versions
604 $hist = $this->img->getHistory();
605 foreach( $hist as $file ) {
606 $dims = $file->getDimensionsString();
607 $s .= $list->imageHistoryLine( false, $file );
609 $s .= $list->endImageHistoryList();
610 } else { $s=''; }
611 $wgOut->addHTML( $s );
613 $this->img->resetHistory(); // free db resources
615 # Exist check because we don't want to show this on pages where an image
616 # doesn't exist along with the noimage message, that would suck. -ævar
617 if( $wgUseExternalEditor && $this->img->exists() ) {
618 $this->uploadLinksBox();
623 function imageLinks()
625 global $wgUser, $wgOut;
627 $limit = 100;
629 $dbr = wfGetDB( DB_SLAVE );
631 $res = $dbr->select(
632 array( 'imagelinks', 'page' ),
633 array( 'page_namespace', 'page_title' ),
634 array( 'il_to' => $this->mTitle->getDBkey(), 'il_from = page_id' ),
635 __METHOD__,
636 array( 'LIMIT' => $limit + 1)
639 if ( 0 == $dbr->numRows( $res ) ) {
640 $wgOut->addWikiMsg( 'nolinkstoimage' );
641 return;
643 $wgOut->addWikiMsg( 'linkstoimage' );
644 $wgOut->addHTML( "<ul class='mw-imagepage-linktoimage'>\n" );
646 $sk = $wgUser->getSkin();
647 $count = 0;
648 while ( $s = $res->fetchObject() ) {
649 $count++;
650 if ( $count <= $limit ) {
651 // We have not yet reached the extra one that tells us there is more to fetch
652 $name = Title::makeTitle( $s->page_namespace, $s->page_title );
653 $link = $sk->makeKnownLinkObj( $name, "" );
654 $wgOut->addHTML( "<li>{$link}</li>\n" );
657 $wgOut->addHTML( "</ul>\n" );
658 $res->free();
660 // Add a links to [[Special:Whatlinkshere]]
661 if ( $count > $limit )
662 $wgOut->addWikiMsg( 'morelinkstoimage', $this->mTitle->getPrefixedDBkey() );
665 function imageRedirects()
667 global $wgUser, $wgOut;
669 $redirects = $this->getTitle()->getRedirectsHere( NS_IMAGE );
670 if ( count( $redirects ) == 0 ) return;
673 $wgOut->addWikiMsg( 'redirectstofile' );
674 $wgOut->addHTML( "<ul class='mw-imagepage-redirectstofile'>\n" );
676 $sk = $wgUser->getSkin();
677 foreach ( $redirects as $title ) {
678 $link = $sk->makeKnownLinkObj( $title, "" );
679 $wgOut->addHTML( "<li>{$link}</li>\n" );
681 $wgOut->addHTML( "</ul>\n" );
685 function imageDupes() {
686 global $wgOut, $wgUser;
688 $this->loadFile();
690 $dupes = $this->getDuplicates();
691 if ( count( $dupes ) == 0 ) return;
693 $wgOut->addWikiMsg( 'duplicatesoffile' );
694 $wgOut->addHTML( "<ul class='mw-imagepage-duplicates'>\n" );
696 $sk = $wgUser->getSkin();
697 foreach ( $dupes as $file ) {
698 if ( $file->isLocal() )
699 $link = $sk->makeKnownLinkObj( $file->getTitle(), "" );
700 else
701 $link = $sk->makeExternalLink( $file->getDescriptionUrl(),
702 $file->getTitle()->getPrefixedText() );
703 $wgOut->addHTML( "<li>{$link}</li>\n" );
705 $wgOut->addHTML( "</ul>\n" );
709 * Delete the file, or an earlier version of it
711 public function delete() {
712 $this->loadFile();
713 if( !$this->img->exists() || !$this->img->isLocal() || $this->img->getRedirected() ) {
714 // Standard article deletion
715 Article::delete();
716 return;
718 $deleter = new FileDeleteForm( $this->img );
719 $deleter->execute();
723 * Revert the file to an earlier version
725 public function revert() {
726 $this->loadFile();
727 $reverter = new FileRevertForm( $this->img );
728 $reverter->execute();
732 * Override handling of action=purge
734 function doPurge() {
735 $this->loadFile();
736 if( $this->img->exists() ) {
737 wfDebug( "ImagePage::doPurge purging " . $this->img->getName() . "\n" );
738 $update = new HTMLCacheUpdate( $this->mTitle, 'imagelinks' );
739 $update->doUpdate();
740 $this->img->upgradeRow();
741 $this->img->purgeCache();
742 } else {
743 wfDebug( "ImagePage::doPurge no image\n" );
745 parent::doPurge();
749 * Display an error with a wikitext description
751 function showError( $description ) {
752 global $wgOut;
753 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
754 $wgOut->setRobotpolicy( "noindex,nofollow" );
755 $wgOut->setArticleRelated( false );
756 $wgOut->enableClientCache( false );
757 $wgOut->addWikiText( $description );
763 * Builds the image revision log shown on image pages
765 * @ingroup Media
767 class ImageHistoryList {
769 protected $img, $skin, $title, $repo;
771 public function __construct( $skin, $curimg, $img ) {
772 $this->skin = $skin;
773 $this->current = $curimg;
774 $this->img = $img;
775 $this->title = $img->getTitle();
778 public function beginImageHistoryList() {
779 global $wgOut, $wgUser;
780 return Xml::element( 'h2', array( 'id' => 'filehistory' ), wfMsg( 'filehist' ) )
781 . $wgOut->parse( wfMsgNoTrans( 'filehist-help' ) )
782 . Xml::openElement( 'table', array( 'class' => 'filehistory' ) ) . "\n"
783 . '<tr><td></td>'
784 . ( $this->current->isLocal() && ($wgUser->isAllowed('delete') || $wgUser->isAllowed('deleterevision') ) ? '<td></td>' : '' )
785 . '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
786 . '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
787 . '<th>' . wfMsgHtml( 'filehist-user' ) . '</th>'
788 . '<th>' . wfMsgHtml( 'filehist-comment' ) . '</th>'
789 . "</tr>\n";
792 public function endImageHistoryList() {
793 return "</table>\n";
796 public function imageHistoryLine( $iscur, $file ) {
797 global $wgUser, $wgLang, $wgContLang, $wgTitle;
799 $timestamp = wfTimestamp(TS_MW, $file->getTimestamp());
800 $img = $iscur ? $file->getName() : $file->getArchiveName();
801 $user = $file->getUser('id');
802 $usertext = $file->getUser('text');
803 $size = $file->getSize();
804 $description = $file->getDescription();
805 $dims = $file->getDimensionsString();
806 $sha1 = $file->getSha1();
808 $local = $this->current->isLocal();
809 $row = $css = $selected = '';
811 // Deletion link
812 if( $local && ($wgUser->isAllowed('delete') || $wgUser->isAllowed('deleterevision') ) ) {
813 $row .= '<td>';
814 # Link to remove from history
815 if( $wgUser->isAllowed( 'delete' ) ) {
816 $q = array();
817 $q[] = 'action=delete';
818 if( !$iscur )
819 $q[] = 'oldimage=' . urlencode( $img );
820 $row .= $this->skin->makeKnownLinkObj(
821 $this->title,
822 wfMsgHtml( $iscur ? 'filehist-deleteall' : 'filehist-deleteone' ),
823 implode( '&', $q )
826 # Link to hide content
827 if( $wgUser->isAllowed( 'deleterevision' ) ) {
828 if( $wgUser->isAllowed('delete') ) {
829 $row .= '<br/>';
831 $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
832 // If file is top revision or locked from this user, don't link
833 if( $iscur || !$file->userCan(File::DELETED_RESTRICTED) ) {
834 $del = wfMsgHtml( 'rev-delundel' );
835 } else {
836 // If the file was hidden, link to sha-1
837 list($ts,$name) = explode('!',$img,2);
838 $del = $this->skin->makeKnownLinkObj( $revdel, wfMsg( 'rev-delundel' ),
839 'target=' . urlencode( $wgTitle->getPrefixedText() ) .
840 '&oldimage=' . urlencode( $ts ) );
841 // Bolden oversighted content
842 if( $file->isDeleted(File::DELETED_RESTRICTED) )
843 $del = "<strong>$del</strong>";
845 $row .= "<tt style='white-space: nowrap;'><small>$del</small></tt>";
847 $row .= '</td>';
850 // Reversion link/current indicator
851 $row .= '<td>';
852 if( $iscur ) {
853 $row .= wfMsgHtml( 'filehist-current' );
854 } elseif( $local && $wgUser->isLoggedIn() && $this->title->userCan( 'edit' ) ) {
855 if( $file->isDeleted(File::DELETED_FILE) ) {
856 $row .= wfMsgHtml('filehist-revert');
857 } else {
858 $q = array();
859 $q[] = 'action=revert';
860 $q[] = 'oldimage=' . urlencode( $img );
861 $q[] = 'wpEditToken=' . urlencode( $wgUser->editToken( $img ) );
862 $row .= $this->skin->makeKnownLinkObj( $this->title,
863 wfMsgHtml( 'filehist-revert' ),
864 implode( '&', $q ) );
867 $row .= '</td>';
869 // Date/time and image link
870 if( $file->getTimestamp() === $this->img->getTimestamp() ) {
871 $selected = "class='filehistory-selected'";
873 $row .= "<td $selected style='white-space: nowrap;'>";
874 if( !$file->userCan(File::DELETED_FILE) ) {
875 # Don't link to unviewable files
876 $row .= '<span class="history-deleted">' . $wgLang->timeAndDate( $timestamp, true ) . '</span>';
877 } else if( $file->isDeleted(File::DELETED_FILE) ) {
878 $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
879 # Make a link to review the image
880 $url = $this->skin->makeKnownLinkObj( $revdel, $wgLang->timeAndDate( $timestamp, true ),
881 "target=".$wgTitle->getPrefixedText()."&file=$sha1.".$this->current->getExtension() );
882 $row .= '<span class="history-deleted">'.$url.'</span>';
883 } else {
884 $url = $iscur ? $this->current->getUrl() : $this->current->getArchiveUrl( $img );
885 $row .= Xml::element( 'a', array( 'href' => $url ), $wgLang->timeAndDate( $timestamp, true ) );
888 $row .= "</td><td>";
890 // Image dimensions
891 $row .= htmlspecialchars( $dims );
893 // File size
894 $row .= " <span style='white-space: nowrap;'>(" . $this->skin->formatSize( $size ) . ')</span>';
896 // Uploading user
897 $row .= '</td><td>';
898 if( $local ) {
899 // Hide deleted usernames
900 if( $file->isDeleted(File::DELETED_USER) ) {
901 $row .= '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
902 } else {
903 $row .= $this->skin->userLink( $user, $usertext ) . " <span style='white-space: nowrap;'>" .
904 $this->skin->userToolLinks( $user, $usertext ) . "</span>";
906 } else {
907 $row .= htmlspecialchars( $usertext );
909 $row .= '</td><td>';
911 // Don't show deleted descriptions
912 if ( $file->isDeleted(File::DELETED_COMMENT) ) {
913 $row .= '<span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span>';
914 } else {
915 $row .= $this->skin->commentBlock( $description, $this->title );
917 $row .= '</td>';
919 wfRunHooks( 'ImagePageFileHistoryLine', array( &$file, &$row, &$css ) );
920 $trCSS = $css ? " class='$css'" : "";
922 return "<tr{$trCSS}>{$row}</tr>\n";