r16692 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r16691‎ | r16692 | r16693 >
Date:07:29, 29 September 2006
Author:yurik
Status:old
Tags:
Comment:
* API: revisions module fixes
Modified paths:
  • /trunk/phase3/includes/api/ApiPageSet.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQuery.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryRevisions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQuery.php
@@ -96,45 +96,25 @@
9797 * #5 Execute all requested modules
9898 */
9999 public function execute() {
100 - $meta = $prop = $list = $generator = $titles = $pageids = $revids = null;
 100+ $meta = $prop = $list = $generator = $titles = $pageids = null;
101101 $redirects = null;
102102 extract($this->extractRequestParams());
103103
104104 //
105105 // Create and initialize PageSet
106106 //
107 - // Only one of the titles/pageids/revids is allowed at the same time
108107 $dataSource = null;
109 - if (isset ($titles))
110 - $dataSource = 'titles';
111 - if (isset ($pageids)) {
112 - if (isset ($dataSource))
113 - $this->dieUsage("Cannot use 'pageids' at the same time as '$dataSource'", 'multisource');
114 - $dataSource = 'pageids';
115 - }
116 - if (isset ($revids)) {
117 - if (isset ($dataSource))
118 - $this->dieUsage("Cannot use 'revids' at the same time as '$dataSource'", 'multisource');
119 - $dataSource = 'revids';
120 - }
 108+ if (isset ($titles) && isset($pageids))
 109+ $this->dieUsage("At present you may not use titles= and pageids= at the same time", 'multisource');
121110
122111 $this->mData = new ApiPageSet($this, $redirects);
123112
124 - switch ($dataSource) {
125 - case 'titles' :
126 - $this->mData->populateTitles($titles);
127 - break;
128 - case 'pageids' :
129 - $this->mData->populatePageIDs($pageids);
130 - break;
131 - case 'titles' :
132 - $this->mData->populateRevIDs($revids);
133 - break;
134 - default :
135 - // Do nothing - some queries do not need any of the data sources.
136 - break;
137 - }
 113+ if (isset($titles))
 114+ $this->mData->populateTitles($titles);
138115
 116+ if (isset($pageids))
 117+ $this->mData->populatePageIDs($pageids);
 118+
139119 //
140120 // If generator is provided, get a new dataset to work on
141121 //
@@ -159,7 +139,8 @@
160140 foreach ($this->mData->getNormalizedTitles() as $rawTitleStr => $titleStr) {
161141 $this->getResult()->addMessage('query', 'normalized', array (
162142 'from' => $rawTitleStr,
163 - 'to' => $titleStr
 143+ 'to' => $titleStr,
 144+ '*' => ''
164145 ), 'n');
165146 }
166147
@@ -168,7 +149,8 @@
169150 foreach ($this->mData->getRedirectTitles() as $titleStrFrom => $titleStrTo) {
170151 $this->getResult()->addMessage('query', 'redirects', array (
171152 'from' => $titleStrFrom,
172 - 'to' => $titleStrTo
 153+ 'to' => $titleStrTo,
 154+ '*' => ''
173155 ), 'r');
174156 }
175157 }
@@ -224,10 +206,6 @@
225207 // GN_ENUM_TYPE => 'integer',
226208 // GN_ENUM_ISMULTI => true
227209 // ),
228 - // 'revids' => array (
229 - // GN_ENUM_TYPE => 'integer',
230 - // GN_ENUM_ISMULTI => true
231 - // ),
232210 'redirects' => false
233211 );
234212 }
@@ -280,7 +258,6 @@
281259 'generator' => 'Use the output of a list as the input for other prop/list/meta items',
282260 'titles' => 'A list of titles to work on',
283261 'pageids' => 'A list of page IDs to work on',
284 - 'revids' => 'A list of revision IDs to work on',
285262 'redirects' => 'Automatically resolve redirects'
286263 );
287264 }
Index: trunk/phase3/includes/api/ApiQueryRevisions.php
@@ -36,7 +36,7 @@
3737 }
3838
3939 public function execute() {
40 - $rvlimit = $rvstartid = $rvendid = $rvstart = $rvend = $rvdir = $rvprop = null;
 40+ $rvrevids = $rvlimit = $rvstartid = $rvendid = $rvstart = $rvend = $rvdir = $rvprop = null;
4141 extract($this->extractRequestParams());
4242
4343 //
@@ -46,17 +46,31 @@
4747 // true when ordered by timestamp from older to newer, false otherwise
4848 $dirNewer = ($rvdir === 'newer');
4949
50 - // If any of those parameters are used, we work with single page only
51 - $singePageMode = ($rvlimit !== 0 || $rvstartid !== 0 || $rvendid !== 0 || $dirNewer || isset ($rvstart) || isset ($rvend));
 50+ // If any of those parameters are used, we can only work with a single page
 51+ // Enumerating revisions on multiple pages make it extremelly
 52+ // difficult to manage continuations and require additional sql indexes
 53+ $enumRevMode = ($rvlimit !== 0 || $rvstartid !== 0 || $rvendid !== 0 || $dirNewer || isset ($rvstart) || isset ($rvend));
5254
5355 if ($rvstartid !== 0 || $rvendid !== 0)
5456 $this->dieUsage('rvstartid/rvendid not implemented', 'notimplemented');
5557
5658 $data = $this->getData();
5759 $pageCount = $data->getPageCount();
58 - if ($singePageMode && $pageCount > 1)
59 - $this->dieUsage('You have supplied multiple pages, but the specified revisions parameters may only be used with one page.', 'rv_multpages');
6060
 61+ if (!empty ($rvrevids)) {
 62+ if ($pageCount > 0)
 63+ $this->dieUsage('The rvrevids= parameter may not be used with titles, pageids, and generator options.', 'rv_rvrevids');
 64+
 65+ if ($enumRevMode)
 66+ $this->dieUsage('The rvrevids= parameter may not be used with the list options (rvlimit, rvstartid, rvendid, dirNewer, rvstart, rvend).', 'rv_rvrevids');
 67+ } else {
 68+ if ($pageCount < 1)
 69+ $this->dieUsage('No pages were given. Please use titles, pageids or a generator to provide page(s) to work on.', 'rv_no_pages');
 70+
 71+ if ($enumRevMode && $pageCount > 1)
 72+ $this->dieUsage('titles, pageids or a generator was used to supply multiple pages, but the rvlimit, rvstartid, rvendid, dirNewer, rvstart, and rvend parameters may only be used on a single page.', 'rv_multpages');
 73+ }
 74+
6175 $tables = array (
6276 'revision'
6377 );
@@ -97,6 +111,7 @@
98112 $fields[] = 'old_id';
99113 $fields[] = 'old_text';
100114 $fields[] = 'old_flags';
 115+ $showContent = true;
101116 break;
102117 default :
103118 $this->dieDebug("unknown rvprop $prop");
@@ -104,25 +119,43 @@
105120 }
106121 }
107122
108 - if (isset ($rvstart))
109 - $conds[] = 'rev_timestamp >= ' . $this->prepareTimestamp($rvstart);
110 - if (isset ($rvend))
111 - $conds[] = 'rev_timestamp <= ' . $this->prepareTimestamp($rvend);
 123+ $userMax = ($showContent ? 50 : 500);
 124+ $botMax = ($showContent ? 200 : 10000);
