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