本文整理汇总了PHP中ResourceLoaderContext::getUser方法的典型用法代码示例。如果您正苦于以下问题:PHP ResourceLoaderContext::getUser方法的具体用法?PHP ResourceLoaderContext::getUser怎么用?PHP ResourceLoaderContext::getUser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ResourceLoaderContext
的用法示例。
在下文中一共展示了ResourceLoaderContext::getUser方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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();
}
示例2: 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;
}
示例3: getUser
public function getUser()
{
if ($this->user === self::INHERIT_VALUE) {
return $this->context->getUser();
}
return $this->user;
}
示例4: 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;
}
示例5: getUser
public function getUser()
{
if (!is_null($this->user)) {
return $this->user;
} else {
return $this->context->getUser();
}
}
示例6: getPages
/**
* @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();
}
示例7: 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());
}
示例8: 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();
}
}
示例9: createLoaderQuery
/**
* 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: getStyleURLsForDebug
/**
* 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: getStyleURLsForDebug
/**
* 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) . '&*'));
}