<?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 );
return $t;
} else {
- $titleCache[$text] = null;
wfProfileOut( $fname );
return NULL;
}
/**
* 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 ) {
* @access public
*/
function getFullURL( $query = '' ) {
- global $wgContLang, $wgArticlePath, $wgServer, $wgScript;
+ global $wgContLang, $wgServer, $wgScript;
if ( '' == $this->mInterwiki ) {
- $p = $wgArticlePath;
return $wgServer . $this->getLocalUrl( $query );
} else {
$baseUrl = $this->getInterwikiLink( $this->mInterwiki );
$namepace .= ':';
}
$url = str_replace( '$1', $namespace . $this->mUrlform, $baseUrl );
+ if( $query != '' ) {
+ if( false === strpos( $url, '?' ) ) {
+ $url .= '?';
+ } else {
+ $url .= '&';
+ }
+ $url .= $query;
+ }
if ( '' != $this->mFragment ) {
$url .= '#' . $this->mFragment;
}
}
}
+ /**
+ * Get a relative directory for putting an HTML version of this article into
+ */
+ function getHashedDirectory() {
+ $dbkey = $this->getPrefixedDBkey();
+ if ( strlen( $dbkey ) < 2 ) {
+ $dbkey = sprintf( "%2s", $dbkey );
+ }
+ $dir = '';
+ for ( $i=0; $i<=1; $i++ ) {
+ if ( $i ) {
+ $dir .= '/';
+ }
+ if ( ord( $dbkey{$i} ) < 128 && ord( $dbkey{$i} ) > 32 ) {
+ $dir .= strtolower( $dbkey{$i} );
+ } else {
+ $dir .= sprintf( "%02X", ord( $dbkey{$i} ) );
+ }
+ }
+ return $dir;
+ }
+
+ function getHashedFilename() {
+ $dbkey = $this->getPrefixedDBkey();
+ $dir = $this->getHashedDirectory();
+ $friendlyName = strtr( $dbkey, '/\\:*?"<>|', '_________' );
+ return "$dir/$friendlyName.html";
+ }
+
/**
* Get a URL with no fragment or server name
* @param string $query an optional query string; if not specified,
* @access public
*/
function getLocalURL( $query = '' ) {
- global $wgLang, $wgArticlePath, $wgScript;
+ global $wgLang, $wgArticlePath, $wgScript, $wgMakeDumpLinks;
if ( $this->isExternal() ) {
return $this->getFullURL();
}
-
+
$dbkey = wfUrlencode( $this->getPrefixedDBkey() );
- if ( $query == '' ) {
+ if ( $wgMakeDumpLinks ) {
+ $url = str_replace( '$1', wfUrlencode( $this->getHashedFilename() ), $wgArticlePath );
+ } elseif ( $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;
$fname = 'Title::secureAndSplit';
wfProfileIn( $fname );
- static $imgpre = false;
- static $rxTc = false;
-
# Initialisation
- if ( $imgpre === false ) {
- $imgpre = ':' . $wgContLang->getNsText( NS_IMAGE ) . ':';
+ static $rxTc = false;
+ if( !$rxTc ) {
# % is needed as well
$rxTc = '/[^' . Title::legalChars() . ']|%[0-9A-Fa-f]{2}/S';
}
# Clean up whitespace
#
- $t = preg_replace( "/[\\s_]+/", '_', $this->mDbkeyform );
- $t = preg_replace( '/^_*(.*?)_*$/', '$1', $t );
+ $t = preg_replace( '/[ _]+/', '_', $this->mDbkeyform );
+ $t = trim( $t, '_' );
if ( '' == $t ) {
wfProfileOut( $fname );
return false;
}
- global $wgUseLatin1;
- if( !$wgUseLatin1 && false !== strpos( $t, UTF8_REPLACEMENT ) ) {
+ if( false !== strpos( $t, UTF8_REPLACEMENT ) ) {
# Contained illegal UTF-8 sequences or forbidden Unicode chars.
wfProfileOut( $fname );
return false;
}
$this->mDbkeyform = $t;
- $done = false;
-
- # :Image: namespace
- if ( 0 == strncasecmp( $imgpre, $t, strlen( $imgpre ) ) ) {
- $t = substr( $t, 1 );
- }
# Initial colon indicating main namespace
if ( ':' == $t{0} ) {
$this->mNamespace = NS_MAIN;
} else {
# Namespace or interwiki prefix
- if ( preg_match( "/^(.+?)_*:_*(.*)$/S", $t, $m ) ) {
- #$p = strtolower( $m[1] );
- $p = $m[1];
- $lowerNs = strtolower( $p );
- if ( $ns = Namespace::getCanonicalIndex( $lowerNs ) ) {
- # Canonical namespace
- $t = $m[2];
- $this->mNamespace = $ns;
- } elseif ( $ns = $wgContLang->getNsIndex( $lowerNs )) {
- # Ordinary namespace
- $t = $m[2];
- $this->mNamespace = $ns;
- } elseif ( $this->getInterwikiLink( $p ) ) {
- # Interwiki link
- $t = $m[2];
- $this->mInterwiki = $p;
-
- if ( !preg_match( "/^([A-Za-z0-9_\\x80-\\xff]+):(.*)$/", $t, $m ) ) {
- $done = true;
- } elseif($this->mInterwiki != $wgLocalInterwiki) {
- $done = true;
+ $firstPass = true;
+ do {
+ if ( preg_match( "/^(.+?)_*:_*(.*)$/S", $t, $m ) ) {
+ $p = $m[1];
+ $lowerNs = strtolower( $p );
+ if ( $ns = Namespace::getCanonicalIndex( $lowerNs ) ) {
+ # Canonical namespace
+ $t = $m[2];
+ $this->mNamespace = $ns;
+ } elseif ( $ns = $wgContLang->getNsIndex( $lowerNs )) {
+ # Ordinary namespace
+ $t = $m[2];
+ $this->mNamespace = $ns;
+ } elseif( $this->getInterwikiLink( $p ) ) {
+ if( !$firstPass ) {
+ # Can't make a local interwiki link to an interwiki link.
+ # That's just crazy!
+ wfProfileOut( $fname );
+ return false;
+ }
+
+ # Interwiki link
+ $t = $m[2];
+ $this->mInterwiki = $p;
+
+ # Redundant interwiki prefix to the local wiki
+ if ( 0 == strcasecmp( $this->mInterwiki, $wgLocalInterwiki ) ) {
+ if( $t == '' ) {
+ # Can't have an empty self-link
+ wfProfileOut( $fname );
+ return false;
+ }
+ $this->mInterwiki = '';
+ $firstPass = false;
+ # Do another namespace split...
+ continue;
+ }
}
+ # If there's no recognized interwiki or namespace,
+ # then let the colon expression be part of the title.
}
- }
+ break;
+ } while( true );
$r = $t;
}
- # Redundant interwiki prefix to the local wiki
- if ( 0 == strcmp( $this->mInterwiki, $wgLocalInterwiki ) ) {
- $this->mInterwiki = '';
- }
# We already know that some pages won't be in the database!
#
if ( '' != $this->mInterwiki || -1 == $this->mNamespace ) {
}
# 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;
+ }
+
# 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', array(&$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
- );
-
+ $redirectArticle = new Article( $this );
+ $newid = $redirectArticle->insertOn( $dbw );
+ $redirectRevision = new Revision( array(
+ 'page' => $newid,
+ 'comment' => $comment,
+ 'text' => $redirectText ) );
+ $revid = $redirectRevision->insertOn( $dbw );
+ $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
$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
$sql .= "($id, $oldid)";
}
- $dbw->query( $sql, DB_MASTER, $fname );
+ $dbw->query( $sql, $fname );
}
# Now, we record the link from the redirect to the new title.
*/
/* 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
- );
- $newid = $dbw->insertId();
+ $redirectText = $wgMwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
+ $redirectArticle = new Article( $this );
+ $newid = $redirectArticle->insertOn( $dbw );
+ $redirectRevision = new Revision( array(
+ 'page' => $newid,
+ 'comment' => $comment,
+ 'text' => $redirectText ) );
+ $revid = $redirectRevision->insertOn( $dbw );
+ $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
$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 );
+ // 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"
- ), $fname );
- $newid = $dbw->insertId();
- $this->resetArticleID( $newid );
+
+ $article = new Article( $this );
+ $newid = $article->insertOn( $dbw );
+ $revision = new Revision( array(
+ 'page' => $newid,
+ 'comment' => $comment,
+ 'text' => "#REDIRECT [[" . $dest->getPrefixedText() . "]]\n",
+ ) );
+ $revisionId = $revision->insertOn( $dbw );
+ $article->updateRevisionOn( $dbw, $revision, 0 );
# Link table
if ( $dest->getArticleID() ) {
* @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();
}
}