X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fresourceloader%2FResourceLoaderModule.php;h=8124f3398b22797ff1ccf120f1c2eeccf1635eee;hb=ba39208f91e5caafab28d97999fdddf0dae00410;hp=48e7937104cef639aa694bb21279059d7ecc5344;hpb=912acabeab195d9e35b08def9f44beb4bdadc98f;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/resourceloader/ResourceLoaderModule.php b/includes/resourceloader/ResourceLoaderModule.php index 48e7937104..8124f3398b 100644 --- a/includes/resourceloader/ResourceLoaderModule.php +++ b/includes/resourceloader/ResourceLoaderModule.php @@ -22,9 +22,11 @@ * @author Roan Kattouw */ +use MediaWiki\MediaWikiServices; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; +use Wikimedia\ScopedCallback; /** * Abstraction for ResourceLoader modules, with name registration and maxage functionality. @@ -186,7 +188,7 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface { public function getConfig() { if ( $this->config === null ) { // Ugh, fall back to default - $this->config = ConfigFactory::getDefaultInstance()->makeConfig( 'main' ); + $this->config = MediaWikiServices::getInstance()->getMainConfig(); } return $this->config; @@ -264,8 +266,8 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface { * * @param ResourceLoaderContext $context * @return array List of CSS strings or array of CSS strings keyed by media type. - * like array( 'screen' => '.foo { width: 0 }' ); - * or array( 'screen' => array( '.foo { width: 0 }' ) ); + * like [ 'screen' => '.foo { width: 0 }' ]; + * or [ 'screen' => [ '.foo { width: 0 }' ] ]; */ public function getStyles( ResourceLoaderContext $context ) { // Stub, override expected @@ -279,7 +281,7 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface { * load the files directly. See also getScriptURLsForDebug() * * @param ResourceLoaderContext $context - * @return array Array( mediaType => array( URL1, URL2, ... ), ... ) + * @return array [ mediaType => [ URL1, URL2, ... ], ... ] */ public function getStyleURLsForDebug( ResourceLoaderContext $context ) { $resourceLoader = $context->getResourceLoader(); @@ -329,14 +331,13 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface { } /** - * Where on the HTML page should this module's JS be loaded? - * - 'top': in the "" - * - 'bottom': at the bottom of the "" + * From where in the page HTML should this module be loaded? * + * @deprecated since 1.29 Obsolete. All modules load async from ``. * @return string */ public function getPosition() { - return 'bottom'; + return 'top'; } /** @@ -417,7 +418,7 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface { // Try in-object cache first if ( !isset( $this->fileDeps[$vary] ) ) { - $dbr = wfGetDB( DB_SLAVE ); + $dbr = wfGetDB( DB_REPLICA ); $deps = $dbr->selectField( 'module_deps', 'md_deps', [ @@ -486,9 +487,14 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface { ] ); - $dbw->onTransactionResolution( function () use ( &$scopeLock ) { - ScopedCallback::consume( $scopeLock ); // release after commit - } ); + if ( $dbw->trxLevel() ) { + $dbw->onTransactionResolution( + function () use ( &$scopeLock ) { + ScopedCallback::consume( $scopeLock ); // release after commit + }, + __METHOD__ + ); + } } } catch ( Exception $e ) { wfDebugLog( 'resourceloader', __METHOD__ . ": failed to update DB: $e" ); @@ -637,7 +643,7 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface { // Styles if ( $context->shouldIncludeStyles() ) { $styles = []; - // Don't create empty stylesheets like array( '' => '' ) for modules + // Don't create empty stylesheets like [ '' => '' ] for modules // that don't *have* any stylesheets (bug 38024). $stylePairs = $this->getStyles( $context ); if ( count( $stylePairs ) ) { @@ -787,10 +793,10 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface { * * @code * $summary = parent::getDefinitionSummary( $context ); - * $summary[] = array( + * $summary[] = [ * 'foo' => 123, * 'bar' => 'quux', - * ); + * ]; * return $summary; * @endcode *