Index: trunk/phase3/docs/hooks.txt |
— | — | @@ -238,6 +238,10 @@ |
239 | 239 | This is a list of known events and parameters; please add to it if |
240 | 240 | you're going to add events to the MediaWiki code. |
241 | 241 | |
| 242 | +'AbortAutoblock': Return false to cancel an autoblock. |
| 243 | +$autoblockip: The IP going to be autoblocked. |
| 244 | +$block: The block from which the autoblock is coming. |
| 245 | + |
242 | 246 | 'AbortLogin': Return false to cancel account login. |
243 | 247 | $user: the User object being authenticated against |
244 | 248 | $password: the password being submitted, not yet checked for validity |
Index: trunk/phase3/includes/User.php |
— | — | @@ -1036,7 +1036,6 @@ |
1037 | 1037 | |
1038 | 1038 | # Proxy blocking |
1039 | 1039 | if ( !$this->isAllowed('proxyunbannable') && !in_array( $ip, $wgProxyWhitelist ) ) { |
1040 | | - |
1041 | 1040 | # Local list |
1042 | 1041 | if ( wfIsLocallyBlockedProxy( $ip ) ) { |
1043 | 1042 | $this->mBlockedby = wfMsg( 'proxyblocker' ); |
Index: trunk/phase3/includes/SpecialUserlogin.php |
— | — | @@ -665,14 +665,16 @@ |
666 | 666 | } |
667 | 667 | |
668 | 668 | /** */ |
669 | | - function userNotPrivilegedMessage() { |
| 669 | + function userNotPrivilegedMessage($errors) { |
670 | 670 | global $wgOut; |
671 | 671 | |
672 | | - $wgOut->setPageTitle( wfMsg( 'whitelistacctitle' ) ); |
| 672 | + $wgOut->setPageTitle( wfMsg( 'permissionserrors' ) ); |
673 | 673 | $wgOut->setRobotpolicy( 'noindex,nofollow' ); |
674 | 674 | $wgOut->setArticleRelated( false ); |
675 | 675 | |
676 | | - $wgOut->addWikiMsg( 'whitelistacctext' ); |
| 676 | + $wgOut->addWikitext( $wgOut->formatPermissionsErrorMessage( $errors, 'createaccount' ) ); |
| 677 | + // Stuff that might want to be added at the end. For example, instructions if blocked. |
| 678 | + $wgOut->addWikiMsg( 'cantcreateaccount-nonblock-text' ); |
677 | 679 | |
678 | 680 | $wgOut->returnToMain( false ); |
679 | 681 | } |
— | — | @@ -711,14 +713,16 @@ |
712 | 714 | global $wgUser, $wgOut, $wgAllowRealName, $wgEnableEmail; |
713 | 715 | global $wgCookiePrefix, $wgAuth, $wgLoginLanguageSelector; |
714 | 716 | global $wgAuth, $wgEmailConfirmToEdit; |
| 717 | + |
| 718 | + $titleObj = SpecialPage::getTitleFor( 'Userlogin' ); |
715 | 719 | |
716 | 720 | if ( $this->mType == 'signup' ) { |
717 | | - if ( !$wgUser->isAllowed( 'createaccount' ) ) { |
718 | | - $this->userNotPrivilegedMessage(); |
719 | | - return; |
720 | | - } elseif ( $wgUser->isBlockedFromCreateAccount() ) { |
| 721 | + if ( $wgUser->isBlockedFromCreateAccount() ) { |
721 | 722 | $this->userBlockedMessage(); |
722 | 723 | return; |
| 724 | + } elseif ( count( $permErrors = $titleObj->getUserPermissionsErrors( 'createaccount', $wgUser, true ) )>0 ) { |
| 725 | + $wgOut->showPermissionsErrorPage( $permErrors, 'createaccount' ); |
| 726 | + return; |
723 | 727 | } |
724 | 728 | } |
725 | 729 | |
Index: trunk/phase3/includes/EditPage.php |
— | — | @@ -389,6 +389,7 @@ |
390 | 390 | } |
391 | 391 | |
392 | 392 | $permErrors = $this->mTitle->getUserPermissionsErrors('edit', $wgUser); |
| 393 | + |
393 | 394 | if( !$this->mTitle->exists() ) { |
394 | 395 | $permErrors = array_merge( $permErrors, |
395 | 396 | wfArrayDiff2( $this->mTitle->getUserPermissionsErrors('create', $wgUser), $permErrors ) ); |
— | — | @@ -414,10 +415,10 @@ |
415 | 416 | } |
416 | 417 | } |
417 | 418 | $permErrors = wfArrayDiff2( $permErrors, $remove ); |
418 | | - |
| 419 | + |
419 | 420 | if ( $permErrors ) { |
420 | 421 | wfDebug( __METHOD__.": User can't edit\n" ); |
421 | | - $this->readOnlyPage( $this->getContent(), true, $permErrors ); |
| 422 | + $this->readOnlyPage( $this->getContent(), true, $permErrors, 'edit' ); |
422 | 423 | wfProfileOut( __METHOD__ ); |
423 | 424 | return; |
424 | 425 | } else { |
— | — | @@ -489,7 +490,7 @@ |
490 | 491 | * Parameters are the same as OutputPage:readOnlyPage() |
491 | 492 | * Redirect to the article page if redlink=1 |
492 | 493 | */ |
493 | | - function readOnlyPage( $source = null, $protected = false, $reasons = array() ) { |
| 494 | + function readOnlyPage( $source = null, $protected = false, $reasons = array(), $action = null ) { |
494 | 495 | global $wgRequest, $wgOut; |
495 | 496 | if ( $wgRequest->getBool( 'redlink' ) ) { |
496 | 497 | // The edit page was reached via a red link. |
— | — | @@ -497,7 +498,7 @@ |
498 | 499 | // they really want a permission error. |
499 | 500 | $wgOut->redirect( $this->mTitle->getFullUrl() ); |
500 | 501 | } else { |
501 | | - $wgOut->readOnlyPage( $source, $protected, $reasons ); |
| 502 | + $wgOut->readOnlyPage( $source, $protected, $reasons, $action ); |
502 | 503 | } |
503 | 504 | } |
504 | 505 | |
Index: trunk/phase3/includes/SpecialBlockip.php |
— | — | @@ -342,18 +342,10 @@ |
343 | 343 | if (strlen($expirestr) == 0) { |
344 | 344 | return array('ipb_expiry_invalid'); |
345 | 345 | } |
346 | | - |
347 | | - if ( $expirestr == 'infinite' || $expirestr == 'indefinite' ) { |
348 | | - $expiry = Block::infinity(); |
349 | | - } else { |
350 | | - # Convert GNU-style date, on error returns -1 for PHP <5.1 and false for PHP >=5.1 |
351 | | - $expiry = strtotime( $expirestr ); |
352 | | - |
353 | | - if ( $expiry < 0 || $expiry === false ) { |
354 | | - return array('ipb_expiry_invalid'); |
355 | | - } |
356 | | - |
357 | | - $expiry = wfTimestamp( TS_MW, $expiry ); |
| 346 | + |
| 347 | + if ( false === ($expiry = Block::parseExpiryInput( $expirestr )) ) { |
| 348 | + // Bad expiry. |
| 349 | + return array('ipb_expiry_invalid'); |
358 | 350 | } |
359 | 351 | |
360 | 352 | # Create block |
Index: trunk/phase3/includes/OutputPage.php |
— | — | @@ -960,7 +960,7 @@ |
961 | 961 | * |
962 | 962 | * @param array $errors Error message keys |
963 | 963 | */ |
964 | | - public function showPermissionsErrorPage( $errors ) |
| 964 | + public function showPermissionsErrorPage( $errors, $action = null ) |
965 | 965 | { |
966 | 966 | global $wgTitle; |
967 | 967 | |
— | — | @@ -973,7 +973,7 @@ |
974 | 974 | $this->enableClientCache( false ); |
975 | 975 | $this->mRedirect = ''; |
976 | 976 | $this->mBodytext = ''; |
977 | | - $this->addWikiText( $this->formatPermissionsErrorMessage( $errors ) ); |
| 977 | + $this->addWikiText( $this->formatPermissionsErrorMessage( $errors, $action ) ); |
978 | 978 | } |
979 | 979 | |
980 | 980 | /** @deprecated */ |
— | — | @@ -1096,8 +1096,14 @@ |
1097 | 1097 | * @param array $errors An array of arrays returned by Title::getUserPermissionsErrors |
1098 | 1098 | * @return string The wikitext error-messages, formatted into a list. |
1099 | 1099 | */ |
1100 | | - public function formatPermissionsErrorMessage( $errors ) { |
1101 | | - $text = wfMsgNoTrans( 'permissionserrorstext', count( $errors ) ) . "\n\n"; |
| 1100 | + public function formatPermissionsErrorMessage( $errors, $action = null ) { |
| 1101 | + if ($action == null) { |
| 1102 | + $text = wfMsgNoTrans( 'permissionserrorstext', count($errors)). "\n\n"; |
| 1103 | + } else { |
| 1104 | + $action_desc = wfMsg( "right-$action" ); |
| 1105 | + $action_desc[0] = strtolower($action_desc[0]); |
| 1106 | + $text = wfMsgNoTrans( 'permissionserrorstext-withaction', count($errors), $action_desc ) . "\n\n"; |
| 1107 | + } |
1102 | 1108 | |
1103 | 1109 | if (count( $errors ) > 1) { |
1104 | 1110 | $text .= '<ul class="permissions-errors">' . "\n"; |
— | — | @@ -1135,7 +1141,7 @@ |
1136 | 1142 | * @param bool $protected Is this a permissions error? |
1137 | 1143 | * @param array $reasons List of reasons for this error, as returned by Title::getUserPermissionsErrors(). |
1138 | 1144 | */ |
1139 | | - public function readOnlyPage( $source = null, $protected = false, $reasons = array() ) { |
| 1145 | + public function readOnlyPage( $source = null, $protected = false, $reasons = array(), $action = null ) { |
1140 | 1146 | global $wgUser, $wgTitle; |
1141 | 1147 | $skin = $wgUser->getSkin(); |
1142 | 1148 | |
— | — | @@ -1156,7 +1162,7 @@ |
1157 | 1163 | } else { |
1158 | 1164 | $this->setPageTitle( wfMsg( 'badaccess' ) ); |
1159 | 1165 | } |
1160 | | - $this->addWikiText( $this->formatPermissionsErrorMessage( $reasons ) ); |
| 1166 | + $this->addWikiText( $this->formatPermissionsErrorMessage( $reasons, $action ) ); |
1161 | 1167 | } else { |
1162 | 1168 | // Wiki is read only |
1163 | 1169 | $this->setPageTitle( wfMsg( 'readonly' ) ); |
Index: trunk/phase3/includes/SpecialIpblocklist.php |
— | — | @@ -327,12 +327,7 @@ |
328 | 328 | $formattedTime = $wgLang->timeanddate( $block->mTimestamp, true ); |
329 | 329 | |
330 | 330 | $properties = array(); |
331 | | - if ( $block->mExpiry === "" || $block->mExpiry === Block::infinity() ) { |
332 | | - $properties[] = $msg['infiniteblock']; |
333 | | - } else { |
334 | | - $properties[] = wfMsgReplaceArgs( $msg['expiringblock'], |
335 | | - array( $wgLang->timeanddate( $block->mExpiry, true ) ) ); |
336 | | - } |
| 331 | + $properties[] = Block::formatExpiry( $block->mExpiry ); |
337 | 332 | if ( $block->mAnonOnly ) { |
338 | 333 | $properties[] = $msg['anononlyblock']; |
339 | 334 | } |
Index: trunk/phase3/includes/Title.php |
— | — | @@ -1158,8 +1158,9 @@ |
1159 | 1159 | else if ($result === false ) |
1160 | 1160 | $errors[] = array('badaccess-group0'); # a generic "We don't want them to do that" |
1161 | 1161 | } |
1162 | | - |
1163 | | - if( NS_SPECIAL == $this->mNamespace ) { |
| 1162 | + |
| 1163 | + $specialOKActions = array( 'createaccount', 'execute' ); |
| 1164 | + if( NS_SPECIAL == $this->mNamespace && !in_array( $action, $specialOKActions) ) { |
1164 | 1165 | $errors[] = array('ns-specialprotected'); |
1165 | 1166 | } |
1166 | 1167 | |
Index: trunk/phase3/includes/Block.php |
— | — | @@ -486,6 +486,12 @@ |
487 | 487 | wfDebug( " No match\n" ); |
488 | 488 | } |
489 | 489 | } |
| 490 | + |
| 491 | + ## Allow hooks to cancel the autoblock. |
| 492 | + if (!wfRunHooks( 'AbortAutoblock', array( $autoblockip, &$this ) )) { |
| 493 | + wfDebug( "Autoblock aborted by hook." ); |
| 494 | + return false; |
| 495 | + } |
490 | 496 | |
491 | 497 | # It's okay to autoblock. Go ahead and create/insert the block. |
492 | 498 | |
— | — | @@ -704,5 +710,48 @@ |
705 | 711 | return $infinity; |
706 | 712 | */ |
707 | 713 | } |
| 714 | + |
| 715 | + /** |
| 716 | + * Convert a DB-encoded expiry into a real string that humans can read. |
| 717 | + */ |
| 718 | + static function formatExpiry( $encoded_expiry ) { |
| 719 | + |
| 720 | + static $msg = null; |
| 721 | + |
| 722 | + if( is_null( $msg ) ) { |
| 723 | + $msg = array(); |
| 724 | + $keys = array( 'infiniteblock', 'expiringblock' ); |
| 725 | + foreach( $keys as $key ) { |
| 726 | + $msg[$key] = wfMsgHtml( $key ); |
| 727 | + } |
| 728 | + } |
| 729 | + |
| 730 | + $expiry = Block::decodeExpiry( $encoded_expiry ); |
| 731 | + if ($expiry == 'infinity') { |
| 732 | + $expirystr = $msg['infiniteblock']; |
| 733 | + } else { |
| 734 | + global $wgLang; |
| 735 | + $expiretimestr = $wgLang->timeanddate( wfTimestamp( TS_MW, $expiry ), true ); |
| 736 | + $expirystr = wfMsgReplaceArgs( $msg['expiringblock'], array($expiretimestr) ); |
| 737 | + } |
708 | 738 | |
| 739 | + return $expirystr; |
| 740 | + } |
| 741 | + |
| 742 | + /** |
| 743 | + * Convert a typed-in expiry time into something we can put into the database. |
| 744 | + */ |
| 745 | + static function parseExpiryInput( $expiry_input ) { |
| 746 | + if ( $expiry_input == 'infinite' || $expiry_input == 'indefinite' ) { |
| 747 | + $expiry = 'infinity'; |
| 748 | + } else { |
| 749 | + $expiry = strtotime( $expiry_input ); |
| 750 | + if ($expiry < 0 || $expiry === false) { |
| 751 | + return false; |
| 752 | + } |
| 753 | + } |
| 754 | + |
| 755 | + return $expiry; |
| 756 | + } |
| 757 | + |
709 | 758 | } |
Index: trunk/phase3/languages/messages/MessagesEn.php |
— | — | @@ -1130,6 +1130,7 @@ |
1131 | 1131 | 'nocreate-loggedin' => 'You do not have permission to create new pages on {{SITENAME}}.', |
1132 | 1132 | 'permissionserrors' => 'Permissions Errors', |
1133 | 1133 | 'permissionserrorstext' => 'You do not have permission to do that, for the following {{PLURAL:$1|reason|reasons}}:', |
| 1134 | +'permissionserrorstext-withaction' => 'You do not have permission to $2, for the following {{PLURAL:$1|reason|reasons}}:', |
1134 | 1135 | 'recreate-deleted-warn' => "'''Warning: You are recreating a page that was previously deleted.''' |
1135 | 1136 | |
1136 | 1137 | You should consider whether it is appropriate to continue editing this page. |
— | — | @@ -1158,6 +1159,7 @@ |
1159 | 1160 | 'cantcreateaccount-text' => "Account creation from this IP address ('''$1''') has been blocked by [[User:$3|$3]]. |
1160 | 1161 | |
1161 | 1162 | The reason given by $3 is ''$2''", |
| 1163 | +'cantcreateaccount-nonblock-text' => '', # do not translate or duplicate this message to other languages |
1162 | 1164 | |
1163 | 1165 | # History pages |
1164 | 1166 | 'viewpagelogs' => 'View logs for this page', |