), $fname );
$newid = $dbw->insertId();
+ $this->mTitle->resetArticleId( $newid );
+
wfProfileOut( $fname );
return $newid;
}
* Update the page record to point to a newly saved revision.
*
* @param Database $dbw
- * @param int $revId
- * @param int $lastRevision
- * @param bool $isRedirect
+ * @param Revision $revision -- for ID number, and text used to set
+ length and redirect status fields
+ * @param int $lastRevision -- if given, will not overwrite the page field
+ * when different from the currently set value.
+ * Giving 0 indicates the new page flag should
+ * be set on.
* @return bool true on success, false on failure
* @access private
*/
- function updateRevisionOn( &$dbw, $revId, $lastRevision = null, $isRedirect = false ) {
+ function updateRevisionOn( &$dbw, $revision, $lastRevision = null ) {
$fname = 'Article::updateToRevision';
wfProfileIn( $fname );
# An extra check against threads stepping on each other
$conditions['page_latest'] = $lastRevision;
}
+ $text = $revision->getText();
$dbw->update( 'page',
array( /* SET */
- 'page_latest' => $revId,
+ 'page_latest' => $revision->getId(),
'page_touched' => $dbw->timestamp(),
'page_is_new' => ($lastRevision === 0) ? 0 : 1,
- 'page_is_redirect' => $isRedirect ? 1 : 0,
+ 'page_is_redirect' => Article::isRedirect( $text ),
+ 'page_len' => strlen( $text ),
),
$conditions,
$fname );
return ( $dbw->affectedRows() != 0 );
}
+ /**
+ * If the given revision is newer than the currently set page_latest,
+ * update the page record. Otherwise, do nothing.
+ *
+ * @param Database $dbw
+ * @param Revision $revision
+ */
+ function updateIfNewerOn( &$dbw, $revision ) {
+ $fname = 'Article::updateIfNewerOn';
+ wfProfileIn( $fname );
+
+ $row = $dbw->selectRow(
+ array( 'revision', 'page' ),
+ array( 'rev_id', 'rev_timestamp' ),
+ array(
+ 'page_id' => $this->getId(),
+ 'page_latest=rev_id' ),
+ $fname );
+ if( $row ) {
+ if( $row->rev_timestamp >= $revision->getTimestamp() ) {
+ wfProfileOut( $fname );
+ return false;
+ }
+ $prev = $row->rev_id;
+ } else {
+ # No or missing previous revision; mark the page as new
+ $prev = 0;
+ }
+
+ $ret = $this->updateRevisionOn( $dbw, $revision, $prev );
+ wfProfileOut( $fname );
+ return $ret;
+ }
+
/**
* Theoretically we could defer these whole insert and update
* functions for after display, but that's taking a big leap
$this->mTitle->resetArticleID( $newid );
# Update the page record with revision data
- $this->updateRevisionOn( $dbw, $revisionId, 0, $this->isRedirect( $text ) );
+ $this->updateRevisionOn( $dbw, $revision, 0 );
Article::onArticleCreate( $this->mTitle );
RecentChange::notifyNew( $now, $this->mTitle, $isminor, $wgUser, $summary );
$revisionId = $revision->insertOn( $dbw );
# Update page
- $ok = $this->updateRevisionOn( $dbw, $revisionId, $lastRevision, $redir );
+ $ok = $this->updateRevisionOn( $dbw, $revision, $lastRevision );
if( !$ok ) {
/* Belated edit conflict! Run away!! */
return;
}
- if (wfRunHooks('WatchArticle', $wgUser, $this)) {
+ if (wfRunHooks('WatchArticle', array(&$wgUser, &$this))) {
$wgUser->addWatch( $this->mTitle );
$wgUser->saveSettings();
- wfRunHooks('WatchArticleComplete', $wgUser, $this);
-
+ wfRunHooks('WatchArticleComplete', array(&$wgUser, &$this));
+
$wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
$wgOut->setRobotpolicy( 'noindex,follow' );
return;
}
- if (wfRunHooks('UnwatchArticle', $wgUser, $this)) {
+ if (wfRunHooks('UnwatchArticle', array(&$wgUser, &$this))) {
$wgUser->removeWatch( $this->mTitle );
$wgUser->saveSettings();
- wfRunHooks('UnwatchArticleComplete', $wgUser, $this);
+ wfRunHooks('UnwatchArticleComplete', array(&$wgUser, &$this));
$wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
$wgOut->setRobotpolicy( 'noindex,follow' );
if( !$moveonly ) {
$restrictions .= ":edit=" . $limit;
}
- if (wfRunHooks('ArticleProtect', $this, $wgUser, $limit == 'sysop', $reason, $moveonly)) {
+ if (wfRunHooks('ArticleProtect', array(&$this, &$wgUser, $limit == 'sysop', $reason, $moveonly))) {
$dbw =& wfGetDB( DB_MASTER );
$dbw->update( 'page',
), 'Article::protect'
);
- wfRunHooks('ArticleProtectComplete', $this, $wgUser, $limit == 'sysop', $reason, $moveonly);
+ wfRunHooks('ArticleProtectComplete', array(&$this, &$wgUser, $limit == 'sysop', $reason, $moveonly));
$log = new LogPage( 'protect' );
if ( $limit === '' ) {
$fname = 'Article::doDelete';
wfDebug( $fname."\n" );
- if (wfRunHooks('ArticleDelete', $this, $wgUser, $reason)) {
+ if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason))) {
if ( $this->doDeleteArticle( $reason ) ) {
$deleted = $this->mTitle->getPrefixedText();
$wgOut->addHTML( '<p>' . $text . "</p>\n" );
$wgOut->returnToMain( false );
- wfRunHooks('ArticleDeleteComplete', $this, $wgUser, $reason);
+ wfRunHooks('ArticleDeleteComplete', array(&$this, &$wgUser, $reason));
} else {
$wgOut->fatalError( wfMsg( 'cannotdelete' ) );
}
$n = $this->mTitle->getNamespace();
# Get the last editor, lock table exclusively
- $s = $dbw->selectRow( array( 'page', 'revision' ),
- array( 'page_id','rev_user','rev_user_text','rev_comment' ),
- array( 'page_title' => $tt, 'page_namespace' => $n ),
- $fname, 'FOR UPDATE'
- );
- if( $s === false ) {
- # Something wrong
+ $dbw->begin();
+ $current = Revision::newFromTitle( $this->mTitle );
+ if( is_null( $current ) ) {
+ # Something wrong... no page?
+ $dbw->rollback();
$wgOut->addHTML( wfMsg( 'notanarticle' ) );
return;
}
- $ut = $dbw->strencode( $s->cur_user_text );
- $uid = $s->rev_user;
- $pid = $s->page_id;
$from = str_replace( '_', ' ', $wgRequest->getVal( 'from' ) );
- if( $from != $s->rev_user_text ) {
+ if( $from != $current->getUserText() ) {
$wgOut->setPageTitle(wfmsg('rollbackfailed'));
$wgOut->addWikiText( wfMsg( 'alreadyrolled',
htmlspecialchars( $this->mTitle->getPrefixedText()),
htmlspecialchars( $from ),
- htmlspecialchars( $s->rev_user_text ) ) );
- if($s->rev_comment != '') {
+ htmlspecialchars( $current->getUserText() ) ) );
+ if( $current->getComment() != '') {
$wgOut->addHTML(
- wfMsg('editcomment',
- htmlspecialchars( $s->rev_comment ) ) );
+ wfMsg( 'editcomment',
+ htmlspecialchars( $current->getComment() ) ) );
}
return;
}
# Get the last edit not by this guy
- $s = $dbw->selectRow( 'old',
- array( 'old_text','old_user','old_user_text','old_timestamp','old_flags' ),
+ $user = IntVal( $current->getUser() );
+ $user_text = $dbw->addQuotes( $current->getUserText() );
+ $s = $dbw->selectRow( 'revision',
+ array( 'rev_id', 'rev_timestamp' ),
array(
- 'old_namespace' => $n,
- 'old_title' => $tt,
- "old_user <> {$uid} OR old_user_text <> '{$ut}'"
- ), $fname, array( 'FOR UPDATE', 'USE INDEX' => 'name_title_timestamp' )
- );
+ 'rev_page' => $current->getPage(),
+ "rev_user <> {$user} OR rev_user_text <> {$user_text}"
+ ), $fname,
+ array(
+ 'USE INDEX' => 'page_timestamp',
+ 'ORDER BY' => 'rev_timestamp DESC' )
+ );
if( $s === false ) {
# Something wrong
+ $dbw->rollback();
$wgOut->setPageTitle(wfMsg('rollbackfailed'));
$wgOut->addHTML( wfMsg( 'cantrollback' ) );
return;
}
-
+
if ( $bot ) {
# Mark all reverted edits as bot
$dbw->update( 'recentchanges',
array( /* SET */
'rc_bot' => 1
), array( /* WHERE */
- 'rc_user' => $uid,
- "rc_timestamp > '{$s->old_timestamp}'",
+ 'rc_cur_id' => $current->getPage(),
+ 'rc_user_text' => $current->getUserText(),
+ "rc_timestamp > '{$s->rev_timestamp}'",
), $fname
);
}
# Save it!
- $newcomment = wfMsg( 'revertpage', $s->old_user_text, $from );
+ $target = Revision::newFromId( $s->rev_id );
+ $newcomment = wfMsg( 'revertpage', $target->getUserText(), $from );
+
$wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
$wgOut->setRobotpolicy( 'noindex,nofollow' );
$wgOut->addHTML( '<h2>' . htmlspecialchars( $newcomment ) . "</h2>\n<hr />\n" );
- $this->updateArticle( Revision::getRevisionText( $s ), $newcomment, 1, $this->mTitle->userIsWatching(), $bot );
+
+ $this->updateArticle( $target->getText(), $newcomment, 1, $this->mTitle->userIsWatching(), $bot );
Article::onArticleEdit( $this->mTitle );
+
+ $dbw->commit();
$wgOut->returnToMain( false );
}
'minor_edit' => $minor ? 1 : 0,
) );
$revisionId = $revision->insertOn( $dbw );
- $this->updateRevisionOn( $dbw, $revisionId, null,
- Article::isRedirect( $text ) );
+ $this->updateRevisionOn( $dbw, $revision );
$dbw->commit();
wfProfileOut( $fname );
}
}
-/**
- * Check whether an article is a stub
- *
- * @public
- * @param integer $articleID ID of the article that is to be checked
- */
-function wfArticleIsStub( $articleID ) {
- global $wgUser;
- $fname = 'wfArticleIsStub';
-
- wfDebugDieBacktrace( 'This function seems to be unused. Pending removal.' );
-
- $threshold = $wgUser->getOption('stubthreshold') ;
- if ( $threshold > 0 ) {
- $dbr =& wfGetDB( DB_SLAVE );
- $s = $dbr->selectRow( array('page', 'text'),
- array( 'LENGTH(old_text) AS len', 'page_namespace', 'page_is_redirect' ),
- array( 'page_id' => $articleID, "page.page_latest=text.old_id" ),
- $fname ) ;
- if ( $s == false OR $s->page_is_redirect OR $s->page_namespace != NS_MAIN ) {
- return false;
- }
- $size = $s->len;
- return ( $size < $threshold );
- }
- return false;
-}
?>