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();
 }
 /**
  * @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;
 }
 public function getUser()
 {
     if ($this->user === self::INHERIT_VALUE) {
         return $this->context->getUser();
     }
     return $this->user;
 }
 /**
  * @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;
 }
 public function getUser()
 {
     if (!is_null($this->user)) {
         return $this->user;
     } else {
         return $this->context->getUser();
     }
 }
 /**
  * @param $context ResourceLoaderContext
  * @return array
  */
 protected function getPages(ResourceLoaderContext $context)
 {
     if ($context->getUser()) {
         $user = User::newFromName($context->getUser());
         if ($user instanceof User) {
             $pages = array();
             foreach ($user->getEffectiveGroups() as $group) {
                 if (in_array($group, array('*', 'user'))) {
                     continue;
                 }
                 $pages["MediaWiki:Group-{$group}.js"] = array('type' => 'script');
                 $pages["MediaWiki:Group-{$group}.css"] = array('type' => 'style');
             }
             return $pages;
         }
     }
     return array();
 }
 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());
 }
 /**
  * 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();
     }
 }
Пример #9
0
 /**
  * Helper for createLoaderURL()
  *
  * @since 1.24
  * @see makeLoaderQuery
  * @param ResourceLoaderContext $context
  * @param array $extraQuery
  * @return array
  */
 public static function createLoaderQuery(ResourceLoaderContext $context, $extraQuery = array())
 {
     return self::makeLoaderQuery($context->getModules(), $context->getLanguage(), $context->getSkin(), $context->getUser(), $context->getVersion(), $context->getDebug(), $context->getOnly(), $context->getRequest()->getBool('printable'), $context->getRequest()->getBool('handheld'), $extraQuery);
 }
Пример #10
0
 /**
  * Get the URL or URLs to load for this module's CSS in debug mode.
  * The default behavior is to return a load.php?only=styles URL for
  * the module, but file-based modules will want to override this to
  * load the files directly. See also getScriptURLsForDebug()
  *
  * @param $context ResourceLoaderContext: Context object
  * @return Array: array( mediaType => array( URL1, URL2, ... ), ... )
  */
 public function getStyleURLsForDebug(ResourceLoaderContext $context)
 {
     $url = ResourceLoader::makeLoaderURL(array($this->getName()), $context->getLanguage(), $context->getSkin(), $context->getUser(), $context->getVersion(), true, 'styles', $context->getRequest()->getBool('printable'), $context->getRequest()->getBool('handheld'));
     return array('all' => array($url));
 }
Пример #11
0
 /**
  * Get the URL or URLs to load for this module's CSS in debug mode.
  * The default behavior is to return a load.php?only=styles URL for
  * the module, but file-based modules will want to override this to
  * load the files directly. See also getScriptURLsForDebug()
  * 
  * @param $context ResourceLoaderContext: Context object
  * @return Array: array( mediaType => array( URL1, URL2, ... ), ... )
  */
 public function getStyleURLsForDebug(ResourceLoaderContext $context)
 {
     global $wgLoadScript;
     // TODO factor out to ResourceLoader static method and deduplicate from makeResourceLoaderLink()
     $query = array('modules' => $this->getName(), 'only' => 'styles', 'skin' => $context->getSkin(), 'user' => $context->getUser(), 'debug' => 'true', 'version' => $context->getVersion());
     ksort($query);
     return array('all' => array(wfAppendQuery($wgLoadScript, $query) . '&*'));
 }