r28151 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r28150‎ | r28151 | r28152 >
Date:20:32, 4 December 2007
Author:catrope
Status:old
Tags:
Comment:
* (bug 12195) Introducing 'undelete' right, which is required for restoring deleted revisions. Granted to sysops by default.
* Fixing whacky indentation in ApiQueryDeletedrevs.php introduced in r28148
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/SpecialUndelete.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryDeletedrevs.php (modified) (history)
  • /trunk/phase3/includes/api/ApiUndelete.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryDeletedrevs.php
@@ -39,194 +39,192 @@
4040 parent :: __construct($query, $moduleName, 'dr');
4141 }
4242
43 - public function execute() {
44 - $this->run();
45 - }
 43+ private function execute() {
4644
47 - private function run() {
48 -
4945 global $wgUser;
5046 // Before doing anything at all, let's check permissions
5147 if(!$wgUser->isAllowed('deletedhistory'))
52 - $this->dieUsage('You don\'t have permission to view deleted revisions', 'permissiondenied');
 48+ $this->dieUsage('You don\'t have permission to view deleted revision information', 'permissiondenied');
5349
54 - $db = $this->getDB();
55 - $params = $this->extractRequestParams();
56 - $prop = array_flip($params['prop']);
57 - $fld_revid = isset($prop['revid']);
58 - $fld_user = isset($prop['user']);
59 - $fld_comment = isset($prop['comment']);
60 - $fld_minor = isset($prop['minor']);
61 - $fld_len = isset($prop['len']);
62 - $fld_content = isset($prop['content']);
63 - $fld_token = isset($prop['token']);
 50+ $db = $this->getDB();
 51+ $params = $this->extractRequestParams();
 52+ $prop = array_flip($params['prop']);
 53+ $fld_revid = isset($prop['revid']);
 54+ $fld_user = isset($prop['user']);
 55+ $fld_comment = isset($prop['comment']);
 56+ $fld_minor = isset($prop['minor']);
 57+ $fld_len = isset($prop['len']);
 58+ $fld_content = isset($prop['content']);
 59+ $fld_token = isset($prop['token']);
6460
65 - $result = $this->getResult();
66 - $pageSet = $this->getPageSet();
67 - $titles = $pageSet->getTitles();
68 - $data = array();
 61+ $result = $this->getResult();
 62+ $pageSet = $this->getPageSet();
 63+ $titles = $pageSet->getTitles();
 64+ $data = array();
6965
70 - $this->addTables('archive');
71 - $this->addFields(array('ar_title', 'ar_namespace', 'ar_timestamp'));
72 - if($fld_revid)
73 - $this->addFields('ar_rev_id');
74 - if($fld_user)
75 - $this->addFields('ar_user_text');
76 - if($fld_comment)
77 - $this->addFields('ar_comment');
78 - if($fld_minor)
79 - $this->addFields('ar_minor_edit');
80 - if($fld_len)
81 - $this->addFields('ar_len');
82 - if($fld_content)
83 - {
84 - $this->addTables('text');
85 - $this->addFields(array('ar_text', 'ar_text_id', 'old_text', 'old_flags'));
86 - $this->addWhere('ar_text_id = old_id');
87 -
88 - // This also means stricter limits
89 - $userMax = 50;
90 - $botMax = 200;
91 - $this->validateLimit('limit', $params['limit'], 1, $userMax, $botMax);
92 - }
93 - if($fld_token)
94 - // Undelete tokens are identical for all pages, so we cache one here
95 - $token = $wgUser->editToken();
96 -
97 - // We need a custom WHERE clause that matches all titles.
98 - if(count($titles) > 0)
99 - {
100 - $lb = new LinkBatch($titles);
101 - $where = $lb->constructSet('ar', $db);
102 - $this->addWhere($where);
103 - }
104 -
105 - $this->addOption('LIMIT', $params['limit'] + 1);
106 - $this->addWhereRange('ar_timestamp', $params['dir'], $params['start'], $params['end']);
107 - if(isset($params['namespace']))
108 - $this->addWhereFld('ar_namespace', $params['namespace']);
109 - $res = $this->select(__METHOD__);
110 - $pages = array();
111 - $count = 0;
112 - // First populate the $pages array
113 - while($row = $db->fetchObject($res))
114 - {
115 - if($count++ == $params['limit'])
116 - {
117 - // We've had enough
118 - $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->ar_timestamp));
119 - break;
120 - }
121 -
122 - $rev = array();
123 - $rev['timestamp'] = wfTimestamp(TS_ISO_8601, $row->ar_timestamp);
 66+ $this->addTables('archive');
 67+ $this->addFields(array('ar_title', 'ar_namespace', 'ar_timestamp'));
12468 if($fld_revid)
125 - $rev['revid'] = $row->ar_rev_id;
 69+ $this->addFields('ar_rev_id');
12670 if($fld_user)
127 - $rev['user'] = $row->ar_user_text;
 71+ $this->addFields('ar_user_text');
12872 if($fld_comment)
129 - $rev['comment'] = $row->ar_comment;
 73+ $this->addFields('ar_comment');
13074 if($fld_minor)
131 - if($row->ar_minor_edit == 1)
132 - $rev['minor'] = '';
 75+ $this->addFields('ar_minor_edit');
13376 if($fld_len)
134 - $rev['len'] = $row->ar_len;
 77+ $this->addFields('ar_len');
13578 if($fld_content)
136 - ApiResult::setContent($rev, Revision::getRevisionText($row));
137 -
138 - $t = Title::makeTitle($row->ar_namespace, $row->ar_title);
139 - if(!isset($pages[$t->getPrefixedText()]))
14079 {
141 - $pages[$t->getPrefixedText()] = array(
142 - 'title' => $t->getPrefixedText(),
143 - 'ns' => intval($row->ar_namespace),
144 - 'revisions' => array($rev)
145 - );
 80+ $this->addTables('text');
 81+ $this->addFields(array('ar_text', 'ar_text_id', 'old_text', 'old_flags'));
 82+ $this->addWhere('ar_text_id = old_id');
 83+
 84+ // This also means stricter limits and stricter restrictions
 85+ if(!$wgUser->isAllowed('undelete'))
 86+ $this->dieUsage('You don\'t have permission to view deleted revision content', 'permissiondenied');
 87+ $userMax = 50;
 88+ $botMax = 200;
 89+ $this->validateLimit('limit', $params['limit'], 1, $userMax, $botMax);
 90+ }
14691 if($fld_token)
147 - $pages[$t->getPrefixedText()]['token'] = $token;
 92+ // Undelete tokens are identical for all pages, so we cache one here
 93+ $token = $wgUser->editToken();
 94+
 95+ // We need a custom WHERE clause that matches all titles.
 96+ if(count($titles) > 0)
 97+ {
 98+ $lb = new LinkBatch($titles);
 99+ $where = $lb->constructSet('ar', $db);
 100+ $this->addWhere($where);
148101 }
149 - else
150 - $pages[$t->getPrefixedText()]['revisions'][] = $rev;
151 - }
152 - $db->freeResult($res);
153102
154 - // We don't want entire pagenames as keys, so let's make this array indexed
155 - foreach($pages as $page)
156 - {
157 - $result->setIndexedTagName($page['revisions'], 'rev');
158 - $data[] = $page;
159 - }
160 - $result->setIndexedTagName($data, 'page');
161 - $result->addValue('query', $this->getModuleName(), $data);
162 - }
 103+ $this->addOption('LIMIT', $params['limit'] + 1);
 104+ $this->addWhereRange('ar_timestamp', $params['dir'], $params['start'], $params['end']);
 105+ if(isset($params['namespace']))
 106+ $this->addWhereFld('ar_namespace', $params['namespace']);
 107+ $res = $this->select(__METHOD__);
 108+ $pages = array();
 109+ $count = 0;
 110+ // First populate the $pages array
 111+ while($row = $db->fetchObject($res))
 112+ {
 113+ if($count++ == $params['limit'])
 114+ {
 115+ // We've had enough
 116+ $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->ar_timestamp));
 117+ break;
 118+ }
