<?php
/**
- * $Id$
* See title.doc
*
* @package MediaWiki
$wgTitleInterwikiCache = array();
define ( 'GAID_FOR_UPDATE', 1 );
+# Title::newFromTitle maintains a cache to avoid
+# expensive re-normalization of commonly used titles.
+# On a batch operation this can become a memory leak
+# if not bounded. After hitting this many titles,
+# reset the cache.
+define( 'MW_TITLECACHE_MAX', 1000 );
+
/**
* Title class
* - Represents a title, which may contain an interwiki designation or namespace
$this->mInterwiki = $this->mUrlform =
$this->mTextform = $this->mDbkeyform = '';
$this->mArticleID = -1;
- $this->mNamespace = 0;
+ $this->mNamespace = NS_MAIN;
$this->mRestrictionsLoaded = false;
$this->mRestrictions = array();
- $this->mDefaultNamespace = 0;
+ # Dont change the following, NS_MAIN is hardcoded in several place
+ # See bug #696
+ $this->mDefaultNamespace = NS_MAIN;
}
/**
* @static
* @access public
*/
- /* static */ function &newFromText( $text, $defaultNamespace = 0 ) {
+ function &newFromText( $text, $defaultNamespace = NS_MAIN ) {
$fname = 'Title::newFromText';
wfProfileIn( $fname );
+ if( is_object( $text ) ) {
+ wfDebugDieBacktrace( 'Title::newFromText given an object' );
+ }
+
/**
* Wiki pages often contain multiple links to the same page.
* Title normalization and parsing can become expensive on
* In theory these are value objects and won't get changed...
*/
static $titleCache = array();
- if( $defaultNamespace == 0 && isset( $titleCache[$text] ) ) {
+ if( $defaultNamespace == NS_MAIN && isset( $titleCache[$text] ) ) {
wfProfileOut( $fname );
return $titleCache[$text];
}
$t->mDefaultNamespace = $defaultNamespace;
if( $t->secureAndSplit() ) {
- if( $defaultNamespace == 0 ) {
+ if( $defaultNamespace == NS_MAIN ) {
+ if( count( $titleCache ) >= MW_TITLECACHE_MAX ) {
+ # Avoid memory leaks on mass operations...
+ $titleCache = array();
+ }
$titleCache[$text] =& $t;
}
wfProfileOut( $fname );
/**
* 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;
}
/**
* 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
$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;
}
}
/**
- * 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
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 ) {
if ( $query == '' ) {
$url = str_replace( '$1', $dbkey, $wgArticlePath );
} else {
+ if( preg_match( '/^(.*&|)action=([^&]*)(&(.*)|)$/', $query, $matches ) ) {
+ global $wgActionPaths;
+ $action = urldecode( $matches[2] );
+ if( isset( $wgActionPaths[$action] ) ) {
+ $query = $matches[1];
+ if( isset( $matches[4] ) ) $query .= $matches[4];
+ $url = str_replace( '$1', $dbkey, $wgActionPaths[$action] );
+ if( $query != '' ) $url .= '?' . $query;
+ return $url;
+ }
+ }
if ( $query == '-' ) {
$query = '';
}
}
return false;
}
+
+ /**
+ * Is this a talk page of some sort?
+ * @return bool
+ * @access public
+ */
+ function isTalkPage() {
+ return Namespace::isTalk( $this->getNamespace() );
+ }
/**
* Is this a .css or .js subpage of a user page?
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] ) ) {
* 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
}
/**
- * 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;
# Clean up whitespace
#
- $t = preg_replace( '/[\\s_]+/', '_', $this->mDbkeyform );
+ $t = preg_replace( '/[ _]+/', '_', $this->mDbkeyform );
$t = trim( $t, '_' );
if ( '' == $t ) {
}
# 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 ) {
+ wfProfileOut( $fname );
return false;
}
$t = $r;
}
+ /**
+ * Can't make a link to a namespace alone...
+ * "empty" local links can only be self-links
+ * with a fragment identifier.
+ */
+ if( $t == '' &&
+ $this->mInterwiki == '' &&
+ $this->mNamespace != NS_MAIN ) {
+ wfProfileOut( $fname );
+ return false;
+ }
+
+ if( $wgUseLatin1 && $this->mInterwiki != '' ) {
+ # On a Latin-1 wiki, numbered character entities may have
+ # left us with a mix of 8-bit and UTF-8 characters, and
+ # some of those might be Windows-1252 special chars.
+ # Normalize interwikis to pure UTF-8.
+ $t = Title::mergeLatin1Utf8( $t );
+ }
+
# Fill fields
$this->mDbkeyform = $t;
$this->mUrlform = wfUrlencode( $t );
} 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;
}
}
} 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;
}
}
* @access public
*/
function moveTo( &$nt, $auth = true ) {
+ global $wgUser;
if( !$this or !$nt ) {
return 'badtitletext';
}
return 'badarticleerror';
}
- if ( $auth && ( !$this->userCanEdit() || !$nt->userCanEdit() ) ) {
+ if ( $auth && (
+ !$this->userCanEdit() || !$nt->userCanEdit() ||
+ !$this->userCanMove() || !$nt->userCanMove() ) ) {
return 'protectedpage';
}
# Fixing category links (those without piped 'alternate' names) to be sorted under the new title
$dbw =& wfGetDB( DB_MASTER );
- $sql = "UPDATE categorylinks SET cl_sortkey=" . $dbw->addQuotes( $nt->getPrefixedText() ) .
+ $categorylinks = $dbw->tableName( 'categorylinks' );
+ $sql = "UPDATE $categorylinks SET cl_sortkey=" . $dbw->addQuotes( $nt->getPrefixedText() ) .
" WHERE cl_from=" . $dbw->addQuotes( $this->getArticleID() ) .
" AND cl_sortkey=" . $dbw->addQuotes( $this->getPrefixedText() );
$dbw->query( $sql, 'SpecialMovepage::doSubmit' );
$u = new SearchUpdate( $newid, $this->getPrefixedDBkey(), '' );
$u->doUpdate();
+ wfRunHooks( 'TitleMoveComplete', $this, $nt, $wgUser, $oldid, $newid );
return true;
}
/* private */ function moveOverExistingRedirect( &$nt ) {
global $wgUser, $wgLinkCache, $wgUseSquid, $wgMwRedir;
$fname = 'Title::moveOverExistingRedirect';
- $comment = wfMsg( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
+ $comment = wfMsgForContent( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
$now = wfTimestampNow();
- $won = wfInvertTimestamp( $now );
+ $rand = wfRandom();
$newid = $nt->getArticleID();
$oldid = $this->getArticleID();
$dbw =& wfGetDB( DB_MASTER );
$links = $dbw->tableName( 'links' );
+ # Delete the old redirect. We don't save it to history since
+ # 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( '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() );
- # Repurpose the old redirect. We don't save it to history since
- # by definition if we've got here it's rather uninteresting.
-
+ # Recreate the redirect, this time in the other direction.
$redirectText = $wgMwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
- $dbw->update( 'cur',
- /* SET */ array(
- '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
- ),
- /* WHERE */ array( 'cur_id' => $newid ),
- $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
+ ), $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() );
- # 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
- );
-
- RecentChange::notifyMoveOverRedirect( $now, $this, $nt, $wgUser, $comment );
+ # Record in RC
+ // Replaced by a log entry
+ // RecentChange::notifyMoveOverRedirect( $now, $this, $nt, $wgUser, $comment );
+ # Log the move
+ $log = new LogPage( 'move' );
+ $log->addEntry( 'move_redir', $this, '', array(1 => $nt->getText()) );
+
# Swap links
# Load titles and IDs
*/
/* private */ function moveToNewTitle( &$nt, &$newid ) {
global $wgUser, $wgLinkCache, $wgUseSquid;
+ global $wgMwRedir;
$fname = 'MovePageForm::moveToNewTitle';
- $comment = wfMsg( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
+ $comment = wfMsgForContent( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
$newid = $nt->getArticleID();
$oldid = $this->getArticleID();
$dbw =& wfGetDB( DB_MASTER );
$now = $dbw->timestamp();
- $won = wfInvertTimestamp( wfTimestamp(TS_MW,$now) );
wfSeedRandom();
$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
+ ), $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
- );
-
+ // attach revision to the new page
+ $dbw->update( 'revision', array('rev_page' => $newid), array('rev_id' => $revid), $fname);
+
# Record in RC
- RecentChange::notifyMoveToNew( $now, $this, $nt, $wgUser, $comment );
+ // Replaced by a log entry
+ // RecentChange::notifyMoveToNew( $now, $this, $nt, $wgUser, $comment );
+
+ # Log the move
+ $log = new LogPage( 'move' );
+ $log->addEntry( 'move', $this, '', array(1 => $nt->getText()) );
# Purge squid and linkscc as per article creation
Article::onArticleCreate( $nt );
* @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() ) {
}
# 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'
);
$fname = 'Title::createRedirect';
$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,
+ ), $fname );
+
+ $dbw->update( 'page',
+ /* SET */ array( 'page_latest' => $revisionId ),
+ /* WHERE */ array( 'page_id' => $newid ),
+ $fname );
$this->resetArticleID( $newid );
# Link table
* @access public
*/
function curCond() {
+ wfDebugDieBacktrace( 'curCond called' );
return array( 'cur_namespace' => $this->mNamespace, 'cur_title' => $this->mDbkeyform );
}
* @access public
*/
function oldCond() {
+ wfDebugDieBacktrace( 'oldCond called' );
return array( 'old_namespace' => $this->mNamespace, 'old_title' => $this->mDbkeyform );
}
*/
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' );
}
/**
*/
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' );
+ }
+
+ /**
+ * Compare with another title.
+ *
+ * @param Title $title
+ * @return bool
+ */
+ function equals( &$title ) {
+ return $this->getInterwiki() == $title->getInterwiki()
+ && $this->getNamespace() == $title->getNamespace()
+ && $this->getDbkey() == $title->getDbkey();
+ }
+
+ /**
+ * Convert Windows-1252 extended codepoints to their real Unicode points.
+ * @param int $codepoint
+ * @return int
+ * @access private
+ */
+ function cp1252toUnicode( $codepoint ) {
+ # Mappings from:
+ # http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1252.TXT
+ static $cp1252 = array(
+ 0x80 => 0x20AC, #EURO SIGN
+ 0x81 => UNICODE_REPLACEMENT,
+ 0x82 => 0x201A, #SINGLE LOW-9 QUOTATION MARK
+ 0x83 => 0x0192, #LATIN SMALL LETTER F WITH HOOK
+ 0x84 => 0x201E, #DOUBLE LOW-9 QUOTATION MARK
+ 0x85 => 0x2026, #HORIZONTAL ELLIPSIS
+ 0x86 => 0x2020, #DAGGER
+ 0x87 => 0x2021, #DOUBLE DAGGER
+ 0x88 => 0x02C6, #MODIFIER LETTER CIRCUMFLEX ACCENT
+ 0x89 => 0x2030, #PER MILLE SIGN
+ 0x8A => 0x0160, #LATIN CAPITAL LETTER S WITH CARON
+ 0x8B => 0x2039, #SINGLE LEFT-POINTING ANGLE QUOTATION MARK
+ 0x8C => 0x0152, #LATIN CAPITAL LIGATURE OE
+ 0x8D => UNICODE_REPLACEMENT,
+ 0x8E => 0x017D, #LATIN CAPITAL LETTER Z WITH CARON
+ 0x8F => UNICODE_REPLACEMENT,
+ 0x90 => UNICODE_REPLACEMENT,
+ 0x91 => 0x2018, #LEFT SINGLE QUOTATION MARK
+ 0x92 => 0x2019, #RIGHT SINGLE QUOTATION MARK
+ 0x93 => 0x201C, #LEFT DOUBLE QUOTATION MARK
+ 0x94 => 0x201D, #RIGHT DOUBLE QUOTATION MARK
+ 0x95 => 0x2022, #BULLET
+ 0x96 => 0x2013, #EN DASH
+ 0x97 => 0x2014, #EM DASH
+ 0x98 => 0x02DC, #SMALL TILDE
+ 0x99 => 0x2122, #TRADE MARK SIGN
+ 0x9A => 0x0161, #LATIN SMALL LETTER S WITH CARON
+ 0x9B => 0x203A, #SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
+ 0x9C => 0x0153, #LATIN SMALL LIGATURE OE
+ 0x9D => UNICODE_REPLACEMENT,
+ 0x9E => 0x017E, #LATIN SMALL LETTER Z WITH CARON
+ 0x9F => 0x0178, #LATIN CAPITAL LETTER Y WITH DIAERESIS
+ );
+ return isset( $cp1252[$codepoint] )
+ ? $cp1252[$codepoint]
+ : $codepoint;
+ }
+
+ /**
+ * HACKHACKHACK
+ * Take a string containing a mix of CP1252 characters and UTF-8 and try
+ * to convert it completely to UTF-8.
+ *
+ * @param string $string
+ * @return string
+ * @access private
+ */
+ function mergeLatin1Utf8( $string ) {
+ return preg_replace_callback(
+ # Windows CP1252 extends ISO-8859-1 by putting extra characters
+ # into the high control chars area. We have to convert these
+ # to their proper Unicode counterparts.
+ '/([\x80-\x9f])/u',
+ create_function( '$matches',
+ 'return codepointToUtf8(
+ Title::cp1252toUnicode(
+ utf8ToCodepoint( $matches[1] ) ) );' ),
+ preg_replace_callback(
+ # Up-convert everything from 8-bit to UTF-8, then
+ # filter the valid-looking UTF-8 back from the
+ # double-converted form.
+ '/((?:[\xc0-\xdf][\x80-\xbf]
+ |[\xe0-\xef][\x80-\xbf]{2}
+ |[\xf0-\xf7][\x80-\xbf]{3})+)/ux',
+ create_function( '$matches',
+ 'return utf8_decode( $matches[1] );' ),
+ utf8_encode( $string ) ) );
}
}