} elseif ( $editInfo->output->getFlag( 'vary-revision' ) ) {
// This can be used for the initial parse, e.g. for filters or doEditContent(),
// but a second parse will be triggered in doEditUpdates(). This is not optimal.
- $logger->info( "Partially usable cache for key '$key' ('$title') [vary_revision]." );
+ $logger->info( "Cache for key '$key' ('$title') has vary_revision." );
+ } elseif ( $editInfo->output->getFlag( 'vary-revision-id' ) ) {
+ // Similar to the above if we didn't guess the ID correctly.
+ $logger->info( "Cache for key '$key' ('$title') has vary_revision_id." );
}
return $editInfo;
* @file
*/
+use \MediaWiki\Logger\LoggerFactory;
+
/**
* Class representing a MediaWiki article and history.
*
}
}
);
+ } else {
+ // Try to avoid a second parse if {{REVISIONID}} is used
+ $edit->popts->setSpeculativeRevIdCallback( function () {
+ return 1 + (int)wfGetDB( DB_MASTER )->selectField(
+ 'revision',
+ 'MAX(rev_id)',
+ [],
+ __METHOD__
+ );
+ } );
}
$edit->output = $edit->pstContent
? $edit->pstContent->getParserOutput( $this->mTitle, $revid, $edit->popts )
];
$content = $revision->getContent();
+ $logger = LoggerFactory::getInstance( 'SaveParse' );
+
// See if the parser output before $revision was inserted is still valid
$editInfo = false;
if ( !$this->mPreparedEdit ) {
- wfDebug( __METHOD__ . ": No prepared edit...\n" );
+ $logger->debug( __METHOD__ . ": No prepared edit...\n" );
} elseif ( $this->mPreparedEdit->output->getFlag( 'vary-revision' ) ) {
- wfDebug( __METHOD__ . ": Prepared edit has vary-revision...\n" );
+ $logger->info( __METHOD__ . ": Prepared edit has vary-revision...\n" );
+ } elseif ( $this->mPreparedEdit->output->getFlag( 'vary-revision-id' )
+ && $this->mPreparedEdit->output->getSpeculativeRevIdUsed() !== $revision->getId()
+ ) {
+ $logger->info( __METHOD__ . ": Prepared edit has vary-revision-id with wrong ID...\n" );
} elseif ( $this->mPreparedEdit->output->getFlag( 'vary-user' ) && !$options['changed'] ) {
- wfDebug( __METHOD__ . ": Prepared edit has vary-user and is null...\n" );
+ $logger->info( __METHOD__ . ": Prepared edit has vary-user and is null...\n" );
} else {
wfDebug( __METHOD__ . ": Using prepared edit...\n" );
$editInfo = $this->mPreparedEdit;
case 'revisionid':
# Let the edit saving system know we should parse the page
# *after* a revision ID has been assigned.
- $this->mOutput->setFlag( 'vary-revision' );
- wfDebug( __METHOD__ . ": {{REVISIONID}} used, setting vary-revision...\n" );
+ $this->mOutput->setFlag( 'vary-revision-id' );
+ wfDebug( __METHOD__ . ": {{REVISIONID}} used, setting vary-revision-id...\n" );
$value = $this->mRevisionId;
+ if ( !$value && $this->mOptions->getSpeculativeRevIdCallback() ) {
+ $value = call_user_func( $this->mOptions->getSpeculativeRevIdCallback() );
+ $this->mOutput->setSpeculativeRevIdUsed( $value );
+ }
break;
case 'revisionday':
# Let the edit saving system know we should parse the page
private $mRemoveComments = true;
/**
- * Callback for current revision fetching. Used as first argument to call_user_func().
+ * @var callable Callback for current revision fetching; first argument to call_user_func().
*/
private $mCurrentRevisionCallback =
[ 'Parser', 'statelessFetchRevision' ];
/**
- * Callback for template fetching. Used as first argument to call_user_func().
+ * @var callable Callback for template fetching; first argument to call_user_func().
*/
private $mTemplateCallback =
[ 'Parser', 'statelessFetchTemplate' ];
+ /**
+ * @var callable|null Callback to generate a guess for {{REVISIONID}}
+ */
+ private $mSpeculativeRevIdCallback;
+
/**
* Enable limit report in an HTML comment on output
*/
return $this->mTemplateCallback;
}
+ /** @since 1.28 */
+ public function getSpeculativeRevIdCallback() {
+ return $this->mSpeculativeRevIdCallback;
+ }
+
public function getEnableLimitReport() {
return $this->mEnableLimitReport;
}
return wfSetVar( $this->mCurrentRevisionCallback, $x );
}
+ /** @since 1.28 */
+ public function setSpeculativeRevIdCallback( $x ) {
+ return wfSetVar( $this->mSpeculativeRevIdCallback, $x );
+ }
+
public function setTemplateCallback( $x ) {
return wfSetVar( $this->mTemplateCallback, $x );
}
*/
private $mFlags = [];
+ /** @var integer|null Assumed rev ID for {{REVISIONID}} if no revision is set */
+ private $mSpeculativeRevId;
+
const EDITSECTION_REGEX =
'#<(?:mw:)?editsection page="(.*?)" section="(.*?)"(?:/>|>(.*?)(</(?:mw:)?editsection>))#';
return $text;
}
+ /**
+ * @param integer $id
+ * @since 1.28
+ */
+ public function setSpeculativeRevIdUsed( $id ) {
+ $this->mSpeculativeRevId = $id;
+ }
+
+ /** @since 1.28 */
+ public function getSpeculativeRevIdUsed() {
+ return $this->mSpeculativeRevId;
+ }
+
public function &getLanguageLinks() {
return $this->mLanguageLinks;
}