163119
 120+ $rev = array();
 121+ $rev['timestamp'] = wfTimestamp(TS_ISO_8601, $row->ar_timestamp);
 122+ if($fld_revid)
 123+ $rev['revid'] = $row->ar_rev_id;
 124+ if($fld_user)
 125+ $rev['user'] = $row->ar_user_text;
 126+ if($fld_comment)
 127+ $rev['comment'] = $row->ar_comment;
 128+ if($fld_minor)
 129+ if($row->ar_minor_edit == 1)
 130+ $rev['minor'] = '';
 131+ if($fld_len)
 132+ $rev['len'] = $row->ar_len;
 133+ if($fld_content)
 134+ ApiResult::setContent($rev, Revision::getRevisionText($row));
 135+
 136+ $t = Title::makeTitle($row->ar_namespace, $row->ar_title);
 137+ if(!isset($pages[$t->getPrefixedText()]))
 138+ {
 139+ $pages[$t->getPrefixedText()] = array(
 140+ 'title' => $t->getPrefixedText(),
 141+ 'ns' => intval($row->ar_namespace),
 142+ 'revisions' => array($rev)
 143+ );
 144+ if($fld_token)
 145+ $pages[$t->getPrefixedText()]['token'] = $token;
 146+ }
 147+ else
 148+ $pages[$t->getPrefixedText()]['revisions'][] = $rev;
 149+ }
 150+ $db->freeResult($res);
 151+
 152+ // We don't want entire pagenames as keys, so let's make this array indexed
 153+ foreach($pages as $page)
 154+ {
 155+ $result->setIndexedTagName($page['revisions'], 'rev');
 156+ $data[] = $page;
 157+ }
 158+ $result->setIndexedTagName($data, 'page');
 159+ $result->addValue('query', $this->getModuleName(), $data);
 160+ }
 161+
