r47216 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r47215‎ | r47216 | r47217 >
Date:15:36, 13 February 2009
Author:catrope
Status:deferred
Tags:
Comment:
* API: Page prop=info by (ns, title) rather than offset
* Also fix a regression from r47214 which caused database errors when $this->titles or $this->missing was empty
Modified paths:
  • /trunk/phase3/includes/api/ApiQueryInfo.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryInfo.php
@@ -207,6 +207,26 @@
208208 $this->everything = $this->titles + $this->missing;
209209 $result = $this->getResult();
210210
 211+ uasort($this->everything, array('Title', 'compare'));
 212+ if(!is_null($this->params['continue']))
 213+ {
 214+ // Throw away any titles we're gonna skip so they don't
 215+ // clutter queries
 216+ $cont = explode('|', $this->params['continue']);
 217+ if(count($cont) != 2)
 218+ $this->dieUsage("Invalid continue param. You should pass the original " .
 219+ "value returned by the previous query", "_badcontinue");
 220+ $conttitle = Title::makeTitleSafe($cont[0], $cont[1]);
 221+ foreach($this->everything as $pageid => $title)
 222+ {
 223+ if(Title::compare($title, $conttitle) >= 0)
 224+ break;
 225+ unset($this->titles[$pageid]);
 226+ unset($this->missing[$pageid]);
 227+ unset($this->everything[$pageid]);
 228+ }
 229+ }
 230+
