r64436 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64435‎ | r64436 | r64437 >
Date:14:08, 31 March 2010
Author:gurch
Status:reverted (Comments)
Tags:
Comment:
(bug 22339) "Go" result should be available through the API
Modified paths:
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/api/ApiGo.php (added) (history)
  • /trunk/phase3/includes/api/ApiMain.php (modified) (history)

Diff [purge]

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
1103 + native
Index: trunk/phase3/includes/api/ApiMain.php
@@ -63,6 +63,7 @@
6464 'parse' => 'ApiParse',
6565 'opensearch' => 'ApiOpenSearch',
6666 'feedwatchlist' => 'ApiFeedWatchlist',
 67+ 'go' => 'ApiGo',
6768 'help' => 'ApiHelp',
6869 'paraminfo' => 'ApiParamInfo',
6970
Index: trunk/phase3/includes/AutoLoader.php
@@ -279,6 +279,7 @@
280280 'ApiFormatWddx' => 'includes/api/ApiFormatWddx.php',
281281 'ApiFormatXml' => 'includes/api/ApiFormatXml.php',
282282 'ApiFormatYaml' => 'includes/api/ApiFormatYaml.php',
 283+ 'ApiGo' => 'includes/api/ApiGo.php',
283284 'ApiHelp' => 'includes/api/ApiHelp.php',
284285 'ApiImport' => 'includes/api/ApiImport.php',
285286 'ApiImportReporter' => 'includes/api/ApiImport.php',

Follow-up revisions

RevisionCommit summaryAuthorDate
r64437release notes for r64436gurch14:39, 31 March 2010
r64508svn:keywords Id for r64436reedy22:38, 1 April 2010
r69202Revert r64436, r64437, r64508 per CR r64436btongminh09:46, 9 July 2010
r69203(bug 22339) Added srwhat=nearmatch to list=search to get a "go" result...btongminh11:08, 9 July 2010

Comments

#Comment by Catrope (talk | contribs)   16:36, 31 March 2010
+		return __CLASS__ . ': $Id: $';

You'll need to set svn:keywords=Id on the file for this to work.

#Comment by Bryan (talk | contribs)   17:07, 31 March 2010

It would be much more logical to implement this as a parameter to list=search. Alternatively this could be a query-generator submodule, so that other page properties can be fetched as well. Also this results an empty string if no match can be found, is the purposefully?

#Comment by Catrope (talk | contribs)   18:34, 31 March 2010

Yes, this should at the very least be a generator, and probably be a mode of list=search.

#Comment by Gurch (talk | contribs)   19:02, 31 March 2010

Generator is definitely a good idea.

As for making it a parameter to list=search, I wasn't sure how that would work. There could certainly be an extra parameter to return the "go" title match in addition to the search results, but catrope's original request (in bug 22339) was after something that would "not run a full-blown search ... if there is no title match". If the parameter on list=search did that it wouldn't be a list any more, which would be confusing.

#Comment by Bryan (talk | contribs)   21:14, 29 April 2010

It's still a list, but a list of 1 item. I don't think that is that confusing.

#Comment by Bryan (talk | contribs)   21:31, 7 July 2010

I am going to revert this, since it has been three months without fix and I don't want the risk of this getting live and having to break it later.

Status & tagging log