164162 protected function getAllowedParams() {
165 - return array (
166 - 'start' => array(
167 - ApiBase :: PARAM_TYPE => 'timestamp'
168 - ),
169 - 'end' => array(
170 - ApiBase :: PARAM_TYPE => 'timestamp',
171 - ),
172 - 'dir' => array(
173 - ApiBase :: PARAM_TYPE => array(
174 - 'newer',
175 - 'older'
176 - ),
177 - ApiBase :: PARAM_DFLT => 'older'
178 - ),
179 - 'namespace' => array(
180 - ApiBase :: PARAM_ISMULTI => true,
181 - ApiBase :: PARAM_TYPE => 'namespace'
182 - ),
183 - 'limit' => array(
184 - ApiBase :: PARAM_DFLT => 10,
185 - ApiBase :: PARAM_TYPE => 'limit',
186 - ApiBase :: PARAM_MIN => 1,
187 - ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
188 - ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
189 - ),
190 - 'prop' => array(
191 - ApiBase :: PARAM_DFLT => 'user|comment',
192 - ApiBase :: PARAM_TYPE => array(
193 - 'revid',
194 - 'user',
195 - 'comment',
196 - 'minor',
197 - 'len',
198 - 'content',
199 - 'token'
 163+ return array (
 164+ 'start' => array(
 165+ ApiBase :: PARAM_TYPE => 'timestamp'
200166 ),
201 - ApiBase :: PARAM_ISMULTI => true
202 - )
203 - );
 167+ 'end' => array(
 168+ ApiBase :: PARAM_TYPE => 'timestamp',
 169+ ),
 170+ 'dir' => array(
 171+ ApiBase :: PARAM_TYPE => array(
 172+ 'newer',
 173+ 'older'
 174+ ),
 175+ ApiBase :: PARAM_DFLT => 'older'
 176+ ),
 177+ 'namespace' => array(
 178+ ApiBase :: PARAM_ISMULTI => true,
 179+ ApiBase :: PARAM_TYPE => 'namespace'
 180+ ),
 181+ 'limit' => array(
 182+ ApiBase :: PARAM_DFLT => 10,
 183+ ApiBase :: PARAM_TYPE => 'limit',
 184+ ApiBase :: PARAM_MIN => 1,
 185+ ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
 186+ ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
 187+ ),
 188+ 'prop' => array(
 189+ ApiBase :: PARAM_DFLT => 'user|comment',
 190+ ApiBase :: PARAM_TYPE => array(
 191+ 'revid',
 192+ 'user',
 193+ 'comment',
 194+ 'minor',
 195+ 'len',
 196+ 'content',
 197+ 'token'
 198+ ),
 199+ ApiBase :: PARAM_ISMULTI => true
 200+ )
 201+ );
204202 }
205203
206204 protected function getParamDescription() {
207 - return array (
208 - 'start' => 'The timestamp to start enumerating from',
209 - 'end' => 'The timestamp to stop enumerating at',
210 - 'dir' => 'The direction in which to enumerate',
211 - 'namespace' => 'The namespaces to search in',
212 - 'limit' => 'The maximum amount of revisions to list',
213 - 'prop' => 'Which properties to get'
214 - );
 205+ return array (
 206+ 'start' => 'The timestamp to start enumerating from',
 207+ 'end' => 'The timestamp to stop enumerating at',
 208+ 'dir' => 'The direction in which to enumerate',
 209+ 'namespace' => 'The namespaces to search in',
 210+ 'limit' => 'The maximum amount of revisions to list',
 211+ 'prop' => 'Which properties to get'
 212+ );
215213 }
216214
217215 protected function getDescription() {
218 - return 'List deleted revisions.';
 216+ return 'List deleted revisions.';
219217 }
220218
221219 protected function getExamples() {
222 - return array (
223 - 'List the first 50 deleted revisions in the Category and Category talk namespaces',
224 - ' api.php?action=query&list=deletedrevs&drdir=newer&drlimit=50&drnamespace=14|15',
225 - 'List the last deleted revisions of Main Page and Talk:Main Page, with content:',
226 - ' api.php?action=query&list=deletedrevs&titles=Main%20Page|Talk:Main%20Page&drprop=user|comment|content'
227 - );
 220+ return array (
 221+ 'List the first 50 deleted revisions in the Category and Category talk namespaces',
 222+ ' api.php?action=query&list=deletedrevs&drdir=newer&drlimit=50&drnamespace=14|15',
 223+ 'List the last deleted revisions of Main Page and Talk:Main Page, with content:',
 224+ ' api.php?action=query&list=deletedrevs&titles=Main%20Page|Talk:Main%20Page&drprop=user|comment|content'
 225+ );
228226 }
229227
230228 public function getVersion() {
231 - return __CLASS__ . ': $Id: ApiQueryDeletedrevs.php 23531 2007-06-30 01:19:14Z simetrical $';
 229+ return __CLASS__ . ': $Id: ApiQueryDeletedrevs.php 23531 2007-06-30 01:19:14Z simetrical $';
232230 }
233231 }
Index: trunk/phase3/includes/api/ApiUndelete.php
@@ -47,7 +47,7 @@
4848 if(!isset($params['token']))
4949 $this->dieUsage('The token parameter must be set', 'notoken');
5050
51 - if(!$wgUser->isAllowed('delete'))
 51+ if(!$wgUser->isAllowed('undelete'))
