本文整理汇总了PHP中ResourceLoader类的典型用法代码示例。如果您正苦于以下问题:PHP ResourceLoader类的具体用法?PHP ResourceLoader怎么用?PHP ResourceLoader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ResourceLoader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* @param ResourceLoader $resourceLoader
* @param WebRequest $request
*/
public function __construct(ResourceLoader $resourceLoader, WebRequest $request)
{
$this->resourceLoader = $resourceLoader;
$this->request = $request;
$this->logger = $resourceLoader->getLogger();
// Future developers: Avoid use of getVal() in this class, which performs
// expensive UTF normalisation by default. Use getRawVal() instead.
// Values here are either one of a finite number of internal IDs,
// or previously-stored user input (e.g. titles, user names) that were passed
// to this endpoint by ResourceLoader itself from the canonical value.
// Values do not come directly from user input and need not match.
// List of modules
$modules = $request->getRawVal('modules');
$this->modules = $modules ? self::expandModuleNames($modules) : [];
// Various parameters
$this->user = $request->getRawVal('user');
$this->debug = $request->getFuzzyBool('debug', $resourceLoader->getConfig()->get('ResourceLoaderDebug'));
$this->only = $request->getRawVal('only', null);
$this->version = $request->getRawVal('version', null);
$this->raw = $request->getFuzzyBool('raw');
// Image requests
$this->image = $request->getRawVal('image');
$this->variant = $request->getRawVal('variant');
$this->format = $request->getRawVal('format');
$this->skin = $request->getRawVal('skin');
$skinnames = Skin::getSkinNames();
// If no skin is specified, or we don't recognize the skin, use the default skin
if (!$this->skin || !isset($skinnames[$this->skin])) {
$this->skin = $resourceLoader->getConfig()->get('DefaultSkin');
}
}
示例2: execute
public function execute()
{
$result = false;
$resourceLoader = new ResourceLoader();
foreach ($resourceLoader->getModuleNames() as $name) {
/** @var ResourceLoaderFileModule $module */
$module = $resourceLoader->getModule($name);
if (!$module || !$module instanceof ResourceLoaderFileModule) {
continue;
}
$hadErrors = false;
foreach ($module->getAllStyleFiles() as $file) {
if ($module->getStyleSheetLang($file) !== 'less') {
continue;
}
try {
$compiler = ResourceLoader::getLessCompiler();
$compiler->compileFile($file);
} catch (Exception $e) {
if (!$hadErrors) {
$this->error("Errors checking module {$name}:\n");
$hadErrors = true;
}
$this->error($e->getMessage() . "\n");
$result = true;
}
}
}
if (!$result) {
$this->output("No errors found\n");
} else {
die(1);
}
}
示例3: __construct
/**
* @param ResourceLoader $resourceLoader
* @param WebRequest $request
*/
public function __construct(ResourceLoader $resourceLoader, WebRequest $request)
{
$this->resourceLoader = $resourceLoader;
$this->request = $request;
// Interpret request
// List of modules
$modules = $request->getVal('modules');
$this->modules = $modules ? self::expandModuleNames($modules) : array();
// Various parameters
$this->skin = $request->getVal('skin');
$this->user = $request->getVal('user');
$this->debug = $request->getFuzzyBool('debug', $resourceLoader->getConfig()->get('ResourceLoaderDebug'));
$this->only = $request->getVal('only');
$this->version = $request->getVal('version');
$this->raw = $request->getFuzzyBool('raw');
// Image requests
$this->image = $request->getVal('image');
$this->variant = $request->getVal('variant');
$this->format = $request->getVal('format');
$skinnames = Skin::getSkinNames();
// If no skin is specified, or we don't recognize the skin, use the default skin
if (!$this->skin || !isset($skinnames[$this->skin])) {
$this->skin = $resourceLoader->getConfig()->get('DefaultSkin');
}
}
示例4: execute
public function execute()
{
$dbw = wfGetDB(DB_MASTER);
$rl = new ResourceLoader(ConfigFactory::getDefaultInstance()->makeConfig('main'));
$moduleNames = $rl->getModuleNames();
$moduleList = implode(', ', array_map(array($dbw, 'addQuotes'), $moduleNames));
$limit = max(1, intval($this->getOption('batchsize', 500)));
$this->output("Cleaning up module_deps table...\n");
$i = 1;
$modDeps = $dbw->tableName('module_deps');
do {
// $dbw->delete() doesn't support LIMIT :(
$where = $moduleList ? "md_module NOT IN ({$moduleList})" : '1=1';
$dbw->query("DELETE FROM {$modDeps} WHERE {$where} LIMIT {$limit}", __METHOD__);
$numRows = $dbw->affectedRows();
$this->output("Batch {$i}: {$numRows} rows\n");
$i++;
wfWaitForSlaves();
} while ($numRows > 0);
$this->output("done\n");
$this->output("Cleaning up msg_resource table...\n");
$i = 1;
$mrRes = $dbw->tableName('msg_resource');
do {
$where = $moduleList ? "mr_resource NOT IN ({$moduleList})" : '1=1';
$dbw->query("DELETE FROM {$mrRes} WHERE {$where} LIMIT {$limit}", __METHOD__);
$numRows = $dbw->affectedRows();
$this->output("Batch {$i}: {$numRows} rows\n");
$i++;
wfWaitForSlaves();
} while ($numRows > 0);
$this->output("done\n");
}
示例5: onResourceLoaderRegisterModules
/**
* @param ResourceLoader $rl
* @return bool
*/
public static function onResourceLoaderRegisterModules(ResourceLoader $rl)
{
$moduleDependencies = array('mediawiki.api', 'mediawiki.RegExp', 'mediawiki.Title', 'mediawiki.jqueryMsg', 'mediawiki.Uri', 'moment', 'jquery.jStorage', 'jquery.client', 'jquery.hidpi');
// If EventLogging is present, add the schema as a dependency.
if (class_exists('ResourceLoaderSchemaModule')) {
$moduleDependencies[] = "schema.Popups";
}
$rl->register("ext.popups", array('scripts' => array('resources/ext.popups.core.js', 'resources/ext.popups.logger.js', 'resources/ext.popups.renderer.js', 'resources/ext.popups.renderer.article.js', 'resources/ext.popups.disablenavpop.js', 'resources/ext.popups.settings.js'), 'styles' => array('resources/ext.popups.core.less', 'resources/ext.popups.animation.less', 'resources/ext.popups.settings.less'), 'dependencies' => $moduleDependencies, 'messages' => array('popups-last-edited', "popups-settings-title", "popups-settings-description", "popups-settings-option-simple", "popups-settings-option-simple-description", "popups-settings-option-advanced", "popups-settings-option-advanced-description", "popups-settings-option-off", "popups-settings-option-off-description", "popups-settings-save", "popups-settings-cancel", "popups-settings-enable", "popups-settings-help", "popups-settings-help-ok", "popups-send-feedback"), 'remoteExtPath' => 'Popups', 'localBasePath' => __DIR__));
return true;
}
示例6: onResourceLoaderRegisterModules
public static function onResourceLoaderRegisterModules(ResourceLoader &$resourceLoader)
{
global $wgFlowEventLogging, $wgResourceModules;
// Only if EventLogging in Flow is enabled & EventLogging exists
if ($wgFlowEventLogging && class_exists('ResourceLoaderSchemaModule')) {
$resourceLoader->register('schema.FlowReplies', array('class' => 'ResourceLoaderSchemaModule', 'schema' => 'FlowReplies', 'revision' => 10561344));
// Add as dependency to Flow JS
$wgResourceModules['ext.flow']['dependencies'][] = 'schema.FlowReplies';
}
return true;
}
示例7: resourceLoaderRegisterModules
/**
* ResourceLoaderRegisterModules hook
*
* Adds modules to ResourceLoader
*
* @param ResourceLoader $resourceLoader
* @return bool
*/
public static function resourceLoaderRegisterModules(&$resourceLoader)
{
global $wgAPIModules;
if (array_key_exists('titleblacklist', $wgAPIModules)) {
self::$modules['ext.uploadWizard']['dependencies'][] = 'mediawiki.api.titleblacklist';
}
if (class_exists('ResourceLoaderSchemaModule')) {
self::$modules['ext.uploadWizard.events']['dependencies'] = array('ext.eventLogging', 'schema.UploadWizardTutorialActions', 'schema.UploadWizardUploadActions');
self::$modules['uw.EventFlowLogger']['dependencies'] += array('ext.eventLogging', 'schema.UploadWizardStep', 'schema.UploadWizardFlowEvent', 'schema.UploadWizardErrorFlowEvent', 'schema.UploadWizardExceptionFlowEvent', 'schema.UploadWizardUploadFlowEvent');
}
foreach (self::$modules as $name => $resources) {
$resourceLoader->register($name, $resources + array('localBasePath' => __DIR__, 'remoteExtPath' => 'UploadWizard'));
}
return true;
}
示例8: testLessFileCompilation
public function testLessFileCompilation()
{
$thisString = $this->toString();
$this->assertTrue(is_string($this->file) && is_file($this->file) && is_readable($this->file), "{$thisString} must refer to a readable file");
$compiler = ResourceLoader::getLessCompiler(RequestContext::getMain()->getConfig());
$this->assertNotNull($compiler->compileFile($this->file));
}
示例9: registerAssetsManagerGroups
protected static function registerAssetsManagerGroups(ResourceLoader $resourceLoader)
{
if (empty(self::$assetsManagerGroups)) {
return true;
}
$assetsConfig = new AssetsConfig();
foreach (self::$assetsManagerGroups as $moduleName => $groupName) {
$type = $assetsConfig->getGroupType($groupName);
$key = null;
switch ($type) {
case AssetsManager::TYPE_JS:
$key = 'scripts';
break;
case AssetsManager::TYPE_CSS:
case AssetsManager::TYPE_SCSS:
$key = 'styles';
break;
}
if (empty($key)) {
// todo: log error
continue;
}
$assets = $assetsConfig->resolve($groupName, false, false);
foreach ($assets as $k => $v) {
if (!preg_match('#^(extensions|resources|skins)/#', $v)) {
unset($assets[$k]);
}
}
$assets = array_values($assets);
$module = array();
$module[$key] = $assets;
$resourceLoader->register($moduleName, $module);
}
return true;
}
示例10: getInlineScript
/**
* Get contents of a javascript file for inline use.
*
* Roughly based MediaWiki core methods:
* - ResourceLoader::filter()
* - ResourceLoaderFileModule::readScriptFiles()
*
* @param string $name Path to file relative to /modules/inline/
* @return string Minified script
* @throws Exception If file doesn't exist
*/
protected static function getInlineScript($name)
{
// Get file
$filePath = __DIR__ . '/../../modules/inline/' . $name;
if (!file_exists($filePath)) {
throw new Exception(__METHOD__ . ": file not found: \"{$filePath}\"");
}
$contents = file_get_contents($filePath);
// Try minified from cache
$key = wfMemcKey('centralauth', 'minify-js', md5($contents));
$cache = wfGetCache(CACHE_ANYTHING);
$cacheEntry = $cache->get($key);
if (is_string($cacheEntry)) {
return $cacheEntry;
}
// Compute new value
$result = '';
try {
$result = JavaScriptMinifier::minify($contents) . "\n/* cache key: {$key} */";
$cache->set($key, $result);
} catch (Exception $e) {
MWExceptionHandler::logException($e);
wfDebugLog('CentralAuth', __METHOD__ . ": minification failed for {$name}: {$e}");
$result = ResourceLoader::formatException($e) . "\n" . $contents;
}
return $result;
}
示例11: testResourceLoaderModifyMaxAge
/**
* @group Slow
* @slowExecutionTime 0.01651 ms
* @dataProvider resourceLoaderModifyMaxAgeDataProvider
*
* @param $timestamp int timestamp in URL
* @param $ttl int expected caching period
*/
public function testResourceLoaderModifyMaxAge($version, $ttl)
{
global $wgHooks;
$resourceLoader = new ResourceLoader();
$resourceLoader->register('WikiaTestModule', array('class' => 'TestResourceLoaderModule'));
$request = new WebRequest();
$request->setVal('modules', 'WikiaTestModule');
$request->setVal('version', join('-', $version));
// set up hooks
$wgHooks['ResourceLoaderCacheControlHeaders'][] = 'ResourceLoaderTest::onResourceLoaderCacheControlHeaders';
ob_start();
$resourceLoader->respond(new ResourceLoaderContext($resourceLoader, $request));
ob_end_clean();
// hook ResourceLoaderHooks::onResourceLoaderModifyMaxAge was called
// check modified caching period with expected one
$this->assertEquals($ttl, self::$ttl, 'TTL should match expected value');
}
示例12: getAllModules
/**
* Get all registered modules from ResouceLoader.
*/
protected static function getAllModules()
{
global $wgEnableJavaScriptTest;
// Test existance of test suite files as well
// (can't use setUp or setMwGlobals because providers are static)
$org_wgEnableJavaScriptTest = $wgEnableJavaScriptTest;
$wgEnableJavaScriptTest = true;
// Initialize ResourceLoader
$rl = new ResourceLoader();
$modules = array();
foreach ($rl->getModuleNames() as $moduleName) {
$modules[$moduleName] = $rl->getModule($moduleName);
}
// Restore settings
$wgEnableJavaScriptTest = $org_wgEnableJavaScriptTest;
return array('modules' => $modules, 'resourceloader' => $rl, 'context' => new ResourceLoaderContext($rl, new FauxRequest()));
}
示例13: test
public function test()
{
$loader = new ResourceLoader();
$definitions = new Definition($loader->load($this->source));
foreach ($definitions->getExpectations() as $definition) {
if (null !== $definition['type']) {
$actual = $loader->getType($definition['uri']);
if ($actual !== $definition['type']) {
throw new FailedExpectationException("Type mismatch for {$definition['uri']}. Got [{$actual}] but expected [{$definition['type']}]");
}
}
$expectation = new Expectation($definition['expected']);
if (!$expectation->assert($loader->load($definition['uri']))) {
throw new FailedExpectationException(implode("\n", $expectation->getMessages()));
}
}
return true;
}
示例14: getStyles
/**
* @param ResourceLoaderContext $context
* @return array
*/
public function getStyles(ResourceLoaderContext $context)
{
$geshi = SyntaxHighlight_GeSHi::prepare('', $this->lang);
if (!$geshi->error) {
$css = SyntaxHighlight_GeSHi::getCSS($geshi);
} else {
$css = ResourceLoader::makeComment($geshi->error());
}
return array('all' => $css);
}
示例15: setUp
protected function setUp()
{
parent::setUp();
ResourceLoader::clearCache();
$globals = [];
foreach (self::getSettings() as $key => $value) {
$globals['wg' . $key] = $value;
}
$this->setMwGlobals($globals);
}