本文整理汇总了PHP中ResourceLoaderContext::getUserObj方法的典型用法代码示例。如果您正苦于以下问题:PHP ResourceLoaderContext::getUserObj方法的具体用法?PHP ResourceLoaderContext::getUserObj怎么用?PHP ResourceLoaderContext::getUserObj使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ResourceLoaderContext
的用法示例。
在下文中一共展示了ResourceLoaderContext::getUserObj方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: 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;
}
示例3: 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;
}
示例4: 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;
}
示例5: 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());
}
示例6: getPages
/**
* Get list of pages used by this module
*
* @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('AllowUserJs')) {
$pages["{$userPage}/common.js"] = ['type' => 'script'];
$pages["{$userPage}/" . $context->getSkin() . '.js'] = ['type' => 'script'];
}
if ($config->get('AllowUserCss')) {
$pages["{$userPage}/common.css"] = ['type' => 'style'];
$pages["{$userPage}/" . $context->getSkin() . '.css'] = ['type' => 'style'];
}
$useSiteJs = $config->get('UseSiteJs');
$useSiteCss = $config->get('UseSiteCss');
// User group pages are maintained site-wide and enabled with site JS/CSS.
if ($useSiteJs || $useSiteCss) {
foreach ($user->getEffectiveGroups() as $group) {
if ($group == '*') {
continue;
}
if ($useSiteJs) {
$pages["MediaWiki:Group-{$group}.js"] = ['type' => 'script'];
}
if ($useSiteCss) {
$pages["MediaWiki:Group-{$group}.css"] = ['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;
}
示例7: getStyles
/**
* @param ResourceLoaderContext $context
* @return array
*/
public function getStyles(ResourceLoaderContext $context)
{
if (!$this->getConfig()->get('AllowUserCssPrefs')) {
return [];
}
$options = $context->getUserObj()->getOptions();
// Build CSS rules
$rules = [];
// Underline: 2 = skin default, 1 = always, 0 = never
if ($options['underline'] < 2) {
$rules[] = "a { text-decoration: " . ($options['underline'] ? 'underline' : 'none') . "; }";
}
$style = implode("\n", $rules);
if ($this->getFlip($context)) {
$style = CSSJanus::transform($style, true, false);
}
return ['all' => $style];
}
示例8: getStyles
/**
* @param ResourceLoaderContext $context
* @return array
*/
public function getStyles(ResourceLoaderContext $context)
{
if (!$this->getConfig()->get('AllowUserCssPrefs')) {
return [];
}
$options = $context->getUserObj()->getOptions();
// Build CSS rules
$rules = [];
// Underline: 2 = skin default, 1 = always, 0 = never
if ($options['underline'] < 2) {
$rules[] = "a { text-decoration: " . ($options['underline'] ? 'underline' : '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 ['all' => $style];
}
示例9: contextUserTokens
/**
* Fetch the tokens for the current user.
*
* @param ResourceLoaderContext $context
* @return array List of tokens keyed by token type
*/
protected function contextUserTokens(ResourceLoaderContext $context)
{
$user = $context->getUserObj();
return array('editToken' => $user->getEditToken(), 'patrolToken' => $user->getEditToken('patrol'), 'watchToken' => $user->getEditToken('watch'));
}
示例10: getScript
/**
* @param ResourceLoaderContext $context
* @return string
*/
public function getScript(ResourceLoaderContext $context)
{
return Xml::encodeJsCall('mw.user.options.set', [$context->getUserObj()->getOptions(User::GETOPTIONS_EXCLUDE_DEFAULTS)], ResourceLoader::inDebugMode());
}