X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fpage%2FWikiPage.php;h=b7eef8faa36f8d7d022ac9f4750f87580364449d;hb=e95da15372e7743ea1d635092bdef456c43888de;hp=6267406897dc24830d1912acd4967f90fafc8e33;hpb=0a5d2b3c69a2daab2008b0fbc604cae001b269de;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php index 6267406897..b7eef8faa3 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -21,7 +21,7 @@ */ /** - * Abstract class for type hinting (accepts WikiPage, Article, ImagePage, CategoryPage) + * Interface for type hinting (accepts WikiPage, Article, ImagePage, CategoryPage) */ interface Page { } @@ -687,18 +687,6 @@ class WikiPage implements Page, IDBAccessObject { 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 */ @@ -1158,6 +1146,7 @@ class WikiPage implements Page, IDBAccessObject { return true; } + /** * Insert a new empty page record for this article. * This *must* be followed up by creating a revision @@ -1166,13 +1155,16 @@ class WikiPage implements Page, IDBAccessObject { * 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' => '', @@ -1188,7 +1180,7 @@ class WikiPage implements Page, IDBAccessObject { ); if ( $dbw->affectedRows() > 0 ) { - $newid = $dbw->insertId(); + $newid = $pageId ?: $dbw->insertId(); $this->mId = $newid; $this->mTitle->resetArticleID( $newid ); @@ -1831,7 +1823,7 @@ class WikiPage implements Page, IDBAccessObject { $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." ); } @@ -1929,12 +1921,12 @@ class WikiPage implements Page, IDBAccessObject { } $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 @@ -1964,7 +1956,7 @@ class WikiPage implements Page, IDBAccessObject { $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." ); } @@ -1992,25 +1984,34 @@ class WikiPage implements Page, IDBAccessObject { $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; } @@ -3559,53 +3560,6 @@ class WikiPage implements Page, IDBAccessObject { } } - /** - * 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