* Add 'GetInternalURL' hook to match the GetFullURL and GetLocalURL ones
[lhc/web/wiklou.git] / includes / ImagePage.php
1 <?php
2 /**
3 * @package MediaWiki
4 */
5
6 /**
7 *
8 */
9 if( !defined( 'MEDIAWIKI' ) )
10 die();
11
12 require_once( 'Image.php' );
13
14 /**
15 * Special handling for image description pages
16 * @package MediaWiki
17 */
18 class ImagePage extends Article {
19
20 /* private */ var $img; // Image object this page is shown for
21 var $mExtraDescription = false;
22
23 function render() {
24 global $wgOut;
25 $wgOut->setArticleBodyOnly(true);
26 $wgOut->addWikitext($this->getContent(true));
27 }
28
29 function view() {
30 global $wgOut, $wgShowEXIF;
31
32 $this->img = new Image( $this->mTitle );
33
34 if( $this->mTitle->getNamespace() == NS_IMAGE ) {
35 if ($wgShowEXIF && $this->img->exists()) {
36 $exif = $this->img->getExifData();
37 $showmeta = count($exif) ? true : false;
38 } else {
39 $exif = false;
40 $showmeta = false;
41 }
42
43 if ($this->img->exists())
44 $wgOut->addHTML($this->showTOC($showmeta));
45
46 $this->openShowImage();
47
48 # No need to display noarticletext, we use our own message, output in openShowImage()
49 if( $this->getID() ) {
50 Article::view();
51 } else {
52 # Just need to set the right headers
53 $wgOut->setArticleFlag( true );
54 $wgOut->setRobotpolicy( 'index,follow' );
55 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
56 $wgOut->addMetaTags();
57 $this->viewUpdates();
58 }
59
60 if ($this->mExtraDescription) {
61 $fol = wfMsg('shareddescriptionfollows');
62 if ($fol != '-')
63 $wgOut->addWikiText(wfMsg('shareddescriptionfollows'));
64 $wgOut->addHTML($this->mExtraDescription);
65 }
66
67 $this->closeShowImage();
68 $this->imageHistory();
69 $this->imageLinks();
70 if( $exif ) {
71 global $wgStylePath;
72 $expand = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-expand' ) ) );
73 $collapse = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-collapse' ) ) );
74 $wgOut->addHTML( "<h2 id=\"metadata\">" . wfMsgHtml( 'metadata' ) . "</h2>\n" );
75 $wgOut->addWikiText( $this->makeMetadataTable( $exif ) );
76 $wgOut->addHTML(
77 "<script type=\"text/javascript\" src=\"$wgStylePath/common/metadata.js\"></script>\n" .
78 "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
79 }
80 } else {
81 Article::view();
82 }
83 }
84
85 /**
86 * Create the TOC
87 *
88 * @access private
89 *
90 * @param bool $metadata Whether or not to show the metadata link
91 * @return string
92 */
93 function showTOC( $metadata ) {
94 global $wgLang;
95 $r = '<ul id="filetoc">
96 <li><a href="#file">' . $wgLang->getNsText( NS_IMAGE ) . '</a></li>
97 <li><a href="#filehistory">' . wfMsgHtml( 'imghistory' ) . '</a></li>
98 <li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . '</a></li>' .
99 ($metadata ? '<li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>' : '') . '
100 </ul>';
101 return $r;
102 }
103
104 /**
105 * Make a table with metadata to be shown in the output page.
106 *
107 * @access private
108 *
109 * @param array $exif The array containing the EXIF data
110 * @return string
111 */
112 function makeMetadataTable( $exif ) {
113 $r = wfMsg( 'metadata-help' ) . "\n\n";
114 $r .= "{| id=mw_metadata class=mw_metadata\n";
115 $visibleFields = $this->visibleMetadataFields();
116 foreach( $exif as $k => $v ) {
117 $tag = strtolower( $k );
118 $msg = wfMsg( "exif-$tag" );
119 $class = "exif-$tag";
120 if( !in_array( $tag, $visibleFields ) ) {
121 $class .= ' collapsable';
122 }
123 $r .= "|- class=\"$class\"\n";
124 $r .= "!| $msg\n";
125 $r .= "|| $v\n";
126 }
127 $r .= '|}';
128 return $r;
129 }
130
131 /**
132 * Get a list of EXIF metadata items which should be displayed when
133 * the metadata table is collapsed.
134 *
135 * @return array of strings
136 * @access private
137 */
138 function visibleMetadataFields() {
139 $fields = array();
140 $lines = explode( "\n", wfMsgForContent( 'metadata-fields' ) );
141 foreach( $lines as $line ) {
142 if( preg_match( '/^\\*\s*(.*?)\s*$/', $line, $matches ) ) {
143 $fields[] = $matches[1];
144 }
145 }
146 return $fields;
147 }
148
149 /**
150 * Overloading Article's getContent method.
151 * Omit noarticletext if sharedupload
152 *
153 * @param $noredir If true, do not follow redirects
154 */
155 function getContent( $noredir )
156 {
157 if ( $this->img && $this->img->fromSharedDirectory && 0 == $this->getID() ) {
158 return '';
159 }
160 return Article::getContent( $noredir );
161 }
162
163 function openShowImage() {
164 global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgUseImageResize;
165
166 $full_url = $this->img->getURL();
167 $anchoropen = '';
168 $anchorclose = '';
169
170 if( $wgUser->getOption( 'imagesize' ) == '' ) {
171 $sizeSel = User::getDefaultOption( 'imagesize' );
172 } else {
173 $sizeSel = intval( $wgUser->getOption( 'imagesize' ) );
174 }
175 if( !isset( $wgImageLimits[$sizeSel] ) ) {
176 $sizeSel = User::getDefaultOption( 'imagesize' );
177 }
178 $max = $wgImageLimits[$sizeSel];
179 $maxWidth = $max[0];
180 $maxHeight = $max[1];
181 $sk = $wgUser->getSkin();
182
183 if ( $this->img->exists() ) {
184 # image
185 $width = $this->img->getWidth();
186 $height = $this->img->getHeight();
187 $showLink = false;
188
189 if ( $this->img->allowInlineDisplay() and $width and $height) {
190 # image
191
192 # "Download high res version" link below the image
193 $msg = wfMsgHtml('showbigimage', $width, $height, intval( $this->img->getSize()/1024 ) );
194
195 # We'll show a thumbnail of this image
196 if ( $width > $maxWidth || $height > $maxHeight ) {
197 # Calculate the thumbnail size.
198 # First case, the limiting factor is the width, not the height.
199 if ( $width / $height >= $maxWidth / $maxHeight ) {
200 $height = round( $height * $maxWidth / $width);
201 $width = $maxWidth;
202 # Note that $height <= $maxHeight now.
203 } else {
204 $newwidth = floor( $width * $maxHeight / $height);
205 $height = round( $height * $newwidth / $width );
206 $width = $newwidth;
207 # Note that $height <= $maxHeight now, but might not be identical
208 # because of rounding.
209 }
210
211 if( $wgUseImageResize ) {
212 $thumbnail = $this->img->getThumbnail( $width );
213 if ( $thumbnail == null ) {
214 $url = $this->img->getViewURL();
215 } else {
216 $url = $thumbnail->getURL();
217 }
218 } else {
219 # No resize ability? Show the full image, but scale
220 # it down in the browser so it fits on the page.
221 $url = $this->img->getViewURL();
222 }
223 $anchoropen = "<a href=\"{$full_url}\">";
224 $anchorclose = "</a><br />";
225 if( $this->img->mustRender() ) {
226 $showLink = true;
227 } else {
228 $anchorclose .= "\n$anchoropen{$msg}</a>";
229 }
230 } else {
231 $url = $this->img->getViewURL();
232 $showLink = true;
233 }
234 $wgOut->addHTML( '<div class="fullImageLink" id="file">' . $anchoropen .
235 "<img border=\"0\" src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" alt=\"" .
236 htmlspecialchars( $wgRequest->getVal( 'image' ) ).'" />' . $anchorclose . '</div>' );
237 } else {
238 #if direct link is allowed but it's not a renderable image, show an icon.
239 if ($this->img->isSafeFile()) {
240 $icon= $this->img->iconThumb();
241
242 $wgOut->addHTML( '<div class="fullImageLink" id="file"><a href="' . $full_url . '">' .
243 $icon->toHtml() .
244 '</a></div>' );
245 }
246
247 $showLink = true;
248 }
249
250
251 if ($showLink) {
252 $filename = wfEscapeWikiText( $this->img->getName() );
253 $info = wfMsg( 'fileinfo',
254 ceil($this->img->getSize()/1024.0),
255 $this->img->getMimeType() );
256
257 if (!$this->img->isSafeFile()) {
258 $warning = wfMsg( 'mediawarning' );
259 $wgOut->addWikiText( <<<END
260 <div class="fullMedia">
261 <span class="dangerousLink">[[Media:$filename|$filename]]</span>
262 <span class="fileInfo"> ($info)</span>
263 </div>
264
265 <div class="mediaWarning">$warning</div>
266 END
267 );
268 } else {
269 $wgOut->addWikiText( <<<END
270 <div class="fullMedia">
271 [[Media:$filename|$filename]] <span class="fileInfo"> ($info)</span>
272 </div>
273 END
274 );
275 }
276 }
277
278 if($this->img->fromSharedDirectory) {
279 $this->printSharedImageText();
280 }
281 } else {
282 # Image does not exist
283
284 $title = Title::makeTitle( NS_SPECIAL, 'Upload' );
285 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),
286 'wpDestFile=' . urlencode( $this->img->getName() ) );
287 $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
288 }
289 }
290
291 function printSharedImageText() {
292 global $wgRepositoryBaseUrl, $wgFetchCommonsDescriptions, $wgOut, $wgUser;
293
294 $url = $wgRepositoryBaseUrl . urlencode($this->mTitle->getDBkey());
295 $sharedtext = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml("sharedupload");
296 if ($wgRepositoryBaseUrl && !$wgFetchCommonsDescriptions) {
297
298 $sk = $wgUser->getSkin();
299 $title = Title::makeTitle( NS_SPECIAL, 'Upload' );
300 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('shareduploadwiki-linktext'),
301 array( 'wpDestFile' => urlencode( $this->img->getName() )));
302 $sharedtext .= " " . wfMsgWikiHtml('shareduploadwiki', $link);
303 }
304 $sharedtext .= "</div>";
305 $wgOut->addHTML($sharedtext);
306
307 if ($wgRepositoryBaseUrl && $wgFetchCommonsDescriptions) {
308 require_once("HttpFunctions.php");
309 $ur = ini_set('allow_url_fopen', true);
310 $text = wfGetHTTP($url . '?action=render');
311 ini_set('allow_url_fopen', $ur);
312 if ($text)
313 $this->mExtraDescription = $text;
314 }
315 }
316
317 function getUploadUrl() {
318 global $wgServer;
319 $uploadTitle = Title::makeTitle( NS_SPECIAL, 'Upload' );
320 return $wgServer . $uploadTitle->getLocalUrl( 'wpDestFile=' . urlencode( $this->img->getName() ) );
321 }
322
323
324 function uploadLinksBox()
325 {
326 global $wgUser, $wgOut;
327
328 if ($this->img->fromSharedDirectory)
329 return;
330
331 $sk = $wgUser->getSkin();
332 $wgOut->addHTML( '<br /><ul>' );
333 if( $wgUser->isAllowed( 'reupload' ) ) {
334 $wgOut->addWikiText( "<li>\n<div>". wfMsg( 'uploadnewversion', $this->getUploadUrl() ) ."</div>\n</li>\n" );
335 }
336 $wgOut->addHTML( '<li>' );
337 $wgOut->addHTML( $sk->makeKnownLinkObj( $this->mTitle,
338 wfMsg( 'edit-externally' ), "action=edit&externaledit=true&mode=file" ) );
339 $wgOut->addWikiText( '<div>' . wfMsg('edit-externally-help') . '</div>' );
340 $wgOut->addHTML( '</li></ul>' );
341 }
342
343 function closeShowImage()
344 {
345 # For overloading
346
347 }
348
349 /**
350 * If the page we've just displayed is in the "Image" namespace,
351 * we follow it with an upload history of the image and its usage.
352 */
353 function imageHistory()
354 {
355 global $wgUser, $wgOut, $wgUseExternalEditor;
356
357 $sk = $wgUser->getSkin();
358
359 $line = $this->img->nextHistoryLine();
360
361 if ( $line ) {
362 $list =& new ImageHistoryList( $sk );
363 $s = $list->beginImageHistoryList() .
364 $list->imageHistoryLine( true, wfTimestamp(TS_MW, $line->img_timestamp),
365 $this->mTitle->getDBkey(), $line->img_user,
366 $line->img_user_text, $line->img_size, $line->img_description,
367 $line->img_width, $line->img_height
368 );
369
370 while ( $line = $this->img->nextHistoryLine() ) {
371 $s .= $list->imageHistoryLine( false, $line->img_timestamp,
372 $line->oi_archive_name, $line->img_user,
373 $line->img_user_text, $line->img_size, $line->img_description,
374 $line->img_width, $line->img_height
375 );
376 }
377 $s .= $list->endImageHistoryList();
378 } else { $s=''; }
379 $wgOut->addHTML( $s );
380
381 # Exist check because we don't want to show this on pages where an image
382 # doesn't exist along with the noimage message, that would suck. -ævar
383 if( $wgUseExternalEditor && $this->img->exists() ) {
384 $this->uploadLinksBox();
385 }
386
387 }
388
389 function imageLinks()
390 {
391 global $wgUser, $wgOut;
392
393 $wgOut->addHTML( '<h2 id="filelinks">' . wfMsg( 'imagelinks' ) . "</h2>\n" );
394
395 $dbr =& wfGetDB( DB_SLAVE );
396 $page = $dbr->tableName( 'page' );
397 $imagelinks = $dbr->tableName( 'imagelinks' );
398
399 $sql = "SELECT page_namespace,page_title FROM $imagelinks,$page WHERE il_to=" .
400 $dbr->addQuotes( $this->mTitle->getDBkey() ) . " AND il_from=page_id";
401 $sql = $dbr->limitResult($sql, 500, 0);
402 $res = $dbr->query( $sql, "ImagePage::imageLinks" );
403
404 if ( 0 == $dbr->numRows( $res ) ) {
405 $wgOut->addHtml( '<p>' . wfMsg( "nolinkstoimage" ) . "</p>\n" );
406 return;
407 }
408 $wgOut->addHTML( '<p>' . wfMsg( 'linkstoimage' ) . "</p>\n<ul>" );
409
410 $sk = $wgUser->getSkin();
411 while ( $s = $dbr->fetchObject( $res ) ) {
412 $name = Title::MakeTitle( $s->page_namespace, $s->page_title );
413 $link = $sk->makeKnownLinkObj( $name, "" );
414 $wgOut->addHTML( "<li>{$link}</li>\n" );
415 }
416 $wgOut->addHTML( "</ul>\n" );
417 }
418
419 function delete()
420 {
421 global $wgUser, $wgOut, $wgRequest;
422
423 $confirm = $wgRequest->wasPosted();
424 $image = $wgRequest->getVal( 'image' );
425 $oldimage = $wgRequest->getVal( 'oldimage' );
426
427 # Only sysops can delete images. Previously ordinary users could delete
428 # old revisions, but this is no longer the case.
429 if ( !$wgUser->isAllowed('delete') ) {
430 $wgOut->sysopRequired();
431 return;
432 }
433 if ( $wgUser->isBlocked() ) {
434 return $this->blockedIPpage();
435 }
436 if ( wfReadOnly() ) {
437 $wgOut->readOnlyPage();
438 return;
439 }
440
441 # Better double-check that it hasn't been deleted yet!
442 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
443 if ( ( !is_null( $image ) )
444 && ( '' == trim( $image ) ) ) {
445 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
446 return;
447 }
448
449 $this->img = new Image( $this->mTitle );
450
451 # Deleting old images doesn't require confirmation
452 if ( !is_null( $oldimage ) || $confirm ) {
453 if( $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
454 $this->doDelete();
455 } else {
456 $wgOut->fatalError( wfMsg( 'sessionfailure' ) );
457 }
458 return;
459 }
460
461 if ( !is_null( $image ) ) {
462 $q = '&image=' . urlencode( $image );
463 } else if ( !is_null( $oldimage ) ) {
464 $q = '&oldimage=' . urlencode( $oldimage );
465 } else {
466 $q = '';
467 }
468 return $this->confirmDelete( $q, $wgRequest->getText( 'wpReason' ) );
469 }
470
471 function doDelete() {
472 global $wgOut, $wgUser, $wgRequest, $wgUseSquid, $wgInternalServer;
473 global $wgPostCommitUpdateList;
474
475 $fname = 'ImagePage::doDelete';
476
477 $reason = $wgRequest->getVal( 'wpReason' );
478 $oldimage = $wgRequest->getVal( 'oldimage' );
479
480 $dbw =& wfGetDB( DB_MASTER );
481
482 if ( !is_null( $oldimage ) ) {
483 if ( strlen( $oldimage ) < 16 ) {
484 $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
485 return;
486 }
487 if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
488 $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
489 return;
490 }
491
492 # Invalidate description page cache
493 $this->mTitle->invalidateCache();
494
495 # Squid purging
496 if ( $wgUseSquid ) {
497 $urlArr = array(
498 $wgInternalServer.wfImageArchiveUrl( $oldimage ),
499 $this->mTitle->getInternalURL()
500 );
501 wfPurgeSquidServers($urlArr);
502 }
503 $this->doDeleteOldImage( $oldimage );
504 $dbw->delete( 'oldimage', array( 'oi_archive_name' => $oldimage ) );
505 $deleted = $oldimage;
506 } else {
507 $image = $this->mTitle->getDBkey();
508 $dest = wfImageDir( $image );
509 $archive = wfImageDir( $image );
510
511 # Delete the image file if it exists; due to sync problems
512 # or manual trimming sometimes the file will be missing.
513 $targetFile = "{$dest}/{$image}";
514 if( file_exists( $targetFile ) && ! @unlink( $targetFile ) ) {
515 # If the deletion operation actually failed, bug out:
516 $wgOut->fileDeleteError( $targetFile );
517 return;
518 }
519 $dbw->delete( 'image', array( 'img_name' => $image ) );
520 $res = $dbw->select( 'oldimage', array( 'oi_archive_name' ), array( 'oi_name' => $image ) );
521
522 # Purge archive URLs from the squid
523 $urlArr = Array();
524 while ( $s = $dbw->fetchObject( $res ) ) {
525 $this->doDeleteOldImage( $s->oi_archive_name );
526 $urlArr[] = $wgInternalServer.wfImageArchiveUrl( $s->oi_archive_name );
527 }
528
529 # And also the HTML of all pages using this image
530 $linksTo = $this->img->getLinksTo();
531 if ( $wgUseSquid ) {
532 $u = SquidUpdate::newFromTitles( $linksTo, $urlArr );
533 array_push( $wgPostCommitUpdateList, $u );
534 }
535
536 $dbw->delete( 'oldimage', array( 'oi_name' => $image ) );
537
538 # Image itself is now gone, and database is cleaned.
539 # Now we remove the image description page.
540
541 $article = new Article( $this->mTitle );
542 $article->doDeleteArticle( $reason ); # ignore errors
543
544 # Invalidate parser cache and client cache for pages using this image
545 # This is left until relatively late to reduce lock time
546 Title::touchArray( $linksTo );
547
548 /* Delete thumbnails and refresh image metadata cache */
549 $this->img->purgeCache();
550
551
552 $deleted = $image;
553 }
554
555 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
556 $wgOut->setRobotpolicy( 'noindex,nofollow' );
557
558 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
559 $text = wfMsg( 'deletedtext', $deleted, $loglink );
560
561 $wgOut->addWikiText( $text );
562
563 $wgOut->returnToMain( false, $this->mTitle->getPrefixedText() );
564 }
565
566 function doDeleteOldImage( $oldimage )
567 {
568 global $wgOut;
569
570 $name = substr( $oldimage, 15 );
571 $archive = wfImageArchiveDir( $name );
572
573 # Delete the image if it exists. Sometimes the file will be missing
574 # due to manual intervention or weird sync problems; treat that
575 # condition gracefully and continue to delete the database entry.
576 # Also some records may end up with an empty oi_archive_name field
577 # if the original file was missing when a new upload was made;
578 # don't try to delete the directory then!
579 #
580 $targetFile = "{$archive}/{$oldimage}";
581 if( $oldimage != '' && file_exists( $targetFile ) && !@unlink( $targetFile ) ) {
582 # If we actually have a file and can't delete it, throw an error.
583 $wgOut->fileDeleteError( "{$archive}/{$oldimage}" );
584 } else {
585 # Log the deletion
586 $log = new LogPage( 'delete' );
587 $log->addEntry( 'delete', $this->mTitle, wfMsg('deletedrevision',$oldimage) );
588 }
589 }
590
591 function revert() {
592 global $wgOut, $wgRequest, $wgUser;
593
594 $oldimage = $wgRequest->getText( 'oldimage' );
595 if ( strlen( $oldimage ) < 16 ) {
596 $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
597 return;
598 }
599 if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
600 $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
601 return;
602 }
603
604 if ( wfReadOnly() ) {
605 $wgOut->readOnlyPage();
606 return;
607 }
608 if( $wgUser->isAnon() ) {
609 $wgOut->errorpage( 'uploadnologin', 'uploadnologintext' );
610 return;
611 }
612 if ( ! $this->mTitle->userCanEdit() ) {
613 $wgOut->sysopRequired();
614 return;
615 }
616 if ( $wgUser->isBlocked() ) {
617 return $this->blockedIPpage();
618 }
619 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
620 $wgOut->errorpage( 'internalerror', 'sessionfailure' );
621 return;
622 }
623 $name = substr( $oldimage, 15 );
624
625 $dest = wfImageDir( $name );
626 $archive = wfImageArchiveDir( $name );
627 $curfile = "{$dest}/{$name}";
628
629 if ( ! is_file( $curfile ) ) {
630 $wgOut->fileNotFoundError( htmlspecialchars( $curfile ) );
631 return;
632 }
633 $oldver = wfTimestampNow() . "!{$name}";
634
635 $dbr =& wfGetDB( DB_SLAVE );
636 $size = $dbr->selectField( 'oldimage', 'oi_size', array( 'oi_archive_name' => $oldimage ) );
637
638 if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
639 $wgOut->fileRenameError( $curfile, "${archive}/{$oldver}" );
640 return;
641 }
642 if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) {
643 $wgOut->fileCopyError( "${archive}/{$oldimage}", $curfile );
644 }
645
646 # Record upload and update metadata cache
647 $img = Image::newFromName( $name );
648 $img->recordUpload( $oldver, wfMsg( "reverted" ) );
649
650 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
651 $wgOut->setRobotpolicy( 'noindex,nofollow' );
652 $wgOut->addHTML( wfMsg( 'imagereverted' ) );
653
654 $descTitle = $img->getTitle();
655 $wgOut->returnToMain( false, $descTitle->getPrefixedText() );
656 }
657
658 function blockedIPpage() {
659 require_once( 'EditPage.php' );
660 $edit = new EditPage( $this );
661 return $edit->blockedIPpage();
662 }
663
664 }
665
666 /**
667 * @todo document
668 * @package MediaWiki
669 */
670 class ImageHistoryList {
671 function ImageHistoryList( &$skin ) {
672 $this->skin =& $skin;
673 }
674
675 function beginImageHistoryList() {
676 $s = "\n<h2 id=\"filehistory\">" . wfMsg( 'imghistory' ) . "</h2>\n" .
677 "<p>" . wfMsg( 'imghistlegend' ) . "</p>\n".'<ul class="special">';
678 return $s;
679 }
680
681 function endImageHistoryList() {
682 $s = "</ul>\n";
683 return $s;
684 }
685
686 function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description, $width, $height ) {
687 global $wgUser, $wgLang, $wgTitle;
688
689 $datetime = $wgLang->timeanddate( $timestamp, true );
690 $del = wfMsg( 'deleteimg' );
691 $delall = wfMsg( 'deleteimgcompletely' );
692 $cur = wfMsg( 'cur' );
693
694 if ( $iscur ) {
695 $url = Image::imageUrl( $img );
696 $rlink = $cur;
697 if ( $wgUser->isAllowed('delete') ) {
698 $link = $wgTitle->escapeLocalURL( 'image=' . $wgTitle->getPartialURL() .
699 '&action=delete' );
700 $style = $this->skin->getInternalLinkAttributes( $link, $delall );
701
702 $dlink = '<a href="'.$link.'"'.$style.'>'.$delall.'</a>';
703 } else {
704 $dlink = $del;
705 }
706 } else {
707 $url = htmlspecialchars( wfImageArchiveUrl( $img ) );
708 if( $wgUser->getID() != 0 && $wgTitle->userCanEdit() ) {
709 $token = urlencode( $wgUser->editToken( $img ) );
710 $rlink = $this->skin->makeKnownLinkObj( $wgTitle,
711 wfMsg( 'revertimg' ), 'action=revert&oldimage=' .
712 urlencode( $img ) . "&wpEditToken=$token" );
713 $dlink = $this->skin->makeKnownLinkObj( $wgTitle,
714 $del, 'action=delete&oldimage=' . urlencode( $img ) .
715 "&wpEditToken=$token" );
716 } else {
717 # Having live active links for non-logged in users
718 # means that bots and spiders crawling our site can
719 # inadvertently change content. Baaaad idea.
720 $rlink = wfMsg( 'revertimg' );
721 $dlink = $del;
722 }
723 }
724 if ( 0 == $user ) {
725 $userlink = $usertext;
726 } else {
727 $userlink = $this->skin->makeLinkObj(
728 Title::makeTitle( NS_USER, $usertext ),
729 $usertext );
730 }
731 $nbytes = wfMsg( 'nbytes', $size );
732 $widthheight = wfMsg( 'widthheight', $width, $height );
733 $style = $this->skin->getInternalLinkAttributes( $url, $datetime );
734
735 $s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a> . . {$userlink} . . {$widthheight} ({$nbytes})";
736
737 $s .= $this->skin->commentBlock( $description, $wgTitle );
738 $s .= "</li>\n";
739 return $s;
740 }
741
742 }
743
744
745 ?>