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