tsfix
[lhc/web/wiklou.git] / includes / Title.php
index f08d91e..3a17b3b 100644 (file)
@@ -1,16 +1,28 @@
 <?php
-# See title.doc
-
+/**
+ * $Id$
+ * See title.doc
+ * 
+ * @package MediaWiki
+ */
+
+/** */
+require_once( 'normal/UtfNormal.php' );
+
+/**
+ *
+ */
 $wgTitleInterwikiCache = array();
-
-# Title class
-# 
-# * Represents a title, which may contain an interwiki designation or namespace
-# * Can fetch various kinds of data from the database, albeit inefficiently. 
-#
-
 define ( 'GAID_FOR_UPDATE', 1 );
 
+/**
+ * Title class
+ * - Represents a title, which may contain an interwiki designation or namespace
+ * - Can fetch various kinds of data from the database, albeit inefficiently. 
+ *
+ * @todo migrate comments to phpdoc format
+ * @package MediaWiki
+ */
 class Title {
        # All member variables should be considered private
        # Please use the accessor functions
@@ -95,17 +107,6 @@ class Title {
                # from some external search tools.
                $s = str_replace( '+', ' ', $url );
                
-               # For links that came from outside, check for alternate/legacy
-               # character encoding.
-               wfDebug( "Servr: $wgServer\n" );
-               if( empty( $_SERVER['HTTP_REFERER'] ) ||
-                       strncmp($wgServer, $_SERVER['HTTP_REFERER'], strlen( $wgServer ) ) ) 
-               {
-                       $s = $wgLang->checkTitleEncoding( $s );
-               } else {
-                       wfDebug( "Refer: {$_SERVER['HTTP_REFERER']}\n" );
-               }
-               
                $t->mDbkeyform = str_replace( ' ', '_', $s );
                if( $t->secureAndSplit() ) {
                        # check that length of title is < cur_title size
@@ -311,10 +312,10 @@ class Title {
                if ( count( $titles ) == 0 ) {
                        return;
                }
+               $dbw =& wfGetDB( DB_MASTER );
                if ( $timestamp == '' ) {
-                       $timestamp = wfTimestampNow();
+                       $timestamp = $dbw->timestamp();
                }
-               $dbw =& wfGetDB( DB_MASTER );
                $cur = $dbw->tableName( 'cur' );
                $sql = "UPDATE $cur SET cur_touched='{$timestamp}' WHERE cur_id IN (";
                $first = true;
@@ -644,7 +645,7 @@ class Title {
                $dbw =& wfGetDB( DB_MASTER );
                $success = $dbw->updateArray( 'cur', 
                        array( /* SET */ 
-                               'cur_touched' => wfTimestampNow()
+                               'cur_touched' => $dbw->timestamp()
                        ), array( /* WHERE */ 
                                'cur_namespace' => $this->getNamespace() ,
                                'cur_title' => $this->getDBkey()
@@ -703,6 +704,13 @@ class Title {
                        wfProfileOut( $fname );
                        return false;
                }
+               
+               global $wgUseLatin1;
+               if( !$wgUseLatin1 &&  false !== strpos( $t, UTF8_REPLACEMENT ) ) {
+                       # Contained illegal UTF-8 sequences or forbidden Unicode chars.
+                       wfProfileOut( $fname );
+                       return false;
+               }
 
                $this->mDbkeyform = $t;
                $done = false;
@@ -963,7 +971,7 @@ class Title {
                # Change the name of the target page:
                $dbw->updateArray( 'cur',
                        /* SET */ array( 
-                               'cur_touched' => $now
+                               'cur_touched' => $dbw->timestamp($now)
                                'cur_namespace' => $nt->getNamespace(),
                                'cur_title' => $nt->getDBkey()
                        ), 
@@ -978,8 +986,8 @@ class Title {
                $redirectText = $wgMwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
                $dbw->updateArray( 'cur',
                        /* SET */ array(
-                               'cur_touched' => $now,
-                               'cur_timestamp' => $now,
+                               'cur_touched' => $dbw->timestamp($now),
+                               'cur_timestamp' => $dbw->timestamp($now),
                                'inverse_timestamp' => $won,
                                'cur_namespace' => $this->getNamespace(),
                                'cur_title' => $this->getDBkey(),
@@ -1081,11 +1089,11 @@ class Title {
                $fname = 'MovePageForm::moveToNewTitle';
                $comment = wfMsg( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
 
-               $now = wfTimestampNow();
-               $won = wfInvertTimestamp( $now );
                $newid = $nt->getArticleID();
                $oldid = $this->getArticleID();
                $dbw =& wfGetDB( DB_MASTER );
+               $now = $dbw->timestamp();
+               $won = wfInvertTimestamp( wfTimestamp(TS_MW,$now) );
 
                # Rename cur entry
                $dbw->updateArray( 'cur',
@@ -1100,8 +1108,9 @@ class Title {
                
                $wgLinkCache->clearLink( $nt->getPrefixedDBkey() );
 
-               # Insert redirct
+               # Insert redirect
                $dbw->insertArray( 'cur', array(
+                       'cur_id' => $dbw->nextSequenceValue('cur_cur_id_seq'),
                        'cur_namespace' => $this->getNamespace(),
                        'cur_title' => $this->getDBkey(),
                        'cur_comment' => $comment,
@@ -1252,82 +1261,54 @@ class Title {
        
        # Get categories to wich belong this title and return an array of
        # categories names.
-       function getParentCategories( ) {
+       # Return an array of parents in the form:
+       #  $parent => $currentarticle
+       function getParentCategories() {
                global $wgLang,$wgUser;
                
                $titlekey = $this->getArticleId();
-               $cns = Namespace::getCategory();
                $sk =& $wgUser->getSkin();
                $parents = array();
                $dbr =& wfGetDB( DB_SLAVE );
                $cur = $dbr->tableName( 'cur' );
                $categorylinks = $dbr->tableName( 'categorylinks' );
 
-               # get the parents categories of this title from the database
-               $sql = "SELECT DISTINCT cur_id FROM $cur,$categorylinks
-                       WHERE cl_from='$titlekey' AND cl_to=cur_title AND cur_namespace='$cns'
-                               ORDER BY cl_sortkey" ;
+               # NEW SQL
+               $sql = "SELECT * FROM categorylinks"
+                    ." WHERE cl_from='$titlekey'"
+                        ." AND cl_from <> '0'"
+                        ." ORDER BY cl_sortkey";
+               
                $res = $dbr->query ( $sql ) ;
                
                if($dbr->numRows($res) > 0) {
-                       while ( $x = $dbr->fetchObject ( $res ) ) $data[] = $x ;
+                       while ( $x = $dbr->fetchObject ( $res ) )
+                               //$data[] = Title::newFromText($wgLang->getNSText ( NS_CATEGORY ).':'.$x->cl_to);
+                               $data[$wgLang->getNSText ( NS_CATEGORY ).':'.$x->cl_to] = $this->getFullText();
                        $dbr->freeResult ( $res ) ;
                } else {
                        $data = '';
                }
                return $data;
        }
-       
-       # will get the parents and grand-parents
-       # TODO : not sure what's happening when a loop happen like:
-       #       Encyclopedia > Astronomy > Encyclopedia
-       function getAllParentCategories(&$stack) {
-               global $wgUser,$wgLang;
-               $result = '';
-               
-               # getting parents
-               $parents = $this->getParentCategories( );
 
-               if($parents == '')
-               {
-                       # The current element has no more parent so we dump the stack
-                       # and make a clean line of categories
-                       $sk =& $wgUser->getSkin() ;
-
-                       foreach ( array_reverse($stack) as $child => $parent )
+       # Go through all parents
+       function getCategorieBrowser() {
+               $parents = $this->getParentCategories();
+               
+               if($parents != '') {
+                       foreach($parents as $parent => $current)
                        {
-                               # make a link of that parent
-                               $result .= $sk->makeLink($wgLang->getNSText ( Namespace::getCategory() ).':'.$parent,$parent);
-                               $result .= ' &gt; ';
-                               $lastchild = $child;
+                               $nt = Title::newFromText($parent);
+                               $stack[$parent] = $nt->getCategorieBrowser();
                        }
-                       # append the last child.
-                       # TODO : We should have a last child unless there is an error in the
-                       # "categorylinks" table.
-                       if(isset($lastchild)) { $result .= $lastchild; }
-                       
-                       $result .= "<br/>\n";
-                       
-                       # now we can empty the stack
-                       $stack = array();
-                       
+                       return $stack;
                } else {
-                       # look at parents of current category
-                       foreach($parents as $parent)
-                       {
-                               # create a title object for the parent
-                               $tpar = Title::newFromID($parent->cur_id);
-                               # add it to the stack
-                               $stack[$this->getText()] = $tpar->getText();
-                               # grab its parents
-                               $result .= $tpar->getAllParentCategories($stack);
-                       }
+                       return array();
                }
-
-               if(isset($result)) { return $result; }
-               else { return ''; };
        }
        
+       
        # Returns an associative array for selecting this title from cur
        function curCond() {
                return array( 'cur_namespace' => $this->mNamespace, 'cur_title' => $this->mDbkeyform );