Capitalization fix in memcached setting
[lhc/web/wiklou.git] / includes / Title.php
index c8ece2a..b23dd4b 100644 (file)
@@ -594,13 +594,6 @@ class Title {
                }
        }
 
-       /**
-        * @deprecated
-        */
-       function getURL() {
-               die( 'Call to obsolete obsolete function Title::getURL()' );
-       }
-       
        /**
         * Get a URL with no fragment or server name
         * @param string $query an optional query string; if not specified,
@@ -622,12 +615,7 @@ class Title {
                        if ( $query == '-' ) {
                                $query = '';
                        }
-                       if ( $wgScript != '' ) {
-                               $url = "{$wgScript}?title={$dbkey}&{$query}";
-                       } else {
-                               # Top level wiki
-                               $url = "/{$dbkey}?{$query}";
-                       }
+                       $url = "{$wgScript}?title={$dbkey}&{$query}";
                }
                return $url;
        }
@@ -754,27 +742,37 @@ class Title {
         */
        function userCanEdit() {
                global $wgUser;
-               if ( -1 == $this->mNamespace ) { return false; }
-               if ( NS_MEDIAWIKI == $this->mNamespace && !$wgUser->isSysop() ) { return false; }
-               # if ( 0 == $this->getArticleID() ) { return false; }
-               if ( $this->mDbkeyform == '_' ) { return false; }
+               if( NS_SPECIAL == $this->mNamespace ) {
+                       return false;
+               }
+               if( NS_MEDIAWIKI == $this->mNamespace &&
+                   !$wgUser->isAllowed('editinterface') ) {
+                       return false;
+               }
+               if( $this->mDbkeyform == '_' ) {
+                       # FIXME: Is this necessary? Shouldn't be allowed anyway...
+                       return false;
+               }
+               
                # protect global styles and js
                if ( NS_MEDIAWIKI == $this->mNamespace 
-                    && preg_match("/\\.(css|js)$/", $this->mTextform )
-                    && !$wgUser->isSysop() )
-               { return false; }
-               //if ( $this->isCssJsSubpage() and !$this->userCanEditCssJsSubpage() ) { return false; }
+                && preg_match("/\\.(css|js)$/", $this->mTextform )
+                    && !$wgUser->isAllowed('editinterface') ) {
+                       return false;
+               }
+               
                # protect css/js subpages of user pages
                # XXX: this might be better using restrictions
                # XXX: Find a way to work around the php bug that prevents using $this->userCanEditCssJsSubpage() from working
-               if( Namespace::getUser() == $this->mNamespace
-                       and preg_match("/\\.(css|js)$/", $this->mTextform )
-                       and !$wgUser->isSysop()
-                       and !preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform) )
-               { return false; }
-               $ur = $wgUser->getRights();
-               foreach ( $this->getRestrictions() as $r ) {
-                       if ( '' != $r && ( ! in_array( $r, $ur ) ) ) {
+               if( NS_USER == $this->mNamespace
+                       && preg_match("/\\.(css|js)$/", $this->mTextform )
+                       && !$wgUser->isAllowed('editinterface')
+                       && !preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform) ) {
+                       return false;
+               }
+
+               foreach( $this->getRestrictions() as $right ) {
+                       if( '' != $right && !$wgUser->isAllowed( $right ) ) {
                                return false;
                        }
                }
@@ -788,17 +786,32 @@ class Title {
         */
        function userCanRead() {
                global $wgUser;
-               global $wgWhitelistRead;
                
-               if( 0 != $wgUser->getID() ) return true;
-               if( !is_array( $wgWhitelistRead ) ) return true;
-               
-               $name = $this->getPrefixedText();
-               if( in_array( $name, $wgWhitelistRead ) ) return true;
-               
-               # Compatibility with old settings
-               if( $this->getNamespace() == NS_MAIN ) {
-                       if( in_array( ':' . $name, $wgWhitelistRead ) ) return true;
+               if( $wgUser->isAllowed('read') ) {
+                       return true;
+               } else {
+                       global $wgWhitelistRead;
+                       
+                       /** If anon users can create an account,
+                           they need to reach the login page first! */
+                       if( $wgUser->isAllowed( 'createaccount' )
+                           && $this->mId == NS_SPECIAL
+                           && $this->getText() == 'Userlogin' ) {
+                               return true;
+                       }
+
+                       /** some pages are explicitly allowed */
+                       $name = $this->getPrefixedText();
+                       if( in_array( $name, $wgWhitelistRead ) ) {
+                               return true;
+                       }
+                       
+                       # Compatibility with old settings
+                       if( $this->getNamespace() == NS_MAIN ) {
+                               if( in_array( ':' . $name, $wgWhitelistRead ) ) {
+                                       return true;
+                               }
+                       }
                }
                return false;
        }
@@ -837,7 +850,7 @@ class Title {
         */
        function userCanEditCssJsSubpage() {
                global $wgUser;
-               return ( $wgUser->isSysop() or preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform) );
+               return ( $wgUser->isAllowed('editinterface') or preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform) );
        }
 
        /**
@@ -1635,11 +1648,10 @@ class Title {
                $sk =& $wgUser->getSkin();
                $parents = array();
                $dbr =& wfGetDB( DB_SLAVE );
-               $cur = $dbr->tableName( 'cur' );
                $categorylinks = $dbr->tableName( 'categorylinks' );
 
                # NEW SQL
-               $sql = "SELECT * FROM categorylinks"
+               $sql = "SELECT * FROM $categorylinks"
                     ." WHERE cl_from='$titlekey'"
                         ." AND cl_from <> '0'"
                         ." ORDER BY cl_sortkey";
@@ -1658,18 +1670,24 @@ class Title {
        }
 
        /**
-        * Go through all parent categories of this Title
+        * Get a tree of parent categories
+        * @param array $children an array with the children in the keys, to check for circular refs
         * @return array
         * @access public
         */
-       function getCategorieBrowser() {
+       function getParentCategoryTree( $children = array() ) {
                $parents = $this->getParentCategories();
                
                if($parents != '') {
                        foreach($parents as $parent => $current)
                        {
-                               $nt = Title::newFromText($parent);
-                               $stack[$parent] = $nt->getCategorieBrowser();
+                               if ( array_key_exists( $parent, $children ) ) {
+                                       # Circular reference
+                                       $stack[$parent] = array();
+                               } else {
+                                       $nt = Title::newFromText($parent);
+                                       $stack[$parent] = $nt->getParentCategoryTree( $children + array($parent => 1) );
+                               }
                        }
                        return $stack;
                } else {