1ffa52db240f2a50040417e26dc7d7b590167d5d
[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 $wgUseExternalEditor, $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 {
165 global $wgOut, $wgUser, $wgImageLimits, $wgRequest,
166 $wgUseImageResize, $wgRepositoryBaseUrl,
167 $wgUseExternalEditor, $wgServer, $wgFetchCommonsDescriptions;
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 if ( $width > $maxWidth ) {
197 $height = floor( $height * $maxWidth / $width );
198 $width = $maxWidth;
199 }
200 if ( $height > $maxHeight ) {
201 $width = floor( $width * $maxHeight / $height );
202 $height = $maxHeight;
203 }
204 if ( $width != $this->img->getWidth() || $height != $this->img->getHeight() ) {
205 if( $wgUseImageResize ) {
206 $thumbnail = $this->img->getThumbnail( $width );
207 if ( $thumbnail == null ) {
208 $url = $this->img->getViewURL();
209 } else {
210 $url = $thumbnail->getURL();
211 }
212 } else {
213 # No resize ability? Show the full image, but scale
214 # it down in the browser so it fits on the page.
215 $url = $this->img->getViewURL();
216 }
217 $anchoropen = "<a href=\"{$full_url}\">";
218 $anchorclose = "</a><br />";
219 if( $this->img->mustRender() ) {
220 $showLink = true;
221 } else {
222 $anchorclose .= "\n$anchoropen{$msg}</a>";
223 }
224 } else {
225 $url = $this->img->getViewURL();
226 $showLink = true;
227 }
228 $wgOut->addHTML( '<div class="fullImageLink" id="file">' . $anchoropen .
229 "<img border=\"0\" src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" alt=\"" .
230 htmlspecialchars( $wgRequest->getVal( 'image' ) ).'" />' . $anchorclose . '</div>' );
231 } else {
232 #if direct link is allowed but it's not a renderable image, show an icon.
233 if ($this->img->isSafeFile()) {
234 $icon= $this->img->iconThumb();
235
236 $wgOut->addHTML( '<div class="fullImageLink" id="file"><a href="' . $full_url . '">' .
237 $icon->toHtml() .
238 '</a></div>' );
239 }
240
241 $showLink = true;
242 }
243
244
245 if ($showLink) {
246 $filename = wfEscapeWikiText( $this->img->getName() );
247 $info = wfMsg( 'fileinfo',
248 ceil($this->img->getSize()/1024.0),
249 $this->img->getMimeType() );
250
251 if (!$this->img->isSafeFile()) {
252 $warning = wfMsg( 'mediawarning' );
253 $wgOut->addWikiText( <<<END
254 <div class="fullMedia">
255 <span class="dangerousLink">[[Media:$filename|$filename]]</span>
256 <span class="fileInfo"> ($info)</span>
257 </div>
258
259 <div class="mediaWarning">$warning</div>
260 END
261 );
262 } else {
263 $wgOut->addWikiText( <<<END
264 <div class="fullMedia">
265 [[Media:$filename|$filename]] <span class="fileInfo"> ($info)</span>
266 </div>
267 END
268 );
269 }
270 }
271
272 if($this->img->fromSharedDirectory) {
273 $this->printSharedImageText();
274 }
275 } else {
276 # Image does not exist
277
278 $title = Title::makeTitle( NS_SPECIAL, 'Upload' );
279 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),
280 'wpDestFile=' . urlencode( $this->img->getName() ) );
281 $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
282 }
283 }
284
285 function printSharedImageText() {
286 global $wgRepositoryBaseUrl, $wgFetchCommonsDescriptions, $wgOut, $wgUser;
287
288 $url = $wgRepositoryBaseUrl . urlencode($this->mTitle->getDBkey());
289 $sharedtext = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml("sharedupload");
290 if ($wgRepositoryBaseUrl && !$wgFetchCommonsDescriptions) {
291
292 $sk = $wgUser->getSkin();
293 $title = Title::makeTitle( NS_SPECIAL, 'Upload' );
294 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('shareduploadwiki-linktext'),
295 array( 'wpDestFile' => urlencode( $this->img->getName() )));
296 $sharedtext .= " " . wfMsgWikiHtml('shareduploadwiki', $link);
297 }
298 $sharedtext .= "</div>";
299 $wgOut->addHTML($sharedtext);
300
301 if ($wgRepositoryBaseUrl && $wgFetchCommonsDescriptions) {
302 require_once("HttpFunctions.php");
303 $ur = ini_set('allow_url_fopen', true);
304 $text = wfGetHTTP($url . '?action=render');
305 ini_set('allow_url_fopen', $ur);
306 if ($text)
307 $this->mExtraDescription = $text;
308 }
309 }
310
311 function getUploadUrl() {
312 global $wgServer;
313 $uploadTitle = Title::makeTitle( NS_SPECIAL, 'Upload' );
314 return $wgServer . $uploadTitle->getLocalUrl( 'wpDestFile=' . urlencode( $this->img->getName() ) );
315 }
316
317
318 function uploadLinksBox()
319 {
320 global $wgUser, $wgOut;
321
322 if ($this->img->fromSharedDirectory)
323 return;
324
325 $sk = $wgUser->getSkin();
326 $wgOut->addHTML( '<br /><ul>' );
327 if( $wgUser->isAllowed( 'reupload' ) ) {
328 $wgOut->addWikiText( "<li>\n<div>". wfMsg( 'uploadnewversion', $this->getUploadUrl() ) ."</div>\n</li>\n" );
329 }
330 $wgOut->addHTML( '<li>' );
331 $wgOut->addHTML( $sk->makeKnownLinkObj( $this->mTitle,
332 wfMsg( 'edit-externally' ), "action=edit&externaledit=true&mode=file" ) );
333 $wgOut->addWikiText( '<div>' . wfMsg('edit-externally-help') . '</div>' );
334 $wgOut->addHTML( '</li></ul>' );
335 }
336
337 function closeShowImage()
338 {
339 # For overloading
340
341 }
342
343 /**
344 * If the page we've just displayed is in the "Image" namespace,
345 * we follow it with an upload history of the image and its usage.
346 */
347 function imageHistory()
348 {
349 global $wgUser, $wgOut, $wgUseExternalEditor;
350
351 $sk = $wgUser->getSkin();
352
353 $line = $this->img->nextHistoryLine();
354
355 if ( $line ) {
356 $list =& new ImageHistoryList( $sk );
357 $s = $list->beginImageHistoryList() .
358 $list->imageHistoryLine( true, wfTimestamp(TS_MW, $line->img_timestamp),
359 $this->mTitle->getDBkey(), $line->img_user,
360 $line->img_user_text, $line->img_size, $line->img_description,
361 $line->img_width, $line->img_height
362 );
363
364 while ( $line = $this->img->nextHistoryLine() ) {
365 $s .= $list->imageHistoryLine( false, $line->img_timestamp,
366 $line->oi_archive_name, $line->img_user,
367 $line->img_user_text, $line->img_size, $line->img_description,
368 $line->img_width, $line->img_height
369 );
370 }
371 $s .= $list->endImageHistoryList();
372 } else { $s=''; }
373 $wgOut->addHTML( $s );
374
375 # Exist check because we don't want to show this on pages where an image
376 # doesn't exist along with the noimage message, that would suck. -ævar
377 if( $wgUseExternalEditor && $this->img->exists() ) {
378 $this->uploadLinksBox();
379 }
380
381 }
382
383 function imageLinks()
384 {
385 global $wgUser, $wgOut;
386
387 $wgOut->addHTML( '<h2 id="filelinks">' . wfMsg( 'imagelinks' ) . "</h2>\n" );
388
389 $dbr =& wfGetDB( DB_SLAVE );
390 $page = $dbr->tableName( 'page' );
391 $imagelinks = $dbr->tableName( 'imagelinks' );
392
393 $sql = "SELECT page_namespace,page_title FROM $imagelinks,$page WHERE il_to=" .
394 $dbr->addQuotes( $this->mTitle->getDBkey() ) . " AND il_from=page_id";
395 $sql = $dbr->limitResult($sql, 500, 0);
396 $res = $dbr->query( $sql, "ImagePage::imageLinks" );
397
398 if ( 0 == $dbr->numRows( $res ) ) {
399 $wgOut->addHtml( '<p>' . wfMsg( "nolinkstoimage" ) . "</p>\n" );
400 return;
401 }
402 $wgOut->addHTML( '<p>' . wfMsg( 'linkstoimage' ) . "</p>\n<ul>" );
403
404 $sk = $wgUser->getSkin();
405 while ( $s = $dbr->fetchObject( $res ) ) {
406 $name = Title::MakeTitle( $s->page_namespace, $s->page_title );
407 $link = $sk->makeKnownLinkObj( $name, "" );
408 $wgOut->addHTML( "<li>{$link}</li>\n" );
409 }
410 $wgOut->addHTML( "</ul>\n" );
411 }
412
413 function delete()
414 {
415 global $wgUser, $wgOut, $wgRequest;
416
417 $confirm = $wgRequest->wasPosted();
418 $image = $wgRequest->getVal( 'image' );
419 $oldimage = $wgRequest->getVal( 'oldimage' );
420
421 # Only sysops can delete images. Previously ordinary users could delete
422 # old revisions, but this is no longer the case.
423 if ( !$wgUser->isAllowed('delete') ) {
424 $wgOut->sysopRequired();
425 return;
426 }
427 if ( $wgUser->isBlocked() ) {
428 return $this->blockedIPpage();
429 }
430 if ( wfReadOnly() ) {
431 $wgOut->readOnlyPage();
432 return;
433 }
434
435 # Better double-check that it hasn't been deleted yet!
436 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
437 if ( ( !is_null( $image ) )
438 && ( '' == trim( $image ) ) ) {
439 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
440 return;
441 }
442
443 $this->img = new Image( $this->mTitle );
444
445 # Deleting old images doesn't require confirmation
446 if ( !is_null( $oldimage ) || $confirm ) {
447 if( $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
448 $this->doDelete();
449 } else {
450 $wgOut->fatalError( wfMsg( 'sessionfailure' ) );
451 }
452 return;
453 }
454
455 if ( !is_null( $image ) ) {
456 $q = '&image=' . urlencode( $image );
457 } else if ( !is_null( $oldimage ) ) {
458 $q = '&oldimage=' . urlencode( $oldimage );
459 } else {
460 $q = '';
461 }
462 return $this->confirmDelete( $q, $wgRequest->getText( 'wpReason' ) );
463 }
464
465 function doDelete()
466 {
467 global $wgOut, $wgUser, $wgContLang, $wgRequest;
468 global $wgUseSquid, $wgInternalServer, $wgPostCommitUpdateList;
469 $fname = 'ImagePage::doDelete';
470
471 $reason = $wgRequest->getVal( 'wpReason' );
472 $oldimage = $wgRequest->getVal( 'oldimage' );
473
474 $dbw =& wfGetDB( DB_MASTER );
475
476 if ( !is_null( $oldimage ) ) {
477 if ( strlen( $oldimage ) < 16 ) {
478 $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
479 return;
480 }
481 if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
482 $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
483 return;
484 }
485
486 # Invalidate description page cache
487 $this->mTitle->invalidateCache();
488
489 # Squid purging
490 if ( $wgUseSquid ) {
491 $urlArr = Array(
492 $wgInternalServer.wfImageArchiveUrl( $oldimage ),
493 $wgInternalServer.$this->mTitle->getFullURL()
494 );
495 wfPurgeSquidServers($urlArr);
496 }
497 $this->doDeleteOldImage( $oldimage );
498 $dbw->delete( 'oldimage', array( 'oi_archive_name' => $oldimage ) );
499 $deleted = $oldimage;
500 } else {
501 $image = $this->mTitle->getDBkey();
502 $dest = wfImageDir( $image );
503 $archive = wfImageDir( $image );
504
505 # Delete the image file if it exists; due to sync problems
506 # or manual trimming sometimes the file will be missing.
507 $targetFile = "{$dest}/{$image}";
508 if( file_exists( $targetFile ) && ! @unlink( $targetFile ) ) {
509 # If the deletion operation actually failed, bug out:
510 $wgOut->fileDeleteError( $targetFile );
511 return;
512 }
513 $dbw->delete( 'image', array( 'img_name' => $image ) );
514 $res = $dbw->select( 'oldimage', array( 'oi_archive_name' ), array( 'oi_name' => $image ) );
515
516 # Purge archive URLs from the squid
517 $urlArr = Array();
518 while ( $s = $dbw->fetchObject( $res ) ) {
519 $this->doDeleteOldImage( $s->oi_archive_name );
520 $urlArr[] = $wgInternalServer.wfImageArchiveUrl( $s->oi_archive_name );
521 }
522
523 # And also the HTML of all pages using this image
524 $linksTo = $this->img->getLinksTo();
525 if ( $wgUseSquid ) {
526 $u = SquidUpdate::newFromTitles( $linksTo, $urlArr );
527 array_push( $wgPostCommitUpdateList, $u );
528 }
529
530 $dbw->delete( 'oldimage', array( 'oi_name' => $image ) );
531
532 # Image itself is now gone, and database is cleaned.
533 # Now we remove the image description page.
534
535 $article = new Article( $this->mTitle );
536 $article->doDeleteArticle( $reason ); # ignore errors
537
538 # Invalidate parser cache and client cache for pages using this image
539 # This is left until relatively late to reduce lock time
540 Title::touchArray( $linksTo );
541
542 /* Delete thumbnails and refresh image metadata cache */
543 $this->img->purgeCache();
544
545
546 $deleted = $image;
547 }
548
549 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
550 $wgOut->setRobotpolicy( 'noindex,nofollow' );
551
552 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
553 $text = wfMsg( 'deletedtext', $deleted, $loglink );
554
555 $wgOut->addWikiText( $text );
556
557 $wgOut->returnToMain( false, $this->mTitle->getPrefixedText() );
558 }
559
560 function doDeleteOldImage( $oldimage )
561 {
562 global $wgOut;
563
564 $name = substr( $oldimage, 15 );
565 $archive = wfImageArchiveDir( $name );
566
567 # Delete the image if it exists. Sometimes the file will be missing
568 # due to manual intervention or weird sync problems; treat that
569 # condition gracefully and continue to delete the database entry.
570 # Also some records may end up with an empty oi_archive_name field
571 # if the original file was missing when a new upload was made;
572 # don't try to delete the directory then!
573 #
574 $targetFile = "{$archive}/{$oldimage}";
575 if( $oldimage != '' && file_exists( $targetFile ) && !@unlink( $targetFile ) ) {
576 # If we actually have a file and can't delete it, throw an error.
577 $wgOut->fileDeleteError( "{$archive}/{$oldimage}" );
578 } else {
579 # Log the deletion
580 $log = new LogPage( 'delete' );
581 $log->addEntry( 'delete', $this->mTitle, wfMsg('deletedrevision',$oldimage) );
582 }
583 }
584
585 function revert()
586 {
587 global $wgOut, $wgRequest, $wgUser;
588 global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
589
590 $oldimage = $wgRequest->getText( 'oldimage' );
591 if ( strlen( $oldimage ) < 16 ) {
592 $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
593 return;
594 }
595 if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
596 $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
597 return;
598 }
599
600 if ( wfReadOnly() ) {
601 $wgOut->readOnlyPage();
602 return;
603 }
604 if( $wgUser->isAnon() ) {
605 $wgOut->errorpage( 'uploadnologin', 'uploadnologintext' );
606 return;
607 }
608 if ( ! $this->mTitle->userCanEdit() ) {
609 $wgOut->sysopRequired();
610 return;
611 }
612 if ( $wgUser->isBlocked() ) {
613 return $this->blockedIPpage();
614 }
615 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
616 $wgOut->errorpage( 'internalerror', 'sessionfailure' );
617 return;
618 }
619 $name = substr( $oldimage, 15 );
620
621 $dest = wfImageDir( $name );
622 $archive = wfImageArchiveDir( $name );
623 $curfile = "{$dest}/{$name}";
624
625 if ( ! is_file( $curfile ) ) {
626 $wgOut->fileNotFoundError( htmlspecialchars( $curfile ) );
627 return;
628 }
629 $oldver = wfTimestampNow() . "!{$name}";
630
631 $dbr =& wfGetDB( DB_SLAVE );
632 $size = $dbr->selectField( 'oldimage', 'oi_size', array( 'oi_archive_name' => $oldimage ) );
633
634 if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
635 $wgOut->fileRenameError( $curfile, "${archive}/{$oldver}" );
636 return;
637 }
638 if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) {
639 $wgOut->fileCopyError( "${archive}/{$oldimage}", $curfile );
640 }
641
642 # Record upload and update metadata cache
643 $img = Image::newFromName( $name );
644 $img->recordUpload( $oldver, wfMsg( "reverted" ) );
645
646 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
647 $wgOut->setRobotpolicy( 'noindex,nofollow' );
648 $wgOut->addHTML( wfMsg( 'imagereverted' ) );
649
650 $descTitle = $img->getTitle();
651 $wgOut->returnToMain( false, $descTitle->getPrefixedText() );
652 }
653
654 function blockedIPpage() {
655 require_once( 'EditPage.php' );
656 $edit = new EditPage( $this );
657 return $edit->blockedIPpage();
658 }
659
660 }
661
662 /**
663 * @todo document
664 * @package MediaWiki
665 */
666 class ImageHistoryList {
667 function ImageHistoryList( &$skin ) {
668 $this->skin =& $skin;
669 }
670
671 function beginImageHistoryList() {
672 $s = "\n<h2 id=\"filehistory\">" . wfMsg( 'imghistory' ) . "</h2>\n" .
673 "<p>" . wfMsg( 'imghistlegend' ) . "</p>\n".'<ul class="special">';
674 return $s;
675 }
676
677 function endImageHistoryList() {
678 $s = "</ul>\n";
679 return $s;
680 }
681
682 function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description, $width, $height ) {
683 global $wgUser, $wgLang, $wgContLang, $wgTitle;
684
685 $datetime = $wgLang->timeanddate( $timestamp, true );
686 $del = wfMsg( 'deleteimg' );
687 $delall = wfMsg( 'deleteimgcompletely' );
688 $cur = wfMsg( 'cur' );
689
690 if ( $iscur ) {
691 $url = Image::imageUrl( $img );
692 $rlink = $cur;
693 if ( $wgUser->isAllowed('delete') ) {
694 $link = $wgTitle->escapeLocalURL( 'image=' . $wgTitle->getPartialURL() .
695 '&action=delete' );
696 $style = $this->skin->getInternalLinkAttributes( $link, $delall );
697
698 $dlink = '<a href="'.$link.'"'.$style.'>'.$delall.'</a>';
699 } else {
700 $dlink = $del;
701 }
702 } else {
703 $url = htmlspecialchars( wfImageArchiveUrl( $img ) );
704 if( $wgUser->getID() != 0 && $wgTitle->userCanEdit() ) {
705 $token = urlencode( $wgUser->editToken( $img ) );
706 $rlink = $this->skin->makeKnownLinkObj( $wgTitle,
707 wfMsg( 'revertimg' ), 'action=revert&oldimage=' .
708 urlencode( $img ) . "&wpEditToken=$token" );
709 $dlink = $this->skin->makeKnownLinkObj( $wgTitle,
710 $del, 'action=delete&oldimage=' . urlencode( $img ) .
711 "&wpEditToken=$token" );
712 } else {
713 # Having live active links for non-logged in users
714 # means that bots and spiders crawling our site can
715 # inadvertently change content. Baaaad idea.
716 $rlink = wfMsg( 'revertimg' );
717 $dlink = $del;
718 }
719 }
720 if ( 0 == $user ) {
721 $userlink = $usertext;
722 } else {
723 $userlink = $this->skin->makeLinkObj(
724 Title::makeTitle( NS_USER, $usertext ),
725 $usertext );
726 }
727 $nbytes = wfMsg( 'nbytes', $size );
728 $widthheight = wfMsg( 'widthheight', $width, $height );
729 $style = $this->skin->getInternalLinkAttributes( $url, $datetime );
730
731 $s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a> . . {$userlink} . . {$widthheight} ({$nbytes})";
732
733 $s .= $this->skin->commentBlock( $description, $wgTitle );
734 $s .= "</li>\n";
735 return $s;
736 }
737
738 }
739
740
741 ?>