00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 if (!defined('MEDIAWIKI')) {
00027
00028 require_once ("ApiBase.php");
00029 }
00030
00034 class ApiOpenSearch extends ApiBase {
00035
00036 public function __construct($main, $action) {
00037 parent :: __construct($main, $action);
00038 }
00039
00040 public function getCustomPrinter() {
00041 return $this->getMain()->createPrinterByName('json');
00042 }
00043
00044 public function execute() {
00045 global $wgEnableMWSuggest;
00046 $params = $this->extractRequestParams();
00047 $search = $params['search'];
00048 $limit = $params['limit'];
00049 $namespaces = $params['namespace'];
00050 $suggest = $params['suggest'];
00051 # $wgEnableMWSuggest hit incoming when $wgEnableMWSuggest is disabled
00052 if( $suggest && !$wgEnableMWSuggest ) return;
00053
00054
00055 $this->getMain()->setCacheMaxAge(1200);
00056
00057 $srchres = PrefixSearch::titleSearch( $search, $limit, $namespaces );
00058
00059
00060 $result = $this->getResult();
00061 $result->addValue(null, 0, $search);
00062 $result->addValue(null, 1, $srchres);
00063 }
00064
00065 public function getAllowedParams() {
00066 return array (
00067 'search' => null,
00068 'limit' => array(
00069 ApiBase :: PARAM_DFLT => 10,
00070 ApiBase :: PARAM_TYPE => 'limit',
00071 ApiBase :: PARAM_MIN => 1,
00072 ApiBase :: PARAM_MAX => 100,
00073 ApiBase :: PARAM_MAX2 => 100
00074 ),
00075 'namespace' => array(
00076 ApiBase :: PARAM_DFLT => NS_MAIN,
00077 ApiBase :: PARAM_TYPE => 'namespace',
00078 ApiBase :: PARAM_ISMULTI => true
00079 ),
00080 'suggest' => false,
00081 );
00082 }
00083
00084 public function getParamDescription() {
00085 return array (
00086 'search' => 'Search string',
00087 'limit' => 'Maximum amount of results to return',
00088 'namespace' => 'Namespaces to search',
00089 'suggest' => 'Do nothing if $wgEnableMWSuggest is false',
00090 );
00091 }
00092
00093 public function getDescription() {
00094 return 'This module implements OpenSearch protocol';
00095 }
00096
00097 protected function getExamples() {
00098 return array (
00099 'api.php?action=opensearch&search=Te'
00100 );
00101 }
00102
00103 public function getVersion() {
00104 return __CLASS__ . ': $Id: ApiOpenSearch.php 47188 2009-02-12 17:27:05Z catrope $';
00105 }
00106 }