This will require downtiime on upgrade, so we're not going to do it until we have a better idea of the cost and can make all necessary changes at once to minimize it.
function &getOldContentFields() {
global $wgArticleOldContentFields;
if ( !$wgArticleOldContentFields ) {
- $wgArticleOldContentFields = array( 'old_articleid','old_text','old_timestamp',
+ $wgArticleOldContentFields = array( 'old_namespace','old_title','old_text','old_timestamp',
'old_user','old_user_text','old_comment','old_flags' );
}
return $wgArticleOldContentFields;
return;
}
- if( $this->mTitle->getArticleID() != $s->old_articleid ) {
- $oldTitle = Title::newFromID( $s->old_articleid );
+ if( $this->mTitle->getNamespace() != $s->old_namespace ||
+ $this->mTitle->getDBkey() != $s->old_title ) {
+ $oldTitle = Title::makeTitle( $s->old_namesapce, $s->old_title );
$this->mTitle = $oldTitle;
$wgTitle = $oldTitle;
}
$dbr =& $this->getDB();
$oldTable = $dbr->tableName( 'old' );
$userTable = $dbr->tableName( 'user' );
- $artid = $title->getArticleID();
+ $encDBkey = $dbr->addQuotes( $title->getDBkey() );
$ns = $title->getNamespace();
$user = $this->getUser();
$sql = "SELECT old_user, old_user_text, user_real_name, MAX(old_timestamp) as timestamp
FROM $oldTable LEFT JOIN $userTable ON old_user = user_id
- WHERE old_articleid = $artid
+ WHERE old_namespace = $user
+ AND old_title = $encDBkey
AND old_user != $user
GROUP BY old_user, old_user_text, user_real_name
ORDER BY timestamp DESC";
$dbw =& wfGetDB( DB_MASTER );
$ns = $this->mTitle->getNamespace();
$title = $this->mTitle->getDBkey();
- $aid = $this->mTitle->getArticleID();
$obj = $dbw->getArray( 'old',
array( 'old_text','old_flags'),
- array( 'old_articleid' => $aid,
+ array( 'old_namespace' => $ns, 'old_title' => $title,
'old_timestamp' => $dbw->timestamp($edittime)),
$fname );
$oldtext = Article::getRevisionText( $obj );
$dbw->insertArray( 'old',
array(
'old_id' => $dbw->nextSequenceValue( 'old_old_id_seq' ),
- 'old_articleid' => $this->mTitle->getArticleID(),
+ 'old_namespace' => $this->mTitle->getNamespace(),
+ 'old_title' => $this->mTitle->getDBkey(),
'old_text' => $oldtext,
'old_comment' => $this->getComment(),
'old_user' => $this->getUser(),
$dbr =& $this->getDB();
$ns = $this->mTitle->getNamespace();
$title = $this->mTitle->getDBkey();
- $artid = $this->mTitle->getArticleID();
$old = $dbr->getArray( 'old',
array( 'old_text', 'old_flags' ),
- array( 'old_articleid' => $artid ),
- $fname, $this->getSelectOptions( array( 'ORDER BY' => 'inverse_timestamp' ) )
+ array(
+ 'old_namespace' => $ns,
+ 'old_title' => $title,
+ ), $fname, $this->getSelectOptions( array( 'ORDER BY' => 'inverse_timestamp' ) )
);
if( $old !== false && !$confirm ) {
$recentchangesTable = $dbw->tableName( 'recentchanges' );
$linksTable = $dbw->tableName( 'links' );
$brokenlinksTable = $dbw->tableName( 'brokenlinks' );
- $artid = $this->mTitle->getArticleID();
$dbw->insertSelect( 'archive', 'cur',
array(
), $fname
);
- $dbw->insertSelect( 'archive', 'cur,old',
+ $dbw->insertSelect( 'archive', 'old',
array(
- 'ar_namespace' => 'cur_namespace',
- 'ar_title' => 'cur_title',
+ 'ar_namespace' => 'old_namespace',
+ 'ar_title' => 'old_title',
'ar_text' => 'old_text',
'ar_comment' => 'old_comment',
'ar_user' => 'old_user',
'ar_minor_edit' => 'old_minor_edit',
'ar_flags' => 'old_flags'
), array(
- 'old_articleid' => $artid
+ 'old_namespace' => $ns,
+ 'old_title' => $t,
), $fname
);
# Now that it's safely backed up, delete it
$dbw->delete( 'cur', array( 'cur_namespace' => $ns, 'cur_title' => $t ), $fname );
- $dbw->delete( 'old', array( 'old_articleid' => $artid ), $fname );
+ $dbw->delete( 'old', array( 'old_namespace' => $ns, 'old_title' => $t ), $fname );
$dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), $fname );
# Finally, clean up the link tables
$s = $dbw->getArray( 'old',
array( 'old_text','old_user','old_user_text','old_timestamp','old_flags' ),
array(
- 'old_articleid' => $pid,
+ 'old_namespace' => $n,
+ 'old_title' => $tt,
"old_user <> {$uid} OR old_user_text <> '{$ut}'"
- ), $fname, array( 'FOR UPDATE', 'USE INDEX' => 'articleid_timestamp' )
+ ), $fname, array( 'FOR UPDATE', 'USE INDEX' => 'name_title_timestamp' )
);
if( $s === false ) {
# Something wrong
# Save to history
$dbw->insertSelect( 'old', 'cur',
array(
- 'old_articleid' => 'cur_id',
+ 'old_namespace' => 'cur_namespace',
+ 'old_title' => 'cur_title',
'old_text' => 'cur_text',
'old_comment' => 'cur_comment',
'old_user' => 'cur_user',
$basenamespace = $wgTitle->getNamespace() & (~1);
$cur_clause = array( 'cur_title' => $wgTitle->getDBkey(), 'cur_namespace' => $basenamespace );
- $old_clause = array( 'old_articleid' => $wgTitle->getArticleID() );
+ $old_clause = array( 'old_title' => $wgTitle->getDBkey(), 'old_namespace' => $basenamespace );
$wl_clause = array( 'wl_title' => $wgTitle->getDBkey(), 'wl_namespace' => $basenamespace );
$fullTitle = $wgTitle->makeName($basenamespace, $wgTitle->getDBKey());
$wgOut->setPagetitle( $fullTitle );
# now for the Talk page ...
$cur_clause = array( 'cur_title' => $wgTitle->getDBkey(), 'cur_namespace' => $basenamespace+1 );
+ $old_clause = array( 'old_title' => $wgTitle->getDBkey(), 'old_namespace' => $basenamespace+1 );
# does it exist?
$exists = $dbr->selectField( 'cur', 'COUNT(*)', $cur_clause, $fname, $this->getSelectOptions() );
# number of edits
if ($exists > 0) {
- $oldartid = $dbr->selectField( 'cur', 'cur_id',
- $cur_clause, $fname, $this->getSelectOptions());
- $old_clause = array( 'old_articleid' => $oldartid );
$old = $dbr->selectField( 'old', 'COUNT(*)', $old_clause, $fname, $this->getSelectOptions() );
$wgOut->addHTML( '<li>' . wfMsg("numtalkedits", $old + 1) . '</li>');
}
$this->mNewid = intval($old);
$dbr =& wfGetDB( DB_SLAVE );
$this->mOldid = $dbr->selectField( 'old', 'old_id',
- "old_articleid = " . $wgTitle->getArticleID() .
+ "old_title='" . $wgTitle->getDBkey() . "'" .
+ ' AND old_namespace=' . $wgTitle->getNamespace() .
" AND old_id<{$this->mNewid} ORDER BY old_id DESC" );
} elseif ( 'next' == $new ) {
$this->mOldid = intval($old);
$dbr =& wfGetDB( DB_SLAVE );
$this->mNewid = $dbr->selectField( 'old', 'old_id',
- "old_articleid = " . $wgTitle->getArticleID() .
+ "old_title='" . $wgTitle->getDBkey() . "'" .
+ ' AND old_namespace=' . $wgTitle->getNamespace() .
" AND old_id>{$this->mOldid} ORDER BY old_id " );
if ( false === $this->mNewid ) {
# if no result, NewId points to the newest old revision. The only newer
$this->mNewUser = $s->cur_user_text;
$this->mNewComment = $s->cur_comment;
} else {
- $s = $dbr->getArray( 'old', array( 'old_articleid', 'old_timestamp', 'old_text',
+ $s = $dbr->getArray( 'old', array( 'old_namespace','old_title','old_timestamp', 'old_text',
'old_flags','old_user_text','old_comment' ), array( 'old_id' => $this->mNewid ), $fname );
if ( $s === false ) {
$this->mNewtext = Article::getRevisionText( $s );
$t = $wgLang->timeanddate( $s->old_timestamp, true );
- $this->mNewPage = Title::newFromID( $s->old_articleid );
+ $this->mNewPage = Title::MakeTitle( $s->old_namespace, $s->old_title );
$newLink = $wgTitle->getLocalUrl ('oldid=' . $this->mNewid);
$this->mPagetitle = wfMsg( 'revisionasof', $t );
$this->mNewtitle = "<a href='$newLink'>{$this->mPagetitle}</a>";
}
if ( 0 == $this->mOldid ) {
$s = $dbr->getArray( 'old',
- array( 'old_timestamp','old_text', 'old_flags','old_user_text','old_comment' ),
+ array( 'old_namespace','old_title','old_timestamp','old_text', 'old_flags','old_user_text','old_comment' ),
array( /* WHERE */
- 'old_articleid' => $this->mNewPage->getArticleID(),
- ), $fname, array( 'ORDER BY' => 'inverse_timestamp', 'USE INDEX' => 'articleid_timestamp' )
+ 'old_namespace' => $this->mNewPage->getNamespace(),
+ 'old_title' => $this->mNewPage->getDBkey()
+ ), $fname, array( 'ORDER BY' => 'inverse_timestamp', 'USE INDEX' => 'name_title_timestamp' )
);
if ( $s === false ) {
wfDebug( 'Unable to load ' . $this->mNewPage->getPrefixedDBkey . " from old\n" );
}
} else {
$s = $dbr->getArray( 'old',
- array( 'old_timestamp','old_text','old_flags','old_user_text','old_comment'),
+ array( 'old_namespace','old_title','old_timestamp','old_text','old_flags','old_user_text','old_comment'),
array( 'old_id' => $this->mOldid ),
$fname
);
return false;
}
}
- $this->mOldPage = Title::newFromID( $wgTitle->getArticleID() );
+ $this->mOldPage = Title::MakeTitle( $s->old_namespace, $s->old_title );
$this->mOldtext = Article::getRevisionText( $s );
$t = $wgLang->timeanddate( $s->old_timestamp, true );
$title = $this->mTitle->getDBkey();
$obj = $dbw->getArray( 'old',
array( 'old_text','old_flags'),
- array( 'old_articleid' => $this->mTitle->getArticleID(),
+ array( 'old_namespace' => $ns, 'old_title' => $title,
'old_timestamp' => $dbw->timestamp($oldDate)),
$fname );
$oldText = Article::getRevisionText( $obj );
$title = $this->mTitle->getText();
$db =& wfGetDB( DB_SLAVE );
- $use_index = $db->useIndexClause( 'articleid_timestamp' );
+ $use_index = $db->useIndexClause( 'name_title_timestamp' );
$oldtable = $db->tableName( 'old' );
$sql = "SELECT old_id,old_user," .
"old_comment,old_user_text,old_timestamp,old_minor_edit ".
"FROM $oldtable $use_index " .
- "WHERE old_articleid='" . $db->strencode( $this->mTitle->getArticleID() ) . "' " .
+ "WHERE old_namespace={$namespace} AND " .
+ "old_title='" . $db->strencode( $this->mTitle->getDBkey() ) . "' " .
"ORDER BY inverse_timestamp".$db->limitResult($limitplus,$rawoffset);
$res = $db->query( $sql, $fname );
$r .= "<tr>";
foreach ( $k as $x ) {
$o = $y->$x ;
- if ( $x == "cur_title" or $x == "rc_title") {
+ if ( $x == "cur_title" or $x == "old_title" or $x == "rc_title") {
$namespace = 0;
if( $x == "cur_title" ) $namespace = $y->cur_namespace;
+ if( $x == "old_title" ) $namespace = $y->old_namespace;
if( $x == "rc_title" ) $namespace = $y->rc_namespace;
if( $namespace ) $o = $wgContLang->getNsText( $namespace ) . ":" . $o;
$o = "<a href=\"" . wfLocalUrlE($o) . "\" class='internal'>" .
"ORDER BY inverse_timestamp LIMIT {$querylimit}";
$res1 = $dbr->query( $sql, $fname );
- $sql = "SELECT old_articleid,old_timestamp,old_comment,old_minor_edit,old_user_text,old_id FROM $old " .
+ $sql = "SELECT old_namespace,old_title,old_timestamp,old_comment,old_minor_edit,old_user_text,old_id FROM $old " .
"WHERE old_user_text='" . $dbr->strencode( $nt->getText() ) . "' {$omq} " .
"ORDER BY inverse_timestamp LIMIT {$querylimit}";
$res2 = $dbr->query( $sql, $fname );
"WHERE cur_user {$userCond} {$cmq} ORDER BY inverse_timestamp LIMIT {$querylimit}";
$res1 = $dbr->query( $sql, $fname );
- $sql = "SELECT old_articleid,old_timestamp,old_comment,old_minor_edit,old_user_text,old_id FROM $old " .
+ $sql = "SELECT old_namespace,old_title,old_timestamp,old_comment,old_minor_edit,old_user_text,old_id FROM $old " .
"WHERE old_user {$userCond} {$omq} ORDER BY inverse_timestamp LIMIT {$querylimit}";
$res2 = $dbr->query( $sql, $fname );
}
$oldid = false;
--$nCur;
} else {
- $tt = Title::newFromID($obj2->old_articleid);
- $ns = $tt->getNamespace();
- $t = $tt->getDBkey();
+ $ns = $obj2->old_namespace;
+ $t = $obj2->old_title;
$ts = $obj2->old_timestamp;
$comment =$obj2->old_comment;
$me = $obj2->old_minor_edit;
global $wgUser, $wgOut, $wgLang, $wgDeferredUpdateList;
global $wgUseSquid, $wgInternalServer, $wgLinkCache;
- $fname = "undelete";
+ $fname = "doUndeleteArticle";
$dbw =& wfGetDB( DB_MASTER );
extract( $dbw->tableNames( 'cur', 'archive', 'old' ) );
# We should merge.
}
- $sql = "INSERT INTO $old (old_articleid,old_text," .
+ $sql = "INSERT INTO $old (old_namespace,old_title,old_text," .
"old_comment,old_user,old_user_text,old_timestamp,inverse_timestamp,old_minor_edit," .
- "old_flags) SELECT ".$this->title->getArticleID().",ar_text,ar_comment," .
+ "old_flags) SELECT ar_namespace,ar_title,ar_text,ar_comment," .
"ar_user,ar_user_text,ar_timestamp,99999999999999-ar_timestamp,ar_minor_edit,ar_flags " .
"FROM $archive WHERE ar_namespace={$namespace} AND ar_title='{$t}' {$oldones}";
$dbw->query( $sql, $fname );
$this->mInterwiki = $this->mUrlform =
$this->mTextform = $this->mDbkeyform = '';
$this->mArticleID = -1;
- $this->mID = -1;
$this->mNamespace = 0;
$this->mRestrictionsLoaded = false;
$this->mRestrictions = array();
- $this->mDefaultNamespace = 0;
+ $this->mDefaultNamespace = 0;
}
# From a prefixed DB key
$fname = 'Title::moveOverExistingRedirect';
$comment = wfMsg( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
- $now = wfTimestampNow();
- $won = wfInvertTimestamp( $now );
+ $now = wfTimestampNow();
+ $won = wfInvertTimestamp( $now );
$newid = $nt->getArticleID();
$oldid = $this->getArticleID();
$dbw =& wfGetDB( DB_MASTER );
$wgLinkCache->clearLink( $this->getPrefixedDBkey() );
+ # Fix the redundant names for the past revisions of the target page.
+ # The redirect should have no old revisions.
+ $dbw->updateArray(
+ /* table */ 'old',
+ /* SET */ array(
+ 'old_namespace' => $nt->getNamespace(),
+ 'old_title' => $nt->getDBkey(),
+ ),
+ /* WHERE */ array(
+ 'old_namespace' => $this->getNamespace(),
+ 'old_title' => $this->getDBkey(),
+ ),
+ $fname
+ );
+
RecentChange::notifyMoveOverRedirect( $now, $this, $nt, $wgUser, $comment );
# Swap links
$newid = $dbw->insertId();
$wgLinkCache->clearLink( $this->getPrefixedDBkey() );
+ # Rename old entries
+ $dbw->updateArray(
+ /* table */ 'old',
+ /* SET */ array(
+ 'old_namespace' => $nt->getNamespace(),
+ 'old_title' => $nt->getDBkey()
+ ),
+ /* WHERE */ array(
+ 'old_namespace' => $this->getNamespace(),
+ 'old_title' => $this->getDBkey()
+ ), $fname
+ );
+
# Record in RC
RecentChange::notifyMoveToNew( $now, $this, $nt, $wgUser, $comment );
# Does the article have a history?
$row = $dbw->getArray( 'old', array( 'old_id' ),
array(
- 'old_articleid' => $nt->getArticleID()
+ 'old_namespace' => $nt->getNamespace(),
+ 'old_title' => $nt->getDBkey()
), $fname, 'FOR UPDATE'
);
}
function oldCond() {
- #return array( 'old_namespace' => $this->mNamespace, 'old_title' => $this->mDbkeyform );
- return array( 'old_articleid' => $this->getArticleID() );
+ return array( 'old_namespace' => $this->mNamespace, 'old_title' => $this->mDbkeyform );
}
}
?>
cur_touched char(14) binary NOT NULL default '',
inverse_timestamp char(14) binary NOT NULL default '',
PRIMARY KEY cur_id (cur_id),
- INDEX name_title (cur_namespace,cur_title),
+ UNIQUE INDEX name_title (cur_namespace,cur_title),
-- Is this one necessary?
INDEX cur_title (cur_title(20)),
CREATE TABLE old (
old_id int(8) unsigned NOT NULL auto_increment,
- old_articleid int(8) unsigned NOT NULL,
+ old_namespace tinyint(2) unsigned NOT NULL default '0',
+ old_title varchar(255) binary NOT NULL default '',
old_text mediumtext NOT NULL default '',
old_comment tinyblob NOT NULL default '',
old_user int(5) unsigned NOT NULL default '0',
inverse_timestamp char(14) binary NOT NULL default '',
PRIMARY KEY old_id (old_id),
- INDEX articleid (old_articleid),
INDEX old_timestamp (old_timestamp),
- INDEX articleid_timestamp (old_articleid,inverse_timestamp),
+ INDEX name_title_timestamp (old_namespace,old_title,inverse_timestamp),
INDEX user_timestamp (old_user,inverse_timestamp),
INDEX usertext_timestamp (old_user_text,inverse_timestamp)
);
-- Key to the page affected. Where a user is the target,
-- this will point to the user page.
log_namespace tinyint unsigned NOT NULL default 0,
- log_title varchar(255) binary NOT NULL default '',
+ log_title varchar(255) NOT NULL default '',
-- Freeform text. Interpreted as edit history comments.
log_comment varchar(255) NOT NULL default '',
array( 'recentchanges', 'rc_patrolled', 'patch-rc-patrol.sql' ),
array( 'user', 'user_real_name', 'patch-user-realname.sql' ),
array( 'user', 'user_token', 'patch-user_token.sql' ),
- array( 'old', 'old_articleid', 'patch-remove-old-title-namespace.sql' ),
);
function add_table( $name, $patch ) {