$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
* @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?
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;
$u = new SearchUpdate( $newid, $this->getPrefixedDBkey(), '' );
$u->doUpdate();
- wfRunHooks( 'TitleMoveComplete', $this, $nt, $wgUser, $oldid, $newid );
+ 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() );
# Record in RC
$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() );
- // attach revision to the new page
- $dbw->update( 'revision', array('rev_page' => $newid), array('rev_id' => $revid), $fname);
-
# Record in RC
// Replaced by a log entry
// RecentChange::notifyMoveToNew( $now, $this, $nt, $wgUser, $comment );
$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();
+ }
}
-?>
\ No newline at end of file
+?>