/**
* Create a WikiPage object of the appropriate class for the given title.
*
- * @param $title Title
+ * @param Title $title
+ *
* @throws MWException
- * @return WikiPage object of the appropriate type
+ * @return WikiPage Object of the appropriate type
*/
public static function factory( Title $title ) {
$ns = $title->getNamespace();
* @param $user User object to check for, only if FOR_THIS_USER is passed
* to the $audience parameter
* @return String|false The text of the current revision
- * @deprecated as of 1.21, getContent() should be used instead.
+ * @deprecated since 1.21, getContent() should be used instead.
*/
public function getText( $audience = Revision::FOR_PUBLIC, User $user = null ) { // @todo deprecated, replace usage!
ContentHandler::deprecated( __METHOD__, '1.21' );
* Get the text of the current revision. No side-effects...
*
* @return String|bool The text of the current revision. False on failure
- * @deprecated as of 1.21, getContent() should be used instead.
+ * @deprecated since 1.21, getContent() should be used instead.
*/
public function getRawText() {
ContentHandler::deprecated( __METHOD__, '1.21' );
}
/**
- * @param $section null|bool|int or a section number (0, 1, 2, T1, T2...)
- * @param string $text new text of the section
- * @param string $sectionTitle new section's subject, only if $section is 'new'
- * @param string $edittime revision timestamp or null to use the current revision
+ * @param mixed $section Null/false, a section number (0, 1, 2, T1, T2, ...) or "new".
+ * @param string $text New text of the section.
+ * @param string $sectionTitle New section's subject, only if $section is "new".
+ * @param string $edittime Revision timestamp or null to use the current revision.
+ *
* @throws MWException
- * @return String new complete article text, or null if error
+ * @return string New complete article text, or null if error.
*
* @deprecated since 1.21, use replaceSectionContent() instead
*/
}
if ( !$this->supportsSections() ) {
- throw new MWException( "sections not supported for content model " . $this->getContentHandler()->getModelID() );
+ throw new MWException( "sections not supported for content model " .
+ $this->getContentHandler()->getModelID() );
}
// could even make section title, but that's not required.
$sectionContent = ContentHandler::makeContent( $text, $this->getTitle() );
- $newContent = $this->replaceSectionContent( $section, $sectionContent, $sectionTitle, $edittime );
+ $newContent = $this->replaceSectionContent( $section, $sectionContent, $sectionTitle,
+ $edittime );
return ContentHandler::getContentText( $newContent );
}
/**
* Returns true if this page's content model supports sections.
*
- * @return boolean whether sections are supported.
+ * @return bool
*
* @todo The skin should check this and not offer section functionality if sections are not supported.
* @todo The EditPage should check this and not offer section functionality if sections are not supported.
}
/**
- * @param $section null|bool|int or a section number (0, 1, 2, T1, T2...)
- * @param $sectionContent Content: new content of the section
- * @param string $sectionTitle new section's subject, only if $section is 'new'
- * @param string $edittime revision timestamp or null to use the current revision
+ * @param mixed $section Null/false, a section number (0, 1, 2, T1, T2, ...) or "new".
+ * @param Content $sectionContent New content of the section.
+ * @param string $sectionTitle New section's subject, only if $section is "new".
+ * @param string $edittime Revision timestamp or null to use the current revision.
*
* @throws MWException
- * @return Content new complete article content, or null if error
+ * @return Content New complete article content, or null if error.
*
* @since 1.21
*/
- public function replaceSectionContent( $section, Content $sectionContent, $sectionTitle = '', $edittime = null ) {
+ public function replaceSectionContent( $section, Content $sectionContent, $sectionTitle = '',
+ $edittime = null ) {
wfProfileIn( __METHOD__ );
if ( strval( $section ) == '' ) {
} else {
if ( !$this->supportsSections() ) {
wfProfileOut( __METHOD__ );
- throw new MWException( "sections not supported for content model " . $this->getContentHandler()->getModelID() );
+ throw new MWException( "sections not supported for content model " .
+ $this->getContentHandler()->getModelID() );
}
// Bug 30711: always use current version when adding a new section
}
$dbw->begin( __METHOD__ );
+ try {
- $prepStatus = $content->prepareSave( $this, $flags, $baseRevId, $user );
- $status->merge( $prepStatus );
-
- if ( !$status->isOK() ) {
- $dbw->rollback( __METHOD__ );
+ $prepStatus = $content->prepareSave( $this, $flags, $baseRevId, $user );
+ $status->merge( $prepStatus );
- wfProfileOut( __METHOD__ );
- return $status;
- }
+ if ( !$status->isOK() ) {
+ $dbw->rollback( __METHOD__ );
- $revisionId = $revision->insertOn( $dbw );
+ wfProfileOut( __METHOD__ );
+ return $status;
+ }
+ $revisionId = $revision->insertOn( $dbw );
- // Update page
- //
- // 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, $oldid, $oldIsRedirect );
+ // Update page
+ //
+ // 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, $oldid, $oldIsRedirect );
- if ( !$ok ) {
- // Belated edit conflict! Run away!!
- $status->fatal( 'edit-conflict' );
+ if ( !$ok ) {
+ // Belated edit conflict! Run away!!
+ $status->fatal( 'edit-conflict' );
- $dbw->rollback( __METHOD__ );
+ $dbw->rollback( __METHOD__ );
- wfProfileOut( __METHOD__ );
- return $status;
- }
+ wfProfileOut( __METHOD__ );
+ return $status;
+ }
- wfRunHooks( 'NewRevisionFromEditComplete', array( $this, $revision, $baseRevId, $user ) );
- // Update recentchanges
- if ( !( $flags & EDIT_SUPPRESS_RC ) ) {
- // Mark as patrolled if the user can do so
- $patrolled = $wgUseRCPatrol && !count(
+ wfRunHooks( 'NewRevisionFromEditComplete', array( $this, $revision, $baseRevId, $user ) );
+ // Update recentchanges
+ if ( !( $flags & EDIT_SUPPRESS_RC ) ) {
+ // Mark as patrolled if the user can do so
+ $patrolled = $wgUseRCPatrol && !count(
$this->mTitle->getUserPermissionsErrors( 'autopatrol', $user ) );
- // Add RC row to the DB
- $rc = RecentChange::notifyEdit( $now, $this->mTitle, $isminor, $user, $summary,
- $oldid, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
- $revisionId, $patrolled
- );
+ // Add RC row to the DB
+ $rc = RecentChange::notifyEdit( $now, $this->mTitle, $isminor, $user, $summary,
+ $oldid, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
+ $revisionId, $patrolled
+ );
- // Log auto-patrolled edits
- if ( $patrolled ) {
- PatrolLog::record( $rc, true, $user );
+ // Log auto-patrolled edits
+ if ( $patrolled ) {
+ PatrolLog::record( $rc, true, $user );
+ }
}
+ $user->incEditCount();
+ } catch ( MWException $e ) {
+ $dbw->rollback( __METHOD__ );
+ // Question: Would it perhaps be better if this method turned all
+ // exceptions into $status's?
+ throw $e;
}
- $user->incEditCount();
$dbw->commit( __METHOD__ );
} else {
// Bug 32948: revision ID must be set to page {{REVISIONID}} and
$status->value['new'] = true;
$dbw->begin( __METHOD__ );
+ try {
- $prepStatus = $content->prepareSave( $this, $flags, $baseRevId, $user );
- $status->merge( $prepStatus );
+ $prepStatus = $content->prepareSave( $this, $flags, $baseRevId, $user );
+ $status->merge( $prepStatus );
- if ( !$status->isOK() ) {
- $dbw->rollback( __METHOD__ );
+ if ( !$status->isOK() ) {
+ $dbw->rollback( __METHOD__ );
- wfProfileOut( __METHOD__ );
- return $status;
- }
+ wfProfileOut( __METHOD__ );
+ return $status;
+ }
- $status->merge( $prepStatus );
+ $status->merge( $prepStatus );
- // Add the page record; stake our claim on this title!
- // This will return false if the article already exists
- $newid = $this->insertOn( $dbw );
+ // Add the page record; stake our claim on this title!
+ // This will return false if the article already exists
+ $newid = $this->insertOn( $dbw );
- if ( $newid === false ) {
- $dbw->rollback( __METHOD__ );
- $status->fatal( 'edit-already-exists' );
+ if ( $newid === false ) {
+ $dbw->rollback( __METHOD__ );
+ $status->fatal( 'edit-already-exists' );
- wfProfileOut( __METHOD__ );
- return $status;
- }
+ wfProfileOut( __METHOD__ );
+ return $status;
+ }
- // Save the revision text...
- $revision = new Revision( array(
- 'page' => $newid,
- 'title' => $this->getTitle(), // for determining the default content model
- 'comment' => $summary,
- 'minor_edit' => $isminor,
- 'text' => $serialized,
- 'len' => $newsize,
- 'user' => $user->getId(),
- 'user_text' => $user->getName(),
- 'timestamp' => $now,
- 'content_model' => $content->getModel(),
- 'content_format' => $serialisation_format,
- ) );
- $revisionId = $revision->insertOn( $dbw );
+ // Save the revision text...
+ $revision = new Revision( array(
+ 'page' => $newid,
+ 'title' => $this->getTitle(), // for determining the default content model
+ 'comment' => $summary,
+ 'minor_edit' => $isminor,
+ 'text' => $serialized,
+ 'len' => $newsize,
+ 'user' => $user->getId(),
+ 'user_text' => $user->getName(),
+ 'timestamp' => $now,
+ 'content_model' => $content->getModel(),
+ 'content_format' => $serialisation_format,
+ ) );
+ $revisionId = $revision->insertOn( $dbw );
- // Bug 37225: use accessor to get the text as Revision may trim it
- $content = $revision->getContent(); // sanity; get normalized version
+ // Bug 37225: use accessor to get the text as Revision may trim it
+ $content = $revision->getContent(); // sanity; get normalized version
- if ( $content ) {
- $newsize = $content->getSize();
- }
+ if ( $content ) {
+ $newsize = $content->getSize();
+ }
- // Update the page record with revision data
- $this->updateRevisionOn( $dbw, $revision, 0 );
+ // Update the page record with revision data
+ $this->updateRevisionOn( $dbw, $revision, 0 );
- wfRunHooks( 'NewRevisionFromEditComplete', array( $this, $revision, false, $user ) );
+ wfRunHooks( 'NewRevisionFromEditComplete', array( $this, $revision, false, $user ) );
- // Update recentchanges
- if ( !( $flags & EDIT_SUPPRESS_RC ) ) {
- // Mark as patrolled if the user can do so
- $patrolled = ( $wgUseRCPatrol || $wgUseNPPatrol ) && !count(
- $this->mTitle->getUserPermissionsErrors( 'autopatrol', $user ) );
- // Add RC row to the DB
- $rc = RecentChange::notifyNew( $now, $this->mTitle, $isminor, $user, $summary, $bot,
- '', $newsize, $revisionId, $patrolled );
+ // Update recentchanges
+ if ( !( $flags & EDIT_SUPPRESS_RC ) ) {
+ // Mark as patrolled if the user can do so
+ $patrolled = ( $wgUseRCPatrol || $wgUseNPPatrol ) && !count(
+ $this->mTitle->getUserPermissionsErrors( 'autopatrol', $user ) );
+ // Add RC row to the DB
+ $rc = RecentChange::notifyNew( $now, $this->mTitle, $isminor, $user, $summary, $bot,
+ '', $newsize, $revisionId, $patrolled );
- // Log auto-patrolled edits
- if ( $patrolled ) {
- PatrolLog::record( $rc, true, $user );
+ // Log auto-patrolled edits
+ if ( $patrolled ) {
+ PatrolLog::record( $rc, true, $user );
+ }
}
+ $user->incEditCount();
+
+ } catch ( MWException $e ) {
+ $dbw->rollback( __METHOD__ );
+ throw $e;
}
- $user->incEditCount();
$dbw->commit( __METHOD__ );
// Update links, etc.
* Prepare text which is about to be saved.
* Returns a stdclass with source, pst and output members
*
- * @deprecated in 1.21: use prepareContentForEdit instead.
+ * @deprecated since 1.21: use prepareContentForEdit instead.
*/
public function prepareTextForEdit( $text, $revid = null, User $user = null ) {
ContentHandler::deprecated( __METHOD__, '1.21' );
$edit = (object)array();
$edit->revid = $revid;
+ $edit->timestamp = wfTimestampNow();
$edit->pstContent = $content ? $content->preSaveTransform( $this->mTitle, $user, $popts ) : null;
// Save it to the parser cache
if ( $wgEnableParserCache ) {
$parserCache = ParserCache::singleton();
- $parserCache->save( $editInfo->output, $this, $editInfo->popts );
+ $parserCache->save(
+ $editInfo->output, $this, $editInfo->popts, $editInfo->timestamp, $editInfo->revid
+ );
}
// Update the links tables and other secondary data
/**
* Take an array of page restrictions and flatten it to a string
* suitable for insertion into the page_restrictions field.
- * @param $limit Array
+ *
+ * @param string[] $limit
+ *
* @throws MWException
- * @return String
+ * @return string
*/
protected static function flattenRestrictions( $limit ) {
if ( !is_array( $limit ) ) {
return array( array( 'notvisiblerev' ) );
}
+ // Set patrolling and bot flag on the edits, which gets rollbacked.
+ // This is done before the rollback edit to have patrolling also on failure (bug 62157).
+ $set = array();
+ if ( $bot && $guser->isAllowed( 'markbotedits' ) ) {
+ // Mark all reverted edits as bot
+ $set['rc_bot'] = 1;
+ }
+
+ if ( $wgUseRCPatrol ) {
+ // Mark all reverted edits as patrolled
+ $set['rc_patrolled'] = 1;
+ }
+
+ if ( count( $set ) ) {
+ $dbw->update( 'recentchanges', $set,
+ array( /* WHERE */
+ 'rc_cur_id' => $current->getPage(),
+ 'rc_user_text' => $current->getUserText(),
+ 'rc_timestamp > ' . $dbw->addQuotes( $s->rev_timestamp ),
+ ), __METHOD__
+ );
+ }
+
// Generate the edit summary if necessary
$target = Revision::newFromId( $s->rev_id );
if ( empty( $summary ) ) {
) );
}
- $set = array();
- if ( $bot && $guser->isAllowed( 'markbotedits' ) ) {
- // Mark all reverted edits as bot
- $set['rc_bot'] = 1;
- }
-
- if ( $wgUseRCPatrol ) {
- // Mark all reverted edits as patrolled
- $set['rc_patrolled'] = 1;
- }
-
- if ( count( $set ) ) {
- $dbw->update( 'recentchanges', $set,
- array( /* WHERE */
- 'rc_cur_id' => $current->getPage(),
- 'rc_user_text' => $current->getUserText(),
- 'rc_timestamp > ' . $dbw->addQuotes( $s->rev_timestamp ),
- ), __METHOD__
- );
- }
-
$revId = $status->value['revision']->getId();
wfRunHooks( 'ArticleRollbackComplete', array( $this, $guser, $target, $current ) );
* Return a list of templates used by this article.
* Uses the templatelinks table
*
- * @deprecated in 1.19; use Title::getTemplateLinksFrom()
+ * @deprecated since 1.19; use Title::getTemplateLinksFrom()
* @return Array of Title objects
*/
public function getUsedTemplates() {
* This function is called right before saving the wikitext,
* so we can do things like signatures and links-in-context.
*
- * @deprecated in 1.19; use Parser::preSaveTransform() instead
+ * @deprecated since 1.19; use Parser::preSaveTransform() instead
* @param string $text article contents
* @param $user User object: user doing the edit
* @param $popts ParserOptions object: parser options, default options for
/**
* Check whether the number of revisions of this page surpasses $wgDeleteRevisionsLimit
*
- * @deprecated in 1.19; use Title::isBigDeletion() instead.
+ * @deprecated since 1.19; use Title::isBigDeletion() instead.
* @return bool
*/
public function isBigDeletion() {
/**
* Get the approximate revision count of this page.
*
- * @deprecated in 1.19; use Title::estimateRevisionCount() instead.
+ * @deprecated since 1.19; use Title::estimateRevisionCount() instead.
* @return int
*/
public function estimateRevisionCount() {
$this->page->getTitle()->getPrefixedDBkey() ) );
}
- if ( $this->cacheable && $this->parserOutput->isCacheable() ) {
+ if ( $this->cacheable && $this->parserOutput->isCacheable() && $isCurrent ) {
ParserCache::singleton()->save(
- $this->parserOutput, $this->page, $this->parserOptions, $cacheTime );
+ $this->parserOutput, $this->page, $this->parserOptions, $cacheTime, $this->revid );
}
// Make sure file cache is not used on uncacheable content.