本文整理汇总了PHP中ResourceLoaderContext类的典型用法代码示例。如果您正苦于以下问题:PHP ResourceLoaderContext类的具体用法?PHP ResourceLoaderContext怎么用?PHP ResourceLoaderContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ResourceLoaderContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPages
public function getPages(ResourceLoaderContext $context)
{
$pages = array();
$missingCallback = $context->getRequest()->getVal('missingCallback');
if ($this->type) {
foreach ($this->articles as $article) {
$pageKey = $article['title'];
$type = isset($article['type']) ? $article['type'] : $this->type;
$pageInfo = array('type' => $type);
if (isset($article['originalName'])) {
$pageInfo['originalName'] = $article['originalName'];
}
if ($missingCallback) {
$pageInfo['missingCallback'] = $missingCallback;
}
if (!empty($article['cityId'])) {
$pageIndex = 'fakename' . $this->id++;
$pageInfo['city_id'] = intval($article['cityId']);
$pageInfo['title'] = $article['title'];
// Unable to resolve wiki to cityId
} else {
if (isset($article['cityId'])) {
$pageInfo['missing'] = true;
}
}
$pages[$pageKey] = $pageInfo;
}
}
return $pages;
}
示例2: useFileCache
/**
* Check if an RL request can be cached.
* Caller is responsible for checking if any modules are private.
* @param $context ResourceLoaderContext
* @return bool
*/
public static function useFileCache(ResourceLoaderContext $context)
{
global $wgUseFileCache, $wgDefaultSkin, $wgLanguageCode;
if (!$wgUseFileCache) {
return false;
}
// Get all query values
$queryVals = $context->getRequest()->getValues();
foreach ($queryVals as $query => $val) {
if ($query === 'modules' || $query === 'version' || $query === '*') {
continue;
// note: &* added as IE fix
} elseif ($query === 'skin' && $val === $wgDefaultSkin) {
continue;
} elseif ($query === 'lang' && $val === $wgLanguageCode) {
continue;
} elseif ($query === 'only' && in_array($val, array('styles', 'scripts'))) {
continue;
} elseif ($query === 'debug' && $val === 'false') {
continue;
}
return false;
}
return true;
// cacheable
}
示例3: getPages
/**
* @param $context ResourceLoaderContext
* @return array
*/
protected function getPages(ResourceLoaderContext $context)
{
$username = $context->getUser();
if ($username === null) {
return array();
}
// Get the normalized title of the user's user page
$userpageTitle = Title::makeTitleSafe(NS_USER, $username);
if (!$userpageTitle instanceof Title) {
return array();
}
$userpage = $userpageTitle->getPrefixedDBkey();
// Needed so $excludepages works
$pages = array("{$userpage}/common.js" => array('type' => 'script'), "{$userpage}/" . $context->getSkin() . '.js' => array('type' => 'script'), "{$userpage}/common.css" => array('type' => 'style'), "{$userpage}/" . $context->getSkin() . '.css' => array('type' => 'style'));
// Hack for bug 26283: if we're on a preview page for a CSS/JS page,
// we need to exclude that page from this module. In that case, the excludepage
// parameter will be set to the name of the page we need to exclude.
$excludepage = $context->getRequest()->getVal('excludepage');
if (isset($pages[$excludepage])) {
// This works because $excludepage is generated with getPrefixedDBkey(),
// just like the keys in $pages[] above
unset($pages[$excludepage]);
}
return $pages;
}
示例4: getPages
/**
* @param ResourceLoaderContext $context
* @return array
*/
protected function getPages(ResourceLoaderContext $context)
{
$useSiteJs = $this->getConfig()->get('UseSiteJs');
$useSiteCss = $this->getConfig()->get('UseSiteCss');
if (!$useSiteJs && !$useSiteCss) {
return array();
}
$user = $context->getUserObj();
if (!$user || $user->isAnon()) {
return array();
}
$pages = array();
foreach ($user->getEffectiveGroups() as $group) {
if ($group == '*') {
continue;
}
if ($useSiteJs) {
$pages["MediaWiki:Group-{$group}.js"] = array('type' => 'script');
}
if ($useSiteCss) {
$pages["MediaWiki:Group-{$group}.css"] = array('type' => 'style');
}
}
return $pages;
}
示例5: getStyles
/**
* @param ResourceLoaderContext $context
* @return array
*/
public function getStyles(ResourceLoaderContext $context)
{
if (!$this->getConfig()->get('AllowUserCssPrefs')) {
return array();
}
$options = $context->getUserObj()->getOptions();
// Build CSS rules
$rules = array();
// Underline: 2 = browser default, 1 = always, 0 = never
if ($options['underline'] < 2) {
$rules[] = "a { text-decoration: " . ($options['underline'] ? 'underline' : 'none') . "; }";
} else {
# The scripts of these languages are very hard to read with underlines
$rules[] = 'a:lang(ar), a:lang(kk-arab), a:lang(mzn), ' . 'a:lang(ps), a:lang(ur) { text-decoration: none; }';
}
if ($options['editfont'] !== 'default') {
// Double-check that $options['editfont'] consists of safe characters only
if (preg_match('/^[a-zA-Z0-9_, -]+$/', $options['editfont'])) {
$rules[] = "textarea { font-family: {$options['editfont']}; }\n";
}
}
$style = implode("\n", $rules);
if ($this->getFlip($context)) {
$style = CSSJanus::transform($style, true, false);
}
return array('all' => $style);
}
示例6: useFileCache
/**
* Check if an RL request can be cached.
* Caller is responsible for checking if any modules are private.
* @param ResourceLoaderContext $context
* @return bool
*/
public static function useFileCache(ResourceLoaderContext $context)
{
global $wgUseFileCache, $wgDefaultSkin, $wgLanguageCode;
if (!$wgUseFileCache) {
return false;
}
// Get all query values
$queryVals = $context->getRequest()->getValues();
foreach ($queryVals as $query => $val) {
if (in_array($query, array('modules', 'image', 'variant', 'version', '*'))) {
// Use file cache regardless of the value of this parameter
continue;
// note: &* added as IE fix
} elseif ($query === 'skin' && $val === $wgDefaultSkin) {
continue;
} elseif ($query === 'lang' && $val === $wgLanguageCode) {
continue;
} elseif ($query === 'only' && in_array($val, array('styles', 'scripts'))) {
continue;
} elseif ($query === 'debug' && $val === 'false') {
continue;
} elseif ($query === 'format' && $val === 'rasterized') {
continue;
}
return false;
}
return true;
// cacheable
}
示例7: getPages
/**
* @param ResourceLoaderContext $context
* @return array List of pages
*/
protected function getPages(ResourceLoaderContext $context)
{
$config = $this->getConfig();
$user = $context->getUserObj();
if ($user->isAnon()) {
return [];
}
// Use localised/normalised variant to ensure $excludepage matches
$userPage = $user->getUserPage()->getPrefixedDBkey();
$pages = [];
if ($config->get('AllowUserCss')) {
$pages["{$userPage}/common.css"] = ['type' => 'style'];
$pages["{$userPage}/" . $context->getSkin() . '.css'] = ['type' => 'style'];
}
// User group pages are maintained site-wide and enabled with site JS/CSS.
if ($config->get('UseSiteCss')) {
foreach ($user->getEffectiveGroups() as $group) {
if ($group == '*') {
continue;
}
$pages["MediaWiki:Group-{$group}.css"] = ['type' => 'style'];
}
}
// Hack for T28283: Allow excluding pages for preview on a CSS/JS page.
// The excludepage parameter is set by OutputPage.
$excludepage = $context->getRequest()->getVal('excludepage');
if (isset($pages[$excludepage])) {
unset($pages[$excludepage]);
}
return $pages;
}
示例8: getPages
/**
* Get list of pages used by this module
*
* @param ResourceLoaderContext $context
* @return array List of pages
*/
protected function getPages(ResourceLoaderContext $context)
{
$allowUserJs = $this->getConfig()->get('AllowUserJs');
$allowUserCss = $this->getConfig()->get('AllowUserCss');
if (!$allowUserJs && !$allowUserCss) {
return array();
}
$user = $context->getUserObj();
if (!$user || $user->isAnon()) {
return array();
}
// Needed so $excludepages works
$userPage = $user->getUserPage()->getPrefixedDBkey();
$pages = array();
if ($allowUserJs) {
$pages["{$userPage}/common.js"] = array('type' => 'script');
$pages["{$userPage}/" . $context->getSkin() . '.js'] = array('type' => 'script');
}
if ($allowUserCss) {
$pages["{$userPage}/common.css"] = array('type' => 'style');
$pages["{$userPage}/" . $context->getSkin() . '.css'] = array('type' => 'style');
}
// Hack for bug 26283: if we're on a preview page for a CSS/JS page,
// we need to exclude that page from this module. In that case, the excludepage
// parameter will be set to the name of the page we need to exclude.
$excludepage = $context->getRequest()->getVal('excludepage');
if (isset($pages[$excludepage])) {
// This works because $excludepage is generated with getPrefixedDBkey(),
// just like the keys in $pages[] above
unset($pages[$excludepage]);
}
return $pages;
}
示例9: getPages
/**
* @param $context ResourceLoaderContext
* @return array
*/
protected function getPages(ResourceLoaderContext $context)
{
global $wgUser, $wgUseSiteJs, $wgUseSiteCss;
$userName = $context->getUser();
if ($userName === null) {
return array();
}
if (!$wgUseSiteJs && !$wgUseSiteCss) {
return array();
}
// Use $wgUser is possible; allows to skip a lot of code
if (is_object($wgUser) && $wgUser->getName() == $userName) {
$user = $wgUser;
} else {
$user = User::newFromName($userName);
if (!$user instanceof User) {
return array();
}
}
$pages = array();
foreach ($user->getEffectiveGroups() as $group) {
if (in_array($group, array('*', 'user'))) {
continue;
}
if ($wgUseSiteJs) {
$pages["MediaWiki:Group-{$group}.js"] = array('type' => 'script');
}
if ($wgUseSiteCss) {
$pages["MediaWiki:Group-{$group}.css"] = array('type' => 'style');
}
}
return $pages;
}
示例10: getPages
protected function getPages(ResourceLoaderContext $context)
{
if ($context->getUser()) {
$username = $context->getUser();
return array("User:{$username}/common.js" => array('type' => 'script'), "User:{$username}/" . $context->getSkin() . '.js' => array('type' => 'script'), "User:{$username}/common.css" => array('type' => 'style'), "User:{$username}/" . $context->getSkin() . '.css' => array('type' => 'style'));
}
return array();
}
示例11: testGetUser
public function testGetUser()
{
$ctx = new ResourceLoaderContext($this->getResourceLoader(), new FauxRequest([]));
$this->assertSame(null, $ctx->getUser());
$this->assertTrue($ctx->getUserObj()->isAnon());
$ctx = new ResourceLoaderContext($this->getResourceLoader(), new FauxRequest(['user' => 'Example']));
$this->assertSame('Example', $ctx->getUser());
$this->assertEquals('Example', $ctx->getUserObj()->getName());
}
示例12: getPages
/**
* Get list of pages used by this module
*
* @param ResourceLoaderContext $context
* @return array List of pages
*/
protected function getPages(ResourceLoaderContext $context)
{
$pages = [];
if ($this->getConfig()->get('UseSiteJs')) {
$pages['MediaWiki:Common.js'] = ['type' => 'script'];
$pages['MediaWiki:' . ucfirst($context->getSkin()) . '.js'] = ['type' => 'script'];
}
return $pages;
}
示例13: getModifiedTime
/**
* @param $context ResourceLoaderContext
* @return array|int|Mixed
*/
public function getModifiedTime(ResourceLoaderContext $context)
{
$hash = $context->getHash();
if (isset($this->modifiedTime[$hash])) {
return $this->modifiedTime[$hash];
}
global $wgUser;
return $this->modifiedTime[$hash] = wfTimestamp(TS_UNIX, $wgUser->getTouched());
}
示例14: getPages
/**
* Gets list of pages used by this module
*
* @param $context ResourceLoaderContext
*
* @return Array: List of pages
*/
protected function getPages(ResourceLoaderContext $context)
{
global $wgHandheldStyle;
$pages = array('MediaWiki:Common.js' => array('type' => 'script'), 'MediaWiki:Common.css' => array('type' => 'style'), 'MediaWiki:' . ucfirst($context->getSkin()) . '.js' => array('type' => 'script'), 'MediaWiki:' . ucfirst($context->getSkin()) . '.css' => array('type' => 'style'), 'MediaWiki:Print.css' => array('type' => 'style', 'media' => 'print'));
if ($wgHandheldStyle) {
$pages['MediaWiki:Handheld.css'] = array('type' => 'style', 'media' => 'handheld');
}
return $pages;
}
示例15: contextUserOptions
/**
* Fetch the context's user options, or if it doesn't match current user,
* the default options.
*
* @param $context ResourceLoaderContext: Context object
* @return Array: List of user options keyed by option name
*/
protected function contextUserOptions(ResourceLoaderContext $context)
{
global $wgUser;
// Verify identity -- this is a private module
if ($context->getUser() === $wgUser->getName()) {
return $wgUser->getOptions();
} else {
return User::getDefaultOptions();
}
}