r34238 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r34237‎ | r34238 | r34239 >
Date:09:37, 5 May 2008
Author:btongminh
Status:old
Tags:
Comment:
API: Expose cascading protection via inprop=protection for non-existent pages.
Modified paths:
  • /trunk/phase3/includes/api/ApiQueryInfo.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryInfo.php
@@ -173,13 +173,71 @@
174174 $res = $this->select(__METHOD__);
175175 $prottitles = array();
176176 while($row = $db->fetchObject($res)) {
177 - $prottitles[$row->pt_namespace][$row->pt_title] = array(
 177+ $prottitles[$row->pt_namespace][$row->pt_title][] = array(
178178 'type' => 'create',
179179 'level' => $row->pt_create_perm,
180180 'expiry' => Block::decodeExpiry($row->pt_expiry, TS_ISO_8601)
181181 );
182182 }
183183 $db->freeResult($res);
 184+
 185+ $images = array();
 186+ $others = array();
 187+ foreach ($missing as $title)
 188+ if ($title->getNamespace() == NS_IMAGE)
 189+ $images[] = $title->getDbKey();
 190+ else
 191+ $others[] = $title;
 192+
 193+ if (count($others) != 0) {
 194+ $lb = new LinkBatch($others);
 195+ $this->resetQueryParams();
 196+ $this->addTables(array('page_restrictions', 'page', 'templatelinks'));
 197+ $this->addFields(array('pr_type', 'pr_level', 'pr_expiry',
 198+ 'page_title', 'page_namespace',
 199+ 'tl_title', 'tl_namespace'));
 200+ $this->addWhere($lb->constructSet('tl', $db));
 201+ $this->addWhere('pr_page = page_id');
 202+ $this->addWhere('pr_page = tl_from');
 203+ $this->addWhereFld('pr_cascade', 1);
 204+
 205+ $res = $this->select(__METHOD__);
 206+ while($row = $db->fetchObject($res)) {
 207+ $source = Title::makeTitle($row->page_namespace, $row->page_title);
 208+ $a = array(
 209+ 'type' => $row->pr_type,
 210+ 'level' => $row->pr_level,
 211+ 'expiry' => Block::decodeExpiry( $row->pr_expiry, TS_ISO_8601 ),
 212+ 'source' => $source->getPrefixedText()
 213+ );
 214+ $prottitles[$row->tl_namespace][$row->tl_title][] = $a;
 215+ }
 216+ $db->freeResult($res);
 217+ }
 218+
 219+ if (count($images) != 0) {
 220+ $this->resetQueryParams();
 221+ $this->addTables(array('page_restrictions', 'page', 'imagelinks'));
 222+ $this->addFields(array('pr_type', 'pr_level', 'pr_expiry',
 223+ 'page_title', 'page_namespace', 'il_to'));
 224+ $this->addWhere('pr_page = page_id');
 225+ $this->addWhere('pr_page = il_from');
 226+ $this->addWhereFld('pr_cascade', 1);
 227+ $this->addWhereFld('il_to', $images);
 228+
 229+ $res = $this->select(__METHOD__);
 230+ while($row = $db->fetchObject($res)) {
 231+ $source = Title::makeTitle($row->page_namespace, $row->page_title);
 232+ $a = array(
 233+ 'type' => $row->pr_type,
 234+ 'level' => $row->pr_level,
 235+ 'expiry' => Block::decodeExpiry( $row->pr_expiry, TS_ISO_8601 ),
 236+ 'source' => $source->getPrefixedText()
 237+ );
 238+ $prottitles[NS_IMAGE][$row->il_to][] = $a;
 239+ }
 240+ $db->freeResult($res);
 241+ }
184242 }
185243
186244 // Run the talkid/subjectid query
@@ -307,7 +365,7 @@
308366 // Apparently the XML formatting code doesn't like array(null)
309367 // This is painful to fix, so we'll just work around it
310368 if(isset($prottitles[$title->getNamespace()][$title->getDBkey()]))
311 - $res['query']['pages'][$pageid]['protection'][] = $prottitles[$title->getNamespace()][$title->getDBkey()];
 369+ $res['query']['pages'][$pageid]['protection'] = $prottitles[$title->getNamespace()][$title->getDBkey()];
312370 else
313371 $res['query']['pages'][$pageid]['protection'] = array();
314372 $result->setIndexedTagName($res['query']['pages'][$pageid]['protection'], 'pr');

Status & tagging log