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