$this->mOldId = $oldId;
}
+ /**
+ * Constructor from an article article
+ * @param $id The article ID to load
+ */
+ public static function newFromID( $id ) {
+ $t = Title::newFromID( $id );
+
+ return $t == null ? null : new Article( $t );
+ }
+
/**
* Tell the page view functions that this view was redirected
* from another page on the wiki.
*/
public function followRedirect() {
$text = $this->getContent();
- return self::followRedirectText( $text );
+ return $this->followRedirectText( $text );
}
/**
*
* @return int The old id for the request
*/
- function getOldIDFromRequest() {
+ public function getOldIDFromRequest() {
global $wgRequest;
$this->mRedirectUrl = false;
$oldid = $wgRequest->getVal( 'oldid' );
}
$revision = Revision::newFromId( $this->mLatest );
if( is_null( $revision ) ) {
- wfDebug( __METHOD__." failed to retrieve current page, rev_id {$data->page_latest}\n" );
+ wfDebug( __METHOD__." failed to retrieve current page, rev_id {$this->mLatest}\n" );
return false;
}
}
// FIXME: Horrible, horrible! This content-loading interface just plain sucks.
// We should instead work with the Revision object when we need it...
- $this->mContent = $revision->revText(); // Loads if user is allowed
+ $this->mContent = $revision->getText( Revision::FOR_THIS_USER ); // Loads if user is allowed
$this->mUser = $revision->getUser();
$this->mUserText = $revision->getUserText();
$user = $this->getUser();
$pageId = $this->getId();
- $sql = "SELECT rev_user, rev_user_text, user_real_name, MAX(rev_timestamp) as timestamp
+ $sql = "SELECT {$userTable}.*, MAX(rev_timestamp) as timestamp
FROM $revTable LEFT JOIN $userTable ON rev_user = user_id
WHERE rev_page = $pageId
AND rev_user != $user
$sql .= ' '. $this->getSelectOptions();
- $res = $dbr->query($sql, __METHOD__);
+ $res = $dbr->query($sql, __METHOD__ );
- while ( $line = $dbr->fetchObject( $res ) ) {
- $contribs[] = array($line->rev_user, $line->rev_user_text, $line->user_real_name);
- }
-
- $dbr->freeResult($res);
- return $contribs;
+ return new UserArrayFromResult( $res );
}
/**
if ( !is_null( $diff ) ) {
$wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
- $de = new DifferenceEngine( $this->mTitle, $oldid, $diff, $rcid, $purge );
+ $diff = $wgRequest->getVal( 'diff' );
+ $htmldiff = $wgRequest->getVal( 'htmldiff' , false);
+ $de = new DifferenceEngine( $this->mTitle, $oldid, $diff, $rcid, $purge, $htmldiff);
// DifferenceEngine directly fetched the revision:
$this->mRevIdFetched = $de->mNewid;
$de->showDiffPage( $diffOnly );
}
# Fetch content and check for errors
if ( !$outputDone ) {
+ # If the article does not exist and was deleted, show the log
+ if ($this->getID() == 0) {
+ $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut );
+ $pager = new LogPager( $loglist, 'delete', false, $this->mTitle->getPrefixedText() );
+ $count = $pager->getNumRows();
+ if( $count > 0 ) {
+ $pager->mLimit = 10;
+ $wgOut->addHtml( '<div id="mw-deleted-notice">' );
+ $wgOut->addWikiMsg( 'deleted-notice' );
+ $wgOut->addHTML(
+ $loglist->beginLogEventsList() .
+ $pager->getBody() .
+ $loglist->endLogEventsList()
+ );
+ if($count > 10){
+ $wgOut->addHtml( $wgUser->getSkin()->link(
+ SpecialPage::getTitleFor( 'Log' ),
+ wfMsgHtml( 'deletelog-fulllog' ),
+ array(),
+ array(
+ 'type' => 'delete',
+ 'page' => $this->mTitle->getPrefixedText() ) ) );
+ }
+ $wgOut->addHtml( '</div>' );
+ }
+ }
$text = $this->getContent();
if ( $text === false ) {
# Failed to load, replace text with error message
if ( $wgUser->isAllowed( 'purge' ) || $wgRequest->wasPosted() ) {
if( wfRunHooks( 'ArticlePurge', array( &$this ) ) ) {
$this->doPurge();
+ $this->view();
}
} else {
$msg = $wgOut->parse( wfMsg( 'confirm_purge' ) );
}
$wgMessageCache->replace( $this->mTitle->getDBkey(), $text );
}
- $this->view();
}
/**
* Best if all done inside a transaction.
*
* @param Database $dbw
- * @return int The newly created page_id key
+ * @return int The newly created page_id key, or false if the title already existed
* @private
*/
function insertOn( $dbw ) {
'page_touched' => $dbw->timestamp(),
'page_latest' => 0, # Fill this in shortly...
'page_len' => 0, # Fill this in shortly...
- ), __METHOD__ );
- $newid = $dbw->insertId();
-
- $this->mTitle->resetArticleId( $newid );
+ ), __METHOD__, 'IGNORE' );
+ $affected = $dbw->affectedRows();
+ if ( $affected ) {
+ $newid = $dbw->insertId();
+ $this->mTitle->resetArticleId( $newid );
+ }
wfProfileOut( __METHOD__ );
- return $newid;
+ return $affected ? $newid : false;
}
/**
( $minor ? EDIT_MINOR : 0 ) |
( $forceBot ? EDIT_FORCE_BOT : 0 );
- $good = $this->doEdit( $text, $summary, $flags );
- if ( $good ) {
- $dbw = wfGetDB( DB_MASTER );
- if ($watchthis) {
- if (!$this->mTitle->userIsWatching()) {
- $dbw->begin();
- $this->doWatch();
- $dbw->commit();
- }
- } else {
- if ( $this->mTitle->userIsWatching() ) {
- $dbw->begin();
- $this->doUnwatch();
- $dbw->commit();
- }
+ $status = $this->doEdit( $text, $summary, $flags );
+ if ( !$status->isOK() ) {
+ return false;
+ }
+
+ $dbw = wfGetDB( DB_MASTER );
+ if ($watchthis) {
+ if (!$this->mTitle->userIsWatching()) {
+ $dbw->begin();
+ $this->doWatch();
+ $dbw->commit();
}
+ } else {
+ if ( $this->mTitle->userIsWatching() ) {
+ $dbw->begin();
+ $this->doUnwatch();
+ $dbw->commit();
+ }
+ }
- $extraQuery = ''; // Give extensions a chance to modify URL query on update
- wfRunHooks( 'ArticleUpdateBeforeRedirect', array( $this, &$sectionanchor, &$extraQuery ) );
+ $extraQuery = ''; // Give extensions a chance to modify URL query on update
+ wfRunHooks( 'ArticleUpdateBeforeRedirect', array( $this, &$sectionanchor, &$extraQuery ) );
- $this->doRedirect( $this->isRedirect( $text ), $sectionanchor, $extraQuery );
- }
- return $good;
+ $this->doRedirect( $this->isRedirect( $text ), $sectionanchor, $extraQuery );
+ return true;
}
/**
* Fill in blank summaries with generated text where possible
*
* If neither EDIT_NEW nor EDIT_UPDATE is specified, the status of the article will be detected.
- * If EDIT_UPDATE is specified and the article doesn't exist, the function will return false. If
- * EDIT_NEW is specified and the article does exist, a duplicate key error will cause an exception
- * to be thrown from the Database. These two conditions are also possible with auto-detection due
- * to MediaWiki's performance-optimised locking strategy.
+ * If EDIT_UPDATE is specified and the article doesn't exist, the function will an
+ * edit-gone-missing error. If EDIT_NEW is specified and the article does exist, an
+ * edit-already-exists error will be returned. These two conditions are also possible with
+ * auto-detection due to MediaWiki's performance-optimised locking strategy.
+ *
* @param $baseRevId, the revision ID this edit was based off, if any
*
- * @return bool success
+ * @return Status object. Possible errors:
+ * edit-hook-aborted: The ArticleSave hook aborted the edit but didn't set the fatal flag of $status
+ * edit-gone-missing: In update mode, but the article didn't exist
+ * edit-conflict: In update mode, the article changed unexpectedly
+ * edit-no-change: Warning that the text was the same as before
+ * edit-already-exists: In creation mode, but the article already exists
+ *
+ * Extensions may define additional errors.
+ *
+ * $return->value will contain an associative array with members as follows:
+ * new: Boolean indicating if the function attempted to create a new article
+ * revision: The revision object for the inserted revision, or null
+ *
+ * Compatibility note: this function previously returned a boolean value indicating success/failure
*/
- function doEdit( $text, $summary, $flags = 0, $baseRevId = false ) {
+ function doEdit( $text, $summary, $flags = 0, $baseRevId = false, $user = null ) {
global $wgUser, $wgDBtransactions, $wgUseAutomaticEditSummaries;
+ # Low-level sanity check
+ if( $this->mTitle->getText() == '' ) {
+ throw new MWException( 'Something is trying to edit an article with an empty title' );
+ }
+
wfProfileIn( __METHOD__ );
- $good = true;
+
+ if ($user == null) {
+ $user = $wgUser;
+ }
+ $status = Status::newGood( array() );
+
+ # Load $this->mTitle->getArticleID() and $this->mLatest if it's not already
+ $this->loadPageData();
if ( !($flags & EDIT_NEW) && !($flags & EDIT_UPDATE) ) {
- $aid = $this->mTitle->getArticleID( GAID_FOR_UPDATE );
+ $aid = $this->mTitle->getArticleID();
if ( $aid ) {
$flags |= EDIT_UPDATE;
} else {
}
}
- if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
+ if( !wfRunHooks( 'ArticleSave', array( &$this, &$user, &$text,
&$summary, $flags & EDIT_MINOR,
- null, null, &$flags ) ) )
+ null, null, &$flags, &$status ) ) )
{
wfDebug( __METHOD__ . ": ArticleSave hook aborted save!\n" );
wfProfileOut( __METHOD__ );
- return false;
+ if ( $status->isOK() ) {
+ $status->fatal( 'edit-hook-aborted');
+ }
+ return $status;
}
# Silently ignore EDIT_MINOR if not allowed
- $isminor = ( $flags & EDIT_MINOR ) && $wgUser->isAllowed('minoredit');
+ $isminor = ( $flags & EDIT_MINOR ) && $user->isAllowed('minoredit');
$bot = $flags & EDIT_FORCE_BOT;
$oldtext = $this->getContent();
if ( $flags & EDIT_UPDATE ) {
# Update article, but only if changed.
+ $status->value['new'] = false;
# Make sure the revision is either completely inserted or not inserted at all
if( !$wgDBtransactions ) {
$userAbort = ignore_user_abort( true );
}
- $lastRevision = 0;
$revisionId = 0;
$changed = ( strcmp( $text, $oldtext ) != 0 );
- (int)$this->isCountable( $oldtext );
$this->mTotalAdjustment = 0;
- $lastRevision = $dbw->selectField(
- 'page', 'page_latest', array( 'page_id' => $this->getId() ) );
-
- if ( !$lastRevision ) {
+ if ( !$this->mLatest ) {
# Article gone missing
wfDebug( __METHOD__.": EDIT_UPDATE specified but article doesn't exist\n" );
+ $status->fatal( 'edit-gone-missing' );
wfProfileOut( __METHOD__ );
- return false;
+ return $status;
}
$revision = new Revision( array(
'comment' => $summary,
'minor_edit' => $isminor,
'text' => $text,
- 'parent_id' => $lastRevision
+ 'parent_id' => $this->mLatest,
+ 'user' => $user->getId(),
+ 'user_text' => $user->getName(),
) );
$dbw->begin();
$revisionId = $revision->insertOn( $dbw );
# Update page
- $ok = $this->updateRevisionOn( $dbw, $revision, $lastRevision );
+ #
+ # Note that we use $this->mLatest instead of fetching a value from the master DB
+ # during the course of this function. This makes sure that EditPage can detect
+ # edit conflicts reliably, either by $ok here, or by $article->getTimestamp()
+ # before this function is called. A previous function used a separate query, this
+ # creates a window where concurrent edits can cause an ignored edit conflict.
+ $ok = $this->updateRevisionOn( $dbw, $revision, $this->mLatest );
if( !$ok ) {
/* Belated edit conflict! Run away!! */
- $good = false;
+ $status->fatal( 'edit-conflict' );
+ # Delete the invalid revision if the DB is not transactional
+ if ( !$wgDBtransactions ) {
+ $dbw->delete( 'revision', array( 'rev_id' => $revisionId ), __METHOD__ );
+ }
+ $revisionId = 0;
$dbw->rollback();
} else {
wfRunHooks( 'NewRevisionFromEditComplete', array( $this, $revision, $baseRevId ) );
# Update recentchanges
if( !( $flags & EDIT_SUPPRESS_RC ) ) {
- $rcid = RecentChange::notifyEdit( $now, $this->mTitle, $isminor, $wgUser, $summary,
- $lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
+ $rc = RecentChange::notifyEdit( $now, $this->mTitle, $isminor, $user, $summary,
+ $this->mLatest, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
$revisionId );
# Mark as patrolled if the user can do so
- if( $GLOBALS['wgUseRCPatrol'] && $wgUser->isAllowed( 'autopatrol' ) ) {
- RecentChange::markPatrolled( $rcid );
- PatrolLog::record( $rcid, true );
+ if( $GLOBALS['wgUseRCPatrol'] && $user->isAllowed( 'autopatrol' ) ) {
+ RecentChange::markPatrolled( $rc, true );
}
}
- $wgUser->incEditCount();
+ $user->incEditCount();
$dbw->commit();
}
} else {
+ $status->warning( 'edit-no-change' );
$revision = null;
// Keep the same revision ID, but do some updates on it
$revisionId = $this->getRevIdFetched();
if( !$wgDBtransactions ) {
ignore_user_abort( $userAbort );
}
-
- if ( $good ) {
- # Invalidate cache of this article and all pages using this article
- # as a template. Partly deferred.
- Article::onArticleEdit( $this->mTitle );
-
- # Update links tables, site stats, etc.
- $this->editUpdates( $text, $summary, $isminor, $now, $revisionId, $changed );
+ // Now that ignore_user_abort is restored, we can respond to fatal errors
+ if ( !$status->isOK() ) {
+ wfProfileOut( __METHOD__ );
+ return $status;
}
+
+ # Invalidate cache of this article and all pages using this article
+ # as a template. Partly deferred.
+ Article::onArticleEdit( $this->mTitle, false ); // leave templatelinks for editUpdates()
+ # Update links tables, site stats, etc.
+ $this->editUpdates( $text, $summary, $isminor, $now, $revisionId, $changed );
} else {
# Create new article
+ $status->value['new'] = true;
# Set statistics members
# We work out if it's countable after PST to avoid counter drift
$dbw->begin();
# Add the page record; stake our claim on this title!
- # This will fail with a database query exception if the article already exists
+ # This will return false if the article already exists
$newid = $this->insertOn( $dbw );
+ if ( $newid === false ) {
+ $dbw->rollback();
+ $status->fatal( 'edit-already-exists' );
+ wfProfileOut( __METHOD__ );
+ return $status;
+ }
+
# Save the revision text...
$revision = new Revision( array(
'page' => $newid,
'comment' => $summary,
'minor_edit' => $isminor,
- 'text' => $text
+ 'text' => $text,
+ 'user' => $user->getId(),
+ 'user_text' => $user->getName(),
) );
$revisionId = $revision->insertOn( $dbw );
wfRunHooks( 'NewRevisionFromEditComplete', array($this, $revision, false) );
if( !( $flags & EDIT_SUPPRESS_RC ) ) {
- $rcid = RecentChange::notifyNew( $now, $this->mTitle, $isminor, $wgUser, $summary, $bot,
+ $rc = RecentChange::notifyNew( $now, $this->mTitle, $isminor, $user, $summary, $bot,
'', strlen( $text ), $revisionId );
# Mark as patrolled if the user can
- if( ($GLOBALS['wgUseRCPatrol'] || $GLOBALS['wgUseNPPatrol']) && $wgUser->isAllowed( 'autopatrol' ) ) {
- RecentChange::markPatrolled( $rcid );
- PatrolLog::record( $rcid, true );
+ if( ($GLOBALS['wgUseRCPatrol'] || $GLOBALS['wgUseNPPatrol']) && $user->isAllowed( 'autopatrol' ) ) {
+ RecentChange::markPatrolled( $rc, true );
}
}
- $wgUser->incEditCount();
+ $user->incEditCount();
$dbw->commit();
# Update links, etc.
# Clear caches
Article::onArticleCreate( $this->mTitle );
- wfRunHooks( 'ArticleInsertComplete', array( &$this, &$wgUser, $text, $summary,
- $flags & EDIT_MINOR, null, null, &$flags, $revision ) );
+ wfRunHooks( 'ArticleInsertComplete', array( &$this, &$user, $text, $summary,
+ $flags & EDIT_MINOR, null, null, &$flags, $revision ) );
}
- if ( $good && !( $flags & EDIT_DEFER_UPDATES ) ) {
+ # Do updates right now unless deferral was requested
+ if ( !( $flags & EDIT_DEFER_UPDATES ) ) {
wfDoUpdates();
}
- if ( $good ) {
- wfRunHooks( 'ArticleSaveComplete', array( &$this, &$wgUser, $text, $summary,
- $flags & EDIT_MINOR, null, null, &$flags, $revision ) );
- }
+ // Return the new revision (or null) to the caller
+ $status->value['revision'] = $revision;
+
+ wfRunHooks( 'ArticleSaveComplete', array( &$this, &$user, $text, $summary,
+ $flags & EDIT_MINOR, null, null, &$flags, $revision, &$status ) );
wfProfileOut( __METHOD__ );
- return $good;
+ return $status;
}
/**
global $wgOut, $wgRequest, $wgUseRCPatrol, $wgUseNPPatrol, $wgUser;
$wgOut->setRobotPolicy( 'noindex,nofollow' );
- # Check patrol config options
-
- if ( !($wgUseNPPatrol || $wgUseRCPatrol)) {
- $wgOut->showErrorPage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
- return;
- }
-
# If we haven't been given an rc_id value, we can't do anything
$rcid = (int) $wgRequest->getVal('rcid');
- $rc = $rcid ? RecentChange::newFromId($rcid) : null;
- if ( is_null ( $rc ) )
- {
+ $rc = RecentChange::newFromId($rcid);
+ if ( is_null($rc) ) {
$wgOut->showErrorPage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
return;
}
- if ( !$wgUseRCPatrol && $rc->getAttribute( 'rc_type' ) != RC_NEW) {
- // Only new pages can be patrolled if the general patrolling is off....???
- // @fixme -- is this necessary? Shouldn't we only bother controlling the
- // front end here?
- $wgOut->showErrorPage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
- return;
- }
+ #It would be nice to see where the user had actually come from, but for now just guess
+ $returnto = $rc->getAttribute( 'rc_type' ) == RC_NEW ? 'Newpages' : 'Recentchanges';
+ $return = Title::makeTitle( NS_SPECIAL, $returnto );
- # Check permissions
- $permission_errors = $this->mTitle->getUserPermissionsErrors( 'patrol', $wgUser );
+ $dbw = wfGetDB( DB_MASTER );
+ $errors = $rc->doMarkPatrolled();
- if (count($permission_errors)>0)
- {
- $wgOut->showPermissionsErrorPage( $permission_errors );
+ if ( in_array(array('rcpatroldisabled'), $errors) ) {
+ $wgOut->showErrorPage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
return;
}
-
- # Handle the 'MarkPatrolled' hook
- if( !wfRunHooks( 'MarkPatrolled', array( $rcid, &$wgUser, false ) ) ) {
+
+ if ( in_array(array('hookaborted'), $errors) ) {
+ // The hook itself has handled any output
return;
}
-
- #It would be nice to see where the user had actually come from, but for now just guess
- $returnto = $rc->getAttribute( 'rc_type' ) == RC_NEW ? 'Newpages' : 'Recentchanges';
- $return = Title::makeTitle( NS_SPECIAL, $returnto );
-
- # If it's left up to us, check that the user is allowed to patrol this edit
- # If the user has the "autopatrol" right, then we'll assume there are no
- # other conditions stopping them doing so
- if( !$wgUser->isAllowed( 'autopatrol' ) ) {
- $rc = RecentChange::newFromId( $rcid );
- # Graceful error handling, as we've done before here...
- # (If the recent change doesn't exist, then it doesn't matter whether
- # the user is allowed to patrol it or not; nothing is going to happen
- if( is_object( $rc ) && $wgUser->getName() == $rc->getAttribute( 'rc_user_text' ) ) {
- # The user made this edit, and can't patrol it
- # Tell them so, and then back off
- $wgOut->setPageTitle( wfMsg( 'markedaspatrollederror' ) );
- $wgOut->addWikiMsg( 'markedaspatrollederror-noautopatrol' );
- $wgOut->returnToMain( false, $return );
- return;
- }
+
+ if ( in_array(array('markedaspatrollederror-noautopatrol'), $errors) ) {
+ $wgOut->setPageTitle( wfMsg( 'markedaspatrollederror' ) );
+ $wgOut->addWikiMsg( 'markedaspatrollederror-noautopatrol' );
+ $wgOut->returnToMain( false, $return );
+ return;
}
- # Check that the revision isn't patrolled already
- # Prevents duplicate log entries
- if( !$rc->getAttribute( 'rc_patrolled' ) ) {
- # Mark the edit as patrolled
- RecentChange::markPatrolled( $rcid );
- PatrolLog::record( $rcid );
- wfRunHooks( 'MarkPatrolledComplete', array( &$rcid, &$wgUser, false ) );
+ if ( !empty($errors) ) {
+ $wgOut->showPermissionsErrorPage( $errors );
+ return;
}
# Inform the user
* @param string $reason
* @return bool true on success
*/
- function updateRestrictions( $limit = array(), $reason = '', $cascade = 0, $expiry = null ) {
+ function updateRestrictions( $limit = array(), $reason = '', $cascade = 0, $expiry = array() ) {
global $wgUser, $wgRestrictionTypes, $wgContLang;
$id = $this->mTitle->getArticleID();
return false;
}
- if (!$cascade) {
+ if( !$cascade ) {
$cascade = false;
}
# FIXME: Same limitations as described in ProtectionForm.php (line 37);
# we expect a single selection, but the schema allows otherwise.
$current = array();
- foreach( $wgRestrictionTypes as $action )
+ $updated = Article::flattenRestrictions( $limit );
+ $changed = false;
+ foreach( $wgRestrictionTypes as $action ) {
$current[$action] = implode( '', $this->mTitle->getRestrictions( $action ) );
+ $changed = ($changed || ($this->mTitle->mRestrictionsExpiry[$action] != $expiry[$action]) );
+ }
$current = Article::flattenRestrictions( $current );
- $updated = Article::flattenRestrictions( $limit );
- $changed = ( $current != $updated );
+ $changed = ($changed || ( $current != $updated ) );
$changed = $changed || ($updated && $this->mTitle->areRestrictionsCascading() != $cascade);
- $changed = $changed || ($updated && $this->mTitle->mRestrictionsExpiry != $expiry);
$protect = ( $updated != '' );
# If nothing's changed, do nothing
if( wfRunHooks( 'ArticleProtect', array( &$this, &$wgUser, $limit, $reason ) ) ) {
$dbw = wfGetDB( DB_MASTER );
-
- $encodedExpiry = Block::encodeExpiry($expiry, $dbw );
-
- $expiry_description = '';
- if ( $encodedExpiry != 'infinity' ) {
- $expiry_description = ' (' . wfMsgForContent( 'protect-expiring', $wgContLang->timeanddate( $expiry, false, false ) ).')';
- }
-
+
# Prepare a null revision to be added to the history
$modified = $current != '' && $protect;
- if ( $protect ) {
+ if( $protect ) {
$comment_type = $modified ? 'modifiedarticleprotection' : 'protectedarticle';
} else {
$comment_type = 'unprotectedarticle';
break;
}
}
-
- $cascade_description = '';
- if ($cascade) {
- $cascade_description = ' ['.wfMsg('protect-summary-cascade').']';
+ $cascade_description = '';
+ if( $cascade ) {
+ $cascade_description = ' ['.wfMsgForContent('protect-summary-cascade').']';
}
if( $reason )
$comment .= ": $reason";
- if( $protect )
- $comment .= " [$updated]";
- if ( $expiry_description && $protect )
- $comment .= "$expiry_description";
- if ( $cascade )
- $comment .= "$cascade_description";
+ $editComment = $comment;
+ $encodedExpiry = array();
+ $protect_description = '';
+ foreach( $limit as $action => $restrictions ) {
+ $encodedExpiry[$action] = Block::encodeExpiry($expiry[$action], $dbw );
+ if( $restrictions != '' ) {
+ $protect_description .= "[$action=$restrictions] (";
+ if( $encodedExpiry[$action] != 'infinity' ) {
+ $protect_description .= wfMsgForContent( 'protect-expiring',
+ $wgContLang->timeanddate( $expiry[$action], false, false ) );
+ } else {
+ $protect_description .= wfMsgForContent( 'protect-expiry-indefinite' );
+ }
+ $protect_description .= ') ';
+ }
+ }
+ $protect_description = trim($protect_description);
+
+ if( $protect_description && $protect )
+ $editComment .= " ($protect_description)";
+ if( $cascade )
+ $editComment .= "$cascade_description";
# Update restrictions table
foreach( $limit as $action => $restrictions ) {
if ($restrictions != '' ) {
$dbw->replace( 'page_restrictions', array(array('pr_page', 'pr_type')),
- array( 'pr_page' => $id, 'pr_type' => $action
- , 'pr_level' => $restrictions, 'pr_cascade' => $cascade ? 1 : 0
- , 'pr_expiry' => $encodedExpiry ), __METHOD__ );
+ array( 'pr_page' => $id,
+ 'pr_type' => $action,
+ 'pr_level' => $restrictions,
+ 'pr_cascade' => ($cascade && $action == 'edit') ? 1 : 0,
+ 'pr_expiry' => $encodedExpiry[$action] ), __METHOD__ );
} else {
$dbw->delete( 'page_restrictions', array( 'pr_page' => $id,
'pr_type' => $action ), __METHOD__ );
}
# Insert a null revision
- $nullRevision = Revision::newNullRevision( $dbw, $id, $comment, true );
+ $nullRevision = Revision::newNullRevision( $dbw, $id, $editComment, true );
$nullRevId = $nullRevision->insertOn( $dbw );
$latest = $this->getLatest();
# Update the protection log
$log = new LogPage( 'protect' );
if( $protect ) {
- $log->addEntry( $modified ? 'modify' : 'protect', $this->mTitle,
- trim( $reason . " [$updated]$cascade_description$expiry_description" ) );
+ $params = array($protect_description,$cascade ? 'cascade' : '');
+ $log->addEntry( $modified ? 'modify' : 'protect', $this->mTitle, trim( $reason), $params );
} else {
$log->addEntry( 'unprotect', $this->mTitle, $reason );
}
* Auto-generates a deletion reason
* @param bool &$hasHistory Whether the page has a history
*/
- public function generateReason(&$hasHistory)
- {
+ public function generateReason( &$hasHistory ) {
global $wgContLang;
- $dbw = wfGetDB(DB_MASTER);
+ $dbw = wfGetDB( DB_MASTER );
// Get the last revision
- $rev = Revision::newFromTitle($this->mTitle);
- if(is_null($rev))
+ $rev = Revision::newFromTitle( $this->mTitle );
+ if( is_null( $rev ) )
return false;
+
// Get the article's contents
$contents = $rev->getText();
$blank = false;
// If the page is blank, use the text from the previous revision,
// which can only be blank if there's a move/import/protect dummy revision involved
- if($contents == '')
- {
+ if( $contents == '' ) {
$prev = $rev->getPrevious();
- if($prev)
- {
+ if( $prev ) {
$contents = $prev->getText();
$blank = true;
}
// Find out if there was only one contributor
// Only scan the last 20 revisions
$limit = 20;
- $res = $dbw->select('revision', 'rev_user_text', array('rev_page' => $this->getID()), __METHOD__,
- array('LIMIT' => $limit));
- if($res === false)
+ $res = $dbw->select( 'revision', 'rev_user_text',
+ array( 'rev_page' => $this->getID() ), __METHOD__,
+ array( 'LIMIT' => $limit )
+ );
+ if( $res === false )
// This page has no revisions, which is very weird
return false;
- if($res->numRows() > 1)
+ if( $res->numRows() > 1 )
$hasHistory = true;
else
$hasHistory = false;
- $row = $dbw->fetchObject($res);
+ $row = $dbw->fetchObject( $res );
$onlyAuthor = $row->rev_user_text;
// Try to find a second contributor
foreach( $res as $row ) {
- if($row->rev_user_text != $onlyAuthor) {
+ if( $row->rev_user_text != $onlyAuthor ) {
$onlyAuthor = false;
break;
}
}
- $dbw->freeResult($res);
+ $dbw->freeResult( $res );
// Generate the summary with a '$1' placeholder
- if($blank) {
+ if( $blank ) {
// The current revision is blank and the one before is also
// blank. It's just not our lucky day
- $reason = wfMsgForContent('exbeforeblank', '$1');
+ $reason = wfMsgForContent( 'exbeforeblank', '$1' );
} else {
- if($onlyAuthor)
- $reason = wfMsgForContent('excontentauthor', '$1', $onlyAuthor);
+ if( $onlyAuthor )
+ $reason = wfMsgForContent( 'excontentauthor', '$1', $onlyAuthor );
else
- $reason = wfMsgForContent('excontent', '$1');
+ $reason = wfMsgForContent( 'excontent', '$1' );
}
// Replace newlines with spaces to prevent uglyness
- $contents = preg_replace("/[\n\r]/", ' ', $contents);
+ $contents = preg_replace( "/[\n\r]/", ' ', $contents );
// Calculate the maximum amount of chars to get
// Max content length = max comment length - length of the comment (excl. $1) - '...'
- $maxLength = 255 - (strlen($reason) - 2) - 3;
- $contents = $wgContLang->truncate($contents, $maxLength, '...');
+ $maxLength = 255 - (strlen( $reason ) - 2) - 3;
+ $contents = $wgContLang->truncate( $contents, $maxLength, '...' );
// Remove possible unfinished links
$contents = preg_replace( '/\[\[([^\]]*)\]?$/', '$1', $contents );
// Now replace the '$1' placeholder
* @return int approximate revision count
*/
function estimateRevisionCount() {
- $dbr = wfGetDB();
+ $dbr = wfGetDB( DB_SLAVE );
// For an exact count...
//return $dbr->selectField( 'revision', 'COUNT(*)',
// array( 'rev_page' => $this->getId() ), __METHOD__ );
} else {
$suppress = '';
}
+ $checkWatch = $wgUser->getBoolOption( 'watchdeletion' ) || $this->mTitle->userIsWatching();
- $form = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->mTitle->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
+ $form = Xml::openElement( 'form', array( 'method' => 'post',
+ 'action' => $this->mTitle->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
Xml::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
Xml::tags( 'legend', null, wfMsgExt( 'delete-legend', array( 'parsemag', 'escapenoentities' ) ) ) .
Xml::openElement( 'table' ) .
Xml::label( wfMsg( 'deleteotherreason' ), 'wpReason' ) .
"</td>
<td>" .
- Xml::input( 'wpReason', 60, $reason, array( 'type' => 'text', 'maxlength' => '255', 'tabindex' => '2', 'id' => 'wpReason' ) ) .
+ Xml::input( 'wpReason', 60, $reason, array( 'type' => 'text', 'maxlength' => '255',
+ 'tabindex' => '2', 'id' => 'wpReason' ) ) .
"</td>
</tr>
<tr>
<td></td>
<td>" .
- Xml::checkLabel( wfMsg( 'watchthis' ), 'wpWatch', 'wpWatch', $wgUser->getBoolOption( 'watchdeletion' ) || $this->mTitle->userIsWatching(), array( 'tabindex' => '3' ) ) .
+ Xml::checkLabel( wfMsg( 'watchthis' ), 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
"</td>
</tr>
$suppress
global $wgOut, $wgUser;
wfDebug( __METHOD__."\n" );
- $id = $this->getId();
+ $id = $this->mTitle->getArticleID( GAID_FOR_UPDATE );
$error = '';
- if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason, &$error))) {
- if ( $this->doDeleteArticle( $reason, $suppress ) ) {
+ if ( wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason, &$error)) ) {
+ if ( $this->doDeleteArticle( $reason, $suppress, $id ) ) {
$deleted = $this->mTitle->getPrefixedText();
$wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
* Deletes the article with database consistency, writes logs, purges caches
* Returns success
*/
- function doDeleteArticle( $reason, $suppress = false ) {
+ function doDeleteArticle( $reason, $suppress = false, $id = 0 ) {
global $wgUseSquid, $wgDeferredUpdateList;
global $wgUseTrackbacks;
$dbw = wfGetDB( DB_MASTER );
$ns = $this->mTitle->getNamespace();
$t = $this->mTitle->getDBkey();
- $id = $this->mTitle->getArticleID();
+ $id = $id ? $id : $this->mTitle->getArticleID( GAID_FOR_UPDATE );
if ( $t == '' || $id == 0 ) {
return false;
# Delete restrictions for it
$dbw->delete( 'page_restrictions', array ( 'pr_page' => $id ), __METHOD__ );
- # Fix category table counts
- $cats = array();
- $res = $dbw->select( 'categorylinks', 'cl_to',
- array( 'cl_from' => $id ), __METHOD__ );
- foreach( $res as $row ) {
- $cats []= $row->cl_to;
- }
- $this->updateCategoryCounts( array(), $cats );
-
# Now that it's safely backed up, delete it
$dbw->delete( 'page', array( 'page_id' => $id ), __METHOD__);
$ok = ( $dbw->affectedRows() > 0 ); // getArticleId() uses slave, could be laggy
# If using cleanup triggers, we can skip some manual deletes
if ( !$dbw->cleanupTriggers() ) {
-
# Clean up recentchanges entries...
$dbw->delete( 'recentchanges',
- array( 'rc_namespace' => $ns, 'rc_title' => $t, 'rc_type != '.RC_LOG ),
+ array( 'rc_type != '.RC_LOG, 'rc_cur_id' => $id ),
__METHOD__ );
}
- $dbw->commit();
# Clear caches
Article::onArticleDelete( $this->mTitle );
+
+ # Fix category table counts
+ $cats = array();
+ $res = $dbw->select( 'categorylinks', 'cl_to', array( 'cl_from' => $id ), __METHOD__ );
+ foreach( $res as $row ) {
+ $cats []= $row->cl_to;
+ }
+ $this->updateCategoryCounts( array(), $cats );
# Clear the cached article id so the interface doesn't act like we exist
$this->mTitle->resetArticleID( 0 );
# Make sure logging got through
$log->addEntry( 'delete', $this->mTitle, $reason, array() );
+
+ $dbw->commit();
return true;
}
# Check permissions
$errors = array_merge( $this->mTitle->getUserPermissionsErrors( 'edit', $wgUser ),
- $this->mTitle->getUserPermissionsErrors( 'rollback', $wgUser ) );
+ $this->mTitle->getUserPermissionsErrors( 'rollback', $wgUser ) );
if( !$wgUser->matchEditToken( $token, array( $this->mTitle->getPrefixedText(), $fromP ) ) )
$errors[] = array( 'sessionfailure' );
# Save
$flags = EDIT_UPDATE;
- if ($wgUser->isAllowed('minoredit'))
+ if( $wgUser->isAllowed('minoredit') )
$flags |= EDIT_MINOR;
if( $bot && ($wgUser->isAllowed('markbotedits') || $wgUser->isAllowed('bot')) )
$flags |= EDIT_FORCE_BOT;
- $this->doEdit( $target->getText(), $summary, $flags, $target->getId() );
+ # Actually store the edit
+ $status = $this->doEdit( $target->getText(), $summary, $flags, $target->getId() );
+ if ( !empty( $status->value['revision'] ) ) {
+ $revId = $status->value['revision']->getId();
+ } else {
+ $revId = false;
+ }
wfRunHooks( 'ArticleRollbackComplete', array( $this, $wgUser, $target ) );
'summary' => $summary,
'current' => $current,
'target' => $target,
+ 'newid' => $revId
);
return array();
}
$wgOut->rateLimited();
return;
}
- if( isset( $result[0][0] ) && ( $result[0][0] == 'alreadyrolled' || $result[0][0] == 'cantrollback' ) ){
+ if( isset( $result[0][0] ) && ( $result[0][0] == 'alreadyrolled' || $result[0][0] == 'cantrollback' ) ) {
$wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) );
$errArray = $result[0];
$errMsg = array_shift( $errArray );
if( isset( $details['current'] ) ){
$current = $details['current'];
if( $current->getComment() != '' ) {
- $wgOut->addWikiMsgArray( 'editcomment', array( $wgUser->getSkin()->formatComment( $current->getComment() ) ), array( 'replaceafter' ) );
+ $wgOut->addWikiMsgArray( 'editcomment', array(
+ $wgUser->getSkin()->formatComment( $current->getComment() ) ), array( 'replaceafter' ) );
}
}
return;
$current = $details['current'];
$target = $details['target'];
+ $newId = $details['newid'];
$wgOut->setPageTitle( wfMsg( 'actioncomplete' ) );
$wgOut->setRobotPolicy( 'noindex,nofollow' );
$old = $wgUser->getSkin()->userLink( $current->getUser(), $current->getUserText() )
$wgOut->returnToMain( false, $this->mTitle );
if( !$wgRequest->getBool( 'hidediff', false ) ) {
- $de = new DifferenceEngine( $this->mTitle, $current->getId(), 'next', false, true );
+ $de = new DifferenceEngine( $this->mTitle, $current->getId(), $newId, false, true );
$de->showDiff( '', '' );
}
}
/**
* Do standard deferred updates after page edit.
* Update links tables, site stats, search index and message cache.
+ * Purges pages that include this page if the text was changed here.
* Every 100th edit, prune the recent changes table.
*
* @private
}
# Update the links tables
- $u = new LinksUpdate( $this->mTitle, $editInfo->output );
+ $u = new LinksUpdate( $this->mTitle, $editInfo->output, false );
+ $u->setRecursiveTouch( $changed ); // refresh/invalidate including pages too
$u->doUpdate();
+
+ wfRunHooks( 'ArticleEditUpdates', array( &$this, &$editInfo, $changed ) );
if( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
if ( 0 == mt_rand( 0, 99 ) ) {
# load of user talk pages and piss people off, nor if it's a minor edit
# by a properly-flagged bot.
if( $this->mTitle->getNamespace() == NS_USER_TALK && $shortTitle != $wgUser->getTitleKey() && $changed
- && !($minoredit && $wgUser->isAllowed('nominornewtalk') ) ) {
- if (wfRunHooks('ArticleEditUpdateNewTalk', array(&$this)) ) {
- $other = User::newFromName( $shortTitle );
+ && !( $minoredit && $wgUser->isAllowed( 'nominornewtalk' ) ) ) {
+ if( wfRunHooks('ArticleEditUpdateNewTalk', array( &$this ) ) ) {
+ $other = User::newFromName( $shortTitle, false );
if ( !$other ) {
wfDebug( __METHOD__.": invalid username\n" );
} elseif( User::isIP( $shortTitle ) ) {
$r = "\n\t\t\t\t<div id=\"mw-{$infomsg}\">" . wfMsg( $infomsg, $td, $userlinks ) . "</div>\n" .
- "\n\t\t\t\t<div id=\"mw-revision-nav\">" . $cdel . wfMsg( 'revision-nav', $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>\n\t\t\t";
+ "\n\t\t\t\t<div id=\"mw-revision-nav\">" . $cdel . wfMsg( 'revision-nav', $prevdiff,
+ $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>\n\t\t\t";
$wgOut->setSubtitle( $r );
}
static $called = false;
if( $called ) {
wfDebug( "Article::tryFileCache(): called twice!?\n" );
- return;
+ return false;
}
$called = true;
- if($this->isFileCacheable()) {
+ if( $this->isFileCacheable() ) {
$touched = $this->mTouched;
$cache = new HTMLFileCache( $this->mTitle );
- if($cache->isFileCacheGood( $touched )) {
+ if( $cache->isFileCacheGood( $touched ) ) {
wfDebug( "Article::tryFileCache(): about to load file\n" );
$cache->loadFromFileCache();
return true;
} else {
wfDebug( "Article::tryFileCache(): not cacheable\n" );
}
+ return false;
}
/**
*/
function isFileCacheable() {
global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest, $wgLang, $wgContLang;
- $action = $wgRequest->getVal( 'action' );
- $oldid = $wgRequest->getVal( 'oldid' );
- $diff = $wgRequest->getVal( 'diff' );
- $redirect = $wgRequest->getVal( 'redirect' );
- $printable = $wgRequest->getVal( 'printable' );
- $page = $wgRequest->getVal( 'page' );
-
- //check for non-standard user language; this covers uselang,
- //and extensions for auto-detecting user language.
- $ulang = $wgLang->getCode();
- $clang = $wgContLang->getCode();
+ // Get all query values
+ $queryVals = $wgRequest->getValues();
+ foreach( $queryVals as $query => $val ) {
+ if( $query == 'title' || ($query == 'action' && $val == 'view') ) {
+ // Normal page view in query form
+ } else {
+ return false;
+ }
+ }
+ // Check for non-standard user language; this covers uselang,
+ // and extensions for auto-detecting user language.
+ $ulang = $wgLang->getCode();
+ $clang = $wgContLang->getCode();
$cacheable = $wgUseFileCache
&& (!$wgShowIPinHeader)
- && ($this->getID() != 0)
+ && ($this->getID() > 0)
&& ($wgUser->isAnon())
&& (!$wgUser->getNewtalk())
- && ($this->mTitle->getNamespace() != NS_SPECIAL )
- && (empty( $action ) || $action == 'view')
- && (!isset($oldid))
- && (!isset($diff))
- && (!isset($redirect))
- && (!isset($printable))
- && !isset($page)
&& (!$this->mRedirectedFrom)
&& ($ulang === $clang);
-
- if ( $cacheable ) {
- //extension may have reason to disable file caching on some pages.
- $cacheable = wfRunHooks( 'IsFileCacheable', array( $this ) );
+ // Extension may have reason to disable file caching on some pages.
+ if( $cacheable ) {
+ $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
}
-
return $cacheable;
}
wfProfileIn( __METHOD__ );
$dbw = wfGetDB( DB_MASTER );
- $dbw->begin();
$revision = new Revision( array(
'page' => $this->getId(),
'text' => $text,
) );
$revision->insertOn( $dbw );
$this->updateRevisionOn( $dbw, $revision );
- $dbw->commit();
wfRunHooks( 'NewRevisionFromEditComplete', array($this, $revision, false) );
* @param $title_obj a title object
*/
- static function onArticleCreate($title) {
- # The talk page isn't in the regular link tables, so we need to update manually:
+ public static function onArticleCreate( $title ) {
+ # Update existence markers on article/talk tabs...
if ( $title->isTalkPage() ) {
$other = $title->getSubjectPage();
} else {
$title->deleteTitleProtection();
}
- static function onArticleDelete( $title ) {
+ public static function onArticleDelete( $title ) {
global $wgUseFileCache, $wgMessageCache;
-
- // Update existence markers on article/talk tabs...
+ # Update existence markers on article/talk tabs...
if( $title->isTalkPage() ) {
$other = $title->getSubjectPage();
} else {
/**
* Purge caches on page update etc
*/
- static function onArticleEdit( $title ) {
+ public static function onArticleEdit( $title, $touchTemplates = true ) {
global $wgDeferredUpdateList, $wgUseFileCache;
// Invalidate caches of articles which include this page
- $wgDeferredUpdateList[] = new HTMLCacheUpdate( $title, 'templatelinks' );
+ if( $touchTemplates )
+ $wgDeferredUpdateList[] = new HTMLCacheUpdate( $title, 'templatelinks' );
// Invalidate the caches of all pages which redirect here
$wgDeferredUpdateList[] = new HTMLCacheUpdate( $title, 'redirect' );
# Purge squid for this page only
$title->purgeSquid();
- # Clear file cache
+ # Clear file cache for this page only
if ( $wgUseFileCache ) {
$cm = new HTMLFileCache( $title );
@unlink( $cm->fileCacheName() );
*
* @return array Array of Title objects
*/
- function getUsedTemplates() {
+ public function getUsedTemplates() {
$result = array();
$id = $this->mTitle->getArticleID();
if( $id == 0 ) {
*
* @return array Array of Title objects
*/
- function getHiddenCategories() {
+ public function getHiddenCategories() {
$result = array();
$id = $this->mTitle->getArticleID();
if( $id == 0 ) {
* @param bool $cache
*/
public function outputWikiText( $text, $cache = true ) {
- global $wgParser, $wgUser, $wgOut, $wgEnableParserCache;
+ global $wgParser, $wgUser, $wgOut, $wgEnableParserCache, $wgUseFileCache;
$popts = $wgOut->parserOptions();
$popts->setTidy(true);
$parserCache = ParserCache::singleton();
$parserCache->save( $parserOutput, $this, $wgUser );
}
+ // Make sure file cache is not used on uncacheable content.
+ // Output that has magic words in it can still use the parser cache
+ // (if enabled), though it will generally expire sooner.
+ if( $parserOutput->getCacheTime() == -1 || $parserOutput->containsOldMagic() ) {
+ $wgUseFileCache = false;
+ }
if ( !wfReadOnly() && $this->mTitle->areRestrictionsCascading() ) {
// templatelinks table may have become out of sync,
if ( count( $templates_diff ) > 0 ) {
# Whee, link updates time.
$u = new LinksUpdate( $this->mTitle, $parserOutput );
-
- $dbw = wfGetDb( DB_MASTER );
- $dbw->begin();
-
$u->doUpdate();
-
- $dbw->commit();
}
}