* @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.
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;
}
/**
- * Where on the HTML page should this module's JS be loaded?
- * - 'top': in the "<head>"
- * - 'bottom': at the bottom of the "<body>"
+ * From where in the page HTML should this module be loaded?
*
+ * @deprecated since 1.29 Obsolete. All modules load async from `<head>`.
* @return string
*/
public function getPosition() {
- return 'bottom';
+ return 'top';
}
/**
}
$vary = $context->getSkin() . '|' . $context->getLanguage();
+ // Use relative paths to avoid ghost entries when $IP changes (T111481)
+ $deps = FormatJson::encode( self::getRelativePaths( $localFileRefs ) );
$dbw = wfGetDB( DB_MASTER );
- $dbw->replace( 'module_deps',
- [ [ 'md_module', 'md_skin' ] ],
+ $dbw->upsert( 'module_deps',
[
'md_module' => $this->getName(),
'md_skin' => $vary,
- // Use relative paths to avoid ghost entries when $IP changes (T111481)
- 'md_deps' => FormatJson::encode( self::getRelativePaths( $localFileRefs ) ),
+ 'md_deps' => $deps,
+ ],
+ [ 'md_module', 'md_skin' ],
+ [
+ 'md_deps' => $deps,
]
);
- $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" );
*
* @code
* $summary = parent::getDefinitionSummary( $context );
- * $summary[] = array(
+ * $summary[] = [
* 'foo' => 123,
* 'bar' => 'quux',
- * );
+ * ];
* return $summary;
* @endcode
*