112125
113 - if ($singePageMode) {
 126+ if ($enumRevMode) {
 127+
 128+ if (isset ($rvstart))
 129+ $conds[] = 'rev_timestamp >= ' . $this->prepareTimestamp($rvstart);
 130+ if (isset ($rvend))
 131+ $conds[] = 'rev_timestamp <= ' . $this->prepareTimestamp($rvend);
 132+
 133+ // must manually initialize unset rvlimit
114134 if (!isset ($rvlimit))
115135 $rvlimit = 10;
116136
117 - $options['LIMIT'] = $rvlimit + 1;
118137 $options['ORDER BY'] = 'rev_timestamp' . ($dirNewer ? '' : ' DESC');
119 -
120 - // get the first (and only) pageid => title pair
121 - foreach($data->getGoodTitles() as $pageId => $titleObj) {
122 - $conds['rev_page'] = $pageId;
123 - break;
124 - }
 138+
 139+ $this->validateLimit('rvlimit', $rvlimit, 1, $userMax, $botMax);
 140+
 141+ // There is only one ID
 142+ $conds['rev_page'] = array_keys($data->getGoodTitles());
 143+
 144+ } else {
 145+ // When working in multi-page non-enumeration mode,
 146+ // limit to the latest revision only
 147+ $tables[] = 'page';
 148+ $conds[] = 'page_id=rev_page';
 149+ $conds[] = 'page_latest=rev_id';
 150+ $this->validateLimit('page_count', $pageCount, 1, $userMax, $botMax);
 151+
 152+ // Get all page IDs
 153+ $conds['page_id'] = array_keys($data->getGoodTitles());
 154+
 155+ $rvlimit = $pageCount; // assumption testing -- we should never get more then $pageCount rows.
125156 }
126157
 158+ $options['LIMIT'] = $rvlimit +1;
 159+
127160 $db = $this->getDB();
128161 $this->profileDBIn();
129162 $res = $db->select($tables, $fields, $conds, __CLASS__ . '::' . __FUNCTION__, $options);
@@ -134,31 +167,32 @@
135168
136169 if (++ $count > $rvlimit) {
137170 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
 171+ if (!$enumRevMode)
 172+ $this->dieDebug('Got more rows then expected'); // bug report
 173+
138174 $startStr = 'rvstartid=' . $row->rev_id;
139 - $msg = array ('continue' => $startStr );
 175+ $msg = array (
 176+ 'continue' => $startStr
 177+ );
140178 $this->getResult()->addMessage('query-status', 'revisions', $msg);
141179 break;
142180 }
143181
144 -
145 - $revid = intval($row->rev_id);
146 - $pageid = intval($row->rev_page);
147 -
148182 $vals = array (
149 - 'revid' => $revid,
 183+ 'revid' => intval($row->rev_id),
150184 'oldid' => intval($row->rev_text_id
151185 ));
152186
153 - if( $row->rev_minor_edit ) {
 187+ if ($row->rev_minor_edit) {
154188 $vals['minor'] = '';
155189 }
156 -
 190+
157191 if ($showTimestamp)
158192 $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $row->rev_timestamp);
159 -
 193+
160194 if ($showUser) {
161195 $vals['user'] = $row->rev_user_text;
162 - if( !$row->rev_user )
 196+ if (!$row->rev_user)
163197 $vals['anon'] = '';
164198 }
165199
@@ -167,13 +201,13 @@
168202
169203 if ($showContent) {
170204 $vals['xml:space'] = 'preserve';
171 - $vals['*'] = Revision::getRevisionText( $row );
 205+ $vals['*'] = Revision :: getRevisionText($row);
172206 } else {
173 - $vals['*'] = ''; // Force all elements to be attributes
 207+ $vals['*'] = ''; // Force all elements to be attributes
174208 }
175209
176 - $data[$pageid]['revisions']['_element'] = 'rv';
177 - $data[$pageid]['revisions'][$revid] = $vals;
 210+ $data[$row->rev_page]['revisions']['_element'] = 'rv';
 211+ $data[$row->rev_page]['revisions'][$row->rev_id] = $vals;
178212 }
179213 $db->freeResult($res);
180214
@@ -182,6 +216,10 @@
183217
184218 protected function getAllowedParams() {
185219 return array (
 220+ 'rvrevids' => array (
 221+ GN_ENUM_ISMULTI => true,
 222+ GN_ENUM_TYPE => 'integer'
 223+ ),
186224 'rvlimit' => array (
187225 GN_ENUM_DFLT => 0,
188226 GN_ENUM_TYPE => 'limit',
Index: trunk/phase3/includes/api/ApiPageSet.php
@@ -83,7 +83,7 @@
8484 * Returns the number of unique pages (not revisions) in the set.
8585 */
8686 public function getPageCount() {
87 - return count($this->getGoodTitles());
 87+ return count($this->getGoodTitles());
8888 }
8989
9090 /**
@@ -176,7 +176,7 @@
177177 'pl_from' => array_keys($redirectIds
178178 )), __CLASS__ . '::' . __FUNCTION__);
179179 $this->profileDBOut();
180 -
 180+
181181 while ($row = $db->fetchObject($res)) {
182182
183183 // Bug 7304 workaround
@@ -199,9 +199,9 @@
200200 }
201201 $db->freeResult($res);
202202 }
203 - $this->profileOut();
 203+ $this->profileOut();
204204 }
205 -
 205+
206206 /**
207207 * Given an array of title strings, convert them into Title objects.
208208 * This method validates access rights for the title,
@@ -237,6 +237,10 @@
238238 return $linkBatch;
239239 }
240240
 241+ public function populatePageIDs($pageids) {
 242+ $this->dieUsage(__FUNCTION__ . " is not implemented", 'notimplemented');
 243+ }
 244+
241245 public function execute() {
242246 $this->dieDebug("execute() is not supported on this object");
243247 }