API: * Fix up r42471 which hardcoded pl_from instead of using $this->bl_from
authorRoan Kattouw <catrope@users.mediawiki.org>
Fri, 24 Oct 2008 22:22:40 +0000 (22:22 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Fri, 24 Oct 2008 22:22:40 +0000 (22:22 +0000)
* Fix the second half of bug 16076 (using pl_from>=123 in combination with multiple values for pl_namespace and pl_title causes filesort)
* By pure accident this fixes a bug about list=backlinks&blredirect dropping results under obscure conditions

includes/api/ApiQueryBacklinks.php

index efc1a91..258a482 100644 (file)
@@ -113,7 +113,7 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
                        $this->addWhereFld($this->bl_ns, $this->rootTitle->getNamespace());
                $this->addWhereFld('page_namespace', $this->params['namespace']);
                if(!is_null($this->contID))
-                       $this->addWhere("pl_from>={$this->contID}");
+                       $this->addWhere("{$this->bl_from}>={$this->contID}");
                if($this->params['filterredir'] == 'redirects')
                        $this->addWhereFld('page_is_redirect', 1);
                if($this->params['filterredir'] == 'nonredirects')
@@ -147,7 +147,23 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
                $this->addWhere($titleWhere);
                $this->addWhereFld('page_namespace', $this->params['namespace']);
                if(!is_null($this->redirID))
-                       $this->addWhere("pl_from>={$this->redirID}");
+               {
+                       $first = $this->redirTitles[0];
+                       $title = $db->strencode($first->getDBKey());
+                       $ns = $first->getNamespace();
+                       $from = $this->redirID;
+                       if($this->hasNS)
+                               $this->addWhere("{$this->bl_ns} > $ns OR ".
+                                               "({$this->bl_ns} = $ns AND ".
+                                               "({$this->bl_title} > '$title' OR ".
+                                               "({$this->bl_title} = '$title' AND ".
+                                               "{$this->bl_from} >= $from)))");
+                       else
+                               $this->addWhere("{$this->bl_title} > '$title' OR ".
+                                               "({$this->bl_title} = '$title' AND ".
+                                               "{$this->bl_from} >= $from)");
+                               
+               }
                if($this->params['filterredir'] == 'redirects')
                        $this->addWhereFld('page_is_redirect', 1);
                if($this->params['filterredir'] == 'nonredirects')