Krinkle has uploaded a new change for review. https://gerrit.wikimedia.org/r/299272
Change subject: [WIP] resourceloader: Move queue formatting out of OutputPage (DRAFT) ...................................................................... [WIP] resourceloader: Move queue formatting out of OutputPage (DRAFT) See <https://phabricator.wikimedia.org/%5487871#2464320>. Change-Id: I605b8cd1e1fc009b4662a0edbc54d09dd65ee1df --- M autoload.php M includes/OutputPage.php A includes/resourceloader/ResourceLoaderClientHtml.php 3 files changed, 111 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/72/299272/1 diff --git a/autoload.php b/autoload.php index d82d699..0371f3e 100644 --- a/autoload.php +++ b/autoload.php @@ -1144,6 +1144,7 @@ 'ResetUserTokens' => __DIR__ . '/maintenance/resetUserTokens.php', 'ResourceFileCache' => __DIR__ . '/includes/cache/ResourceFileCache.php', 'ResourceLoader' => __DIR__ . '/includes/resourceloader/ResourceLoader.php', + 'ResourceLoaderClientHtml' => __DIR__ . '/includes/resourceloader/ResourceLoaderClientHtml.php', 'ResourceLoaderContext' => __DIR__ . '/includes/resourceloader/ResourceLoaderContext.php', 'ResourceLoaderEditToolbarModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderEditToolbarModule.php', 'ResourceLoaderFileModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderFileModule.php', diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 474ad7e..29e1216 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -2950,6 +2950,7 @@ * JS stuff to put in the "<head>". This is the startup module, config * vars and modules marked with position 'top' * + * @deprecated since 1.28 Unused * @return string HTML fragment */ function getHeadScripts() { diff --git a/includes/resourceloader/ResourceLoaderClientHtml.php b/includes/resourceloader/ResourceLoaderClientHtml.php new file mode 100644 index 0000000..d9c0dde --- /dev/null +++ b/includes/resourceloader/ResourceLoaderClientHtml.php @@ -0,0 +1,109 @@ +<?php +/** + * Bootstrapping for a ResourceLoader client on an HTML page. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + * @author Timo Tijhof + */ + +use MediaWiki\Logger\LoggerFactory; + +/** + * @since 1.28 + */ +class ResourceLoaderClientHtml { + + /** @var ResourceLoader */ + private $resourceLoader; + + /** @var array */ + private $modules = []; + + /** @var array */ + private $moduleScripts = []; + + /** @var array */ + private $moduleStyles = []; + + public function __construct( ResourceLoader $resourceLoader ) { + $this->resourceLoader = $resourceLoader; + } + + /** + * Ensure one or more modules are loaded. + * + * @param string|array $modules Module name or array of module names + */ + public function addModules( $modules ) { + $this->modules = array_merge( $this->modules, (array)$modules ); + } + + /** + * Ensure the scripts of one or more modules are loaded. + * + * @deprecated since 1.28 + * @param string|array $modules Module name or array of module names + */ + public function addModuleScripts( $modules ) { + $this->moduleScripts = array_merge( $this->moduleScripts, (array)$modules ); + } + + /** + * Ensure the styles of one or more modules are loaded. + * + * @deprecated since 1.28 + * @param string|array $modules Module name or array of module names + */ + public function addModuleStyles( $modules ) { + $this->moduleStyles = array_merge( $this->moduleStyles, (array)$modules ); + } + + /** + * TODO: + * - Implement analogous logic for: + * - getAllowedModules() - filter by trusted origin level + * - filterModules() - split by queue position (deprecated) + * - split by scripts/styles-only and regular (deprecated) + */ + + public function getDocumentElementAttributes() { + // For OutputPage::headElement() -> + // Skin::getHtmlElementAttributes() + // - class="client-nojs" (changed by startup.js) + // - (later) data-rl-load=",,," data-rl-state-ready=",,," data-rl-state-loading=",,," + // (to be dealt by startup.js, instead of current state() and load() inline scripts) + } + + /** + * @return string HTML + */ + public function getHeadHtml() { + // For OutputPage::headElement() + // See + // getInlineHeadScripts() + // buildCssLinks() + // getExternalHeadScripts() + // makeResourceLoaderLink() + } + + public function getBodyHtml() { + // For OutputPage::getBottomScripts() -> + // Skin::bottomScripts -> BaseTemplate::printTrail(). + } + +} -- To view, visit https://gerrit.wikimedia.org/r/299272 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I605b8cd1e1fc009b4662a0edbc54d09dd65ee1df Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Krinkle <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
