Merge SCHEMA_WORK into HEAD. Lots of changes, some things are probably broken:
authorBrion Vibber <brion@users.mediawiki.org>
Sun, 19 Dec 2004 08:00:50 +0000 (08:00 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Sun, 19 Dec 2004 08:00:50 +0000 (08:00 +0000)
* Page moves/overwrites are a little iffy
* Compression might not be working right
* Profit!

60 files changed:
RELEASE-NOTES
Version.php [deleted file]
config/index.php
includes/Article.php
includes/CategoryPage.php
includes/Database.php
includes/DifferenceEngine.php
includes/EditPage.php
includes/HistoryBlob.php
includes/Image.php
includes/ImagePage.php
includes/LinkCache.php
includes/LinksUpdate.php
includes/MessageCache.php
includes/OutputPage.php
includes/PageHistory.php
includes/Parser.php
includes/RawPage.php
includes/RecentChange.php
includes/SearchEngine.php
includes/SearchMySQL3.php
includes/SearchMySQL4.php
includes/Setup.php
includes/SpecialAllmessages.php
includes/SpecialAllpages.php
includes/SpecialAncientpages.php
includes/SpecialAsksql.php
includes/SpecialBooksources.php
includes/SpecialBrokenRedirects.php
includes/SpecialContributions.php
includes/SpecialDeadendpages.php
includes/SpecialDisambiguations.php
includes/SpecialDoubleRedirects.php
includes/SpecialLog.php
includes/SpecialLonelypages.php
includes/SpecialMaintenance.php
includes/SpecialNewpages.php
includes/SpecialPopularpages.php
includes/SpecialRandompage.php
includes/SpecialRecentchangeslinked.php
includes/SpecialSearch.php
includes/SpecialShortpages.php
includes/SpecialStatistics.php
includes/SpecialUncategorizedpages.php
includes/SpecialWatchlist.php
includes/SpecialWhatlinkshere.php
includes/SquidUpdate.php
includes/Title.php
includes/User.php
languages/LanguageUtf8.php
maintenance/InitialiseMessages.inc
maintenance/archives/patch-restructure.sql [new file with mode: 0644]
maintenance/compressOld.inc
maintenance/convertUtf8.php
maintenance/parserTests.php
maintenance/tables.sql
maintenance/updaters.inc
tests/SearchEngineTest.php
tests/SearchMySQL3Test.php
tests/SearchMySQL4Test.php

index 5ce29b5..be4cb60 100644 (file)
@@ -12,10 +12,10 @@ New exciting things! Need further work and testing...
 * user groups/permissions scheme
 * e-mail change notifications
 * 'live preview' reduces preview reload burden on supported browsers
+* Schema reworking: http://meta.wikimedia.org/wiki/Proposed_Database_Schema_Changes/October_2004
 * ...and more!
 
 Need to merge:
-* SCHEMA_WORK
 * stuff
 
 
diff --git a/Version.php b/Version.php
deleted file mode 100644 (file)
index b963890..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<?php
-# The actual version number is in DefaultSettings.php
-# and can be seen through the wiki at [[Special:Version]]
-
-# This is for an ancient update item and probably is not
-# necessary.
-$wgSoftwareRevision = 1002;
-?>
index efed31f..f79af5b 100644 (file)
@@ -494,7 +494,7 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) {
 
                $wgDatabase->selectDB( $wgDBname );
 
-               if( $wgDatabase->tableExists( "cur" ) ) {
+               if( $wgDatabase->tableExists( "cur" ) || $wgDatabase->tableExists( "revision" ) ) {
                        print "<li>There are already MediaWiki tables in this database. Checking if updates are needed...</li>\n";
                        
                        # Create user if required
@@ -556,16 +556,26 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) {
                        $titleobj = Title::newFromText( wfMsgNoDB( "mainpage" ) );
                        $now = wfTimestampNow();
                        $won = wfInvertTimestamp( $now );
-                       $wgDatabase->insert( 'cur',
-                               array( 'cur_namespace'     => $titleobj->getNamespace(),
-                                      'cur_title'         => $titleobj->getDBkey(),
-                                      'cur_text'          => wfMsg( 'mainpagetext' ) . "\n\n" .
-                                                             wfMsg( 'mainpagedocfooter' ),
-                                      'cur_timestamp'     => $now,
-                                      'inverse_timestamp' => $won,
-                                      'cur_touched'       => $now,
-                                      'cur_user'          => 0,
-                                      'cur_user_text'     => 'MediaWiki default' ) );
+                       
+                       extract( $wgDatabase->tableNames( 'text', 'page', 'revision' ) );
+                       $titleobj = Title::newFromText( wfMsgNoDB( "mainpage" ) );
+                       $title = $titleobj->getDBkey();
+                       $sql = "INSERT INTO $text (old_text, old_flags) VALUES ('" .
+                               wfStrencode( wfMsg( "mainpagetext" ) . "\n\n" . wfMsg( "mainpagedocfooter" ) ) .
+                               "', '')";
+                       $wgDatabase->query( $sql, $fname );
+                       $text_id = $wgDatabase->insertID();
+
+                       $sql = "INSERT INTO $page (page_namespace, page_title, page_restrictions, page_counter, page_is_redirect, 
+                               page_is_new, page_random, page_touched, page_latest) VALUES (
+                               0, '{$title}', '', 0, 0, 1, 0.5, '{$now}', {$text_id} )";
+                       $wgDatabase->query( $sql, $fname );
+                       $page_id = $wgDatabase->insertID();
+
+                       $sql = "INSERT INTO $revision (rev_id, rev_page, rev_comment, rev_user, rev_user_text,
+                                       rev_timestamp, inverse_timestamp, rev_minor_edit)
+                               VALUES ({$text_id}, {$page_id}, '', 0, 'MediaWiki default', '{$now}', '{$won}', 0)";
+                       $wgDatabase->query( $sql, $fname );
 
                        print "<li><pre>";
                        initialiseMessages();
index 572583d..afeaacd 100644 (file)
@@ -32,6 +32,7 @@ class Article {
        var $mTouched, $mFileCache, $mTitle;
        var $mId, $mTable;
        var $mForUpdate;
+       var $mOldId;
        /**#@-*/
 
        /**
@@ -83,6 +84,7 @@ class Article {
                if( isset( $row->$textField ) ) {
                        $text = $row->$textField;
                } else {
+                       wfProfileOut( $fname );
                        return false;
                }
 
@@ -272,25 +274,11 @@ class Article {
        /**
         * Return an array of the columns of the "cur"-table
         */
-       function &getCurContentFields() {
-               global $wgArticleCurContentFields;
-               if ( !$wgArticleCurContentFields ) {
-                       $wgArticleCurContentFields = array( 'cur_text','cur_timestamp','cur_user', 'cur_user_text',
-                         'cur_comment','cur_counter','cur_restrictions','cur_touched' );
-               }
-               return $wgArticleCurContentFields;
-       }
-
-       /**
-        * Return an array of the columns of the "old"-table
-        */
-       function &getOldContentFields() {
-               global $wgArticleOldContentFields;
-               if ( !$wgArticleOldContentFields ) {
-                       $wgArticleOldContentFields = array( 'old_namespace','old_title','old_text','old_timestamp',
-                         'old_user','old_user_text','old_comment','old_flags' );
-               }
-               return $wgArticleOldContentFields;
+       function getContentFields() {
+               return $wgArticleContentFields = array(
+                 'old_text','old_flags',
+                 'rev_timestamp','rev_user', 'rev_user_text', 'rev_comment','page_counter',
+                 'page_namespace', 'page_title', 'page_restrictions','page_touched','page_is_redirect' );
        }
 
        /**
@@ -301,18 +289,18 @@ class Article {
        function getOldID() {
                global $wgRequest, $wgOut;
                static $lastid;
-
+               
                if ( isset( $lastid ) ) {
                        return $lastid;
                }
-
+               # Query variables :P
                $oldid = $wgRequest->getVal( 'oldid' );
                if ( isset( $oldid ) ) {
                        $dbr =& $this->getDB();
                        $oldid = IntVal( $oldid );
                        if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
                                $nextid = $this->mTitle->getNextRevisionID( $oldid );
-                               if ( $nextid ) {
+                               if ( $nextid  ) {
                                        $oldid = $nextid;
                                } else {
                                        $wgOut->redirect( $this->mTitle->getFullURL( 'redirect=no' ) );
@@ -333,7 +321,7 @@ class Article {
 
        /**
         * Load the revision (including cur_text) into this object
-       */
+        */
        function loadContent( $noredir = false ) {
                global $wgOut, $wgRequest;
 
@@ -351,85 +339,117 @@ class Article {
 
                $t = $this->mTitle->getPrefixedText();
 
-               if ( isset( $oldid ) ) {
+               $noredir = $noredir || ($wgRequest->getVal( 'redirect' ) == 'no');
+               $this->mOldId = $oldid;
+               $this->fetchContent( $oldid, $noredir, true );
+       }
+       
+       /**
+        * @param int $oldid 0 for whatever the latest revision is
+        * @param bool $noredir Set to true to avoid following redirects
+        * @param bool $globalTitle Set to true to change the global $wgTitle object when following redirects or other unexpected title changes
+        * @return string
+        */
+       function fetchContent( $oldid = 0, $noredir = false, $globalTitle = false ) {
+               if ( $this->mContentLoaded ) {
+                       return $this->mContent;
+               }
+               $dbr =& $this->getDB();
+               $fname = 'Article::fetchContent';
+
+               # Pre-fill content with error message so that if something
+               # fails we'll have something telling us what we intended.
+               $t = $this->mTitle->getPrefixedText();
+               if( $oldid ) {
                        $t .= ',oldid='.$oldid;
                }
-               if ( isset( $redirect ) ) {
+               if( isset( $redirect ) ) {
                        $redirect = ($redirect == 'no') ? 'no' : 'yes';
                        $t .= ',redirect='.$redirect;
                }
                $this->mContent = wfMsg( 'missingarticle', $t );
 
-               if ( ! $oldid ) {       # Retrieve current version
+               if( !$oldid ) {
+                       # Retrieve current version
                        $id = $this->getID();
-                       if ( 0 == $id ) return;
-
-                       $s = $dbr->selectRow( 'cur', $this->getCurContentFields(), array( 'cur_id' => $id ), $fname,
-                               $this->getSelectOptions() );
-                       if ( $s === false ) {
-                               return;
+                       if ( 0 == $id ) {
+                               return false;
                        }
 
-                       # If we got a redirect, follow it (unless we've been told
-                       # not to by either the function parameter or the query
-                       if ( ( 'no' != $redirect ) && ( false == $noredir ) ) {
-                               $rt = Title::newFromRedirect( $s->cur_text );
-                               # process if title object is valid and not special:userlogout
-                               if ( $rt && ! ( $rt->getNamespace() == NS_SPECIAL && $rt->getText() == 'Userlogout' ) ) {
-                                       # Gotta hand redirects to special pages differently:
-                                       # Fill the HTTP response "Location" header and ignore
-                                       # the rest of the page we're on.
+                       $s = $dbr->selectRow( array( 'text', 'revision', 'page' ),
+                               $this->getContentFields(),
+                               "page_id='$id' AND rev_page=page_id AND rev_id=page_latest AND old_id=rev_id",
+                               $fname, $this->getSelectOptions() );
+               } else {
+                       # Historical revision
+                       $s = $dbr->selectRow( array( 'text', 'revision', 'page' ),
+                               $this->getContentFields(),
+                               "rev_page=page_id AND rev_id='$oldid' AND old_id=rev_id",
+                               $fname, $this->getSelectOptions() );
+               }
+               if ( $s === false ) {
+                       return false;
+               }
 
+               # If we got a redirect, follow it (unless we've been told
+               # not to by either the function parameter or the query
+               if ( !$oldid && !$noredir ) {
+                       $rt = Title::newFromRedirect( Article::getRevisionText( $s ) );
+                       # process if title object is valid and not special:userlogout
+                       if ( $rt && ! ( $rt->getNamespace() == NS_SPECIAL && $rt->getText() == 'Userlogout' ) ) {
+                               # Gotta hand redirects to special pages differently:
+                               # Fill the HTTP response "Location" header and ignore
+                               # the rest of the page we're on.
+                               if( $globalTitle ) {
+                                       global $wgOut;
                                        if ( $rt->getInterwiki() != '' ) {
                                                $wgOut->redirect( $rt->getFullURL() ) ;
-                                               return;
+                                               return false;
                                        }
                                        if ( $rt->getNamespace() == NS_SPECIAL ) {
                                                $wgOut->redirect( $rt->getFullURL() );
-                                               return;
+                                               return false;
                                        }
-                                       $rid = $rt->getArticleID();
-                                       if ( 0 != $rid ) {
-                                               $redirRow = $dbr->selectRow( 'cur', $this->getCurContentFields(),
-                                                       array( 'cur_id' => $rid ), $fname, $this->getSelectOptions() );
-
-                                               if ( $redirRow !== false ) {
-                                                       $this->mRedirectedFrom = $this->mTitle->getPrefixedText();
-                                                       $this->mTitle = $rt;
-                                                       $s = $redirRow;
-                                               }
+                               }
+                               $rid = $rt->getArticleID();
+                               if ( 0 != $rid ) {
+                                       $redirRow = $dbr->selectRow( array( 'text', 'revision', 'page' ),
+                                               $this->getContentFields(),
+                                               "page_id='$rid' AND rev_page=page_id AND rev_id=page_latest AND old_id=rev_id",
+                                               $fname, $this->getSelectOptions() );
+
+                                       if ( $redirRow !== false ) {
+                                               $this->mRedirectedFrom = $this->mTitle->getPrefixedText();
+                                               $this->mTitle = $rt;
+                                               $s = $redirRow;
                                        }
                                }
                        }
+               }
 
-                       $this->mContent = $s->cur_text;
-                       $this->mUser = $s->cur_user;
-                       $this->mUserText = $s->cur_user_text;
-                       $this->mComment = $s->cur_comment;
-                       $this->mCounter = $s->cur_counter;
-                       $this->mTimestamp = wfTimestamp(TS_MW,$s->cur_timestamp);
-                       $this->mTouched = wfTimestamp(TS_MW,$s->cur_touched);
-                       $this->mTitle->loadRestrictions( $s->cur_restrictions );
-               } else { # oldid set, retrieve historical version
-                       $s = $dbr->selectRow( 'old', $this->getOldContentFields(), array( 'old_id' => $oldid ),
-                               $fname, $this->getSelectOptions() );
-                       if ( $s === false ) {
-                               return;
-                       }
-
-                       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;
-                       }
-                       $this->mContent = Article::getRevisionText( $s );
-                       $this->mUser = $s->old_user;
-                       $this->mUserText = $s->old_user_text;
-                       $this->mComment = $s->old_comment;
-                       $this->mCounter = 0;
-                       $this->mTimestamp = wfTimestamp(TS_MW,$s->old_timestamp);
+               # if the title's different from expected, update...
+               if( $globalTitle &&
+                       ( $this->mTitle->getNamespace() != $s->page_namespace ||
+                       $this->mTitle->getDBkey() != $s->page_title ) ) {
+                       $oldTitle = Title::makeTitle( $s->page_namesapce, $s->page_title );
+                       $this->mTitle = $oldTitle;
+                       global $wgTitle;
+                       $wgTitle = $oldTitle;
                }
+               
+               # Back to the business at hand...
+               $this->mCounter = $s->page_counter;
+               $this->mTitle->mRestrictions = explode( ',', trim( $s->page_restrictions ) );
+               $this->mTitle->mRestrictionsLoaded = true;
+               $this->mTouched = wfTimestamp( TS_MW, $s->page_touched );
+
+               $this->mContent = Article::getRevisionText( $s );
+               
+               $this->mUser = $s->rev_user;
+               $this->mUserText = $s->rev_user_text;
+               $this->mComment = $s->rev_comment;
+               $this->mTimestamp = wfTimestamp( TS_MW, $s->rev_timestamp );
+               
                $this->mContentLoaded = true;
                return $this->mContent;
        }
@@ -441,68 +461,7 @@ class Article {
         * @param integer $oldid
         */
        function getContentWithoutUsingSoManyDamnGlobals( $oldid = 0, $noredir = false ) {
-               if ( $this->mContentLoaded ) {
-                       return $this->mContent;
-               }
-               $this->mContent = false;
-
-               $fname = 'Article::getContentWithout';
-               $dbr =& $this->getDB();
-
-               if ( ! $oldid ) {       # Retrieve current version
-                       $id = $this->getID();
-                       if ( 0 == $id ) {
-                               return false;
-                       }
-
-                       $s = $dbr->selectRow( 'cur', $this->getCurContentFields(), array( 'cur_id' => $id ),
-                               $fname, $this->getSelectOptions() );
-                       if ( $s === false ) {
-                               return false;
-                       }
-
-                       # If we got a redirect, follow it (unless we've been told
-                       # not to by either the function parameter or the query
-                       if ( !$noredir ) {
-                               $rt = Title::newFromRedirect( $s->cur_text );
-                               if( $rt &&  $rt->getInterwiki() == '' && $rt->getNamespace() != NS_SPECIAL ) {
-                                       $rid = $rt->getArticleID();
-                                       if ( 0 != $rid ) {
-                                               $redirRow = $dbr->selectRow( 'cur', $this->getCurContentFields(),
-                                                       array( 'cur_id' => $rid ), $fname, $this->getSelectOptions() );
-
-                                               if ( $redirRow !== false ) {
-                                                       $this->mRedirectedFrom = $this->mTitle->getPrefixedText();
-                                                       $this->mTitle = $rt;
-                                                       $s = $redirRow;
-                                               }
-                                       }
-                               }
-                       }
-
-                       $this->mContent = $s->cur_text;
-                       $this->mUser = $s->cur_user;
-                       $this->mUserText = $s->cur_user_text;
-                       $this->mComment = $s->cur_comment;
-                       $this->mCounter = $s->cur_counter;
-                       $this->mTimestamp = wfTimestamp(TS_MW,$s->cur_timestamp);
-                       $this->mTouched = wfTimestamp(TS_MW,$s->cur_touched);
-                       $this->mTitle->loadRestrictions( $s->cur_restrictions );
-               } else { # oldid set, retrieve historical version
-                       $s = $dbr->selectRow( 'old', $this->getOldContentFields(), array( 'old_id' => $oldid ),
-                               $fname, $this->getSelectOptions() );
-                       if ( $s === false ) {
-                               return false;
-                       }
-                       $this->mContent = Article::getRevisionText( $s );
-                       $this->mUser = $s->old_user;
-                       $this->mUserText = $s->old_user_text;
-                       $this->mComment = $s->old_comment;
-                       $this->mCounter = 0;
-                       $this->mTimestamp = wfTimestamp(TS_MW,$s->old_timestamp);
-               }
-               $this->mContentLoaded = true;
-               return $this->mContent;
+               return $this->fetchContent( $oldid, $noredir, false );
        }
 
        /**
@@ -556,7 +515,7 @@ class Article {
                if ( -1 == $this->mCounter ) {
                        $id = $this->getID();
                        $dbr =& $this->getDB();
-                       $this->mCounter = $dbr->selectField( 'cur', 'cur_counter', 'cur_id='.$id,
+                       $this->mCounter = $dbr->selectField( 'page', 'page_counter', array( 'page_id' => $id ),
                                'Article::getCount', $this->getSelectOptions() );
                }
                return $this->mCounter;
@@ -590,27 +549,29 @@ class Article {
        }
 
        /**
-        * Loads everything from cur except cur_text
+        * Loads everything except the text
         * This isn't necessary for all uses, so it's only done if needed.
         * @private
         */
        function loadLastEdit() {
                global $wgOut;
-               if ( -1 != $this->mUser ) return;
+
+               if ( -1 != $this->mUser )
+                       return;
 
                $fname = 'Article::loadLastEdit';
 
                $dbr =& $this->getDB();
-               $s = $dbr->selectRow( 'cur',
-                 array( 'cur_user','cur_user_text','cur_timestamp', 'cur_comment','cur_minor_edit' ),
-                 array( 'cur_id' => $this->getID() ), $fname, $this->getSelectOptions() );
+               $s = $dbr->selectRow( array( 'revision', 'page') ,
+                 array( 'rev_user','rev_user_text','rev_timestamp', 'rev_comment','rev_minor_edit' ),
+                 array( 'page_id' => $this->getID(), 'page_latest=rev_id' ), $fname, $this->getSelectOptions() );
 
                if ( $s !== false ) {
-                       $this->mUser = $s->cur_user;
-                       $this->mUserText = $s->cur_user_text;
-                       $this->mTimestamp = wfTimestamp(TS_MW,$s->cur_timestamp);
-                       $this->mComment = $s->cur_comment;
-                       $this->mMinorEdit = $s->cur_minor_edit;
+                       $this->mUser = $s->rev_user;
+                       $this->mUserText = $s->rev_user_text;
+                       $this->mTimestamp = wfTimestamp(TS_MW,$s->rev_timestamp);
+                       $this->mComment = $s->rev_comment;
+                       $this->mMinorEdit = $s->rev_minor_edit;
                }
        }
 
@@ -647,18 +608,17 @@ class Article {
                $title = $this->mTitle;
                $contribs = array();
                $dbr =& $this->getDB();
-               $oldTable = $dbr->tableName( 'old' );
+               $revTable = $dbr->tableName( 'revision' );
                $userTable = $dbr->tableName( 'user' );
                $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_namespace = $user
-                       AND old_title = $encDBkey
+               $sql = "SELECT rev_user, rev_user_text, user_real_name, MAX(rev_timestamp) as timestamp
+                       FROM $revTable LEFT JOIN $userTable ON rev_user = user_id
+                       WHERE rev_page = $pageId
                        AND old_user != $user
-                       GROUP BY old_user, old_user_text, user_real_name
+                       GROUP BY rev_user, rev_user_text, user_real_name
                        ORDER BY timestamp DESC";
 
                if ($limit > 0) { $sql .= ' LIMIT '.$limit; }
@@ -667,7 +627,7 @@ class Article {
                $res = $dbr->query($sql, $fname);
 
                while ( $line = $dbr->fetchObject( $res ) ) {
-                       $contribs[] = array($line->old_user, $line->old_user_text, $line->user_real_name);
+                       $contribs[] = array($line->rev_user, $line->rev_user_text, $line->user_real_name);
                }
 
                $dbr->freeResult($res);
@@ -747,7 +707,7 @@ class Article {
                        # We're looking at an old revision
 
                        if ( !empty( $oldid ) ) {
-                               $this->setOldSubtitle( $oldid );
+                               $this->setOldSubtitle( isset($this->mOldId) ? $this->mOldId : $oldid );
                                $wgOut->setRobotpolicy( 'noindex,follow' );
                        }
                        if ( '' != $this->mRedirectedFrom ) {
@@ -836,32 +796,47 @@ class Article {
                $won = wfInvertTimestamp( $now );
                wfSeedRandom();
                $rand = wfRandom();
-               $dbw =& wfGetDB( DB_MASTER );
+               $isminor = ( $isminor && $wgUser->getID() ) ? 1 : 0;
+               
+               $mungedText = $text;
+               $flags = Article::compressRevisionText( $mungedText );
 
-               $cur_id = $dbw->nextSequenceValue( 'cur_cur_id_seq' );
+               $dbw =& wfGetDB( DB_MASTER );
 
-               $isminor = ( $isminor && $wgUser->getID() ) ? 1 : 0;
+               $old_id = $dbw->nextSequenceValue( 'text_old_id_seq' );
+               $dbw->insert( 'text', array(
+                       'old_id' => $old_id,
+                       'old_text' => $mungedText,
+                       'old_flags' => $flags,
+               ), $fname );
+               $revisionId = $dbw->insertId();
+               
+               $page_id = $dbw->nextSequenceValue( 'page_page_id_seq' );
+               $dbw->insert( 'page', array(
+                       'page_id' => $page_id,
+                       'page_namespace' => $ns,
+                       'page_title' => $ttl,
+                       'page_counter' => 0,
+                       'page_restrictions' => '',
+                       'page_is_redirect' => $redir,
+                       'page_is_new' => 1,
+                       'page_random' => $rand,
+                       'page_touched' => $dbw->timestamp($now),
+                       'page_latest' => $revisionId,
+               ), $fname );
+               $newid = $dbw->insertId();
 
-               $dbw->insert( 'cur', array(
-                       'cur_id' => $cur_id,
-                       'cur_namespace' => $ns,
-                       'cur_title' => $ttl,
-                       'cur_text' => $text,
-                       'cur_comment' => $summary,
-                       'cur_user' => $wgUser->getID(),
-                       'cur_timestamp' => $dbw->timestamp($now),
-                       'cur_minor_edit' => $isminor,
-                       'cur_counter' => 0,
-                       'cur_restrictions' => '',
-                       'cur_user_text' => $wgUser->getName(),
-                       'cur_is_redirect' => $redir,
-                       'cur_is_new' => 1,
-                       'cur_random' => $rand,
-                       'cur_touched' => $dbw->timestamp($now),
+               $dbw->insert( 'revision', array(
+                       'rev_page' => $newid,
+                       'rev_id' => $revisionId,
+                       'rev_comment' => $summary,
+                       'rev_user' => $wgUser->getID(),
+                       'rev_timestamp' => $dbw->timestamp($now),
+                       'rev_minor_edit' => $isminor,
+                       'rev_user_text' => $wgUser->getName(),
                        'inverse_timestamp' => $won,
                ), $fname );
 
-               $newid = $dbw->insertId();
                $this->mTitle->resetArticleID( $newid );
 
                Article::onArticleCreate( $this->mTitle );
@@ -877,8 +852,11 @@ class Article {
 
                # The talk page isn't in the regular link tables, so we need to update manually:
                $talkns = $ns ^ 1; # talk -> normal; normal -> talk
-               $dbw->update( 'cur', array('cur_touched' => $dbw->timestamp($now) ),
-                       array(  'cur_namespace' => $talkns, 'cur_title' => $ttl ), $fname );
+               $dbw->update( 'page',
+                       array( 'page_touched' => $dbw->timestamp($now) ),
+                       array( 'page_namespace' => $talkns,
+                              'page_title' => $ttl ),
+                       $fname );
 
                # standard deferred updates
                $this->editUpdates( $text, $summary, $isminor, $now );
@@ -887,25 +865,42 @@ class Article {
                $this->showArticle( $text, wfMsg( 'newarticle' ), false, $isminor, $now, $summary, $oldid );
        }
 
-
        /**
-        * Side effects: loads last edit if $edittime is NULL
+        * Fetch and uncompress the text for a given revision.
+        * Can ask by rev_id number or timestamp (set $field)
         */
+       function fetchRevisionText( $revId = null, $field = 'rev_id' ) {
+               $fname = 'Article::fetchRevisionText';
+               $dbw =& wfGetDB( DB_MASTER );
+               if( $revId ) {
+                       $rev = $dbw->addQuotes( $revId );
+               } else {
+                       $rev = 'page_latest';
+               }
+               $result = $dbw->query(
+                       sprintf( "SELECT old_text, old_flags
+                               FROM %s,%s,%s
+                               WHERE old_id=rev_id AND rev_page=page_id AND page_id=%d
+                               AND %s=%s",
+                               $dbw->tableName( 'page' ),
+                               $dbw->tableName( 'revision' ),
+                               $dbw->tableName( 'text' ),
+                               IntVal( $this->mTitle->getArticleId() ),
+                               $field,
+                               $rev ),
+                       $fname );
+               $obj = $dbw->fetchObject( $result );
+               $dbw->freeResult( $result );
+               $oldtext = Article::getRevisionText( $obj );
+               return $oldtext;
+       }
+       
        function getTextOfLastEditWithSectionReplacedOrAdded($section, $text, $summary = '', $edittime = NULL) {
                $fname = 'Article::getTextOfLastEditWithSectionReplacedOrAdded';
-               if(is_null($edittime)) {
-                       $this->loadLastEdit();
-                       $oldtext = $this->getContent( true );
+               if( is_null( $edittime ) ) {
+                       $oldtext = $this->fetchRevisionText();
                } else {
-                       $dbw =& wfGetDB( DB_MASTER );
-                       $ns = $this->mTitle->getNamespace();
-                       $title = $this->mTitle->getDBkey();
-                       $obj = $dbw->selectRow( 'old', 
-                               array( 'old_text','old_flags'), 
-                               array( 'old_namespace' => $ns, 'old_title' => $title, 
-                                       'old_timestamp' => $dbw->timestamp($edittime)),
-                               $fname );
-                       $oldtext = Article::getRevisionText( $obj );
+                       $oldtext = $this->fetchRevisionText( $edittime, 'rev_timestamp' );
                }
                if ($section != '') {
                        if($section=='new') {
@@ -1030,22 +1025,47 @@ class Article {
                        $now = wfTimestampNow();
                        $won = wfInvertTimestamp( $now );
 
-                       # First update the cur row
-                       $dbw->update( 'cur',
-                               array( /* SET */
-                                       'cur_text' => $text,
-                                       'cur_comment' => $summary,
-                                       'cur_minor_edit' => $me2,
-                                       'cur_user' => $wgUser->getID(),
-                                       'cur_timestamp' => $dbw->timestamp($now),
-                                       'cur_user_text' => $wgUser->getName(),
-                                       'cur_is_redirect' => $redir,
-                                       'cur_is_new' => 0,
-                                       'cur_touched' => $dbw->timestamp($now),
+                       $mungedText = $text;
+                       $flags = Article::compressRevisionText( $newtext );
+                       
+                       $lastRevision = $dbw->selectField(
+                               'page', 'page_latest', array( 'page_id' => $this->getId() ) );
+                       
+                       # Record the text to the text table
+                       $old_id = $dbw->nextSequenceValue( 'text_old_id_val' );
+                       $dbw->insert( 'text',
+                               array(
+                                       'old_id' => $old_id,
+                                       'old_text' => $mungedText,
+                                       'old_flags' => $flags,
+                               ), $fname
+                       );
+                       $revisionId = $dbw->insertId();
+                       
+                       # Record the edit in revisions
+                       $dbw->insert( 'revision',
+                               array(
+                                       'rev_id' => $revisionId,
+                                       'rev_page' => $this->getID(),
+                                       'rev_comment' => $summary,
+                                       'rev_minor_edit' => $me2,
+                                       'rev_user' => $wgUser->getID(),
+                                       'rev_user_text' => $wgUser->getName(),
+                                       'rev_timestamp' => $dbw->timestamp( $now ),
                                        'inverse_timestamp' => $won
+                               ), $fname
+                       );
+                       
+                       # Update page
+                       $dbw->update( 'page',
+                               array( /* SET */
+                                       'page_latest' => $revisionId,
+                                       'page_touched' => $dbw->timestamp( $now ),
+                                       'page_is_new' => 0,
+                                       'page_is_redirect' => $redir,
                                ), array( /* WHERE */
-                                       'cur_id' => $this->getID(),
-                                       'cur_timestamp' => $dbw->timestamp($this->getTimestamp())
+                                       'page_id' => $this->getID(),
+                                       'page_latest' => $lastRevision, # Paranoia
                                ), $fname
                        );
 
@@ -1053,32 +1073,10 @@ class Article {
                                /* Belated edit conflict! Run away!! */
                                $good = false;
                        } else {
-                               # Now insert the previous revision into old
-
-                               # This overwrites $oldtext if revision compression is on
-                               $flags = Article::compressRevisionText( $oldtext );
-
-                               $dbw->insert( 'old',
-                                       array(
-                                               'old_id' => $dbw->nextSequenceValue( 'old_old_id_seq' ),
-                                               'old_namespace' => $this->mTitle->getNamespace(),
-                                               'old_title' => $this->mTitle->getDBkey(),
-                                               'old_text' => $oldtext,
-                                               'old_comment' => $this->getComment(),
-                                               'old_user' => $this->getUser(),
-                                               'old_user_text' => $this->getUserText(),
-                                               'old_timestamp' => $dbw->timestamp($this->getTimestamp()),
-                                               'old_minor_edit' => $me1,
-                                               'inverse_timestamp' => wfInvertTimestamp( $this->getTimestamp() ),
-                                               'old_flags' => $flags,
-                                       ), $fname
-                               );
-
-                               $oldid = $dbw->insertId();
-
+                               # Update recentchanges and purge cache and whatnot
                                $bot = (int)($wgUser->isBot() || $forceBot);
                                RecentChange::notifyEdit( $now, $this->mTitle, $me2, $wgUser, $summary,
-                                       $oldid, $this->getTimestamp(), $bot );
+                                       $lastRevision, $this->getTimestamp(), $bot );
                                Article::onArticleEdit( $this->mTitle );
                        }
                }
@@ -1121,7 +1119,7 @@ class Article {
                        $u->doUpdate();
                }
 
-               $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $me2, $now, $summary, $oldid );
+               $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $me2, $now, $summary, $revisionId );
                }
                return $good;
        }
@@ -1317,6 +1315,15 @@ class Article {
                $reason = $wgRequest->getText( 'wpReasonProtect' );
 
                if ( $confirm ) {
+                       $dbw =& wfGetDB( DB_MASTER );
+                       $dbw->update( 'page',
+                               array( /* SET */
+                                       'page_touched' => $dbw->timestamp(),
+                                       'page_restrictions' => (string)$limit
+                               ), array( /* WHERE */
+                                       'page_id' => $id
+                               ), 'Article::protect'
+                       );
 
                        $restrictions = "move=" . $limit;
                        if( !$moveonly ) {
@@ -2010,11 +2017,11 @@ class Article {
                $fname = 'Article::checkTouched';
                $id = $this->getID();
                $dbr =& $this->getDB();
-               $s = $dbr->selectRow( 'cur', array( 'cur_touched', 'cur_is_redirect' ),
-                       array( 'cur_id' => $id ), $fname, $this->getSelectOptions() );
+               $s = $dbr->selectRow( 'page', array( 'page_touched', 'page_is_redirect' ),
+                       array( 'page_id' => $id ), $fname, $this->getSelectOptions() );
                if( $s !== false ) {
-                       $this->mTouched = wfTimestamp(TS_MW,$s->cur_touched);
-                       return !$s->cur_is_redirect;
+                       $this->mTouched = wfTimestamp( TS_MW, $s->page_touched );
+                       return !$s->page_is_redirect;
                } else {
                        return false;
                }
@@ -2030,6 +2037,9 @@ class Article {
        function quickEdit( $text, $comment = '', $minor = 0 ) {
                global $wgUser;
                $fname = 'Article::quickEdit';
+
+               #wfDebugDieBacktrace( "$fname called." );
+
                wfProfileIn( $fname );
 
                $dbw =& wfGetDB( DB_MASTER );
@@ -2037,7 +2047,34 @@ class Article {
                $dbkey = $this->mTitle->getDBkey();
                $encDbKey = $dbw->strencode( $dbkey );
                $timestamp = wfTimestampNow();
-
+               # insert new text
+               $dbw->insert( 'text', array(
+                               'old_text' => $text,
+                               'old_flags' => "" ), $fname );
+               $text_id = $dbw->insertID();
+
+               # update page
+               $dbw->update( 'page', array(
+                       'page_is_new' => 0,
+                       'page_touched' => $timestamp,
+                       'page_is_redirect' => $this->isRedirect( $text ) ? 1 : 0,
+                       'page_latest' => $text_id ),
+                       array( 'page_namespace' => $ns, 'page_title' => $dbkey ), $fname );
+               # Retrieve page ID
+               $page_id = $dbw->selectField( 'page', 'page_id', array( 'page_namespace' => $ns, 'page_title' => $dbkey ), $fname );
+
+               # update revision
+               $dbw->insert( 'revision', array(
+                       'rev_id' => $text_id,
+                       'rev_page' => $page_id,
+                       'rev_comment' => $comment,
+                       'rev_user' => $wgUser->getID(),
+                       'rev_user_text' => $wgUser->getName(),
+                       'rev_timestamp' => $timestamp,
+                       'inverse_timestamp' => wfInvertTimestamp( $timestamp ),
+                       'rev_minor_edit' => intval($minor) ),
+                       $fname );
+/*
                # Save to history
                $dbw->insertSelect( 'old', 'cur',
                        array(
@@ -2083,6 +2120,7 @@ class Article {
                        $fields['cur_random'] = $rand = wfRandom();
                        $dbw->insert( 'cur', $fields, $fname );
                }
+*/
                wfProfileOut( $fname );
        }
 
@@ -2097,12 +2135,12 @@ class Article {
                global $wgHitcounterUpdateFreq;
 
                $dbw =& wfGetDB( DB_MASTER );
-               $curTable = $dbw->tableName( 'cur' );
+               $pageTable = $dbw->tableName( 'page' );
                $hitcounterTable = $dbw->tableName( 'hitcounter' );
                $acchitsTable = $dbw->tableName( 'acchits' );
 
                if( $wgHitcounterUpdateFreq <= 1 ){ //
-                       $dbw->query( "UPDATE $curTable SET cur_counter = cur_counter + 1 WHERE cur_id = $id" );
+                       $dbw->query( "UPDATE $pageTable SET page_counter = page_counter + 1 WHERE page_id = $id" );
                        return;
                }
 
@@ -2255,4 +2293,30 @@ class Article {
        }
 }
 
+/**
+ * Check whether an article is a stub
+ *
+ * @public
+ * @param integer $articleID   ID of the article that is to be checked
+ */
+function wfArticleIsStub( $articleID ) {
+       global $wgUser;
+       $fname = 'wfArticleIsStub';
+
+       $threshold = $wgUser->getOption('stubthreshold') ;
+       if ( $threshold > 0 ) {
+               $dbr =& wfGetDB( DB_SLAVE );
+               $s = $dbr->selectRow( array('page', 'text'),
+                       array( 'LENGTH(old_text) AS len', 'page_namespace', 'page_is_redirect' ),
+                       array( 'page_id' => $articleID, "page.page_latest=text.old_id" ),
+                       $fname ) ;
+               if ( $s == false OR $s->page_is_redirect OR $s->page_namespace != 0 ) {
+                       return false;
+               }
+               $size = $s->len;
+               return ( $size < $threshold );
+       }
+       return false;
+}
+
 ?>
index cb749cf..2bed882 100644 (file)
@@ -69,24 +69,24 @@ class CategoryPage extends Article {
 
                # FIXME: add limits
                $dbr =& wfGetDB( DB_SLAVE );
-               $cur = $dbr->tableName( 'cur' );
+               $page = $dbr->tableName( 'page' );
                $categorylinks = $dbr->tableName( 'categorylinks' );
 
                $t = $dbr->strencode( $this->mTitle->getDBKey() );
-               $sql = "SELECT DISTINCT cur_title,cur_namespace FROM $cur,$categorylinks " .
-                       "WHERE cl_to='$t' AND cl_from=cur_id AND cur_is_redirect=0 ORDER BY cl_sortkey" ;
+               $sql = "SELECT DISTINCT page_title, page_namespace FROM $page,$categorylinks " .
+                               "WHERE cl_to='$t' AND cl_from=page_id AND page_is_redirect=0 ORDER BY cl_sortkey" ;
                $res = $dbr->query( $sql, $fname ) ;
                # For all pages that link to this category
                while ( $x = $dbr->fetchObject ( $res ) )
                {
-                       $t = $wgContLang->getNsText ( $x->cur_namespace ) ;
+                       $t = $wgContLang->getNsText ( $x->page_namespace ) ;
                        if ( $t != '' ) $t .= ':' ;
-                       $t .= $x->cur_title ;
+                       $t .= $x->page_title ;
 
-                       if ( $x->cur_namespace == NS_CATEGORY ) {
-                               array_push ( $children , $sk->makeLink ( $t ) ) ; # Subcategory
+                       if ( $x->page_namespace == NS_CATEGORY ) {
+                                       array_push ( $children , $sk->makeLink ( $t ) ) ; # Subcategory
                        } else {
-                               array_push ( $articles , $sk->makeLink ( $t ) ) ; # Page in this category
+                                       array_push ( $articles , $sk->makeLink ( $t ) ) ; # Page in this category
                        }
                }
                $dbr->freeResult ( $res ) ;
@@ -105,6 +105,20 @@ class CategoryPage extends Article {
                        $r .= implode ( ', ' , $articles ) ;
                }
 
+               # Showing subcategories
+               if ( count ( $children ) > 0 ) {
+                       $r .= '<h2>'.wfMsg('subcategories')."</h2>\n" ;
+                       $r .= implode ( ', ' , $children ) ;
+               }
+
+               # Showing pages in this category
+               if ( count ( $articles ) > 0 ) {
+                       $ti = $this->mTitle->getText() ;
+                       $h =  wfMsg( 'category_header', $ti );
+                       $r .= "<h2>$h</h2>\n" ;
+                       $r .= implode ( ', ' , $articles ) ;
+               }
+
                return $r ;
        }
 
@@ -128,21 +142,21 @@ class CategoryPage extends Article {
 
                # FIXME: add limits
                $dbr =& wfGetDB( DB_SLAVE );
-               $cur = $dbr->tableName( 'cur' );
+               $page = $dbr->tableName( 'page' );
                $categorylinks = $dbr->tableName( 'categorylinks' );
 
                $t = $dbr->strencode( $this->mTitle->getDBKey() );
-               $sql = "SELECT DISTINCT cur_title,cur_namespace,cl_sortkey FROM " .
-                       "$cur,$categorylinks WHERE cl_to='$t' AND cl_from=cur_id AND cur_is_redirect=0 ORDER BY cl_sortkey" ;
+               $sql = "SELECT DISTINCT page_title,page_namespace,cl_sortkey FROM " .
+                               "$page,$categorylinks WHERE cl_to='$t' AND cl_from=page_id AND page_is_redirect ORDER BY cl_sortkey" ;
                $res = $dbr->query ( $sql ) ;
                while ( $x = $dbr->fetchObject ( $res ) )
                {
-                       $t = $ns = $wgContLang->getNsText ( $x->cur_namespace ) ;
+                       $t = $ns = $wgContLang->getNsText ( $x->page_namespace ) ;
                        if ( $t != '' ) $t .= ':' ;
-                       $t .= $x->cur_title ;
-                       $ctitle = str_replace( '_',' ',$x->cur_title );
+                       $t .= $x->page_title ;
+                       $ctitle = str_replace( '_',' ',$x->page_title );
 
-                       if ( $x->cur_namespace == NS_CATEGORY ) {
+                       if ( $x->page_namespace == NS_CATEGORY ) {
                                array_push ( $children, $sk->makeKnownLink ( $t, $ctitle ) ) ; # Subcategory
 
                                // If there's a link from Category:A to Category:B, the sortkey of the resulting
@@ -150,12 +164,12 @@ class CategoryPage extends Article {
                                // Workaround: If sortkey == "Category:".$title, than use $title for sorting,
                                // else use sortkey...
                                if ( ($ns.':'.$ctitle) == $x->cl_sortkey ) {
-                                       array_push ( $children_start_char, $wgContLang->firstChar( $x->cur_title ) );
+                                       array_push ( $children_start_char, $wgContLang->firstChar( $x->page_title ) );
                                } else {
                                        array_push ( $children_start_char, $wgContLang->firstChar( $x->cl_sortkey ) ) ;
                                }
-                       } elseif ( $wgCategoryMagicGallery && $x->cur_namespace == NS_IMAGE ) {
-                               $ig->add( new Image( $x->cur_title ) );
+                       } elseif ( $wgCategoryMagicGallery && $x->page_namespace == NS_IMAGE ) {
+                               $ig->add( new Image( $x->page_title ) );
                        } else {
                                array_push ( $articles , $sk->makeKnownLink ( $t ) ) ; # Page in this category
                                array_push ( $articles_start_char, $wgContLang->firstChar( $x->cl_sortkey ) ) ;
index f42a2cf..6cd4727 100644 (file)
@@ -652,8 +652,8 @@ class Database {
         * $conds: a condition map, terms are ANDed together. 
         *   Items with numeric keys are taken to be literal conditions
         * Takes an array of selected variables, and a condition map, which is ANDed
-        * e.g. selectRow( "cur", array( "cur_id" ), array( "cur_namespace" => 0, "cur_title" => "Astronomy" ) )
-        *   would return an object where $obj->cur_id is the ID of the Astronomy article
+        * e.g. selectRow( "page", array( "page_id" ), array( "page_namespace" => 0, "page_title" => "Astronomy" ) )
+        *   would return an object where $obj->page_id is the ID of the Astronomy article
         *
         * @todo migrate documentation to phpdocumentor format
         */
index 4c6017e..360e5f0 100644 (file)
@@ -259,26 +259,31 @@ class DifferenceEngine {
 
                $dbr =& wfGetDB( DB_SLAVE );
                if ( 0 == $this->mNewid || 0 == $this->mOldid ) {
+                       /* Fetch current revision */
                        $wgOut->setArticleFlag( true );
                        $newLink = $wgTitle->escapeLocalUrl();
                        $this->mPagetitle = htmlspecialchars( wfMsg( 'currentrev' ) );
                        $this->mNewtitle = "<a href='$newLink'>{$this->mPagetitle}</a>";
                        $id = $wgTitle->getArticleID();
 
-                       $s = $dbr->selectRow( 'cur', array( 'cur_text', 'cur_user_text', 'cur_comment' ),
-                               array( 'cur_id' => $id ), $fname );
+                       $s = $dbr->selectRow( array( 'page', 'revision', 'text' ),
+                               array( 'old_flags', 'old_text', 'rev_user_text', 'rev_comment' ),
+                               "page_id=$id AND page_id=rev_page AND rev_id=old_id", $fname );
                        if ( $s === false ) {
-                               wfDebug( "Unable to load cur_id $id\n" );
+                               wfDebug( "Unable to load page_id $id\n" );
                                return false;
                        }
 
                        $this->mNewPage = &$wgTitle;
-                       $this->mNewtext = $s->cur_text;
-                       $this->mNewUser = $s->cur_user_text;
-                       $this->mNewComment = $s->cur_comment;
+                       $this->mNewtext = Article::getRevisionText( $s );
+                       $this->mNewUser = $s->rev_user_text;
+                       $this->mNewComment = $s->rev_comment;
                } else {
-                       $s = $dbr->selectRow( 'old', array( 'old_namespace','old_title','old_timestamp', 'old_text',
-                               'old_flags','old_user_text','old_comment' ), array( 'old_id' => $this->mNewid ), $fname );
+                       $s = $dbr->selectRow( array( 'page', 'revision', 'text' ),
+                               array( 'page_namespace','page_title','rev_timestamp', 'old_text',
+                               'old_flags','rev_user_text','rev_comment' ),
+                               "page_id=rev_page AND rev_id=old_id AND rev_id={$this->mNewid}",
+                               $fname );
 
                        if ( $s === false ) {
                                wfDebug( "Unable to load old_id {$this->mNewid}\n" );
@@ -287,13 +292,13 @@ class DifferenceEngine {
 
                        $this->mNewtext = Article::getRevisionText( $s );
 
-                       $t = $wgLang->timeanddate( $s->old_timestamp, true );
-                       $this->mNewPage = Title::MakeTitle( $s->old_namespace, $s->old_title );
+                       $t = $wgLang->timeanddate( $s->rev_timestamp, true );
+                       $this->mNewPage = Title::MakeTitle( $s->page_namespace, $s->page_title );
                        $newLink = $wgTitle->escapeLocalUrl ('oldid=' . $this->mNewid);
                        $this->mPagetitle = htmlspecialchars( wfMsg( 'revisionasof', $t ) );
                        $this->mNewtitle = "<a href='$newLink'>{$this->mPagetitle}</a>";
-                       $this->mNewUser = $s->old_user_text;
-                       $this->mNewComment = $s->old_comment;
+                       $this->mNewUser = $s->rev_user_text;
+                       $this->mNewComment = $s->rev_comment;
                }
                if ( 0 == $this->mOldid ) {
                        $s = $dbr->selectRow( 'old',
@@ -308,9 +313,9 @@ class DifferenceEngine {
                                return false;
                        }
                } else {
-                       $s = $dbr->selectRow( 'old',
-                               array( 'old_namespace','old_title','old_timestamp','old_text','old_flags','old_user_text','old_comment'),
-                               array( 'old_id' => $this->mOldid ),
+                       $s = $dbr->selectRow( array( 'page', 'revision', 'text' ),
+                               array( 'page_namespace','page_title','rev_timestamp','old_text','old_flags','rev_user_text','rev_comment'),
+                               "page_id=rev_page AND rev_id=old_id AND rev_id={$this->mOldid}",
                                $fname
                        );
                        if ( $s === false ) {
@@ -318,14 +323,14 @@ class DifferenceEngine {
                                return false;
                        }
                }
-               $this->mOldPage = Title::MakeTitle( $s->old_namespace, $s->old_title );
+               $this->mOldPage = Title::MakeTitle( $s->page_namespace, $s->page_title );
                $this->mOldtext = Article::getRevisionText( $s );
 
-               $t = $wgLang->timeanddate( $s->old_timestamp, true );
+               $t = $wgLang->timeanddate( $s->rev_timestamp, true );
                $oldLink = $this->mOldPage->escapeLocalUrl ('oldid=' . $this->mOldid);
                $this->mOldtitle = "<a href='$oldLink'>" . htmlspecialchars( wfMsg( 'revisionasof', $t ) ) . '</a>';
-               $this->mOldUser = $s->old_user_text;
-               $this->mOldComment = $s->old_comment;
+               $this->mOldUser = $s->rev_user_text;
+               $this->mOldComment = $s->rev_comment;
 
                return true;
        }
index 0f4e779..33e17c9 100644 (file)
@@ -434,17 +434,17 @@ class EditPage {
                }
                # Prepare a list of templates used by this page
                $db =& wfGetDB( DB_SLAVE );
-               $cur = $db->tableName( 'cur' );
+               $page = $db->tableName( 'page' );
                $links = $db->tableName( 'links' );
                $id = $this->mTitle->getArticleID();
-               $sql = "SELECT cur_namespace,cur_title,cur_id ".
-                       "FROM $cur,$links WHERE l_to=cur_id AND l_from={$id} and cur_namespace=".NS_TEMPLATE;
+               $sql = "SELECT page_namespace,page_title,page_id ".
+                       "FROM $page,$links WHERE l_to=page_id AND l_from={$id} and page_namespace=".NS_TEMPLATE;
                $res = $db->query( $sql, "EditPage::editform" );
 
                if ( $db->numRows( $res ) ) {
                        $templates = '<br />'. wfMsg( 'templatesused' ) . '<ul>';
                        while ( $row = $db->fetchObject( $res ) ) {
-                               if ( $titleObj = Title::makeTitle( $row->cur_namespace, $row->cur_title ) ) {
+                               if ( $titleObj = Title::makeTitle( $row->page_namespace, $row->page_title ) ) {
                                        $templates .= '<li>' . $sk->makeLinkObj( $titleObj ) . '</li>';
                                }
                        }
@@ -473,14 +473,15 @@ class EditPage {
                        $liveOnclick = '';
                }
                
-               $wgOut->addHTML( "
+               $wgOut->addHTML( <<<END
 {$toolbar}
-<form id=\"editform\" name=\"editform\" method=\"post\" action=\"$action\"
-enctype=\"multipart/form-data\">
+<form id="editform" name="editform" method="post" action="$action"
+enctype="multipart/form-data">
 {$commentsubject}
-<textarea tabindex='1' accesskey=\",\" name=\"wpTextbox1\" rows='{$rows}'
-cols='{$cols}'{$ew}>" .
-htmlspecialchars( $wgContLang->recodeForEdit( $this->textbox1 ) ) .
+<textarea tabindex='1' accesskey="," name="wpTextbox1" rows='{$rows}'
+cols='{$cols}'{$ew}>
+END
+. htmlspecialchars( $wgContLang->recodeForEdit( $this->textbox1 ) ) .
 "
 </textarea>
 <br />{$editsummary}
@@ -659,21 +660,12 @@ htmlspecialchars( $wgContLang->recodeForEdit( $this->textbox1 ) ) .
         * @todo document
         */
        function mergeChangesInto( &$text ){
-               $fname = 'EditPage::mergeChangesInto';
-               $oldDate = $this->edittime;
-               $dbw =& wfGetDB( DB_MASTER );
-               $obj = $dbw->selectRow( 'cur', array( 'cur_text' ), array( 'cur_id' => $this->mTitle->getArticleID() ), 
-                       $fname, 'FOR UPDATE' );
-
-               $yourtext = $obj->cur_text;
-               $ns = $this->mTitle->getNamespace();
-               $title = $this->mTitle->getDBkey();
-               $obj = $dbw->selectRow( 'old', 
-                       array( 'old_text','old_flags'), 
-                       array( 'old_namespace' => $ns, 'old_title' => $title, 
-                               'old_timestamp' => $dbw->timestamp($oldDate)),
-                       $fname );
-               $oldText = Article::getRevisionText( $obj );
+               $yourtext = $this->mArticle->fetchRevisionText();
+               
+               $db =& wfGetDB( DB_SLAVE );
+               $oldText = $this->mArticle->fetchRevisionText(
+                       $db->timestamp( $this->edittime ),
+                       'rev_timestamp' );
                
                if(wfMerge($oldText, $text, $yourtext, $result)){
                        $text = $result;
index ffbfc13..611e34d 100644 (file)
@@ -155,7 +155,7 @@ class HistoryBlobStub
        
        function getText() {
                $dbr =& wfGetDB( DB_SLAVE );
-               $row = $dbr->selectRow( 'old', array( 'old_flags', 'old_text' ), array( 'old_id' => $this->mOldId ) );
+               $row = $dbr->selectRow( 'text', array( 'old_flags', 'old_text' ), array( 'old_id' => $this->mOldId ) );
                if ( !$row || $row->old_flags != 'object' ) {
                        return false;
                }
index 90c4a9f..6445453 100644 (file)
@@ -748,7 +748,7 @@ function wfRecordUpload( $name, $oldver, $size, $desc, $copyStatus = "", $source
                        'img_description' => $desc,
                        'img_user' => $wgUser->getID(),
                        'img_user_text' => $wgUser->getName(),
-               ), $fname, 'IGNORE'
+               ), $fname, 'IGNORE' 
        );
        $descTitle = Title::makeTitleSafe( NS_IMAGE, $name );
 
@@ -757,27 +757,49 @@ function wfRecordUpload( $name, $oldver, $size, $desc, $copyStatus = "", $source
                $id = $descTitle->getArticleID();
 
                if ( $id == 0 ) {
-                       $seqVal = $dbw->nextSequenceValue( 'cur_cur_id_seq' );
-                       $dbw->insert( 'cur',
+                       $now = wfTimestampNow();
+                       $won = wfInvertTimestamp( $now );
+
+                       $text_old_id = $dbw->nextSequenceValue( 'text_old_id_seq' );
+                       $dbw->insert( 'text',
+                               array(
+                                       'old_id' => $text_old_id,
+                                       'old_text' => $textdesc,
+                                       'old_flags' => '' ),
+                               $fname );
+                       if ( is_null( $text_old_id ) ) $text_old_id = $dbw->insertId();
+
+                       $page_page_id = $dbw->nextSequenceValue( 'page_page_id' );
+                       $dbw->insert( 'page',
                                array(
-                                       'cur_id' => $seqVal,
-                                       'cur_namespace' => NS_IMAGE,
-                                       'cur_title' => $name,
-                                       'cur_comment' => $desc,
-                                       'cur_user' => $wgUser->getID(),
-                                       'cur_user_text' => $wgUser->getName(),
-                                       'cur_timestamp' => $dbw->timestamp($now),
-                                       'cur_is_new' => 1,
-                                       'cur_text' => $textdesc,
+                                       'page_id'        => $page_page_id,
+                                       'page_namespace' => NS_IMAGE,
+                                       'page_title'     => $name,
+                                       'page_restrictions' => '',
+                                       'page_counter'   => 0,
+                                       'page_is_redirect' => 0,
+                                       'page_is_new'    => 1,
+                                       'page_random'    => 0.5,
+                                       'page_touched'   => $now,
+                                       'page_latest'    => $text_old_id ),
+                               $fname );
+                       if ( is_null( $page_page_id ) ) $page_page_id = $dbw->insertId();
+
+                       $dbw->insert( 'revision',
+                               array(
+                                       'rev_id'        => $text_old_id,
+                                       'rev_page'      => $page_page_id,
+                                       'rev_comment'   => $desc,
+                                       'rev_user'      => $wgUser->getID(),
+                                       'rev_user_text' => $wgUser->getName(),
+                                       'rev_timestamp' => $now,
                                        'inverse_timestamp' => $won,
-                                       'cur_touched' => $dbw->timestamp($now)
-                               ), $fname
-                       );
-                       $id = $dbw->insertId() or 0; # We should throw an error instead
+                                       'rev_minor_edit' => 0 ),
+                               $fname );
 
                        RecentChange::notifyNew( $now, $descTitle, 0, $wgUser, $desc );
 
-                       $u = new SearchUpdate( $id, $name, $desc );
+                       $u = new SearchUpdate( $page_page_id, $name, $desc );
                        $u->doUpdate();
                }
        } else {
index 3609c00..e99e046 100644 (file)
@@ -144,11 +144,11 @@ class ImagePage extends Article {
                $wgOut->addHTML( '<h2>' . wfMsg( 'imagelinks' ) . "</h2>\n" );
 
                $dbr =& wfGetDB( DB_SLAVE );
-               $cur = $dbr->tableName( 'cur' );
+               $page = $dbr->tableName( 'page' );
                $imagelinks = $dbr->tableName( 'imagelinks' );
                
-               $sql = "SELECT cur_namespace,cur_title FROM $imagelinks,$cur WHERE il_to=" .
-                 $dbr->addQuotes( $this->mTitle->getDBkey() ) . " AND il_from=cur_id"
+               $sql = "SELECT page_namespace,page_title FROM $imagelinks,$page WHERE il_to=" .
+                 $dbr->addQuotes( $this->mTitle->getDBkey() ) . " AND il_from=page_id"
                  . " LIMIT 500"; # quickie emergency brake
                $res = $dbr->query( $sql, DB_SLAVE, "Article::imageLinks" );
 
@@ -160,7 +160,7 @@ class ImagePage extends Article {
 
                $sk = $wgUser->getSkin();
                while ( $s = $dbr->fetchObject( $res ) ) {
-                       $name = Title::MakeTitle( $s->cur_namespace, $s->cur_title );
+                       $name = Title::MakeTitle( $s->page_namespace, $s->page_title );
                        $link = $sk->makeKnownLinkObj( $name, "" );
                        $wgOut->addHTML( "<li>{$link}</li>\n" );
                }
@@ -188,11 +188,10 @@ class ImagePage extends Article {
 
                # Better double-check that it hasn't been deleted yet!
                $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
-               if ( !is_null( $image ) ) {
-                       if ( '' == trim( $image ) ) {
-                               $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
-                               return;
-                       }
+               if ( ( !is_null( $image ) )
+                 && ( '' == trim( $image ) ) ) {
+                       $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
+                       return;
                }
                
                # Deleting old images doesn't require confirmation
index b4bb757..fae8ff7 100644 (file)
@@ -147,7 +147,7 @@ class LinkCache {
                                $options = array();
                        }
 
-                       $id = $db->selectField( 'cur', 'cur_id', array( 'cur_namespace' => $ns, 'cur_title' => $t ), $fname, $options );
+                       $id = $db->selectField( 'page', 'page_id', array( 'page_namespace' => $ns, 'page_title' => $t ), $fname, $options );
                        if ( !$id ) {
                                $id = 0;
                        }
@@ -192,16 +192,16 @@ class LinkCache {
                        $options = '';
                }
 
-               $cur = $db->tableName( 'cur' );
+               $page = $db->tableName( 'page' );
                $links = $db->tableName( 'links' );
 
-               $sql = "SELECT cur_id,cur_namespace,cur_title
-                       FROM $cur,$links
-                       WHERE cur_id=l_to AND l_from=$id $options";
+               $sql = "SELECT page_id,page_namespace,page_title
+                       FROM $page,$links
+                       WHERE page_id=l_to AND l_from=$id $options";
                $res = $db->query( $sql, $fname );
                while( $s = $db->fetchObject( $res ) ) {
-                       $this->addGoodLink( $s->cur_id,
-                               Title::makeName( $s->cur_namespace, $s->cur_title )
+                       $this->addGoodLink( $s->page_id,
+                               Title::makeName( $s->page_namespace, $s->page_title )
                                );
                }
                
index 83ac569..7384177 100644 (file)
@@ -272,7 +272,7 @@ class LinksUpdate {
                $fname = 'LinksUpdate::fixBrokenLinks';
 
                $dbw =& wfGetDB( DB_MASTER );
-               $cur = $dbw->tableName( 'cur' );
+               $page = $dbw->tableName( 'page' );
                $links = $dbw->tableName( 'links' );
                
                $res = $dbw->select( 'brokenlinks', array( 'bl_from' ), array( 'bl_to' => $this->mTitle ), 
@@ -281,7 +281,7 @@ class LinksUpdate {
 
                $arr=array();
                $now = $dbw->timestamp();
-               $sql2 = "UPDATE $cur SET cur_touched='{$now}' WHERE cur_id IN (";
+               $sql2 = "UPDATE $page SET page_touched='{$now}' WHERE page_id IN (";
                $first = true;
                while ( $row = $dbw->fetchObject( $res ) ) {
                        if ( ! $first ) { $sql2 .= ","; }
index 86f95c7..9191d60 100755 (executable)
@@ -101,7 +101,7 @@ class MessageCache
                        }
 
                        if ( !is_array( $this->mCache ) ) {
-                               wfMsg( "MessageCache::load(): individual message mode\n" );
+                               wfDebug( "MessageCache::load(): individual message mode\n" );
                                # If it is 'loading' or 'error', switch to individual message mode, otherwise disable
                                # Causing too much DB load, disabling -- TS
                                $this->mDisable = true;
@@ -130,22 +130,26 @@ class MessageCache
                global $wgPartialMessageCache;
                $fname = 'MessageCache::loadFromDB';
                $dbr =& wfGetDB( DB_SLAVE );
-               $conditions = array( 'cur_is_redirect' => 0, 
-                                       'cur_namespace' => NS_MEDIAWIKI);
+               $conditions = array( 'page_is_redirect' => 0, 
+                                       'page_namespace' => NS_MEDIAWIKI);
                if ($wgPartialMessageCache) {
+                       wfDebugDieBacktrace( "Confused about how this works." );
                        if (is_array($wgPartialMessageCache)) {
-                               $conditions['cur_title']=$wgPartialMessageCache;
+                               $conditions['page_title']=$wgPartialMessageCache;
                        } else {
                                require_once("MessageCacheHints.php");
-                               $conditions['cur_title']=MessageCacheHints::get();
+                               $conditions['page_title']=MessageCacheHints::get();
                        }
                }
-               $res = $dbr->select( 'cur',
-                       array( 'cur_title', 'cur_text' ), $conditions, $fname);
+               $res = $dbr->select( array( 'page', 'text' ),
+                       array( 'page_title', 'old_text', 'old_flags' ),
+                       'page_is_redirect=0 AND page_namespace = '.NS_MEDIAWIKI.' AND page_latest = old_id',
+                       $fname
+               );
 
                $this->mCache = array();
                for ( $row = $dbr->fetchObject( $res ); $row; $row = $dbr->fetchObject( $res ) ) {
-                       $this->mCache[$row->cur_title] = $row->cur_text;
+                       $this->mCache[$row->page_title] = Article::getRevisionText( $row );
                }
 
                $dbr->freeResult( $res );
@@ -172,11 +176,6 @@ class MessageCache
         */
        function isCacheable( $key ) {
                return true;
-               /*
-               global $wgAllMessagesEn, $wgLang;
-               return array_key_exists( $wgLang->lcfirst( $key ), $wgAllMessagesEn ) ||
-                       array_key_exists( $key, $wgAllMessagesEn );
-               */
        }
 
        function replace( $title, $text ) {
@@ -258,13 +257,16 @@ class MessageCache
                        # If it wasn't in the cache, load each message from the DB individually
                        if ( !$message ) {
                                $dbr =& wfGetDB( DB_SLAVE );
-                               $result = $dbr->selectRow( 'cur', array('cur_text'),
-                                 array( 'cur_namespace' => NS_MEDIAWIKI, 'cur_title' => $title ),
+                               $result = $dbr->selectRow( array( 'page', 'text' ),
+                                 array( 'old_flags', 'old_text' ),
+                                 'page_namespace=' . NS_MEDIAWIKI .
+                                 ' AND page_title=' . $dbr->addQuotes( $title ) .
+                                 ' AND page_latest=old_id',
                                  'MessageCache::get' );
                                if ( $result ) {
-                                       $message = $result->cur_text;
-                                       if( $this->mUseCache ) {
-                                               $this->mCache[$title] = $message;
+                                       $message = Article::getRevisionText( $result );
+                                       if ($this->mUseCache) {
+                                               $this->mCache[$title]=$message;
                                                /* individual messages may be often 
                                                   recached until proper purge code exists 
                                                */
index 2597557..963ac3e 100644 (file)
@@ -818,6 +818,7 @@ class OutputPage {
        function transformBuffer( $options = 0 ) {
        }
 
+
 }
 
 }
index 754a2d1..405f41b 100644 (file)
@@ -39,7 +39,8 @@ class PageHistory {
                $wgOut->setArticleRelated( true );
                $wgOut->setRobotpolicy( 'noindex,nofollow' );
 
-               if( $this->mTitle->getArticleID() == 0 ) {
+               $id = $this->mTitle->getArticleID();
+               if( $id == 0 ) {
                        $wgOut->addHTML( wfMsg( 'nohistory' ) );
                        wfProfileOut( $fname );
                        return;
@@ -47,15 +48,8 @@ class PageHistory {
 
                list( $limit, $offset ) = wfCheckLimits();
 
-               /* We have to draw the latest revision from 'cur' */
-               $rawlimit = $limit;
-               $rawoffset = $offset - 1;
-               if( 0 == $offset ) {
-                       $rawlimit--;
-                       $rawoffset = 0;
-               }
                /* Check one extra row to see whether we need to show 'next' and diff links */
-               $limitplus = $rawlimit + 1;
+               $limitplus = $limit + 1;
 
                $namespace = $this->mTitle->getNamespace();
                $title = $this->mTitle->getText();
@@ -70,15 +64,15 @@ class PageHistory {
                        $notificationtimestamp = $row->wl_notificationtimestamp;
                } else $notificationtimestamp = false ;
 
-               $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_namespace={$namespace} AND " .
-                 "old_title='" . $db->strencode( $this->mTitle->getDBkey() ) . "' " .
-                 "ORDER BY inverse_timestamp".$db->limitResult($limitplus,$rawoffset);
+               $db =& wfGetDB( DB_SLAVE );
+               $use_index = $db->useIndexClause( 'page_timestamp' );
+               $revision = $db->tableName( 'revision' );
+
+               $sql = "SELECT rev_id,rev_user," .
+                 "rev_comment,rev_user_text,rev_timestamp,rev_minor_edit ".
+                 "FROM $revision $use_index " .
+                 "WHERE rev_page=$id " .
+                 "ORDER BY inverse_timestamp ".$db->limitResult($limitplus,$offset);
                $res = $db->query( $sql, $fname );
 
                $revs = $db->numRows( $res );
@@ -104,27 +98,17 @@ class PageHistory {
                }
                $s .= $this->beginHistoryList();
                $counter = 1;
-               if( $offset == 0 ){
-                       $this->linesonpage++;
-                       $s .= $this->historyLine(
-                               $this->mArticle->getTimestamp(),
-                               $this->mArticle->getUser(),
-                               $this->mArticle->getUserText(), $namespace,
-                               $title, 0, $this->mArticle->getComment(),
-                               ( $this->mArticle->getMinorEdit() > 0 ),
-                               $counter++,
-                               $notificationtimestamp
-                       );
-               }
                while ( $line = $db->fetchObject( $res ) ) {
                        $s .= $this->historyLine(
-                               $line->old_timestamp, $line->old_user,
-                               $line->old_user_text, $namespace,
-                               $title, $line->old_id,
-                               $line->old_comment, ( $line->old_minor_edit > 0 ),
-                               $counter++,
-                               $notificationtimestamp
+                               $line->rev_timestamp, $line->rev_user,
+                               $line->rev_user_text, $namespace,
+                               $title, $line->rev_id,
+                               $line->rev_comment, ( $line->rev_minor_edit > 0 ),
+                               $counter,
+                               $notificationtimestamp,
+                               ($counter == 1 && $offset == 0)
                        );
+                       $counter++;
                }
                $s .= $this->endHistoryList( !$atend );
                $s .= $numbar;
@@ -154,7 +138,7 @@ class PageHistory {
                return $s;
        }
 
-       function historyLine( $ts, $u, $ut, $ns, $ttl, $oid, $c, $isminor, $counter = '', $notificationtimestamp = false ) {
+       function historyLine( $ts, $u, $ut, $ns, $ttl, $oid, $c, $isminor, $counter = '', $notificationtimestamp = false, $latest = false ) {
                global $wgLang, $wgContLang;
 
                static $message;
@@ -189,7 +173,7 @@ class PageHistory {
                }
 
                $s = '<li>';
-               if ( $oid ) {
+               if ( $oid && !$latest ) {
                        $curlink = $this->mSkin->makeKnownLinkObj( $this->mTitle, $message['cur'],
                          'diff=0&oldid='.$oid );
                } else {
@@ -199,7 +183,7 @@ class PageHistory {
                if( $this->linesonpage > 1) {
                        # XXX: move title texts to javascript
                        $checkmark = '';
-                       if ( !$oid ) {
+                       if ( !$oid || $latest ) {
                                $arbitrary = '<input type="radio" style="visibility:hidden" name="oldid" value="'.$oid.'" title="'.$message['selectolderversionfordiff'].'" />';
                                $checkmark = ' checked="checked"';
                        } else {
index a1f2ae3..911736d 100644 (file)
@@ -158,7 +158,11 @@ class Parser
                $this->mOutputType = OT_HTML;
 
                $stripState = NULL;
-               $text = $this->strip( $text, $this->mStripState );
+               global $fnord; $fnord = 1;
+               //$text = $this->strip( $text, $this->mStripState );
+               // VOODOO MAGIC FIX! Sometimes the above segfaults in PHP5.
+               $x =& $this->mStripState;
+               $text = $this->strip( $text, $x );
 
                $text = $this->internalParse( $text, $linestart );
                $text = $this->unstrip( $text, $this->mStripState );
@@ -2952,7 +2956,7 @@ class Parser
                if ( !empty( $wgLinkHolders['namespaces'] ) ) {
                        wfProfileIn( $fname.'-check' );
                        $dbr =& wfGetDB( DB_SLAVE );
-                       $cur = $dbr->tableName( 'cur' );
+                       $page = $dbr->tableName( 'page' );
                        $sk = $wgUser->getSkin();
                        $threshold = $wgUser->getOption('stubthreshold');
                        
@@ -2981,14 +2985,19 @@ class Parser
                                        # Not in the link cache, add it to the query
                                        if ( !isset( $current ) ) {
                                                $current = $val;
-                                               $query =  "SELECT cur_id, cur_namespace, cur_title";
+                                               $tables = $page;
+                                               $join = '';
+                                               $query =  "SELECT page_id, page_namespace, page_title";
                                                if ( $threshold > 0 ) {
-                                                       $query .= ", LENGTH(cur_text) AS cur_len, cur_is_redirect";
-                                               } 
-                                               $query .= " FROM $cur WHERE (cur_namespace=$val AND cur_title IN(";
+                                                       $textTable = $dbr->tableName( 'text' );
+                                                       $query .= ', LENGTH(old_text) AS page_len, page_is_redirect';
+                                                       $tables .= ", $textTable";
+                                                       $join = 'page_latest=old_id AND';
+                                               }
+                                               $query .= " FROM $tables WHERE $join (page_namespace=$val AND page_title IN(";
                                        } elseif ( $current != $val ) {
                                                $current = $val;
-                                               $query .= ")) OR (cur_namespace=$val AND cur_title IN(";
+                                               $query .= ")) OR (page_namespace=$val AND page_title IN(";
                                        } else {
                                                $query .= ', ';
                                        }
@@ -3009,13 +3018,13 @@ class Parser
                                # 1 = known
                                # 2 = stub
                                while ( $s = $dbr->fetchObject($res) ) {
-                                       $title = Title::makeTitle( $s->cur_namespace, $s->cur_title );
+                                       $title = Title::makeTitle( $s->page_namespace, $s->page_title );
                                        $pdbk = $title->getPrefixedDBkey();
-                                       $wgLinkCache->addGoodLink( $s->cur_id, $pdbk );
+                                       $wgLinkCache->addGoodLink( $s->page_id, $pdbk );
                                        
                                        if ( $threshold >  0 ) {
-                                               $size = $s->cur_len;
-                                               if ( $s->cur_is_redirect || $s->cur_namespace != 0 || $length < $threshold ) {
+                                               $size = $s->page_len;
+                                               if ( $s->page_is_redirect || $s->page_namespace != 0 || $length < $threshold ) {
                                                        $colours[$pdbk] = 1;
                                                } else {
                                                        $colours[$pdbk] = 2;
index aa22d2b..8873dc8 100644 (file)
@@ -93,7 +93,7 @@ class RawPage {
                
                if( !$this->mTitle ) return '';
                $dbr =& wfGetDB( DB_SLAVE );
-               extract( $dbr->tableNames( 'cur', 'old' ) );
+               extract( $dbr->tableNames( 'revision', 'page', 'text' ) );
 
                $t = $dbr->strencode( $this->mTitle->getDBKey() );
                $ns = $this->mTitle->getNamespace();
@@ -103,14 +103,14 @@ class RawPage {
                        return $rawtext;
                }
                # else get it from the DB
+               $sql = "SELECT old_text AS text, rev_timestamp AS timestamp
+                       FROM $text, $revision";
                if(!empty($this->mOldId)) {
-                       $sql = "SELECT old_text AS text,old_timestamp AS timestamp,".
-                                   "old_user AS user,old_flags AS flags FROM $old " .
-                       "WHERE old_id={$this->mOldId}";
+                       $sql .= " WHERE old_id={$this->mOldId} AND rev_id={$this->mOldId}";
                } else {
-                       $sql = "SELECT cur_id as id,cur_timestamp as timestamp,cur_user as user,cur_user_text as user_text," .
-                       "cur_restrictions as restrictions,cur_comment as comment,cur_text as text FROM $cur " .
-                       "WHERE cur_namespace=$ns AND cur_title='$t'";
+                       $sql .= ", $page
+                               WHERE page_namespace=$ns AND page_title='$t'
+                                 AND page_latest=rev_id AND rev_id=old_id";
                }
                $res = $dbr->query( $sql, $fname );
                if( $s = $dbr->fetchObject( $res ) ) {
index f64191d..2f15679 100644 (file)
@@ -349,16 +349,16 @@ class RecentChange
        function loadFromCurRow( $row )
        {
                $this->mAttribs = array(
-                       'rc_timestamp' => $row->cur_timestamp,
-                       'rc_cur_time' => $row->cur_timestamp,
-                       'rc_user' => $row->cur_user,
-                       'rc_user_text' => $row->cur_user_text,
-                       'rc_namespace' => $row->cur_namespace,
-                       'rc_title' => $row->cur_title,
-                       'rc_comment' => $row->cur_comment,
-                       'rc_minor' => !!$row->cur_minor_edit,
-                       'rc_type' => $row->cur_is_new ? RC_NEW : RC_EDIT,
-                       'rc_cur_id' => $row->cur_id,
+                       'rc_timestamp' => $row->rev_timestamp,
+                       'rc_cur_time' => $row->rev_timestamp,
+                       'rc_user' => $row->rev_user,
+                       'rc_user_text' => $row->rev_user_text,
+                       'rc_namespace' => $row->page_namespace,
+                       'rc_title' => $row->page_title,
+                       'rc_comment' => $row->rev_comment,
+                       'rc_minor' => !!$row->rev_minor_edit,
+                       'rc_type' => $row->page_is_new ? RC_NEW : RC_EDIT,
+                       'rc_cur_id' => $row->page_id,
                        'rc_this_oldid' => 0,
                        'rc_last_oldid' => 0,
                        'rc_bot'        => 0,
@@ -367,7 +367,7 @@ class RecentChange
                        'rc_ip' => '',
                        'rc_patrolled' => '1',  # we can't support patrolling on the Watchlist
                                                # currently because it uses cur, not recentchanges
-                       'rc_new' => $row->cur_is_new # obsolete
+                       'rc_new' => $row->page_is_new # obsolete
                );
 
                $this->mExtra = array();
index f16aba2..d368086 100644 (file)
@@ -170,7 +170,7 @@ class SearchEngine {
                if ($namespaces == '') {
                        $namespaces = '0';
                }
-               return 'AND cur_namespace IN (' . $namespaces . ')';
+               return 'AND page_namespace IN (' . $namespaces . ')';
        }
        
        /**
index d3b263d..48770d1 100644 (file)
@@ -75,11 +75,12 @@ class SearchMySQL3 extends SearchEngine {
 
        function queryMain( $filteredTerm, $fulltext ) {
                $match = $this->parseQuery( $filteredTerm, $fulltext );
-               $cur = $this->db->tableName( 'cur' );
+               $page = $this->db->tableName( 'page' );
+               $text = $this->db->tableName( 'text' );
                $searchindex = $this->db->tableName( 'searchindex' );
-               return 'SELECT cur_id, cur_namespace, cur_title, cur_text ' .
-                       "FROM $cur,$searchindex " .
-                       'WHERE cur_id=si_page AND ' . $match;
+               return 'SELECT page_id, page_namespace, page_title, old_flags, old_text ' .
+                       "FROM $page,$text,$searchindex " .
+                       'WHERE page_id=si_page AND page_latest=old_id AND ' . $match;
        }
 
        function update( $id, $title, $text ) {
index a1fa5b3..a78e415 100644 (file)
@@ -72,11 +72,12 @@ class SearchMySQL4 extends SearchEngine {
 
        function queryMain( $filteredTerm, $fulltext ) {
                $match = $this->parseQuery( $filteredTerm, $fulltext );
-               $cur = $this->db->tableName( 'cur' );
+               $page = $this->db->tableName( 'page' );
+               $text = $this->db->tableName( 'text' );
                $searchindex = $this->db->tableName( 'searchindex' );
-               return 'SELECT cur_id, cur_namespace, cur_title, cur_text ' .
-                       "FROM $cur,$searchindex " .
-                       'WHERE cur_id=si_page AND ' . $match;
+               return 'SELECT page_id, page_namespace, page_title, old_flags, old_text ' .
+                       "FROM $page,$text,$searchindex " .
+                       'WHERE page_id=si_page AND page_latest=old_id AND ' . $match;
        }
 
         function update( $id, $title, $text ) {
index 0f55446..842e7c9 100644 (file)
@@ -77,7 +77,7 @@ require_once( 'ParserCache.php' );
 require_once( 'WebRequest.php' );
 require_once( 'LoadBalancer.php' );
 require_once( 'HistoryBlob.php' );
-       
+
 $wgRequest = new WebRequest();
 
 wfProfileOut( $fname.'-includes' );
index d1e9c28..21085bc 100644 (file)
@@ -113,11 +113,11 @@ function makeHTMLText( $messages ) {
                NS_MEDIAWIKI_TALK => array()
        );
        $dbr =& wfGetDB( DB_SLAVE );
-       $res = $dbr->select( 'cur',
-               array( 'cur_namespace', 'cur_title' ),
-               "cur_namespace IN (" . NS_MEDIAWIKI . ", " . NS_MEDIAWIKI_TALK . ")" );
+       $page = $dbr->tableName( 'page' );
+       $sql = "SELECT page_namespace,page_title FROM $page WHERE page_namespace IN (" . NS_MEDIAWIKI . ", " . NS_MEDIAWIKI_TALK . ")";
+       $res = $dbr->query( $sql );
        while( $s = $dbr->fetchObject( $res ) ) {
-               $pageExists[$s->cur_namespace][$s->cur_title] = true;
+               $pageExists[$s->page_namespace][$s->page_title] = true;
        }
        $dbr->freeResult( $res );
        wfProfileOut( "$fname-check" );
index 1989af3..e657842 100644 (file)
@@ -67,14 +67,14 @@ function indexShowToplevel ( $namespace = 0 ) {
        # in the querycache table.
 
        $dbr =& wfGetDB( DB_SLAVE );
-       $cur = $dbr->tableName( 'cur' );
-       $fromwhere = "FROM $cur WHERE cur_namespace=$namespace";
-       $order_arr = array ( 'ORDER BY' => 'cur_title' );
-       $order_str = 'ORDER BY cur_title';
+       $page = $dbr->tableName( 'page' );
+       $fromwhere = "FROM $page WHERE page_namespace=$namespace";
+       $order_arr = array ( 'ORDER BY' => 'page_title' );
+       $order_str = 'ORDER BY page_title';
        $out = "";
-       $where = array( 'cur_namespace' => $namespace );
+       $where = array( 'page_namespace' => $namespace );
 
-       $count = $dbr->selectField( 'cur', 'COUNT(*)', $where, $fname );
+       $count = $dbr->selectField( 'page', 'COUNT(*)', $where, $fname );
        $sections = ceil( $count / $indexMaxperpage );
 
        if ( $sections < 3 ) {
@@ -95,24 +95,24 @@ function indexShowToplevel ( $namespace = 0 ) {
        $stopat = ( $offset + $toplevelMaxperpage < $sections )
                  ? $offset + $toplevelMaxperpage : $sections ;
 
-       # This array is going to hold the cur_titles in order.
+       # This array is going to hold the page_titles in order.
        $lines = array();
 
        # If we are going to show n rows, we need n+1 queries to find the relevant titles.
        for ( $i = $offset; $i <= $stopat; $i++ ) {
                if ( $i == $sections )                  # if we're displaying the last section, we need to
-                       $from = $count-1;                       # find the last cur_title in the DB
+                       $from = $count-1;                       # find the last page_title in the DB
                else if ( $i > $offset )
                        $from = $i * $indexMaxperpage - 1;
                else
                        $from = $i * $indexMaxperpage;
                $limit = ( $i == $offset || $i == $stopat ) ? 1 : 2;
-               $sql = "SELECT cur_title $fromwhere $order_str " . $dbr->limitResult ( $limit, $from );
+               $sql = "SELECT page_title $fromwhere $order_str " . $dbr->limitResult ( $limit, $from );
                $res = $dbr->query( $sql, $fname );
                $s = $dbr->fetchObject( $res );
-               array_push ( $lines, $s->cur_title );
+               array_push ( $lines, $s->page_title );
                if ( $s = $dbr->fetchObject( $res ) ) {
-                       array_push ( $lines, $s->cur_title );
+                       array_push ( $lines, $s->page_title );
                }
                $dbr->freeResult( $res );
        }
@@ -185,14 +185,14 @@ function indexShowChunk( $from, $namespace = 0 ) {
 
        $out = "";
        $dbr =& wfGetDB( DB_SLAVE );
-       $cur = $dbr->tableName( 'cur' );
+       $page = $dbr->tableName( 'page' );
        
        $fromTitle = Title::newFromURL( $from );
        $fromKey = is_null( $fromTitle ) ? '' : $fromTitle->getDBkey();
        
-       $sql = "SELECT cur_title FROM $cur WHERE cur_namespace=$namespacee" .
-               " AND cur_title >= ".  $dbr->addQuotes( $fromKey ) .
-               " ORDER BY cur_title LIMIT " . $maxPlusOne;
+       $sql = "SELECT page_title FROM $page WHERE page_namespace=$namespacee" .
+               " AND page_title >= ".  $dbr->addQuotes( $fromKey ) .
+               " ORDER BY page_title LIMIT " . $maxPlusOne;
        $res = $dbr->query( $sql, "indexShowChunk" );
 
        ### FIXME: side link to previous
@@ -200,11 +200,11 @@ function indexShowChunk( $from, $namespace = 0 ) {
        $n = 0;
        $out = '<table style="background: inherit;" border="0" width="100%">';
        while( ($n < $indexMaxperpage) && ($s = $dbr->fetchObject( $res )) ) {
-               $t = Title::makeTitle( $namespacee, $s->cur_title );
+               $t = Title::makeTitle( $namespacee, $s->page_title );
                if( $t ) {
                        $link = $sk->makeKnownLinkObj( $t, $t->getText() );
                } else {
-                       $link = '[[' . htmlspecialchars( $s->cur_title ) . ']]';
+                       $link = '[[' . htmlspecialchars( $s->page_title ) . ']]';
                }
                if( $n % 3 == 0 ) {
                        $out .= '<tr>';
@@ -230,8 +230,8 @@ function indexShowChunk( $from, $namespace = 0 ) {
                $namespaceparam = $namespace ? "&namespace=$namespace" : "";
                $out2 .= " | " . $sk->makeKnownLink(
                        $wgContLang->specialPage( "Allpages" ),
-                       wfMsg ( 'nextpage', $s->cur_title ),
-                       "from=" . wfUrlEncode ( $s->cur_title ) . $namespaceparam );
+                       wfMsg ( 'nextpage', $s->page_title ),
+                       "from=" . wfUrlEncode ( $s->page_title ) . $namespaceparam );
        }
        $out2 .= "</td></tr></table><hr />";
 
index f799cc2..c847e1e 100644 (file)
@@ -29,15 +29,17 @@ class AncientPagesPage extends QueryPage {
 
        function getSQL() {
                $db =& wfGetDB( DB_SLAVE );
-               $cur = $db->tableName( 'cur' );
-               $use_index = $db->useIndexClause( 'cur_timestamp' );
+               $page = $db->tableName( 'page' );
+               $revision = $db->tableName( 'revision' );
+               #$use_index = $db->useIndexClause( 'cur_timestamp' ); # FIXME! this is gone
                return
                        "SELECT 'Ancientpages' as type,
-                                       cur_namespace as namespace,
-                               cur_title as title,
-                               cur_timestamp as value
-                       FROM $cur $use_index
-                       WHERE cur_namespace=0 AND cur_is_redirect=0";
+                                       page_namespace as namespace,
+                               page_title as title,
+                               rev_timestamp as value
+                       FROM $page, $revision
+                       WHERE page_namespace=0 AND page_is_redirect=0
+                         AND page_latest=rev_id";
        }
        
        function sortDescending() {
index f48eedc..96f0623 100644 (file)
@@ -119,7 +119,7 @@ class SqlQueryForm {
                                array_push( $k, $conn->fieldName( $res, $x ) );
                        }
 
-                       if ( $n == 2 && in_array( "cur_title", $k ) && in_array( "cur_namespace", $k ) ) {
+                       if ( $n == 2 && in_array( "page_title", $k ) && in_array( "page_namespace", $k ) ) {
                                $titleList = true;
                        }
 
@@ -132,9 +132,9 @@ class SqlQueryForm {
                        if ( $titleList ) {
                                $r = "";
                                foreach ( $a as $y ) {
-                                       $sTitle = htmlspecialchars( $y->cur_title );
-                                       if ( $y->cur_namespace ) {
-                                               $sNamespace = $wgContLang->getNsText( $y->cur_namespace );
+                                       $sTitle = htmlspecialchars( $y->page_title );
+                                       if ( $y->page_namespace ) {
+                                               $sNamespace = $wgContLang->getNsText( $y->page_namespace );
                                                $link = "$sNamespace:$sTitle";
                                        } else {
                                                $link = "$sTitle";
@@ -154,10 +154,9 @@ class SqlQueryForm {
                                        $r .= "<tr>";
                                        foreach ( $k as $x ) {
                                                $o = $y->$x ;
-                                               if ( $x == "cur_title" or $x == "old_title" or $x == "rc_title") {
+                                               if ( $x == "page_title"  or $x == "rc_title") {
                                                        $namespace = 0;
-                                                       if( $x == "cur_title" && isset( $y->cur_namespace ) ) $namespace = $y->cur_namespace;
-                                                       if( $x == "old_title" && isset( $y->old_namespace ) ) $namespace = $y->old_namespace;
+                                                       if( $x == "page_title" && isset( $y->page_namespace ) ) $namespace = $y->page_namespace;
                                                        if( $x == "rc_title" && isset( $y->rc_namespace ) ) $namespace = $y->rc_namespace;
                                                        $title =& Title::makeTitle( $namespace, $o );
                                                        $o = "<a href=\"" . $title->escapeLocalUrl() . "\" class='internal'>" .
index 75847a0..bd8596f 100644 (file)
@@ -53,8 +53,9 @@ class BookSourceList {
                # First, see if we have a custom list setup in
                # [[Wikipedia:Book sources]] or equivalent.
                $bstitle = Title::makeTitleSafe( NS_PROJECT, wfMsg( "booksources" ) );
-               $dbr =& wfGetDB( DB_SLAVE );
-               $bstext = $dbr->selectField( 'cur', 'cur_text', $bstitle->curCond(), $fname );
+               $bsarticle = new Article( $bstitle );
+               $bstext = $bsarticle->getContent( false );
+
                if( $bstext ) { 
                        $bstext = str_replace( "MAGICNUMBER", $this->mIsbn, $bstext );
                        $wgOut->addWikiText( $bstext );
index d94d405..9c48cb4 100644 (file)
@@ -31,10 +31,10 @@ class BrokenRedirectsPage extends PageQueryPage {
 
        function getSQL() {
                $dbr =& wfGetDB( DB_SLAVE );
-               extract( $dbr->tableNames( 'cur', 'brokenlinks' ) );
+               extract( $dbr->tableNames( 'page', 'brokenlinks' ) );
 
-               $sql = "SELECT bl_to,cur_title FROM $brokenlinks,$cur " .
-                      "WHERE cur_is_redirect=1 AND cur_namespace=0 AND bl_from=cur_id ";
+               $sql = "SELECT bl_to,page_title FROM $brokenlinks,$page " .
+                      "WHERE page_is_redirect=1 AND page_namespace=0 AND bl_from=page_id ";
                return $sql;
        }
 
@@ -46,8 +46,8 @@ class BrokenRedirectsPage extends PageQueryPage {
                global $wgContLang ;
                
                $ns = $wgContLang->getNamespaces() ; /* not used, why bother? */
-               $from = $skin->makeKnownLink( $result->cur_title ,'', 'redirect=no' );
-               $edit = $skin->makeBrokenLink( $result->cur_title , "(".wfMsg("qbedit").")" , 'redirect=no');
+               $from = $skin->makeKnownLink( $result->page_title ,'', 'redirect=no' );
+               $edit = $skin->makeBrokenLink( $result->page_title , "(".wfMsg("qbedit").")" , 'redirect=no');
                $to   = $skin->makeBrokenLink( $result->bl_to );
                                
                return "$from $edit => $to";
index cf4b3bc..6d5d1f9 100644 (file)
@@ -73,55 +73,39 @@ function wfSpecialContributions( $par = '' ) {
        $wgOut->setSubtitle( wfMsg( 'contribsub', $ul ) );
 
        if ( $hideminor ) {
-               $cmq = 'AND cur_minor_edit=0';
-               $omq = 'AND old_minor_edit=0';
-               $mlink = $sk->makeKnownLink( $wgContLang->specialPage( 'Contributions' ),
-                 WfMsg( 'show' ), "target=" . htmlspecialchars( $nt->getPrefixedURL() ) .
+               $minorQuery = "AND rev_minor_edit=0";
+               $mlink = $sk->makeKnownLink( $wgContLang->specialPage( "Contributions" ),
+                 WfMsg( "show" ), "target=" . htmlspecialchars( $nt->getPrefixedURL() ) .
                  "&offset={$offset}&limit={$limit}&hideminor=0&namespace={$namespace}" );
        } else {
-               $cmq = $omq = '';
+               $minorQuery = "";
                $mlink = $sk->makeKnownLink( $wgContLang->specialPage( "Contributions" ),
                  WfMsg( 'hide' ), 'target=' . htmlspecialchars( $nt->getPrefixedURL() ) .
                  "&offset={$offset}&limit={$limit}&hideminor=1&namespace={$namespace}" );
        }
        
        if( !is_null($namespace) ) {
-               $cmq .= " AND cur_namespace = {$namespace}";
-               $omq .= " AND old_namespace = {$namespace}";
+               $minorQuery .= " AND page_namespace = {$namespace}";
        }
        
        extract( $dbr->tableNames( 'old', 'cur' ) );
-       if ( $userCond == '' ) {
-               # We may have to force the index, as some options will cause
-               # MySQL to incorrectly pick eg the namespace index.
-               list( $useIndex, $tailOpts ) = $dbr->makeSelectOptions( array(
-                       'USE INDEX' => 'usertext_timestamp',
-                       'LIMIT' => $querylimit ) );
-               
-               $sql = "SELECT cur_namespace,cur_title,cur_timestamp,cur_comment,cur_minor_edit,cur_is_new,cur_user_text FROM $cur $useIndex " .
-                 "WHERE cur_user_text='" . $dbr->strencode( $nt->getText() ) . "' {$cmq} " .
-                 "ORDER BY inverse_timestamp $tailOpts";
-               $res1 = $dbr->query( $sql, $fname );
-
-               $sql = "SELECT old_namespace,old_title,old_timestamp,old_comment,old_minor_edit,old_user_text,old_id FROM $old $useIndex " .
-                 "WHERE old_user_text='" . $dbr->strencode( $nt->getText() ) . "' {$omq} " .
-                 "ORDER BY inverse_timestamp $tailOpts";
-               $res2 = $dbr->query( $sql, $fname );
+       if ( $userCond == "" ) {
+               $condition = "rev_user_text=" . $dbr->addQuotes( $nt->getText() );
+               $index = 'usertext_timestamp';
        } else {
-               list( $useIndex, $tailOpts ) = $dbr->makeSelectOptions( array(
-                       'USE INDEX' => 'user_timestamp',
-                       'LIMIT' => $querylimit ) );
-               
-               $sql = "SELECT cur_namespace,cur_title,cur_timestamp,cur_comment,cur_minor_edit,cur_is_new,cur_user_text FROM $cur $useIndex " .
-                 "WHERE cur_user {$userCond} {$cmq} ORDER BY inverse_timestamp $tailOpts";
-               $res1 = $dbr->query( $sql, $fname );
-
-               $sql = "SELECT old_namespace,old_title,old_timestamp,old_comment,old_minor_edit,old_user_text,old_id FROM $old $useIndex " .
-                 "WHERE old_user {$userCond} {$omq} ORDER BY inverse_timestamp $tailOpts";
-               $res2 = $dbr->query( $sql, $fname );
+               $condition = "rev_user {$userCond}";
+               $index = 'user_timestamp';
        }
-       $nCur = $dbr->numRows( $res1 );
-       $nOld = $dbr->numRows( $res2 );
+       $page = $dbr->tableName( 'page' );
+       $revision = $dbr->tableName( 'revision' );
+       $sql = "SELECT
+               page_namespace,page_title,page_is_new,page_latest,
+               rev_id,rev_timestamp,rev_comment,rev_minor_edit,rev_user_text
+               FROM $page,$revision USE INDEX($index)
+               WHERE page_id=rev_page AND $condition $minorQuery " .
+         "ORDER BY inverse_timestamp LIMIT {$querylimit}";
+       $res = $dbr->query( $sql, $fname );
+       $numRows = $dbr->numRows( $res );
 
        $wgOut->addHTML( namespaceForm( $target, $hideminor, $namespace ) );
 
@@ -129,56 +113,31 @@ function wfSpecialContributions( $par = '' ) {
        $wgOut->addHTML( "<p>{$top}\n" );
 
        $sl = wfViewPrevNext( $offset, $limit,
-         $wgContLang->specialpage( 'Contributions' ),
+         $wgContLang->specialpage( "Contributions" ),
          "hideminor={$hideminor}&namespace={$namespace}&target=" . wfUrlEncode( $target ),
-         ($nCur + $nOld) <= $offlimit);
+         ($numRows) <= $offlimit);
 
-        $shm = wfMsg( 'showhideminor', $mlink );
+       $shm = wfMsg( "showhideminor", $mlink );
        $wgOut->addHTML( "<br />{$sl} ($shm)</p>\n");
 
 
-       if ( 0 == $nCur && 0 == $nOld ) {
-               $wgOut->addHTML( "\n<p>" . wfMsg( 'nocontribs' ) . "</p>\n" );
+       if ( 0 == $numRows ) {
+               $wgOut->addHTML( "\n<p>" . wfMsg( "nocontribs" ) . "</p>\n" );
                return;
        }
-       if ( 0 != $nCur ) { $obj1 = $dbr->fetchObject( $res1 ); }
-       if ( 0 != $nOld ) { $obj2 = $dbr->fetchObject( $res2 ); }
 
        $wgOut->addHTML( "<ul>\n" );
-       for( $n = 0; $n < $offlimit; $n++ ) {
-               if ( 0 == $nCur && 0 == $nOld ) { break; }
-
-               if ( ( 0 == $nOld ) ||
-                 ( ( 0 != $nCur ) &&
-                 ( $obj1->cur_timestamp >= $obj2->old_timestamp ) ) ) {
-                       $ns = $obj1->cur_namespace;
-                       $t = $obj1->cur_title;
-                       $ts = $obj1->cur_timestamp;
-                       $comment =$obj1->cur_comment;
-                       $me = $obj1->cur_minor_edit;
-                       $isnew = $obj1->cur_is_new;
-                       $usertext = $obj1->cur_user_text;
-
-                       $obj1 = $dbr->fetchObject( $res1 );
-                       $topmark = true;
-                       $oldid = false;
-                       --$nCur;
-               } else {
-                       $ns = $obj2->old_namespace;
-                       $t = $obj2->old_title;
-                       $ts = $obj2->old_timestamp;
-                       $comment =$obj2->old_comment;
-                       $me = $obj2->old_minor_edit;
-                       $usertext = $obj2->old_user_text;
-                       $oldid = $obj2->old_id;
-
-                       $obj2 = $dbr->fetchObject( $res2 );
-                       $topmark = false;
-                       $isnew = false;
-                       --$nOld;
-               }
-               if( $n >= $offset )
-                       ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, ( $me > 0), $isnew, $usertext, $oldid );
+       while( $obj = $dbr->fetchObject( $res ) ) {
+               ucListEdit( $sk,
+                       $obj->page_namespace,
+                       $obj->page_title,
+                       $obj->rev_timestamp,
+                       ($obj->rev_id == $obj->page_latest),
+                       $obj->rev_comment,
+                       ($obj->rev_minor_edit),
+                       $obj->page_is_new,
+                       $obj->rev_user_text,
+                       $obj->rev_id );
        }
        $wgOut->addHTML( "</ul>\n" );
 
index 2b15db6..3329e33 100644 (file)
@@ -44,12 +44,12 @@ class DeadendPagesPage extends PageQueryPage {
         */
        function getSQL() {
                $dbr =& wfGetDB( DB_SLAVE );
-               extract( $dbr->tableNames( 'cur', 'links' ) );
-               return "SELECT 'Deadendpages' as type, cur_namespace AS namespace, cur_title as title, cur_title AS value " . 
-       "FROM $cur LEFT JOIN $links ON cur_id = l_from " .
+               extract( $dbr->tableNames( 'page', 'links' ) );
+               return "SELECT 'Deadendpages' as type, page_namespace AS namespace, page_title as title, page_title AS value " . 
+       "FROM $page LEFT JOIN $links ON page_id = l_from " .
        "WHERE l_from IS NULL " .
-       "AND cur_namespace = 0 " .
-       "AND cur_is_redirect = 0";
+       "AND page_namespace = 0 " .
+       "AND page_is_redirect = 0";
     }
 }
 
index 0243e05..0c4693e 100644 (file)
@@ -34,18 +34,18 @@ class DisambiguationsPage extends PageQueryPage {
 
        function getSQL() {
                $dbr =& wfGetDB( DB_SLAVE );
-               extract( $dbr->tableNames( 'cur', 'links' ) );
+               extract( $dbr->tableNames( 'page', 'links' ) );
                
                $dp = Title::newFromText(wfMsgForContent("disambiguationspage"));
                $dpid = $dp->getArticleID();
                        
-               $sql = "SELECT ca.cur_namespace AS ns_art, ca.cur_title AS title_art,"
-                       .        " cb.cur_namespace AS ns_dis, cb.cur_title AS title_dis"
-                   . " FROM links as la, links as lb, cur as ca, cur as cb"
+               $sql = "SELECT pa.page_namespace AS ns_art, pa.page_title AS title_art,"
+                       .        " pb.page_namespace AS ns_dis, pb.page_title AS title_dis"
+                   . " FROM {$links} as la, {$links} as lb, {$page} as pa, {$page} as pb"
                    . " WHERE la.l_to = '{$dpid}'"
                    . " AND la.l_from = lb.l_to"
-                   . " AND ca.cur_id = lb.l_from"
-                   . " AND cb.cur_id = lb.l_to";
+                   . " AND pa.page_id = lb.l_from"
+                   . " AND pb.page_id = lb.l_to";
 
                return $sql;
        }
index 41091ce..977499b 100644 (file)
@@ -31,14 +31,15 @@ class DoubleRedirectsPage extends PageQueryPage {
 
        function getSQL() {
                $dbr =& wfGetDB( DB_SLAVE );
-               extract( $dbr->tableNames( 'cur', 'links' ) );
+               extract( $dbr->tableNames( 'page', 'links', 'text' ) );
 
-               $sql = "SELECT ca.cur_namespace as ns_a, ca.cur_title as title_a," . 
-                          "  cb.cur_namespace as ns_b, cb.cur_title as title_b," .
-                          "  cb.cur_text AS rt " . 
-                          "FROM $links,$cur AS ca,$cur AS cb ". 
-                          "WHERE ca.cur_is_redirect=1 AND cb.cur_is_redirect=1 AND l_to=cb.cur_id " .
-                          "  AND l_from=ca.cur_id " ;
+               $sql = "SELECT pa.page_namespace as ns_a, pa.page_title as title_a,
+                            pb.page_namespace as ns_b, pb.page_title as title_b,
+                            old_text AS rt 
+                          FROM $text AS t, $links,$page AS pa,$page AS pb 
+                          WHERE pa.page_is_redirect=1 AND pb.page_is_redirect=1 AND l_to=pb.page_id 
+                            AND l_from=pa.page_id 
+                            AND pb.page_latest=t.old_id" ;
                return $sql;
        }
 
index e3c0b5a..6d6dbbb 100644 (file)
@@ -59,9 +59,9 @@ class LogReader {
         * @private
         */
        function setupQuery( $request ) {
-               $cur = $this->db->tableName( 'cur' );
+               $page = $this->db->tableName( 'page' );
                $user = $this->db->tableName( 'user' );
-               $this->joinClauses = array( "LEFT OUTER JOIN $cur ON log_namespace=cur_namespace AND log_title=cur_title" );
+               $this->joinClauses = array( "LEFT OUTER JOIN $page ON log_namespace=page_namespace AND log_title=page_title" );
                $this->whereClauses = array( 'user_id=log_user' );
                
                $this->limitType( $request->getVal( 'type' ) );
@@ -145,7 +145,7 @@ class LogReader {
                $user = $this->db->tableName( 'user' );
                $sql = "SELECT log_type, log_action, log_timestamp,
                        log_user, user_name,
-                       log_namespace, log_title, cur_id,
+                       log_namespace, log_title, page_id,
                        log_comment FROM $user, $logging ";
                if( !empty( $this->joinClauses ) ) {
                        $sql .= implode( ',', $this->joinClauses );
@@ -250,7 +250,7 @@ class LogViewer {
                $title = Title::makeTitle( $s->log_namespace, $s->log_title );
                $user = Title::makeTitleSafe( NS_USER, $s->user_name );
                $time = $wgLang->timeanddate( $s->log_timestamp );
-               if( $s->cur_id ) {
+               if( $s->page_id ) {
                        $titleLink = $this->skin->makeKnownLinkObj( $title );
                } else {
                        $titleLink = $this->skin->makeBrokenLinkObj( $title );
index d8d97d8..86e0b8d 100644 (file)
@@ -32,11 +32,11 @@ class LonelyPagesPage extends PageQueryPage {
        
        function getSQL() {
                $dbr =& wfGetDB( DB_SLAVE );
-               extract( $dbr->tableNames( 'cur', 'links' ) );
+               extract( $dbr->tableNames( 'page', 'links' ) );
 
-               return "SELECT 'Lonelypages' as type, cur_namespace AS namespace, cur_title AS title, cur_title AS value " .
-                       "FROM $cur LEFT JOIN $links ON cur_id=l_to ".
-                       "WHERE l_to IS NULL AND cur_namespace=0 AND cur_is_redirect=0";
+               return "SELECT 'Lonelypages' as type, page_namespace AS namespace, page_title AS title, page_title AS value " .
+                       "FROM $page LEFT JOIN $links ON page_id=l_to ".
+                       "WHERE l_to IS NULL AND page_namespace=0 AND page_is_redirect=0";
        }
 }
 
index 85c1510..abd88a1 100644 (file)
@@ -157,8 +157,8 @@ function wfSpecialSelfLinks() {
 
        list( $limit, $offset ) = wfCheckLimits();
 
-       $sql = "SELECT cur_namespace,cur_title FROM cur,links " . 
-         "WHERE l_from=l_to AND l_to=cur_id " . 
+       $sql = "SELECT page_namespace,page_title FROM page,links " . 
+         "WHERE l_from=l_to AND l_to=page_id " . 
          "LIMIT {$offset}, {$limit}";
 
        $res = wfQuery( $sql, DB_SLAVE, $fname );
@@ -175,7 +175,7 @@ function wfSpecialSelfLinks() {
        $sk = $wgUser->getSkin();
        $s = '<ol start=' . ( $offset + 1 ) . '>';
        while ( $obj = wfFetchObject( $res ) ) {
-               $title = Title::makeTitle( $obj->cur_namespace, $obj->cur_title );
+               $title = Title::makeTitle( $obj->page_namespace, $obj->page_title );
                $s .= "<li>".$sk->makeKnownLinkObj( $title )."</li>\n" ;
        }
        wfFreeResult( $res );
index 123ab1d..9367a5e 100644 (file)
@@ -32,8 +32,9 @@ class NewPagesPage extends QueryPage {
                $usepatrol = ( $wgUseRCPatrol && $wgUser->getID() != 0 &&
                               ( $wgUser->isAllowed('patrol') || !$wgOnlySysopsCanPatrol ) ) ? 1 : 0;
                $dbr =& wfGetDB( DB_SLAVE );
-               extract( $dbr->tableNames( 'recentchanges', 'cur' ) );
+               extract( $dbr->tableNames( 'recentchanges', 'page', 'text' ) );
 
+               # FIXME: text will break with compression
                return
                        "SELECT 'Newpages' as type,
                                rc_namespace AS namespace,
@@ -46,11 +47,12 @@ class NewPagesPage extends QueryPage {
                                '{$usepatrol}' as usepatrol,
                                rc_patrolled AS patrolled,
                                rc_id AS rcid,
-                               length(cur_text) as length,
-                               cur_text as text
-                       FROM $recentchanges,$cur
-                       WHERE rc_cur_id=cur_id AND rc_new=1
-                         AND rc_namespace=0 AND cur_is_redirect=0";
+                               length(old_text) as length,
+                               old_text as text
+                       FROM $recentchanges,$page,$text
+                       WHERE rc_cur_id=page_id AND rc_new=1
+                         AND rc_namespace=0 AND page_is_redirect=0
+                         AND page_latest=old_id";
        }
 
        function formatResult( $skin, $result ) {
index ca96168..3234996 100644 (file)
@@ -22,22 +22,22 @@ class PopularPagesPage extends QueryPage {
        }
 
        function isExpensive() {
-               # cur_counter is not indexed
+               # page_counter is not indexed
                return true;
        }
        function isSyndicated() { return false; }
 
        function getSQL() {
                $dbr =& wfGetDB( DB_SLAVE );
-               $cur = $dbr->tableName( 'cur' );
+               $page = $dbr->tableName( 'page' );
 
                return
                        "SELECT 'Popularpages' as type,
-                               cur_namespace as namespace,
-                               cur_title as title,
-                               cur_counter as value
-                       FROM $cur
-                       WHERE cur_namespace=0 AND cur_is_redirect=0";
+                               page_namespace as namespace,
+                               page_title as title,
+                               page_counter as value
+                       FROM $page
+                       WHERE page_namespace=0 AND page_is_redirect=0";
        }
 
        function formatResult( $skin, $result ) {
index 62269ec..9a9326c 100644 (file)
@@ -24,25 +24,25 @@ function wfSpecialRandompage() {
        $randstr = wfRandom();
        
        $db =& wfGetDB( DB_SLAVE );
-       $use_index = $db->useIndexClause( 'cur_random' );
-       $cur = $db->tableName( 'cur' );
+       $use_index = $db->useIndexClause( 'page_random' );
+       $page = $db->tableName( 'page' );
 
        if ( $wgExtraRandompageSQL ) {
                $extra = "AND ($wgExtraRandompageSQL)";
        } else {
                $extra = '';
        }
-       $sqlget = "SELECT cur_id,cur_title
-               FROM $cur $use_index
-               WHERE cur_namespace=0 AND cur_is_redirect=0 $extra
-               AND cur_random>$randstr
-               ORDER BY cur_random
+       $sqlget = "SELECT page_id,page_title
+               FROM $page $use_index
+               WHERE page_namespace=0 AND page_is_redirect=0 $extra
+               AND page_random>$randstr
+               ORDER BY page_random
                LIMIT 1";
        $res = $db->query( $sqlget, $fname );
        
        $title = null;
        if( $s = $db->fetchObject( $res ) ) {
-               $title =& Title::makeTitle( NS_MAIN, $s->cur_title );
+               $title =& Title::makeTitle( NS_MAIN, $s->page_title );
        }       
        if( is_null( $title ) ) {
                # That's not supposed to happen :)
index be254df..b90b7b6 100644 (file)
@@ -62,27 +62,24 @@ function wfSpecialRecentchangeslinked( $par = NULL ) {
                  "&days={$days}&limit={$limit}&hideminor=1" );
        }
        if ( $hideminor ) {
-               $cmq = 'AND cur_minor_edit=0';
+               $cmq = 'AND rev_minor_edit=0';
        } else { $cmq = ''; }
 
        // If target is a Category, use categorylinks and invert from and to
-       if ( $nt->getNamespace() == NS_CATEGORY ) {
-               extract( $dbr->tableNames( 'cur', 'categorylinks' ) );
+       if( $nt->getNamespace() == NS_CATEGORY ) {
                $catkey = $dbr->addQuotes( $nt->getDBKey() );
-               $sql = "SELECT cur_id,cur_namespace,cur_title,cur_user,cur_comment," .
-                 "cur_user_text,cur_timestamp,cur_minor_edit,cur_is_new FROM $categorylinks, $cur " .
-                 "WHERE cur_timestamp > '{$cutoff}' {$cmq} AND cl_from=cur_id AND cl_to=$catkey " .
-                 "GROUP BY cur_id,cur_namespace,cur_title,cur_user,cur_comment,cur_user_text," .
-                 "cur_timestamp,cur_minor_edit,cur_is_new,inverse_timestamp ORDER BY inverse_timestamp LIMIT {$limit}";
+               $sql = "SELECT page_id,page_namespace,page_title,rev_user,rev_comment," .
+                 "rev_user_text,rev_timestamp,rev_minor_edit,page_is_new FROM $categorylinks, $revision, $page " .
+                 "WHERE rev_timestamp > '{$cutoff}' {$cmq} AND cl_from=page_id AND cl_to=$catkey " .
+                         "GROUP BY page_id,page_namespace,page_title,rev_user,rev_comment,rev_user_text," .
+                 "rev_timestamp,rev_minor_edit,page_is_new,inverse_timestamp ORDER BY inverse_timestamp LIMIT {$limit}";
        } else {
-               extract( $dbr->tableNames( 'cur', 'links' ) );
-               $sql = "SELECT cur_id,cur_namespace,cur_title,cur_user,cur_comment," .
-                 "cur_user_text,cur_timestamp,cur_minor_edit,cur_is_new FROM $links, $cur " .
-                 "WHERE cur_timestamp > '{$cutoff}' {$cmq} AND l_to=cur_id AND l_from=$id " .
-                         "GROUP BY cur_id,cur_namespace,cur_title,cur_user,cur_comment,cur_user_text," .
-                 "cur_timestamp,cur_minor_edit,cur_is_new,inverse_timestamp ORDER BY inverse_timestamp LIMIT {$limit}";
+               $sql = "SELECT page_id,page_namespace,page_title,rev_user,rev_comment," .
+                 "rev_user_text,rev_timestamp,rev_minor_edit,page_is_new FROM $links, $revision, $page " .
+                 "WHERE rev_timestamp > '{$cutoff}' {$cmq} AND l_to=page_id AND l_from=$id " .
+                         "GROUP BY page_id,page_namespace,page_title,rev_user,rev_comment,rev_user_text," .
+                 "rev_timestamp,rev_minor_edit,page_is_new,inverse_timestamp ORDER BY inverse_timestamp LIMIT {$limit}";
        }
-
        $res = $dbr->query( $sql, $fname );
 
        $wgOut->addHTML("&lt; ".$sk->makeKnownLinkObj($nt, "", "redirect=no" )."<br />\n");
index c604313..d4e5e64 100644 (file)
@@ -292,7 +292,7 @@ class SpecialSearch {
                wfProfileIn( $fname );
                global $wgUser, $wgContLang;
 
-               $t = Title::makeTitle( $row->cur_namespace, $row->cur_title );
+               $t = Title::makeTitle( $row->page_namespace, $row->page_title );
                if( is_null( $t ) ) {
                        wfProfileOut( $fname );
                        return "<!-- Broken link in search result -->\n";
@@ -305,9 +305,10 @@ class SpecialSearch {
                if ( '' == $contextchars ) { $contextchars = 50; }
 
                $link = $sk->makeKnownLinkObj( $t, '' );
-               $size = wfMsg( 'nbytes', strlen( $row->cur_text ) );
+               $text = Article::getRevisionText( $row );
+               $size = wfMsg( 'nbytes', strlen( $text ) );
 
-               $lines = explode( "\n", $row->cur_text );
+               $lines = explode( "\n", $text );
 
                $max = IntVal( $contextchars ) + 1;
                $pat1 = "/(.*)($terms)(.{0,$max})/i";
index 3faf483..1467a44 100644 (file)
@@ -29,16 +29,21 @@ class ShortPagesPage extends QueryPage {
 
        function getSQL() {
                $dbr =& wfGetDB( DB_SLAVE );
-               $cur = $dbr->tableName( 'cur' );
+               $page = $dbr->tableName( 'page' );
+               $text = $dbr->tableName( 'text' );
                $name = $dbr->addQuotes( $this->getName() );
                
+               # FIXME: Not only is this teh suck, it will fail
+               # if we compress revisions on save as it will return
+               # the compressed size.
                return
                        "SELECT $name as type,
-                                       cur_namespace as namespace,
-                               cur_title as title,
-                               LENGTH(cur_text) AS value
-                       FROM $cur
-                       WHERE cur_namespace=0 AND cur_is_redirect=0";
+                                       page_namespace as namespace,
+                               page_title as title,
+                               LENGTH(old_text) AS value
+                       FROM $page, $text
+                       WHERE page_namespace=0 AND page_is_redirect=0
+                         AND page_latest=old_id";
        }
        
        function sortDescending() {
index 91d845c..36c3c16 100644 (file)
@@ -15,9 +15,9 @@ function wfSpecialStatistics() {
        $wgOut->addHTML( "<h2>" . wfMsg( "sitestats" ) . "</h2>\n" );
        
        $dbr =& wfGetDB( DB_SLAVE );
-       extract( $dbr->tableNames( 'cur', 'site_stats', 'user', 'user_rights' ) );
+       extract( $dbr->tableNames( 'page', 'site_stats', 'user', 'user_rights' ) );
 
-       $sql = "SELECT COUNT(cur_id) AS total FROM $cur";
+       $sql = "SELECT COUNT(page_id) AS total FROM $page";
        $res = $dbr->query( $sql, $fname );
        $row = $dbr->fetchObject( $res );
        $total = $row->total;
index b8d2cd9..d35a889 100755 (executable)
@@ -33,11 +33,11 @@ class UncategorizedPagesPage extends PageQueryPage {
        
        function getSQL() {
                $dbr =& wfGetDB( DB_SLAVE );
-               extract( $dbr->tableNames( 'cur', 'categorylinks' ) );
+               extract( $dbr->tableNames( 'page', 'categorylinks' ) );
 
-               return "SELECT 'Uncategorizedpages' as type, cur_namespace AS namespace, cur_title AS title, cur_title AS value " .
-                       "FROM $cur LEFT JOIN $categorylinks ON cur_id=cl_from ".
-                       "WHERE cl_from IS NULL AND cur_namespace=$this->requestedNamespace AND cur_is_redirect=0";
+               return "SELECT 'Uncategorizedpages' as type, page_namespace AS namespace, page_title AS title, page_title AS value " .
+                       "FROM $page LEFT JOIN $categorylinks ON page_id=cl_from ".
+                       "WHERE cl_from IS NULL AND page_namespace=$this->requestedNamespace AND page_is_redirect=0";
        }
 }
 
index ea295dc..25f4ef7 100644 (file)
@@ -74,7 +74,7 @@ function wfSpecialWatchlist() {
        }
 
        $dbr =& wfGetDB( DB_SLAVE );
-       extract( $dbr->tableNames( 'cur', 'watchlist', 'recentchanges' ) );
+       extract( $dbr->tableNames( 'page', 'revision', 'watchlist', 'recentchanges' ) );
 
        $sql = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_user=$uid";
        $res = $dbr->query( $sql, $fname );
@@ -107,10 +107,10 @@ function wfSpecialWatchlist() {
                $cutoff = false;
                $npages = wfMsg( "all" );
        } else {
-               $docutoff = "AND cur_timestamp > '" .
+               $docutoff = "AND rev_timestamp > '" .
                  ( $cutoff = $dbr->timestamp( time() - intval( $days * 86400 ) ) )
                  . "'";
-               $sql = "SELECT COUNT(*) AS n FROM $cur WHERE cur_timestamp>'$cutoff'";
+               $sql = "SELECT COUNT(*) AS n FROM $page, $revision  WHERE rev_timestamp>'$cutoff' AND page_id=rev_page";
                $res = $dbr->query( $sql, $fname );
                $s = $dbr->fetchObject( $res );
                $npages = $s->n;
@@ -160,19 +160,19 @@ function wfSpecialWatchlist() {
 
        # Up estimate of watched items by 15% to compensate for talk pages...
        if( $cutoff && ( $nitems*1.15 > $npages ) ) {
-               $x = "cur_timestamp";
+               $x = "rev_timestamp";
                $y = wfMsg( "watchmethod-recent" );
                # TG patch: here we do not consider pages and their talk pages equivalent - why should we ?
                # The change results in talk-pages not automatically included in watchlists, when their parent page is included
                # $z = "wl_namespace=cur_namespace & ~1";
-               $z = "wl_namespace=cur_namespace";
+               $z = "wl_namespace=page_namespace";
        } else {
-               $x = "name_title_timestamp";
+               $x = "page_timestamp";
                $y = wfMsg( "watchmethod-list" );
                # TG patch: here we do not consider pages and their talk pages equivalent - why should we ?
                # The change results in talk-pages not automatically included in watchlists, when their parent page is included
                # $z = "(wl_namespace=cur_namespace OR wl_namespace+1=cur_namespace)";
-               $z = "wl_namespace=cur_namespace";
+               $z = "wl_namespace=page_namespace";
        }
 
 
@@ -182,14 +182,15 @@ function wfSpecialWatchlist() {
 
        $use_index = $dbr->useIndexClause( $x );
        $sql = "SELECT
-  cur_namespace,cur_title,cur_comment, cur_id,
-  cur_user,cur_user_text,cur_timestamp,cur_minor_edit,cur_is_new,wl_notificationtimestamp
-  FROM $watchlist,$cur $use_index
+  page_namespace,page_title,rev_comment, page_id,
+  rev_user,rev_user_text,rev_timestamp,rev_minor_edit,page_is_new,wl_notificationtimestamp
+  FROM $watchlist,$page,$revision  $use_index
   WHERE wl_user=$uid
   AND $z
-  AND wl_title=cur_title
+  AND wl_title=page_title
+  AND page_latest=rev_id
   $docutoff
-  ORDER BY cur_timestamp DESC";
+  ORDER BY rev_timestamp DESC";
 
 
        $res = $dbr->query( $sql, $fname );
index 9c4b7c8..df0c075 100644 (file)
@@ -36,11 +36,11 @@ function wfSpecialWhatlinkshere($par = NULL) {
 
        $wgOut->addHTML("&lt; ".$sk->makeKnownLinkObj($nt, "", "redirect=no" )."<br />\n");
        $dbr =& wfGetDB( DB_SLAVE );
-       extract( $dbr->tableNames( 'cur', 'brokenlinks', 'links' ) );
+       extract( $dbr->tableNames( 'page', 'brokenlinks', 'links' ) );
 
        if ( 0 == $id ) {
-               $sql = "SELECT cur_id,cur_namespace,cur_title,cur_is_redirect FROM $brokenlinks,$cur WHERE bl_to='" .
-                 $dbr->strencode( $nt->getPrefixedDBkey() ) . "' AND bl_from=cur_id LIMIT $limit";
+               $sql = "SELECT page_id,page_namespace,page_title,page_is_redirect FROM $brokenlinks,$page WHERE bl_to='" .
+                 $dbr->strencode( $nt->getPrefixedDBkey() ) . "' AND bl_from=page_id LIMIT $limit";
                $res = $dbr->query( $sql, $fname );
 
                if ( 0 == $dbr->numRows( $res ) ) {
@@ -50,16 +50,16 @@ function wfSpecialWhatlinkshere($par = NULL) {
                        $wgOut->addHTML( "\n<ul>" );
 
                        while ( $row = $dbr->fetchObject( $res ) ) {
-                               $nt = Title::makeTitle( $row->cur_namespace, $row->cur_title );
+                               $nt = Title::makeTitle( $row->page_namespace, $row->page_title );
                                if( !$nt ) {
                                        continue;
                                }
                                $link = $sk->makeKnownLinkObj( $nt, "", "redirect=no" );
                                $wgOut->addHTML( "<li>{$link}" );
 
-                               if ( $row->cur_is_redirect ) {
+                               if ( $row->page_is_redirect ) {
                                        $wgOut->addHTML( $isredir );
-                                       wfShowIndirectLinks( 1, $row->cur_id, $limit );
+                                       wfShowIndirectLinks( 1, $row->page_id, $limit );
                                }
                                $wgOut->addHTML( "</li>\n" );
                        }
@@ -79,9 +79,9 @@ function wfShowIndirectLinks( $level, $lid, $limit ) {
        $fname = "wfShowIndirectLinks";
 
        $dbr =& wfGetDB( DB_READ );
-       extract( $dbr->tableNames( 'links','cur' ) );
+       extract( $dbr->tableNames( 'links','page' ) );
 
-       $sql = "SELECT cur_id,cur_namespace,cur_title,cur_is_redirect FROM $links,$cur WHERE l_to={$lid} AND l_from=cur_id LIMIT $limit";
+       $sql = "SELECT page_id,page_namespace,page_title,page_is_redirect FROM $links,$page WHERE l_to={$lid} AND l_from=page_id LIMIT $limit";
        $res = $dbr->query( $sql, $fname );
 
        if ( 0 == $dbr->numRows( $res ) ) {
@@ -98,13 +98,13 @@ function wfShowIndirectLinks( $level, $lid, $limit ) {
 
        $wgOut->addHTML( "<ul>" );
        while ( $row = $dbr->fetchObject( $res ) ) {
-               $nt = Title::makeTitle( $row->cur_namespace, $row->cur_title );
+               $nt = Title::makeTitle( $row->page_namespace, $row->page_title );
                if( !$nt ) {
                        $wgOut->addHTML( "<!-- bad backlink: " . htmlspecialchars( $row->l_from ) . " -->\n" );
                        continue;
                }
 
-               if ( $row->cur_is_redirect ) {
+               if ( $row->page_is_redirect ) {
                        $extra = "redirect=no";
                } else {
                        $extra = "";
@@ -113,10 +113,10 @@ function wfShowIndirectLinks( $level, $lid, $limit ) {
                $link = $sk->makeKnownLinkObj( $nt, "", $extra );
                $wgOut->addHTML( "<li>{$link}" );
 
-               if ( $row->cur_is_redirect ) {
+               if ( $row->page_is_redirect ) {
                        $wgOut->addHTML( $isredir );
                        if ( $level < 2 ) {
-                               wfShowIndirectLinks( $level + 1, $row->cur_id, $limit );
+                               wfShowIndirectLinks( $level + 1, $row->page_id, $limit );
                        }
                }
                $wgOut->addHTML( "</li>\n" );
index d35ffb3..1c91d54 100644 (file)
@@ -33,15 +33,15 @@ class SquidUpdate {
 
                $dbr =& wfGetDB( DB_SLAVE );
                $links = $dbr->tableName( 'links' );
-               $cur = $dbr->tableName( 'cur' );
+               $page = $dbr->tableName( 'page' );
 
-               $sql = "SELECT cur_namespace,cur_title FROM $links,$cur WHERE l_to={$id} and l_from=cur_id" ;
+               $sql = "SELECT page_namespace,page_title FROM $links,$page WHERE l_to={$id} and l_from=page_id" ;
                $res = $dbr->query( $sql, $fname ) ;
                $blurlArr = $title->getSquidURLs();
                if ( $dbr->numRows( $res ) <= $this->mMaxTitles ) {
                        while ( $BL = $dbr->fetchObject ( $res ) )
                        {
-                               $tobj = Title::makeTitle( $BL->cur_namespace, $BL->cur_title ) ; 
+                               $tobj = Title::makeTitle( $BL->page_namespace, $BL->page_title ) ; 
                                $blurlArr[] = $tobj->getInternalURL();
                        }
                }
@@ -58,16 +58,16 @@ class SquidUpdate {
                # Get a list of URLs linking to this (currently non-existent) page
                $dbr =& wfGetDB( DB_SLAVE );
                $brokenlinks = $dbr->tableName( 'brokenlinks' );
-               $cur = $dbr->tableName( 'cur' );
+               $page = $dbr->tableName( 'page' );
                $encTitle = $dbr->addQuotes( $title->getPrefixedDBkey() );
 
-               $sql = "SELECT cur_namespace,cur_title FROM $brokenlinks,$cur WHERE bl_to={$encTitle} AND bl_from=cur_id";
+               $sql = "SELECT page_namespace,page_title FROM $brokenlinks,$cur WHERE bl_to={$encTitle} AND bl_from=page_id";
                $res = $dbr->query( $sql, $fname );
                $blurlArr = array();
                if ( $dbr->numRows( $res ) <= $this->mMaxTitles ) {
                        while ( $BL = $dbr->fetchObject( $res ) )
                        {
-                               $tobj = Title::makeTitle( $BL->cur_namespace, $BL->cur_title );
+                               $tobj = Title::makeTitle( $BL->page_namespace, $BL->page_title );
                                $blurlArr[] = $tobj->getInternalURL();
                        }
                }
index b65d059..e0dd5b2 100644 (file)
@@ -165,19 +165,19 @@ class Title {
        
        /**
         * Create a new Title from an article ID
-        * @todo This is inefficiently implemented, the cur row is requested
+        * @todo This is inefficiently implemented, the page row is requested
         * but not used for anything else
-        * @param int $id the cur_id corresponding to the Title to create
+        * @param int $id the page_id corresponding to the Title to create
         * @return Title the new object, or NULL on an error
         * @access public
         */
        /* static */ function newFromID( $id ) {
                $fname = 'Title::newFromID';
                $dbr =& wfGetDB( DB_SLAVE );
-               $row = $dbr->selectRow( 'cur', array( 'cur_namespace', 'cur_title' ), 
-                       array( 'cur_id' => $id ), $fname );
+               $row = $dbr->selectRow( 'page', array( 'page_namespace', 'page_title' ), 
+                       array( 'page_id' => $id ), $fname );
                if ( $row !== false ) {
-                       $title = Title::makeTitle( $row->cur_namespace, $row->cur_title );
+                       $title = Title::makeTitle( $row->page_namespace, $row->page_title );
                } else {
                        $title = NULL;
                }
@@ -275,7 +275,7 @@ class Title {
 
        /**
         * Get the prefixed DB key associated with an ID
-        * @param int $id the cur_id of the article
+        * @param int $id the page_id of the article
         * @return Title an object representing the article, or NULL
         *      if no such article was found
         * @static
@@ -285,10 +285,10 @@ class Title {
                $fname = 'Title::nameOf';
                $dbr =& wfGetDB( DB_SLAVE );
                
-               $s = $dbr->selectRow( 'cur', array( 'cur_namespace','cur_title' ),  array( 'cur_id' => $id ), $fname );
+               $s = $dbr->selectRow( 'page', array( 'page_namespace','page_title' ),  array( 'page_id' => $id ), $fname );
                if ( $s === false ) { return NULL; }
 
-               $n = Title::makeName( $s->cur_namespace, $s->cur_title );
+               $n = Title::makeName( $s->page_namespace, $s->page_title );
                return $n;
        }
 
@@ -436,7 +436,7 @@ class Title {
        }
 
        /**
-        * Update the cur_touched field for an array of title objects
+        * Update the page_touched field for an array of title objects
         * @todo Inefficient unless the IDs are already loaded into the
         *      link cache
         * @param array $titles an array of Title objects to be touched
@@ -453,8 +453,8 @@ class Title {
                if ( $timestamp == '' ) {
                        $timestamp = $dbw->timestamp();
                }
-               $cur = $dbw->tableName( 'cur' );
-               $sql = "UPDATE $cur SET cur_touched='{$timestamp}' WHERE cur_id IN (";
+               $page = $dbw->tableName( 'page' );
+               $sql = "UPDATE $page SET page_touched='{$timestamp}' WHERE page_id IN (";
                $first = true;
 
                foreach ( $titles as $title ) {
@@ -926,7 +926,7 @@ class Title {
 
                if ( ! $this->mRestrictionsLoaded ) {
                        $dbr =& wfGetDB( DB_SLAVE );
-                       $res = $dbr->selectField( 'cur', 'cur_restrictions', 'cur_id='.$id );
+                       $res = $dbr->selectField( 'page', 'page_restrictions', 'page_id='.$id );
                        $this->loadRestrictions( $res );
                }
                if( isset( $this->mRestrictions[$action] ) ) {
@@ -976,7 +976,7 @@ class Title {
         * keys in the "bad links" section of $wgLinkCache.
         *
         * - This is called from Article::insertNewArticle() to allow
-        * loading of the new cur_id. It's also called from
+        * loading of the new page_id. It's also called from
         * Article::doDeleteArticle()
         *
         * @param int $newid the new Article ID
@@ -993,19 +993,19 @@ class Title {
        }
        
        /**
-        * Updates cur_touched for this page; called from LinksUpdate.php
+        * Updates page_touched for this page; called from LinksUpdate.php
         * @return bool true if the update succeded
         * @access public
         */
        function invalidateCache() {
                $now = wfTimestampNow();
                $dbw =& wfGetDB( DB_MASTER );
-               $success = $dbw->update( 'cur', 
+               $success = $dbw->update( 'page', 
                        array( /* SET */ 
-                               'cur_touched' => $dbw->timestamp()
+                               'page_touched' => $dbw->timestamp()
                        ), array( /* WHERE */ 
-                               'cur_namespace' => $this->getNamespace() ,
-                               'cur_title' => $this->getDBkey()
+                               'page_namespace' => $this->getNamespace() ,
+                               'page_title' => $this->getDBkey()
                        ), 'Title::invalidateCache'
                );
                return $success;
@@ -1167,7 +1167,7 @@ class Title {
                }
 
                # We shouldn't need to query the DB for the size.
-               #$maxSize = $dbr->textFieldSize( 'cur', 'cur_title' );
+               #$maxSize = $dbr->textFieldSize( 'page', 'page_title' );
                if ( strlen( $r ) > 255 ) {
                        return false;
                }
@@ -1233,16 +1233,16 @@ class Title {
                } else {
                        $db =& wfGetDB( DB_SLAVE );
                }
-               $cur = $db->tableName( 'cur' );
+               $page = $db->tableName( 'page' );
                $links = $db->tableName( 'links' );
 
-               $sql = "SELECT cur_namespace,cur_title,cur_id FROM $cur,$links WHERE l_from=cur_id AND l_to={$id} $options";
+               $sql = "SELECT page_namespace,page_title,page_id FROM $page,$links WHERE l_from=page_id AND l_to={$id} $options";
                $res = $db->query( $sql, 'Title::getLinksTo' );
                $retVal = array();
                if ( $db->numRows( $res ) ) {
                        while ( $row = $db->fetchObject( $res ) ) {
-                               if ( $titleObj = Title::makeTitle( $row->cur_namespace, $row->cur_title ) ) {
-                                       $wgLinkCache->addGoodLink( $row->cur_id, $titleObj->getPrefixedDBkey() );
+                               if ( $titleObj = Title::makeTitle( $row->page_namespace, $row->page_title ) ) {
+                                       $wgLinkCache->addGoodLink( $row->page_id, $titleObj->getPrefixedDBkey() );
                                        $retVal[] = $titleObj;
                                }
                        }
@@ -1267,18 +1267,18 @@ class Title {
                } else {
                        $db =& wfGetDB( DB_SLAVE );
                }
-               $cur = $db->tableName( 'cur' );
+               $page = $db->tableName( 'page' );
                $brokenlinks = $db->tableName( 'brokenlinks' );
                $encTitle = $db->strencode( $this->getPrefixedDBkey() );
 
-               $sql = "SELECT cur_namespace,cur_title,cur_id FROM $brokenlinks,$cur " .
-                 "WHERE bl_from=cur_id AND bl_to='$encTitle' $options";
+               $sql = "SELECT page_namespace,page_title,page_id FROM $brokenlinks,$page " .
+                 "WHERE bl_from=page_id AND bl_to='$encTitle' $options";
                $res = $db->query( $sql, "Title::getBrokenLinksTo" );
                $retVal = array();
                if ( $db->numRows( $res ) ) {
                        while ( $row = $db->fetchObject( $res ) ) {
-                               $titleObj = Title::makeTitle( $row->cur_namespace, $row->cur_title );
-                               $wgLinkCache->addGoodLink( $row->cur_id, $titleObj->getPrefixedDBkey() );
+                               $titleObj = Title::makeTitle( $row->page_namespace, $row->page_title );
+                               $wgLinkCache->addGoodLink( $row->page_id, $titleObj->getPrefixedDBkey() );
                                $retVal[] = $titleObj;
                        }
                }
@@ -1400,6 +1400,7 @@ class Title {
                
                $now = wfTimestampNow();
                $won = wfInvertTimestamp( $now );
+               $rand = wfRandom();
                $newid = $nt->getArticleID();
                $oldid = $this->getArticleID();
                $dbw =& wfGetDB( DB_MASTER );
@@ -1409,59 +1410,49 @@ class Title {
                # by definition if we've got here it's rather uninteresting.
                # We have to remove it so that the next step doesn't trigger
                # a conflict on the unique namespace+title index...
-               $dbw->delete( 'cur', array( 'cur_id' => $newid ), $fname );
+               $dbw->delete( 'page', array( 'page_id' => $newid ), $fname );
                
                # Change the name of the target page:
-               $dbw->update( 'cur',
+               $dbw->update( 'page',
                        /* SET */ array( 
-                               'cur_touched' => $dbw->timestamp($now), 
-                               'cur_namespace' => $nt->getNamespace(),
-                               'cur_title' => $nt->getDBkey()
+                               'page_touched' => $dbw->timestamp($now), 
+                               'page_namespace' => $nt->getNamespace(),
+                               'page_title' => $nt->getDBkey()
                        ), 
-                       /* WHERE */ array( 'cur_id' => $oldid ),
+                       /* WHERE */ array( 'page_id' => $oldid ),
                        $fname
                );
                $wgLinkCache->clearLink( $nt->getPrefixedDBkey() );
 
                # Recreate the redirect, this time in the other direction.
                $redirectText = $wgMwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
-               $dbw->insert( 'cur',
-                       /* SET */ array(
-                               'cur_id' => $newid,
-                               'cur_touched' => $dbw->timestamp($now),
-                               'cur_timestamp' => $dbw->timestamp($now),
-                               'inverse_timestamp' => $won,
-                               'cur_namespace' => $this->getNamespace(),
-                               'cur_title' => $this->getDBkey(),
-                               'cur_text' => $wgMwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n",
-                               'cur_comment' => $comment,
-                               'cur_user' => $wgUser->getID(),
-                               'cur_minor_edit' => 0,
-                               'cur_counter' => 0,
-                               'cur_restrictions' => '',
-                               'cur_user_text' => $wgUser->getName(),
-                               'cur_is_redirect' => 1,
-                               'cur_is_new' => 1
-                       ),
-                       $fname
+               $dbw->insert( 'revision', array(
+                       'rev_id' => $dbw->nextSequenceValue('rev_rev_id_seq'),
+                       'rev_comment' => $comment,
+                       'rev_user' => $wgUser->getID(),
+                       'rev_user_text' => $wgUser->getName(),
+                       'rev_timestamp' => $now,
+                       'inverse_timestamp' => $won ), $fname
                );
-               
-               $wgLinkCache->clearLink( $this->getPrefixedDBkey() );
-
-               # Fix the redundant names for the past revisions of the target page.
-               # The redirect should have no old revisions.
-               $dbw->update(
-                       /* table */ 'old',
-                       /* SET */ array( 
-                               'old_namespace' => $nt->getNamespace(),
-                               'old_title' => $nt->getDBkey(),
-                       ),
-                       /* WHERE */ array( 
-                               'old_namespace' => $this->getNamespace(),
-                               'old_title' => $this->getDBkey(),
-                       ),
-                       $fname
+               $revid = $dbw->insertId();
+               $dbw->insert( 'text', array(
+                       'old_id' => $revid,
+                       'old_flags' => '',
+                       'old_text' => $redirectText,
+                       ), $fname
                );
+               $dbw->insert( 'page', array(
+                       'page_id' => $dbw->nextSequenceValue('page_page_id_seq'),
+                       'page_namespace' => $this->getNamespace(),
+                       'page_title' => $this->getDBkey(),
+                       'page_touched' => $now,
+                       'page_is_redirect' => 1,
+                       'page_random' => $rand,
+                       'page_is_new' => 1,
+                       'page_latest' => $revid), $fname
+               );
+               $newid = $dbw->insertId();
+               $wgLinkCache->clearLink( $this->getPrefixedDBkey() );
                
                RecentChange::notifyMoveOverRedirect( $now, $this, $nt, $wgUser, $comment );
 
@@ -1530,6 +1521,7 @@ class Title {
         */
        /* private */ function moveToNewTitle( &$nt, &$newid ) {
                global $wgUser, $wgLinkCache, $wgUseSquid;
+               global $wgMwRedir;
                $fname = 'MovePageForm::moveToNewTitle';
                $comment = wfMsg( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
 
@@ -1542,50 +1534,48 @@ class Title {
                $rand = wfRandom();
 
                # Rename cur entry
-               $dbw->update( 'cur',
+               $dbw->update( 'page',
                        /* SET */ array(
-                               'cur_touched' => $now,
-                               'cur_namespace' => $nt->getNamespace(),
-                               'cur_title' => $nt->getDBkey()
+                               'page_touched' => $now,
+                               'page_namespace' => $nt->getNamespace(),
+                               'page_title' => $nt->getDBkey()
                        ),
-                       /* WHERE */ array( 'cur_id' => $oldid ),
+                       /* WHERE */ array( 'page_id' => $oldid ),
                        $fname
                );
                
                $wgLinkCache->clearLink( $nt->getPrefixedDBkey() );
 
                # Insert redirect
-               $dbw->insert( 'cur', array(
-                       'cur_id' => $dbw->nextSequenceValue('cur_cur_id_seq'),
-                       'cur_namespace' => $this->getNamespace(),
-                       'cur_title' => $this->getDBkey(),
-                       'cur_comment' => $comment,
-                       'cur_user' => $wgUser->getID(),
-                       'cur_user_text' => $wgUser->getName(),
-                       'cur_timestamp' => $now,
-                       'inverse_timestamp' => $won,
-                       'cur_touched' => $now,
-                       'cur_is_redirect' => 1,
-                       'cur_random' => $rand,
-                       'cur_is_new' => 1,
-                       'cur_text' => "#REDIRECT [[" . $nt->getPrefixedText() . "]]\n" ), $fname
+               $redirectText = $wgMwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
+               $dbw->insert( 'revision', array(
+                       'rev_id' => $dbw->nextSequenceValue('rev_rev_id_seq'),
+                       'rev_comment' => $comment,
+                       'rev_user' => $wgUser->getID(),
+                       'rev_user_text' => $wgUser->getName(),
+                       'rev_timestamp' => $now,
+                       'inverse_timestamp' => $won ), $fname
+               );
+               $revid = $dbw->insertId();
+               $dbw->insert( 'text', array(
+                       'old_id' => $revid,
+                       'old_flags' => '',
+                       'old_text' => $redirectText
+                       ), $fname
+               );
+               $dbw->insert( 'page', array(
+                       'page_id' => $dbw->nextSequenceValue('page_page_id_seq'),
+                       'page_namespace' => $this->getNamespace(),
+                       'page_title' => $this->getDBkey(),
+                       'page_touched' => $now,
+                       'page_is_redirect' => 1,
+                       'page_random' => $rand,
+                       'page_is_new' => 1,
+                       'page_latest' => $revid), $fname
                );
                $newid = $dbw->insertId();
                $wgLinkCache->clearLink( $this->getPrefixedDBkey() );
 
-               # Rename old entries
-               $dbw->update( 
-                       /* 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 );
 
@@ -1625,21 +1615,24 @@ class Title {
         * @access public
         */
        function isValidMoveTarget( $nt ) {
+               
                $fname = 'Title::isValidMoveTarget';
                $dbw =& wfGetDB( DB_MASTER );
 
                # Is it a redirect?
                $id  = $nt->getArticleID();
-               $obj = $dbw->selectRow( 'cur', array( 'cur_is_redirect','cur_text' ), 
-                       array( 'cur_id' => $id ), $fname, 'FOR UPDATE' );
+               $obj = $dbw->selectRow( array( 'page', 'text') ,
+                       array( 'page_is_redirect','old_text' ), 
+                       array( 'page_id' => $id, 'page_latest=old_id' ),
+                       $fname, 'FOR UPDATE' );
 
-               if ( !$obj || 0 == $obj->cur_is_redirect ) { 
+               if ( !$obj || 0 == $obj->page_is_redirect ) { 
                        # Not a redirect
                        return false; 
                }
 
                # Does the redirect point to the source?
-               if ( preg_match( "/\\[\\[\\s*([^\\]\\|]*)]]/", $obj->cur_text, $m ) ) {
+               if ( preg_match( "/\\[\\[\\s*([^\\]\\|]*)]]/", $obj->old_text, $m ) ) {
                        $redirTitle = Title::newFromText( $m[1] );
                        if( !is_object( $redirTitle ) ||
                                $redirTitle->getPrefixedDBkey() != $this->getPrefixedDBkey() ) {
@@ -1648,10 +1641,11 @@ class Title {
                }
 
                # Does the article have a history?
-               $row = $dbw->selectRow( 'old', array( 'old_id' ), 
-                       array( 
-                               'old_namespace' => $nt->getNamespace(),
-                               'old_title' => $nt->getDBkey() 
+               $row = $dbw->selectRow( array( 'page', 'revision'),
+                       array( 'rev_id' ), 
+                       array( 'page_namespace' => $nt->getNamespace(),
+                               'page_title' => $nt->getDBkey(),
+                               'page_id=rev_page AND page_latest != rev_id'
                        ), $fname, 'FOR UPDATE' 
                );
 
@@ -1678,23 +1672,41 @@ class Title {
                $dbw =& wfGetDB( DB_MASTER );
                $now = wfTimestampNow();
                $won = wfInvertTimestamp( $now );
-               $seqVal = $dbw->nextSequenceValue( 'cur_cur_id_seq' );
-
-               $dbw->insert( 'cur', array(
-                       'cur_id' => $seqVal,
-                       'cur_namespace' => $this->getNamespace(),
-                       'cur_title' => $this->getDBkey(),
-                       'cur_comment' => $comment,
-                       'cur_user' => $wgUser->getID(),
-                       'cur_user_text' => $wgUser->getName(),
-                       'cur_timestamp' => $now,
-                       'inverse_timestamp' => $won,
-                       'cur_touched' => $now,
-                       'cur_is_redirect' => 1,
-                       'cur_is_new' => 1,
-                       'cur_text' => "#REDIRECT [[" . $dest->getPrefixedText() . "]]\n" 
+               
+               $seqVal = $dbw->nextSequenceValue( 'page_page_id_seq' );
+               $dbw->insert( 'page', array(
+                       'page_id' => $seqVal,
+                       'page_namespace' => $this->getNamespace(),
+                       'page_title' => $this->getDBkey(),
+                       'page_touched' => $now,
+                       'page_is_redirect' => 1,
+                       'page_is_new' => 1,
+                       'page_latest' => NULL,
                ), $fname );
                $newid = $dbw->insertId();
+
+               $seqVal = $dbw->nextSequenceValue( 'text_old_id_seq' );
+               $dbw->insert( 'text', array(
+                       'old_id' => $seqVal,
+                       'old_flags' => '',
+                       'old_text' => "#REDIRECT [[" . $dest->getPrefixedText() . "]]\n"
+               ), $fname );
+               $revisionId = $dbw->insertId();
+               
+               $dbw->insert( 'revision', array(
+                       'rev_id' => $seqVal,
+                       'rev_page' => $newid,
+                       'rev_comment' => $comment,
+                       'rev_user' => $wgUser->getID(),
+                       'rev_user_text' => $wgUser->getName(),
+                       'rev_timestamp' => $now,
+                       'inverse_timestamp' => $won,
+               ), $fname );
+               
+               $dbw->update( 'page',
+                       /* SET */   array( 'page_latest' => $revisionId ),
+                       /* WHERE */ array( 'page_id' => $newid ),
+                       $fname );
                $this->resetArticleID( $newid );
                
                # Link table
@@ -1789,6 +1801,7 @@ class Title {
         * @access public
         */
        function curCond() {
+               wfDebugDieBacktrace( 'curCond called' );
                return array( 'cur_namespace' => $this->mNamespace, 'cur_title' => $this->mDbkeyform );
        }
 
@@ -1800,6 +1813,7 @@ class Title {
         * @access public
         */
        function oldCond() {
+               wfDebugDieBacktrace( 'oldCond called' );
                return array( 'old_namespace' => $this->mNamespace, 'old_title' => $this->mDbkeyform );
        }
 
@@ -1811,10 +1825,9 @@ class Title {
         */
        function getPreviousRevisionID( $revision ) {
                $dbr =& wfGetDB( DB_SLAVE );
-               return $dbr->selectField( 'old', 'old_id',
-                       'old_title=' . $dbr->addQuotes( $this->getDBkey() ) .
-                       ' AND old_namespace=' . IntVal( $this->getNamespace() ) .
-                       ' AND old_id<' . IntVal( $revision ) . ' ORDER BY old_id DESC' );
+               return $dbr->selectField( 'revision', 'rev_id',
+                       'rev_page=' . IntVal( $this->getArticleId() ) .
+                       ' AND rev_id<' . IntVal( $revision ) . ' ORDER BY rev_id DESC' );
        }
 
        /**
@@ -1825,10 +1838,9 @@ class Title {
         */
        function getNextRevisionID( $revision ) {
                $dbr =& wfGetDB( DB_SLAVE );
-               return $dbr->selectField( 'old', 'old_id',
-                       'old_title=' . $dbr->addQuotes( $this->getDBkey() ) .
-                       ' AND old_namespace=' . IntVal( $this->getNamespace() ) .
-                       ' AND old_id>' . IntVal( $revision ) . ' ORDER BY old_id' );
+               return $dbr->selectField( 'revision', 'rev_id',
+                       'rev_page=' . IntVal( $this->getArticleId() ) .
+                       ' AND rev_id>' . IntVal( $revision ) . ' ORDER BY rev_id' );
        }
 
 }
index 5f0260d..becea05 100644 (file)
@@ -1025,7 +1025,7 @@ class User {
        }
 
        function spreadBlock() {
-               global $wgIP;
+               global $wgIP;
                # If the (non-anonymous) user is blocked, this function will block any IP address
                # that they successfully log on from.
                $fname = 'User::spreadBlock';
index 681940e..8e8eaba 100644 (file)
@@ -104,6 +104,9 @@ class LanguageUtf8 extends Language {
        function checkTitleEncoding( $s ) {
                global $wgInputEncoding;
 
+               if( is_array( $s ) ) {
+                       wfDebugDieBacktrace( 'Given array to checkTitleEncoding.' );
+               }
                # Check for non-UTF-8 URLs
                $ishigh = preg_match( '/[\x80-\xff]/', $s);
                if(!$ishigh) return $s;
index b057f96..02eb932 100755 (executable)
@@ -109,12 +109,15 @@ function initialiseMessagesReal( $overwrite = false, $messageArray = false ) {
        
        $dbr =& wfGetDB( DB_SLAVE );
        $dbw =& wfGetDB( DB_MASTER );
-       $cur = $dbr->tableName( 'cur' );
+       $page = $dbr->tableName( 'page' );
+       $revision = $dbr->tableName( 'revision' );
 
        $timestamp = wfTimestampNow();
        $invTimestamp = wfInvertTimestamp( $timestamp );
 
-       $sql = "SELECT cur_title,cur_is_new,cur_user_text FROM $cur WHERE cur_namespace=$ns AND cur_title IN(";
+       #$sql = "SELECT cur_title,cur_is_new,cur_user_text FROM $cur WHERE cur_namespace=$ns AND cur_title IN(";
+       $sql = "SELECT page_title,page_is_new,rev_user_text FROM $page, $revision WHERE
+               page_namespace=$ns AND rev_page=page_id AND page_title IN(";
 
        # Get keys from $wgAllMessagesEn, which is more complete than the local language
        $first = true;
@@ -149,10 +152,10 @@ function initialiseMessagesReal( $overwrite = false, $messageArray = false ) {
        # Decide whether or not each one needs to be overwritten
        $existingTitles = array();
        while ( $row ) {
-               if ( $row->cur_user_text != $username ) {
-                       $existingTitles[$row->cur_title] = 'keep';
+               if ( $row->rev_user_text != $username ) {
+                       $existingTitles[$row->page_title] = 'keep';
                } else {
-                       $existingTitles[$row->cur_title] = 'chuck';
+                       $existingTitles[$row->page_title] = 'chuck';
                }
 
                $row = $dbr->fetchObject( $res );
@@ -186,24 +189,28 @@ function initialiseMessagesReal( $overwrite = false, $messageArray = false ) {
                                $article = new Article( $mwTitleObj );
                                $article->quickEdit( $message );
                        }
-                       $doInsert = false;
                } else {
-                       array_push( $arr, array(
-                               'cur_namespace' => $ns,
-                               'cur_title' => $title,
-                               'cur_text' => $message,
-                               'cur_user' => 0,
-                               'cur_user_text' => $username,
-                               'cur_timestamp' => $dbw->timestamp( $timestamp ),
-                               'cur_restrictions' => 'sysop',
-                               'cur_is_new' => 1,
-                               'inverse_timestamp' => $invTimestamp,
-                               'cur_touched' => $dbw->timestamp( $timestamp ) ) );
+                       extract( $dbw->tableNames( 'text', 'page', 'revision' ) );
+                       $sql = "INSERT INTO $text (old_text, old_flags) VALUES ('" .
+                               wfStrencode( $message ) .
+                               "', '')";
+                       $dbw->query( $sql, $fname );
+                       $text_id = $dbw->insertID();
+
+                       $sql = "INSERT INTO $page (page_namespace, page_title, page_restrictions, page_counter, page_is_redirect,
+                               page_is_new, page_random, page_touched, page_latest) VALUES (
+                               {$ns}, '{$title}', 'sysop', 0, 0, 1, 0.5, '{$timestamp}', {$text_id} )";
+                       $dbw->query( $sql, $fname );
+                       $page_id = $dbw->insertID();
+
+                       $sql = "INSERT INTO $revision (rev_id, rev_page, rev_comment, rev_user, rev_user_text,
+                                                       rev_timestamp, inverse_timestamp, rev_minor_edit)
+                                       VALUES ({$text_id}, {$page_id}, '', 0, '{$username}', '{$timestamp}', '{$invTimestamp}', 0)";
+                       $dbw->query( $sql, $fname );
+
                }
        }
 
-       $dbw->insert( 'cur', $arr, $fname );
-
        # Clear the relevant memcached key
        print 'Clearing message cache...';
        $wgMessageCache->clear();
diff --git a/maintenance/archives/patch-restructure.sql b/maintenance/archives/patch-restructure.sql
new file mode 100644 (file)
index 0000000..392b122
--- /dev/null
@@ -0,0 +1,148 @@
+-- The Great Restructuring of October 2004
+-- Creates 'page', 'revision' tables and transforms the classic
+-- cur+old into a separate page+revision+text structure.
+--
+-- The pre-conversion 'old' table is renamed to 'text' and used
+-- without internal restructuring to avoid rebuilding the entire
+-- table. (This can be done separately if desired.)
+--
+-- The pre-conversion 'cur' table is now redundant and can be
+-- discarded when done.
+
+CREATE TABLE /*$wgDBprefix*/page (
+  page_id int(8) unsigned NOT NULL auto_increment,
+  page_namespace tinyint NOT NULL,
+  page_title varchar(255) binary NOT NULL,
+  page_restrictions tinyblob NOT NULL default '',
+  page_counter bigint(20) unsigned NOT NULL default '0',
+  page_is_redirect tinyint(1) unsigned NOT NULL default '0',
+  page_is_new tinyint(1) unsigned NOT NULL default '0',
+  page_random real unsigned NOT NULL,
+  page_touched char(14) binary NOT NULL default '',
+  page_latest int(8) unsigned NOT NULL,
+
+  PRIMARY KEY page_id (page_id),
+  UNIQUE INDEX name_title (page_namespace,page_title),
+  INDEX (page_random)
+);
+
+CREATE TABLE /*$wgDBprefix*/revision (
+  rev_id int(8) unsigned NOT NULL auto_increment,
+  rev_page int(8) unsigned NOT NULL,
+  rev_comment tinyblob NOT NULL default '',
+  rev_user int(5) unsigned NOT NULL default '0',
+  rev_user_text varchar(255) binary NOT NULL default '',
+  rev_timestamp char(14) binary NOT NULL default '',
+  rev_minor_edit tinyint(1) unsigned NOT NULL default '0',
+  inverse_timestamp char(14) binary NOT NULL default '',
+  
+  PRIMARY KEY rev_page_id (rev_page, rev_id),
+  UNIQUE INDEX rev_id (rev_id),
+  INDEX rev_timestamp (rev_timestamp),
+  INDEX page_timestamp (rev_page,inverse_timestamp),
+  INDEX user_timestamp (rev_user,inverse_timestamp),
+  INDEX usertext_timestamp (rev_user_text,inverse_timestamp)
+);
+
+-- If creating new 'text' table it would look like this:
+--
+-- CREATE TABLE /*$wgDBprefix*/text (
+--   old_id int(8) unsigned NOT NULL auto_increment,
+--   old_text mediumtext NOT NULL default '',
+--   old_flags tinyblob NOT NULL default '',
+--   
+--   PRIMARY KEY old_id (old_id)
+-- );
+
+
+-- Lock!
+LOCK TABLES /*$wgDBprefix*/page WRITE, /*$wgDBprefix*/revision WRITE, /*$wgDBprefix*/old WRITE, /*$wgDBprefix*/cur WRITE;
+
+-- Save the last old_id value for later
+SELECT (@maxold:=MAX(old_id)) FROM /*$wgDBprefix*/old;
+
+-- First, copy all current entries into the old table.
+INSERT
+  INTO /*$wgDBprefix*/old
+    (old_namespace,
+    old_title,
+    old_text,
+    old_comment,
+    old_user,
+    old_user_text,
+    old_timestamp,
+    old_minor_edit,
+    old_flags,
+    inverse_timestamp)
+  SELECT
+    cur_namespace,
+    cur_title,
+    cur_text,
+    cur_comment,
+    cur_user,
+    cur_user_text,
+    cur_timestamp,
+    cur_minor_edit,
+    '',
+    inverse_timestamp
+  FROM /*$wgDBprefix*/cur;
+
+-- Now, copy all old data except the text into revisions
+INSERT
+  INTO /*$wgDBprefix*/revision
+    (rev_id,
+    rev_page,
+    rev_comment,
+    rev_user,
+    rev_user_text,
+    rev_timestamp,
+    inverse_timestamp,
+    rev_minor_edit)
+  SELECT
+    old_id,
+    cur_id,
+    old_comment,
+    old_user,
+    old_user_text,
+    old_timestamp,
+    old.inverse_timestamp,
+    old_minor_edit
+  FROM /*$wgDBprefix*/old,/*$wgDBprefix*/cur
+  WHERE old_namespace=cur_namespace
+    AND old_title=cur_title;
+
+-- And, copy the cur data into page
+INSERT
+  INTO /*$wgDBprefix*/page
+    (page_id,
+    page_namespace,
+    page_title,
+    page_restrictions,
+    page_counter,
+    page_is_redirect,
+    page_is_new,
+    page_random,
+    page_touched,
+    page_latest)
+  SELECT
+    cur_id,
+    cur_namespace,
+    cur_title,
+    cur_restrictions,
+    cur_counter,
+    cur_is_redirect,
+    cur_is_new,
+    cur_random,
+    cur_touched,
+    rev_id
+  FROM /*$wgDBprefix*/cur,/*$wgDBprefix*/revision
+  WHERE cur_id=rev_page
+    AND rev_timestamp=cur_timestamp
+    AND rev_id > @maxold;
+
+UNLOCK TABLES;
+
+-- Keep the old table around as the text store.
+-- Its extra fields will be ignored, but trimming them is slow
+-- so we won't bother doing it for now.
+ALTER TABLE /*$wgDBprefix*/old RENAME TO /*$wgDBprefix*/text;
index d5159ba..30dec07 100644 (file)
@@ -62,24 +62,27 @@ function compressWithConcat( $startId, $maxChunkSize, $maxChunkFactor, $factorTh
        $dbw =& wfGetDB( DB_MASTER );
 
        # First get a list of all pages
-       $pageRes = $dbw->select( 'cur', array('cur_namespace', 'cur_title'), false, $fname );
+       $pageRes = $dbw->select( 'page', 'page_id', false, $fname );
 
        # For each of those, get a list of revisions which fit the criteria
        $conds = array();
        if ( $beginDate ) {
-               $conds[] = "old_timestamp>'" . $beginDate . "'";
+               $conds[] = "rev_timestamp>'" . $beginDate . "'";
        } 
        if ( $endDate )  {
-               $conds[] = "old_timestamp<'" . $endDate . "'";
+               $conds[] = "rev_timestamp<'" . $endDate . "'";
        }
        if ( $startId ) {
-               $conds[] = 'old_id>=' . $startId;
+               $conds[] = 'rev_id>=' . $startId;
        }
        if ( $loadStyle == LS_CHUNKED ) {
-               $fields = array( 'old_id', 'old_flags', 'old_text' );
+               $tables = array( 'revision', 'text' );
+               $fields = array( 'rev_id', 'old_flags', 'old_text' );
+               $conds[] = 'rev_id=old_id';
                $revLoadOptions = 'FOR UPDATE';
        } else {
-               $fields = array( 'old_id' );
+               $tables = array( 'revision' );
+               $fields = array( 'rev_id' );
                $revLoadOptions = array();
        }
 
@@ -90,7 +93,7 @@ function compressWithConcat( $startId, $maxChunkSize, $maxChunkFactor, $factorTh
 
                # Load revisions
                $revRes = $dbw->select( 'old', $fields,
-                       array( 'old_namespace' => $pageRow->cur_namespace, 'old_title' => $pageRow->cur_title ) + $conds, 
+                       array( 'rev_page' => $pageRow->page_id ) + $conds, 
                        $fname,
                        $revLoadOptions
                );
@@ -118,15 +121,15 @@ function compressWithConcat( $startId, $maxChunkSize, $maxChunkFactor, $factorTh
                        $stubs = array();
                        $dbw->begin();
                        $usedChunk = false;
-                       $primaryOldid = $revs[$i]->old_id;
+                       $primaryOldid = $revs[$i]->rev_id;
                        
                        # Get the text of each revision and add it to the object
                        for ( $j = 0; $j < $thisChunkSize && $chunk->isHappy( $maxChunkFactor, $factorThreshold ); $j++ ) {
-                               $oldid = $revs[$i + $j]->old_id;
+                               $oldid = $revs[$i + $j]->rev_id;
                                
                                # Get text
                                if ( $loadStyle == LS_INDIVIDUAL ) {
-                                       $textRow = $dbw->selectRow( 'old', 
+                                       $textRow = $dbw->selectRow( 'text', 
                                                array( 'old_flags', 'old_text' ),
                                                array( 'old_id' => $oldid ),
                                                $fname,
@@ -167,7 +170,7 @@ function compressWithConcat( $startId, $maxChunkSize, $maxChunkFactor, $factorTh
                        # If we couldn't actually use any stubs because the pages were too small, do nothing
                        if ( $usedChunk ) {
                                # Store the main object
-                               $dbw->update( 'old',
+                               $dbw->update( 'text',
                                        array( /* SET */
                                                'old_text' => serialize( $chunk ),
                                                'old_flags' => 'object',
@@ -180,7 +183,7 @@ function compressWithConcat( $startId, $maxChunkSize, $maxChunkFactor, $factorTh
                                for ( $j = 1; $j < $thisChunkSize; $j++ ) {
                                        # Skip if not compressing
                                        if ( $stubs[$j] !== false ) {
-                                               $dbw->update( 'old',
+                                               $dbw->update( 'text',
                                                        array( /* SET */
                                                                'old_text' => $stubs[$j],
                                                                'old_flags' => 'object',
@@ -200,4 +203,5 @@ function compressWithConcat( $startId, $maxChunkSize, $maxChunkFactor, $factorTh
        }
        return true;
 }
+
 ?>
index def49e9..4af3e86 100644 (file)
@@ -18,186 +18,142 @@ UTF-8 conversion of DOOOOOOOM
 */
 
 
-if(function_exists("iconv")) {
-       # There are likely to be Windows code page 1252 chars in there.
-       # Convert them to the proper UTF-8 chars if possible.
-       function toUtf8($string) {
-               return wfStrencode(iconv("CP1252", "UTF-8", $string));
+class UtfUpdater {
+       function UtfUpdater() {
+               $this->db =& wfGetDB( DB_MASTER );
        }
-} else {
-       # Will work from plain iso 8859-1 and may corrupt these chars
-       function toUtf8($string) {
-               return wfStrencode(utf8_encode($string));
-       }
-}
-
-
-
-# user table
-$sql = "SELECT user_id,user_name,user_real_name,user_options FROM user";
-$res = wfQuery( $sql, DB_WRITE );
-print "Converting " . wfNumResults( $res ) . " user accounts:\n";
-$n = 0;
-while( $s = wfFetchObject( $res ) ) {
-       $uname = toUtf8( $s->user_name );
-       $ureal = toUtf8( $s->user_real_name );
-       $uoptions = toUtf8( $s->user_options );
-       if( $uname != wfStrencode( $s->user_name ) ||
-               $ureal != wfStrencode( $s->user_real_name ) ||
-               $uoptions != wfStrencode( $s->user_options ) ) {
-               $now = wfTimestampNow();
-               $sql = "UPDATE user
-                       SET user_name='$uname',user_real_name='$ureal',
-                               user_options='$uoptions',user_touched='$now'
-                       WHERE user_id={$s->user_id}";
-               wfQuery( $sql, DB_WRITE );
-               $wgMemc->delete( "$wgDBname:user:id:{$s->user_id}" );
-               $u++;
+       
+       function toUtf8( $string ) {
+               if( function_exists( 'iconv' ) ) {
+                       # There are likely to be Windows code page 1252 chars in there.
+                       # Convert them to the proper UTF-8 chars if possible.
+                       return iconv( 'CP1252', 'UTF-8', $string );
+               } else {
+                       # Will work from plain iso 8859-1 and may corrupt these chars
+                       return utf8_encode( $string );
+               }
        }
-       if( ++$n % 100 == 0 ) print "$n\n";
-}
-wfFreeResult( $res );
-if( $n ) {
-       printf("%2.02%% required conversion.\n\n", $u / $n);
-} else {
-       print "None?\n\n";
-}
 
-# ipblocks
-$sql = "SELECT DISTINCT ipb_reason FROM ipblocks";
-$res = wfQuery( $sql, DB_WRITE );
-print "Converting " . wfNumResults( $res ) . " IP block comments:\n";
-$n = 0;
-while( $s = wfFetchObject( $res ) ) {
-       $ucomment = toUtf8($s->ipb_reason);
-       $ocomment = wfStrencode( $s->ipb_reason );
-       if( $u != $o ) {
-               $sql = "UPDATE ipblocks SET ipb_reason='$ucomment' WHERE ipb_reason='$ocomment'";
-               wfQuery( $sql, DB_WRITE );
-               $u++;
+       function clearTable( $table ) {
+               print "Clearing $table...\n";
+               $tableName = $this->db->tableName( $table );
+               $this->db->query( 'TRUNCATE $tableName' );
        }
-       if( ++$n % 100 == 0 ) print "$n\n";
-}
-wfFreeResult( $res );
-if( $n ) {
-       printf("%2.02%% required conversion.\n\n", $u / $n);
-} else {
-       print "None?\n\n";
-}
-
-# image
-$sql = "SELECT img_name,img_description,img_user_text FROM image";
-       img_name --> also need to rename files
-       img_description
-       img_user_text
-
-oldimage
-       oi_name
-       oi_archive_name --> also need to rename files
-       oi_user_text
-
-recentchanges
-       rc_user_text
-       rc_title
-       rc_comment
-
-# searchindex
-print "Clearing searchindex... don't forget to rebuild it.\n";
-$sql = "DELETE FROM searchindex";
-wfQuery( $sql, DB_WRITE );
-
-# linkscc
-print "Clearing linkscc...\n";
-$sql = "DELETE FROM linkscc";
-wfQuery( $sql, DB_WRITE );
-
-# querycache: just rebuild these
-print "Clearing querycache...\n";
-$sql = "DELETE FROM querycache";
-wfQuery( $sql, DB_WRITE );
-
-# objectcache
-print "Clearing objectcache...\n";
-$sql = "DELETE FROM objectcache";
-wfQuery( $sql, DB_WRITE );
-
-
-function unicodeLinks( $table, $field ) {
-       $sql = "SELECT DISTINCT $field FROM $table WHERE $field RLIKE '[\x80-\xff]'";
-       $res = wfQuery( $sql, DB_WRITE );
-       print "Converting " . wfNumResults( $res ) . " from $table:\n";
-       $n = 0;
-       while( $s = wfFetchObject( $res ) ) {
-               $ulink = toUtf8( $s->$field );
-               $olink = wfStrencode( $s->$field );
-               $sql = "UPDATE $table SET $field='$ulink' WHERE $field='$olink'";
-               wfQuery( $sql, DB_WRITE );
-               if( ++$n % 100 == 0 ) print "$n\n";
+       
+       /**
+        * @param string $table Table to be converted
+        * @param string $key Primary key, to identify fields in the UPDATE. If NULL, all fields will be used to match.
+        * @param array $fields List of all fields to grab and convert. If null, will assume you want the $key, and will ask for DISTINCT.
+        * @param array $timestamp A field which should be updated to the current timestamp on changed records.
+        * @access private
+        */
+       function convertTable( $table, $key, $fields = null, $timestamp = null ) {
+               $fname = 'UtfUpdater::convertTable';
+               if( $fields ) {
+                       $distinct = '';
+               } else {
+                       # If working on one key only, there will be multiple rows.
+                       # Use DISTINCT to return only one and save us some trouble.
+                       $fields = array( $key );
+                       $distinct = 'DISTINCT';
+               }
+               $condition = '';
+               foreach( $fields as $field ) {
+                       if( $condition ) $condition .= ' OR ';
+                       $condition .= "$field RLIKE '[\x80-\xff]'";
+               }
+               $res = $this->db->selectArray(
+                       $table,
+                       array_merge( $fields, array( $key ) ),
+                       $condition,
+                       $fname,
+                       $distinct );
+               print "Converting " . $this->db->numResults( $res ) . " rows from $table:\n";
+               $n = 0;
+               while( $s = $this->db->fetchObject( $res ) ) {
+                       $set = array();
+                       foreach( $fields as $field ) {
+                               $set[] = $this->toUtf8( $s->$field );
+                       }
+                       if( $timestamp ) {
+                               $set[$timestamp] = $this->db->timestamp();
+                       }
+                       if( $key ) {
+                               $keyCond = array( $key, $s->$key );
+                       } else {
+                               $keyCond = array();
+                               foreach( $fields as $field ) {
+                                       $keyCond[$field] = $s->$field;
+                               }
+                       }
+                       $this->db->updateArray(
+                               $table,
+                               $set,
+                               $keyCond,
+                               $fname );
+                       if( ++$n % 100 == 0 ) echo "$n\n";
+               }
+               echo "$n done.\n";
+               $this->db->freeResult( $res );
        }
-       wfFreeResult( $res );
-       print "Done.\n\n";
-}
-unicodeLinks( "brokenlinks", "bl_to" );
-unicodeLinks( "imagelinks", "il_to" );
-unicodeLinks( "categorylinks", "cl_to" );
-
-
-# The big guys...
-$sql = "SELECT cur_id,cur_namespace,cur_title,cur_text,cur_user_text FROM cur
-WHERE cur_title rlike '[\x80-\xff]' OR cur_comment rlike '[\x80-\xff]'
-OR cur_user_text rlike '[\x80-\xff]' OR cur_text rlike '[\x80-\xff]'";
-$res = wfQuery( $sql, DB_WRITE );
-print "Converting " . wfNumResults( $res ) . " cur pages:\n";
-$n = 0;
-while( $s = wfFetchObject( $res ) ) {
-       $utitle = toUtf8( $s->cur_title );
-       $uuser = toUtf8( $s->cur_user_text );
-       $ucomment = toUtf8( $s->cur_comment );
-       $utext = toUtf8( $s->cur_text );
-       $now = wfTimestampNow();
        
-       $sql = "UPDATE cur
-               SET cur_title='$utitle',cur_user_text='$uuser',
-                       cur_comment='$ucomment',cur_text='$utext'
-               WHERE cur_id={$s->cur_id}";
-       wfQuery( $sql, DB_WRITE );
-       #$wgMemc->delete( "$wgDBname:user:id:{$s->user_id}" );
+       function lockTables( $tables ) {
+               $query = '';
+               foreach( $tables as $table ) {
+                       $tableName = $this->db->tableName( $table );
+                       if( $query ) $query .= ', ';
+                       $query .= '$tableName WRITE';
+               }
+               $this->db->query( 'LOCK TABLES ' . $query );
+       }
        
-       $otitle = wfStrencode( $s->cur_title );
-       if( $otitle != $utitle ) {
-               # Also update titles in watchlist and old
-               $sql = "UPDATE old SET old_title='$utitle'
-                       WHERE old_namespace={$s->cur_namespace} AND old_title='$otitle'";
-               wfQuery( $sql, DB_WRITE );
+       function updateAll() {
+               $this->lockTables( array(
+                       'linkscc', 'objectcache', 'searchindex', 'querycache',
+                       'ipblocks', 'user', 'page', 'revision', 'recentchanges',
+                       'brokenlinks', 'categorylinks', 'imagelinks', 'watchlist',
+                       'image', 'oldimage', 'archive' ) );
+               
+               # These are safe to clear out:
+               $this->clearTable( 'linkscc' );
+               $this->clearTable( 'objectcache' );
+
+               # These need to be rebuild if used:
+               $this->clearTable( 'searchindex' );
+               $this->clearTable( 'querycache' );
+
+               # And convert the rest...
+               $this->convertTable( 'ipblocks', 'ipb_id', array( 'ipb_reason' ) );
+               $this->convertTable( 'user', 'user_id', 
+                       array( 'user_name', 'user_real_name', 'user_options' ),
+                       'user_touched' );
+               $this->convertTable( 'page', 'page_id',
+                       array( 'page_title' ), 'page_touched' );
+               $this->convertTable( 'revision', 'rev_id',
+                       array( 'rev_user_text', 'rev_comment' ) );
+               
+               $this->convertTable( 'recentchanges', 'rc_id',
+                       array( 'rc_user_text', 'rc_title', 'rc_comment' ) );
                
-               $ns = IntVal( $s->cur_namespace) & ~1;
-               $sql = "UPDATE watchlist SET wl_title='$utitle'
-                       WHERE wl_namespace=$ns AND wl_title='$otitle'";
-               wfQuery( $sql, DB_WRITE );
-               $u++;
+               $this->convertTable( 'brokenlinks', 'bl_to' );
+               $this->convertTable( 'categorylinks', 'cl_to' );
+               $this->convertTable( 'imagelinks', 'il_to' );
+               $this->convertTable( 'watchlist', 'wl_title' );
+               
+               # FIXME: We'll also need to change the files.
+               $this->convertTable( 'image', 'img_name',
+                       array( 'img_name', 'img_description', 'img_user_text' ) );
+               $this->convertTable( 'oldimage', 'archive_name',
+                       array( 'oi_name', 'oi_archive_name', 'oi_description', 'oi_user_text' ) );
+               
+               # Don't change the ar_text entries; use $wgLegacyEncoding to read them at runtime
+               $this->convertTable( 'archive', null,
+                       array( 'ar_title', 'ar_comment', 'ar_user_text' ) );
+               echo "Not converting text table: be sure to set \$wgLegacyEncoding!\n";
+               
+               $this->db->query( 'UNLOCK TABLES' );
        }
        
-       if( ++$n % 100 == 0 ) print "$n\n";
-}
-wfFreeResult( $res );
-if( $n ) {
-       printf("Updated old/watchlist titles on %2.02%%.\n\n", $u / $n);
-} else {
-       print "Didn't update any old/watchlist titles.\n\n";
 }
 
-/*
-old
-       old_title
-       old_text -> may be gzipped
-       old_comment
-       old_user_text
-
-archive
-       ar_title
-       ar_text -> may be gzipped
-       ar_comment
-       ar_user_text
-*/
-
 ?>
index 284b941..6140539 100644 (file)
@@ -311,7 +311,7 @@ class ParserTest {
        # List of temporary tables to create, without prefix
        # Some of these probably aren't necessary
        function listTables() {
-               return array('user', 'cur', 'old', 'links',
+               return array('user', 'page', 'revision', 'text', 'links',
                        'brokenlinks', 'imagelinks', 'categorylinks',
                        'linkscc', 'site_stats', 'hitcounter',
                        'ipblocks', 'image', 'oldimage',
index d7a56f0..9ddddb7 100644 (file)
@@ -35,55 +35,51 @@ CREATE TABLE /*$wgDBprefix*/user_rights (
 --  INDEX user_ip (user_ip)
 -- );
 
-CREATE TABLE /*$wgDBprefix*/cur (
-  cur_id int(8) unsigned NOT NULL auto_increment,
-  cur_namespace tinyint(2) unsigned NOT NULL default '0',
-  cur_title varchar(255) binary NOT NULL default '',
-  cur_text mediumtext NOT NULL default '',
-  cur_comment tinyblob NOT NULL default '',
-  cur_user int(5) unsigned NOT NULL default '0',
-  cur_user_text varchar(255) binary NOT NULL default '',
-  cur_timestamp char(14) binary NOT NULL default '',
-  cur_restrictions tinyblob NOT NULL default '',
-  cur_counter bigint(20) unsigned NOT NULL default '0',
-  cur_is_redirect tinyint(1) unsigned NOT NULL default '0',
-  cur_minor_edit tinyint(1) unsigned NOT NULL default '0',
-  cur_is_new tinyint(1) unsigned NOT NULL default '0',
-  cur_random real unsigned NOT NULL,
-  cur_touched char(14) binary NOT NULL default '',
+CREATE TABLE /*$wgDBprefix*/page (
+  page_id int(8) unsigned NOT NULL auto_increment,
+  page_namespace tinyint NOT NULL,
+  page_title varchar(255) binary NOT NULL,
+  page_restrictions tinyblob NOT NULL default '',
+  page_counter bigint(20) unsigned NOT NULL default '0',
+  page_is_redirect tinyint(1) unsigned NOT NULL default '0',
+  page_is_new tinyint(1) unsigned NOT NULL default '0',
+  page_random real unsigned NOT NULL,
+  page_touched char(14) binary NOT NULL default '',
+  page_latest int(8) unsigned NOT NULL,
+
+  PRIMARY KEY page_id (page_id),
+  UNIQUE INDEX name_title (page_namespace,page_title),
+  INDEX (page_random)
+);
+
+CREATE TABLE /*$wgDBprefix*/revision (
+  rev_id int(8) unsigned NOT NULL auto_increment,
+  rev_page int(8) unsigned NOT NULL,
+  rev_comment tinyblob NOT NULL default '',
+  rev_user int(5) unsigned NOT NULL default '0',
+  rev_user_text varchar(255) binary NOT NULL default '',
+  rev_timestamp char(14) binary NOT NULL default '',
+  rev_minor_edit tinyint(1) unsigned NOT NULL default '0',
   inverse_timestamp char(14) binary NOT NULL default '',
-  PRIMARY KEY cur_id (cur_id),
-  UNIQUE INDEX name_title (cur_namespace,cur_title),
   
-  -- Is this one necessary?
-  INDEX cur_title (cur_title(20)),
-  
-  INDEX cur_timestamp (cur_timestamp),
-  INDEX (cur_random),
-  INDEX name_title_timestamp (cur_namespace,cur_title,inverse_timestamp),
-  INDEX user_timestamp (cur_user,inverse_timestamp),
-  INDEX usertext_timestamp (cur_user_text,inverse_timestamp),
-  INDEX namespace_redirect_timestamp(cur_namespace,cur_is_redirect,cur_timestamp)
+  PRIMARY KEY rev_page_id (rev_page, rev_id),
+  UNIQUE INDEX rev_id (rev_id),
+  INDEX rev_timestamp (rev_timestamp),
+  INDEX page_timestamp (rev_page,inverse_timestamp),
+  INDEX user_timestamp (rev_user,inverse_timestamp),
+  INDEX usertext_timestamp (rev_user_text,inverse_timestamp)
 );
 
-CREATE TABLE /*$wgDBprefix*/old (
+
+--
+-- Holds text of individual page revisions.
+--
+CREATE TABLE /*$wgDBprefix*/text (
   old_id int(8) unsigned NOT NULL auto_increment,
-  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',
-  old_user_text varchar(255) binary NOT NULL,
-  old_timestamp char(14) binary NOT NULL default '',
-  old_minor_edit tinyint(1) NOT NULL default '0',
   old_flags tinyblob NOT NULL default '',
-  inverse_timestamp char(14) binary NOT NULL default '',
   
-  PRIMARY KEY old_id (old_id),
-  INDEX old_timestamp (old_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)
+  PRIMARY KEY old_id (old_id)
 );
 
 CREATE TABLE /*$wgDBprefix*/archive (
index 9ce63eb..dfd9d35 100644 (file)
@@ -251,6 +251,141 @@ function do_group_update() {
        }
 }
 
+function do_schema_restructuring() {
+       global $wgDatabase;
+       $fname="do_schema_restructuring";
+       if ( $wgDatabase->tableExists( 'page' ) ) {
+               echo "...page table already exists.\n";
+       } else {
+               echo "...converting from cur/old to page/revision/text DB structure.\n"; flush();
+               echo "......checking for duplicate entries.\n"; flush();
+               $rows = $wgDatabase->query( 'SELECT cur_title, cur_namespace, COUNT(cur_namespace) AS c
+                               FROM cur GROUP BY cur_title, cur_namespace HAVING c>1', $fname );
+
+               if ( $wgDatabase->numRows( $rows ) > 0 ) {
+                       echo "......<b>Found duplicate entries</b>\n";
+                       echo ( sprintf( "<b>      %-60s %3s %5s</b>\n", 'Title', 'NS', 'Count' ) );
+                       while ( $row = $wgDatabase->fetchObject( $rows ) ) {
+                               if ( ! isset( $duplicate[$row->cur_namespace] ) ) {
+                                       $duplicate[$row->cur_namespace] = array();
+                               }
+                               $duplicate[$row->cur_namespace][] = $row->cur_title;
+                               echo ( sprintf( "      %-60s %3s %5s\n", $row->cur_title, $row->cur_namespace, $row->c ) );
+                       }
+                       $sql = 'SELECT cur_title, cur_namespace, cur_id, cur_timestamp FROM cur WHERE ';
+                       $firstCond = true; 
+                       foreach ( $duplicate as $ns => $titles ) {
+                               if ( $firstCond ) {
+                                       $firstCond = false;
+                               } else {
+                                       $sql .= ' AND ';
+                               }
+                               $sql .= "( cur_namespace = {$ns} AND cur_title in (";
+                               $first = true;
+                               foreach ( $titles as $t ) {
+                                       if ( $first ) {
+                                               $sql .= $wgDatabase->addQuotes( $t );
+                                               $first = false;
+                                       } else {
+                                               $sql .= ', ' . $wgDatabase->addQuotes( $t );
+                                       }
+                               }
+                               $sql .= ") ) \n";
+                       }
+                       # By sorting descending, the most recent entry will be the first in the list.
+                       # All following entries will be deleted by the next while-loop.
+                       $sql .= 'ORDER BY cur_namespace, cur_title, cur_timestamp DESC';
+
+                       $rows = $wgDatabase->query( $sql, $fname );
+
+                       $prev_title = $prev_namespace = false;
+                       $deleteId = array();
+
+                       while ( $row = $wgDatabase->fetchObject( $rows ) ) {
+                               if ( $prev_title == $row->cur_title && $prev_namespace == $row->cur_namespace ) {
+                                       $deleteId[] = $row->cur_id;
+                               }
+                               $prev_title     = $row->cur_title;
+                               $prev_namespace = $row->cur_namespace;
+                       }
+                       $sql = 'DELETE FROM cur WHERE cur_id IN ( ' . join( ',', $deleteId ) . ')';
+                       $rows = $wgDatabase->query( $sql, $fname );
+                       echo "......<b>Deleted</b> ".$wgDatabase->affectedRows()." records.\n";
+               }
+               
+
+               echo "......Creating tables.\n";
+               $wgDatabase->query(" CREATE TABLE page (
+                       page_id int(8) unsigned NOT NULL auto_increment,
+                       page_namespace tinyint NOT NULL,
+                       page_title varchar(255) binary NOT NULL,
+                       page_restrictions tinyblob NOT NULL default '',
+                       page_counter bigint(20) unsigned NOT NULL default '0',
+                       page_is_redirect tinyint(1) unsigned NOT NULL default '0',
+                       page_is_new tinyint(1) unsigned NOT NULL default '0',
+                       page_random real unsigned NOT NULL,
+                       page_touched char(14) binary NOT NULL default '',
+                       page_latest int(8) unsigned NOT NULL,
+
+                       PRIMARY KEY page_id (page_id),
+                       UNIQUE INDEX name_title (page_namespace,page_title),
+                       INDEX (page_random)
+                       )", $fname );
+               $wgDatabase->query("CREATE TABLE revision (
+                       rev_id int(8) unsigned NOT NULL auto_increment,
+                       rev_page int(8) unsigned NOT NULL,
+                       rev_comment tinyblob NOT NULL default '',
+                       rev_user int(5) unsigned NOT NULL default '0',
+                       rev_user_text varchar(255) binary NOT NULL default '',
+                       rev_timestamp char(14) binary NOT NULL default '',
+                       rev_minor_edit tinyint(1) unsigned NOT NULL default '0',
+                       inverse_timestamp char(14) binary NOT NULL default '',
+  
+                       PRIMARY KEY rev_page_id (rev_page, rev_id),
+                       UNIQUE INDEX rev_id (rev_id),
+                       INDEX rev_timestamp (rev_timestamp),
+                       INDEX page_timestamp (rev_page,inverse_timestamp),
+                       INDEX user_timestamp (rev_user,inverse_timestamp),
+                       INDEX usertext_timestamp (rev_user_text,inverse_timestamp)
+                       )", $fname );
+
+               echo "......Locking tables.\n";
+               $wgDatabase->query( 'LOCK TABLES page WRITE, revision WRITE, old WRITE, cur WRITE', $fname );
+
+               $maxold = $wgDatabase->selectField( 'old', 'max(old_id)', '', $fname );
+               echo "......maxold is {$maxold}\n";
+
+               echo "......Moving text from cur.\n";
+               $wgDatabase->query( "INSERT INTO old (old_namespace, old_title, old_text, old_comment, old_user, old_user_text,
+                               old_timestamp, old_minor_edit, old_flags, inverse_timestamp)
+                       SELECT cur_namespace, cur_title, cur_text, cur_comment, cur_user, cur_user_text, cur_timestamp, cur_minor_edit,
+                               '', inverse_timestamp
+                       FROM cur", $fname );
+
+               echo "......Setting up revision table.\n";
+               $wgDatabase->query( "INSERT INTO revision (rev_id, rev_page, rev_comment, rev_user, rev_user_text, rev_timestamp,
+                               inverse_timestamp, rev_minor_edit)
+                       SELECT old_id, cur_id, old_comment, old_user, old_user_text,
+                               old_timestamp, old.inverse_timestamp, old_minor_edit
+                       FROM old,cur WHERE old_namespace=cur_namespace AND old_title=cur_title", $fname );
+
+               echo "......Setting up page table.\n";
+               $wgDatabase->query( "INSERT INTO page (page_id, page_namespace, page_title, page_restrictions, page_counter,
+                               page_is_redirect, page_is_new, page_random, page_touched, page_latest)
+                       SELECT cur_id, cur_namespace, cur_title, cur_restrictions, cur_counter, cur_is_redirect, cur_is_new,
+                               cur_random, cur_touched, rev_id
+                       FROM cur,revision
+                       WHERE cur_id=rev_page AND rev_timestamp=cur_timestamp AND rev_id > {$maxold}", $fname );
+
+               echo "......Unlocking tables.\n";
+               $wgDatabase->query( "UNLOCK TABLES", $fname );
+
+               echo "......Renaming old.\n";
+               $wgDatabase->query( "ALTER TABLE old RENAME TO text", $fname );
+               echo "...done.\n";
+       }
+}
+
 function do_all_updates() {
        global $wgNewTables, $wgNewFields;
        
@@ -279,6 +414,8 @@ function do_all_updates() {
        do_copy_newtalk_to_watchlist(); flush();
        do_user_update(); flush();
 
+       do_schema_restructuring(); flush();
+
        if ( isTemplateInitialised() ) {
                print "Template namespace already initialised\n";
        } else {
index 0a04bf4..cc3df09 100644 (file)
@@ -16,19 +16,47 @@ class SearchEngine_TestCase extends PHPUnit_TestCase {
        
        function insertSearchData() {
                $this->db->safeQuery( <<<END
-               INSERT INTO ! (cur_id,cur_namespace,cur_title,cur_text)
-               VALUES (1, 0, 'Main_Page', 'This is a main page'),
-                          (2, 1, 'Main_Page', 'This is a talk page to the main page, see [[smithee]]'),
-                          (3, 0, 'Smithee', 'A smithee is one who smiths. See also [[Alan Smithee]]'),
-                          (4, 1, 'Smithee', 'This article sucks.'),
-                          (5, 0, 'Unrelated_page', 'Nothing in this page is about the S word.'),
-                          (6, 0, 'Another_page', 'This page also is unrelated.'),
-                          (7, 4, 'Help', 'Help me!'),
-                          (8, 0, 'Thppt', 'Blah blah'),
-                          (9, 0, 'Alan_Smithee', 'yum'),
-                          (10, 0, 'Pages', 'are food')
+               INSERT INTO ! (page_id,page_namespace,page_title,page_latest)
+               VALUES (1, 0, 'Main_Page', 1),
+                          (2, 1, 'Main_Page', 2),
+                          (3, 0, 'Smithee', 3),
+                          (4, 1, 'Smithee', 4),
+                          (5, 0, 'Unrelated_page', 5),
+                          (6, 0, 'Another_page', 6),
+                          (7, 4, 'Help', 7),
+                          (8, 0, 'Thppt', 8),
+                          (9, 0, 'Alan_Smithee', 9),
+                          (10, 0, 'Pages', 10)
 END
-                       , $this->db->tableName( 'cur' ) );
+                       , $this->db->tableName( 'page' ) );
+               $this->db->safeQuery( <<<END
+               INSERT INTO ! (rev_id,rev_page)
+               VALUES (1, 1),
+                      (2, 2),
+                      (3, 3),
+                      (4, 4),
+                      (5, 5),
+                      (6, 6),
+                      (7, 7),
+                      (8, 8),
+                      (9, 9),
+                      (10, 10)
+END
+                       , $this->db->tableName( 'revision' ) );
+               $this->db->safeQuery( <<<END
+               INSERT INTO ! (old_id,old_text)
+               VALUES (1, 'This is a main page'),
+                          (2, 'This is a talk page to the main page, see [[smithee]]'),
+                          (3, 'A smithee is one who smiths. See also [[Alan Smithee]]'),
+                          (4, 'This article sucks.'),
+                          (5, 'Nothing in this page is about the S word.'),
+                          (6, 'This page also is unrelated.'),
+                          (7, 'Help me!'),
+                          (8, 'Blah blah'),
+                          (9, 'yum'),
+                          (10,'are food')
+END
+                       , $this->db->tableName( 'text' ) );
                $this->db->safeQuery( <<<END
                INSERT INTO ! (si_page,si_title,si_text)
                VALUES (1, 'main page', 'this is a main page'),
@@ -48,7 +76,7 @@ END
        function fetchIds( &$results ) {
                $matches = array();
                while( $row = $results->fetchObject() ) {
-                       $matches[] = IntVal( $row->cur_id );
+                       $matches[] = IntVal( $row->page_id );
                }
                $results->free();
                # Search is not guaranteed to return results in a certain order;
index 433b821..9767e18 100644 (file)
@@ -14,7 +14,7 @@ class SearchMySQL3Test extends SearchEngine_TestCase {
                $GLOBALS['wgContLang'] = new LanguageUtf8;
                $this->db =& buildTestDatabase(
                        'mysql3',
-                       array( 'cur', 'searchindex' ) );
+                       array( 'page', 'revision', 'text', 'searchindex' ) );
                if( $this->db ) {
                        $this->insertSearchData();
                }
index 129ec60..4038572 100644 (file)
@@ -14,7 +14,7 @@ class SearchMySQL4Test extends SearchEngine_TestCase {
                $GLOBALS['wgContLang'] = new LanguageUtf8;
                $this->db =& buildTestDatabase(
                        'mysql4',
-                       array( 'cur', 'searchindex' ) );
+                       array( 'page', 'revision', 'text', 'searchindex' ) );
                if( $this->db ) {
                        $this->insertSearchData();
                }