* API watchlist: Forced an index, enabled generator
[lhc/web/wiklou.git] / includes / api / ApiOpenSearch.php
1 <?php
2
3
4 /*
5 * Created on Oct 13, 2006
6 *
7 * API for MediaWiki 1.8+
8 *
9 * Copyright (C) 2006 Yuri Astrakhan <FirstnameLastname@gmail.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 * http://www.gnu.org/copyleft/gpl.html
25 */
26
27 if (!defined('MEDIAWIKI')) {
28 // Eclipse helper - will be ignored in production
29 require_once ("ApiFormatBase.php");
30 }
31
32 class ApiOpenSearch extends ApiFormatBase {
33
34 private $mResult = array();
35
36 public function __construct($main, $action) {
37 parent :: __construct($main, $action);
38 }
39
40 public function getMimeType() {
41 return 'application/json';
42 }
43
44 public function execute() {
45 $command = null;
46 extract($this->ExtractRequestParams());
47
48 // Prepare nested request
49 $params = new FauxRequest(array (
50 'action' => 'query',
51 'list' => 'allpages',
52 'apnamespace' => 0,
53 'aplimit' => 10,
54 'apprefix' => $command
55 ));
56
57 // Execute
58 $module = new ApiMain($params);
59 $module->execute();
60
61 // Get clean data
62 $result =& $module->getResult();
63 $result->SanitizeData();
64 $data = $result->GetData();
65
66 // Reformat useful data for future printing
67 $result = array();
68 foreach ($data['query']['allpages'] as $pageid => &$pageinfo) {
69 $result[] = $pageinfo['title'];
70 }
71
72 $this->mResult = array($command, $result);
73 }
74
75 public function executePrinter() {
76 $json = new Services_JSON();
77 $this->printText($json->encode($this->mResult, true));
78 }
79
80 protected function GetAllowedParams() {
81 return array (
82 'command' => null
83 );
84 }
85
86 protected function GetParamDescription() {
87 return array (
88 'command' => 'Search string'
89 );
90 }
91
92 protected function GetDescription() {
93 return 'This module implements OpenSearch protocol';
94 }
95
96 protected function GetExamples() {
97 return array (
98 'api.php?action=opensearch&command=Te'
99 );
100 }
101
102 public function getVersion() {
103 return __CLASS__ . ': $Id$';
104 }
105 }
106 ?>