Don't duplicate code, use wfAppendQuery
[lhc/web/wiklou.git] / includes / api / ApiQueryBacklinks.php
index 8081837..a953451 100644 (file)
@@ -29,12 +29,12 @@ 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
  *
- * @addtogroup API
+ * @ingroup API
  */
 class ApiQueryBacklinks extends ApiQueryGeneratorBase {
 
@@ -141,7 +141,7 @@ 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);
@@ -229,7 +229,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);
@@ -263,9 +263,13 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
                if (!is_null($this->params['continue']))
                        $this->parseContinueParam();
                else {
-                       $title = $this->params['title'];
-                       if (!is_null($title)) {
-                               $this->rootTitle = Title :: newFromText($title);
+                       if ( $this->params['title'] !== "" ) {
+                               $title = Title::newFromText( $this->params['title'] );
+                               if ( !$title ) {
+                                       $this->dieUsageMsg(array('invalidtitle', $this->params['title']));
+                               } else {
+                                       $this->rootTitle = $title;
+                               }
                        } else {
                                $this->dieUsageMsg(array('missingparam', 'title'));
                        }