$this->mInterwiki = $this->mUrlform =
$this->mTextform = $this->mDbkeyform = '';
$this->mArticleID = -1;
- $this->mNamespace = 0;
+ $this->mNamespace = NS_MAIN;
$this->mRestrictionsLoaded = false;
$this->mRestrictions = array();
# Dont change the following, NS_MAIN is hardcoded in several place
* @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();
* @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?
# Clean up whitespace
#
- $t = preg_replace( '/[\\s_]+/', '_', $this->mDbkeyform );
+ $t = preg_replace( '/[ _]+/', '_', $this->mDbkeyform );
$t = trim( $t, '_' );
if ( '' == $t ) {
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;
# We shouldn't need to query the DB for the size.
#$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 );
* @access public
*/
function moveTo( &$nt, $auth = true ) {
+ global $wgUser;
if( !$this or !$nt ) {
return 'badtitletext';
}
$u = new SearchUpdate( $newid, $this->getPrefixedDBkey(), '' );
$u->doUpdate();
+ wfRunHooks( 'TitleMoveComplete', array(&$this, &$nt, &$wgUser, $oldid, $newid) );
return true;
}
$comment = wfMsgForContent( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
$now = wfTimestampNow();
- $won = wfInvertTimestamp( $now );
$rand = wfRandom();
$newid = $nt->getArticleID();
$oldid = $this->getArticleID();
# Recreate the redirect, this time in the other direction.
$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();
+ $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() );
-
- 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.
$oldid = $this->getArticleID();
$dbw =& wfGetDB( DB_MASTER );
$now = $dbw->timestamp();
- $won = wfInvertTimestamp( wfTimestamp(TS_MW,$now) );
wfSeedRandom();
$rand = wfRandom();
# Insert redirect
$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();
+ $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() );
# 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 );
$fname = 'Title::createRedirect';
$dbw =& wfGetDB( DB_MASTER );
- $now = wfTimestampNow();
- $won = wfInvertTimestamp( $now );
- $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 );
+ $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() ) {
'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();
+ }
}
?>