Index: trunk/phase3/includes/api/ApiQueryBase.php |
— | — | @@ -214,6 +214,17 @@ |
215 | 215 | return str_replace('_', ' ', $key); |
216 | 216 | } |
217 | 217 | |
| 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 | + |
218 | 229 | public static function getBaseVersion() { |
219 | 230 | return __CLASS__ . ': $Id$'; |
220 | 231 | } |
Index: trunk/phase3/includes/api/ApiQueryInfo.php |
— | — | @@ -50,12 +50,21 @@ |
51 | 51 | |
52 | 52 | public function execute() { |
53 | 53 | |
| 54 | + global $wgUser; |
| 55 | + |
54 | 56 | $params = $this->extractRequestParams(); |
55 | 57 | $fld_protection = false; |
56 | 58 | if(!is_null($params['prop'])) { |
57 | 59 | $prop = array_flip($params['prop']); |
58 | 60 | $fld_protection = isset($prop['protection']); |
59 | 61 | } |
| 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 | + } |
60 | 69 | |
61 | 70 | $pageSet = $this->getPageSet(); |
62 | 71 | $titles = $pageSet->getGoodTitles(); |
— | — | @@ -85,7 +94,7 @@ |
86 | 95 | $db->freeResult($res); |
87 | 96 | } |
88 | 97 | |
89 | | - foreach ( $titles as $pageid => $unused ) { |
| 98 | + foreach ( $titles as $pageid => $title ) { |
90 | 99 | $pageInfo = array ( |
91 | 100 | 'touched' => wfTimestamp(TS_ISO_8601, $pageTouched[$pageid]), |
92 | 101 | 'lastrevid' => intval($pageLatest[$pageid]), |
— | — | @@ -99,6 +108,18 @@ |
100 | 109 | if ($pageIsNew[$pageid]) |
101 | 110 | $pageInfo['new'] = ''; |
102 | 111 | |
| 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 | + |
103 | 124 | if($fld_protection) { |
104 | 125 | if (isset($protections[$pageid])) { |
105 | 126 | $pageInfo['protection'] = $protections[$pageid]; |
— | — | @@ -122,7 +143,16 @@ |
123 | 144 | ApiBase :: PARAM_ISMULTI => true, |
124 | 145 | ApiBase :: PARAM_TYPE => array ( |
125 | 146 | '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 | + )), |
127 | 157 | ); |
128 | 158 | } |
129 | 159 | |
— | — | @@ -131,7 +161,8 @@ |
132 | 162 | 'prop' => array ( |
133 | 163 | 'Which additional properties to get:', |
134 | 164 | ' "protection" - List the protection level of each page' |
135 | | - ) |
| 165 | + ), |
| 166 | + 'token' => 'Request a token to perform a data-modifying action on a page', |
136 | 167 | ); |
137 | 168 | } |
138 | 169 | |