return str_replace('_', ' ', $key);
}
+ public function getTokenFlag($tokenArr, $action) {
+ if (in_array($action, $tokenArr)) {
+ global $wgUser;
+ if ($wgUser->isAllowed($action))
+ return true;
+ else
+ $this->dieUsage("Action '$action' is not allowed for the current user", 'permissiondenied');
+ }
+ return false;
+ }
+
public static function getBaseVersion() {
return __CLASS__ . ': $Id$';
}
public function execute() {
+ global $wgUser;
+
$params = $this->extractRequestParams();
$fld_protection = false;
if(!is_null($params['prop'])) {
$prop = array_flip($params['prop']);
$fld_protection = isset($prop['protection']);
}
+ if(!is_null($params['token'])) {
+ $token = $params['token'];
+ $tok_edit = $this->getTokenFlag($token, 'edit');
+ $tok_delete = $this->getTokenFlag($token, 'delete');
+ $tok_protect = $this->getTokenFlag($token, 'protect');
+ $tok_move = $this->getTokenFlag($token, 'move');
+ }
$pageSet = $this->getPageSet();
$titles = $pageSet->getGoodTitles();
$db->freeResult($res);
}
- foreach ( $titles as $pageid => $unused ) {
+ foreach ( $titles as $pageid => $title ) {
$pageInfo = array (
'touched' => wfTimestamp(TS_ISO_8601, $pageTouched[$pageid]),
'lastrevid' => intval($pageLatest[$pageid]),
if ($pageIsNew[$pageid])
$pageInfo['new'] = '';
+ if (!is_null($token)) {
+ // Currently all tokens are generated the same way, but it might change
+ if ($tok_edit)
+ $pageInfo['edittoken'] = $wgUser->editToken();
+ if ($tok_delete)
+ $pageInfo['deletetoken'] = $wgUser->editToken();
+ if ($tok_protect)
+ $pageInfo['protecttoken'] = $wgUser->editToken();
+ if ($tok_move)
+ $pageInfo['movetoken'] = $wgUser->editToken();
+ }
+
if($fld_protection) {
if (isset($protections[$pageid])) {
$pageInfo['protection'] = $protections[$pageid];
ApiBase :: PARAM_ISMULTI => true,
ApiBase :: PARAM_TYPE => array (
'protection'
- ))
+ )),
+ 'token' => array (
+ ApiBase :: PARAM_DFLT => NULL,
+ ApiBase :: PARAM_ISMULTI => true,
+ ApiBase :: PARAM_TYPE => array (
+ 'edit',
+ 'delete',
+ 'protect',
+ 'move',
+ )),
);
}
'prop' => array (
'Which additional properties to get:',
' "protection" - List the protection level of each page'
- )
+ ),
+ 'token' => 'Request a token to perform a data-modifying action on a page',
);
}