Don't use public-audience-only function
[lhc/web/wiklou.git] / includes / api / ApiQueryBacklinks.php
index 0ae3681..df4daf9 100644 (file)
@@ -29,7 +29,7 @@ if (!defined('MEDIAWIKI')) {
 }
 
 /**
- * This is three-in-one module to query:
+ * This is three-in-one module to query:
  *   * backlinks  - links pointing to the given page,
  *   * embeddedin - what pages transclude the given page within themselves,
  *   * imageusage - what pages use the given image
@@ -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("page_id>={$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')
@@ -141,13 +141,29 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
                $titleWhere = '';
                foreach($this->redirTitles as $t)
                        $titleWhere .= ($titleWhere != '' ? " OR " : '') .
-                                       "({$this->bl_title} = '{$t->getDBKey()}'" .
+                                       "({$this->bl_title} = ".$db->addQuotes($t->getDBKey()).
                                        ($this->hasNS ? " AND {$this->bl_ns} = '{$t->getNamespace()}'" : "") .
                                        ")";
                $this->addWhere($titleWhere);
                $this->addWhereFld('page_namespace', $this->params['namespace']);
                if(!is_null($this->redirID))
-                       $this->addWhere("page_id>={$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')
@@ -195,7 +211,7 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
                }
                $db->freeResult($res);
 
-               if($this->redirect && !empty($this->redirTitles))
+               if($this->redirect && count($this->redirTitles))
                {
                        $this->resetQueryParams();
                        $this->prepareSecondQuery($resultPageSet);
@@ -229,7 +245,7 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
                        $resultData = array();
                        foreach($this->data as $ns => $a)
                                foreach($a as $title => $arr)
-                                       $resultData[$arr['pageid']] = $arr;
+                                       $resultData[] = $arr;
                        $result = $this->getResult();
                        $result->setIndexedTagName($resultData, $this->bl_code);
                        $result->addValue('query', $this->getModuleName(), $resultData);