Esempio n. 1
0
 private function getTokenTypes()
 {
     // If we're in a mode that breaks the same-origin policy, no tokens can
     // be obtained
     if ($this->lacksSameOriginSecurity()) {
         return [];
     }
     static $types = null;
     if ($types) {
         return $types;
     }
     $types = ['patrol' => ['ApiQueryRecentChanges', 'getPatrolToken']];
     $names = ['edit', 'delete', 'protect', 'move', 'block', 'unblock', 'email', 'import', 'watch', 'options'];
     foreach ($names as $name) {
         $types[$name] = ['ApiQueryInfo', 'get' . ucfirst($name) . 'Token'];
     }
     Hooks::run('ApiTokensGetTokenTypes', [&$types]);
     // For forwards-compat, copy any token types from ApiQueryTokens that
     // we don't already have something for.
     $user = $this->getUser();
     $request = $this->getRequest();
     foreach (ApiQueryTokens::getTokenTypeSalts() as $name => $salt) {
         if (!isset($types[$name])) {
             $types[$name] = function () use($salt, $user, $request) {
                 return ApiQueryTokens::getToken($user, $request->getSession(), $salt)->toString();
             };
         }
     }
     ksort($types);
     return $types;
 }
Esempio n. 2
0
 /**
  * Validate the supplied token.
  *
  * @since 1.24
  * @param string $token Supplied token
  * @param array $params All supplied parameters for the module
  * @return bool
  * @throws MWException
  */
 public final function validateToken($token, array $params)
 {
     $tokenType = $this->needsToken();
     $salts = ApiQueryTokens::getTokenTypeSalts();
     if (!isset($salts[$tokenType])) {
         throw new MWException("Module '{$this->getModuleName()}' tried to use token type '{$tokenType}' " . 'without registering it');
     }
     if ($this->getUser()->matchEditToken($token, $salts[$tokenType], $this->getRequest())) {
         return true;
     }
     $webUiSalt = $this->getWebUITokenSalt($params);
     if ($webUiSalt !== null && $this->getUser()->matchEditToken($token, $webUiSalt, $this->getRequest())) {
         return true;
     }
     return false;
 }
Esempio n. 3
0
 public function getAllowedParams()
 {
     return array('type' => array(ApiBase::PARAM_TYPE => array_keys(ApiQueryTokens::getTokenTypeSalts()), ApiBase::PARAM_REQUIRED => true), 'token' => array(ApiBase::PARAM_TYPE => 'string', ApiBase::PARAM_REQUIRED => true), 'maxtokenage' => array(ApiBase::PARAM_TYPE => 'integer'));
 }