/**
  * @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);
 }
 /**
  * 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;
 }
 /**
  * @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;
 }
 /**
  * @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;
 }
 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());
 }
 /**
  * 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;
 }
 /**
  * @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];
 }
 /**
  * @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];
 }
 /**
  * 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'));
 }
 /**
  * @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());
 }