}
/**
- * This is three-in-one module to query:
+ * This is a 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 {
);
public function __construct($query, $moduleName) {
- $code = $prefix = $linktbl = null;
extract($this->backlinksSettings[$moduleName]);
parent :: __construct($query, $moduleName, $code);
private function prepareFirstQuery($resultPageSet = null) {
/* SELECT page_id, page_title, page_namespace, page_is_redirect
- * FROM pagelinks JOIN page ON pl_from=page_id
- * WHERE pl_title='Foo' AND pl_namespace=0
+ * FROM pagelinks, page WHERE pl_from=page_id
+ * AND pl_title='Foo' AND pl_namespace=0
* LIMIT 11 ORDER BY pl_from
*/
- $db = $this->getDb();
- $this->addTables(array($this->bl_table, 'page'));
+ $db = $this->getDB();
+ $this->addTables(array('page', $this->bl_table));
$this->addWhere("{$this->bl_from}=page_id");
if(is_null($resultPageSet))
$this->addFields(array('page_id', 'page_title', 'page_namespace'));
else
$this->addFields($resultPageSet->getPageTableFields());
$this->addFields('page_is_redirect');
- $this->addWhereFld($this->bl_title, $this->rootTitle->getDbKey());
+ $this->addWhereFld($this->bl_title, $this->rootTitle->getDBKey());
if($this->hasNS)
$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')
private function prepareSecondQuery($resultPageSet = null) {
/* SELECT page_id, page_title, page_namespace, page_is_redirect, pl_title, pl_namespace
- * FROM pagelinks JOIN page ON pl_from=page_id
- * WHERE (pl_title='Foo' AND pl_namespace=0) OR (pl_title='Bar' AND pl_namespace=1)
- * LIMIT 11 ORDER BY pl_namespace, pl_title, pl_from
+ FROM pagelinks, page WHERE pl_from=page_id
+ AND (pl_title='Foo' AND pl_namespace=0) OR (pl_title='Bar' AND pl_namespace=1)
+ ORDER BY pl_namespace, pl_title, pl_from LIMIT 11
*/
- $db = $this->getDb();
- $this->addTables(array($this->bl_table, 'page'));
+ $db = $this->getDB();
+ $this->addTables(array('page', $this->bl_table));
$this->addWhere("{$this->bl_from}=page_id");
if(is_null($resultPageSet))
$this->addFields(array('page_id', 'page_title', 'page_namespace', 'page_is_redirect'));
$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')
$this->prepareFirstQuery($resultPageSet);
$db = $this->getDB();
- $res = $this->select(__METHOD__);
+ $res = $this->select(__METHOD__.'::firstQuery');
$count = 0;
$this->data = array ();
}
$db->freeResult($res);
- if($this->redirect && !empty($this->redirTitles))
+ if($this->redirect && count($this->redirTitles))
{
$this->resetQueryParams();
$this->prepareSecondQuery($resultPageSet);
- $res = $this->select(__METHOD__);
+ $res = $this->select(__METHOD__.'::secondQuery');
$count = 0;
while($row = $db->fetchObject($res))
{
if($this->hasNS)
$contTitle = Title::makeTitle($row->{$this->bl_ns}, $row->{$this->bl_title});
else
- $contTitle = Title::makeTitle(NS_IMAGE, $row->{$this->bl_title});
+ $contTitle = Title::makeTitle(NS_FILE, $row->{$this->bl_title});
$this->continueStr = $this->getContinueRedirStr($contTitle->getArticleID(), $row->page_id);
break;
}
$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);
ApiQueryBase::addTitleInfo($a, Title::makeTitle($row->page_namespace, $row->page_title));
if($row->page_is_redirect)
$a['redirect'] = '';
- $ns = $this->hasNS ? $row->{$this->bl_ns} : NS_IMAGE;
+ $ns = $this->hasNS ? $row->{$this->bl_ns} : NS_FILE;
$this->data[$ns][$row->{$this->bl_title}]['redirlinks'][] = $a;
$this->getResult()->setIndexedTagName($this->data[$ns][$row->{$this->bl_title}]['redirlinks'], $this->bl_code);
}
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"));
+ $this->dieUsageMsg(array('missingparam', 'title'));
}
}
// only image titles are allowed for the root in imageinfo mode
- if (!$this->hasNS && $this->rootTitle->getNamespace() !== NS_IMAGE)
+ if (!$this->hasNS && $this->rootTitle->getNamespace() !== NS_FILE)
$this->dieUsage("The title for {$this->getModuleName()} query must be an image", 'bad_image_title');
}