use Wikimedia\Rdbms\LBFactory;
use Wikimedia\Rdbms\ILBFactory;
use Wikimedia\Rdbms\LoadBalancer;
+use Wikimedia\Rdbms\DBTransactionError;
/**
* Class for managing the deferred updates
* @since 1.34
*/
public static function attemptUpdate( DeferrableUpdate $update, ILBFactory $lbFactory ) {
+ $ticket = $lbFactory->getEmptyTransactionTicket( __METHOD__ );
+ if ( !$ticket || $lbFactory->hasTransactionRound() ) {
+ throw new DBTransactionError( null, "A database transaction round is pending." );
+ }
+
if ( $update instanceof DataUpdate ) {
- $update->setTransactionTicket( $lbFactory->getEmptyTransactionTicket( __METHOD__ ) );
+ $update->setTransactionTicket( $ticket );
}
- if (
+ $fnameTrxOwner = get_class( $update ) . '::doUpdate';
+ $useExplicitTrxRound = !(
$update instanceof TransactionRoundAwareUpdate &&
$update->getTransactionRoundRequirement() == $update::TRX_ROUND_ABSENT
- ) {
- $fnameTrxOwner = null;
+ );
+ // Flush any pending changes left over from an implicit transaction round
+ if ( $useExplicitTrxRound ) {
+ $lbFactory->beginMasterChanges( $fnameTrxOwner ); // new explicit round
} else {
- $fnameTrxOwner = get_class( $update ) . '::doUpdate';
+ $lbFactory->commitMasterChanges( $fnameTrxOwner ); // new implicit round
}
-
- if ( $fnameTrxOwner !== null ) {
- $lbFactory->beginMasterChanges( $fnameTrxOwner );
- }
-
+ // Run the update after any stale master view snapshots have been flushed
$update->doUpdate();
-
- if ( $fnameTrxOwner !== null ) {
- $lbFactory->commitMasterChanges( $fnameTrxOwner );
- }
+ // Commit any pending changes from the explicit or implicit transaction round
+ $lbFactory->commitMasterChanges( $fnameTrxOwner );
}
/**
}
public function validate( $value, $alldata ) {
- if ( !$this->mParams['exists'] ) {
+ if ( !$this->mParams['exists'] || $value === '' ) {
return true;
}
/**
* @deprecated DO NOT CALL ME.
- * This method was introduced when factoring UploadImporter out of WikiRevision.
- * It only has 1 use by the deprecated downloadSource method in WikiRevision.
- * Do not use this in new code.
+ * This method was introduced when factoring (Importable)UploadRevisionImporter out of
+ * WikiRevision. It only has 1 use by the deprecated downloadSource method in WikiRevision.
+ * Do not use this in new code, it will be made private soon.
*
* @param ImportableUploadRevision $wikiRevision
*
/**
* @since 1.12.2
- * @deprecated in 1.31. Use UploadImporter::import
+ * @deprecated in 1.31. Use UploadRevisionImporter::import
* @return bool
*/
public function importUpload() {
/**
* @since 1.12.2
- * @deprecated in 1.31. Use UploadImporter::downloadSource
+ * @deprecated in 1.31. No replacement
* @return bool|string
*/
public function downloadSource() {
throw new MWException( __METHOD__ . ": invalid versionCallback for file" .
" \"{$fileInfo['name']}\" in module \"{$this->getName()}\"" );
}
- $expanded['definitionSummary'] = ( $fileInfo['versionCallback'] )( $context );
+ $expanded['definitionSummary'] =
+ ( $fileInfo['versionCallback'] )( $context, $this->getConfig() );
// Don't invoke 'callback' here as it may be expensive (T223260).
$expanded['callback'] = $fileInfo['callback'];
} else {
- $expanded['content'] = ( $fileInfo['callback'] )( $context );
+ $expanded['content'] = ( $fileInfo['callback'] )( $context, $this->getConfig() );
}
} elseif ( isset( $fileInfo['config'] ) ) {
if ( $type !== 'data' ) {
$fileInfo['content'] = $content;
unset( $fileInfo['filePath'] );
} elseif ( isset( $fileInfo['callback'] ) ) {
- $fileInfo['content'] = ( $fileInfo['callback'] )( $context );
+ $fileInfo['content'] = ( $fileInfo['callback'] )( $context, $this->getConfig() );
unset( $fileInfo['callback'] );
}
'remoteBasePath' => "$wgResourceBasePath/resources/src/mediawiki.jqueryMsg",
'packageFiles' => [
'mediawiki.jqueryMsg.js',
- [ 'name' => 'parserDefaults.json', 'callback' => function ( ResourceLoaderContext $context ) {
+ [ 'name' => 'parserDefaults.json', 'callback' => function (
+ ResourceLoaderContext $context, Config $config
+ ) {
$tagData = Sanitizer::getRecognizedTagData();
$allowedHtmlElements = array_merge(
array_keys( $tagData['htmlpairs'] ),
);
$magicWords = [
- 'SITENAME' => $context->getConfig()->get( 'Sitename' ),
+ 'SITENAME' => $config->get( 'Sitename' ),
];
Hooks::run( 'ResourceLoaderJqueryMsgModuleMagicWords', [ $context, &$magicWords ] );