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