Note that restrictions are rights, not groups. So now, cascading protection will...
[lhc/web/wiklou.git] / includes / Title.php
index c7ea915..616cc3d 100644 (file)
@@ -1052,13 +1052,19 @@ class Title {
         * @return array Array of arrays of the arguments to wfMsg to explain permissions problems.
         */
        public function getUserPermissionsErrors( $action, $user, $doExpensiveQueries = true ) {
+               if( !StubObject::isRealObject( $user ) ) {
+                       //Since StubObject is always used on globals, we can unstub $wgUser here and set $user = $wgUser
+                       global $wgUser;
+                       $wgUser->_unstub( '', 5 );
+                       $user = $wgUser;
+               }
                $errors = $this->getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries );
 
                global $wgContLang;
                global $wgLang;
                global $wgEmailConfirmToEdit;
 
-               if ( $wgEmailConfirmToEdit && !$user->isEmailConfirmed() ) {
+               if ( $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount' ) {
                        $errors[] = array( 'confirmedittext' );
                }
 
@@ -1213,15 +1219,10 @@ class Title {
                                $right = 'protect';
                        }
                        if( '' != $right && !$user->isAllowed( $right ) ) {
-                               //Users with 'editprotected' permission can edit protected pages
-                               if( $action=='edit' && $user->isAllowed( 'editprotected' ) ) {
-                                       //Users with 'editprotected' permission cannot edit protected pages
-                                       //with cascading option turned on.
-                                       if($this->mCascadeRestriction) {
-                                               $errors[] = array( 'protectedpagetext', $right );
-                                       } else {
-                                               //Nothing, user can edit!
-                                       }
+                               // Users with 'editprotected' permission can edit protected
+                               // pages if protection is not with cascading option turned on.
+                               if( $action=='edit' && $user->isAllowed( 'editprotected' ) && !$this->areRestrictionsCascading() ) {
+                                       // Nothing, user can edit!
                                } else {
                                        $errors[] = array( 'protectedpagetext', $right );
                                }
@@ -1605,16 +1606,13 @@ class Title {
         * The restriction array is an array of each type, each of which contains an array of unique groups
         */
        public function getCascadeProtectionSources( $get_pages = true ) {
-               global $wgEnableCascadingProtection, $wgRestrictionTypes;
+               global $wgRestrictionTypes;
 
                # Define our dimension of restrictions types
                $pagerestrictions = array();
                foreach( $wgRestrictionTypes as $action )
                        $pagerestrictions[$action] = array();
 
-               if (!$wgEnableCascadingProtection)
-                       return array( false, $pagerestrictions );
-
                if ( isset( $this->mCascadeSources ) && $get_pages ) {
                        return array( $this->mCascadeSources, $this->mCascadingRestrictions );
                } else if ( isset( $this->mHasCascadingRestrictions ) && !$get_pages ) {
@@ -1623,7 +1621,7 @@ class Title {
 
                wfProfileIn( __METHOD__ );
 
-               $dbr = wfGetDb( DB_SLAVE );
+               $dbr = wfGetDB( DB_SLAVE );
 
                if ( $this->getNamespace() == NS_IMAGE ) {
                        $tables = array ('imagelinks', 'page_restrictions');
@@ -1717,7 +1715,8 @@ class Title {
                # Backwards-compatibility: also load the restrictions from the page record (old format).
 
                if ( $oldFashionedRestrictions === NULL ) {
-                       $oldFashionedRestrictions = $dbr->selectField( 'page', 'page_restrictions', array( 'page_id' => $this->getArticleId() ), __METHOD__ );
+                       $oldFashionedRestrictions = $dbr->selectField( 'page', 'page_restrictions', 
+                               array( 'page_id' => $this->getArticleId() ), __METHOD__ );
                }
 
                if ($oldFashionedRestrictions != '') {
@@ -1923,7 +1922,7 @@ class Title {
                if ($this->mLatestID !== false)
                        return $this->mLatestID;
 
-               $db = ($flags & GAID_FOR_UPDATE) ? wfGetDB(DB_MASTER) : wfGetDB(DB_SLAVE);
+               $db = ($flags & GAID_FOR_UPDATE) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
                return $this->mLatestID = $db->selectField( 'revision',
                        "max(rev_id)",
                        array('rev_page' => $this->getArticleID($flags)),
@@ -2394,7 +2393,7 @@ class Title {
         */
        public function isValidMoveOperation( &$nt, $auth = true ) {
                $errors = array();      
-               if( !$this or !$nt ) {
+               if( !$nt ) {
                        // Normally we'd add this to $errors, but we'll get
                        // lots of syntax errors if $nt is not an object
                        return array(array('badtitletext'));
@@ -2478,7 +2477,7 @@ class Title {
         */
        public function moveTo( &$nt, $auth = true, $reason = '', $createRedirect = true ) {
                $err = $this->isValidMoveOperation( $nt, $auth );
-               if( is_array($err) ) {
+               if( is_array( $err ) ) {
                        return $err;
                }
 
@@ -2490,9 +2489,8 @@ class Title {
                        $err = $this->moveToNewTitle( $nt, $reason, $createRedirect );
                        $pageCountChange = ($createRedirect ? 1 : 0);
                }
-               # FIXME: moveToNewTitle() and moveOverExistingRedirect() return
-               #        wikitext if a file move goes bad
-               if( is_string( $err ) ) {
+
+               if( is_array( $err ) ) {
                        return $err;
                }
                $redirid = $this->getArticleID();
@@ -2616,7 +2614,7 @@ class Title {
                $nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true );
                $nullRevId = $nullRevision->insertOn( $dbw );
                
-               $article = new Article( $nt );
+               $article = new Article( $this );
                wfRunHooks( 'NewRevisionFromEditComplete', array($article, $nullRevision, false) );
 
                # Change the name of the target page:
@@ -2667,7 +2665,7 @@ class Title {
                                $status = $file->move( $nt );
                                if( !$status->isOk() ) {
                                        $dbw->rollback();
-                                       return $status->getWikiText();
+                                       return $status->getErrorsArray();
                                }
                        }
                }
@@ -2683,6 +2681,7 @@ class Title {
                        $u = new SquidUpdate( $urls );
                        $u->doUpdate();
                }
+               
        }
 
        /**
@@ -2711,7 +2710,7 @@ class Title {
                $nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true );
                $nullRevId = $nullRevision->insertOn( $dbw );
                
-               $article = new Article( $nt );
+               $article = new Article( $this );
                wfRunHooks( 'NewRevisionFromEditComplete', array($article, $nullRevision, false) );
 
                # Rename page entry
@@ -2760,7 +2759,7 @@ class Title {
                                $status = $file->move( $nt );
                                if( !$status->isOk() ) {
                                        $dbw->rollback();
-                                       return $status->getWikiText();
+                                       return $status->getErrorsArray();
                                }
                        }
                }
@@ -2776,6 +2775,7 @@ class Title {
                # Purge old title from squid
                # The new title, and links to the new title, are purged in Article::onArticleCreate()
                $this->purgeSquid();
+               
        }
 
        /**