* (bug 674) Allow users to be blocked from editing a specific article
[lhc/web/wiklou.git] / includes / Title.php
index ab6a0d0..0bef7bc 100644 (file)
@@ -1107,9 +1107,7 @@ class Title {
                }
                $errors = $this->getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries );
 
-               global $wgContLang;
-               global $wgLang;
-               global $wgEmailConfirmToEdit;
+               global $wgContLang, $wgLang, $wgEmailConfirmToEdit;
 
                if ( $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount' ) {
                        $errors[] = array( 'confirmedittext' );
@@ -1141,20 +1139,7 @@ class Title {
                        $blockTimestamp = $wgLang->timeanddate( wfTimestamp( TS_MW, $user->mBlock->mTimestamp ), true );
 
                        if ( $blockExpiry == 'infinity' ) {
-                               // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite'
-                               $scBlockExpiryOptions = wfMsg( 'ipboptions' );
-
-                               foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
-                                       if ( strpos( $option, ':' ) == false )
-                                               continue;
-
-                                       list ($show, $value) = explode( ":", $option );
-
-                                       if ( $value == 'infinite' || $value == 'indefinite' ) {
-                                               $blockExpiry = $show;
-                                               break;
-                                       }
-                               }
+                               $blockExpiry = wfMsg( 'ipbinfinite' );
                        } else {
                                $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW, $blockExpiry ), true );
                        }
@@ -1164,9 +1149,9 @@ class Title {
                        $errors[] = array( ($block->mAuto ? 'autoblockedtext' : 'blockedtext'), $link, $reason, $ip, $name, 
                                $blockid, $blockExpiry, $intended, $blockTimestamp );
                }
-               
+
                // Remove the errors being ignored.
-               
+
                foreach( $errors as $index => $error ) {
                        $error_key = is_array($error) ? $error[0] : $error;
                        
@@ -1189,6 +1174,8 @@ class Title {
         * @return \type{\array} Array of arrays of the arguments to wfMsg to explain permissions problems.
         */
        private function getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries = true ) {
+               global $wgLang;
+
                wfProfileIn( __METHOD__ );
 
                $errors = array();
@@ -1334,6 +1321,26 @@ class Title {
                        $errors[] = $return;
                }
 
+               // Check per-user restrictions
+               if( $action != 'read' ) {
+                       $r = $user->getRestrictionForPage( $this );
+                       if( !$r )
+                               $r = $user->getRestrictionForNamespace( $this->getNamespace() );
+                       if( $r ) {
+                               $start = $wgLang->timeanddate( $r->getTimestamp() );
+                               $end = $r->getExpiry() == 'infinity' ?
+                                       wfMsg( 'ipbinfinite' ) :
+                                       $wgLang->timeanddate( $r->getExpiry() );
+                               if( $r->isPage() )
+                                       $errors[] = array( 'userrestricted-page', $this->getFullText(),
+                                               $r->getBlockerText(), $r->getReason(), $start, $end );
+                               elseif( $r->isNamespace() ) {
+                                       $errors[] = array( 'userrestricted-namespace', $wgLang->getDisplayNsText( $this->getNamespace() ),
+                                               $r->getBlockerText(), $r->getReason(), $start, $end );
+                               }
+                       }
+               }
+
                wfProfileOut( __METHOD__ );
                return $errors;
        }