4 * Created on Sep 25, 2006
6 * API for MediaWiki 1.8+
8 * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * http://www.gnu.org/copyleft/gpl.html
26 if (!defined('MEDIAWIKI')) {
27 // Eclipse helper - will be ignored in production
28 require_once ('ApiQueryBase.php');
32 * Query module to enumerate all available pages.
36 class ApiQueryDoubleRedirects
extends ApiQueryGeneratorBase
{
37 public function __construct($query, $moduleName) {
38 parent
:: __construct($query, $moduleName, 'do');
41 public function execute() {
45 public function executeGenerator($resultPageSet) {
46 if ($resultPageSet->isResolvingRedirects())
47 $this->dieUsage('Use "gapfilterredir=nonredirects" option instead of "redirects" when using allpages as a generator', 'params');
49 $this->run($resultPageSet);
52 private function run($resultPageSet = null) {
54 $params = $this->extractRequestParams();
56 list( $page, $redirect ) = $db->tableNamesN( 'page', 'redirect' );
57 $this->addFields( array(
58 "pa.page_namespace as namespace",
59 "pa.page_title as title",
60 "pa.page_id as pageid",
61 "pb.page_namespace as nsb",
62 "pb.page_title as tb",
64 "pc.page_namespace as nsc",
65 "pc.page_title as tc",
69 $this->addTables($redirect, 'ra');
70 $this->addTables($redirect, 'rb');
71 $this->addTables($page, 'pa');
72 $this->addTables($page, 'pb');
73 $this->addTables($page, 'pc');
74 $this->addWhere(array(
75 "ra.rd_from=pa.page_id",
76 "ra.rd_namespace=pb.page_namespace",
77 "ra.rd_title=pb.page_title",
78 "rb.rd_from=pb.page_id",
79 "rb.rd_namespace=pc.page_namespace",
80 "rb.rd_title=pc.page_title"
83 $limit = $params['limit'];
84 $this->addOption('LIMIT', $limit+
1);
85 if(!is_null($params['offset']))
86 $this->addOption('OFFSET', $params['offset']);
87 $res = $this->select(__METHOD__
);
88 $result = $this->getResult();
90 while ($row = $db->fetchObject($res)) {
91 if (++
$count > $limit) {
92 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
93 // TODO: Security issue - if the user has no right to view next title, it will still be shown
94 $this->setContinueEnumParameter('offset', @$params['offset'] +
$params['limit']);
97 if (is_null($resultPageSet)) {
98 $title = Title
:: makeTitle($row->page_namespace
, $row->title
);
99 $titleB = Title
:: makeTitle($row->page_namespace
, $row->tb
);
100 $titleC = Title
:: makeTitle($row->page_namespace
, $row->tc
);
102 'pageid' => $row->pageid
,
103 'ns' => intval($row->namespace),
104 'title' => $title->getPrefixedText(),
105 'idb' => intval($row->idb
),
106 'nsb' => intval($row->nsb
),
107 'tb' => $titleB->getPrefixedText(),
108 'idc' => intval($row->idc
),
109 'nsc' => intval($row->nsc
),
110 'tc' => $titleC->getPrefixedText(),
112 $fit = $result->addValue(array('query', $this->getModuleName()), null, $vals);
115 $this->setContinueEnumParameter('offset', @$params['offset'] +
$count - 1);
119 $resultPageSet->processDbRow($row);
122 $db->freeResult($res);
124 if (is_null($resultPageSet)) {
125 $result->setIndexedTagName_internal(array('query', $this->getModuleName()), 'p');
129 public function getAllowedParams() {
132 ApiBase
:: PARAM_DFLT
=> 10,
133 ApiBase
:: PARAM_TYPE
=> 'limit',
134 ApiBase
:: PARAM_MIN
=> 1,
135 ApiBase
:: PARAM_MAX
=> ApiBase
:: LIMIT_BIG1
,
136 ApiBase
:: PARAM_MAX2
=> ApiBase
:: LIMIT_BIG2
142 public function getParamDescription() {
144 'limit' => 'How many links to return',
145 'offset' => 'When more results are available, use this to continue',
149 public function getDescription() {
150 return 'Enumerate all double redirects';
153 protected function getExamples() {
155 'api.php?action=query&list=doubleredirects',
159 public function getVersion() {
160 return __CLASS__
. ': $Id: ApiQueryDoubleRedirects.php 46845 2009-07-24 14:00:00Z alexsh $';