211231 $this->pageRestrictions = $pageSet->getCustomField('page_restrictions');
212232 $this->pageIsRedir = $pageSet->getCustomField('page_is_redirect');
213233 $this->pageIsNew = $pageSet->getCustomField('page_is_new');
@@ -224,13 +244,7 @@
225245 if($this->fld_talkid || $this->fld_subjectid)
226246 $this->getTSIDs();
227247
228 - $count = 0;
229 - ksort($this->everything); // Ensure they're always in the same order
230248 foreach($this->everything as $pageid => $title) {
231 - $count++;
232 - if(!is_null($params['continue']))
233 - if($count < $params['continue'])
234 - continue;
235249 $pageInfo = $this->extractPageInfo($pageid, $title);
236250 $fit = $result->addValue(array (
237251 'query',
@@ -238,7 +252,9 @@
239253 ), $pageid, $pageInfo);
240254 if(!$fit)
241255 {
242 - $this->setContinueEnumParameter('continue', $count);
 256+ $this->setContinueEnumParameter('continue',
 257+ $title->getNamespace() . '|' .
 258+ $title->getText());
243259 break;
244260 }
245261 }
@@ -308,74 +324,81 @@
309325 $db = $this->getDB();
310326
311327 // Get normal protections for existing titles
312 - $this->addTables(array('page_restrictions', 'page'));
313 - $this->addWhere('page_id=pr_page');
314 - $this->addFields(array('pr_page', 'pr_type', 'pr_level',
315 - 'pr_expiry', 'pr_cascade', 'page_namespace',
316 - 'page_title'));
317 - $this->addWhereFld('pr_page', array_keys($this->titles));
 328+ if(count($this->titles))
 329+ {
 330+ $this->addTables(array('page_restrictions', 'page'));
 331+ $this->addWhere('page_id=pr_page');
 332+ $this->addFields(array('pr_page', 'pr_type', 'pr_level',
 333+ 'pr_expiry', 'pr_cascade', 'page_namespace',
 334+ 'page_title'));
 335+ $this->addWhereFld('pr_page', array_keys($this->titles));
318336
319 - $res = $this->select(__METHOD__);
320 - while($row = $db->fetchObject($res)) {
321 - $a = array(
322 - 'type' => $row->pr_type,
323 - 'level' => $row->pr_level,
324 - 'expiry' => Block::decodeExpiry($row->pr_expiry, TS_ISO_8601)
325 - );
326 - if($row->pr_cascade)
327 - $a['cascade'] = '';
328 - $this->protections[$row->page_namespace][$row->page_title][] = $a;
 337+ $res = $this->select(__METHOD__);
 338+ while($row = $db->fetchObject($res)) {
 339+ $a = array(
 340+ 'type' => $row->pr_type,
 341+ 'level' => $row->pr_level,
 342+ 'expiry' => Block::decodeExpiry($row->pr_expiry, TS_ISO_8601)
 343+ );
 344+ if($row->pr_cascade)
 345+ $a['cascade'] = '';
 346+ $this->protections[$row->page_namespace][$row->page_title][] = $a;
329347
330 - # Also check old restrictions
331 - if($pageRestrictions[$row->pr_page]) {
332 - foreach(explode(':', trim($this->pageRestrictions[$row->pr_page])) as $restrict) {
333 - $temp = explode('=', trim($restrict));
334 - if(count($temp) == 1) {
335 - // old old format should be treated as edit/move restriction
336 - $restriction = trim( $temp[0] );
337 -
338 - if($restriction == '')
339 - continue;
340 - $this->protections[$row->page_namespace][$row->page_title][] = array(
341 - 'type' => 'edit',
342 - 'level' => $restriction,
343 - 'expiry' => 'infinity',
344 - );
345 - $this->protections[$row->page_namespace][$row->page_title][] = array(
346 - 'type' => 'move',
347 - 'level' => $restriction,
348 - 'expiry' => 'infinity',
349 - );
350 - } else {
351 - $restriction = trim($temp[1]);
352 - if($restriction == '')
353 - continue;
354 - $this->protections[$row->page_namespace][$row->page_title][] = array(
355 - 'type' => $temp[0],
356 - 'level' => $restriction,
357 - 'expiry' => 'infinity',
358 - );
 348+ # Also check old restrictions
 349+ if($pageRestrictions[$row->pr_page]) {
 350+ $restrictions = explode(':', trim($this->pageRestrictions[$row->pr_page]));
 351+ foreach($restrictions as $restrict) {
 352+ $temp = explode('=', trim($restrict));
 353+ if(count($temp) == 1) {
 354+ // old old format should be treated as edit/move restriction
 355+ $restriction = trim($temp[0]);
 356+
 357+ if($restriction == '')
 358+ continue;
 359+ $this->protections[$row->page_namespace][$row->page_title][] = array(
 360+ 'type' => 'edit',
 361+ 'level' => $restriction,
 362+ 'expiry' => 'infinity',
 363+ );
 364+ $this->protections[$row->page_namespace][$row->page_title][] = array(
 365+ 'type' => 'move',
 366+ 'level' => $restriction,
 367+ 'expiry' => 'infinity',
 368+ );
 369+ } else {
 370+ $restriction = trim($temp[1]);
 371+ if($restriction == '')
 372+ continue;
 373+ $this->protections[$row->page_namespace][$row->page_title][] = array(
 374+ 'type' => $temp[0],
 375+ 'level' => $restriction,
 376+ 'expiry' => 'infinity',
 377+ );
 378+ }
359379 }
360380 }
361381 }
 382+ $db->freeResult($res);
362383 }
363 - $db->freeResult($res);
364384
365385 // Get protections for missing titles
366 - $this->resetQueryParams();
367 - $lb = new LinkBatch($this->missing);
368 - $this->addTables('protected_titles');
369 - $this->addFields(array('pt_title', 'pt_namespace', 'pt_create_perm', 'pt_expiry'));
370 - $this->addWhere($lb->constructSet('pt', $db));
371 - $res = $this->select(__METHOD__);
372 - while($row = $db->fetchObject($res)) {
373 - $this->protections[$row->pt_namespace][$row->pt_title][] = array(
374 - 'type' => 'create',
375 - 'level' => $row->pt_create_perm,
376 - 'expiry' => Block::decodeExpiry($row->pt_expiry, TS_ISO_8601)
377 - );
 386+ if(count($this->missing))
 387+ {
 388+ $this->resetQueryParams();
 389+ $lb = new LinkBatch($this->missing);
 390+ $this->addTables('protected_titles');
 391+ $this->addFields(array('pt_title', 'pt_namespace', 'pt_create_perm', 'pt_expiry'));
 392+ $this->addWhere($lb->constructSet('pt', $db));
 393+ $res = $this->select(__METHOD__);
 394+ while($row = $db->fetchObject($res)) {
 395+ $this->protections[$row->pt_namespace][$row->pt_title][] = array(
 396+ 'type' => 'create',
 397+ 'level' => $row->pt_create_perm,
 398+ 'expiry' => Block::decodeExpiry($row->pt_expiry, TS_ISO_8601)
 399+ );
 400+ }
 401+ $db->freeResult($res);
378402 }
379 - $db->freeResult($res);
380403
381404 // Cascading protections
382405 $images = $others = array();

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r47214catrope14:44, 13 February 2009

Status & tagging log