From 147f79eedd24482d4c333e589fba418cba07a6fa Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 9 Jun 2016 23:22:45 -0700 Subject: [PATCH] Improvements to {{REVISIONUSER}} handling * Do not change the result to a null editing user anymore. * Use a new vary-user flag instead of vary-revision. This will only cause a reparse on null edits. Normal edits can still use the prepared output now. * Edit stashing now applies for pages with this magic word. * Fixed bug where the second prepareContentForEdit() call (due to vary-X flags) would still check the edit stash. Bug: T135261 Bug: T136678 Change-Id: Id1733443ac3bf053ca61e5ae25db3fbf4499e9f9 --- includes/Revision.php | 19 ++++++++++++++++++- includes/page/WikiPage.php | 31 ++++++++++++++++++++++--------- includes/parser/Parser.php | 6 +++--- 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/includes/Revision.php b/includes/Revision.php index 0e45b251c1..eda898916c 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -720,11 +720,28 @@ class Revision implements IDBAccessObject { /** * Set the revision ID * + * This should only be used for proposed revisions that turn out to be null edits + * * @since 1.19 * @param int $id */ public function setId( $id ) { - $this->mId = $id; + $this->mId = (int)$id; + } + + /** + * Set the user ID/name + * + * This should only be used for proposed revisions that turn out to be null edits + * + * @since 1.28 + * @param integer $id User ID + * @param string $name User name + */ + public function setUserIdAndName( $id, $name ) { + $this->mUser = (int)$id; + $this->mUserText = $name; + $this->mOrigUserText = $name; } /** diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php index a3c3ecee4a..8d9d5a8628 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -1794,8 +1794,12 @@ class WikiPage implements Page, IDBAccessObject { $this->mTimestamp = $now; } else { // Bug 32948: revision ID must be set to page {{REVISIONID}} and - // related variables correctly + // related variables correctly. Likewise for {{REVISIONUSER}} (T135261). $revision->setId( $this->getLatest() ); + $revision->setUserIdAndName( + $this->getUser( Revision::RAW ), + $this->getUserText( Revision::RAW ) + ); } if ( $changed ) { @@ -2071,7 +2075,7 @@ class WikiPage implements Page, IDBAccessObject { } else { $edit->timestamp = wfTimestampNow(); } - // @note: $cachedEdit is not used if the rev ID was referenced in the text + // @note: $cachedEdit is safely not used if the rev ID was referenced in the text $edit->revid = $revid; if ( $cachedEdit ) { @@ -2164,17 +2168,26 @@ class WikiPage implements Page, IDBAccessObject { ]; $content = $revision->getContent(); - // Parse the text - // Be careful not to do pre-save transform twice: $text is usually - // already pre-save transformed once. - if ( !$this->mPreparedEdit || $this->mPreparedEdit->output->getFlag( 'vary-revision' ) ) { - wfDebug( __METHOD__ . ": No prepared edit or vary-revision is set...\n" ); - $editInfo = $this->prepareContentForEdit( $content, $revision, $user ); + // See if the parser output before $revision was inserted is still valid + $editInfo = false; + if ( !$this->mPreparedEdit ) { + wfDebug( __METHOD__ . ": No prepared edit...\n" ); + } elseif ( $this->mPreparedEdit->output->getFlag( 'vary-revision' ) ) { + wfDebug( __METHOD__ . ": Prepared edit has vary-revision...\n" ); + } elseif ( $this->mPreparedEdit->output->getFlag( 'vary-user' ) && !$options['changed'] ) { + wfDebug( __METHOD__ . ": Prepared edit has vary-user and is null...\n" ); } else { - wfDebug( __METHOD__ . ": No vary-revision, using prepared edit...\n" ); + wfDebug( __METHOD__ . ": Using prepared edit...\n" ); $editInfo = $this->mPreparedEdit; } + if ( !$editInfo ) { + // Parse the text again if needed. Be careful not to do pre-save transform twice: + // $text is usually already pre-save transformed once. Avoid using the edit stash + // as any prepared content from there or in doEditContent() was already rejected. + $editInfo = $this->prepareContentForEdit( $content, $revision, $user, null, false ); + } + // Save it to the parser cache. // Make sure the cache time matches page_touched to avoid double parsing. ParserCache::singleton()->save( diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index cbdfec38b3..63a297b2d7 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -2648,9 +2648,9 @@ class Parser { break; case 'revisionuser': # Let the edit saving system know we should parse the page - # *after* a revision ID has been assigned. This is for null edits. - $this->mOutput->setFlag( 'vary-revision' ); - wfDebug( __METHOD__ . ": {{REVISIONUSER}} used, setting vary-revision...\n" ); + # *after* a revision ID has been assigned for null edits. + $this->mOutput->setFlag( 'vary-user' ); + wfDebug( __METHOD__ . ": {{REVISIONUSER}} used, setting vary-user...\n" ); $value = $this->getRevisionUser(); break; case 'revisionsize': -- 2.20.1