本文整理汇总了PHP中IContextSource::setUser方法的典型用法代码示例。如果您正苦于以下问题:PHP IContextSource::setUser方法的具体用法?PHP IContextSource::setUser怎么用?PHP IContextSource::setUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IContextSource
的用法示例。
在下文中一共展示了IContextSource::setUser方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: performRequest
/**
* Performs the request.
* - bad titles
* - read restriction
* - local interwiki redirects
* - redirect loop
* - special pages
* - normal pages
*
* @throws MWException|PermissionsError|BadTitleError|HttpError
* @return void
*/
private function performRequest()
{
global $wgTitle;
$request = $this->context->getRequest();
$requestTitle = $title = $this->context->getTitle();
$output = $this->context->getOutput();
$user = $this->context->getUser();
### <SANDSTORM>
global $wgAuth;
$name = array_key_exists('HTTP_X_SANDSTORM_USERNAME', $_SERVER) ? $_SERVER['HTTP_X_SANDSTORM_USERNAME'] : 'Public';
$name = urldecode($name);
$original_name = $name;
$id = array_key_exists('HTTP_X_SANDSTORM_USER_ID', $_SERVER) ? $_SERVER['HTTP_X_SANDSTORM_USER_ID'] : '';
$count = 2;
$isNew = false;
if ($user->isAnon()) {
$u = null;
do {
$u = User::newFromName($name, 'creatable');
// TODO
if (!is_object($u)) {
wfLogWarning('no name for ' . $name);
throw new BadTitleError();
}
if (0 != $u->idForName() && $u->getEmail() !== $id && !empty($id)) {
$name = $original_name . $count;
}
$count++;
} while (0 != $u->idForName() && $u->getEmail() !== $id && !empty($id));
if (0 == $u->idForName()) {
$permissions = array_key_exists('HTTP_X_SANDSTORM_PERMISSIONS', $_SERVER) ? $_SERVER['HTTP_X_SANDSTORM_PERMISSIONS'] : '';
$pass = sha1(mt_rand());
$u->setRealName($name);
$u->setEmail($id);
if (!$wgAuth->addUser($u, $pass, "", $name)) {
// TODO
wfLogWarning('externaldberror');
}
$this->initUser($u, $pass, false);
if (strpos($permissions, 'admin') !== false) {
wfLogWarning('setting user as admin: ' . $name);
$u->addGroup('sysop');
$u->addGroup('bureaucrat');
$u->saveSettings();
}
if (!empty($id)) {
$u->addGroup('editor');
$u->saveSettings();
}
$isNew = true;
}
// wfSetupSession();
// Not sure why, but I manually have to set session cookie
setcookie(session_name(), MWCryptRand::generateHex(32), 0, '/');
$u->setCookies();
wfResetSessionID();
$this->context->setUser($u);
$user = $this->context->getUser();
$wgUser = $u;
}
if ($isNew) {
wfRunHooks('AddNewAccount', array($u, false));
$u->addNewUserLogEntry('create');
$injected_html = '';
wfRunHooks('UserLoginComplete', array(&$u, &$injected_html));
$welcome_creation_msg = 'welcomecreation-msg';
wfRunHooks('BeforeWelcomeCreation', array(&$welcome_creation_msg, &$injected_html));
} else {
$injected_html = '';
wfRunHooks('UserLoginComplete', array(&$u, &$injected_html));
}
# </SANDSTORM>
if ($request->getVal('printable') === 'yes') {
$output->setPrintable();
}
$unused = null;
// To pass it by reference
Hooks::run('BeforeInitialize', array(&$title, &$unused, &$output, &$user, $request, $this));
// Invalid titles. Bug 21776: The interwikis must redirect even if the page name is empty.
if (is_null($title) || $title->getDBkey() == '' && !$title->isExternal() || $title->isSpecial('Badtitle')) {
$this->context->setTitle(SpecialPage::getTitleFor('Badtitle'));
throw new BadTitleError();
}
// Check user's permissions to read this page.
// We have to check here to catch special pages etc.
// We will check again in Article::view().
$permErrors = $title->isSpecial('RunJobs') ? array() : $title->getUserPermissionsErrors('read', $user);
if (count($permErrors)) {
//.........这里部分代码省略.........