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