r24533 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24532‎ | r24533 | r24534 >
Date:22:46, 1 August 2007
Author:yurik
Status:old
Tags:
Comment:
API: Added various edit tokens to prop=info (except rollback - will be added to revisions)
Modified paths:
  • /trunk/phase3/includes/api/ApiQueryBase.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryInfo.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryBase.php
@@ -214,6 +214,17 @@
215215 return str_replace('_', ' ', $key);
216216 }
217217
 218+ public function getTokenFlag($tokenArr, $action) {
 219+ if (in_array($action, $tokenArr)) {
 220+ global $wgUser;
 221+ if ($wgUser->isAllowed($action))
 222+ return true;
 223+ else
 224+ $this->dieUsage("Action '$action' is not allowed for the current user", 'permissiondenied');
 225+ }
 226+ return false;
 227+ }
 228+
218229 public static function getBaseVersion() {
219230 return __CLASS__ . ': $Id$';
220231 }
Index: trunk/phase3/includes/api/ApiQueryInfo.php
@@ -50,12 +50,21 @@
5151
5252 public function execute() {
5353
 54+ global $wgUser;
 55+
5456 $params = $this->extractRequestParams();
5557 $fld_protection = false;
5658 if(!is_null($params['prop'])) {
5759 $prop = array_flip($params['prop']);
5860 $fld_protection = isset($prop['protection']);
5961 }
 62+ if(!is_null($params['token'])) {
 63+ $token = $params['token'];
 64+ $tok_edit = $this->getTokenFlag($token, 'edit');
 65+ $tok_delete = $this->getTokenFlag($token, 'delete');
 66+ $tok_protect = $this->getTokenFlag($token, 'protect');
 67+ $tok_move = $this->getTokenFlag($token, 'move');
 68+ }
6069
6170 $pageSet = $this->getPageSet();
6271 $titles = $pageSet->getGoodTitles();
@@ -85,7 +94,7 @@
8695 $db->freeResult($res);
8796 }
8897
89 - foreach ( $titles as $pageid => $unused ) {
 98+ foreach ( $titles as $pageid => $title ) {
9099 $pageInfo = array (
91100 'touched' => wfTimestamp(TS_ISO_8601, $pageTouched[$pageid]),
92101 'lastrevid' => intval($pageLatest[$pageid]),
@@ -99,6 +108,18 @@
100109 if ($pageIsNew[$pageid])
101110 $pageInfo['new'] = '';
102111
 112+ if (!is_null($token)) {
 113+ // Currently all tokens are generated the same way, but it might change
 114+ if ($tok_edit)
 115+ $pageInfo['edittoken'] = $wgUser->editToken();
 116+ if ($tok_delete)
 117+ $pageInfo['deletetoken'] = $wgUser->editToken();
 118+ if ($tok_protect)
 119+ $pageInfo['protecttoken'] = $wgUser->editToken();
 120+ if ($tok_move)
 121+ $pageInfo['movetoken'] = $wgUser->editToken();
 122+ }
 123+
103124 if($fld_protection) {
104125 if (isset($protections[$pageid])) {
105126 $pageInfo['protection'] = $protections[$pageid];
@@ -122,7 +143,16 @@
123144 ApiBase :: PARAM_ISMULTI => true,
124145 ApiBase :: PARAM_TYPE => array (
125146 'protection'
126 - ))
 147+ )),
 148+ 'token' => array (
 149+ ApiBase :: PARAM_DFLT => NULL,
 150+ ApiBase :: PARAM_ISMULTI => true,
 151+ ApiBase :: PARAM_TYPE => array (
 152+ 'edit',
 153+ 'delete',
 154+ 'protect',
 155+ 'move',
 156+ )),
127157 );
128158 }
129159
@@ -131,7 +161,8 @@
132162 'prop' => array (
133163 'Which additional properties to get:',
134164 ' "protection" - List the protection level of each page'
135 - )
 165+ ),
 166+ 'token' => 'Request a token to perform a data-modifying action on a page',
136167 );
137168 }
138169

Follow-up revisions

RevisionCommit summaryAuthorDate
r24563apiedit: Merging latest revisions from trunk, expect r24533catrope12:05, 3 August 2007
r24631Merged revisions 24480-24600 via svnmerge from...david18:39, 6 August 2007

Status & tagging log