5252 $this->dieUsage('You don\'t have permission to restore deleted revisions', 'permissiondenied');
5353 if($wgUser->isBlocked())
5454 $this->dieUsage('You have been blocked from editing', 'blocked');
Index: trunk/phase3/includes/SpecialUndelete.php
@@ -544,7 +544,7 @@
545545 if( $par != "" ) {
546546 $this->mTarget = $par;
547547 }
548 - if ( $wgUser->isAllowed( 'delete' ) && !$wgUser->isBlocked() ) {
 548+ if ( $wgUser->isAllowed( 'undelete' ) && !$wgUser->isBlocked() ) {
549549 $this->mAllowed = true;
550550 } else {
551551 $this->mAllowed = false;
Index: trunk/phase3/includes/DefaultSettings.php
@@ -1085,6 +1085,7 @@
10861086 $wgGroupPermissions['sysop']['createaccount'] = true;
10871087 $wgGroupPermissions['sysop']['delete'] = true;
10881088 $wgGroupPermissions['sysop']['deletedhistory'] = true; // can view deleted history entries, but not see or restore the text
 1089+$wgGroupPermissions['sysop']['undelete'] = true;
10891090 $wgGroupPermissions['sysop']['editinterface'] = true;
10901091 $wgGroupPermissions['sysop']['editusercssjs'] = true;
10911092 $wgGroupPermissions['sysop']['import'] = true;
Index: trunk/phase3/RELEASE-NOTES
@@ -87,6 +87,7 @@
8888 does not exists
8989 * (bug 8396) Ignore out-of-date serialised message caches
9090 * Add descriptive <title> to revision difference page
 91+* (bug 12195) Undeleting pages now requires 'undelete' permission
9192
9293 === Bug fixes in 1.12 ===
9394

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r28148Removing double tabs inserted due to my editor's retarded tabsize=4 setting.catrope16:33, 4 December 2007

Status & tagging log