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