*/
/**
- * Abstract class for type hinting (accepts WikiPage, Article, ImagePage, CategoryPage)
+ * Interface for type hinting (accepts WikiPage, Article, ImagePage, CategoryPage)
*/
interface Page {
}
return false;
}
- /**
- * Get the text of the current revision. No side-effects...
- *
- * @return string|bool The text of the current revision. False on failure
- * @deprecated since 1.21, getContent() should be used instead.
- */
- public function getRawText() {
- ContentHandler::deprecated( __METHOD__, '1.21' );
-
- return $this->getText( Revision::RAW );
- }
-
/**
* @return string MW timestamp of last article revision
*/
return true;
}
+
/**
* Insert a new empty page record for this article.
* This *must* be followed up by creating a revision
* Best if all done inside a transaction.
*
* @param IDatabase $dbw
- * @return int|bool The newly created page_id key; false if the title already existed
+ * @param int|null $pageId Custom page ID that will be used for the insert statement
+ *
+ * @return bool|int The newly created page_id key; false if the title already existed
*/
- public function insertOn( $dbw ) {
+ public function insertOn( $dbw, $pageId = null ) {
+ $pageIdForInsert = $pageId ?: $dbw->nextSequenceValue( 'page_page_id_seq' );
$dbw->insert(
'page',
array(
- 'page_id' => $dbw->nextSequenceValue( 'page_page_id_seq' ),
+ 'page_id' => $pageIdForInsert,
'page_namespace' => $this->mTitle->getNamespace(),
'page_title' => $this->mTitle->getDBkey(),
'page_restrictions' => '',
);
if ( $dbw->affectedRows() > 0 ) {
- $newid = $dbw->insertId();
+ $newid = $pageId ?: $dbw->insertId();
$this->mId = $newid;
$this->mTitle->resetArticleID( $newid );
$revisionId = $revision->insertOn( $dbw );
// Update page_latest and friends to reflect the new revision
if ( !$this->updateRevisionOn( $dbw, $revision, null, $meta['oldIsRedirect'] ) ) {
- $dbw->rollback( __METHOD__ );
+ $dbw->rollback( __METHOD__ ); // sanity; this should never happen
throw new MWException( "Failed to update page row to use new revision." );
}
}
$dbw = wfGetDB( DB_MASTER );
- $dbw->begin( __METHOD__ );
+ $dbw->startAtomic( __METHOD__ );
// Add the page record unless one already exists for the title
$newid = $this->insertOn( $dbw );
if ( $newid === false ) {
- $dbw->commit( __METHOD__ ); // nothing inserted
+ $dbw->endAtomic( __METHOD__ ); // nothing inserted
$status->fatal( 'edit-already-exists' );
return $status; // nothing done
$revisionId = $revision->insertOn( $dbw );
// Update the page record with revision data
if ( !$this->updateRevisionOn( $dbw, $revision, 0 ) ) {
- $dbw->rollback( __METHOD__ );
+ $dbw->rollback( __METHOD__ ); // sanity; this should never happen
throw new MWException( "Failed to update page row to use new revision." );
}
$user->incEditCount();
- $dbw->commit( __METHOD__ );
+ $dbw->endAtomic( __METHOD__ );
$this->mTimestamp = $now;
- // Update links, etc.
- $this->doEditUpdates( $revision, $user, array( 'created' => true ) );
-
- $hook_args = array( &$this, &$user, $content, $summary,
- $flags & EDIT_MINOR, null, null, &$flags, $revision );
- ContentHandler::runLegacyHooks( 'ArticleInsertComplete', $hook_args );
- Hooks::run( 'PageContentInsertComplete', $hook_args );
-
// Return the new revision to the caller
$status->value['revision'] = $revision;
- // Trigger post-save hook
- $hook_args = array( &$this, &$user, $content, $summary,
- $flags & EDIT_MINOR, null, null, &$flags, $revision, &$status, $meta['baseRevId'] );
- ContentHandler::runLegacyHooks( 'ArticleSaveComplete', $hook_args );
- Hooks::run( 'PageContentSaveComplete', $hook_args );
+ // Do secondary updates once the main changes have been committed...
+ $that = $this;
+ $dbw->onTransactionIdle(
+ function () use (
+ &$that, $dbw, $revision, &$user, $content, $summary, &$flags, $meta, &$status
+ ) {
+ // Do per-page updates in a transaction
+ $dbw->setFlag( DBO_TRX );
+ // Update links, etc.
+ $that->doEditUpdates( $revision, $user, array( 'created' => true ) );
+ // Trigger post-create hook
+ $params = array( &$that, &$user, $content, $summary,
+ $flags & EDIT_MINOR, null, null, &$flags, $revision );
+ ContentHandler::runLegacyHooks( 'ArticleInsertComplete', $params );
+ Hooks::run( 'PageContentInsertComplete', $params );
+ // Trigger post-save hook
+ $params = array_merge( $params, array( &$status, $meta['baseRevId'] ) );
+ ContentHandler::runLegacyHooks( 'ArticleSaveComplete', $params );
+ Hooks::run( 'PageContentSaveComplete', $params );
+
+ }
+ );
return $status;
}
}
}
- /**
- * This function is called right before saving the wikitext,
- * so we can do things like signatures and links-in-context.
- *
- * @deprecated since 1.19; use Parser::preSaveTransform() instead
- * @param string $text Article contents
- * @param User $user User doing the edit
- * @param ParserOptions $popts Parser options, default options for
- * the user loaded if null given
- * @return string Article contents with altered wikitext markup (signatures
- * converted, {{subst:}}, templates, etc.)
- */
- public function preSaveTransform( $text, User $user = null, ParserOptions $popts = null ) {
- global $wgParser, $wgUser;
-
- wfDeprecated( __METHOD__, '1.19' );
-
- $user = is_null( $user ) ? $wgUser : $user;
-
- if ( $popts === null ) {
- $popts = ParserOptions::newFromUser( $user );
- }
-
- return $wgParser->preSaveTransform( $text, $this->mTitle, $user, $popts );
- }
-
- /**
- * Update the article's restriction field, and leave a log entry.
- *
- * @deprecated since 1.19
- * @param array $limit Set of restriction keys
- * @param string $reason
- * @param int &$cascade Set to false if cascading protection isn't allowed.
- * @param array $expiry Per restriction type expiration
- * @param User $user The user updating the restrictions
- * @return bool True on success
- */
- public function updateRestrictions(
- $limit = array(), $reason = '', &$cascade = 0, $expiry = array(), User $user = null
- ) {
- global $wgUser;
-
- $user = is_null( $user ) ? $wgUser : $user;
-
- return $this->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user )->isOK();
- }
-
/**
* Returns a list of updates to be performed when this page is deleted. The
* updates should remove any information about this page from secondary data