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