當前位置: 首頁>>代碼示例>>PHP>>正文


PHP IContextSource::setUser方法代碼示例

本文整理匯總了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)) {
//.........這裏部分代碼省略.........
開發者ID:paulproteus,項目名稱:semantic-mediawiki-sandstorm,代碼行數:101,代碼來源:MediaWiki.php


注:本文中的IContextSource::setUser方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。