(bug 13441) Allow Special:Recentchanges to show bots only
[lhc/web/wiklou.git] / includes / Title.php
index ff8a234..0c91eab 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 ) {
@@ -577,7 +577,7 @@ class Title {
         */
        public function getSubjectNsText() {
                global $wgContLang;
-               return $wgContLang->getNsText( Namespace::getSubject( $this->mNamespace ) );
+               return $wgContLang->getNsText( MWNamespace::getSubject( $this->mNamespace ) );
        }
 
        /**
@@ -586,7 +586,7 @@ class Title {
         */
        public function getTalkNsText() {
                global $wgContLang;
-               return( $wgContLang->getNsText( Namespace::getTalk( $this->mNamespace ) ) );
+               return( $wgContLang->getNsText( MWNamespace::getTalk( $this->mNamespace ) ) );
        }
 
        /**
@@ -594,7 +594,7 @@ class Title {
         * @return bool
         */
        public function canTalk() {
-               return( Namespace::canTalk( $this->mNamespace ) );
+               return( MWNamespace::canTalk( $this->mNamespace ) );
        }
 
        /**
@@ -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;
+                                       }
                                }
                        }
                }
@@ -1200,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 );
+                               }
                        }
                }
 
@@ -1373,7 +1377,7 @@ class Title {
         * @return boolean
         */
        public function isMovable() {
-               return Namespace::isMovable( $this->getNamespace() )
+               return MWNamespace::isMovable( $this->getNamespace() )
                        && $this->getInterwiki() == '';
        }
 
@@ -1384,17 +1388,17 @@ 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 ) {
                        return $result;
                }
 
+               # Shortcut for public wikis, allows skipping quite a bit of code
+               if ($wgGroupPermissions['*']['read'])
+                       return true;
+
                if( $wgUser->isAllowed( 'read' ) ) {
                        return true;
                } else {
@@ -1414,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
@@ -1430,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
@@ -1457,7 +1461,7 @@ class Title {
         * @return bool
         */
        public function isTalkPage() {
-               return Namespace::isTalk( $this->getNamespace() );
+               return MWNamespace::isTalk( $this->getNamespace() );
        }
 
        /**
@@ -1517,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
@@ -1535,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) );
        }
 
        /**
@@ -1656,10 +1660,13 @@ 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('');
 
@@ -1675,8 +1682,8 @@ 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] ) );
                                }
@@ -1693,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
@@ -2107,9 +2118,8 @@ class Title {
                $this->mUrlform = wfUrlencode( $dbkey );
 
                $this->mTextform = str_replace( '_', ' ', $dbkey );
-               
-               # Hooks can reject titles by returning false
-               return wfRunHooks('TitleSecureAndSplit', array( $this, &$dbkey )); 
+
+               return true;
        }
 
        /**
@@ -2130,7 +2140,7 @@ class Title {
         * @return Title the object for the talk page
         */
        public function getTalkPage() {
-               return Title::makeTitle( Namespace::getTalk( $this->getNamespace() ), $this->getDBkey() );
+               return Title::makeTitle( MWNamespace::getTalk( $this->getNamespace() ), $this->getDBkey() );
        }
 
        /**
@@ -2140,7 +2150,7 @@ class Title {
         * @return Title the object for the subject page
         */
        public function getSubjectPage() {
-               return Title::makeTitle( Namespace::getSubject( $this->getNamespace() ), $this->getDBkey() );
+               return Title::makeTitle( MWNamespace::getSubject( $this->getNamespace() ), $this->getDBkey() );
        }
 
        /**
@@ -2681,7 +2691,7 @@ class Title {
         */
        public function isWatchable() {
                return !$this->isExternal()
-                       && Namespace::isWatchable( $this->getNamespace() );
+                       && MWNamespace::isWatchable( $this->getNamespace() );
        }
 
        /**
@@ -2885,7 +2895,12 @@ class Title {
                $title = htmlspecialchars($this->getText());
                $tburl = $this->trackbackURL();
 
-               return "
+               // Autodiscovery RDF is placed in comments so HTML validator
+               // won't barf. This is a rather icky workaround, but seems
+               // frequently used by this kind of RDF thingy.
+               //
+               // Spec: http://www.sixapart.com/pronet/docs/trackback_spec
+               return "<!--
 <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"
          xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
          xmlns:trackback=\"http://madskills.com/public/xml/rss/module/trackback/\">
@@ -2894,7 +2909,8 @@ class Title {
    dc:identifier=\"$url\"
    dc:title=\"$title\"
    trackback:ping=\"$tburl\" />
-</rdf:RDF>";
+</rdf:RDF>
+-->";
        }
 
        /**
@@ -2976,7 +2992,7 @@ class Title {
         * @return bool
         */
        public function isContentPage() {
-               return Namespace::isContent( $this->getNamespace() );
+               return MWNamespace::isContent( $this->getNamespace() );
        }
        
 }