Capitalization fix in memcached setting
[lhc/web/wiklou.git] / includes / Title.php
index ef11553..b23dd4b 100644 (file)
@@ -157,7 +157,7 @@ class Title {
        /* static */ function newFromID( $id ) {
                $fname = 'Title::newFromID';
                $dbr =& wfGetDB( DB_SLAVE );
-               $row = $dbr->getArray( 'cur', array( 'cur_namespace', 'cur_title' ), 
+               $row = $dbr->selectRow( 'cur', array( 'cur_namespace', 'cur_title' ), 
                        array( 'cur_id' => $id ), $fname );
                if ( $row !== false ) {
                        $title = Title::makeTitle( $row->cur_namespace, $row->cur_title );
@@ -265,7 +265,7 @@ class Title {
                $fname = 'Title::nameOf';
                $dbr =& wfGetDB( DB_SLAVE );
                
-               $s = $dbr->getArray( 'cur', array( 'cur_namespace','cur_title' ),  array( 'cur_id' => $id ), $fname );
+               $s = $dbr->selectRow( 'cur', array( 'cur_namespace','cur_title' ),  array( 'cur_id' => $id ), $fname );
                if ( $s === false ) { return NULL; }
 
                $n = Title::makeName( $s->cur_namespace, $s->cur_title );
@@ -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) );
        }
 
        /**
@@ -851,7 +864,7 @@ class Title {
 
                if ( ! $this->mRestrictionsLoaded ) {
                        $dbr =& wfGetDB( DB_SLAVE );
-                       $res = $dbr->getField( 'cur', 'cur_restrictions', 'cur_id='.$id );
+                       $res = $dbr->selectField( 'cur', 'cur_restrictions', 'cur_id='.$id );
                        $this->mRestrictions = explode( ',', trim( $res ) );
                        $this->mRestrictionsLoaded = true;
                }
@@ -866,7 +879,7 @@ class Title {
        function isDeleted() {
                $fname = 'Title::isDeleted';
                $dbr =& wfGetDB( DB_SLAVE );
-               $n = $dbr->getField( 'archive', 'COUNT(*)', array( 'ar_namespace' => $this->getNamespace(), 
+               $n = $dbr->selectField( 'archive', 'COUNT(*)', array( 'ar_namespace' => $this->getNamespace(), 
                        'ar_title' => $this->getDBkey() ), $fname );
                return (int)$n;
        }
@@ -923,7 +936,7 @@ class Title {
        function invalidateCache() {
                $now = wfTimestampNow();
                $dbw =& wfGetDB( DB_MASTER );
-               $success = $dbw->updateArray( 'cur', 
+               $success = $dbw->update( 'cur', 
                        array( /* SET */ 
                                'cur_touched' => $dbw->timestamp()
                        ), array( /* WHERE */ 
@@ -979,7 +992,7 @@ class Title {
                if ( $imgpre === false ) {
                        $imgpre = ':' . $wgContLang->getNsText( Namespace::getImage() ) . ':';
                        # % is needed as well
-                       $rxTc = '/[^' . Title::legalChars() . ']/';
+                       $rxTc = '/[^' . Title::legalChars() . ']|%[0-9A-Fa-f]{2}/';
                }
 
                $this->mInterwiki = $this->mFragment = '';
@@ -1312,7 +1325,7 @@ class Title {
                $links = $dbw->tableName( 'links' );
 
                # Change the name of the target page:
-               $dbw->updateArray( 'cur',
+               $dbw->update( 'cur',
                        /* SET */ array( 
                                'cur_touched' => $dbw->timestamp($now), 
                                'cur_namespace' => $nt->getNamespace(),
@@ -1327,7 +1340,7 @@ class Title {
                # by definition if we've got here it's rather uninteresting.
                
                $redirectText = $wgMwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
-               $dbw->updateArray( 'cur',
+               $dbw->update( 'cur',
                        /* SET */ array(
                                'cur_touched' => $dbw->timestamp($now),
                                'cur_timestamp' => $dbw->timestamp($now),
@@ -1352,7 +1365,7 @@ class Title {
 
                # Fix the redundant names for the past revisions of the target page.
                # The redirect should have no old revisions.
-               $dbw->updateArray(
+               $dbw->update(
                        /* table */ 'old',
                        /* SET */ array( 
                                'old_namespace' => $nt->getNamespace(),
@@ -1410,7 +1423,7 @@ class Title {
                # Now, we record the link from the redirect to the new title.
                # It should have no other outgoing links...
                $dbw->delete( 'links', array( 'l_from' => $newid ) );
-               $dbw->insertArray( 'links', array( 'l_from' => $newid, 'l_to' => $oldid ) );
+               $dbw->insert( 'links', array( 'l_from' => $newid, 'l_to' => $oldid ) );
                
                # Clear linkscc
                LinkCache::linksccClearLinksTo( $oldid );
@@ -1444,7 +1457,7 @@ class Title {
                $rand = wfRandom();
 
                # Rename cur entry
-               $dbw->updateArray( 'cur',
+               $dbw->update( 'cur',
                        /* SET */ array(
                                'cur_touched' => $now,
                                'cur_namespace' => $nt->getNamespace(),
@@ -1457,7 +1470,7 @@ class Title {
                $wgLinkCache->clearLink( $nt->getPrefixedDBkey() );
 
                # Insert redirect
-               $dbw->insertArray( 'cur', array(
+               $dbw->insert( 'cur', array(
                        'cur_id' => $dbw->nextSequenceValue('cur_cur_id_seq'),
                        'cur_namespace' => $this->getNamespace(),
                        'cur_title' => $this->getDBkey(),
@@ -1476,7 +1489,7 @@ class Title {
                $wgLinkCache->clearLink( $this->getPrefixedDBkey() );
 
                # Rename old entries
-               $dbw->updateArray
+               $dbw->update( 
                        /* table */ 'old',
                        /* SET */ array(
                                'old_namespace' => $nt->getNamespace(),
@@ -1495,11 +1508,11 @@ class Title {
                Article::onArticleCreate( $nt );
 
                # Any text links to the old title must be reassigned to the redirect
-               $dbw->updateArray( 'links', array( 'l_to' => $newid ), array( 'l_to' => $oldid ), $fname );
+               $dbw->update( 'links', array( 'l_to' => $newid ), array( 'l_to' => $oldid ), $fname );
                LinkCache::linksccClearLinksTo( $oldid );
 
                # Record the just-created redirect's linking to the page
-               $dbw->insertArray( 'links', array( 'l_from' => $newid, 'l_to' => $oldid ), $fname );
+               $dbw->insert( 'links', array( 'l_from' => $newid, 'l_to' => $oldid ), $fname );
 
                # Non-existent target may have had broken links to it; these must
                # now be removed and made into good links.
@@ -1532,7 +1545,7 @@ class Title {
 
                # Is it a redirect?
                $id  = $nt->getArticleID();
-               $obj = $dbw->getArray( 'cur', array( 'cur_is_redirect','cur_text' ), 
+               $obj = $dbw->selectRow( 'cur', array( 'cur_is_redirect','cur_text' ), 
                        array( 'cur_id' => $id ), $fname, 'FOR UPDATE' );
 
                if ( !$obj || 0 == $obj->cur_is_redirect ) { 
@@ -1550,7 +1563,7 @@ class Title {
                }
 
                # Does the article have a history?
-               $row = $dbw->getArray( 'old', array( 'old_id' ), 
+               $row = $dbw->selectRow( 'old', array( 'old_id' ), 
                        array( 
                                'old_namespace' => $nt->getNamespace(),
                                'old_title' => $nt->getDBkey() 
@@ -1582,7 +1595,7 @@ class Title {
                $won = wfInvertTimestamp( $now );
                $seqVal = $dbw->nextSequenceValue( 'cur_cur_id_seq' );
 
-               $dbw->insertArray( 'cur', array(
+               $dbw->insert( 'cur', array(
                        'cur_id' => $seqVal,
                        'cur_namespace' => $this->getNamespace(),
                        'cur_title' => $this->getDBkey(),
@@ -1601,14 +1614,14 @@ class Title {
                
                # Link table
                if ( $dest->getArticleID() ) {
-                       $dbw->insertArray( 'links', 
+                       $dbw->insert( 'links', 
                                array(
                                        'l_to' => $dest->getArticleID(),
                                        'l_from' => $newid
                                ), $fname 
                        );
                } else {
-                       $dbw->insertArray( 'brokenlinks', 
+                       $dbw->insert( 'brokenlinks', 
                                array( 
                                        'bl_to' => $dest->getPrefixedDBkey(),
                                        'bl_from' => $newid
@@ -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 {