* (bug 7405) Make Linker methods static. Patch by Dan Li.
[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 /**
13 * Special handling for image description pages
14 * @package MediaWiki
15 */
16 class ImagePage extends Article {
17
18 /* private */ var $img; // Image object this page is shown for
19 var $mExtraDescription = false;
20
21 /**
22 * Handler for action=render
23 * Include body text only; none of the image extras
24 */
25 function render() {
26 global $wgOut;
27 $wgOut->setArticleBodyOnly( true );
28 $wgOut->addSecondaryWikitext( $this->getContent() );
29 }
30
31 function view() {
32 global $wgOut, $wgShowEXIF;
33
34 $this->img = new Image( $this->mTitle );
35
36 if( $this->mTitle->getNamespace() == NS_IMAGE ) {
37 if ($wgShowEXIF && $this->img->exists()) {
38 $exif = $this->img->getExifData();
39 $showmeta = count($exif) ? true : false;
40 } else {
41 $exif = false;
42 $showmeta = false;
43 }
44
45 if ($this->img->exists())
46 $wgOut->addHTML($this->showTOC($showmeta));
47
48 $this->openShowImage();
49
50 # No need to display noarticletext, we use our own message, output in openShowImage()
51 if( $this->getID() ) {
52 Article::view();
53 } else {
54 # Just need to set the right headers
55 $wgOut->setArticleFlag( true );
56 $wgOut->setRobotpolicy( 'index,follow' );
57 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
58 $this->viewUpdates();
59 }
60
61 # Show shared description, if needed
62 if( $this->mExtraDescription ) {
63 $fol = wfMsg( 'shareddescriptionfollows' );
64 if( $fol != '-' ) {
65 $wgOut->addWikiText( $fol );
66 }
67 $wgOut->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription . '</div>' );
68 }
69
70 $this->closeShowImage();
71 $this->imageHistory();
72 $this->imageLinks();
73 if( $exif ) {
74 global $wgStylePath, $wgStyleVersion;
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?wgStyleVersion\"></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, $wgLang;
167 global $wgUseImageResize, $wgGenerateThumbnailOnParse;
168
169 $full_url = $this->img->getURL();
170 $anchoropen = '';
171 $anchorclose = '';
172
173 if( $wgUser->getOption( 'imagesize' ) == '' ) {
174 $sizeSel = User::getDefaultOption( 'imagesize' );
175 } else {
176 $sizeSel = intval( $wgUser->getOption( 'imagesize' ) );
177 }
178 if( !isset( $wgImageLimits[$sizeSel] ) ) {
179 $sizeSel = User::getDefaultOption( 'imagesize' );
180 }
181 $max = $wgImageLimits[$sizeSel];
182 $maxWidth = $max[0];
183 $maxHeight = $max[1];
184
185 if ( $this->img->exists() ) {
186 # image
187 $page = $wgRequest->getIntOrNull( 'page' );
188 if ( ! is_null( $page ) ) {
189 $this->img->selectPage( $page );
190 } else {
191 $page = 1;
192 }
193 $width = $this->img->getWidth();
194 $height = $this->img->getHeight();
195 $showLink = false;
196
197 if ( $this->img->allowInlineDisplay() and $width and $height) {
198 # image
199
200 # "Download high res version" link below the image
201 $msg = wfMsgHtml('showbigimage', $width, $height, intval( $this->img->getSize()/1024 ) );
202
203 # We'll show a thumbnail of this image
204 if ( $width > $maxWidth || $height > $maxHeight ) {
205 # Calculate the thumbnail size.
206 # First case, the limiting factor is the width, not the height.
207 if ( $width / $height >= $maxWidth / $maxHeight ) {
208 $height = round( $height * $maxWidth / $width);
209 $width = $maxWidth;
210 # Note that $height <= $maxHeight now.
211 } else {
212 $newwidth = floor( $width * $maxHeight / $height);
213 $height = round( $height * $newwidth / $width );
214 $width = $newwidth;
215 # Note that $height <= $maxHeight now, but might not be identical
216 # because of rounding.
217 }
218
219 if( $wgUseImageResize ) {
220 $thumbnail = $this->img->getThumbnail( $width, -1, $wgGenerateThumbnailOnParse );
221 if ( $thumbnail == null ) {
222 $url = $this->img->getViewURL();
223 } else {
224 $url = $thumbnail->getURL();
225 }
226 } else {
227 # No resize ability? Show the full image, but scale
228 # it down in the browser so it fits on the page.
229 $url = $this->img->getViewURL();
230 }
231 $anchoropen = "<a href=\"{$full_url}\">";
232 $anchorclose = "</a><br />";
233 if( $this->img->mustRender() ) {
234 $showLink = true;
235 } else {
236 $anchorclose .= "\n$anchoropen{$msg}</a>";
237 }
238 } else {
239 $url = $this->img->getViewURL();
240 $showLink = true;
241 }
242
243 if ( $this->img->isMultipage() ) {
244 $wgOut->addHTML( '<table class="multipageimage"><tr><td>' );
245 }
246
247 $wgOut->addHTML( '<div class="fullImageLink" id="file">' . $anchoropen .
248 "<img border=\"0\" src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" alt=\"" .
249 htmlspecialchars( $wgRequest->getVal( 'image' ) ).'" />' . $anchorclose . '</div>' );
250
251 if ( $this->img->isMultipage() ) {
252 $count = $this->img->pageCount();
253
254 if ( $page > 1 ) {
255 $label = $wgOut->parse( wfMsg( 'imgmultipageprev' ), false );
256 $link = Linker::makeLinkObj( $this->mTitle, $label, 'page='. ($page-1) );
257 $this->img->selectPage( $page - 1 );
258 $thumb1 = Linker::makeThumbLinkObj( $this->img, $link, $label, 'none' );
259 } else {
260 $thumb1 = '';
261 }
262
263 if ( $page < $count ) {
264 $label = wfMsg( 'imgmultipagenext' );
265 $this->img->selectPage( $page + 1 );
266 $link = Linker::makeLinkObj( $this->mTitle, $label, 'page='. ($page+1) );
267 $thumb2 = Linker::makeThumbLinkObj( $this->img, $link, $label, 'none' );
268 } else {
269 $thumb2 = '';
270 }
271
272 $select = '<form name="pageselector" action="' . $this->img->getEscapeLocalUrl( '' ) . '" method="GET" onchange="document.pageselector.submit();">' ;
273 $select .= $wgOut->parse( wfMsg( 'imgmultigotopre' ), false ) .
274 ' <select id="pageselector" name="page">';
275 for ( $i=1; $i <= $count; $i++ ) {
276 $select .= Xml::option( $wgLang->formatNum( $i ), $i,
277 $i == $page );
278 }
279 $select .= '</select>' . $wgOut->parse( wfMsg( 'imgmultigotopost' ), false ) .
280 '<input type="submit" value="' .
281 htmlspecialchars( wfMsg( 'imgmultigo' ) ) . '"></form>';
282
283 $wgOut->addHTML( '</td><td><div class="multipageimagenavbox">' .
284 "$select<hr />$thumb1\n$thumb2<br clear=\"all\" /></div></td></tr></table>" );
285 }
286 } else {
287 #if direct link is allowed but it's not a renderable image, show an icon.
288 if ($this->img->isSafeFile()) {
289 $icon= $this->img->iconThumb();
290
291 $wgOut->addHTML( '<div class="fullImageLink" id="file"><a href="' . $full_url . '">' .
292 $icon->toHtml() .
293 '</a></div>' );
294 }
295
296 $showLink = true;
297 }
298
299
300 if ($showLink) {
301 $filename = wfEscapeWikiText( $this->img->getName() );
302 $info = wfMsg( 'fileinfo',
303 ceil($this->img->getSize()/1024.0),
304 $this->img->getMimeType() );
305
306 global $wgContLang;
307 $dirmark = $wgContLang->getDirMark();
308 if (!$this->img->isSafeFile()) {
309 $warning = wfMsg( 'mediawarning' );
310 $wgOut->addWikiText( <<<END
311 <div class="fullMedia">
312 <span class="dangerousLink">[[Media:$filename|$filename]]</span>$dirmark
313 <span class="fileInfo"> ($info)</span>
314 </div>
315
316 <div class="mediaWarning">$warning</div>
317 END
318 );
319 } else {
320 $wgOut->addWikiText( <<<END
321 <div class="fullMedia">
322 [[Media:$filename|$filename]]$dirmark <span class="fileInfo"> ($info)</span>
323 </div>
324 END
325 );
326 }
327 }
328
329 if($this->img->fromSharedDirectory) {
330 $this->printSharedImageText();
331 }
332 } else {
333 # Image does not exist
334
335 $title = SpecialPage::getTitleFor( 'Upload' );
336 $link = Linker::makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),
337 'wpDestFile=' . urlencode( $this->img->getName() ) );
338 $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
339 }
340 }
341
342 function printSharedImageText() {
343 global $wgRepositoryBaseUrl, $wgFetchCommonsDescriptions, $wgOut;
344
345 $url = $wgRepositoryBaseUrl . urlencode($this->mTitle->getDBkey());
346 $sharedtext = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml("sharedupload");
347 if ($wgRepositoryBaseUrl && !$wgFetchCommonsDescriptions) {
348 $title = SpecialPage::getTitleFor( 'Upload' );
349 $link = Linker::makeKnownLinkObj($title, wfMsgHtml('shareduploadwiki-linktext'),
350 array( 'wpDestFile' => urlencode( $this->img->getName() )));
351 $sharedtext .= " " . wfMsgWikiHtml('shareduploadwiki', $link);
352 }
353 $sharedtext .= "</div>";
354 $wgOut->addHTML($sharedtext);
355
356 if ($wgRepositoryBaseUrl && $wgFetchCommonsDescriptions) {
357 $text = Http::get($url . '?action=render');
358 if ($text)
359 $this->mExtraDescription = $text;
360 }
361 }
362
363 function getUploadUrl() {
364 global $wgServer;
365 $uploadTitle = SpecialPage::getTitleFor( 'Upload' );
366 return $wgServer . $uploadTitle->getLocalUrl( 'wpDestFile=' . urlencode( $this->img->getName() ) );
367 }
368
369 /**
370 * Print out the various links at the bottom of the image page, e.g. reupload,
371 * external editing (and instructions link) etc.
372 */
373 function uploadLinksBox() {
374 global $wgUser, $wgOut;
375
376 if( $this->img->fromSharedDirectory )
377 return;
378
379 $wgOut->addHtml( '<br /><ul>' );
380
381 # "Upload a new version of this file" link
382 if( $wgUser->isAllowed( 'reupload' ) ) {
383 $ulink = Linker::makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
384 $wgOut->addHtml( "<li><div>{$ulink}</div></li>" );
385 }
386
387 # External editing link
388 $elink = Linker::makeKnownLinkObj( $this->mTitle, wfMsg( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
389 $wgOut->addHtml( '<li>' . $elink . '<div>' . wfMsgWikiHtml( 'edit-externally-help' ) . '</div></li>' );
390
391 $wgOut->addHtml( '</ul>' );
392 }
393
394 function closeShowImage()
395 {
396 # For overloading
397
398 }
399
400 /**
401 * If the page we've just displayed is in the "Image" namespace,
402 * we follow it with an upload history of the image and its usage.
403 */
404 function imageHistory() {
405 global $wgOut, $wgUseExternalEditor;
406
407 $line = $this->img->nextHistoryLine();
408
409 if ( $line ) {
410 $list = new ImageHistoryList();
411 $s = $list->beginImageHistoryList() .
412 $list->imageHistoryLine( true, wfTimestamp(TS_MW, $line->img_timestamp),
413 $this->mTitle->getDBkey(), $line->img_user,
414 $line->img_user_text, $line->img_size, $line->img_description,
415 $line->img_width, $line->img_height
416 );
417
418 while ( $line = $this->img->nextHistoryLine() ) {
419 $s .= $list->imageHistoryLine( false, $line->img_timestamp,
420 $line->oi_archive_name, $line->img_user,
421 $line->img_user_text, $line->img_size, $line->img_description,
422 $line->img_width, $line->img_height
423 );
424 }
425 $s .= $list->endImageHistoryList();
426 } else { $s=''; }
427 $wgOut->addHTML( $s );
428
429 # Exist check because we don't want to show this on pages where an image
430 # doesn't exist along with the noimage message, that would suck. -ævar
431 if( $wgUseExternalEditor && $this->img->exists() ) {
432 $this->uploadLinksBox();
433 }
434
435 }
436
437 function imageLinks() {
438 global $wgOut;
439
440 $wgOut->addHTML( '<h2 id="filelinks">' . wfMsg( 'imagelinks' ) . "</h2>\n" );
441
442 $dbr =& wfGetDB( DB_SLAVE );
443 $page = $dbr->tableName( 'page' );
444 $imagelinks = $dbr->tableName( 'imagelinks' );
445
446 $sql = "SELECT page_namespace,page_title FROM $imagelinks,$page WHERE il_to=" .
447 $dbr->addQuotes( $this->mTitle->getDBkey() ) . " AND il_from=page_id";
448 $sql = $dbr->limitResult($sql, 500, 0);
449 $res = $dbr->query( $sql, "ImagePage::imageLinks" );
450
451 if ( 0 == $dbr->numRows( $res ) ) {
452 $wgOut->addHtml( '<p>' . wfMsg( "nolinkstoimage" ) . "</p>\n" );
453 return;
454 }
455 $wgOut->addHTML( '<p>' . wfMsg( 'linkstoimage' ) . "</p>\n<ul>" );
456
457 while ( $s = $dbr->fetchObject( $res ) ) {
458 $name = Title::MakeTitle( $s->page_namespace, $s->page_title );
459 $link = Linker::makeKnownLinkObj( $name, "" );
460 $wgOut->addHTML( "<li>{$link}</li>\n" );
461 }
462 $wgOut->addHTML( "</ul>\n" );
463 }
464
465 function delete()
466 {
467 global $wgUser, $wgOut, $wgRequest;
468
469 $confirm = $wgRequest->wasPosted();
470 $reason = $wgRequest->getVal( 'wpReason' );
471 $image = $wgRequest->getVal( 'image' );
472 $oldimage = $wgRequest->getVal( 'oldimage' );
473
474 # Only sysops can delete images. Previously ordinary users could delete
475 # old revisions, but this is no longer the case.
476 if ( !$wgUser->isAllowed('delete') ) {
477 $wgOut->permissionRequired( 'delete' );
478 return;
479 }
480 if ( $wgUser->isBlocked() ) {
481 return $this->blockedIPpage();
482 }
483 if ( wfReadOnly() ) {
484 $wgOut->readOnlyPage();
485 return;
486 }
487
488 # Better double-check that it hasn't been deleted yet!
489 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
490 if ( ( !is_null( $image ) )
491 && ( '' == trim( $image ) ) ) {
492 $wgOut->showFatalError( wfMsg( 'cannotdelete' ) );
493 return;
494 }
495
496 $this->img = new Image( $this->mTitle );
497
498 # Deleting old images doesn't require confirmation
499 if ( !is_null( $oldimage ) || $confirm ) {
500 if( $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
501 $this->doDelete( $reason );
502 } else {
503 $wgOut->showFatalError( wfMsg( 'sessionfailure' ) );
504 }
505 return;
506 }
507
508 if ( !is_null( $image ) ) {
509 $q = '&image=' . urlencode( $image );
510 } else if ( !is_null( $oldimage ) ) {
511 $q = '&oldimage=' . urlencode( $oldimage );
512 } else {
513 $q = '';
514 }
515 return $this->confirmDelete( $q, $wgRequest->getText( 'wpReason' ) );
516 }
517
518 /*
519 * Delete an image.
520 * @param $reason User provided reason for deletion.
521 */
522 function doDelete( $reason ) {
523 global $wgOut, $wgRequest, $wgUseSquid;
524 global $wgPostCommitUpdateList;
525
526 $fname = 'ImagePage::doDelete';
527
528 $oldimage = $wgRequest->getVal( 'oldimage' );
529
530 $dbw =& wfGetDB( DB_MASTER );
531
532 if ( !is_null( $oldimage ) ) {
533 if ( strlen( $oldimage ) < 16 ) {
534 $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
535 return;
536 }
537 if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
538 $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
539 return;
540 }
541 if ( !$this->doDeleteOldImage( $oldimage ) ) {
542 return;
543 }
544 $deleted = $oldimage;
545 } else {
546 $ok = $this->img->delete( $reason );
547 if( !$ok ) {
548 # If the deletion operation actually failed, bug out:
549 $wgOut->showFileDeleteError( $this->img->getName() );
550 return;
551 }
552
553 # Image itself is now gone, and database is cleaned.
554 # Now we remove the image description page.
555
556 $article = new Article( $this->mTitle );
557 $article->doDeleteArticle( $reason ); # ignore errors
558
559 $deleted = $this->img->getName();
560 }
561
562 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
563 $wgOut->setRobotpolicy( 'noindex,nofollow' );
564
565 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
566 $text = wfMsg( 'deletedtext', $deleted, $loglink );
567
568 $wgOut->addWikiText( $text );
569
570 $wgOut->returnToMain( false, $this->mTitle->getPrefixedText() );
571 }
572
573 /**
574 * @return success
575 */
576 function doDeleteOldImage( $oldimage )
577 {
578 global $wgOut;
579
580 $ok = $this->img->deleteOld( $oldimage, '' );
581 if( !$ok ) {
582 # If we actually have a file and can't delete it, throw an error.
583 # Something went awry...
584 $wgOut->showFileDeleteError( "$oldimage" );
585 } else {
586 # Log the deletion
587 $log = new LogPage( 'delete' );
588 $log->addEntry( 'delete', $this->mTitle, wfMsg('deletedrevision',$oldimage) );
589 }
590 return $ok;
591 }
592
593 function revert() {
594 global $wgOut, $wgRequest, $wgUser;
595
596 $oldimage = $wgRequest->getText( 'oldimage' );
597 if ( strlen( $oldimage ) < 16 ) {
598 $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
599 return;
600 }
601 if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
602 $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
603 return;
604 }
605
606 if ( wfReadOnly() ) {
607 $wgOut->readOnlyPage();
608 return;
609 }
610 if( $wgUser->isAnon() ) {
611 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
612 return;
613 }
614 if ( ! $this->mTitle->userCanEdit() ) {
615 $wgOut->readOnlyPage( $this->getContent(), true );
616 return;
617 }
618 if ( $wgUser->isBlocked() ) {
619 return $this->blockedIPpage();
620 }
621 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
622 $wgOut->showErrorPage( '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_dir( $dest ) ) wfMkdirParents( $dest );
632 if ( !is_dir( $archive ) ) wfMkdirParents( $archive );
633
634 if ( ! is_file( $curfile ) ) {
635 $wgOut->showFileNotFoundError( htmlspecialchars( $curfile ) );
636 return;
637 }
638 $oldver = wfTimestampNow() . "!{$name}";
639
640 $dbr =& wfGetDB( DB_SLAVE );
641 $size = $dbr->selectField( 'oldimage', 'oi_size', array( 'oi_archive_name' => $oldimage ) );
642
643 if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
644 $wgOut->showFileRenameError( $curfile, "${archive}/{$oldver}" );
645 return;
646 }
647 if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) {
648 $wgOut->showFileCopyError( "${archive}/{$oldimage}", $curfile );
649 return;
650 }
651
652 # Record upload and update metadata cache
653 $img = Image::newFromName( $name );
654 $img->recordUpload( $oldver, wfMsg( "reverted" ) );
655
656 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
657 $wgOut->setRobotpolicy( 'noindex,nofollow' );
658 $wgOut->addHTML( wfMsg( 'imagereverted' ) );
659
660 $descTitle = $img->getTitle();
661 $wgOut->returnToMain( false, $descTitle->getPrefixedText() );
662 }
663
664 function blockedIPpage() {
665 $edit = new EditPage( $this );
666 return $edit->blockedIPpage();
667 }
668
669 /**
670 * Override handling of action=purge
671 */
672 function doPurge() {
673 $this->img = new Image( $this->mTitle );
674 if( $this->img->exists() ) {
675 wfDebug( "ImagePage::doPurge purging " . $this->img->getName() . "\n" );
676 $update = new HTMLCacheUpdate( $this->mTitle, 'imagelinks' );
677 $update->doUpdate();
678 $this->img->purgeCache();
679 } else {
680 wfDebug( "ImagePage::doPurge no image\n" );
681 }
682 parent::doPurge();
683 }
684
685 }
686
687 /**
688 * @todo document
689 * @package MediaWiki
690 */
691 class ImageHistoryList {
692 function ImageHistoryList() {
693 }
694
695 function beginImageHistoryList() {
696 $s = "\n<h2 id=\"filehistory\">" . wfMsg( 'imghistory' ) . "</h2>\n" .
697 "<p>" . wfMsg( 'imghistlegend' ) . "</p>\n".'<ul class="special">';
698 return $s;
699 }
700
701 function endImageHistoryList() {
702 $s = "</ul>\n";
703 return $s;
704 }
705
706 function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description, $width, $height ) {
707 global $wgUser, $wgLang, $wgTitle, $wgContLang;
708
709 $datetime = $wgLang->timeanddate( $timestamp, true );
710 $del = wfMsg( 'deleteimg' );
711 $delall = wfMsg( 'deleteimgcompletely' );
712 $cur = wfMsg( 'cur' );
713
714 if ( $iscur ) {
715 $url = Image::imageUrl( $img );
716 $rlink = $cur;
717 if ( $wgUser->isAllowed('delete') ) {
718 $dlink = Linker::makeKnownLinkObj( $wgTitle, $delall,
719 'image=' . $wgTitle->getPartialURL() . '&action=delete');
720 } else {
721 $dlink = $del;
722 }
723 } else {
724 $url = htmlspecialchars( wfImageArchiveUrl( $img ) );
725 if( $wgUser->getID() != 0 && $wgTitle->userCanEdit() ) {
726 $token = urlencode( $wgUser->editToken( $img ) );
727 $rlink = Linker::makeKnownLinkObj( $wgTitle,
728 wfMsg( 'revertimg' ), 'action=revert&oldimage=' .
729 urlencode( $img ) . "&wpEditToken=$token" );
730 $dlink = Linker::makeKnownLinkObj( $wgTitle,
731 $del, 'action=delete&oldimage=' . urlencode( $img ) .
732 "&wpEditToken=$token" );
733 } else {
734 # Having live active links for non-logged in users
735 # means that bots and spiders crawling our site can
736 # inadvertently change content. Baaaad idea.
737 $rlink = wfMsg( 'revertimg' );
738 $dlink = $del;
739 }
740 }
741
742 $userlink = Linker::userLink( $user, $usertext ) . Linker::userToolLinks( $user, $usertext );
743 $nbytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
744 $wgLang->formatNum( $size ) );
745 $widthheight = wfMsg( 'widthheight', $width, $height );
746 $style = Linker::getInternalLinkAttributes( $url, $datetime );
747
748 $s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a> . . {$userlink} . . {$widthheight} ({$nbytes})";
749
750 $s .= Linker::commentBlock( $description, $wgTitle );
751 $s .= "</li>\n";
752 return $s;
753 }
754
755 }
756
757
758 ?>