* Move image page redirect checking to ImagePage. Should now also work on foreign...
[lhc/web/wiklou.git] / includes / ImagePage.php
1 <?php
2 /**
3 */
4
5 /**
6 *
7 */
8 if( !defined( 'MEDIAWIKI' ) )
9 die( 1 );
10
11 /**
12 * Special handling for image description pages
13 *
14 * @addtogroup Media
15 */
16 class ImagePage extends Article {
17
18 /* private */ var $img; // Image object this page is shown for
19 /* private */ var $repo;
20 var $mExtraDescription = false;
21
22 function __construct( $title, $time = false ) {
23 parent::__construct( $title );
24 $this->img = wfFindFile( $this->mTitle, $time );
25 if ( !$this->img ) {
26 $this->img = wfLocalFile( $this->mTitle );
27 $this->current = $this->img;
28 } else {
29 $this->current = $time ? wfLocalFile( $this->mTitle ) : $this->img;
30 }
31 $this->repo = $this->img->repo;
32 }
33
34 /**
35 * Handler for action=render
36 * Include body text only; none of the image extras
37 */
38 function render() {
39 global $wgOut;
40 $wgOut->setArticleBodyOnly( true );
41 parent::view();
42 }
43
44 function view() {
45 global $wgOut, $wgShowEXIF, $wgRequest, $wgUser;
46
47 if ( $this->img->getRedirected() )
48 return Article::view();
49
50 $diff = $wgRequest->getVal( 'diff' );
51 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
52
53 if ( $this->mTitle->getNamespace() != NS_IMAGE || ( isset( $diff ) && $diffOnly ) )
54 return Article::view();
55
56 if ($wgShowEXIF && $this->img->exists()) {
57 // FIXME: bad interface, see note on MediaHandler::formatMetadata().
58 $formattedMetadata = $this->img->formatMetadata();
59 $showmeta = $formattedMetadata !== false;
60 } else {
61 $showmeta = false;
62 }
63
64 if ($this->img->exists())
65 $wgOut->addHTML($this->showTOC($showmeta));
66
67 $this->openShowImage();
68
69 # No need to display noarticletext, we use our own message, output in openShowImage()
70 if ( $this->getID() ) {
71 Article::view();
72 } else {
73 # Just need to set the right headers
74 $wgOut->setArticleFlag( true );
75 $wgOut->setRobotpolicy( 'noindex,nofollow' );
76 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
77 $this->viewUpdates();
78 }
79
80 # Show shared description, if needed
81 if ( $this->mExtraDescription ) {
82 $fol = wfMsgNoTrans( 'shareddescriptionfollows' );
83 if( $fol != '-' && !wfEmptyMsg( 'shareddescriptionfollows', $fol ) ) {
84 $wgOut->addWikiText( $fol );
85 }
86 $wgOut->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription . '</div>' );
87 } else {
88 $this->checkSharedConflict();
89 }
90
91 $this->closeShowImage();
92 $this->imageHistory();
93 $this->imageLinks();
94
95 if ( $showmeta ) {
96 global $wgStylePath, $wgStyleVersion;
97 $expand = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-expand' ) ) );
98 $collapse = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-collapse' ) ) );
99 $wgOut->addHTML( Xml::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ). "\n" );
100 $wgOut->addWikiText( $this->makeMetadataTable( $formattedMetadata ) );
101 $wgOut->addHTML(
102 "<script type=\"text/javascript\" src=\"$wgStylePath/common/metadata.js?$wgStyleVersion\"></script>\n" .
103 "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
104 }
105 }
106
107 public function getRedirectTarget() {
108 if ( $this->img->isLocal() )
109 return parent::getRedirectTarget();
110
111 // Foreign image page
112 $from = $this->img->getRedirected();
113 return $this->mRedirectTarget = Title::makeTitle( NS_IMAGE, $from );
114 }
115
116 /**
117 * Create the TOC
118 *
119 * @access private
120 *
121 * @param bool $metadata Whether or not to show the metadata link
122 * @return string
123 */
124 function showTOC( $metadata ) {
125 global $wgLang;
126 $r = '<ul id="filetoc">
127 <li><a href="#file">' . $wgLang->getNsText( NS_IMAGE ) . '</a></li>
128 <li><a href="#filehistory">' . wfMsgHtml( 'filehist' ) . '</a></li>
129 <li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . '</a></li>' .
130 ($metadata ? ' <li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>' : '') . '
131 </ul>';
132 return $r;
133 }
134
135 /**
136 * Make a table with metadata to be shown in the output page.
137 *
138 * FIXME: bad interface, see note on MediaHandler::formatMetadata().
139 *
140 * @access private
141 *
142 * @param array $exif The array containing the EXIF data
143 * @return string
144 */
145 function makeMetadataTable( $metadata ) {
146 $r = wfMsg( 'metadata-help' ) . "\n\n";
147 $r .= "{| id=mw_metadata class=mw_metadata\n";
148 foreach ( $metadata as $type => $stuff ) {
149 foreach ( $stuff as $v ) {
150 $class = Sanitizer::escapeId( $v['id'] );
151 if( $type == 'collapsed' ) {
152 $class .= ' collapsable';
153 }
154 $r .= "|- class=\"$class\"\n";
155 $r .= "!| {$v['name']}\n";
156 $r .= "|| {$v['value']}\n";
157 }
158 }
159 $r .= '|}';
160 return $r;
161 }
162
163 /**
164 * Overloading Article's getContent method.
165 *
166 * Omit noarticletext if sharedupload; text will be fetched from the
167 * shared upload server if possible.
168 */
169 function getContent() {
170 if( $this->img && !$this->img->isLocal() && 0 == $this->getID() ) {
171 return '';
172 }
173 return Article::getContent();
174 }
175
176 function openShowImage() {
177 global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgLang, $wgContLang;
178
179 $full_url = $this->img->getURL();
180 $linkAttribs = false;
181 $sizeSel = intval( $wgUser->getOption( 'imagesize') );
182 if( !isset( $wgImageLimits[$sizeSel] ) ) {
183 $sizeSel = User::getDefaultOption( 'imagesize' );
184
185 // The user offset might still be incorrect, specially if
186 // $wgImageLimits got changed (see bug #8858).
187 if( !isset( $wgImageLimits[$sizeSel] ) ) {
188 // Default to the first offset in $wgImageLimits
189 $sizeSel = 0;
190 }
191 }
192 $max = $wgImageLimits[$sizeSel];
193 $maxWidth = $max[0];
194 $maxHeight = $max[1];
195 $sk = $wgUser->getSkin();
196 $dirmark = $wgContLang->getDirMark();
197
198 if ( $this->img->exists() ) {
199 # image
200 $page = $wgRequest->getIntOrNull( 'page' );
201 if ( is_null( $page ) ) {
202 $params = array();
203 $page = 1;
204 } else {
205 $params = array( 'page' => $page );
206 }
207 $width_orig = $this->img->getWidth();
208 $width = $width_orig;
209 $height_orig = $this->img->getHeight();
210 $height = $height_orig;
211 $mime = $this->img->getMimeType();
212 $showLink = false;
213 $linkAttribs = array( 'href' => $full_url );
214 $longDesc = $this->img->getLongDesc();
215
216 wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this , &$wgOut ) ) ;
217
218 if ( $this->img->allowInlineDisplay() ) {
219 # image
220
221 # "Download high res version" link below the image
222 #$msgsize = wfMsgHtml('file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->img->getSize() ), $mime );
223 # We'll show a thumbnail of this image
224 if ( $width > $maxWidth || $height > $maxHeight ) {
225 # Calculate the thumbnail size.
226 # First case, the limiting factor is the width, not the height.
227 if ( $width / $height >= $maxWidth / $maxHeight ) {
228 $height = round( $height * $maxWidth / $width);
229 $width = $maxWidth;
230 # Note that $height <= $maxHeight now.
231 } else {
232 $newwidth = floor( $width * $maxHeight / $height);
233 $height = round( $height * $newwidth / $width );
234 $width = $newwidth;
235 # Note that $height <= $maxHeight now, but might not be identical
236 # because of rounding.
237 }
238 $msgbig = wfMsgHtml( 'show-big-image' );
239 $msgsmall = wfMsgExt( 'show-big-image-thumb',
240 array( 'parseinline' ), $wgLang->formatNum( $width ), $wgLang->formatNum( $height ) );
241 } else {
242 # Image is small enough to show full size on image page
243 $msgbig = htmlspecialchars( $this->img->getName() );
244 $msgsmall = wfMsgExt( 'file-nohires', array( 'parseinline' ) );
245 }
246
247 $params['width'] = $width;
248 $thumbnail = $this->img->transform( $params );
249
250 $anchorclose = "<br />";
251 if( $this->img->mustRender() ) {
252 $showLink = true;
253 } else {
254 $anchorclose .=
255 $msgsmall .
256 '<br />' . Xml::tags( 'a', $linkAttribs, $msgbig ) . "$dirmark " . $longDesc;
257 }
258
259 if ( $this->img->isMultipage() ) {
260 $wgOut->addHTML( '<table class="multipageimage"><tr><td>' );
261 }
262
263 if ( $thumbnail ) {
264 $options = array(
265 'alt' => $this->img->getTitle()->getPrefixedText(),
266 'file-link' => true,
267 );
268 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
269 $thumbnail->toHtml( $options ) .
270 $anchorclose . '</div>' );
271 }
272
273 if ( $this->img->isMultipage() ) {
274 $count = $this->img->pageCount();
275
276 if ( $page > 1 ) {
277 $label = $wgOut->parse( wfMsg( 'imgmultipageprev' ), false );
278 $link = $sk->makeKnownLinkObj( $this->mTitle, $label, 'page='. ($page-1) );
279 $thumb1 = $sk->makeThumbLinkObj( $this->mTitle, $this->img, $link, $label, 'none',
280 array( 'page' => $page - 1 ) );
281 } else {
282 $thumb1 = '';
283 }
284
285 if ( $page < $count ) {
286 $label = wfMsg( 'imgmultipagenext' );
287 $link = $sk->makeKnownLinkObj( $this->mTitle, $label, 'page='. ($page+1) );
288 $thumb2 = $sk->makeThumbLinkObj( $this->mTitle, $this->img, $link, $label, 'none',
289 array( 'page' => $page + 1 ) );
290 } else {
291 $thumb2 = '';
292 }
293
294 global $wgScript;
295 $select = '<form name="pageselector" action="' .
296 htmlspecialchars( $wgScript ) .
297 '" method="get" onchange="document.pageselector.submit();">' .
298 Xml::hidden( 'title', $this->getTitle()->getPrefixedDbKey() );
299 $select .= $wgOut->parse( wfMsg( 'imgmultigotopre' ), false ) .
300 ' <select id="pageselector" name="page">';
301 for ( $i=1; $i <= $count; $i++ ) {
302 $select .= Xml::option( $wgLang->formatNum( $i ), $i,
303 $i == $page );
304 }
305 $select .= '</select>' . $wgOut->parse( wfMsg( 'imgmultigotopost' ), false ) .
306 '<input type="submit" value="' .
307 htmlspecialchars( wfMsg( 'imgmultigo' ) ) . '"></form>';
308
309 $wgOut->addHTML( '</td><td><div class="multipageimagenavbox">' .
310 "$select<hr />$thumb1\n$thumb2<br clear=\"all\" /></div></td></tr></table>" );
311 }
312 } else {
313 #if direct link is allowed but it's not a renderable image, show an icon.
314 if ($this->img->isSafeFile()) {
315 $icon= $this->img->iconThumb();
316
317 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
318 $icon->toHtml( array( 'desc-link' => true ) ) .
319 '</div>' );
320 }
321
322 $showLink = true;
323 }
324
325
326 if ($showLink) {
327 $filename = wfEscapeWikiText( $this->img->getName() );
328
329 if (!$this->img->isSafeFile()) {
330 $warning = wfMsgNoTrans( 'mediawarning' );
331 $wgOut->addWikiText( <<<EOT
332 <div class="fullMedia">
333 <span class="dangerousLink">[[Media:$filename|$filename]]</span>$dirmark
334 <span class="fileInfo"> $longDesc</span>
335 </div>
336
337 <div class="mediaWarning">$warning</div>
338 EOT
339 );
340 } else {
341 $wgOut->addWikiText( <<<EOT
342 <div class="fullMedia">
343 [[Media:$filename|$filename]]$dirmark <span class="fileInfo"> $longDesc</span>
344 </div>
345 EOT
346 );
347 }
348 }
349
350 if(!$this->img->isLocal()) {
351 $this->printSharedImageText();
352 }
353 } else {
354 # Image does not exist
355
356 $title = SpecialPage::getTitleFor( 'Upload' );
357 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),
358 'wpDestFile=' . urlencode( $this->img->getName() ) );
359 $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
360 }
361 }
362
363 /**
364 * Show a notice that the file is from a shared repository
365 */
366 function printSharedImageText() {
367 global $wgOut, $wgUser;
368
369 $descUrl = $this->img->getDescriptionUrl();
370 $descText = $this->img->getDescriptionText();
371 $s = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml( 'sharedupload' );
372 if ( $descUrl ) {
373 $sk = $wgUser->getSkin();
374 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadwiki-linktext' ) );
375 $msg = ( $descText ) ? 'shareduploadwiki-desc' : 'shareduploadwiki';
376 $msg = wfMsgExt( $msg, array( 'parseinline', 'replaceafter' ), $link );
377 if ( $msg != '-' ) {
378 # Show message only if not voided by local sysops
379 $s .= $msg;
380 }
381 }
382 $s .= "</div>";
383 $wgOut->addHTML( $s );
384
385 if ( $descText ) {
386 $this->mExtraDescription = $descText;
387 }
388 }
389
390 function checkSharedConflict() {
391 global $wgOut, $wgUser;
392 $repoGroup = RepoGroup::singleton();
393 if( !$repoGroup->hasForeignRepos() ) {
394 return;
395 }
396 if( !$this->img->isLocal() ) {
397 return;
398 }
399
400 $this->dupFile = null;
401 $repoGroup->forEachForeignRepo( array( $this, 'checkSharedConflictCallback' ) );
402
403 if( !$this->dupFile )
404 return;
405 $dupfile = $this->dupFile;
406 $same = (
407 ($this->img->getSha1() == $dupfile->getSha1()) &&
408 ($this->img->getSize() == $dupfile->getSize())
409 );
410
411 $sk = $wgUser->getSkin();
412 $descUrl = $dupfile->getDescriptionUrl();
413 if( $same ) {
414 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadduplicate-linktext' ) );
415 $wgOut->addHTML( '<div id="shared-image-dup">' . wfMsgWikiHtml( 'shareduploadduplicate', $link ) . '</div>' );
416 } else {
417 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadconflict-linktext' ) );
418 $wgOut->addHTML( '<div id="shared-image-conflict">' . wfMsgWikiHtml( 'shareduploadconflict', $link ) . '</div>' );
419 }
420 }
421
422 function checkSharedConflictCallback( $repo ) {
423 $dupfile = $repo->newFile( $this->img->getTitle() );
424 if( $dupfile->exists() )
425 $this->dupFile = $dupfile;
426 return $dupfile->exists();
427 }
428
429 function getUploadUrl() {
430 $uploadTitle = SpecialPage::getTitleFor( 'Upload' );
431 return $uploadTitle->getFullUrl( 'wpDestFile=' . urlencode( $this->img->getName() ) );
432 }
433
434 /**
435 * Print out the various links at the bottom of the image page, e.g. reupload,
436 * external editing (and instructions link) etc.
437 */
438 function uploadLinksBox() {
439 global $wgUser, $wgOut;
440
441 if( !$this->img->isLocal() )
442 return;
443
444 $sk = $wgUser->getSkin();
445
446 $wgOut->addHtml( '<br /><ul>' );
447
448 # "Upload a new version of this file" link
449 if( UploadForm::userCanReUpload($wgUser,$this->img->name) ) {
450 $ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
451 $wgOut->addHtml( "<li><div class='plainlinks'>{$ulink}</div></li>" );
452 }
453
454 # Link to Special:FileDuplicateSearch
455 $dupeLink = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'FileDuplicateSearch', $this->mTitle->getDBkey() ), wfMsgHtml( 'imagepage-searchdupe' ) );
456 $wgOut->addHtml( "<li>{$dupeLink}</li>" );
457
458 # External editing link
459 $elink = $sk->makeKnownLinkObj( $this->mTitle, wfMsgHtml( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
460 $wgOut->addHtml( '<li>' . $elink . '<div>' . wfMsgWikiHtml( 'edit-externally-help' ) . '</div></li>' );
461
462 $wgOut->addHtml( '</ul>' );
463 }
464
465 function closeShowImage()
466 {
467 # For overloading
468
469 }
470
471 /**
472 * If the page we've just displayed is in the "Image" namespace,
473 * we follow it with an upload history of the image and its usage.
474 */
475 function imageHistory()
476 {
477 global $wgUser, $wgOut, $wgUseExternalEditor;
478
479 $sk = $wgUser->getSkin();
480
481 if ( $this->img->exists() ) {
482 $list = new ImageHistoryList( $sk, $this->current );
483 $file = $this->current;
484 $dims = $file->getDimensionsString();
485 $s = $list->beginImageHistoryList() .
486 $list->imageHistoryLine( true, $file );
487 // old image versions
488 $hist = $this->img->getHistory();
489 foreach( $hist as $file ) {
490 $dims = $file->getDimensionsString();
491 $s .= $list->imageHistoryLine( false, $file );
492 }
493 $s .= $list->endImageHistoryList();
494 } else { $s=''; }
495 $wgOut->addHTML( $s );
496
497 $this->img->resetHistory(); // free db resources
498
499 # Exist check because we don't want to show this on pages where an image
500 # doesn't exist along with the noimage message, that would suck. -ævar
501 if( $wgUseExternalEditor && $this->img->exists() ) {
502 $this->uploadLinksBox();
503 }
504
505 }
506
507 function imageLinks()
508 {
509 global $wgUser, $wgOut;
510
511 $wgOut->addHTML( Xml::element( 'h2', array( 'id' => 'filelinks' ), wfMsg( 'imagelinks' ) ) . "\n" );
512
513 $dbr = wfGetDB( DB_SLAVE );
514 $page = $dbr->tableName( 'page' );
515 $imagelinks = $dbr->tableName( 'imagelinks' );
516
517 $sql = "SELECT page_namespace,page_title FROM $imagelinks,$page WHERE il_to=" .
518 $dbr->addQuotes( $this->mTitle->getDBkey() ) . " AND il_from=page_id";
519 $sql = $dbr->limitResult($sql, 500, 0);
520 $res = $dbr->query( $sql, "ImagePage::imageLinks" );
521
522 if ( 0 == $dbr->numRows( $res ) ) {
523 $wgOut->addHtml( '<p>' . wfMsg( "nolinkstoimage" ) . "</p>\n" );
524 return;
525 }
526 $wgOut->addHTML( '<p>' . wfMsg( 'linkstoimage' ) . "</p>\n<ul>" );
527
528 $sk = $wgUser->getSkin();
529 while ( $s = $dbr->fetchObject( $res ) ) {
530 $name = Title::MakeTitle( $s->page_namespace, $s->page_title );
531 $link = $sk->makeKnownLinkObj( $name, "" );
532 $wgOut->addHTML( "<li>{$link}</li>\n" );
533 }
534 $wgOut->addHTML( "</ul>\n" );
535 }
536
537 /**
538 * Delete the file, or an earlier version of it
539 */
540 public function delete() {
541 if( !$this->img->exists() || !$this->img->isLocal() ) {
542 // Standard article deletion
543 Article::delete();
544 return;
545 }
546 $deleter = new FileDeleteForm( $this->img );
547 $deleter->execute();
548 }
549
550 /**
551 * Revert the file to an earlier version
552 */
553 public function revert() {
554 $reverter = new FileRevertForm( $this->img );
555 $reverter->execute();
556 }
557
558 /**
559 * Override handling of action=purge
560 */
561 function doPurge() {
562 if( $this->img->exists() ) {
563 wfDebug( "ImagePage::doPurge purging " . $this->img->getName() . "\n" );
564 $update = new HTMLCacheUpdate( $this->mTitle, 'imagelinks' );
565 $update->doUpdate();
566 $this->img->upgradeRow();
567 $this->img->purgeCache();
568 } else {
569 wfDebug( "ImagePage::doPurge no image\n" );
570 }
571 parent::doPurge();
572 }
573
574 /**
575 * Display an error with a wikitext description
576 */
577 function showError( $description ) {
578 global $wgOut;
579 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
580 $wgOut->setRobotpolicy( "noindex,nofollow" );
581 $wgOut->setArticleRelated( false );
582 $wgOut->enableClientCache( false );
583 $wgOut->addWikiText( $description );
584 }
585
586 }
587
588 /**
589 * Builds the image revision log shown on image pages
590 *
591 * @addtogroup Media
592 */
593 class ImageHistoryList {
594
595 protected $img, $skin, $title, $repo;
596
597 public function __construct( $skin, $img ) {
598 $this->skin = $skin;
599 $this->img = $img;
600 $this->title = $img->getTitle();
601 }
602
603 public function beginImageHistoryList() {
604 global $wgOut, $wgUser;
605 $deleteColumn = $wgUser->isAllowed( 'delete' ) || $wgUser->isAllowed( 'deleterevision' );
606 return Xml::element( 'h2', array( 'id' => 'filehistory' ), wfMsg( 'filehist' ) )
607 . $wgOut->parse( wfMsgNoTrans( 'filehist-help' ) )
608 . Xml::openElement( 'table', array( 'class' => 'filehistory' ) ) . "\n"
609 . '<tr><td></td>'
610 . ( $this->img->isLocal() && $deleteColumn ? '<td></td>' : '' )
611 . '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
612 . '<th>' . wfMsgHtml( 'filehist-user' ) . '</th>'
613 . '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
614 . '<th class="mw-imagepage-filesize">' . wfMsgHtml( 'filehist-filesize' ) . '</th>'
615 . '<th>' . wfMsgHtml( 'filehist-comment' ) . '</th>'
616 . "</tr>\n";
617 }
618
619 public function endImageHistoryList() {
620 return "</table>\n";
621 }
622
623 public function imageHistoryLine( $iscur, $file ) {
624 global $wgUser, $wgLang, $wgContLang, $wgTitle;
625
626 $timestamp = wfTimestamp(TS_MW, $file->getTimestamp());
627 $img = $iscur ? $file->getName() : $file->getArchiveName();
628 $user = $file->getUser('id');
629 $usertext = $file->getUser('text');
630 $size = $file->getSize();
631 $description = $file->getDescription();
632 $dims = $file->getDimensionsString();
633 $sha1 = $file->getSha1();
634
635 $local = $this->img->isLocal();
636 $row = '';
637
638 // Deletion link
639 if( $local && ($wgUser->isAllowed('delete') || $wgUser->isAllowed('deleterevision') ) ) {
640 $row .= '<td>';
641 # Link to remove from history
642 if( $wgUser->isAllowed( 'delete' ) ) {
643 $q = array();
644 $q[] = 'action=delete';
645 if( !$iscur )
646 $q[] = 'oldimage=' . urlencode( $img );
647 $row .= $this->skin->makeKnownLinkObj(
648 $this->title,
649 wfMsgHtml( $iscur ? 'filehist-deleteall' : 'filehist-deleteone' ),
650 implode( '&', $q )
651 );
652 $row .= '<br/>';
653 }
654 # Link to hide content
655 if( $wgUser->isAllowed( 'deleterevision' ) ) {
656 $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
657 // If file is top revision or locked from this user, don't link
658 if( $iscur || !$file->userCan(File::DELETED_RESTRICTED) ) {
659 $del = wfMsgHtml( 'rev-delundel' );
660 } else {
661 // If the file was hidden, link to sha-1
662 list($ts,$name) = explode('!',$img,2);
663 $del = $this->skin->makeKnownLinkObj( $revdel, wfMsg( 'rev-delundel' ),
664 'target=' . urlencode( $wgTitle->getPrefixedText() ) .
665 '&oldimage=' . urlencode( $ts ) );
666 // Bolden oversighted content
667 if( $file->isDeleted(File::DELETED_RESTRICTED) )
668 $del = "<strong>$del</strong>";
669 }
670 $row .= "<tt><small>$del</small></tt>";
671 }
672 $row .= '</td>';
673 }
674
675 // Reversion link/current indicator
676 $row .= '<td>';
677 if( $iscur ) {
678 $row .= wfMsgHtml( 'filehist-current' );
679 } elseif( $local && $wgUser->isLoggedIn() && $this->title->userCan( 'edit' ) ) {
680 if( $file->isDeleted(File::DELETED_FILE) ) {
681 $row .= wfMsgHtml('filehist-revert');
682 } else {
683 $q = array();
684 $q[] = 'action=revert';
685 $q[] = 'oldimage=' . urlencode( $img );
686 $q[] = 'wpEditToken=' . urlencode( $wgUser->editToken( $img ) );
687 $row .= $this->skin->makeKnownLinkObj( $this->title,
688 wfMsgHtml( 'filehist-revert' ),
689 implode( '&', $q ) );
690 }
691 }
692 $row .= '</td>';
693
694 // Date/time and image link
695 $row .= '<td>';
696 if( !$file->userCan(File::DELETED_FILE) ) {
697 # Don't link to unviewable files
698 $row .= '<span class="history-deleted">' . $wgLang->timeAndDate( $timestamp, true ) . '</span>';
699 } else if( $file->isDeleted(File::DELETED_FILE) ) {
700 $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
701 # Make a link to review the image
702 $url = $this->skin->makeKnownLinkObj( $revdel, $wgLang->timeAndDate( $timestamp, true ),
703 "target=".$wgTitle->getPrefixedText()."&file=$sha1.".$this->img->getExtension() );
704 $row .= '<span class="history-deleted">'.$url.'</span>';
705 } else {
706 $url = $iscur ? $this->img->getUrl() : $this->img->getArchiveUrl( $img );
707 $row .= Xml::element( 'a',
708 array( 'href' => $url ),
709 $wgLang->timeAndDate( $timestamp, true ) );
710 }
711
712 $row .= '</td>';
713
714 // Uploading user
715 $row .= '<td>';
716 if( $local ) {
717 // Hide deleted usernames
718 if( $file->isDeleted(File::DELETED_USER) )
719 $row .= '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
720 else
721 $row .= $this->skin->userLink( $user, $usertext ) .
722 $this->skin->userToolLinks( $user, $usertext );
723 } else {
724 $row .= htmlspecialchars( $usertext );
725 }
726 $row .= '</td>';
727
728 // Image dimensions
729 $row .= '<td>' . htmlspecialchars( $dims ) . '</td>';
730
731 // File size
732 $row .= '<td class="mw-imagepage-filesize">' . $this->skin->formatSize( $size ) . '</td>';
733
734 // Don't show deleted descriptions
735 if ( $file->isDeleted(File::DELETED_COMMENT) )
736 $row .= '<td><span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span></td>';
737 else
738 $row .= '<td>' . $this->skin->commentBlock( $description, $this->title ) . '</td>';
739
740 return "<tr>{$row}</tr>\n";
741 }
742 }