Some code cleanup per Nikerabbit
[lhc/web/wiklou.git] / includes / Title.php
index 6599b91..0bef7bc 100644 (file)
@@ -809,7 +809,7 @@ class Title {
         */
        public function getLocalURL( $query = '', $variant = false ) {
                global $wgArticlePath, $wgScript, $wgServer, $wgRequest;
-               global $wgVariantArticlePath, $wgContLang, $wgUser;
+               global $wgVariantArticlePath, $wgContLang, $wgUser, $wgArticlePathForCurid;
 
                if( is_array( $query ) ) {
                        $query = wfArrayToCGI( $query );
@@ -833,7 +833,7 @@ class Title {
                        }
                } else {
                        $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
-                       if ( $query == '' ) {
+                       if ( $query == '' || ($wgArticlePathForCurid && substr_count( $query, '&' ) == 0 && strpos( $query, 'curid=' ) === 0 ) ) {
                                if( $variant != false && $wgContLang->hasVariants() ) {
                                        if( $wgVariantArticlePath == false ) {
                                                $variantArticlePath =  "$wgScript?title=$1&variant=$2"; // default
@@ -845,6 +845,7 @@ class Title {
                                } else {
                                        $url = str_replace( '$1', $dbkey, $wgArticlePath );
                                }
+                               $url = wfAppendQuery( $url, $query );
                        } else {
                                global $wgActionPaths;
                                $url = false;
@@ -1106,15 +1107,14 @@ 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' );
                }
 
-               if ( $user->isBlockedFrom( $this ) && $action != 'createaccount' ) {
+               // Edit blocks should not affect reading. Account creation blocks handled at userlogin.
+               if ( $user->isBlockedFrom( $this ) && $action != 'read' && $action != 'createaccount' ) {
                        $block = $user->mBlock;
 
                        // This is from OutputPage::blockedPage
@@ -1139,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 );
                        }
@@ -1162,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;
                        
@@ -1187,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();
@@ -1332,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;
        }
@@ -1895,6 +1904,18 @@ class Title {
                                : array();
        }
 
+       /**
+        * Get the expiry time for the restriction against a given action
+        * @return 14-char timestamp, or 'infinity' if the page is protected forever 
+        * or not protected at all, or false if the action is not recognised.
+        */
+       public function getRestrictionExpiry( $action ) {
+               if( !$this->mRestrictionsLoaded ) {
+                       $this->loadRestrictions();
+               }
+               return isset( $this->mRestrictionsExpiry[$action] ) ? $this->mRestrictionsExpiry[$action] : false;
+       }
+
        /**
         * Is there a version of this page in the deletion archive?
         * @return \type{\int} the number of archived revisions
@@ -2560,6 +2581,7 @@ class Title {
                }
 
                $pageid = $this->getArticleID();
+               $protected = $this->isProtected();
                if( $nt->exists() ) {
                        $err = $this->moveOverExistingRedirect( $nt, $reason, $createRedirect );
                        $pageCountChange = ($createRedirect ? 0 : -1);
@@ -2594,8 +2616,28 @@ class Title {
                                'cl_sortkey' => $this->getPrefixedText() ),
                        __METHOD__ );
 
-               # Update watchlists
+               if( $protected ) {
+                       # Protect the redirect title as the title used to be...
+                       $dbw->insertSelect( 'page_restrictions', 'page_restrictions',
+                               array( 
+                                       'pr_page'    => $redirid,
+                                       'pr_type'    => 'pr_type',
+                                       'pr_level'   => 'pr_level',
+                                       'pr_cascade' => 'pr_cascade',
+                                       'pr_user'    => 'pr_user',
+                                       'pr_expiry'  => 'pr_expiry'
+                               ),
+                               array( 'pr_page' => $pageid ),
+                               __METHOD__,
+                               array( 'IGNORE' )
+                       );
+                       # Update the protection log
+                       $log = new LogPage( 'protect' );
+                       $comment = wfMsgForContent('1movedto2',$this->getPrefixedText(), $nt->getPrefixedText() );
+                       $log->addEntry( 'protect', $nt, $comment, array() ); // FIXME: $params?
+               }
 
+               # Update watchlists
                $oldnamespace = $this->getNamespace() & ~1;
                $newnamespace = $nt->getNamespace() & ~1;
                $oldtitle = $this->getDBkey();
@@ -2668,7 +2710,6 @@ class Title {
                $latest = $this->getLatestRevID();
 
                $dbw = wfGetDB( DB_MASTER );
-               $dbw->begin();
 
                # Delete the old redirect. We don't save it to history since
                # by definition if we've got here it's rather uninteresting.
@@ -2748,7 +2789,6 @@ class Title {
                                }
                        }
                }
-               $dbw->commit();
 
                # Log the move
                $log = new LogPage( 'move' );
@@ -2785,7 +2825,6 @@ class Title {
                $latest = $this->getLatestRevId();
                
                $dbw = wfGetDB( DB_MASTER );
-               $dbw->begin();
                $now = $dbw->timestamp();
 
                # Save a null revision in the page's history notifying of the move
@@ -2845,7 +2884,6 @@ class Title {
                                }
                        }
                }
-               $dbw->commit();
 
                # Log the move
                $log = new LogPage( 'move' );