Index: trunk/phase3/includes/api/ApiGo.php |
— | — | @@ -0,0 +1,101 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Created on Mar 30, 2010 |
| 6 | + * API for MediaWiki 1.8+ |
| 7 | + * |
| 8 | + * Copyright © 2010 Matthew Britton <Firstname>.<Lastname>@btinternet.com |
| 9 | + * |
| 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. |
| 14 | + * |
| 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. |
| 19 | + * |
| 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 |
| 24 | + */ |
| 25 | + |
| 26 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 27 | + // Eclipse helper - will be ignored in production |
| 28 | + require_once( "ApiBase.php" ); |
| 29 | +} |
| 30 | + |
| 31 | +/** |
| 32 | +* API module to determine the result of a "Go" search |
| 33 | +* |
| 34 | + * @ingroup API |
| 35 | + */ |
| 36 | +class ApiGo extends ApiBase { |
| 37 | + |
| 38 | + /** |
| 39 | + * Std ctor. |
| 40 | + */ |
| 41 | + public function __construct( $main, $action ) { |
| 42 | + parent::__construct( $main, $action ); |
| 43 | + } |
| 44 | + |
| 45 | + public function execute() { |
| 46 | + $params = $this->extractRequestParams(); |
| 47 | + $text = $params['text']; |
| 48 | + |
| 49 | + if ( is_null( $text ) ) { |
| 50 | + $this->dieUsageMsg( array( 'missingparam', 'text' ) ); |
| 51 | + } |
| 52 | + |
| 53 | + // Strip underscores |
| 54 | + $text = str_replace( '_', ' ', $text ); |
| 55 | + |
| 56 | + $nearMatch = SearchEngine::getNearMatch( $text ); |
| 57 | + |
| 58 | + $this->getResult()->addValue( null, $this->getModuleName(), array( 'text' => $text, 'result' => $nearMatch ) ); |
| 59 | + } |
| 60 | + |
| 61 | + public function mustBePosted() { |
| 62 | + return false; |
| 63 | + } |
| 64 | + |
| 65 | + public function isWriteMode() { |
| 66 | + return false; |
| 67 | + } |
| 68 | + |
| 69 | + public function getAllowedParams() { |
| 70 | + return array( |
| 71 | + 'text' => null, |
| 72 | + ); |
| 73 | + } |
| 74 | + |
| 75 | + public function getParamDescription() { |
| 76 | + return array( |
| 77 | + 'text' => 'Text to try a "Go" match for' |
| 78 | + ); |
| 79 | + } |
| 80 | + |
| 81 | + public function getDescription() { |
| 82 | + return array( |
| 83 | + 'Determine the title one will be taken to by a "Go" search, if any' |
| 84 | + ); |
| 85 | + } |
| 86 | + |
| 87 | + public function getPossibleErrors() { |
| 88 | + return array_merge( parent::getPossibleErrors(), array( |
| 89 | + array( 'missingparam', 'text' ) |
| 90 | + ) ); |
| 91 | + } |
| 92 | + |
| 93 | + protected function getExamples() { |
| 94 | + return array( |
| 95 | + 'api.php?action=go&text=Foo' |
| 96 | + ); |
| 97 | + } |
| 98 | + |
| 99 | + public function getVersion() { |
| 100 | + return __CLASS__ . ': $Id: $'; |
| 101 | + } |
| 102 | +} |
Property changes on: trunk/phase3/includes/api/ApiGo.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 103 | + native |
Index: trunk/phase3/includes/api/ApiMain.php |
— | — | @@ -63,6 +63,7 @@ |
64 | 64 | 'parse' => 'ApiParse', |
65 | 65 | 'opensearch' => 'ApiOpenSearch', |
66 | 66 | 'feedwatchlist' => 'ApiFeedWatchlist', |
| 67 | + 'go' => 'ApiGo', |
67 | 68 | 'help' => 'ApiHelp', |
68 | 69 | 'paraminfo' => 'ApiParamInfo', |
69 | 70 | |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -279,6 +279,7 @@ |
280 | 280 | 'ApiFormatWddx' => 'includes/api/ApiFormatWddx.php', |
281 | 281 | 'ApiFormatXml' => 'includes/api/ApiFormatXml.php', |
282 | 282 | 'ApiFormatYaml' => 'includes/api/ApiFormatYaml.php', |
| 283 | + 'ApiGo' => 'includes/api/ApiGo.php', |
283 | 284 | 'ApiHelp' => 'includes/api/ApiHelp.php', |
284 | 285 | 'ApiImport' => 'includes/api/ApiImport.php', |
285 | 286 | 'ApiImportReporter' => 'includes/api/ApiImport.php', |