Implement user-is-blocked and wiki-is-read-only as exceptions.
authorHappy-melon <happy-melon@users.mediawiki.org>
Wed, 13 Apr 2011 14:30:55 +0000 (14:30 +0000)
committerHappy-melon <happy-melon@users.mediawiki.org>
Wed, 13 Apr 2011 14:30:55 +0000 (14:30 +0000)
includes/AutoLoader.php
includes/Exception.php
includes/OutputPage.php

index 751a6d6..9ba9d86 100644 (file)
@@ -196,6 +196,7 @@ $wgAutoloadLocalClasses = array(
        'RawPage' => 'includes/RawPage.php',
        'RCCacheEntry' => 'includes/ChangesList.php',
        'RdfMetaData' => 'includes/Metadata.php',
+       'ReadOnlyError' => 'includes/Exception.php',
        'RecentChange' => 'includes/RecentChange.php',
        'RegexlikeReplacer' => 'includes/StringUtils.php',
        'ReplacementArray' => 'includes/StringUtils.php',
@@ -249,6 +250,7 @@ $wgAutoloadLocalClasses = array(
        'User' => 'includes/User.php',
        'UserArray' => 'includes/UserArray.php',
        'UserArrayFromResult' => 'includes/UserArray.php',
+       'UserBlockedError' => 'includes/Exception.php',
        'UserMailer' => 'includes/UserMailer.php',
        'UserRightsProxy' => 'includes/UserRightsProxy.php',
        'ViewCountUpdate' => 'includes/ViewCountUpdate.php',
index ea8986d..ad345a3 100644 (file)
@@ -370,6 +370,56 @@ class PermissionsError extends ErrorPageError {
        }
 }
 
+/**
+ * Show an error when the wiki is locked/read-only and the user tries to do
+ * something that requires write access
+ */
+class ReadOnlyError extends ErrorPageError {
+       public function __construct(){
+               parent::__construct(
+                       'readonly',
+                       'readonlytext',
+                       wfReadOnlyReason()
+               );
+       }
+}
+
+/**
+ * Show an error when the user tries to do something whilst blocked
+ */
+class UserBlockedError extends ErrorPageError {
+       public function __construct( Block $block ){
+               global $wgLang;
+
+               $blockerUserpage = $block->getBlocker()->getUserPage();
+               $link = "[[{$blockerUserpage->getPrefixedText()}|{$blockerUserpage->getText()}]]";
+
+               $reason = $block->mReason;
+               if( $reason == '' ) {
+                       $reason = wfMsg( 'blockednoreason' );
+               }
+
+               /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
+                * This could be a username, an IP range, or a single IP. */
+               $intended = $block->getTarget();
+
+               parent::__construct(
+                       'blockedtitle',
+                       $block->mAuto ? 'autoblocketext' : 'blockedtext',
+                       array(
+                               $link,
+                               $reason,
+                               wfGetIP(),
+                               $block->getBlocker()->getName(),
+                               $block->getId(),
+                               $wgLang->formatExpiry( $block->mExpiry ),
+                               $intended,
+                               $wgLang->timeanddate( wfTimestamp( TS_MW, $block->mTimestamp ), true )
+                       )
+               );
+       }
+}
+
 /**
  * Install an exception handler for MediaWiki exception types.
  */
index 1d1df0e..34eac1e 100644 (file)
@@ -1933,53 +1933,10 @@ class OutputPage {
 
        /**
         * Produce a "user is blocked" page.
-        *
-        * @param $return Boolean: whether to have a "return to $wgTitle" message or not.
-        * @return nothing
+        * @deprecated since 1.18
         */
-       function blockedPage( $return = true ) {
-               global $wgContLang;
-
-               $this->setPageTitle( wfMsg( 'blockedtitle' ) );
-               $this->setRobotPolicy( 'noindex,nofollow' );
-               $this->setArticleRelated( false );
-
-               $name = $this->getUser()->blockedBy();
-               $reason = $this->getUser()->blockedFor();
-               if( $reason == '' ) {
-                       $reason = wfMsg( 'blockednoreason' );
-               }
-               $blockTimestamp = $this->getContext()->getLang()->timeanddate(
-                       wfTimestamp( TS_MW, $this->getUser()->mBlock->mTimestamp ), true
-               );
-               $ip = wfGetIP();
-
-               $link = '[[' . $wgContLang->getNsText( NS_USER ) . ":{$name}|{$name}]]";
-
-               $blockid = $this->getUser()->mBlock->getId();
-
-               $blockExpiry = $this->getContext()->getLang()->formatExpiry( $this->getUser()->mBlock->mExpiry );
-
-               if ( $this->getUser()->mBlock->mAuto ) {
-                       $msg = 'autoblockedtext';
-               } else {
-                       $msg = 'blockedtext';
-               }
-
-               /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
-                * This could be a username, an IP range, or a single IP. */
-               $intended = $this->getUser()->mBlock->getTarget();
-
-               $this->addWikiMsg(
-                       $msg, $link, $reason, $ip, $name, $blockid, $blockExpiry,
-                       $intended, $blockTimestamp
-               );
-
-               # Don't auto-return to special pages
-               if( $return ) {
-                       $return = $this->getTitle()->getNamespace() > -1 ? $this->getTitle() : null;
-                       $this->returnToMain( null, $return );
-               }
+       function blockedPage() {
+               throw new UserBlockedError( $this->getUser()->mBlock );
        }
 
        /**
@@ -2163,9 +2120,7 @@ class OutputPage {
                        $this->addWikiText( $this->formatPermissionsErrorMessage( $reasons, $action ) );
                } else {
                        // Wiki is read only
-                       $this->setPageTitle( wfMsg( 'readonly' ) );
-                       $reason = wfReadOnlyReason();
-                       $this->wrapWikiMsg( "<div class='mw-readonly-error'>\n$1\n</div>", array( 'readonlytext', $reason ) );
+                       throw new ReadOnlyError;
                }
 
                // Show source, if supplied