Index: trunk/phase3/includes/specials/SpecialUndelete.php |
— | — | @@ -569,7 +569,7 @@ |
570 | 570 | */ |
571 | 571 | class UndeleteForm { |
572 | 572 | var $mAction, $mTarget, $mTimestamp, $mRestore, $mInvert, $mTargetObj; |
573 | | - var $mTargetTimestamp, $mAllowed, $mComment; |
| 573 | + var $mTargetTimestamp, $mAllowed, $mComment, $mToken; |
574 | 574 | |
575 | 575 | function UndeleteForm( $request, $par = "" ) { |
576 | 576 | global $wgUser; |
— | — | @@ -588,6 +588,7 @@ |
589 | 589 | $this->mDiff = $request->getCheck( 'diff' ); |
590 | 590 | $this->mComment = $request->getText( 'wpComment' ); |
591 | 591 | $this->mUnsuppress = $request->getVal( 'wpUnsuppress' ) && $wgUser->isAllowed( 'suppressrevision' ); |
| 592 | + $this->mToken = $request->getVal( 'token' ); |
592 | 593 | |
593 | 594 | if( $par != "" ) { |
594 | 595 | $this->mTarget = $par; |
— | — | @@ -654,6 +655,9 @@ |
655 | 656 | if( !$file->userCan( File::DELETED_FILE ) ) { |
656 | 657 | $wgOut->permissionRequired( 'suppressrevision' ); |
657 | 658 | return false; |
| 659 | + } elseif ( !$wgUser->matchEditToken( $this->mToken, $this->mFile ) ) { |
| 660 | + $this->showFileConfirmationForm( $this->mFile ); |
| 661 | + return false; |
658 | 662 | } else { |
659 | 663 | return $this->showFile( $this->mFile ); |
660 | 664 | } |
— | — | @@ -887,6 +891,29 @@ |
888 | 892 | } |
889 | 893 | |
890 | 894 | /** |
| 895 | + * Show a form confirming whether a tokenless user really wants to see a file |
| 896 | + */ |
| 897 | + private function showFileConfirmationForm( $key ) { |
| 898 | + global $wgOut, $wgUser, $wgLang; |
| 899 | + $file = new ArchivedFile( $this->mTargetObj, '', $this->mFile ); |
| 900 | + $wgOut->addWikiMsg( 'undelete-show-file-confirm', |
| 901 | + $this->mTargetObj->getText(), |
| 902 | + $wgLang->timeanddate( $file->getTimestamp() ) ); |
| 903 | + $wgOut->addHTML( |
| 904 | + Xml::openElement( 'form', array( |
| 905 | + 'method' => 'POST', |
| 906 | + 'action' => SpecialPage::getTitleFor( 'Undelete' )->getLocalUrl( |
| 907 | + 'target=' . urlencode( $this->mTarget ) . |
| 908 | + '&file=' . urlencode( $key ) . |
| 909 | + '&token=' . urlencode( $wgUser->editToken( $key ) ) ) |
| 910 | + ) |
| 911 | + ) . |
| 912 | + Xml::submitButton( wfMsg( 'undelete-show-file-submit' ) ) . |
| 913 | + '</form>' |
| 914 | + ); |
| 915 | + } |
| 916 | + |
| 917 | + /** |
891 | 918 | * Show a deleted file version requested by the visitor. |
892 | 919 | */ |
893 | 920 | private function showFile( $key ) { |
— | — | @@ -1194,13 +1221,15 @@ |
1195 | 1222 | * @return string |
1196 | 1223 | */ |
1197 | 1224 | function getFileLink( $file, $titleObj, $ts, $key, $sk ) { |
1198 | | - global $wgLang; |
| 1225 | + global $wgLang, $wgUser; |
1199 | 1226 | |
1200 | 1227 | if( !$file->userCan(File::DELETED_FILE) ) { |
1201 | 1228 | return '<span class="history-deleted">' . $wgLang->timeanddate( $ts, true ) . '</span>'; |
1202 | 1229 | } else { |
1203 | 1230 | $link = $sk->makeKnownLinkObj( $titleObj, $wgLang->timeanddate( $ts, true ), |
1204 | | - "target=".$this->mTargetObj->getPrefixedUrl()."&file=$key" ); |
| 1231 | + "target=".$this->mTargetObj->getPrefixedUrl(). |
| 1232 | + "&file=$key" . |
| 1233 | + "&token=" . urlencode( $wgUser->editToken( $key ) ) ); |
1205 | 1234 | if( $file->isDeleted(File::DELETED_FILE) ) |
1206 | 1235 | $link = '<span class="history-deleted">' . $link . '</span>'; |
1207 | 1236 | return $link; |
Index: trunk/phase3/img_auth.php |
— | — | @@ -17,6 +17,12 @@ |
18 | 18 | wfProfileIn( 'img_auth.php' ); |
19 | 19 | require_once( dirname( __FILE__ ) . '/includes/StreamFile.php' ); |
20 | 20 | |
| 21 | +$perms = User::getGroupPermissions( array( '*' ) ); |
| 22 | +if ( in_array( 'read', $perms, true ) ) { |
| 23 | + wfDebugLog( 'img_auth', 'Public wiki' ); |
| 24 | + wfPublicError(); |
| 25 | +} |
| 26 | + |
21 | 27 | // Extract path and image information |
22 | 28 | if( !isset( $_SERVER['PATH_INFO'] ) ) { |
23 | 29 | wfDebugLog( 'img_auth', 'Missing PATH_INFO' ); |
— | — | @@ -88,3 +94,25 @@ |
89 | 95 | wfLogProfilingData(); |
90 | 96 | exit(); |
91 | 97 | } |
| 98 | + |
| 99 | +/** |
| 100 | + * Show a 403 error for use when the wiki is public |
| 101 | + */ |
| 102 | +function wfPublicError() { |
| 103 | + header( 'HTTP/1.0 403 Forbidden' ); |
| 104 | + header( 'Content-Type: text/html; charset=utf-8' ); |
| 105 | + echo <<<ENDS |
| 106 | +<html> |
| 107 | +<body> |
| 108 | +<h1>Access Denied</h1> |
| 109 | +<p>The function of img_auth.php is to output files from a private wiki. This wiki |
| 110 | +is configured as a public wiki. For optimal security, img_auth.php is disabled in |
| 111 | +this case. |
| 112 | +</p> |
| 113 | +</body> |
| 114 | +</html> |
| 115 | +ENDS; |
| 116 | + wfLogProfilingData(); |
| 117 | + exit; |
| 118 | +} |
| 119 | + |
Index: trunk/phase3/languages/messages/MessagesEn.php |
— | — | @@ -2491,6 +2491,8 @@ |
2492 | 2492 | 'undelete-error-long' => 'Errors were encountered while undeleting the file: |
2493 | 2493 | |
2494 | 2494 | $1', |
| 2495 | +'undelete-show-file-confirm' => 'Are you sure you want to view a deleted revision of the file "<nowiki>$1</nowiki>" from $2?', |
| 2496 | +'undelete-show-file-submit' => 'Yes', |
2495 | 2497 | |
2496 | 2498 | # Namespace form on various pages |
2497 | 2499 | 'namespace' => 'Namespace:', |