Back out kturner's old table restructure for now.
authorBrion Vibber <brion@users.mediawiki.org>
Sun, 26 Sep 2004 19:49:44 +0000 (19:49 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Sun, 26 Sep 2004 19:49:44 +0000 (19:49 +0000)
This will require downtiime on upgrade, so we're not going to do it until we have a better idea of the cost and can make all necessary changes at once to minimize it.

includes/Article.php
includes/DifferenceEngine.php
includes/EditPage.php
includes/PageHistory.php
includes/SpecialAsksql.php
includes/SpecialContributions.php
includes/SpecialUndelete.php
includes/Title.php
maintenance/tables.sql
maintenance/updaters.inc

index aba9799..7dc3727 100644 (file)
@@ -382,7 +382,7 @@ class Article {
        function &getOldContentFields() {
                global $wgArticleOldContentFields;
                if ( !$wgArticleOldContentFields ) {
-                       $wgArticleOldContentFields = array( 'old_articleid','old_text','old_timestamp',
+                       $wgArticleOldContentFields = array( 'old_namespace','old_title','old_text','old_timestamp',
                          'old_user','old_user_text','old_comment','old_flags' );
                }
                return $wgArticleOldContentFields;
@@ -475,8 +475,9 @@ class Article {
                                return;
                        }
 
-                       if( $this->mTitle->getArticleID() != $s->old_articleid ) {
-                               $oldTitle = Title::newFromID( $s->old_articleid );
+                       if( $this->mTitle->getNamespace() != $s->old_namespace ||
+                               $this->mTitle->getDBkey() != $s->old_title ) {
+                               $oldTitle = Title::makeTitle( $s->old_namesapce, $s->old_title );
                                $this->mTitle = $oldTitle;
                                $wgTitle = $oldTitle;
                        }
@@ -707,13 +708,14 @@ class Article {
                $dbr =& $this->getDB();
                $oldTable = $dbr->tableName( 'old' );
                $userTable = $dbr->tableName( 'user' );
-               $artid = $title->getArticleID();
+               $encDBkey = $dbr->addQuotes( $title->getDBkey() );
                $ns = $title->getNamespace();
                $user = $this->getUser();
 
                $sql = "SELECT old_user, old_user_text, user_real_name, MAX(old_timestamp) as timestamp
                        FROM $oldTable LEFT JOIN $userTable ON old_user = user_id
-                       WHERE old_articleid = $artid
+                       WHERE old_namespace = $user
+                       AND old_title = $encDBkey
                        AND old_user != $user
                        GROUP BY old_user, old_user_text, user_real_name
                        ORDER BY timestamp DESC";
@@ -949,10 +951,9 @@ class Article {
                        $dbw =& wfGetDB( DB_MASTER );
                        $ns = $this->mTitle->getNamespace();
                        $title = $this->mTitle->getDBkey();
-                       $aid = $this->mTitle->getArticleID();
                        $obj = $dbw->getArray( 'old', 
                                array( 'old_text','old_flags'), 
-                               array( 'old_articleid' => $aid
+                               array( 'old_namespace' => $ns, 'old_title' => $title
                                        'old_timestamp' => $dbw->timestamp($edittime)),
                                $fname );
                        $oldtext = Article::getRevisionText( $obj );
@@ -1111,7 +1112,8 @@ class Article {
                                $dbw->insertArray( 'old',
                                        array(
                                                'old_id' => $dbw->nextSequenceValue( 'old_old_id_seq' ),
-                                               'old_articleid' => $this->mTitle->getArticleID(),
+                                               'old_namespace' => $this->mTitle->getNamespace(),
+                                               'old_title' => $this->mTitle->getDBkey(),
                                                'old_text' => $oldtext,
                                                'old_comment' => $this->getComment(),
                                                'old_user' => $this->getUser(),
@@ -1468,11 +1470,12 @@ class Article {
                $dbr =& $this->getDB();
                $ns = $this->mTitle->getNamespace();
                $title = $this->mTitle->getDBkey();
-               $artid = $this->mTitle->getArticleID();
                $old = $dbr->getArray( 'old',
                        array( 'old_text', 'old_flags' ),
-                       array( 'old_articleid' => $artid ),
-                       $fname, $this->getSelectOptions( array( 'ORDER BY' => 'inverse_timestamp' ) )
+                       array(
+                               'old_namespace' => $ns,
+                               'old_title' => $title,
+                       ), $fname, $this->getSelectOptions( array( 'ORDER BY' => 'inverse_timestamp' ) )
                );
 
                if( $old !== false && !$confirm ) {
@@ -1668,7 +1671,6 @@ class Article {
                $recentchangesTable = $dbw->tableName( 'recentchanges' );
                $linksTable = $dbw->tableName( 'links' );
                $brokenlinksTable = $dbw->tableName( 'brokenlinks' );
-               $artid = $this->mTitle->getArticleID();
 
                $dbw->insertSelect( 'archive', 'cur',
                        array(
@@ -1687,10 +1689,10 @@ class Article {
                        ), $fname
                );
 
-               $dbw->insertSelect( 'archive', 'cur,old',
+               $dbw->insertSelect( 'archive', 'old',
                        array(
-                               'ar_namespace' => 'cur_namespace',
-                               'ar_title' => 'cur_title',
+                               'ar_namespace' => 'old_namespace',
+                               'ar_title' => 'old_title',
                                'ar_text' => 'old_text',
                                'ar_comment' => 'old_comment',
                                'ar_user' => 'old_user',
@@ -1699,14 +1701,15 @@ class Article {
                                'ar_minor_edit' => 'old_minor_edit',
                                'ar_flags' => 'old_flags'
                        ), array(
-                               'old_articleid' => $artid
+                               'old_namespace' => $ns,
+                               'old_title' => $t,
                        ), $fname
                );
 
                # Now that it's safely backed up, delete it
 
                $dbw->delete( 'cur', array( 'cur_namespace' => $ns, 'cur_title' => $t ), $fname );
-               $dbw->delete( 'old', array( 'old_articleid' => $artid ), $fname );
+               $dbw->delete( 'old', array( 'old_namespace' => $ns, 'old_title' => $t ), $fname );
                $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), $fname );
 
                # Finally, clean up the link tables
@@ -1798,9 +1801,10 @@ class Article {
                $s = $dbw->getArray( 'old',
                        array( 'old_text','old_user','old_user_text','old_timestamp','old_flags' ),
                        array(
-                               'old_articleid' => $pid,
+                               'old_namespace' => $n,
+                               'old_title' => $tt,
                                "old_user <> {$uid} OR old_user_text <> '{$ut}'"
-                       ), $fname, array( 'FOR UPDATE', 'USE INDEX' => 'articleid_timestamp' )
+                       ), $fname, array( 'FOR UPDATE', 'USE INDEX' => 'name_title_timestamp' )
                );
                if( $s === false ) {
                        # Something wrong
@@ -2013,7 +2017,8 @@ class Article {
                # Save to history
                $dbw->insertSelect( 'old', 'cur',
                        array(
-                               'old_articleid' => 'cur_id',
+                               'old_namespace' => 'cur_namespace',
+                               'old_title' => 'cur_title',
                                'old_text' => 'cur_text',
                                'old_comment' => 'cur_comment',
                                'old_user' => 'cur_user',
@@ -2167,7 +2172,7 @@ class Article {
 
                $basenamespace = $wgTitle->getNamespace() & (~1);
                $cur_clause = array( 'cur_title' => $wgTitle->getDBkey(), 'cur_namespace' => $basenamespace );
-               $old_clause = array( 'old_articleid' => $wgTitle->getArticleID() );
+               $old_clause = array( 'old_title' => $wgTitle->getDBkey(), 'old_namespace' => $basenamespace );
                $wl_clause  = array( 'wl_title' => $wgTitle->getDBkey(), 'wl_namespace' => $basenamespace );
                $fullTitle = $wgTitle->makeName($basenamespace, $wgTitle->getDBKey());
                $wgOut->setPagetitle(  $fullTitle );
@@ -2200,15 +2205,13 @@ class Article {
 
                        # now for the Talk page ...
                        $cur_clause = array( 'cur_title' => $wgTitle->getDBkey(), 'cur_namespace' => $basenamespace+1 );
+                       $old_clause = array( 'old_title' => $wgTitle->getDBkey(), 'old_namespace' => $basenamespace+1 );
 
                        # does it exist?
                        $exists = $dbr->selectField( 'cur', 'COUNT(*)', $cur_clause, $fname, $this->getSelectOptions() );
 
                        # number of edits
                        if ($exists > 0) {
-                               $oldartid = $dbr->selectField( 'cur', 'cur_id', 
-                                       $cur_clause, $fname, $this->getSelectOptions());
-                               $old_clause = array( 'old_articleid' => $oldartid );
                                $old = $dbr->selectField( 'old', 'COUNT(*)', $old_clause, $fname, $this->getSelectOptions() );
                                $wgOut->addHTML( '<li>' . wfMsg("numtalkedits", $old + 1) . '</li>');
                        }
index 0998dcb..198c9b3 100644 (file)
@@ -27,7 +27,8 @@ class DifferenceEngine {
                        $this->mNewid = intval($old);
                        $dbr =& wfGetDB( DB_SLAVE );
                        $this->mOldid = $dbr->selectField( 'old', 'old_id',
-                               "old_articleid = " . $wgTitle->getArticleID() .
+                               "old_title='" . $wgTitle->getDBkey() . "'" .
+                               ' AND old_namespace=' . $wgTitle->getNamespace() .
                                " AND old_id<{$this->mNewid} ORDER BY old_id DESC" );
 
                } elseif ( 'next' == $new ) {
@@ -38,7 +39,8 @@ class DifferenceEngine {
                        $this->mOldid = intval($old);
                        $dbr =& wfGetDB( DB_SLAVE );
                        $this->mNewid = $dbr->selectField( 'old', 'old_id',
-                               "old_articleid = " . $wgTitle->getArticleID() .
+                               "old_title='" . $wgTitle->getDBkey() . "'" .
+                               ' AND old_namespace=' . $wgTitle->getNamespace() .
                                " AND old_id>{$this->mOldid} ORDER BY old_id " );
                        if ( false === $this->mNewid ) {
                                # if no result, NewId points to the newest old revision. The only newer
@@ -271,7 +273,7 @@ class DifferenceEngine {
                        $this->mNewUser = $s->cur_user_text;
                        $this->mNewComment = $s->cur_comment;
                } else {
-                       $s = $dbr->getArray( 'old', array( 'old_articleid', 'old_timestamp', 'old_text',
+                       $s = $dbr->getArray( 'old', array( 'old_namespace','old_title','old_timestamp', 'old_text',
                                'old_flags','old_user_text','old_comment' ), array( 'old_id' => $this->mNewid ), $fname );
 
                        if ( $s === false ) {
@@ -282,7 +284,7 @@ class DifferenceEngine {
                        $this->mNewtext = Article::getRevisionText( $s );
 
                        $t = $wgLang->timeanddate( $s->old_timestamp, true );
-                       $this->mNewPage = Title::newFromID( $s->old_articleid );
+                       $this->mNewPage = Title::MakeTitle( $s->old_namespace, $s->old_title );
                        $newLink = $wgTitle->getLocalUrl ('oldid=' . $this->mNewid);
                        $this->mPagetitle = wfMsg( 'revisionasof', $t );
                        $this->mNewtitle = "<a href='$newLink'>{$this->mPagetitle}</a>";
@@ -291,10 +293,11 @@ class DifferenceEngine {
                }
                if ( 0 == $this->mOldid ) {
                        $s = $dbr->getArray( 'old',
-                               array( 'old_timestamp','old_text', 'old_flags','old_user_text','old_comment' ),
+                               array( 'old_namespace','old_title','old_timestamp','old_text', 'old_flags','old_user_text','old_comment' ),
                                array( /* WHERE */
-                                       'old_articleid' => $this->mNewPage->getArticleID(),
-                               ), $fname, array( 'ORDER BY' => 'inverse_timestamp', 'USE INDEX' => 'articleid_timestamp' )
+                                       'old_namespace' => $this->mNewPage->getNamespace(),
+                                       'old_title' => $this->mNewPage->getDBkey()
+                               ), $fname, array( 'ORDER BY' => 'inverse_timestamp', 'USE INDEX' => 'name_title_timestamp' )
                        );
                        if ( $s === false ) {
                                wfDebug( 'Unable to load ' . $this->mNewPage->getPrefixedDBkey . " from old\n" );
@@ -302,7 +305,7 @@ class DifferenceEngine {
                        }
                } else {
                        $s = $dbr->getArray( 'old',
-                               array( 'old_timestamp','old_text','old_flags','old_user_text','old_comment'),
+                               array( 'old_namespace','old_title','old_timestamp','old_text','old_flags','old_user_text','old_comment'),
                                array( 'old_id' => $this->mOldid ),
                                $fname
                        );
@@ -311,7 +314,7 @@ class DifferenceEngine {
                                return false;
                        }
                }
-               $this->mOldPage = Title::newFromID( $wgTitle->getArticleID() );
+               $this->mOldPage = Title::MakeTitle( $s->old_namespace, $s->old_title );
                $this->mOldtext = Article::getRevisionText( $s );
 
                $t = $wgLang->timeanddate( $s->old_timestamp, true );
index 38c3d1b..67ea7ca 100644 (file)
@@ -621,7 +621,7 @@ htmlspecialchars( $wgContLang->recodeForEdit( $this->textbox1 ) ) .
                $title = $this->mTitle->getDBkey();
                $obj = $dbw->getArray( 'old', 
                        array( 'old_text','old_flags'), 
-                       array( 'old_articleid' => $this->mTitle->getArticleID()
+                       array( 'old_namespace' => $ns, 'old_title' => $title
                                'old_timestamp' => $dbw->timestamp($oldDate)),
                        $fname );
                $oldText = Article::getRevisionText( $obj );
index a3768af..f0c8a8a 100644 (file)
@@ -61,13 +61,14 @@ class PageHistory {
                $title = $this->mTitle->getText();
 
                $db =& wfGetDB( DB_SLAVE );
-               $use_index = $db->useIndexClause( 'articleid_timestamp' );
+               $use_index = $db->useIndexClause( 'name_title_timestamp' );
                $oldtable = $db->tableName( 'old' );
 
                $sql = "SELECT old_id,old_user," .
                  "old_comment,old_user_text,old_timestamp,old_minor_edit ".
                  "FROM $oldtable $use_index " .
-                 "WHERE old_articleid='" . $db->strencode( $this->mTitle->getArticleID() ) . "' " .
+                 "WHERE old_namespace={$namespace} AND " .
+                 "old_title='" . $db->strencode( $this->mTitle->getDBkey() ) . "' " .
                  "ORDER BY inverse_timestamp".$db->limitResult($limitplus,$rawoffset);
                $res = $db->query( $sql, $fname );
 
index 85749ec..1876d81 100644 (file)
@@ -154,9 +154,10 @@ class SqlQueryForm {
                                        $r .= "<tr>";
                                        foreach ( $k as $x ) {
                                                $o = $y->$x ;
-                                               if ( $x == "cur_title" or $x == "rc_title") {
+                                               if ( $x == "cur_title" or $x == "old_title" or $x == "rc_title") {
                                                        $namespace = 0;
                                                        if( $x == "cur_title" ) $namespace = $y->cur_namespace;
+                                                       if( $x == "old_title" ) $namespace = $y->old_namespace;
                                                        if( $x == "rc_title" ) $namespace = $y->rc_namespace;
                                                        if( $namespace ) $o = $wgContLang->getNsText( $namespace ) . ":" . $o;
                                                        $o = "<a href=\"" . wfLocalUrlE($o) . "\" class='internal'>" .
index dc0901f..9a97865 100644 (file)
@@ -86,7 +86,7 @@ function wfSpecialContributions( $par = '' ) {
                  "ORDER BY inverse_timestamp LIMIT {$querylimit}";
                $res1 = $dbr->query( $sql, $fname );
 
-               $sql = "SELECT old_articleid,old_timestamp,old_comment,old_minor_edit,old_user_text,old_id FROM $old " .
+               $sql = "SELECT old_namespace,old_title,old_timestamp,old_comment,old_minor_edit,old_user_text,old_id FROM $old " .
                  "WHERE old_user_text='" . $dbr->strencode( $nt->getText() ) . "' {$omq} " .
                  "ORDER BY inverse_timestamp LIMIT {$querylimit}";
                $res2 = $dbr->query( $sql, $fname );
@@ -95,7 +95,7 @@ function wfSpecialContributions( $par = '' ) {
                  "WHERE cur_user {$userCond} {$cmq} ORDER BY inverse_timestamp LIMIT {$querylimit}";
                $res1 = $dbr->query( $sql, $fname );
 
-               $sql = "SELECT old_articleid,old_timestamp,old_comment,old_minor_edit,old_user_text,old_id FROM $old " .
+               $sql = "SELECT old_namespace,old_title,old_timestamp,old_comment,old_minor_edit,old_user_text,old_id FROM $old " .
                  "WHERE old_user {$userCond} {$omq} ORDER BY inverse_timestamp LIMIT {$querylimit}";
                $res2 = $dbr->query( $sql, $fname );
        }
@@ -141,9 +141,8 @@ function wfSpecialContributions( $par = '' ) {
                        $oldid = false;
                        --$nCur;
                } else {
-                       $tt = Title::newFromID($obj2->old_articleid);
-                       $ns = $tt->getNamespace();
-                       $t = $tt->getDBkey();
+                       $ns = $obj2->old_namespace;
+                       $t = $obj2->old_title;
                        $ts = $obj2->old_timestamp;
                        $comment =$obj2->old_comment;
                        $me = $obj2->old_minor_edit;
index f0ebd8b..d213e56 100644 (file)
@@ -88,7 +88,7 @@ class PageArchive {
                global $wgUser, $wgOut, $wgLang, $wgDeferredUpdateList;
                global  $wgUseSquid, $wgInternalServer, $wgLinkCache;
 
-               $fname = "undelete";
+               $fname = "doUndeleteArticle";
 
                $dbw =& wfGetDB( DB_MASTER );
                extract( $dbw->tableNames( 'cur', 'archive', 'old' ) );
@@ -134,9 +134,9 @@ class PageArchive {
                        # We should merge.
                }
                
-               $sql = "INSERT INTO $old (old_articleid,old_text," .
+               $sql = "INSERT INTO $old (old_namespace,old_title,old_text," .
                  "old_comment,old_user,old_user_text,old_timestamp,inverse_timestamp,old_minor_edit," .
-                 "old_flags) SELECT ".$this->title->getArticleID().",ar_text,ar_comment," .
+                 "old_flags) SELECT ar_namespace,ar_title,ar_text,ar_comment," .
                  "ar_user,ar_user_text,ar_timestamp,99999999999999-ar_timestamp,ar_minor_edit,ar_flags " .
                  "FROM $archive WHERE ar_namespace={$namespace} AND ar_title='{$t}' {$oldones}";
                $dbw->query( $sql, $fname );
index a7639a3..a97eb34 100644 (file)
@@ -49,11 +49,10 @@ class Title {
                $this->mInterwiki = $this->mUrlform =
                $this->mTextform = $this->mDbkeyform = '';
                $this->mArticleID = -1;
-               $this->mID = -1;
                $this->mNamespace = 0;
                $this->mRestrictionsLoaded = false;
                $this->mRestrictions = array();
-               $this->mDefaultNamespace = 0;
+        $this->mDefaultNamespace = 0;
        }
 
        # From a prefixed DB key
@@ -969,8 +968,8 @@ class Title {
                $fname = 'Title::moveOverExistingRedirect';
                $comment = wfMsg( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
                
-               $now = wfTimestampNow();
-               $won = wfInvertTimestamp( $now );
+        $now = wfTimestampNow();
+        $won = wfInvertTimestamp( $now );
                $newid = $nt->getArticleID();
                $oldid = $this->getArticleID();
                $dbw =& wfGetDB( DB_MASTER );
@@ -1015,6 +1014,21 @@ class Title {
                
                $wgLinkCache->clearLink( $this->getPrefixedDBkey() );
 
+               # Fix the redundant names for the past revisions of the target page.
+               # The redirect should have no old revisions.
+               $dbw->updateArray(
+                       /* table */ 'old',
+                       /* SET */ array( 
+                               'old_namespace' => $nt->getNamespace(),
+                               'old_title' => $nt->getDBkey(),
+                       ),
+                       /* WHERE */ array( 
+                               'old_namespace' => $this->getNamespace(),
+                               'old_title' => $this->getDBkey(),
+                       ),
+                       $fname
+               );
+               
                RecentChange::notifyMoveOverRedirect( $now, $this, $nt, $wgUser, $comment );
 
                # Swap links
@@ -1122,6 +1136,19 @@ class Title {
                $newid = $dbw->insertId();
                $wgLinkCache->clearLink( $this->getPrefixedDBkey() );
 
+               # Rename old entries
+               $dbw->updateArray( 
+                       /* table */ 'old',
+                       /* SET */ array(
+                               'old_namespace' => $nt->getNamespace(),
+                               'old_title' => $nt->getDBkey()
+                       ),
+                       /* WHERE */ array(
+                               'old_namespace' => $this->getNamespace(),
+                               'old_title' => $this->getDBkey()
+                       ), $fname
+               );
+               
                # Record in RC
                RecentChange::notifyMoveToNew( $now, $this, $nt, $wgUser, $comment );
 
@@ -1181,7 +1208,8 @@ class Title {
                # Does the article have a history?
                $row = $dbw->getArray( 'old', array( 'old_id' ), 
                        array( 
-                               'old_articleid' => $nt->getArticleID()
+                               'old_namespace' => $nt->getNamespace(),
+                               'old_title' => $nt->getDBkey() 
                        ), $fname, 'FOR UPDATE' 
                );
 
@@ -1297,8 +1325,7 @@ class Title {
        }
 
        function oldCond() {
-               #return array( 'old_namespace' => $this->mNamespace, 'old_title' => $this->mDbkeyform );
-               return array( 'old_articleid' => $this->getArticleID() );
+               return array( 'old_namespace' => $this->mNamespace, 'old_title' => $this->mDbkeyform );
        }
 }
 ?>
index b81257d..2ffbacb 100644 (file)
@@ -50,7 +50,7 @@ CREATE TABLE cur (
   cur_touched char(14) binary NOT NULL default '',
   inverse_timestamp char(14) binary NOT NULL default '',
   PRIMARY KEY cur_id (cur_id),
-  INDEX name_title (cur_namespace,cur_title),
+  UNIQUE INDEX name_title (cur_namespace,cur_title),
   
   -- Is this one necessary?
   INDEX cur_title (cur_title(20)),
@@ -65,7 +65,8 @@ CREATE TABLE cur (
 
 CREATE TABLE old (
   old_id int(8) unsigned NOT NULL auto_increment,
-  old_articleid int(8) unsigned NOT NULL,
+  old_namespace tinyint(2) unsigned NOT NULL default '0',
+  old_title varchar(255) binary NOT NULL default '',
   old_text mediumtext NOT NULL default '',
   old_comment tinyblob NOT NULL default '',
   old_user int(5) unsigned NOT NULL default '0',
@@ -76,9 +77,8 @@ CREATE TABLE old (
   inverse_timestamp char(14) binary NOT NULL default '',
   
   PRIMARY KEY old_id (old_id),
-  INDEX articleid (old_articleid),
   INDEX old_timestamp (old_timestamp),
-  INDEX articleid_timestamp (old_articleid,inverse_timestamp),
+  INDEX name_title_timestamp (old_namespace,old_title,inverse_timestamp),
   INDEX user_timestamp (old_user,inverse_timestamp),
   INDEX usertext_timestamp (old_user_text,inverse_timestamp)
 );
@@ -328,7 +328,7 @@ CREATE TABLE logging (
   -- Key to the page affected. Where a user is the target,
   -- this will point to the user page.
   log_namespace tinyint unsigned NOT NULL default 0,
-  log_title varchar(255) binary NOT NULL default '',
+  log_title varchar(255) NOT NULL default '',
   
   -- Freeform text. Interpreted as edit history comments.
   log_comment varchar(255) NOT NULL default '',
index 87c5d03..78bfbfa 100644 (file)
@@ -27,7 +27,6 @@ $wgNewFields = array(
        array( 'recentchanges', 'rc_patrolled',     'patch-rc-patrol.sql' ),
        array( 'user',          'user_real_name',   'patch-user-realname.sql' ),
        array( 'user',          'user_token',       'patch-user_token.sql' ),
-       array( 'old',           'old_articleid',    'patch-remove-old-title-namespace.sql' ),
 );
 
 function add_table( $name, $patch ) {