/** * Get a token from a salt * @param User $user * @param MediaWiki\\Session\\Session $session * @param string|array $salt A string will be used as the salt for * User::getEditTokenObject() to fetch the token, which will give a * LoggedOutEditToken (always "+\\") for anonymous users. An array will * be used as parameters to MediaWiki\\Session\\Session::getToken(), which * will always return a full token even for anonymous users. An array will * also persist the session. * @return MediaWiki\\Session\\Token */ public static function getToken(User $user, MediaWiki\Session\Session $session, $salt) { if (is_array($salt)) { $session->persist(); return call_user_func_array(array($session, 'getToken'), $salt); } else { return $user->getEditTokenObject($salt, $session->getRequest()); } }
/** * @param array $data Array of *non*-urlencoded key => value pairs, the * fake GET/POST values * @param bool $wasPosted Whether to treat the data as POST * @param MediaWiki\Session\Session|array|null $session Session, session * data array, or null * @param string $protocol 'http' or 'https' * @throws MWException */ public function __construct($data = [], $wasPosted = false, $session = null, $protocol = 'http') { $this->requestTime = microtime(true); if (is_array($data)) { $this->data = $data; } else { throw new MWException("FauxRequest() got bogus data"); } $this->wasPosted = $wasPosted; if ($session instanceof MediaWiki\Session\Session) { $this->sessionId = $session->getSessionId(); } elseif (is_array($session)) { $mwsession = SessionManager::singleton()->getEmptySession($this); $this->sessionId = $mwsession->getSessionId(); foreach ($session as $key => $value) { $mwsession->set($key, $value); } } elseif ($session !== null) { throw new MWException("FauxRequest() got bogus session"); } $this->protocol = $protocol; }
/** * @param MediaWiki\\Session\\Session $session * @param string $key * @param mixed $value */ public static function setSessionData(MediaWiki\Session\Session $session, $key, $value) { $data = $session->get(self::SESSION_KEYNAME, array()); if (!is_array($data)) { $data = array(); } $data[$key] = $value; $session->set(self::SESSION_KEYNAME, $data); }