http://www.mediawiki.org/wiki/Special:Code/MediaWiki/64436

Revision: 64436
Author:   gurch
Date:     2010-03-31 14:08:55 +0000 (Wed, 31 Mar 2010)

Log Message:
-----------
(bug 22339) "Go" result should be available through the API

Modified Paths:
--------------
    trunk/phase3/includes/AutoLoader.php
    trunk/phase3/includes/api/ApiMain.php

Added Paths:
-----------
    trunk/phase3/includes/api/ApiGo.php

Modified: trunk/phase3/includes/AutoLoader.php
===================================================================
--- trunk/phase3/includes/AutoLoader.php        2010-03-31 12:33:11 UTC (rev 
64435)
+++ trunk/phase3/includes/AutoLoader.php        2010-03-31 14:08:55 UTC (rev 
64436)
@@ -279,6 +279,7 @@
        'ApiFormatWddx' => 'includes/api/ApiFormatWddx.php',
        'ApiFormatXml' => 'includes/api/ApiFormatXml.php',
        'ApiFormatYaml' => 'includes/api/ApiFormatYaml.php',
+       'ApiGo' => 'includes/api/ApiGo.php',
        'ApiHelp' => 'includes/api/ApiHelp.php',
        'ApiImport' => 'includes/api/ApiImport.php',
        'ApiImportReporter' => 'includes/api/ApiImport.php',

Added: trunk/phase3/includes/api/ApiGo.php
===================================================================
--- trunk/phase3/includes/api/ApiGo.php                         (rev 0)
+++ trunk/phase3/includes/api/ApiGo.php 2010-03-31 14:08:55 UTC (rev 64436)
@@ -0,0 +1,101 @@
+<?php
+
+/**
+ * Created on Mar 30, 2010
+ * API for MediaWiki 1.8+
+ *
+ * Copyright © 2010 Matthew Britton <Firstname>.<Lastname>@btinternet.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+if ( !defined( 'MEDIAWIKI' ) ) {
+       // Eclipse helper - will be ignored in production
+       require_once( "ApiBase.php" );
+}
+
+/**
+* API module to determine the result of a "Go" search
+*
+ * @ingroup API
+ */
+class ApiGo extends ApiBase {
+
+       /**
+        * Std ctor.
+        */
+       public function __construct( $main, $action ) {
+               parent::__construct( $main, $action );
+       }
+
+       public function execute() {
+               $params = $this->extractRequestParams();
+               $text = $params['text'];
+
+               if ( is_null( $text ) ) {
+                       $this->dieUsageMsg( array( 'missingparam', 'text' ) );
+               }
+               
+               // Strip underscores
+               $text = str_replace( '_', ' ', $text );
+               
+               $nearMatch = SearchEngine::getNearMatch( $text );
+
+               $this->getResult()->addValue( null, $this->getModuleName(), 
array( 'text' => $text, 'result' => $nearMatch ) );
+       }
+
+       public function mustBePosted() {
+               return false;
+       }
+
+       public function isWriteMode() {
+               return false;
+       }
+
+       public function getAllowedParams() {
+               return array(
+                       'text' => null,
+               );
+       }
+
+       public function getParamDescription() {
+               return array(
+                       'text' => 'Text to try a "Go" match for'
+               );
+       }
+
+       public function getDescription() {
+               return array(
+                       'Determine the title one will be taken to by a "Go" 
search, if any'
+               );
+       }
+       
+       public function getPossibleErrors() {
+               return array_merge( parent::getPossibleErrors(), array(
+                       array( 'missingparam', 'text' )
+               ) );
+       }
+
+       protected function getExamples() {
+               return array(
+                       'api.php?action=go&text=Foo'
+               );
+       }
+
+       public function getVersion() {
+               return __CLASS__ . ': $Id: $';
+       }
+}


Property changes on: trunk/phase3/includes/api/ApiGo.php
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: trunk/phase3/includes/api/ApiMain.php
===================================================================
--- trunk/phase3/includes/api/ApiMain.php       2010-03-31 12:33:11 UTC (rev 
64435)
+++ trunk/phase3/includes/api/ApiMain.php       2010-03-31 14:08:55 UTC (rev 
64436)
@@ -63,6 +63,7 @@
                'parse' => 'ApiParse',
                'opensearch' => 'ApiOpenSearch',
                'feedwatchlist' => 'ApiFeedWatchlist',
+               'go' => 'ApiGo',
                'help' => 'ApiHelp',
                'paraminfo' => 'ApiParamInfo',
 



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to