API: Backlink-style queries (backlinks, imageusage, embeddedin) now use ??title param...
authorYuri Astrakhan <yurik@users.mediawiki.org>
Fri, 6 Jul 2007 07:16:38 +0000 (07:16 +0000)
committerYuri Astrakhan <yurik@users.mediawiki.org>
Fri, 6 Jul 2007 07:16:38 +0000 (07:16 +0000)
RELEASE-NOTES
includes/api/ApiBase.php
includes/api/ApiQueryBacklinks.php
includes/api/ApiQueryUserContributions.php

index a9bc70b..94bf76b 100644 (file)
@@ -299,6 +299,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 10411) Site language in meta=siteinfo
 * (bug 10391) action=help doesn't return help if format is fancy markup
 * (bug 10297) include previous revision ID in prop=revisions
+* backlinks, embeddedin and imageusage lists should use (bl|ei|iu)title parameter
+  instead of titles. Titles for these lists is obsolete and might stop working soon.
 
 == Maintenance script changes since 1.10 ==
 
index b728e93..833db59 100644 (file)
@@ -124,6 +124,15 @@ abstract class ApiBase {
                return $this->getResult()->getData();
        }
 
+       /**
+        * Set warning section for this module. Users should monitor this section to notice any changes in API.
+        */
+       public function setWarning($warning) {
+               $msg = array();
+               ApiResult :: setContent($msg, $warning);
+               $this->getResult()->addValue('warnings', $this->getModuleName(), $msg);
+       }
+
        /**
         * If the module may only be used with a certain format module,
         * it should override this method to return an instance of that formatter.
index 336d7fa..be76c95 100644 (file)
@@ -38,7 +38,7 @@ if (!defined('MEDIAWIKI')) {
  */
 class ApiQueryBacklinks extends ApiQueryGeneratorBase {
 
-       private $rootTitle, $contRedirs, $contLevel, $contTitle, $contID;
+       private $params, $rootTitle, $contRedirs, $contLevel, $contTitle, $contID;
 
        // output element name, database column field prefix, database table 
        private $backlinksSettings = array (
@@ -98,13 +98,13 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
        }
 
        private function run($resultPageSet = null) {
-               $continue = $namespace = $redirect = $limit = null;
-               extract($this->extractRequestParams());
-
+               $this->params = $this->extractRequestParams();
+               
+               $redirect = $this->params['redirect'];
                if ($redirect)
                        ApiBase :: dieDebug(__METHOD__, 'Redirect has not been implemented', 'notimplemented');
 
-               $this->processContinue($continue, $redirect);
+               $this->processContinue();
 
                $this->addFields($this->bl_fields);
                if (is_null($resultPageSet))
@@ -122,7 +122,9 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
                if ($this->hasNS)
                        $this->addWhereFld($this->bl_ns, $this->rootTitle->getNamespace());
                $this->addWhereFld($this->bl_title, $this->rootTitle->getDBkey());
-               $this->addWhereFld('page_namespace', $namespace);
+               $this->addWhereFld('page_namespace', $this->params['namespace']);
+
+               $limit = $this->params['limit'];
                $this->addOption('LIMIT', $limit +1);
                $this->addOption('ORDER BY', $this->bl_sort);
 
@@ -130,7 +132,7 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
                        $this->addWhereFld('page_is_redirect', 0);
 
                $db = $this->getDB();
-               if (!is_null($continue)) {
+               if (!is_null($this->params['continue'])) {
                        $plfrm = intval($this->contID);
                        if ($this->contLevel == 0) {
                                // For the first level, there is only one target title, so no need for complex filtering
@@ -194,20 +196,25 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
                return $vals;
        }
 
-       protected function processContinue($continue, $redirect) {
+       protected function processContinue() {
                $pageSet = $this->getPageSet();
                $count = $pageSet->getTitleCount();
-               if (!is_null($continue)) {
-                       if ($count !== 0)
-                               $this->dieUsage("When continuing the {$this->getModuleName()} query, no other titles may be provided", 'titles_on_continue');
-                       $this->parseContinueParam($continue, $redirect);
+               
+               if (!is_null($this->params['continue'])) {
+                       $this->parseContinueParam();
 
                        // Skip all completed links
 
                } else {
-                       if ($count !== 1)
-                               $this->dieUsage("The {$this->getModuleName()} query requires one title to start", 'bad_title_count');
-                       $this->rootTitle = current($pageSet->getTitles()); // only one title there
+                       $title = $this->params['title'];
+                       if (!is_null($title)) {
+                               $this->rootTitle = Title :: newFromText($title);
+                       } else {  // This case is obsolete. Will support this for a while
+                               if ($count !== 1)
+                                       $this->dieUsage("The {$this->getModuleName()} query requires one title to start", 'bad_title_count');
+                               $this->rootTitle = current($pageSet->getTitles()); // only one title there
+                               $this->setWarning('Using titles parameter is obsolete for this list. Use ' . $this->encodeParamName('title') . ' instead.');
+                       }
                }
 
                // only image titles are allowed for the root 
@@ -215,9 +222,9 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
                        $this->dieUsage("The title for {$this->getModuleName()} query must be an image", 'bad_image_title');
        }
 
-       protected function parseContinueParam($continue, $redirect) {
-               $continueList = explode('|', $continue);
-               if ($redirect) {
+       protected function parseContinueParam() {
+               $continueList = explode('|', $this->params['continue']);
+               if ($this->params['redirect']) {
                        //
                        // expected redirect-mode parameter:
                        // ns|db_key|step|level|ns|db_key|id
@@ -312,6 +319,7 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
        protected function getAllowedParams() {
 
                return array (
+                       'title' => null,
                        'continue' => null,
                        'namespace' => array (
                                ApiBase :: PARAM_ISMULTI => true,
@@ -330,6 +338,7 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
 
        protected function getParamDescription() {
                return array (
+                       'title' => 'Title to search. If null, titles= parameter will be used instead, but will be obsolete soon.',
                        'continue' => 'When more results are available, use this to continue.',
                        'namespace' => 'The namespace to enumerate.',
                        'redirect' => 'If linking page is a redirect, find all pages that link to that redirect (not implemented)',
@@ -353,16 +362,16 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
        protected function getExamples() {
                static $examples = array (
                        'backlinks' => array (
-                               "api.php?action=query&list=backlinks&titles=Main%20Page",
-                               "api.php?action=query&generator=backlinks&titles=Main%20Page&prop=info"
+                               "api.php?action=query&list=backlinks&bltitle=Main%20Page",
+                               "api.php?action=query&generator=backlinks&gbltitle=Main%20Page&prop=info"
                        ),
                        'embeddedin' => array (
-                               "api.php?action=query&list=embeddedin&titles=Template:Stub",
-                               "api.php?action=query&generator=embeddedin&titles=Template:Stub&prop=info"
+                               "api.php?action=query&list=embeddedin&eititle=Template:Stub",
+                               "api.php?action=query&generator=embeddedin&geititle=Template:Stub&prop=info"
                        ),
                        'imageusage' => array (
-                               "api.php?action=query&list=imageusage&titles=Image:Albert%20Einstein%20Head.jpg",
-                               "api.php?action=query&generator=imageusage&titles=Image:Albert%20Einstein%20Head.jpg&prop=info"
+                               "api.php?action=query&list=imageusage&iutitle=Image:Albert%20Einstein%20Head.jpg",
+                               "api.php?action=query&generator=imageusage&giutitle=Image:Albert%20Einstein%20Head.jpg&prop=info"
                        )
                );
 
index 213b126..9b91b12 100644 (file)
@@ -135,8 +135,7 @@ class ApiQueryContributions extends ApiQueryBase {
                $this->addWhereRange('rev_timestamp', 
                        $this->params['dir'], $this->params['start'], $this->params['end'] );
 
-               if(count($this->params['namespace']) > 0)
-                       $this->addWhereFld('page_namespace', $this->params['namespace']);
+               $this->addWhereFld('page_namespace', $this->params['namespace']);
 
                $show = $this->params['show'];
                if (!is_null($show)) {