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 $this->getMain()->setCacheMode( 'public' );
00057
00058 $srchres = PrefixSearch::titleSearch( $search, $limit, $namespaces );
00059
00060
00061 $result = $this->getResult();
00062 $result->addValue(null, 0, $search);
00063 $result->addValue(null, 1, $srchres);
00064 }
00065
00066 public function getAllowedParams() {
00067 return array (
00068 'search' => null,
00069 'limit' => array(
00070 ApiBase :: PARAM_DFLT => 10,
00071 ApiBase :: PARAM_TYPE => 'limit',
00072 ApiBase :: PARAM_MIN => 1,
00073 ApiBase :: PARAM_MAX => 100,
00074 ApiBase :: PARAM_MAX2 => 100
00075 ),
00076 'namespace' => array(
00077 ApiBase :: PARAM_DFLT => NS_MAIN,
00078 ApiBase :: PARAM_TYPE => 'namespace',
00079 ApiBase :: PARAM_ISMULTI => true
00080 ),
00081 'suggest' => false,
00082 );
00083 }
00084
00085 public function getParamDescription() {
00086 return array (
00087 'search' => 'Search string',
00088 'limit' => 'Maximum amount of results to return',
00089 'namespace' => 'Namespaces to search',
00090 'suggest' => 'Do nothing if $wgEnableMWSuggest is false',
00091 );
00092 }
00093
00094 public function getDescription() {
00095 return 'This module implements OpenSearch protocol';
00096 }
00097
00098 protected function getExamples() {
00099 return array (
00100 'api.php?action=opensearch&search=Te'
00101 );
00102 }
00103
00104 public function getVersion() {
00105 return __CLASS__ . ': $Id: ApiOpenSearch.php 69986 2010-07-27 03:57:39Z tstarling $';
00106 }
00107 }