r23774 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23773‎ | r23774 | r23775 >
Date:07:16, 6 July 2007
Author:yurik
Status:old
Tags:
Comment:
API: Backlink-style queries (backlinks, imageusage, embeddedin) now use ??title parameter instead of titles (support for titles will be discontinued later).
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/api/ApiBase.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryBacklinks.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryUserContributions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryBacklinks.php
@@ -38,7 +38,7 @@
3939 */
4040 class ApiQueryBacklinks extends ApiQueryGeneratorBase {
4141
42 - private $rootTitle, $contRedirs, $contLevel, $contTitle, $contID;
 42+ private $params, $rootTitle, $contRedirs, $contLevel, $contTitle, $contID;
4343
4444 // output element name, database column field prefix, database table
4545 private $backlinksSettings = array (
@@ -98,13 +98,13 @@
9999 }
100100
101101 private function run($resultPageSet = null) {
102 - $continue = $namespace = $redirect = $limit = null;
103 - extract($this->extractRequestParams());
104 -
 102+ $this->params = $this->extractRequestParams();
 103+
 104+ $redirect = $this->params['redirect'];
105105 if ($redirect)
106106 ApiBase :: dieDebug(__METHOD__, 'Redirect has not been implemented', 'notimplemented');
107107
108 - $this->processContinue($continue, $redirect);
 108+ $this->processContinue();
109109
110110 $this->addFields($this->bl_fields);
111111 if (is_null($resultPageSet))
@@ -122,7 +122,9 @@
123123 if ($this->hasNS)
124124 $this->addWhereFld($this->bl_ns, $this->rootTitle->getNamespace());
125125 $this->addWhereFld($this->bl_title, $this->rootTitle->getDBkey());
126 - $this->addWhereFld('page_namespace', $namespace);
 126+ $this->addWhereFld('page_namespace', $this->params['namespace']);
 127+
 128+ $limit = $this->params['limit'];
127129 $this->addOption('LIMIT', $limit +1);
128130 $this->addOption('ORDER BY', $this->bl_sort);
129131
@@ -130,7 +132,7 @@
131133 $this->addWhereFld('page_is_redirect', 0);
132134
133135 $db = $this->getDB();
134 - if (!is_null($continue)) {
 136+ if (!is_null($this->params['continue'])) {
135137 $plfrm = intval($this->contID);
136138 if ($this->contLevel == 0) {
137139 // For the first level, there is only one target title, so no need for complex filtering
@@ -194,20 +196,25 @@
195197 return $vals;
196198 }
197199
198 - protected function processContinue($continue, $redirect) {
 200+ protected function processContinue() {
199201 $pageSet = $this->getPageSet();
200202 $count = $pageSet->getTitleCount();
201 - if (!is_null($continue)) {
202 - if ($count !== 0)
203 - $this->dieUsage("When continuing the {$this->getModuleName()} query, no other titles may be provided", 'titles_on_continue');
204 - $this->parseContinueParam($continue, $redirect);
 203+
 204+ if (!is_null($this->params['continue'])) {
 205+ $this->parseContinueParam();
205206
206207 // Skip all completed links
207208
208209 } else {
209 - if ($count !== 1)
210 - $this->dieUsage("The {$this->getModuleName()} query requires one title to start", 'bad_title_count');
211 - $this->rootTitle = current($pageSet->getTitles()); // only one title there
 210+ $title = $this->params['title'];
 211+ if (!is_null($title)) {
 212+ $this->rootTitle = Title :: newFromText($title);
 213+ } else { // This case is obsolete. Will support this for a while
 214+ if ($count !== 1)
 215+ $this->dieUsage("The {$this->getModuleName()} query requires one title to start", 'bad_title_count');
 216+ $this->rootTitle = current($pageSet->getTitles()); // only one title there
 217+ $this->setWarning('Using titles parameter is obsolete for this list. Use ' . $this->encodeParamName('title') . ' instead.');
 218+ }
212219 }
213220
214221 // only image titles are allowed for the root
@@ -215,9 +222,9 @@
216223 $this->dieUsage("The title for {$this->getModuleName()} query must be an image", 'bad_image_title');
217224 }
218225
219 - protected function parseContinueParam($continue, $redirect) {
220 - $continueList = explode('|', $continue);
221 - if ($redirect) {
 226+ protected function parseContinueParam() {
 227+ $continueList = explode('|', $this->params['continue']);
 228+ if ($this->params['redirect']) {
222229 //
223230 // expected redirect-mode parameter:
224231 // ns|db_key|step|level|ns|db_key|id
@@ -312,6 +319,7 @@
313320 protected function getAllowedParams() {
314321
315322 return array (
 323+ 'title' => null,
316324 'continue' => null,
317325 'namespace' => array (
318326 ApiBase :: PARAM_ISMULTI => true,
@@ -330,6 +338,7 @@
331339
332340 protected function getParamDescription() {
333341 return array (
 342+ 'title' => 'Title to search. If null, titles= parameter will be used instead, but will be obsolete soon.',
334343 'continue' => 'When more results are available, use this to continue.',
335344 'namespace' => 'The namespace to enumerate.',
336345 'redirect' => 'If linking page is a redirect, find all pages that link to that redirect (not implemented)',
@@ -353,16 +362,16 @@
354363 protected function getExamples() {
355364 static $examples = array (
356365 'backlinks' => array (
357 - "api.php?action=query&list=backlinks&titles=Main%20Page",
358 - "api.php?action=query&generator=backlinks&titles=Main%20Page&prop=info"
 366+ "api.php?action=query&list=backlinks&bltitle=Main%20Page",
 367+ "api.php?action=query&generator=backlinks&gbltitle=Main%20Page&prop=info"
359368 ),
360369 'embeddedin' => array (
361 - "api.php?action=query&list=embeddedin&titles=Template:Stub",
362 - "api.php?action=query&generator=embeddedin&titles=Template:Stub&prop=info"
 370+ "api.php?action=query&list=embeddedin&eititle=Template:Stub",
 371+ "api.php?action=query&generator=embeddedin&geititle=Template:Stub&prop=info"
363372 ),
364373 'imageusage' => array (
365 - "api.php?action=query&list=imageusage&titles=Image:Albert%20Einstein%20Head.jpg",
366 - "api.php?action=query&generator=imageusage&titles=Image:Albert%20Einstein%20Head.jpg&prop=info"
 374+ "api.php?action=query&list=imageusage&iutitle=Image:Albert%20Einstein%20Head.jpg",
 375+ "api.php?action=query&generator=imageusage&giutitle=Image:Albert%20Einstein%20Head.jpg&prop=info"
367376 )
368377 );
369378
Index: trunk/phase3/includes/api/ApiBase.php
@@ -125,6 +125,15 @@
126126 }
127127
128128 /**
 129+ * Set warning section for this module. Users should monitor this section to notice any changes in API.
 130+ */
 131+ public function setWarning($warning) {
 132+ $msg = array();
 133+ ApiResult :: setContent($msg, $warning);
 134+ $this->getResult()->addValue('warnings', $this->getModuleName(), $msg);
 135+ }
 136+
 137+ /**
129138 * If the module may only be used with a certain format module,
130139 * it should override this method to return an instance of that formatter.
131140 * A value of null means the default format will be used.
Index: trunk/phase3/includes/api/ApiQueryUserContributions.php
@@ -135,8 +135,7 @@
136136 $this->addWhereRange('rev_timestamp',
137137 $this->params['dir'], $this->params['start'], $this->params['end'] );
138138
139 - if(count($this->params['namespace']) > 0)
140 - $this->addWhereFld('page_namespace', $this->params['namespace']);
 139+ $this->addWhereFld('page_namespace', $this->params['namespace']);
141140
142141 $show = $this->params['show'];
143142 if (!is_null($show)) {
Index: trunk/phase3/RELEASE-NOTES
@@ -299,6 +299,8 @@
300300 * (bug 10411) Site language in meta=siteinfo
301301 * (bug 10391) action=help doesn't return help if format is fancy markup
302302 * (bug 10297) include previous revision ID in prop=revisions
 303+* backlinks, embeddedin and imageusage lists should use (bl|ei|iu)title parameter
 304+ instead of titles. Titles for these lists is obsolete and might stop working soon.
303305
304306 == Maintenance script changes since 1.10 ==
305307

Follow-up revisions

RevisionCommit summaryAuthorDate
r23912Merged revisions 23662-23909 via svnmerge from...david18:11, 9 July 2007

Status & tagging log