* (bug 1459) Search for duplicate files by hash: Special:FileDuplicateSearch
[lhc/web/wiklou.git] / includes / Title.php
index 8a9d3ee..8191b2a 100644 (file)
@@ -285,10 +285,10 @@ class Title {
         */
        public static function newFromRedirect( $text ) {
                $redir = MagicWord::get( 'redirect' );
-               if( $redir->matchStart( $text ) ) {
+               if( $redir->matchStart( trim($text) ) ) {
                        // Extract the first link and see if it's usable
                        $m = array();
-                       if( preg_match( '!\[{2}(.*?)(?:\||\]{2})!', $text, $m ) ) {
+                       if( preg_match( '!\[{2}(.*?)(?:\|.*?)?\]{2}!', $text, $m ) ) {
                                // Strip preceding colon used to "escape" categories, etc.
                                // and URL-decode links
                                if( strpos( $m[1], '%' ) !== false ) {
@@ -942,27 +942,20 @@ class Title {
         * @return boolean
         */
        public function isProtected( $action = '' ) {
-               global $wgRestrictionLevels;
+               global $wgRestrictionLevels, $wgRestrictionTypes;
 
                # Special pages have inherent protection
                if( $this->getNamespace() == NS_SPECIAL )
                        return true;
 
-               # Check regular protection levels                               
-               if( $action == 'edit' || $action == '' ) {
-                       $r = $this->getRestrictions( 'edit' );
-                       foreach( $wgRestrictionLevels as $level ) {
-                               if( in_array( $level, $r ) && $level != '' ) {
-                                       return( true );
-                               }
-                       }
-               }
-               
-               if( $action == 'move' || $action == '' ) {
-                       $r = $this->getRestrictions( 'move' );
-                       foreach( $wgRestrictionLevels as $level ) {
-                               if( in_array( $level, $r ) && $level != '' ) {
-                                       return( true );
+               # Check regular protection levels
+               foreach( $wgRestrictionTypes as $type ){                
+                       if( $action == $type || $action == '' ) {
+                               $r = $this->getRestrictions( $type );
+                               foreach( $wgRestrictionLevels as $level ) {
+                                       if( in_array( $level, $r ) && $level != '' ) {
+                                               return true;
+                                       }
                                }
                        }
                }
@@ -971,7 +964,7 @@ class Title {
        }
 
        /**
-        * Is $wgUser is watching this page?
+        * Is $wgUser watching this page?
         * @return boolean
         */
        public function userIsWatching() {
@@ -1037,6 +1030,7 @@ class Title {
         * FIXME: This *does not* check throttles (User::pingLimiter()).
         *
         * @param string $action action that permission needs to be checked for
+        * @param User $user user to check
         * @param bool $doExpensiveQueries Set this to false to avoid doing unnecessary queries.
         * @return array Array of arrays of the arguments to wfMsg to explain permissions problems.
         */
@@ -1045,7 +1039,7 @@ class Title {
 
                global $wgContLang;
                global $wgLang;
-               global $wgEmailConfirmToEdit, $wgUser;
+               global $wgEmailConfirmToEdit;
 
                if ( $wgEmailConfirmToEdit && !$user->isEmailConfirmed() ) {
                        $errors[] = array( 'confirmedittext' );
@@ -1108,6 +1102,7 @@ class Title {
         * checks on wfReadOnly() and blocks)
         *
         * @param string $action action that permission needs to be checked for
+        * @param User $user user to check
         * @param bool $doExpensiveQueries Set this to false to avoid doing unnecessary queries.
         * @return array Array of arrays of the arguments to wfMsg to explain permissions problems.
         */
@@ -1198,7 +1193,18 @@ class Title {
                                $right = 'protect';
                        }
                        if( '' != $right && !$user->isAllowed( $right ) ) {
-                               $errors[] = array( 'protectedpagetext', $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!
+                                       }
+                               } else {
+                                       $errors[] = array( 'protectedpagetext', $right );
+                               }
                        }
                }
 
@@ -1382,11 +1388,11 @@ class Title {
         */
        public function userCanRead() {
                global $wgUser, $wgGroupPermissions;
-               
+
                # Shortcut for public wikis, allows skipping quite a bit of code path
                if ($wgGroupPermissions['*']['read'])
                        return true;
-               
+
                $result = null;
                wfRunHooks( 'userCan', array( &$this, &$wgUser, 'read', &$result ) );
                if ( $result !== null ) {
@@ -1412,14 +1418,14 @@ class Title {
                        if( !is_array($wgWhitelistRead) ) {
                                return false;
                        }
-                       
+
                        /**
                         * Check for explicit whitelisting
                         */
                        $name = $this->getPrefixedText();
                        if( in_array( $name, $wgWhitelistRead, true ) )
                                return true;
-                       
+
                        /**
                         * Old settings might have the title prefixed with
                         * a colon for main-namespace pages
@@ -1428,7 +1434,7 @@ class Title {
                                if( in_array( ':' . $name, $wgWhitelistRead ) )
                                        return true;
                        }
-                       
+
                        /**
                         * If it's a special page, ditch the subpage bit
                         * and check again
@@ -1515,14 +1521,14 @@ class Title {
         * @return bool
         */
        public function isCssSubpage() {
-               return ( NS_USER == $this->mNamespace and preg_match("/\\/.*\\.css$/", $this->mTextform ) );
+               return ( NS_USER == $this->mNamespace && preg_match("/\\/.*\\.css$/", $this->mTextform ) );
        }
        /**
         * Is this a .js subpage of a user page?
         * @return bool
         */
        public function isJsSubpage() {
-               return ( NS_USER == $this->mNamespace and preg_match("/\\/.*\\.js$/", $this->mTextform ) );
+               return ( NS_USER == $this->mNamespace && preg_match("/\\/.*\\.js$/", $this->mTextform ) );
        }
        /**
         * Protect css/js subpages of user pages: can $wgUser edit
@@ -1533,7 +1539,7 @@ class Title {
         */
        public function userCanEditCssJsSubpage() {
                global $wgUser;
-               return ( $wgUser->isAllowed('editusercssjs') or preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform) );
+               return ( $wgUser->isAllowed('editusercssjs') || preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform) );
        }
 
        /**
@@ -1654,10 +1660,15 @@ class Title {
         * @param resource $res restrictions as an SQL result.
         */
        private function loadRestrictionsFromRow( $res, $oldFashionedRestrictions = NULL ) {
-               $dbr = wfGetDb( DB_SLAVE );
+               global $wgRestrictionTypes;
+               $dbr = wfGetDB( DB_SLAVE );
+
+               foreach( $wgRestrictionTypes as $type ){
+                       $this->mRestrictions[$type] = array();
+               }
 
-               $this->mRestrictions['edit'] = array();
-               $this->mRestrictions['move'] = array();
+               $this->mCascadeRestriction = false;
+               $this->mRestrictionsExpiry = Block::decodeExpiry('');
 
                # Backwards-compatibility: also load the restrictions from the page record (old format).
 
@@ -1671,16 +1682,14 @@ class Title {
                                $temp = explode( '=', trim( $restrict ) );
                                if(count($temp) == 1) {
                                        // old old format should be treated as edit/move restriction
-                                       $this->mRestrictions["edit"] = explode( ',', trim( $temp[0] ) );
-                                       $this->mRestrictions["move"] = explode( ',', trim( $temp[0] ) );
+                                       $this->mRestrictions['edit'] = explode( ',', trim( $temp[0] ) );
+                                       $this->mRestrictions['move'] = explode( ',', trim( $temp[0] ) );
                                } else {
                                        $this->mRestrictions[$temp[0]] = explode( ',', trim( $temp[1] ) );
                                }
                        }
 
                        $this->mOldRestrictions = true;
-                       $this->mCascadeRestriction = false;
-                       $this->mRestrictionsExpiry = Block::decodeExpiry('');
 
                }
 
@@ -1691,6 +1700,10 @@ class Title {
 
                        while ($row = $dbr->fetchObject( $res ) ) {
                                # Cycle through all the restrictions.
+                               
+                               // Don't take care of restrictions types that aren't in $wgRestrictionTypes
+                               if( !in_array( $row->pr_type, $wgRestrictionTypes ) )
+                                       continue;
 
                                // This code should be refactored, now that it's being used more generally,
                                // But I don't really see any harm in leaving it in Block for now -werdna
@@ -2720,6 +2733,7 @@ class Title {
         * @return array
         */
        public function getParentCategoryTree( $children = array() ) {
+               $stack = array();
                $parents = $this->getParentCategories();
 
                if($parents != '') {