2006-10-01 04:38:31 +00:00
|
|
|
<?php
|
2010-02-23 18:05:46 +00:00
|
|
|
/**
|
2010-12-22 20:52:06 +00:00
|
|
|
*
|
2006-10-01 04:38:31 +00:00
|
|
|
*
|
2010-08-07 19:59:42 +00:00
|
|
|
* Created on Sep 4, 2006
|
|
|
|
|
*
|
2012-07-15 20:13:02 +00:00
|
|
|
* Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
|
2006-10-01 04:38:31 +00:00
|
|
|
*
|
|
|
|
|
* 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.,
|
2010-06-21 13:13:32 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2006-10-01 04:38:31 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2010-08-07 19:59:42 +00:00
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @defgroup API API
|
2006-10-01 04:38:31 +00:00
|
|
|
*/
|
|
|
|
|
|
2006-10-14 07:18:08 +00:00
|
|
|
/**
|
2007-05-19 20:26:08 +00:00
|
|
|
* This is the main API class, used for both external and internal processing.
|
|
|
|
|
* When executed, it will create the requested formatter object,
|
|
|
|
|
* instantiate and execute an object associated with the needed action,
|
|
|
|
|
* and use formatter to print results.
|
|
|
|
|
* In case of an exception, an error message will be printed using the same formatter.
|
|
|
|
|
*
|
|
|
|
|
* To use API from another application, run it using FauxRequest object, in which
|
|
|
|
|
* case any internal exceptions will not be handled but passed up to the caller.
|
2008-04-14 07:45:50 +00:00
|
|
|
* After successful execution, use getResult() for the resulting data.
|
|
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup API
|
2006-10-14 07:18:08 +00:00
|
|
|
*/
|
2006-10-01 04:38:31 +00:00
|
|
|
class ApiMain extends ApiBase {
|
2006-10-14 07:18:08 +00:00
|
|
|
/**
|
|
|
|
|
* When no format parameter is given, this format will be used
|
|
|
|
|
*/
|
2014-09-16 20:45:09 +00:00
|
|
|
const API_DEFAULT_FORMAT = 'jsonfm';
|
2006-10-14 07:18:08 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* List of available modules: action name => module class
|
|
|
|
|
*/
|
2010-02-23 18:05:46 +00:00
|
|
|
private static $Modules = array(
|
2007-05-27 23:50:24 +00:00
|
|
|
'login' => 'ApiLogin',
|
2008-01-08 18:10:58 +00:00
|
|
|
'logout' => 'ApiLogout',
|
2012-08-08 13:58:47 +00:00
|
|
|
'createaccount' => 'ApiCreateAccount',
|
2007-05-14 05:28:06 +00:00
|
|
|
'query' => 'ApiQuery',
|
2007-10-08 14:24:54 +00:00
|
|
|
'expandtemplates' => 'ApiExpandTemplates',
|
2007-12-01 13:37:02 +00:00
|
|
|
'parse' => 'ApiParse',
|
2014-11-20 00:33:51 +00:00
|
|
|
'stashedit' => 'ApiStashEdit',
|
2007-12-03 15:52:27 +00:00
|
|
|
'opensearch' => 'ApiOpenSearch',
|
2011-06-06 14:50:34 +00:00
|
|
|
'feedcontributions' => 'ApiFeedContributions',
|
2014-02-02 16:30:44 +00:00
|
|
|
'feedrecentchanges' => 'ApiFeedRecentChanges',
|
2007-12-03 15:52:27 +00:00
|
|
|
'feedwatchlist' => 'ApiFeedWatchlist',
|
|
|
|
|
'help' => 'ApiHelp',
|
2008-01-22 21:22:04 +00:00
|
|
|
'paraminfo' => 'ApiParamInfo',
|
2010-10-28 19:20:21 +00:00
|
|
|
'rsd' => 'ApiRsd',
|
2011-05-01 21:56:02 +00:00
|
|
|
'compare' => 'ApiComparePages',
|
2012-03-28 22:02:10 +00:00
|
|
|
'tokens' => 'ApiTokens',
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2009-03-06 13:49:44 +00:00
|
|
|
// Write modules
|
|
|
|
|
'purge' => 'ApiPurge',
|
2012-08-20 14:55:28 +00:00
|
|
|
'setnotificationtimestamp' => 'ApiSetNotificationTimestamp',
|
2007-12-02 14:24:07 +00:00
|
|
|
'rollback' => 'ApiRollback',
|
|
|
|
|
'delete' => 'ApiDelete',
|
|
|
|
|
'undelete' => 'ApiUndelete',
|
|
|
|
|
'protect' => 'ApiProtect',
|
|
|
|
|
'block' => 'ApiBlock',
|
|
|
|
|
'unblock' => 'ApiUnblock',
|
2008-01-04 22:33:22 +00:00
|
|
|
'move' => 'ApiMove',
|
2008-03-03 18:08:40 +00:00
|
|
|
'edit' => 'ApiEditPage',
|
here it is ... the upload-api, script-server, js2 (javascript phase2) branch merge 1st attempt.
Here is a short overview of changes and associated default configuration variables (most everything is off by default) also see ~soon to be updated~: http://www.mediawiki.org/wiki/Media_Projects_Overview
= Upload Improvements =
==Upload API ==
* Based on the early work of Bryan Tong and others it adds the upload option to the api.
* We rewrite Special:Upload page to include use the new refactoring
* Added in token checks in both the SpecialUpload.php page so avoids DOS / xss copy-by-url JavaScript based cross site POST file submissions
== Copy by URL==
$wgAllowCopyUploads = false;
* http class rewrite includes a new http background download see: includes/HttpFunctions.php
* spins off a php process that calls: maintenance/http_session_download.php
* pushes updates to the session and gives the user a progress bar on http copy uploads from other server progress (using js2 upload interface) (if not using the js2 upload interface it does the request in-place but the download is limited to the php ini timeout time)
== Firefogg ==
* Firefogg enables resumable upload by chunks
* progress indicators and conditional invokation (js2 system)
* and of-course client side transcoding.
= Script Server =
$wgEnableScriptLoader = false;
* off by default if $wgEnableScriptLoader is turned on script files are grouped, gziped, cached etc.
for more info see: http://www.mediawiki.org/wiki/Extension:ScriptLoader
* Includes some early skin js include fixes (skin/script system still lots of love)
* Includes a "javascript class autoloader" this is packaged into mwEmbed so that the mwEmbed library can work in stand alone mode (while retaining localization and script serving) (one such application is the make page for firefogg.org : http://www.firefogg.org/make/index.html )
* The file that contains the autojavascript loading classes is: js2/php/jsAutoloadLocalClasses.php
* One can use this auto class loading dependency system with extensions and add-ons but I need to better document that.
= js2 system / mwEmbed=
$wgEnableJS2system = false
* includes initial rewrite towards more jquery based javascript code
* especially for the Special:Upload page.
* Also the edit page include support for the "add-media-wizard"
* includes dependency loader for javascript that optionally takes advantage of the script-loader
* remote embedding of javascript interfaces (like embedding video, or commons media searching)
* $wgDebugJavaScript = false; .. .this variable lets you always get "always fresh javascript". When used with the script-loader it does not minify the script-loader output.
= mwEmbed =
* Will commit a separate patch to oggHandler that conditionally outputs <video tag> to use the new javascript video player.
** mv_embed player includes: play-head, volume control, remote embedding, oggz-chop support across plugins.
* add-media-wizard adds easy inserts of media to pages (with import)
== jQuery==
* we include a base install of jQuery, jQuery ui and some plugins.
* all the javascript classes are in the scriptloader so its easy to load any set of jquery ui components that you may need using the script-server. You get a callback so you can then execute js with dependencies loaded.
== other stuff ==
there is a bit more code in js2 that pertains to sequence editing, timed text display and basic image editing. We include a base import of pixastic-lib & pixastic-editor... will work with the pixastic developer to try and ensure upstream compatibility on our usage of the library for in-browser photo and sequence manipulation.
2009-07-14 23:52:14 +00:00
|
|
|
'upload' => 'ApiUpload',
|
2011-03-05 17:23:35 +00:00
|
|
|
'filerevert' => 'ApiFileRevert',
|
2008-06-01 17:58:27 +00:00
|
|
|
'emailuser' => 'ApiEmailUser',
|
2008-08-21 15:44:13 +00:00
|
|
|
'watch' => 'ApiWatch',
|
2008-09-04 15:17:51 +00:00
|
|
|
'patrol' => 'ApiPatrol',
|
2009-02-04 20:11:27 +00:00
|
|
|
'import' => 'ApiImport',
|
2014-08-26 13:06:12 +00:00
|
|
|
'clearhasmsg' => 'ApiClearHasMsg',
|
2009-03-28 19:08:47 +00:00
|
|
|
'userrights' => 'ApiUserrights',
|
2012-04-16 20:02:34 +00:00
|
|
|
'options' => 'ApiOptions',
|
2013-03-24 10:01:51 +00:00
|
|
|
'imagerotate' => 'ApiImageRotate',
|
2013-06-26 20:59:40 +00:00
|
|
|
'revisiondelete' => 'ApiRevisionDelete',
|
2006-10-14 07:18:08 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* List of available formats: format name => format class
|
|
|
|
|
*/
|
2010-02-23 18:05:46 +00:00
|
|
|
private static $Formats = array(
|
2006-10-14 07:18:08 +00:00
|
|
|
'json' => 'ApiFormatJson',
|
|
|
|
|
'jsonfm' => 'ApiFormatJson',
|
2006-10-22 23:45:20 +00:00
|
|
|
'php' => 'ApiFormatPhp',
|
|
|
|
|
'phpfm' => 'ApiFormatPhp',
|
|
|
|
|
'wddx' => 'ApiFormatWddx',
|
|
|
|
|
'wddxfm' => 'ApiFormatWddx',
|
2006-10-14 07:18:08 +00:00
|
|
|
'xml' => 'ApiFormatXml',
|
|
|
|
|
'xmlfm' => 'ApiFormatXml',
|
|
|
|
|
'yaml' => 'ApiFormatYaml',
|
2006-10-22 23:45:20 +00:00
|
|
|
'yamlfm' => 'ApiFormatYaml',
|
2008-01-24 13:12:03 +00:00
|
|
|
'rawfm' => 'ApiFormatJson',
|
|
|
|
|
'txt' => 'ApiFormatTxt',
|
2008-01-24 13:16:34 +00:00
|
|
|
'txtfm' => 'ApiFormatTxt',
|
|
|
|
|
'dbg' => 'ApiFormatDbg',
|
2010-08-09 00:19:55 +00:00
|
|
|
'dbgfm' => 'ApiFormatDbg',
|
|
|
|
|
'dump' => 'ApiFormatDump',
|
|
|
|
|
'dumpfm' => 'ApiFormatDump',
|
2012-04-16 15:45:51 +00:00
|
|
|
'none' => 'ApiFormatNone',
|
2006-10-14 07:18:08 +00:00
|
|
|
);
|
2010-01-22 03:14:52 +00:00
|
|
|
|
2013-11-16 19:09:17 +00:00
|
|
|
// @codingStandardsIgnoreStart String contenation on "msg" not allowed to break long line
|
2008-08-04 14:26:20 +00:00
|
|
|
/**
|
|
|
|
|
* List of user roles that are specifically relevant to the API.
|
|
|
|
|
* array( 'right' => array ( 'msg' => 'Some message with a $1',
|
|
|
|
|
* 'params' => array ( $someVarToSubst ) ),
|
|
|
|
|
* );
|
|
|
|
|
*/
|
2010-02-23 18:05:46 +00:00
|
|
|
private static $mRights = array(
|
|
|
|
|
'writeapi' => array(
|
API: HTMLize and internationalize the help, add Special:ApiHelp
The existing API help, formatted as basically a plain-text document
embedded in XML and with a little bolding and a few links
syntax-highlighted in after the fact, works ok for experienced programmers
but isn't at all newbie-friendly. Further, all the help is hard-coded in
English, which isn't very friendly to non-English speakers.
So let's rewrite it. The help text is now obtained from i18n messages
and output in HTML, with the default display consisting of help for a
single module with links to help for other modules. This, of course,
necessitates deprecating many of the existing help-related methods and
hooks and replacing them with new ones, but backwards compatibility is
maintained for almost everything.
At the same time, action=paraminfo also needs to support the
'description' and other help-related fields being output in wikitext or
HTML, and I11cb063d (to access all modules via the 'modules' parameter
instead of having 'modules', 'formatmodules', 'querymodules', and so on)
is folded in.
And we also add Special:ApiHelp. When directly accessed, it simply
redirects to api.php with appropriate parameters. But it's also
transcludable to allow up-to-date API help text to be included within
the on-wiki documentation.
Note this patch doesn't actually add i18n messages for any API modules
besides ApiMain and ApiHelp. That will come in a followup patch, but for
the moment the backwards-compatibility code handles them nicely.
While we're messing with the documentation, we may as well add the
"internal" flag requested in bug 62905 (although the 'includeinternal'
parameter it also requests doesn't make much sense anymore) and a
"deprecated" flag that's needed by several modules now.
Bug: 30936
Bug: 38126
Bug: 42343
Bug: 45641
Bug: 62905
Bug: 63211
Change-Id: Ib14c00df06d85c2f6364d83b2b10ce34c7f513cc
2014-09-16 17:54:01 +00:00
|
|
|
'msg' => 'right-writeapi',
|
2010-02-23 18:05:46 +00:00
|
|
|
'params' => array()
|
|
|
|
|
),
|
2012-10-26 16:18:59 +00:00
|
|
|
'apihighlimits' => array(
|
API: HTMLize and internationalize the help, add Special:ApiHelp
The existing API help, formatted as basically a plain-text document
embedded in XML and with a little bolding and a few links
syntax-highlighted in after the fact, works ok for experienced programmers
but isn't at all newbie-friendly. Further, all the help is hard-coded in
English, which isn't very friendly to non-English speakers.
So let's rewrite it. The help text is now obtained from i18n messages
and output in HTML, with the default display consisting of help for a
single module with links to help for other modules. This, of course,
necessitates deprecating many of the existing help-related methods and
hooks and replacing them with new ones, but backwards compatibility is
maintained for almost everything.
At the same time, action=paraminfo also needs to support the
'description' and other help-related fields being output in wikitext or
HTML, and I11cb063d (to access all modules via the 'modules' parameter
instead of having 'modules', 'formatmodules', 'querymodules', and so on)
is folded in.
And we also add Special:ApiHelp. When directly accessed, it simply
redirects to api.php with appropriate parameters. But it's also
transcludable to allow up-to-date API help text to be included within
the on-wiki documentation.
Note this patch doesn't actually add i18n messages for any API modules
besides ApiMain and ApiHelp. That will come in a followup patch, but for
the moment the backwards-compatibility code handles them nicely.
While we're messing with the documentation, we may as well add the
"internal" flag requested in bug 62905 (although the 'includeinternal'
parameter it also requests doesn't make much sense anymore) and a
"deprecated" flag that's needed by several modules now.
Bug: 30936
Bug: 38126
Bug: 42343
Bug: 45641
Bug: 62905
Bug: 63211
Change-Id: Ib14c00df06d85c2f6364d83b2b10ce34c7f513cc
2014-09-16 17:54:01 +00:00
|
|
|
'msg' => 'api-help-right-apihighlimits',
|
2010-07-22 21:54:19 +00:00
|
|
|
'params' => array( ApiBase::LIMIT_SML2, ApiBase::LIMIT_BIG2 )
|
2010-02-23 18:05:46 +00:00
|
|
|
)
|
2008-08-05 16:12:52 +00:00
|
|
|
);
|
2013-11-16 19:09:17 +00:00
|
|
|
// @codingStandardsIgnoreEnd
|
2008-08-04 14:26:20 +00:00
|
|
|
|
2010-12-23 19:53:28 +00:00
|
|
|
/**
|
|
|
|
|
* @var ApiFormatBase
|
|
|
|
|
*/
|
|
|
|
|
private $mPrinter;
|
|
|
|
|
|
2013-02-05 06:52:55 +00:00
|
|
|
private $mModuleMgr, $mResult;
|
|
|
|
|
private $mAction;
|
|
|
|
|
private $mEnableWrite;
|
2010-07-26 07:35:30 +00:00
|
|
|
private $mInternalMode, $mSquidMaxage, $mModule;
|
2006-10-01 04:38:31 +00:00
|
|
|
|
2010-07-23 07:17:56 +00:00
|
|
|
private $mCacheMode = 'private';
|
|
|
|
|
private $mCacheControl = array();
|
2012-09-19 10:07:48 +00:00
|
|
|
private $mParamsUsed = array();
|
2010-02-14 23:52:45 +00:00
|
|
|
|
2006-10-01 04:38:31 +00:00
|
|
|
/**
|
2010-02-23 18:05:46 +00:00
|
|
|
* Constructs an instance of ApiMain that utilizes the module and format specified by $request.
|
|
|
|
|
*
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param IContextSource|WebRequest $context If this is an instance of
|
2013-11-16 19:09:17 +00:00
|
|
|
* FauxRequest, errors are thrown and no printing occurs
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param bool $enableWrite Should be set to true if the api may modify data
|
2010-02-23 18:05:46 +00:00
|
|
|
*/
|
2011-10-26 23:27:01 +00:00
|
|
|
public function __construct( $context = null, $enableWrite = false ) {
|
|
|
|
|
if ( $context === null ) {
|
|
|
|
|
$context = RequestContext::getMain();
|
|
|
|
|
} elseif ( $context instanceof WebRequest ) {
|
|
|
|
|
// BC for pre-1.19
|
|
|
|
|
$request = $context;
|
|
|
|
|
$context = RequestContext::getMain();
|
|
|
|
|
}
|
|
|
|
|
// We set a derivative context so we can change stuff later
|
|
|
|
|
$this->setContext( new DerivativeContext( $context ) );
|
|
|
|
|
|
2011-10-27 01:13:19 +00:00
|
|
|
if ( isset( $request ) ) {
|
2011-10-29 16:14:11 +00:00
|
|
|
$this->getContext()->setRequest( $request );
|
2011-10-27 01:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
2011-10-26 23:27:01 +00:00
|
|
|
$this->mInternalMode = ( $this->getRequest() instanceof FauxRequest );
|
2006-10-25 03:54:56 +00:00
|
|
|
|
2006-10-01 04:38:31 +00:00
|
|
|
// Special handling for the main module: $parent === $this
|
2010-02-23 18:05:46 +00:00
|
|
|
parent::__construct( $this, $this->mInternalMode ? 'main_int' : 'main' );
|
2006-10-01 04:38:31 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( !$this->mInternalMode ) {
|
2007-07-12 06:54:08 +00:00
|
|
|
// Impose module restrictions.
|
2008-04-14 07:45:50 +00:00
|
|
|
// If the current user cannot read,
|
2007-07-14 19:04:31 +00:00
|
|
|
// Remove all modules other than login
|
|
|
|
|
global $wgUser;
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2012-09-19 10:07:48 +00:00
|
|
|
if ( $this->getVal( 'callback' ) !== null ) {
|
2008-03-03 05:45:37 +00:00
|
|
|
// JSON callback allows cross-site reads.
|
|
|
|
|
// For safety, strip user credentials.
|
|
|
|
|
wfDebug( "API: stripping user credentials for JSON callback\n" );
|
|
|
|
|
$wgUser = new User();
|
2011-10-26 23:27:01 +00:00
|
|
|
$this->getContext()->setUser( $wgUser );
|
2008-03-03 05:45:37 +00:00
|
|
|
}
|
2007-07-12 06:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
API: HTMLize and internationalize the help, add Special:ApiHelp
The existing API help, formatted as basically a plain-text document
embedded in XML and with a little bolding and a few links
syntax-highlighted in after the fact, works ok for experienced programmers
but isn't at all newbie-friendly. Further, all the help is hard-coded in
English, which isn't very friendly to non-English speakers.
So let's rewrite it. The help text is now obtained from i18n messages
and output in HTML, with the default display consisting of help for a
single module with links to help for other modules. This, of course,
necessitates deprecating many of the existing help-related methods and
hooks and replacing them with new ones, but backwards compatibility is
maintained for almost everything.
At the same time, action=paraminfo also needs to support the
'description' and other help-related fields being output in wikitext or
HTML, and I11cb063d (to access all modules via the 'modules' parameter
instead of having 'modules', 'formatmodules', 'querymodules', and so on)
is folded in.
And we also add Special:ApiHelp. When directly accessed, it simply
redirects to api.php with appropriate parameters. But it's also
transcludable to allow up-to-date API help text to be included within
the on-wiki documentation.
Note this patch doesn't actually add i18n messages for any API modules
besides ApiMain and ApiHelp. That will come in a followup patch, but for
the moment the backwards-compatibility code handles them nicely.
While we're messing with the documentation, we may as well add the
"internal" flag requested in bug 62905 (although the 'includeinternal'
parameter it also requests doesn't make much sense anymore) and a
"deprecated" flag that's needed by several modules now.
Bug: 30936
Bug: 38126
Bug: 42343
Bug: 45641
Bug: 62905
Bug: 63211
Change-Id: Ib14c00df06d85c2f6364d83b2b10ce34c7f513cc
2014-09-16 17:54:01 +00:00
|
|
|
$uselang = $this->getParameter( 'uselang' );
|
|
|
|
|
if ( $uselang === 'user' ) {
|
|
|
|
|
$uselang = $this->getUser()->getOption( 'language' );
|
|
|
|
|
$uselang = RequestContext::sanitizeLangCode( $uselang );
|
2014-12-09 07:23:30 +00:00
|
|
|
Hooks::run( 'UserGetLanguageObject', array( $this->getUser(), &$uselang, $this ) );
|
2014-11-04 21:42:43 +00:00
|
|
|
} elseif ( $uselang === 'content' ) {
|
|
|
|
|
global $wgContLang;
|
|
|
|
|
$uselang = $wgContLang->getCode();
|
API: HTMLize and internationalize the help, add Special:ApiHelp
The existing API help, formatted as basically a plain-text document
embedded in XML and with a little bolding and a few links
syntax-highlighted in after the fact, works ok for experienced programmers
but isn't at all newbie-friendly. Further, all the help is hard-coded in
English, which isn't very friendly to non-English speakers.
So let's rewrite it. The help text is now obtained from i18n messages
and output in HTML, with the default display consisting of help for a
single module with links to help for other modules. This, of course,
necessitates deprecating many of the existing help-related methods and
hooks and replacing them with new ones, but backwards compatibility is
maintained for almost everything.
At the same time, action=paraminfo also needs to support the
'description' and other help-related fields being output in wikitext or
HTML, and I11cb063d (to access all modules via the 'modules' parameter
instead of having 'modules', 'formatmodules', 'querymodules', and so on)
is folded in.
And we also add Special:ApiHelp. When directly accessed, it simply
redirects to api.php with appropriate parameters. But it's also
transcludable to allow up-to-date API help text to be included within
the on-wiki documentation.
Note this patch doesn't actually add i18n messages for any API modules
besides ApiMain and ApiHelp. That will come in a followup patch, but for
the moment the backwards-compatibility code handles them nicely.
While we're messing with the documentation, we may as well add the
"internal" flag requested in bug 62905 (although the 'includeinternal'
parameter it also requests doesn't make much sense anymore) and a
"deprecated" flag that's needed by several modules now.
Bug: 30936
Bug: 38126
Bug: 42343
Bug: 45641
Bug: 62905
Bug: 63211
Change-Id: Ib14c00df06d85c2f6364d83b2b10ce34c7f513cc
2014-09-16 17:54:01 +00:00
|
|
|
}
|
|
|
|
|
$code = RequestContext::sanitizeLangCode( $uselang );
|
|
|
|
|
$this->getContext()->setLanguage( $code );
|
|
|
|
|
if ( !$this->mInternalMode ) {
|
|
|
|
|
global $wgLang;
|
2014-10-22 21:26:40 +00:00
|
|
|
$wgLang = $this->getContext()->getLanguage();
|
|
|
|
|
RequestContext::getMain()->setLanguage( $wgLang );
|
API: HTMLize and internationalize the help, add Special:ApiHelp
The existing API help, formatted as basically a plain-text document
embedded in XML and with a little bolding and a few links
syntax-highlighted in after the fact, works ok for experienced programmers
but isn't at all newbie-friendly. Further, all the help is hard-coded in
English, which isn't very friendly to non-English speakers.
So let's rewrite it. The help text is now obtained from i18n messages
and output in HTML, with the default display consisting of help for a
single module with links to help for other modules. This, of course,
necessitates deprecating many of the existing help-related methods and
hooks and replacing them with new ones, but backwards compatibility is
maintained for almost everything.
At the same time, action=paraminfo also needs to support the
'description' and other help-related fields being output in wikitext or
HTML, and I11cb063d (to access all modules via the 'modules' parameter
instead of having 'modules', 'formatmodules', 'querymodules', and so on)
is folded in.
And we also add Special:ApiHelp. When directly accessed, it simply
redirects to api.php with appropriate parameters. But it's also
transcludable to allow up-to-date API help text to be included within
the on-wiki documentation.
Note this patch doesn't actually add i18n messages for any API modules
besides ApiMain and ApiHelp. That will come in a followup patch, but for
the moment the backwards-compatibility code handles them nicely.
While we're messing with the documentation, we may as well add the
"internal" flag requested in bug 62905 (although the 'includeinternal'
parameter it also requests doesn't make much sense anymore) and a
"deprecated" flag that's needed by several modules now.
Bug: 30936
Bug: 38126
Bug: 42343
Bug: 45641
Bug: 62905
Bug: 63211
Change-Id: Ib14c00df06d85c2f6364d83b2b10ce34c7f513cc
2014-09-16 17:54:01 +00:00
|
|
|
}
|
|
|
|
|
|
2014-01-24 02:51:11 +00:00
|
|
|
$config = $this->getConfig();
|
2013-02-05 06:52:55 +00:00
|
|
|
$this->mModuleMgr = new ApiModuleManager( $this );
|
|
|
|
|
$this->mModuleMgr->addModules( self::$Modules, 'action' );
|
2014-01-24 02:51:11 +00:00
|
|
|
$this->mModuleMgr->addModules( $config->get( 'APIModules' ), 'action' );
|
2013-02-05 06:52:55 +00:00
|
|
|
$this->mModuleMgr->addModules( self::$Formats, 'format' );
|
2014-01-24 02:51:11 +00:00
|
|
|
$this->mModuleMgr->addModules( $config->get( 'APIFormatModules' ), 'format' );
|
2006-10-22 23:45:20 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->mResult = new ApiResult( $this );
|
2006-10-02 18:27:06 +00:00
|
|
|
$this->mEnableWrite = $enableWrite;
|
2006-10-22 23:45:20 +00:00
|
|
|
|
2013-11-14 12:42:04 +00:00
|
|
|
$this->mSquidMaxage = -1; // flag for executeActionWithErrorHandling()
|
2008-04-11 15:20:45 +00:00
|
|
|
$this->mCommit = false;
|
2006-10-01 04:38:31 +00:00
|
|
|
}
|
|
|
|
|
|
2007-07-15 00:52:35 +00:00
|
|
|
/**
|
|
|
|
|
* Return true if the API was started by other PHP code using FauxRequest
|
2011-01-30 08:16:13 +00:00
|
|
|
* @return bool
|
2007-07-15 00:52:35 +00:00
|
|
|
*/
|
|
|
|
|
public function isInternalMode() {
|
|
|
|
|
return $this->mInternalMode;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-20 10:08:40 +00:00
|
|
|
/**
|
2010-01-22 03:14:52 +00:00
|
|
|
* Get the ApiResult object associated with current request
|
2010-09-29 18:18:07 +00:00
|
|
|
*
|
|
|
|
|
* @return ApiResult
|
2007-05-20 10:08:40 +00:00
|
|
|
*/
|
2006-11-29 05:45:03 +00:00
|
|
|
public function getResult() {
|
2006-10-14 07:18:08 +00:00
|
|
|
return $this->mResult;
|
2006-10-01 21:20:55 +00:00
|
|
|
}
|
2010-01-22 03:14:52 +00:00
|
|
|
|
2009-08-27 22:09:28 +00:00
|
|
|
/**
|
|
|
|
|
* Get the API module object. Only works after executeAction()
|
2011-01-30 08:16:13 +00:00
|
|
|
*
|
|
|
|
|
* @return ApiBase
|
2009-08-27 22:09:28 +00:00
|
|
|
*/
|
|
|
|
|
public function getModule() {
|
|
|
|
|
return $this->mModule;
|
|
|
|
|
}
|
2010-07-23 07:33:40 +00:00
|
|
|
|
2010-06-03 09:53:28 +00:00
|
|
|
/**
|
|
|
|
|
* Get the result formatter object. Only works after setupExecuteAction()
|
2010-09-29 18:18:07 +00:00
|
|
|
*
|
|
|
|
|
* @return ApiFormatBase
|
2010-06-03 09:53:28 +00:00
|
|
|
*/
|
|
|
|
|
public function getPrinter() {
|
|
|
|
|
return $this->mPrinter;
|
|
|
|
|
}
|
2006-10-01 21:20:55 +00:00
|
|
|
|
2007-05-20 10:08:40 +00:00
|
|
|
/**
|
|
|
|
|
* Set how long the response should be cached.
|
2011-05-08 16:48:30 +00:00
|
|
|
*
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param int $maxage
|
2007-05-20 10:08:40 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
public function setCacheMaxAge( $maxage ) {
|
2010-02-14 23:52:45 +00:00
|
|
|
$this->setCacheControl( array(
|
|
|
|
|
'max-age' => $maxage,
|
|
|
|
|
's-maxage' => $maxage
|
|
|
|
|
) );
|
|
|
|
|
}
|
2010-07-23 07:17:56 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the type of caching headers which will be sent.
|
|
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $mode One of:
|
2010-07-23 07:33:40 +00:00
|
|
|
* - 'public': Cache this object in public caches, if the maxage or smaxage
|
2010-07-23 07:17:56 +00:00
|
|
|
* parameter is set, or if setCacheMaxAge() was called. If a maximum age is
|
|
|
|
|
* not provided by any of these means, the object will be private.
|
|
|
|
|
* - 'private': Cache this object only in private client-side caches.
|
|
|
|
|
* - 'anon-public-user-private': Make this object cacheable for logged-out
|
2010-07-23 07:33:40 +00:00
|
|
|
* users, but private for logged-in users. IMPORTANT: If this is set, it must be
|
|
|
|
|
* set consistently for a given URL, it cannot be set differently depending on
|
2010-07-23 07:17:56 +00:00
|
|
|
* things like the contents of the database, or whether the user is logged in.
|
|
|
|
|
*
|
|
|
|
|
* If the wiki does not allow anonymous users to read it, the mode set here
|
2010-07-23 07:33:40 +00:00
|
|
|
* will be ignored, and private caching headers will always be sent. In other words,
|
2010-07-23 07:17:56 +00:00
|
|
|
* the "public" mode is equivalent to saying that the data sent is as public as a page
|
|
|
|
|
* view.
|
|
|
|
|
*
|
2010-07-23 07:33:40 +00:00
|
|
|
* For user-dependent data, the private mode should generally be used. The
|
|
|
|
|
* anon-public-user-private mode should only be used where there is a particularly
|
2010-07-23 07:17:56 +00:00
|
|
|
* good performance reason for caching the anonymous response, but where the
|
2010-07-23 07:33:40 +00:00
|
|
|
* response to logged-in users may differ, or may contain private data.
|
2010-07-23 07:17:56 +00:00
|
|
|
*
|
|
|
|
|
* If this function is never called, then the default will be the private mode.
|
|
|
|
|
*/
|
|
|
|
|
public function setCacheMode( $mode ) {
|
|
|
|
|
if ( !in_array( $mode, array( 'private', 'public', 'anon-public-user-private' ) ) ) {
|
2010-07-23 07:33:40 +00:00
|
|
|
wfDebug( __METHOD__ . ": unrecognised cache mode \"$mode\"\n" );
|
2013-11-14 12:42:04 +00:00
|
|
|
|
2010-07-23 07:17:56 +00:00
|
|
|
// Ignore for forwards-compatibility
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-26 14:58:02 +00:00
|
|
|
if ( !User::isEveryoneAllowed( 'read' ) ) {
|
2010-07-23 07:17:56 +00:00
|
|
|
// Private wiki, only private headers
|
|
|
|
|
if ( $mode !== 'private' ) {
|
2010-07-23 07:33:40 +00:00
|
|
|
wfDebug( __METHOD__ . ": ignoring request for $mode cache mode, private wiki\n" );
|
2013-11-14 12:42:04 +00:00
|
|
|
|
2010-07-23 07:17:56 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
API: HTMLize and internationalize the help, add Special:ApiHelp
The existing API help, formatted as basically a plain-text document
embedded in XML and with a little bolding and a few links
syntax-highlighted in after the fact, works ok for experienced programmers
but isn't at all newbie-friendly. Further, all the help is hard-coded in
English, which isn't very friendly to non-English speakers.
So let's rewrite it. The help text is now obtained from i18n messages
and output in HTML, with the default display consisting of help for a
single module with links to help for other modules. This, of course,
necessitates deprecating many of the existing help-related methods and
hooks and replacing them with new ones, but backwards compatibility is
maintained for almost everything.
At the same time, action=paraminfo also needs to support the
'description' and other help-related fields being output in wikitext or
HTML, and I11cb063d (to access all modules via the 'modules' parameter
instead of having 'modules', 'formatmodules', 'querymodules', and so on)
is folded in.
And we also add Special:ApiHelp. When directly accessed, it simply
redirects to api.php with appropriate parameters. But it's also
transcludable to allow up-to-date API help text to be included within
the on-wiki documentation.
Note this patch doesn't actually add i18n messages for any API modules
besides ApiMain and ApiHelp. That will come in a followup patch, but for
the moment the backwards-compatibility code handles them nicely.
While we're messing with the documentation, we may as well add the
"internal" flag requested in bug 62905 (although the 'includeinternal'
parameter it also requests doesn't make much sense anymore) and a
"deprecated" flag that's needed by several modules now.
Bug: 30936
Bug: 38126
Bug: 42343
Bug: 45641
Bug: 62905
Bug: 63211
Change-Id: Ib14c00df06d85c2f6364d83b2b10ce34c7f513cc
2014-09-16 17:54:01 +00:00
|
|
|
if ( $mode === 'public' && $this->getParameter( 'uselang' ) === 'user' ) {
|
|
|
|
|
// User language is used for i18n, so we don't want to publicly
|
|
|
|
|
// cache. Anons are ok, because if they have non-default language
|
|
|
|
|
// then there's an appropriate Vary header set by whatever set
|
|
|
|
|
// their non-default language.
|
|
|
|
|
wfDebug( __METHOD__ . ": downgrading cache mode 'public' to " .
|
2014-10-30 16:50:19 +00:00
|
|
|
"'anon-public-user-private' due to uselang=user\n" );
|
API: HTMLize and internationalize the help, add Special:ApiHelp
The existing API help, formatted as basically a plain-text document
embedded in XML and with a little bolding and a few links
syntax-highlighted in after the fact, works ok for experienced programmers
but isn't at all newbie-friendly. Further, all the help is hard-coded in
English, which isn't very friendly to non-English speakers.
So let's rewrite it. The help text is now obtained from i18n messages
and output in HTML, with the default display consisting of help for a
single module with links to help for other modules. This, of course,
necessitates deprecating many of the existing help-related methods and
hooks and replacing them with new ones, but backwards compatibility is
maintained for almost everything.
At the same time, action=paraminfo also needs to support the
'description' and other help-related fields being output in wikitext or
HTML, and I11cb063d (to access all modules via the 'modules' parameter
instead of having 'modules', 'formatmodules', 'querymodules', and so on)
is folded in.
And we also add Special:ApiHelp. When directly accessed, it simply
redirects to api.php with appropriate parameters. But it's also
transcludable to allow up-to-date API help text to be included within
the on-wiki documentation.
Note this patch doesn't actually add i18n messages for any API modules
besides ApiMain and ApiHelp. That will come in a followup patch, but for
the moment the backwards-compatibility code handles them nicely.
While we're messing with the documentation, we may as well add the
"internal" flag requested in bug 62905 (although the 'includeinternal'
parameter it also requests doesn't make much sense anymore) and a
"deprecated" flag that's needed by several modules now.
Bug: 30936
Bug: 38126
Bug: 42343
Bug: 45641
Bug: 62905
Bug: 63211
Change-Id: Ib14c00df06d85c2f6364d83b2b10ce34c7f513cc
2014-09-16 17:54:01 +00:00
|
|
|
$mode = 'anon-public-user-private';
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-23 07:33:40 +00:00
|
|
|
wfDebug( __METHOD__ . ": setting cache mode $mode\n" );
|
2010-07-23 07:17:56 +00:00
|
|
|
$this->mCacheMode = $mode;
|
|
|
|
|
}
|
2010-07-23 07:33:40 +00:00
|
|
|
|
2010-02-14 23:52:45 +00:00
|
|
|
/**
|
|
|
|
|
* Set directives (key/value pairs) for the Cache-Control header.
|
|
|
|
|
* Boolean values will be formatted as such, by including or omitting
|
|
|
|
|
* without an equals sign.
|
2010-07-23 07:17:56 +00:00
|
|
|
*
|
2010-07-23 07:33:40 +00:00
|
|
|
* Cache control values set here will only be used if the cache mode is not
|
2010-07-23 07:17:56 +00:00
|
|
|
* private, see setCacheMode().
|
2011-06-05 15:10:11 +00:00
|
|
|
*
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param array $directives
|
2010-02-14 23:52:45 +00:00
|
|
|
*/
|
|
|
|
|
public function setCacheControl( $directives ) {
|
|
|
|
|
$this->mCacheControl = $directives + $this->mCacheControl;
|
2006-10-22 23:45:20 +00:00
|
|
|
}
|
2010-07-23 07:33:40 +00:00
|
|
|
|
2007-05-20 10:08:40 +00:00
|
|
|
/**
|
|
|
|
|
* Create an instance of an output formatter by its name
|
2011-01-30 08:16:13 +00:00
|
|
|
*
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param string $format
|
2011-05-08 16:48:30 +00:00
|
|
|
*
|
2011-01-30 08:16:13 +00:00
|
|
|
* @return ApiFormatBase
|
2007-05-20 10:08:40 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
public function createPrinterByName( $format ) {
|
2013-02-05 06:52:55 +00:00
|
|
|
$printer = $this->mModuleMgr->getModule( $format, 'format' );
|
|
|
|
|
if ( $printer === null ) {
|
2008-10-25 16:23:09 +00:00
|
|
|
$this->dieUsage( "Unrecognized format: {$format}", 'unknown_format' );
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2013-11-14 12:42:04 +00:00
|
|
|
|
2013-02-05 06:52:55 +00:00
|
|
|
return $printer;
|
2006-10-15 07:43:52 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-05-20 10:08:40 +00:00
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* Execute api request. Any errors will be handled if the API was called by the remote client.
|
2007-05-20 10:08:40 +00:00
|
|
|
*/
|
2006-10-01 04:38:31 +00:00
|
|
|
public function execute() {
|
|
|
|
|
$this->profileIn();
|
2010-02-23 18:05:46 +00:00
|
|
|
if ( $this->mInternalMode ) {
|
2006-10-14 07:18:08 +00:00
|
|
|
$this->executeAction();
|
2010-02-23 18:05:46 +00:00
|
|
|
} else {
|
2006-10-14 07:18:08 +00:00
|
|
|
$this->executeActionWithErrorHandling();
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2010-01-22 03:14:52 +00:00
|
|
|
|
2006-10-14 07:18:08 +00:00
|
|
|
$this->profileOut();
|
|
|
|
|
}
|
2006-10-22 23:45:20 +00:00
|
|
|
|
2007-05-20 10:08:40 +00:00
|
|
|
/**
|
|
|
|
|
* Execute an action, and in case of an error, erase whatever partial results
|
|
|
|
|
* have been accumulated, and replace it with an error message and a help screen.
|
|
|
|
|
*/
|
2006-10-14 07:18:08 +00:00
|
|
|
protected function executeActionWithErrorHandling() {
|
Reimplement CORS properly, addressing Tim's concerns
Tim's concerns (listed at
https://bugzilla.wikimedia.org/show_bug.cgi?id=20814#c6) were:
* Lack of Vary: Origin breaks Squid caching
* Vary: Origin on everything would be disastrous, so add an origin param
* Origin header is space-separated list, wasn't treated as such
This commit:
* Remove CORS code from api.php and reimplement it in ApiMain.php
* Add 'origin' parameter to ApiMain
* If 'origin' parameter doesn't match Origin header, send a 403
* If origin is whitelisted, set CORS headers and set Vary: Origin
* Add https?:// to wildcard matching logic, wasn't there but is needed
CORS now works :) you can test it locally as follows:
Set $wgCrossSiteAJAXdomains[] = '*.wikipedia.org';
Log into MediaWiki on localhost
Go to Wikipedia, open a JS console, and run:
$.ajax( {
'url': 'http://localhost/w/api.php',
'data': {
'action': 'query',
'meta': 'userinfo',
'format': 'json',
'origin': 'https://en.wikipedia.org'
// or whichever domain you're on; must be correct!
},
'xhrFields': {
'withCredentials': true
},
'success': function( data ) {
alert( 'Foreign user ' + data.query.userinfo.name +
' (ID ' + data.query.userinfo.id + ')' );
}
} );
Change-Id: I725ce176866d7c81dd9ad6d7bc4a86b7160f2458
2012-06-01 12:14:47 +00:00
|
|
|
// Verify the CORS header before executing the action
|
|
|
|
|
if ( !$this->handleCORS() ) {
|
|
|
|
|
// handleCORS() has sent a 403, abort
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-26 20:41:00 +00:00
|
|
|
// Exit here if the request method was OPTIONS
|
|
|
|
|
// (assume there will be a followup GET or POST)
|
|
|
|
|
if ( $this->getRequest()->getMethod() === 'OPTIONS' ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-14 07:18:08 +00:00
|
|
|
// In case an error occurs during data output,
|
2007-05-20 10:08:40 +00:00
|
|
|
// clear the output buffer and print just the error information
|
2006-10-13 05:21:38 +00:00
|
|
|
ob_start();
|
|
|
|
|
|
2012-09-19 10:07:48 +00:00
|
|
|
$t = microtime( true );
|
2006-10-01 04:38:31 +00:00
|
|
|
try {
|
2006-10-14 07:18:08 +00:00
|
|
|
$this->executeAction();
|
2010-01-11 15:55:52 +00:00
|
|
|
} catch ( Exception $e ) {
|
2014-03-06 14:37:26 +00:00
|
|
|
$this->handleException( $e );
|
2007-07-15 00:52:35 +00:00
|
|
|
}
|
2010-07-23 07:17:56 +00:00
|
|
|
|
2012-09-19 10:07:48 +00:00
|
|
|
// Log the request whether or not there was an error
|
2013-03-24 10:01:51 +00:00
|
|
|
$this->logRequest( microtime( true ) - $t );
|
2012-09-19 10:07:48 +00:00
|
|
|
|
2010-07-23 07:33:40 +00:00
|
|
|
// Send cache headers after any code which might generate an error, to
|
2010-07-23 07:17:56 +00:00
|
|
|
// avoid sending public cache headers for errors.
|
|
|
|
|
$this->sendCacheHeaders();
|
|
|
|
|
|
|
|
|
|
ob_end_flush();
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-06 14:37:26 +00:00
|
|
|
/**
|
|
|
|
|
* Handle an exception as an API response
|
|
|
|
|
*
|
|
|
|
|
* @since 1.23
|
|
|
|
|
* @param Exception $e
|
|
|
|
|
*/
|
|
|
|
|
protected function handleException( Exception $e ) {
|
2014-03-27 16:18:38 +00:00
|
|
|
// Bug 63145: Rollback any open database transactions
|
2014-04-22 16:56:40 +00:00
|
|
|
if ( !( $e instanceof UsageException ) ) {
|
|
|
|
|
// UsageExceptions are intentional, so don't rollback if that's the case
|
|
|
|
|
MWExceptionHandler::rollbackMasterChangesAndLog( $e );
|
|
|
|
|
}
|
2014-03-27 16:18:38 +00:00
|
|
|
|
2014-03-06 14:37:26 +00:00
|
|
|
// Allow extra cleanup and logging
|
2014-12-09 07:23:30 +00:00
|
|
|
Hooks::run( 'ApiMain::onException', array( $this, $e ) );
|
2014-03-06 14:37:26 +00:00
|
|
|
|
|
|
|
|
// Log it
|
|
|
|
|
if ( !( $e instanceof UsageException ) ) {
|
|
|
|
|
MWExceptionHandler::logException( $e );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Handle any kind of exception by outputting properly formatted error message.
|
|
|
|
|
// If this fails, an unhandled exception should be thrown so that global error
|
|
|
|
|
// handler will process and log it.
|
|
|
|
|
|
|
|
|
|
$errCode = $this->substituteResultWithError( $e );
|
|
|
|
|
|
|
|
|
|
// Error results should not be cached
|
|
|
|
|
$this->setCacheMode( 'private' );
|
|
|
|
|
|
|
|
|
|
$response = $this->getRequest()->response();
|
|
|
|
|
$headerStr = 'MediaWiki-API-Error: ' . $errCode;
|
|
|
|
|
if ( $e->getCode() === 0 ) {
|
|
|
|
|
$response->header( $headerStr );
|
|
|
|
|
} else {
|
|
|
|
|
$response->header( $headerStr, true, $e->getCode() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Reset and print just the error message
|
|
|
|
|
ob_clean();
|
|
|
|
|
|
|
|
|
|
// If the error occurred during printing, do a printer->profileOut()
|
|
|
|
|
$this->mPrinter->safeProfileOut();
|
|
|
|
|
$this->printResult( true );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handle an exception from the ApiBeforeMain hook.
|
|
|
|
|
*
|
|
|
|
|
* This tries to print the exception as an API response, to be more
|
|
|
|
|
* friendly to clients. If it fails, it will rethrow the exception.
|
|
|
|
|
*
|
|
|
|
|
* @since 1.23
|
|
|
|
|
* @param Exception $e
|
|
|
|
|
*/
|
|
|
|
|
public static function handleApiBeforeMainException( Exception $e ) {
|
|
|
|
|
ob_start();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$main = new self( RequestContext::getMain(), false );
|
|
|
|
|
$main->handleException( $e );
|
|
|
|
|
} catch ( Exception $e2 ) {
|
|
|
|
|
// Nope, even that didn't work. Punt.
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Log the request and reset cache headers
|
|
|
|
|
$main->logRequest( 0 );
|
|
|
|
|
$main->sendCacheHeaders();
|
|
|
|
|
|
|
|
|
|
ob_end_flush();
|
|
|
|
|
}
|
|
|
|
|
|
Reimplement CORS properly, addressing Tim's concerns
Tim's concerns (listed at
https://bugzilla.wikimedia.org/show_bug.cgi?id=20814#c6) were:
* Lack of Vary: Origin breaks Squid caching
* Vary: Origin on everything would be disastrous, so add an origin param
* Origin header is space-separated list, wasn't treated as such
This commit:
* Remove CORS code from api.php and reimplement it in ApiMain.php
* Add 'origin' parameter to ApiMain
* If 'origin' parameter doesn't match Origin header, send a 403
* If origin is whitelisted, set CORS headers and set Vary: Origin
* Add https?:// to wildcard matching logic, wasn't there but is needed
CORS now works :) you can test it locally as follows:
Set $wgCrossSiteAJAXdomains[] = '*.wikipedia.org';
Log into MediaWiki on localhost
Go to Wikipedia, open a JS console, and run:
$.ajax( {
'url': 'http://localhost/w/api.php',
'data': {
'action': 'query',
'meta': 'userinfo',
'format': 'json',
'origin': 'https://en.wikipedia.org'
// or whichever domain you're on; must be correct!
},
'xhrFields': {
'withCredentials': true
},
'success': function( data ) {
alert( 'Foreign user ' + data.query.userinfo.name +
' (ID ' + data.query.userinfo.id + ')' );
}
} );
Change-Id: I725ce176866d7c81dd9ad6d7bc4a86b7160f2458
2012-06-01 12:14:47 +00:00
|
|
|
/**
|
|
|
|
|
* Check the &origin= query parameter against the Origin: HTTP header and respond appropriately.
|
|
|
|
|
*
|
|
|
|
|
* If no origin parameter is present, nothing happens.
|
|
|
|
|
* If an origin parameter is present but doesn't match the Origin header, a 403 status code
|
|
|
|
|
* is set and false is returned.
|
|
|
|
|
* If the parameter and the header do match, the header is checked against $wgCrossSiteAJAXdomains
|
|
|
|
|
* and $wgCrossSiteAJAXdomainExceptions, and if the origin qualifies, the appropriate CORS
|
|
|
|
|
* headers are set.
|
|
|
|
|
*
|
|
|
|
|
* @return bool False if the caller should abort (403 case), true otherwise (all other cases)
|
|
|
|
|
*/
|
|
|
|
|
protected function handleCORS() {
|
|
|
|
|
$originParam = $this->getParameter( 'origin' ); // defaults to null
|
|
|
|
|
if ( $originParam === null ) {
|
|
|
|
|
// No origin parameter, nothing to do
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2012-08-20 14:55:28 +00:00
|
|
|
|
|
|
|
|
$request = $this->getRequest();
|
|
|
|
|
$response = $request->response();
|
Reimplement CORS properly, addressing Tim's concerns
Tim's concerns (listed at
https://bugzilla.wikimedia.org/show_bug.cgi?id=20814#c6) were:
* Lack of Vary: Origin breaks Squid caching
* Vary: Origin on everything would be disastrous, so add an origin param
* Origin header is space-separated list, wasn't treated as such
This commit:
* Remove CORS code from api.php and reimplement it in ApiMain.php
* Add 'origin' parameter to ApiMain
* If 'origin' parameter doesn't match Origin header, send a 403
* If origin is whitelisted, set CORS headers and set Vary: Origin
* Add https?:// to wildcard matching logic, wasn't there but is needed
CORS now works :) you can test it locally as follows:
Set $wgCrossSiteAJAXdomains[] = '*.wikipedia.org';
Log into MediaWiki on localhost
Go to Wikipedia, open a JS console, and run:
$.ajax( {
'url': 'http://localhost/w/api.php',
'data': {
'action': 'query',
'meta': 'userinfo',
'format': 'json',
'origin': 'https://en.wikipedia.org'
// or whichever domain you're on; must be correct!
},
'xhrFields': {
'withCredentials': true
},
'success': function( data ) {
alert( 'Foreign user ' + data.query.userinfo.name +
' (ID ' + data.query.userinfo.id + ')' );
}
} );
Change-Id: I725ce176866d7c81dd9ad6d7bc4a86b7160f2458
2012-06-01 12:14:47 +00:00
|
|
|
// Origin: header is a space-separated list of origins, check all of them
|
2012-08-20 14:55:28 +00:00
|
|
|
$originHeader = $request->getHeader( 'Origin' );
|
|
|
|
|
if ( $originHeader === false ) {
|
|
|
|
|
$origins = array();
|
|
|
|
|
} else {
|
|
|
|
|
$origins = explode( ' ', $originHeader );
|
|
|
|
|
}
|
2013-11-16 19:09:17 +00:00
|
|
|
|
Reimplement CORS properly, addressing Tim's concerns
Tim's concerns (listed at
https://bugzilla.wikimedia.org/show_bug.cgi?id=20814#c6) were:
* Lack of Vary: Origin breaks Squid caching
* Vary: Origin on everything would be disastrous, so add an origin param
* Origin header is space-separated list, wasn't treated as such
This commit:
* Remove CORS code from api.php and reimplement it in ApiMain.php
* Add 'origin' parameter to ApiMain
* If 'origin' parameter doesn't match Origin header, send a 403
* If origin is whitelisted, set CORS headers and set Vary: Origin
* Add https?:// to wildcard matching logic, wasn't there but is needed
CORS now works :) you can test it locally as follows:
Set $wgCrossSiteAJAXdomains[] = '*.wikipedia.org';
Log into MediaWiki on localhost
Go to Wikipedia, open a JS console, and run:
$.ajax( {
'url': 'http://localhost/w/api.php',
'data': {
'action': 'query',
'meta': 'userinfo',
'format': 'json',
'origin': 'https://en.wikipedia.org'
// or whichever domain you're on; must be correct!
},
'xhrFields': {
'withCredentials': true
},
'success': function( data ) {
alert( 'Foreign user ' + data.query.userinfo.name +
' (ID ' + data.query.userinfo.id + ')' );
}
} );
Change-Id: I725ce176866d7c81dd9ad6d7bc4a86b7160f2458
2012-06-01 12:14:47 +00:00
|
|
|
if ( !in_array( $originParam, $origins ) ) {
|
|
|
|
|
// origin parameter set but incorrect
|
|
|
|
|
// Send a 403 response
|
|
|
|
|
$message = HttpStatus::getMessage( 403 );
|
|
|
|
|
$response->header( "HTTP/1.1 403 $message", true, 403 );
|
|
|
|
|
$response->header( 'Cache-Control: no-cache' );
|
|
|
|
|
echo "'origin' parameter does not match Origin header\n";
|
2013-11-14 12:42:04 +00:00
|
|
|
|
Reimplement CORS properly, addressing Tim's concerns
Tim's concerns (listed at
https://bugzilla.wikimedia.org/show_bug.cgi?id=20814#c6) were:
* Lack of Vary: Origin breaks Squid caching
* Vary: Origin on everything would be disastrous, so add an origin param
* Origin header is space-separated list, wasn't treated as such
This commit:
* Remove CORS code from api.php and reimplement it in ApiMain.php
* Add 'origin' parameter to ApiMain
* If 'origin' parameter doesn't match Origin header, send a 403
* If origin is whitelisted, set CORS headers and set Vary: Origin
* Add https?:// to wildcard matching logic, wasn't there but is needed
CORS now works :) you can test it locally as follows:
Set $wgCrossSiteAJAXdomains[] = '*.wikipedia.org';
Log into MediaWiki on localhost
Go to Wikipedia, open a JS console, and run:
$.ajax( {
'url': 'http://localhost/w/api.php',
'data': {
'action': 'query',
'meta': 'userinfo',
'format': 'json',
'origin': 'https://en.wikipedia.org'
// or whichever domain you're on; must be correct!
},
'xhrFields': {
'withCredentials': true
},
'success': function( data ) {
alert( 'Foreign user ' + data.query.userinfo.name +
' (ID ' + data.query.userinfo.id + ')' );
}
} );
Change-Id: I725ce176866d7c81dd9ad6d7bc4a86b7160f2458
2012-06-01 12:14:47 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2013-11-16 19:09:17 +00:00
|
|
|
|
2014-01-24 02:51:11 +00:00
|
|
|
$config = $this->getConfig();
|
2013-11-16 19:09:17 +00:00
|
|
|
$matchOrigin = self::matchOrigin(
|
|
|
|
|
$originParam,
|
2014-01-24 02:51:11 +00:00
|
|
|
$config->get( 'CrossSiteAJAXdomains' ),
|
|
|
|
|
$config->get( 'CrossSiteAJAXdomainExceptions' )
|
2013-11-16 19:09:17 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ( $matchOrigin ) {
|
Reimplement CORS properly, addressing Tim's concerns
Tim's concerns (listed at
https://bugzilla.wikimedia.org/show_bug.cgi?id=20814#c6) were:
* Lack of Vary: Origin breaks Squid caching
* Vary: Origin on everything would be disastrous, so add an origin param
* Origin header is space-separated list, wasn't treated as such
This commit:
* Remove CORS code from api.php and reimplement it in ApiMain.php
* Add 'origin' parameter to ApiMain
* If 'origin' parameter doesn't match Origin header, send a 403
* If origin is whitelisted, set CORS headers and set Vary: Origin
* Add https?:// to wildcard matching logic, wasn't there but is needed
CORS now works :) you can test it locally as follows:
Set $wgCrossSiteAJAXdomains[] = '*.wikipedia.org';
Log into MediaWiki on localhost
Go to Wikipedia, open a JS console, and run:
$.ajax( {
'url': 'http://localhost/w/api.php',
'data': {
'action': 'query',
'meta': 'userinfo',
'format': 'json',
'origin': 'https://en.wikipedia.org'
// or whichever domain you're on; must be correct!
},
'xhrFields': {
'withCredentials': true
},
'success': function( data ) {
alert( 'Foreign user ' + data.query.userinfo.name +
' (ID ' + data.query.userinfo.id + ')' );
}
} );
Change-Id: I725ce176866d7c81dd9ad6d7bc4a86b7160f2458
2012-06-01 12:14:47 +00:00
|
|
|
$response->header( "Access-Control-Allow-Origin: $originParam" );
|
|
|
|
|
$response->header( 'Access-Control-Allow-Credentials: true' );
|
2014-12-01 14:42:36 +00:00
|
|
|
$response->header( 'Access-Control-Allow-Headers: Api-User-Agent' );
|
Reimplement CORS properly, addressing Tim's concerns
Tim's concerns (listed at
https://bugzilla.wikimedia.org/show_bug.cgi?id=20814#c6) were:
* Lack of Vary: Origin breaks Squid caching
* Vary: Origin on everything would be disastrous, so add an origin param
* Origin header is space-separated list, wasn't treated as such
This commit:
* Remove CORS code from api.php and reimplement it in ApiMain.php
* Add 'origin' parameter to ApiMain
* If 'origin' parameter doesn't match Origin header, send a 403
* If origin is whitelisted, set CORS headers and set Vary: Origin
* Add https?:// to wildcard matching logic, wasn't there but is needed
CORS now works :) you can test it locally as follows:
Set $wgCrossSiteAJAXdomains[] = '*.wikipedia.org';
Log into MediaWiki on localhost
Go to Wikipedia, open a JS console, and run:
$.ajax( {
'url': 'http://localhost/w/api.php',
'data': {
'action': 'query',
'meta': 'userinfo',
'format': 'json',
'origin': 'https://en.wikipedia.org'
// or whichever domain you're on; must be correct!
},
'xhrFields': {
'withCredentials': true
},
'success': function( data ) {
alert( 'Foreign user ' + data.query.userinfo.name +
' (ID ' + data.query.userinfo.id + ')' );
}
} );
Change-Id: I725ce176866d7c81dd9ad6d7bc4a86b7160f2458
2012-06-01 12:14:47 +00:00
|
|
|
$this->getOutput()->addVaryHeader( 'Origin' );
|
|
|
|
|
}
|
2013-11-14 12:42:04 +00:00
|
|
|
|
Reimplement CORS properly, addressing Tim's concerns
Tim's concerns (listed at
https://bugzilla.wikimedia.org/show_bug.cgi?id=20814#c6) were:
* Lack of Vary: Origin breaks Squid caching
* Vary: Origin on everything would be disastrous, so add an origin param
* Origin header is space-separated list, wasn't treated as such
This commit:
* Remove CORS code from api.php and reimplement it in ApiMain.php
* Add 'origin' parameter to ApiMain
* If 'origin' parameter doesn't match Origin header, send a 403
* If origin is whitelisted, set CORS headers and set Vary: Origin
* Add https?:// to wildcard matching logic, wasn't there but is needed
CORS now works :) you can test it locally as follows:
Set $wgCrossSiteAJAXdomains[] = '*.wikipedia.org';
Log into MediaWiki on localhost
Go to Wikipedia, open a JS console, and run:
$.ajax( {
'url': 'http://localhost/w/api.php',
'data': {
'action': 'query',
'meta': 'userinfo',
'format': 'json',
'origin': 'https://en.wikipedia.org'
// or whichever domain you're on; must be correct!
},
'xhrFields': {
'withCredentials': true
},
'success': function( data ) {
alert( 'Foreign user ' + data.query.userinfo.name +
' (ID ' + data.query.userinfo.id + ')' );
}
} );
Change-Id: I725ce176866d7c81dd9ad6d7bc4a86b7160f2458
2012-06-01 12:14:47 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Attempt to match an Origin header against a set of rules and a set of exceptions
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $value Origin header
|
|
|
|
|
* @param array $rules Set of wildcard rules
|
|
|
|
|
* @param array $exceptions Set of wildcard rules
|
2013-11-16 19:09:17 +00:00
|
|
|
* @return bool True if $value matches a rule in $rules and doesn't match
|
|
|
|
|
* any rules in $exceptions, false otherwise
|
Reimplement CORS properly, addressing Tim's concerns
Tim's concerns (listed at
https://bugzilla.wikimedia.org/show_bug.cgi?id=20814#c6) were:
* Lack of Vary: Origin breaks Squid caching
* Vary: Origin on everything would be disastrous, so add an origin param
* Origin header is space-separated list, wasn't treated as such
This commit:
* Remove CORS code from api.php and reimplement it in ApiMain.php
* Add 'origin' parameter to ApiMain
* If 'origin' parameter doesn't match Origin header, send a 403
* If origin is whitelisted, set CORS headers and set Vary: Origin
* Add https?:// to wildcard matching logic, wasn't there but is needed
CORS now works :) you can test it locally as follows:
Set $wgCrossSiteAJAXdomains[] = '*.wikipedia.org';
Log into MediaWiki on localhost
Go to Wikipedia, open a JS console, and run:
$.ajax( {
'url': 'http://localhost/w/api.php',
'data': {
'action': 'query',
'meta': 'userinfo',
'format': 'json',
'origin': 'https://en.wikipedia.org'
// or whichever domain you're on; must be correct!
},
'xhrFields': {
'withCredentials': true
},
'success': function( data ) {
alert( 'Foreign user ' + data.query.userinfo.name +
' (ID ' + data.query.userinfo.id + ')' );
}
} );
Change-Id: I725ce176866d7c81dd9ad6d7bc4a86b7160f2458
2012-06-01 12:14:47 +00:00
|
|
|
*/
|
|
|
|
|
protected static function matchOrigin( $value, $rules, $exceptions ) {
|
|
|
|
|
foreach ( $rules as $rule ) {
|
|
|
|
|
if ( preg_match( self::wildcardToRegex( $rule ), $value ) ) {
|
|
|
|
|
// Rule matches, check exceptions
|
|
|
|
|
foreach ( $exceptions as $exc ) {
|
|
|
|
|
if ( preg_match( self::wildcardToRegex( $exc ), $value ) ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-14 12:42:04 +00:00
|
|
|
|
Reimplement CORS properly, addressing Tim's concerns
Tim's concerns (listed at
https://bugzilla.wikimedia.org/show_bug.cgi?id=20814#c6) were:
* Lack of Vary: Origin breaks Squid caching
* Vary: Origin on everything would be disastrous, so add an origin param
* Origin header is space-separated list, wasn't treated as such
This commit:
* Remove CORS code from api.php and reimplement it in ApiMain.php
* Add 'origin' parameter to ApiMain
* If 'origin' parameter doesn't match Origin header, send a 403
* If origin is whitelisted, set CORS headers and set Vary: Origin
* Add https?:// to wildcard matching logic, wasn't there but is needed
CORS now works :) you can test it locally as follows:
Set $wgCrossSiteAJAXdomains[] = '*.wikipedia.org';
Log into MediaWiki on localhost
Go to Wikipedia, open a JS console, and run:
$.ajax( {
'url': 'http://localhost/w/api.php',
'data': {
'action': 'query',
'meta': 'userinfo',
'format': 'json',
'origin': 'https://en.wikipedia.org'
// or whichever domain you're on; must be correct!
},
'xhrFields': {
'withCredentials': true
},
'success': function( data ) {
alert( 'Foreign user ' + data.query.userinfo.name +
' (ID ' + data.query.userinfo.id + ')' );
}
} );
Change-Id: I725ce176866d7c81dd9ad6d7bc4a86b7160f2458
2012-06-01 12:14:47 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-14 12:42:04 +00:00
|
|
|
|
Reimplement CORS properly, addressing Tim's concerns
Tim's concerns (listed at
https://bugzilla.wikimedia.org/show_bug.cgi?id=20814#c6) were:
* Lack of Vary: Origin breaks Squid caching
* Vary: Origin on everything would be disastrous, so add an origin param
* Origin header is space-separated list, wasn't treated as such
This commit:
* Remove CORS code from api.php and reimplement it in ApiMain.php
* Add 'origin' parameter to ApiMain
* If 'origin' parameter doesn't match Origin header, send a 403
* If origin is whitelisted, set CORS headers and set Vary: Origin
* Add https?:// to wildcard matching logic, wasn't there but is needed
CORS now works :) you can test it locally as follows:
Set $wgCrossSiteAJAXdomains[] = '*.wikipedia.org';
Log into MediaWiki on localhost
Go to Wikipedia, open a JS console, and run:
$.ajax( {
'url': 'http://localhost/w/api.php',
'data': {
'action': 'query',
'meta': 'userinfo',
'format': 'json',
'origin': 'https://en.wikipedia.org'
// or whichever domain you're on; must be correct!
},
'xhrFields': {
'withCredentials': true
},
'success': function( data ) {
alert( 'Foreign user ' + data.query.userinfo.name +
' (ID ' + data.query.userinfo.id + ')' );
}
} );
Change-Id: I725ce176866d7c81dd9ad6d7bc4a86b7160f2458
2012-06-01 12:14:47 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Helper function to convert wildcard string into a regex
|
|
|
|
|
* '*' => '.*?'
|
|
|
|
|
* '?' => '.'
|
|
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $wildcard String with wildcards
|
Reimplement CORS properly, addressing Tim's concerns
Tim's concerns (listed at
https://bugzilla.wikimedia.org/show_bug.cgi?id=20814#c6) were:
* Lack of Vary: Origin breaks Squid caching
* Vary: Origin on everything would be disastrous, so add an origin param
* Origin header is space-separated list, wasn't treated as such
This commit:
* Remove CORS code from api.php and reimplement it in ApiMain.php
* Add 'origin' parameter to ApiMain
* If 'origin' parameter doesn't match Origin header, send a 403
* If origin is whitelisted, set CORS headers and set Vary: Origin
* Add https?:// to wildcard matching logic, wasn't there but is needed
CORS now works :) you can test it locally as follows:
Set $wgCrossSiteAJAXdomains[] = '*.wikipedia.org';
Log into MediaWiki on localhost
Go to Wikipedia, open a JS console, and run:
$.ajax( {
'url': 'http://localhost/w/api.php',
'data': {
'action': 'query',
'meta': 'userinfo',
'format': 'json',
'origin': 'https://en.wikipedia.org'
// or whichever domain you're on; must be correct!
},
'xhrFields': {
'withCredentials': true
},
'success': function( data ) {
alert( 'Foreign user ' + data.query.userinfo.name +
' (ID ' + data.query.userinfo.id + ')' );
}
} );
Change-Id: I725ce176866d7c81dd9ad6d7bc4a86b7160f2458
2012-06-01 12:14:47 +00:00
|
|
|
* @return string Regular expression
|
|
|
|
|
*/
|
|
|
|
|
protected static function wildcardToRegex( $wildcard ) {
|
|
|
|
|
$wildcard = preg_quote( $wildcard, '/' );
|
|
|
|
|
$wildcard = str_replace(
|
|
|
|
|
array( '\*', '\?' ),
|
|
|
|
|
array( '.*?', '.' ),
|
|
|
|
|
$wildcard
|
|
|
|
|
);
|
2013-11-14 12:42:04 +00:00
|
|
|
|
2014-12-08 15:43:50 +00:00
|
|
|
return "/^https?:\/\/$wildcard$/";
|
Reimplement CORS properly, addressing Tim's concerns
Tim's concerns (listed at
https://bugzilla.wikimedia.org/show_bug.cgi?id=20814#c6) were:
* Lack of Vary: Origin breaks Squid caching
* Vary: Origin on everything would be disastrous, so add an origin param
* Origin header is space-separated list, wasn't treated as such
This commit:
* Remove CORS code from api.php and reimplement it in ApiMain.php
* Add 'origin' parameter to ApiMain
* If 'origin' parameter doesn't match Origin header, send a 403
* If origin is whitelisted, set CORS headers and set Vary: Origin
* Add https?:// to wildcard matching logic, wasn't there but is needed
CORS now works :) you can test it locally as follows:
Set $wgCrossSiteAJAXdomains[] = '*.wikipedia.org';
Log into MediaWiki on localhost
Go to Wikipedia, open a JS console, and run:
$.ajax( {
'url': 'http://localhost/w/api.php',
'data': {
'action': 'query',
'meta': 'userinfo',
'format': 'json',
'origin': 'https://en.wikipedia.org'
// or whichever domain you're on; must be correct!
},
'xhrFields': {
'withCredentials': true
},
'success': function( data ) {
alert( 'Foreign user ' + data.query.userinfo.name +
' (ID ' + data.query.userinfo.id + ')' );
}
} );
Change-Id: I725ce176866d7c81dd9ad6d7bc4a86b7160f2458
2012-06-01 12:14:47 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-23 07:17:56 +00:00
|
|
|
protected function sendCacheHeaders() {
|
2011-06-05 20:29:47 +00:00
|
|
|
$response = $this->getRequest()->response();
|
2012-06-01 11:11:32 +00:00
|
|
|
$out = $this->getOutput();
|
|
|
|
|
|
2014-01-24 02:51:11 +00:00
|
|
|
$config = $this->getConfig();
|
|
|
|
|
|
|
|
|
|
if ( $config->get( 'VaryOnXFP' ) ) {
|
2012-06-01 11:11:32 +00:00
|
|
|
$out->addVaryHeader( 'X-Forwarded-Proto' );
|
|
|
|
|
}
|
2011-06-05 19:51:31 +00:00
|
|
|
|
2010-07-23 07:17:56 +00:00
|
|
|
if ( $this->mCacheMode == 'private' ) {
|
2011-06-05 19:51:31 +00:00
|
|
|
$response->header( 'Cache-Control: private' );
|
2010-07-23 07:17:56 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-24 02:51:11 +00:00
|
|
|
$useXVO = $config->get( 'UseXVO' );
|
2010-07-23 07:17:56 +00:00
|
|
|
if ( $this->mCacheMode == 'anon-public-user-private' ) {
|
2012-06-01 11:11:32 +00:00
|
|
|
$out->addVaryHeader( 'Cookie' );
|
|
|
|
|
$response->header( $out->getVaryHeader() );
|
2014-01-24 02:51:11 +00:00
|
|
|
if ( $useXVO ) {
|
2011-11-08 16:06:59 +00:00
|
|
|
$response->header( $out->getXVO() );
|
|
|
|
|
if ( $out->haveCacheVaryCookies() ) {
|
2010-07-23 07:17:56 +00:00
|
|
|
// Logged in, mark this request private
|
2011-06-05 19:51:31 +00:00
|
|
|
$response->header( 'Cache-Control: private' );
|
2010-07-23 07:17:56 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// Logged out, send normal public headers below
|
|
|
|
|
} elseif ( session_id() != '' ) {
|
|
|
|
|
// Logged in or otherwise has session (e.g. anonymous users who have edited)
|
|
|
|
|
// Mark request private
|
2011-06-05 19:51:31 +00:00
|
|
|
$response->header( 'Cache-Control: private' );
|
2013-11-14 12:42:04 +00:00
|
|
|
|
2010-07-23 07:17:56 +00:00
|
|
|
return;
|
|
|
|
|
} // else no XVO and anonymous, send public headers below
|
2010-07-14 19:00:54 +00:00
|
|
|
}
|
2011-09-07 21:14:55 +00:00
|
|
|
|
2011-08-03 12:00:47 +00:00
|
|
|
// Send public headers
|
2012-06-01 11:11:32 +00:00
|
|
|
$response->header( $out->getVaryHeader() );
|
2014-01-24 02:51:11 +00:00
|
|
|
if ( $useXVO ) {
|
2012-06-01 11:11:32 +00:00
|
|
|
$response->header( $out->getXVO() );
|
2011-08-03 12:00:47 +00:00
|
|
|
}
|
2007-07-15 00:52:35 +00:00
|
|
|
|
2010-02-14 23:52:45 +00:00
|
|
|
// If nobody called setCacheMaxAge(), use the (s)maxage parameters
|
|
|
|
|
if ( !isset( $this->mCacheControl['s-maxage'] ) ) {
|
|
|
|
|
$this->mCacheControl['s-maxage'] = $this->getParameter( 'smaxage' );
|
|
|
|
|
}
|
|
|
|
|
if ( !isset( $this->mCacheControl['max-age'] ) ) {
|
|
|
|
|
$this->mCacheControl['max-age'] = $this->getParameter( 'maxage' );
|
2008-06-16 20:06:23 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-23 07:17:56 +00:00
|
|
|
if ( !$this->mCacheControl['s-maxage'] && !$this->mCacheControl['max-age'] ) {
|
|
|
|
|
// Public cache not requested
|
|
|
|
|
// Sending a Vary header in this case is harmless, and protects us
|
|
|
|
|
// against conditional calls of setCacheMaxAge().
|
2011-06-05 19:51:31 +00:00
|
|
|
$response->header( 'Cache-Control: private' );
|
2013-11-14 12:42:04 +00:00
|
|
|
|
2010-07-23 07:17:56 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->mCacheControl['public'] = true;
|
|
|
|
|
|
|
|
|
|
// Send an Expires header
|
|
|
|
|
$maxAge = min( $this->mCacheControl['s-maxage'], $this->mCacheControl['max-age'] );
|
|
|
|
|
$expiryUnixTime = ( $maxAge == 0 ? 1 : time() + $maxAge );
|
2011-06-05 19:51:31 +00:00
|
|
|
$response->header( 'Expires: ' . wfTimestamp( TS_RFC2822, $expiryUnixTime ) );
|
2010-02-14 23:52:45 +00:00
|
|
|
|
|
|
|
|
// Construct the Cache-Control header
|
|
|
|
|
$ccHeader = '';
|
|
|
|
|
$separator = '';
|
|
|
|
|
foreach ( $this->mCacheControl as $name => $value ) {
|
|
|
|
|
if ( is_bool( $value ) ) {
|
|
|
|
|
if ( $value ) {
|
|
|
|
|
$ccHeader .= $separator . $name;
|
2010-02-15 21:34:31 +00:00
|
|
|
$separator = ', ';
|
2010-02-14 23:52:45 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$ccHeader .= $separator . "$name=$value";
|
2010-02-15 21:34:31 +00:00
|
|
|
$separator = ', ';
|
2010-02-14 23:52:45 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-02-23 18:05:46 +00:00
|
|
|
|
2011-06-05 19:51:31 +00:00
|
|
|
$response->header( "Cache-Control: $ccHeader" );
|
2007-07-15 00:52:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Replace the result data with the information about an exception.
|
2008-04-14 07:45:50 +00:00
|
|
|
* Returns the error code
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param Exception $e
|
2011-01-30 08:16:13 +00:00
|
|
|
* @return string
|
2007-07-15 00:52:35 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
protected function substituteResultWithError( $e ) {
|
2011-06-30 01:06:17 +00:00
|
|
|
$result = $this->getResult();
|
2014-03-27 15:11:17 +00:00
|
|
|
|
2010-02-15 23:56:09 +00:00
|
|
|
// Printer may not be initialized if the extractRequestParams() fails for the main module
|
2013-04-26 12:18:06 +00:00
|
|
|
if ( !isset( $this->mPrinter ) ) {
|
2010-02-15 23:56:09 +00:00
|
|
|
// The printer has not been created yet. Try to manually get formatter value.
|
|
|
|
|
$value = $this->getRequest()->getVal( 'format', self::API_DEFAULT_FORMAT );
|
2013-02-05 06:52:55 +00:00
|
|
|
if ( !$this->mModuleMgr->isDefined( $value, 'format' ) ) {
|
2010-02-15 23:56:09 +00:00
|
|
|
$value = self::API_DEFAULT_FORMAT;
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2010-02-15 23:56:09 +00:00
|
|
|
|
|
|
|
|
$this->mPrinter = $this->createPrinterByName( $value );
|
|
|
|
|
}
|
2006-10-22 23:45:20 +00:00
|
|
|
|
2014-03-27 15:11:17 +00:00
|
|
|
// Printer may not be able to handle errors. This is particularly
|
|
|
|
|
// likely if the module returns something for getCustomPrinter().
|
|
|
|
|
if ( !$this->mPrinter->canPrintErrors() ) {
|
|
|
|
|
$this->mPrinter->safeProfileOut();
|
|
|
|
|
$this->mPrinter = $this->createPrinterByName( self::API_DEFAULT_FORMAT );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update raw mode flag for the selected printer.
|
|
|
|
|
$result->setRawMode( $this->mPrinter->getNeedsRawData() );
|
|
|
|
|
|
2014-01-24 02:51:11 +00:00
|
|
|
$config = $this->getConfig();
|
|
|
|
|
|
2010-02-15 23:56:09 +00:00
|
|
|
if ( $e instanceof UsageException ) {
|
API: HTMLize and internationalize the help, add Special:ApiHelp
The existing API help, formatted as basically a plain-text document
embedded in XML and with a little bolding and a few links
syntax-highlighted in after the fact, works ok for experienced programmers
but isn't at all newbie-friendly. Further, all the help is hard-coded in
English, which isn't very friendly to non-English speakers.
So let's rewrite it. The help text is now obtained from i18n messages
and output in HTML, with the default display consisting of help for a
single module with links to help for other modules. This, of course,
necessitates deprecating many of the existing help-related methods and
hooks and replacing them with new ones, but backwards compatibility is
maintained for almost everything.
At the same time, action=paraminfo also needs to support the
'description' and other help-related fields being output in wikitext or
HTML, and I11cb063d (to access all modules via the 'modules' parameter
instead of having 'modules', 'formatmodules', 'querymodules', and so on)
is folded in.
And we also add Special:ApiHelp. When directly accessed, it simply
redirects to api.php with appropriate parameters. But it's also
transcludable to allow up-to-date API help text to be included within
the on-wiki documentation.
Note this patch doesn't actually add i18n messages for any API modules
besides ApiMain and ApiHelp. That will come in a followup patch, but for
the moment the backwards-compatibility code handles them nicely.
While we're messing with the documentation, we may as well add the
"internal" flag requested in bug 62905 (although the 'includeinternal'
parameter it also requests doesn't make much sense anymore) and a
"deprecated" flag that's needed by several modules now.
Bug: 30936
Bug: 38126
Bug: 42343
Bug: 45641
Bug: 62905
Bug: 63211
Change-Id: Ib14c00df06d85c2f6364d83b2b10ce34c7f513cc
2014-09-16 17:54:01 +00:00
|
|
|
// User entered incorrect parameters - generate error response
|
2010-02-15 23:56:09 +00:00
|
|
|
$errMessage = $e->getMessageArray();
|
API: HTMLize and internationalize the help, add Special:ApiHelp
The existing API help, formatted as basically a plain-text document
embedded in XML and with a little bolding and a few links
syntax-highlighted in after the fact, works ok for experienced programmers
but isn't at all newbie-friendly. Further, all the help is hard-coded in
English, which isn't very friendly to non-English speakers.
So let's rewrite it. The help text is now obtained from i18n messages
and output in HTML, with the default display consisting of help for a
single module with links to help for other modules. This, of course,
necessitates deprecating many of the existing help-related methods and
hooks and replacing them with new ones, but backwards compatibility is
maintained for almost everything.
At the same time, action=paraminfo also needs to support the
'description' and other help-related fields being output in wikitext or
HTML, and I11cb063d (to access all modules via the 'modules' parameter
instead of having 'modules', 'formatmodules', 'querymodules', and so on)
is folded in.
And we also add Special:ApiHelp. When directly accessed, it simply
redirects to api.php with appropriate parameters. But it's also
transcludable to allow up-to-date API help text to be included within
the on-wiki documentation.
Note this patch doesn't actually add i18n messages for any API modules
besides ApiMain and ApiHelp. That will come in a followup patch, but for
the moment the backwards-compatibility code handles them nicely.
While we're messing with the documentation, we may as well add the
"internal" flag requested in bug 62905 (although the 'includeinternal'
parameter it also requests doesn't make much sense anymore) and a
"deprecated" flag that's needed by several modules now.
Bug: 30936
Bug: 38126
Bug: 42343
Bug: 45641
Bug: 62905
Bug: 63211
Change-Id: Ib14c00df06d85c2f6364d83b2b10ce34c7f513cc
2014-09-16 17:54:01 +00:00
|
|
|
$link = wfExpandUrl( wfScript( 'api' ) );
|
|
|
|
|
ApiResult::setContent( $errMessage, "See $link for API usage" );
|
2010-02-15 23:56:09 +00:00
|
|
|
} else {
|
|
|
|
|
// Something is seriously wrong
|
2014-01-24 02:51:11 +00:00
|
|
|
if ( ( $e instanceof DBQueryError ) && !$config->get( 'ShowSQLErrors' ) ) {
|
2010-02-23 18:05:46 +00:00
|
|
|
$info = 'Database query error';
|
2006-10-14 07:18:08 +00:00
|
|
|
} else {
|
2010-02-15 23:56:09 +00:00
|
|
|
$info = "Exception Caught: {$e->getMessage()}";
|
2006-10-14 07:18:08 +00:00
|
|
|
}
|
2006-10-22 23:45:20 +00:00
|
|
|
|
2010-02-23 18:05:46 +00:00
|
|
|
$errMessage = array(
|
2010-02-15 23:56:09 +00:00
|
|
|
'code' => 'internal_api_error_' . get_class( $e ),
|
|
|
|
|
'info' => $info,
|
|
|
|
|
);
|
2013-11-16 19:09:17 +00:00
|
|
|
ApiResult::setContent(
|
|
|
|
|
$errMessage,
|
2014-01-24 02:51:11 +00:00
|
|
|
$config->get( 'ShowExceptionDetails' ) ? "\n\n{$e->getTraceAsString()}\n\n" : ''
|
2013-11-16 19:09:17 +00:00
|
|
|
);
|
2010-02-15 23:56:09 +00:00
|
|
|
}
|
|
|
|
|
|
2013-01-18 06:45:43 +00:00
|
|
|
// Remember all the warnings to re-add them later
|
|
|
|
|
$oldResult = $result->getData();
|
|
|
|
|
$warnings = isset( $oldResult['warnings'] ) ? $oldResult['warnings'] : null;
|
|
|
|
|
|
2011-06-30 01:06:17 +00:00
|
|
|
$result->reset();
|
2010-02-15 23:56:09 +00:00
|
|
|
// Re-add the id
|
|
|
|
|
$requestid = $this->getParameter( 'requestid' );
|
2010-02-23 18:05:46 +00:00
|
|
|
if ( !is_null( $requestid ) ) {
|
Added ApiResult::NO_SIZE_CHECK flag for addValue()
This way we no longer need to disable size checking just for one operation
(enable|disable)SizeCheck functions were depricated.
Overall, this is a much better practice than disabling than re-enabling
the flag, as it might lead to accidentally forgetting to re-enable it,
just like the issue with the dangling file handlers, etc.
Example:
disable, do some complex logic, re-enable. And later, by accident,
the complex logic is changed to return a value half-way, or throws
an exception that gets handled as part of normal operations. This
results in the unsafe disabled state of the result object,
which is not good (tm).
Change-Id: I389a334d35f52f23a1847aca4aef5e96b262f589
2014-07-07 18:07:14 +00:00
|
|
|
$result->addValue( null, 'requestid', $requestid, ApiResult::NO_SIZE_CHECK );
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2014-01-24 02:51:11 +00:00
|
|
|
if ( $config->get( 'ShowHostnames' ) ) {
|
2011-10-26 19:39:56 +00:00
|
|
|
// servedby is especially useful when debugging errors
|
Added ApiResult::NO_SIZE_CHECK flag for addValue()
This way we no longer need to disable size checking just for one operation
(enable|disable)SizeCheck functions were depricated.
Overall, this is a much better practice than disabling than re-enabling
the flag, as it might lead to accidentally forgetting to re-enable it,
just like the issue with the dangling file handlers, etc.
Example:
disable, do some complex logic, re-enable. And later, by accident,
the complex logic is changed to return a value half-way, or throws
an exception that gets handled as part of normal operations. This
results in the unsafe disabled state of the result object,
which is not good (tm).
Change-Id: I389a334d35f52f23a1847aca4aef5e96b262f589
2014-07-07 18:07:14 +00:00
|
|
|
$result->addValue( null, 'servedby', wfHostName(), ApiResult::NO_SIZE_CHECK );
|
2011-10-26 19:39:56 +00:00
|
|
|
}
|
2013-01-18 06:45:43 +00:00
|
|
|
if ( $warnings !== null ) {
|
Added ApiResult::NO_SIZE_CHECK flag for addValue()
This way we no longer need to disable size checking just for one operation
(enable|disable)SizeCheck functions were depricated.
Overall, this is a much better practice than disabling than re-enabling
the flag, as it might lead to accidentally forgetting to re-enable it,
just like the issue with the dangling file handlers, etc.
Example:
disable, do some complex logic, re-enable. And later, by accident,
the complex logic is changed to return a value half-way, or throws
an exception that gets handled as part of normal operations. This
results in the unsafe disabled state of the result object,
which is not good (tm).
Change-Id: I389a334d35f52f23a1847aca4aef5e96b262f589
2014-07-07 18:07:14 +00:00
|
|
|
$result->addValue( null, 'warnings', $warnings, ApiResult::NO_SIZE_CHECK );
|
2013-01-18 06:45:43 +00:00
|
|
|
}
|
2011-10-26 19:39:56 +00:00
|
|
|
|
Added ApiResult::NO_SIZE_CHECK flag for addValue()
This way we no longer need to disable size checking just for one operation
(enable|disable)SizeCheck functions were depricated.
Overall, this is a much better practice than disabling than re-enabling
the flag, as it might lead to accidentally forgetting to re-enable it,
just like the issue with the dangling file handlers, etc.
Example:
disable, do some complex logic, re-enable. And later, by accident,
the complex logic is changed to return a value half-way, or throws
an exception that gets handled as part of normal operations. This
results in the unsafe disabled state of the result object,
which is not good (tm).
Change-Id: I389a334d35f52f23a1847aca4aef5e96b262f589
2014-07-07 18:07:14 +00:00
|
|
|
$result->addValue( null, 'error', $errMessage, ApiResult::NO_SIZE_CHECK );
|
2006-10-17 02:01:20 +00:00
|
|
|
|
2007-07-15 00:52:35 +00:00
|
|
|
return $errMessage['code'];
|
2006-10-01 04:38:31 +00:00
|
|
|
}
|
|
|
|
|
|
2006-10-14 07:18:08 +00:00
|
|
|
/**
|
2010-03-30 17:14:53 +00:00
|
|
|
* Set up for the execution.
|
2011-01-30 08:16:13 +00:00
|
|
|
* @return array
|
2006-10-14 07:18:08 +00:00
|
|
|
*/
|
2010-03-30 17:14:53 +00:00
|
|
|
protected function setupExecuteAction() {
|
2008-08-05 16:12:52 +00:00
|
|
|
// First add the id to the top element
|
2011-06-30 01:06:17 +00:00
|
|
|
$result = $this->getResult();
|
2010-01-11 15:55:52 +00:00
|
|
|
$requestid = $this->getParameter( 'requestid' );
|
2010-02-23 18:05:46 +00:00
|
|
|
if ( !is_null( $requestid ) ) {
|
2011-06-30 01:06:17 +00:00
|
|
|
$result->addValue( null, 'requestid', $requestid );
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2011-10-26 19:39:56 +00:00
|
|
|
|
2014-01-24 02:51:11 +00:00
|
|
|
if ( $this->getConfig()->get( 'ShowHostnames' ) ) {
|
2011-10-26 19:39:56 +00:00
|
|
|
$servedby = $this->getParameter( 'servedby' );
|
|
|
|
|
if ( $servedby ) {
|
|
|
|
|
$result->addValue( null, 'servedby', wfHostName() );
|
|
|
|
|
}
|
2010-07-10 10:37:39 +00:00
|
|
|
}
|
2008-01-08 18:10:58 +00:00
|
|
|
|
2014-08-08 16:56:07 +00:00
|
|
|
if ( $this->getParameter( 'curtimestamp' ) ) {
|
|
|
|
|
$result->addValue( null, 'curtimestamp', wfTimestamp( TS_ISO_8601, time() ),
|
|
|
|
|
ApiResult::NO_SIZE_CHECK );
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-28 06:59:19 +00:00
|
|
|
$params = $this->extractRequestParams();
|
2010-02-22 03:34:56 +00:00
|
|
|
|
2007-06-29 22:05:30 +00:00
|
|
|
$this->mAction = $params['action'];
|
2008-06-20 10:51:17 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( !is_string( $this->mAction ) ) {
|
2010-02-23 18:05:46 +00:00
|
|
|
$this->dieUsage( 'The API requires a valid action parameter', 'unknown_action' );
|
2008-07-30 07:23:22 +00:00
|
|
|
}
|
2010-02-23 18:05:46 +00:00
|
|
|
|
2010-03-30 17:14:53 +00:00
|
|
|
return $params;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set up the module for response
|
2010-09-28 01:33:11 +00:00
|
|
|
* @return ApiBase The module that will handle this action
|
2010-03-30 17:14:53 +00:00
|
|
|
*/
|
|
|
|
|
protected function setupModule() {
|
2006-10-14 07:18:08 +00:00
|
|
|
// Instantiate the module requested by the user
|
2013-02-05 06:52:55 +00:00
|
|
|
$module = $this->mModuleMgr->getModule( $this->mAction, 'action' );
|
|
|
|
|
if ( $module === null ) {
|
|
|
|
|
$this->dieUsage( 'The API requires a valid action parameter', 'unknown_action' );
|
|
|
|
|
}
|
2010-02-15 23:53:43 +00:00
|
|
|
$moduleParams = $module->extractRequestParams();
|
2010-02-23 18:05:46 +00:00
|
|
|
|
2014-08-08 16:56:07 +00:00
|
|
|
// Check token, if necessary
|
|
|
|
|
if ( $module->needsToken() === true ) {
|
|
|
|
|
throw new MWException(
|
|
|
|
|
"Module '{$module->getModuleName()}' must be updated for the new token handling. " .
|
|
|
|
|
"See documentation for ApiBase::needsToken for details."
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if ( $module->needsToken() ) {
|
|
|
|
|
if ( !$module->mustBePosted() ) {
|
|
|
|
|
throw new MWException(
|
|
|
|
|
"Module '{$module->getModuleName()}' must require POST to use tokens."
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-19 19:44:28 +00:00
|
|
|
if ( !isset( $moduleParams['token'] ) ) {
|
2010-02-15 23:53:43 +00:00
|
|
|
$this->dieUsageMsg( array( 'missingparam', 'token' ) );
|
2013-11-17 19:54:11 +00:00
|
|
|
}
|
|
|
|
|
|
2014-09-18 19:56:53 +00:00
|
|
|
if ( !$this->getConfig()->get( 'DebugAPI' ) &&
|
|
|
|
|
array_key_exists(
|
|
|
|
|
$module->encodeParamName( 'token' ),
|
|
|
|
|
$this->getRequest()->getQueryValues()
|
|
|
|
|
)
|
|
|
|
|
) {
|
2014-08-08 16:56:07 +00:00
|
|
|
$this->dieUsage(
|
2014-09-11 01:22:17 +00:00
|
|
|
"The '{$module->encodeParamName( 'token' )}' parameter was found in the query string, but must be in the POST body",
|
2014-08-08 16:56:07 +00:00
|
|
|
'mustposttoken'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !$module->validateToken( $moduleParams['token'], $moduleParams ) ) {
|
2013-11-17 19:54:11 +00:00
|
|
|
$this->dieUsageMsg( 'sessionfailure' );
|
2010-02-15 23:53:43 +00:00
|
|
|
}
|
|
|
|
|
}
|
2013-11-14 12:42:04 +00:00
|
|
|
|
2010-03-30 17:14:53 +00:00
|
|
|
return $module;
|
|
|
|
|
}
|
2010-02-14 22:20:27 +00:00
|
|
|
|
2010-03-30 17:14:53 +00:00
|
|
|
/**
|
|
|
|
|
* Check the max lag if necessary
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param ApiBase $module Api module being used
|
|
|
|
|
* @param array $params Array an array containing the request parameters.
|
|
|
|
|
* @return bool True on success, false should exit immediately
|
2010-03-30 17:14:53 +00:00
|
|
|
*/
|
2010-04-17 20:58:04 +00:00
|
|
|
protected function checkMaxLag( $module, $params ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $module->shouldCheckMaxlag() && isset( $params['maxlag'] ) ) {
|
2007-11-19 15:57:58 +00:00
|
|
|
// Check for maxlag
|
|
|
|
|
$maxLag = $params['maxlag'];
|
2008-03-30 09:48:15 +00:00
|
|
|
list( $host, $lag ) = wfGetLB()->getMaxLag();
|
2007-11-19 15:57:58 +00:00
|
|
|
if ( $lag > $maxLag ) {
|
2011-06-05 20:29:47 +00:00
|
|
|
$response = $this->getRequest()->response();
|
2011-06-05 19:51:31 +00:00
|
|
|
|
|
|
|
|
$response->header( 'Retry-After: ' . max( intval( $maxLag ), 5 ) );
|
|
|
|
|
$response->header( 'X-Database-Lag: ' . intval( $lag ) );
|
|
|
|
|
|
2014-01-24 02:51:11 +00:00
|
|
|
if ( $this->getConfig()->get( 'ShowHostnames' ) ) {
|
2009-07-16 08:04:15 +00:00
|
|
|
$this->dieUsage( "Waiting for $host: $lag seconds lagged", 'maxlag' );
|
2007-11-19 15:57:58 +00:00
|
|
|
}
|
2013-11-14 12:42:04 +00:00
|
|
|
|
2013-11-17 19:54:11 +00:00
|
|
|
$this->dieUsage( "Waiting for a database server: $lag seconds lagged", 'maxlag' );
|
2007-11-19 15:57:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
2013-11-14 12:42:04 +00:00
|
|
|
|
2010-03-30 17:14:53 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check for sufficient permissions to execute
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param ApiBase $module An Api module
|
2010-03-30 17:14:53 +00:00
|
|
|
*/
|
2010-04-17 20:58:04 +00:00
|
|
|
protected function checkExecutePermissions( $module ) {
|
2011-10-26 23:27:01 +00:00
|
|
|
$user = $this->getUser();
|
2013-07-12 15:06:41 +00:00
|
|
|
if ( $module->isReadMode() && !User::isEveryoneAllowed( 'read' ) &&
|
2013-11-14 12:42:04 +00:00
|
|
|
!$user->isAllowed( 'read' )
|
|
|
|
|
) {
|
2011-05-19 17:51:16 +00:00
|
|
|
$this->dieUsageMsg( 'readrequired' );
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $module->isWriteMode() ) {
|
2010-02-23 18:05:46 +00:00
|
|
|
if ( !$this->mEnableWrite ) {
|
2011-05-19 17:51:16 +00:00
|
|
|
$this->dieUsageMsg( 'writedisabled' );
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2011-10-26 23:27:01 +00:00
|
|
|
if ( !$user->isAllowed( 'writeapi' ) ) {
|
2011-05-19 17:51:16 +00:00
|
|
|
$this->dieUsageMsg( 'writerequired' );
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
|
|
|
|
if ( wfReadOnly() ) {
|
2009-07-12 12:38:03 +00:00
|
|
|
$this->dieReadOnly();
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2009-03-06 13:49:44 +00:00
|
|
|
}
|
2012-08-21 15:52:47 +00:00
|
|
|
|
|
|
|
|
// Allow extensions to stop execution for arbitrary reasons.
|
|
|
|
|
$message = false;
|
2014-12-09 07:23:30 +00:00
|
|
|
if ( !Hooks::run( 'ApiCheckCanExecute', array( $module, $user, &$message ) ) ) {
|
2012-08-21 15:52:47 +00:00
|
|
|
$this->dieUsageMsg( $message );
|
|
|
|
|
}
|
2010-03-30 17:14:53 +00:00
|
|
|
}
|
2009-03-06 13:49:44 +00:00
|
|
|
|
2013-10-16 22:27:59 +00:00
|
|
|
/**
|
|
|
|
|
* Check asserts of the user's rights
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param array $params
|
2013-10-16 22:27:59 +00:00
|
|
|
*/
|
|
|
|
|
protected function checkAsserts( $params ) {
|
|
|
|
|
if ( isset( $params['assert'] ) ) {
|
|
|
|
|
$user = $this->getUser();
|
|
|
|
|
switch ( $params['assert'] ) {
|
|
|
|
|
case 'user':
|
|
|
|
|
if ( $user->isAnon() ) {
|
|
|
|
|
$this->dieUsage( 'Assertion that the user is logged in failed', 'assertuserfailed' );
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'bot':
|
|
|
|
|
if ( !$user->isAllowed( 'bot' ) ) {
|
|
|
|
|
$this->dieUsage( 'Assertion that the user has the bot right failed', 'assertbotfailed' );
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-30 17:14:53 +00:00
|
|
|
/**
|
|
|
|
|
* Check POST for external response and setup result printer
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param ApiBase $module An Api module
|
2014-07-24 17:42:45 +00:00
|
|
|
* @param array $params An array with the request parameters
|
2010-03-30 17:14:53 +00:00
|
|
|
*/
|
2010-04-17 20:58:04 +00:00
|
|
|
protected function setupExternalResponse( $module, $params ) {
|
2013-01-18 15:23:17 +00:00
|
|
|
if ( !$this->getRequest()->wasPosted() && $module->mustBePosted() ) {
|
|
|
|
|
// Module requires POST. GET request might still be allowed
|
|
|
|
|
// if $wgDebugApi is true, otherwise fail.
|
|
|
|
|
$this->dieUsageMsgOrDebug( array( 'mustbeposted', $this->mAction ) );
|
2010-03-30 17:14:53 +00:00
|
|
|
}
|
2006-10-22 23:45:20 +00:00
|
|
|
|
2010-03-30 17:14:53 +00:00
|
|
|
// See if custom printer is used
|
|
|
|
|
$this->mPrinter = $module->getCustomPrinter();
|
|
|
|
|
if ( is_null( $this->mPrinter ) ) {
|
|
|
|
|
// Create an appropriate printer
|
|
|
|
|
$this->mPrinter = $this->createPrinterByName( $params['format'] );
|
|
|
|
|
}
|
2006-10-22 23:45:20 +00:00
|
|
|
|
2010-03-30 17:14:53 +00:00
|
|
|
if ( $this->mPrinter->getNeedsRawData() ) {
|
|
|
|
|
$this->getResult()->setRawMode();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Execute the actual module, without any error handling
|
|
|
|
|
*/
|
|
|
|
|
protected function executeAction() {
|
|
|
|
|
$params = $this->setupExecuteAction();
|
|
|
|
|
$module = $this->setupModule();
|
2013-02-05 06:52:55 +00:00
|
|
|
$this->mModule = $module;
|
2010-03-30 17:14:53 +00:00
|
|
|
|
2010-04-17 20:58:04 +00:00
|
|
|
$this->checkExecutePermissions( $module );
|
2010-03-30 17:14:53 +00:00
|
|
|
|
2010-09-25 16:45:41 +00:00
|
|
|
if ( !$this->checkMaxLag( $module, $params ) ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-03-30 17:14:53 +00:00
|
|
|
|
|
|
|
|
if ( !$this->mInternalMode ) {
|
2010-04-17 20:58:04 +00:00
|
|
|
$this->setupExternalResponse( $module, $params );
|
2006-10-14 07:18:08 +00:00
|
|
|
}
|
2006-10-22 23:45:20 +00:00
|
|
|
|
2013-10-16 22:27:59 +00:00
|
|
|
$this->checkAsserts( $params );
|
|
|
|
|
|
2006-10-14 07:18:08 +00:00
|
|
|
// Execute
|
|
|
|
|
$module->profileIn();
|
|
|
|
|
$module->execute();
|
2014-12-09 07:23:30 +00:00
|
|
|
Hooks::run( 'APIAfterExecute', array( &$module ) );
|
2006-10-14 07:18:08 +00:00
|
|
|
$module->profileOut();
|
2006-10-22 23:45:20 +00:00
|
|
|
|
2013-03-02 00:06:46 +00:00
|
|
|
$this->reportUnusedParams();
|
2012-09-19 10:07:48 +00:00
|
|
|
|
2013-03-02 00:06:46 +00:00
|
|
|
if ( !$this->mInternalMode ) {
|
2012-05-13 09:20:04 +00:00
|
|
|
//append Debug information
|
|
|
|
|
MWDebug::appendDebugInfoToApiResult( $this->getContext(), $this->getResult() );
|
|
|
|
|
|
2006-10-14 07:18:08 +00:00
|
|
|
// Print result data
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->printResult( false );
|
2006-10-14 07:18:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
2006-10-22 23:45:20 +00:00
|
|
|
|
2012-09-19 10:07:48 +00:00
|
|
|
/**
|
|
|
|
|
* Log the preceding request
|
2013-11-16 21:15:17 +00:00
|
|
|
* @param int $time Time in seconds
|
2012-09-19 10:07:48 +00:00
|
|
|
*/
|
|
|
|
|
protected function logRequest( $time ) {
|
|
|
|
|
$request = $this->getRequest();
|
|
|
|
|
$milliseconds = $time === null ? '?' : round( $time * 1000 );
|
2012-10-10 18:13:40 +00:00
|
|
|
$s = 'API' .
|
2012-09-19 10:07:48 +00:00
|
|
|
' ' . $request->getMethod() .
|
|
|
|
|
' ' . wfUrlencode( str_replace( ' ', '_', $this->getUser()->getName() ) ) .
|
|
|
|
|
' ' . $request->getIP() .
|
2013-04-13 11:36:24 +00:00
|
|
|
' T=' . $milliseconds . 'ms';
|
2012-09-19 10:07:48 +00:00
|
|
|
foreach ( $this->getParamsUsed() as $name ) {
|
|
|
|
|
$value = $request->getVal( $name );
|
|
|
|
|
if ( $value === null ) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
$s .= ' ' . $name . '=';
|
|
|
|
|
if ( strlen( $value ) > 256 ) {
|
|
|
|
|
$encValue = $this->encodeRequestLogValue( substr( $value, 0, 256 ) );
|
|
|
|
|
$s .= $encValue . '[...]';
|
|
|
|
|
} else {
|
|
|
|
|
$s .= $this->encodeRequestLogValue( $value );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$s .= "\n";
|
2013-11-14 11:17:25 +00:00
|
|
|
wfDebugLog( 'api', $s, 'private' );
|
2012-09-19 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Encode a value in a format suitable for a space-separated log line.
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param string $s
|
2014-05-24 20:06:01 +00:00
|
|
|
* @return string
|
2012-09-19 10:07:48 +00:00
|
|
|
*/
|
|
|
|
|
protected function encodeRequestLogValue( $s ) {
|
|
|
|
|
static $table;
|
|
|
|
|
if ( !$table ) {
|
|
|
|
|
$chars = ';@$!*(),/:';
|
2013-11-16 19:09:17 +00:00
|
|
|
$numChars = strlen( $chars );
|
|
|
|
|
for ( $i = 0; $i < $numChars; $i++ ) {
|
2013-01-12 06:50:48 +00:00
|
|
|
$table[rawurlencode( $chars[$i] )] = $chars[$i];
|
2012-09-19 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
}
|
2013-11-14 12:42:04 +00:00
|
|
|
|
2012-09-19 10:07:48 +00:00
|
|
|
return strtr( rawurlencode( $s ), $table );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the request parameters used in the course of the preceding execute() request
|
2014-04-15 18:12:09 +00:00
|
|
|
* @return array
|
2012-09-19 10:07:48 +00:00
|
|
|
*/
|
|
|
|
|
protected function getParamsUsed() {
|
|
|
|
|
return array_keys( $this->mParamsUsed );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a request value, and register the fact that it was used, for logging.
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param string $name
|
|
|
|
|
* @param mixed $default
|
|
|
|
|
* @return mixed
|
2012-09-19 10:07:48 +00:00
|
|
|
*/
|
|
|
|
|
public function getVal( $name, $default = null ) {
|
|
|
|
|
$this->mParamsUsed[$name] = true;
|
2013-11-14 12:42:04 +00:00
|
|
|
|
2014-04-17 14:24:30 +00:00
|
|
|
$ret = $this->getRequest()->getVal( $name );
|
|
|
|
|
if ( $ret === null ) {
|
|
|
|
|
if ( $this->getRequest()->getArray( $name ) !== null ) {
|
|
|
|
|
// See bug 10262 for why we don't just join( '|', ... ) the
|
|
|
|
|
// array.
|
|
|
|
|
$this->setWarning(
|
|
|
|
|
"Parameter '$name' uses unsupported PHP array syntax"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
$ret = $default;
|
|
|
|
|
}
|
|
|
|
|
return $ret;
|
2012-09-19 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a boolean request value, and register the fact that the parameter
|
|
|
|
|
* was used, for logging.
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param string $name
|
|
|
|
|
* @return bool
|
2012-09-19 10:07:48 +00:00
|
|
|
*/
|
|
|
|
|
public function getCheck( $name ) {
|
2014-04-17 14:24:30 +00:00
|
|
|
return $this->getVal( $name, null ) !== null;
|
2012-09-19 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-26 21:45:37 +00:00
|
|
|
/**
|
|
|
|
|
* Get a request upload, and register the fact that it was used, for logging.
|
|
|
|
|
*
|
|
|
|
|
* @since 1.21
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $name Parameter name
|
2013-02-26 21:45:37 +00:00
|
|
|
* @return WebRequestUpload
|
|
|
|
|
*/
|
|
|
|
|
public function getUpload( $name ) {
|
|
|
|
|
$this->mParamsUsed[$name] = true;
|
2013-11-14 12:42:04 +00:00
|
|
|
|
2013-02-26 21:45:37 +00:00
|
|
|
return $this->getRequest()->getUpload( $name );
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-26 08:30:53 +00:00
|
|
|
/**
|
|
|
|
|
* Report unused parameters, so the client gets a hint in case it gave us parameters we don't know,
|
|
|
|
|
* for example in case of spelling mistakes or a missing 'g' prefix for generators.
|
|
|
|
|
*/
|
|
|
|
|
protected function reportUnusedParams() {
|
|
|
|
|
$paramsUsed = $this->getParamsUsed();
|
|
|
|
|
$allParams = $this->getRequest()->getValueNames();
|
|
|
|
|
|
2013-03-02 00:06:46 +00:00
|
|
|
if ( !$this->mInternalMode ) {
|
|
|
|
|
// Printer has not yet executed; don't warn that its parameters are unused
|
|
|
|
|
$printerParams = array_map(
|
|
|
|
|
array( $this->mPrinter, 'encodeParamName' ),
|
2013-11-14 18:40:13 +00:00
|
|
|
array_keys( $this->mPrinter->getFinalParams() ?: array() )
|
2013-03-02 00:06:46 +00:00
|
|
|
);
|
|
|
|
|
$unusedParams = array_diff( $allParams, $paramsUsed, $printerParams );
|
|
|
|
|
} else {
|
|
|
|
|
$unusedParams = array_diff( $allParams, $paramsUsed );
|
|
|
|
|
}
|
2013-02-23 21:19:29 +00:00
|
|
|
|
2013-04-19 18:03:05 +00:00
|
|
|
if ( count( $unusedParams ) ) {
|
2012-09-26 08:30:53 +00:00
|
|
|
$s = count( $unusedParams ) > 1 ? 's' : '';
|
|
|
|
|
$this->setWarning( "Unrecognized parameter$s: '" . implode( $unusedParams, "', '" ) . "'" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-01 04:38:31 +00:00
|
|
|
/**
|
2007-05-20 10:08:40 +00:00
|
|
|
* Print results using the current printer
|
2011-05-08 16:48:30 +00:00
|
|
|
*
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param bool $isError
|
2006-10-01 04:38:31 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
protected function printResult( $isError ) {
|
2014-01-24 02:51:11 +00:00
|
|
|
if ( $this->getConfig()->get( 'DebugAPI' ) !== false ) {
|
2013-02-08 20:39:40 +00:00
|
|
|
$this->setWarning( 'SECURITY WARNING: $wgDebugAPI is enabled' );
|
2013-01-18 15:23:17 +00:00
|
|
|
}
|
|
|
|
|
|
2009-02-10 15:56:34 +00:00
|
|
|
$this->getResult()->cleanUpUTF8();
|
2006-10-01 04:38:31 +00:00
|
|
|
$printer = $this->mPrinter;
|
|
|
|
|
$printer->profileIn();
|
2008-04-14 07:45:50 +00:00
|
|
|
|
API: HTMLize and internationalize the help, add Special:ApiHelp
The existing API help, formatted as basically a plain-text document
embedded in XML and with a little bolding and a few links
syntax-highlighted in after the fact, works ok for experienced programmers
but isn't at all newbie-friendly. Further, all the help is hard-coded in
English, which isn't very friendly to non-English speakers.
So let's rewrite it. The help text is now obtained from i18n messages
and output in HTML, with the default display consisting of help for a
single module with links to help for other modules. This, of course,
necessitates deprecating many of the existing help-related methods and
hooks and replacing them with new ones, but backwards compatibility is
maintained for almost everything.
At the same time, action=paraminfo also needs to support the
'description' and other help-related fields being output in wikitext or
HTML, and I11cb063d (to access all modules via the 'modules' parameter
instead of having 'modules', 'formatmodules', 'querymodules', and so on)
is folded in.
And we also add Special:ApiHelp. When directly accessed, it simply
redirects to api.php with appropriate parameters. But it's also
transcludable to allow up-to-date API help text to be included within
the on-wiki documentation.
Note this patch doesn't actually add i18n messages for any API modules
besides ApiMain and ApiHelp. That will come in a followup patch, but for
the moment the backwards-compatibility code handles them nicely.
While we're messing with the documentation, we may as well add the
"internal" flag requested in bug 62905 (although the 'includeinternal'
parameter it also requests doesn't make much sense anymore) and a
"deprecated" flag that's needed by several modules now.
Bug: 30936
Bug: 38126
Bug: 42343
Bug: 45641
Bug: 62905
Bug: 63211
Change-Id: Ib14c00df06d85c2f6364d83b2b10ce34c7f513cc
2014-09-16 17:54:01 +00:00
|
|
|
$printer->initPrinter( false );
|
2007-10-24 19:34:29 +00:00
|
|
|
|
2006-10-15 07:43:52 +00:00
|
|
|
$printer->execute();
|
2006-10-01 04:38:31 +00:00
|
|
|
$printer->closePrinter();
|
|
|
|
|
$printer->profileOut();
|
|
|
|
|
}
|
2010-01-22 03:14:52 +00:00
|
|
|
|
2011-01-30 08:16:13 +00:00
|
|
|
/**
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2009-03-06 13:49:44 +00:00
|
|
|
public function isReadMode() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2006-10-14 07:18:08 +00:00
|
|
|
|
2007-05-20 10:08:40 +00:00
|
|
|
/**
|
|
|
|
|
* See ApiBase for description.
|
2011-05-08 16:48:30 +00:00
|
|
|
*
|
|
|
|
|
* @return array
|
2007-05-20 10:08:40 +00:00
|
|
|
*/
|
2008-01-28 19:05:26 +00:00
|
|
|
public function getAllowedParams() {
|
2010-02-23 18:05:46 +00:00
|
|
|
return array(
|
|
|
|
|
'action' => array(
|
|
|
|
|
ApiBase::PARAM_DFLT => 'help',
|
2014-08-14 20:12:58 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'submodule',
|
2006-10-14 07:18:08 +00:00
|
|
|
),
|
API: HTMLize and internationalize the help, add Special:ApiHelp
The existing API help, formatted as basically a plain-text document
embedded in XML and with a little bolding and a few links
syntax-highlighted in after the fact, works ok for experienced programmers
but isn't at all newbie-friendly. Further, all the help is hard-coded in
English, which isn't very friendly to non-English speakers.
So let's rewrite it. The help text is now obtained from i18n messages
and output in HTML, with the default display consisting of help for a
single module with links to help for other modules. This, of course,
necessitates deprecating many of the existing help-related methods and
hooks and replacing them with new ones, but backwards compatibility is
maintained for almost everything.
At the same time, action=paraminfo also needs to support the
'description' and other help-related fields being output in wikitext or
HTML, and I11cb063d (to access all modules via the 'modules' parameter
instead of having 'modules', 'formatmodules', 'querymodules', and so on)
is folded in.
And we also add Special:ApiHelp. When directly accessed, it simply
redirects to api.php with appropriate parameters. But it's also
transcludable to allow up-to-date API help text to be included within
the on-wiki documentation.
Note this patch doesn't actually add i18n messages for any API modules
besides ApiMain and ApiHelp. That will come in a followup patch, but for
the moment the backwards-compatibility code handles them nicely.
While we're messing with the documentation, we may as well add the
"internal" flag requested in bug 62905 (although the 'includeinternal'
parameter it also requests doesn't make much sense anymore) and a
"deprecated" flag that's needed by several modules now.
Bug: 30936
Bug: 38126
Bug: 42343
Bug: 45641
Bug: 62905
Bug: 63211
Change-Id: Ib14c00df06d85c2f6364d83b2b10ce34c7f513cc
2014-09-16 17:54:01 +00:00
|
|
|
'format' => array(
|
|
|
|
|
ApiBase::PARAM_DFLT => ApiMain::API_DEFAULT_FORMAT,
|
|
|
|
|
ApiBase::PARAM_TYPE => 'submodule',
|
|
|
|
|
),
|
2013-04-19 18:03:05 +00:00
|
|
|
'maxlag' => array(
|
2010-02-23 18:05:46 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'integer'
|
2007-11-19 15:57:58 +00:00
|
|
|
),
|
2010-02-23 18:05:46 +00:00
|
|
|
'smaxage' => array(
|
|
|
|
|
ApiBase::PARAM_TYPE => 'integer',
|
|
|
|
|
ApiBase::PARAM_DFLT => 0
|
2008-06-16 19:49:43 +00:00
|
|
|
),
|
2010-02-23 18:05:46 +00:00
|
|
|
'maxage' => array(
|
|
|
|
|
ApiBase::PARAM_TYPE => 'integer',
|
|
|
|
|
ApiBase::PARAM_DFLT => 0
|
2008-06-16 20:06:23 +00:00
|
|
|
),
|
2013-10-16 22:27:59 +00:00
|
|
|
'assert' => array(
|
|
|
|
|
ApiBase::PARAM_TYPE => array( 'user', 'bot' )
|
|
|
|
|
),
|
2008-08-05 16:12:52 +00:00
|
|
|
'requestid' => null,
|
2013-04-19 18:03:05 +00:00
|
|
|
'servedby' => false,
|
2014-08-08 16:56:07 +00:00
|
|
|
'curtimestamp' => false,
|
Reimplement CORS properly, addressing Tim's concerns
Tim's concerns (listed at
https://bugzilla.wikimedia.org/show_bug.cgi?id=20814#c6) were:
* Lack of Vary: Origin breaks Squid caching
* Vary: Origin on everything would be disastrous, so add an origin param
* Origin header is space-separated list, wasn't treated as such
This commit:
* Remove CORS code from api.php and reimplement it in ApiMain.php
* Add 'origin' parameter to ApiMain
* If 'origin' parameter doesn't match Origin header, send a 403
* If origin is whitelisted, set CORS headers and set Vary: Origin
* Add https?:// to wildcard matching logic, wasn't there but is needed
CORS now works :) you can test it locally as follows:
Set $wgCrossSiteAJAXdomains[] = '*.wikipedia.org';
Log into MediaWiki on localhost
Go to Wikipedia, open a JS console, and run:
$.ajax( {
'url': 'http://localhost/w/api.php',
'data': {
'action': 'query',
'meta': 'userinfo',
'format': 'json',
'origin': 'https://en.wikipedia.org'
// or whichever domain you're on; must be correct!
},
'xhrFields': {
'withCredentials': true
},
'success': function( data ) {
alert( 'Foreign user ' + data.query.userinfo.name +
' (ID ' + data.query.userinfo.id + ')' );
}
} );
Change-Id: I725ce176866d7c81dd9ad6d7bc4a86b7160f2458
2012-06-01 12:14:47 +00:00
|
|
|
'origin' => null,
|
API: HTMLize and internationalize the help, add Special:ApiHelp
The existing API help, formatted as basically a plain-text document
embedded in XML and with a little bolding and a few links
syntax-highlighted in after the fact, works ok for experienced programmers
but isn't at all newbie-friendly. Further, all the help is hard-coded in
English, which isn't very friendly to non-English speakers.
So let's rewrite it. The help text is now obtained from i18n messages
and output in HTML, with the default display consisting of help for a
single module with links to help for other modules. This, of course,
necessitates deprecating many of the existing help-related methods and
hooks and replacing them with new ones, but backwards compatibility is
maintained for almost everything.
At the same time, action=paraminfo also needs to support the
'description' and other help-related fields being output in wikitext or
HTML, and I11cb063d (to access all modules via the 'modules' parameter
instead of having 'modules', 'formatmodules', 'querymodules', and so on)
is folded in.
And we also add Special:ApiHelp. When directly accessed, it simply
redirects to api.php with appropriate parameters. But it's also
transcludable to allow up-to-date API help text to be included within
the on-wiki documentation.
Note this patch doesn't actually add i18n messages for any API modules
besides ApiMain and ApiHelp. That will come in a followup patch, but for
the moment the backwards-compatibility code handles them nicely.
While we're messing with the documentation, we may as well add the
"internal" flag requested in bug 62905 (although the 'includeinternal'
parameter it also requests doesn't make much sense anymore) and a
"deprecated" flag that's needed by several modules now.
Bug: 30936
Bug: 38126
Bug: 42343
Bug: 45641
Bug: 62905
Bug: 63211
Change-Id: Ib14c00df06d85c2f6364d83b2b10ce34c7f513cc
2014-09-16 17:54:01 +00:00
|
|
|
'uselang' => array(
|
2014-11-04 21:42:43 +00:00
|
|
|
ApiBase::PARAM_DFLT => 'user',
|
API: HTMLize and internationalize the help, add Special:ApiHelp
The existing API help, formatted as basically a plain-text document
embedded in XML and with a little bolding and a few links
syntax-highlighted in after the fact, works ok for experienced programmers
but isn't at all newbie-friendly. Further, all the help is hard-coded in
English, which isn't very friendly to non-English speakers.
So let's rewrite it. The help text is now obtained from i18n messages
and output in HTML, with the default display consisting of help for a
single module with links to help for other modules. This, of course,
necessitates deprecating many of the existing help-related methods and
hooks and replacing them with new ones, but backwards compatibility is
maintained for almost everything.
At the same time, action=paraminfo also needs to support the
'description' and other help-related fields being output in wikitext or
HTML, and I11cb063d (to access all modules via the 'modules' parameter
instead of having 'modules', 'formatmodules', 'querymodules', and so on)
is folded in.
And we also add Special:ApiHelp. When directly accessed, it simply
redirects to api.php with appropriate parameters. But it's also
transcludable to allow up-to-date API help text to be included within
the on-wiki documentation.
Note this patch doesn't actually add i18n messages for any API modules
besides ApiMain and ApiHelp. That will come in a followup patch, but for
the moment the backwards-compatibility code handles them nicely.
While we're messing with the documentation, we may as well add the
"internal" flag requested in bug 62905 (although the 'includeinternal'
parameter it also requests doesn't make much sense anymore) and a
"deprecated" flag that's needed by several modules now.
Bug: 30936
Bug: 38126
Bug: 42343
Bug: 45641
Bug: 62905
Bug: 63211
Change-Id: Ib14c00df06d85c2f6364d83b2b10ce34c7f513cc
2014-09-16 17:54:01 +00:00
|
|
|
),
|
2006-10-14 07:18:08 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
API: HTMLize and internationalize the help, add Special:ApiHelp
The existing API help, formatted as basically a plain-text document
embedded in XML and with a little bolding and a few links
syntax-highlighted in after the fact, works ok for experienced programmers
but isn't at all newbie-friendly. Further, all the help is hard-coded in
English, which isn't very friendly to non-English speakers.
So let's rewrite it. The help text is now obtained from i18n messages
and output in HTML, with the default display consisting of help for a
single module with links to help for other modules. This, of course,
necessitates deprecating many of the existing help-related methods and
hooks and replacing them with new ones, but backwards compatibility is
maintained for almost everything.
At the same time, action=paraminfo also needs to support the
'description' and other help-related fields being output in wikitext or
HTML, and I11cb063d (to access all modules via the 'modules' parameter
instead of having 'modules', 'formatmodules', 'querymodules', and so on)
is folded in.
And we also add Special:ApiHelp. When directly accessed, it simply
redirects to api.php with appropriate parameters. But it's also
transcludable to allow up-to-date API help text to be included within
the on-wiki documentation.
Note this patch doesn't actually add i18n messages for any API modules
besides ApiMain and ApiHelp. That will come in a followup patch, but for
the moment the backwards-compatibility code handles them nicely.
While we're messing with the documentation, we may as well add the
"internal" flag requested in bug 62905 (although the 'includeinternal'
parameter it also requests doesn't make much sense anymore) and a
"deprecated" flag that's needed by several modules now.
Bug: 30936
Bug: 38126
Bug: 42343
Bug: 45641
Bug: 62905
Bug: 63211
Change-Id: Ib14c00df06d85c2f6364d83b2b10ce34c7f513cc
2014-09-16 17:54:01 +00:00
|
|
|
/** @see ApiBase::getExamplesMessages() */
|
2014-10-28 17:17:02 +00:00
|
|
|
protected function getExamplesMessages() {
|
API: HTMLize and internationalize the help, add Special:ApiHelp
The existing API help, formatted as basically a plain-text document
embedded in XML and with a little bolding and a few links
syntax-highlighted in after the fact, works ok for experienced programmers
but isn't at all newbie-friendly. Further, all the help is hard-coded in
English, which isn't very friendly to non-English speakers.
So let's rewrite it. The help text is now obtained from i18n messages
and output in HTML, with the default display consisting of help for a
single module with links to help for other modules. This, of course,
necessitates deprecating many of the existing help-related methods and
hooks and replacing them with new ones, but backwards compatibility is
maintained for almost everything.
At the same time, action=paraminfo also needs to support the
'description' and other help-related fields being output in wikitext or
HTML, and I11cb063d (to access all modules via the 'modules' parameter
instead of having 'modules', 'formatmodules', 'querymodules', and so on)
is folded in.
And we also add Special:ApiHelp. When directly accessed, it simply
redirects to api.php with appropriate parameters. But it's also
transcludable to allow up-to-date API help text to be included within
the on-wiki documentation.
Note this patch doesn't actually add i18n messages for any API modules
besides ApiMain and ApiHelp. That will come in a followup patch, but for
the moment the backwards-compatibility code handles them nicely.
While we're messing with the documentation, we may as well add the
"internal" flag requested in bug 62905 (although the 'includeinternal'
parameter it also requests doesn't make much sense anymore) and a
"deprecated" flag that's needed by several modules now.
Bug: 30936
Bug: 38126
Bug: 42343
Bug: 45641
Bug: 62905
Bug: 63211
Change-Id: Ib14c00df06d85c2f6364d83b2b10ce34c7f513cc
2014-09-16 17:54:01 +00:00
|
|
|
return array(
|
2014-09-18 17:38:23 +00:00
|
|
|
'action=help'
|
|
|
|
|
=> 'apihelp-help-example-main',
|
|
|
|
|
'action=help&recursivesubmodules=1'
|
|
|
|
|
=> 'apihelp-help-example-recursive',
|
API: HTMLize and internationalize the help, add Special:ApiHelp
The existing API help, formatted as basically a plain-text document
embedded in XML and with a little bolding and a few links
syntax-highlighted in after the fact, works ok for experienced programmers
but isn't at all newbie-friendly. Further, all the help is hard-coded in
English, which isn't very friendly to non-English speakers.
So let's rewrite it. The help text is now obtained from i18n messages
and output in HTML, with the default display consisting of help for a
single module with links to help for other modules. This, of course,
necessitates deprecating many of the existing help-related methods and
hooks and replacing them with new ones, but backwards compatibility is
maintained for almost everything.
At the same time, action=paraminfo also needs to support the
'description' and other help-related fields being output in wikitext or
HTML, and I11cb063d (to access all modules via the 'modules' parameter
instead of having 'modules', 'formatmodules', 'querymodules', and so on)
is folded in.
And we also add Special:ApiHelp. When directly accessed, it simply
redirects to api.php with appropriate parameters. But it's also
transcludable to allow up-to-date API help text to be included within
the on-wiki documentation.
Note this patch doesn't actually add i18n messages for any API modules
besides ApiMain and ApiHelp. That will come in a followup patch, but for
the moment the backwards-compatibility code handles them nicely.
While we're messing with the documentation, we may as well add the
"internal" flag requested in bug 62905 (although the 'includeinternal'
parameter it also requests doesn't make much sense anymore) and a
"deprecated" flag that's needed by several modules now.
Bug: 30936
Bug: 38126
Bug: 42343
Bug: 45641
Bug: 62905
Bug: 63211
Change-Id: Ib14c00df06d85c2f6364d83b2b10ce34c7f513cc
2014-09-16 17:54:01 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function modifyHelp( array &$help, array $options ) {
|
|
|
|
|
// Wish PHP had an "array_insert_before". Instead, we have to manually
|
|
|
|
|
// reindex the array to get 'permissions' in the right place.
|
|
|
|
|
$oldHelp = $help;
|
|
|
|
|
$help = array();
|
|
|
|
|
foreach ( $oldHelp as $k => $v ) {
|
|
|
|
|
if ( $k === 'submodules' ) {
|
|
|
|
|
$help['permissions'] = '';
|
|
|
|
|
}
|
|
|
|
|
$help[$k] = $v;
|
|
|
|
|
}
|
|
|
|
|
$help['credits'] = '';
|
|
|
|
|
|
|
|
|
|
// Fill 'permissions'
|
|
|
|
|
$help['permissions'] .= Html::openElement( 'div',
|
|
|
|
|
array( 'class' => 'apihelp-block apihelp-permissions' ) );
|
|
|
|
|
$m = $this->msg( 'api-help-permissions' );
|
|
|
|
|
if ( !$m->isDisabled() ) {
|
|
|
|
|
$help['permissions'] .= Html::rawElement( 'div', array( 'class' => 'apihelp-block-head' ),
|
|
|
|
|
$m->numParams( count( self::$mRights ) )->parse()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
$help['permissions'] .= Html::openElement( 'dl' );
|
|
|
|
|
foreach ( self::$mRights as $right => $rightMsg ) {
|
|
|
|
|
$help['permissions'] .= Html::element( 'dt', null, $right );
|
|
|
|
|
|
|
|
|
|
$rightMsg = $this->msg( $rightMsg['msg'], $rightMsg['params'] )->parse();
|
|
|
|
|
$help['permissions'] .= Html::rawElement( 'dd', null, $rightMsg );
|
|
|
|
|
|
|
|
|
|
$groups = array_map( function ( $group ) {
|
|
|
|
|
return $group == '*' ? 'all' : $group;
|
|
|
|
|
}, User::getGroupsWithPermission( $right ) );
|
|
|
|
|
|
|
|
|
|
$help['permissions'] .= Html::rawElement( 'dd', null,
|
|
|
|
|
$this->msg( 'api-help-permissions-granted-to' )
|
|
|
|
|
->numParams( count( $groups ) )
|
|
|
|
|
->params( $this->getLanguage()->commaList( $groups ) )
|
|
|
|
|
->parse()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
$help['permissions'] .= Html::closeElement( 'dl' );
|
|
|
|
|
$help['permissions'] .= Html::closeElement( 'div' );
|
|
|
|
|
|
|
|
|
|
// Fill 'credits', if applicable
|
|
|
|
|
if ( empty( $options['nolead'] ) ) {
|
|
|
|
|
$help['credits'] .= Html::element( 'h' . min( 6, $options['headerlevel'] + 1 ),
|
|
|
|
|
array( 'id' => '+credits', 'class' => 'apihelp-header' ),
|
|
|
|
|
$this->msg( 'api-credits-header' )->parse()
|
|
|
|
|
);
|
|
|
|
|
$help['credits'] .= $this->msg( 'api-credits' )->useDatabase( false )->parseAsBlock();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private $mCanApiHighLimits = null;
|
|
|
|
|
|
2007-05-20 10:08:40 +00:00
|
|
|
/**
|
API: HTMLize and internationalize the help, add Special:ApiHelp
The existing API help, formatted as basically a plain-text document
embedded in XML and with a little bolding and a few links
syntax-highlighted in after the fact, works ok for experienced programmers
but isn't at all newbie-friendly. Further, all the help is hard-coded in
English, which isn't very friendly to non-English speakers.
So let's rewrite it. The help text is now obtained from i18n messages
and output in HTML, with the default display consisting of help for a
single module with links to help for other modules. This, of course,
necessitates deprecating many of the existing help-related methods and
hooks and replacing them with new ones, but backwards compatibility is
maintained for almost everything.
At the same time, action=paraminfo also needs to support the
'description' and other help-related fields being output in wikitext or
HTML, and I11cb063d (to access all modules via the 'modules' parameter
instead of having 'modules', 'formatmodules', 'querymodules', and so on)
is folded in.
And we also add Special:ApiHelp. When directly accessed, it simply
redirects to api.php with appropriate parameters. But it's also
transcludable to allow up-to-date API help text to be included within
the on-wiki documentation.
Note this patch doesn't actually add i18n messages for any API modules
besides ApiMain and ApiHelp. That will come in a followup patch, but for
the moment the backwards-compatibility code handles them nicely.
While we're messing with the documentation, we may as well add the
"internal" flag requested in bug 62905 (although the 'includeinternal'
parameter it also requests doesn't make much sense anymore) and a
"deprecated" flag that's needed by several modules now.
Bug: 30936
Bug: 38126
Bug: 42343
Bug: 45641
Bug: 62905
Bug: 63211
Change-Id: Ib14c00df06d85c2f6364d83b2b10ce34c7f513cc
2014-09-16 17:54:01 +00:00
|
|
|
* Check whether the current user is allowed to use high limits
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function canApiHighLimits() {
|
|
|
|
|
if ( !isset( $this->mCanApiHighLimits ) ) {
|
|
|
|
|
$this->mCanApiHighLimits = $this->getUser()->isAllowed( 'apihighlimits' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->mCanApiHighLimits;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Overrides to return this instance's module manager.
|
|
|
|
|
* @return ApiModuleManager
|
|
|
|
|
*/
|
|
|
|
|
public function getModuleManager() {
|
|
|
|
|
return $this->mModuleMgr;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-18 19:33:09 +00:00
|
|
|
/**
|
|
|
|
|
* Fetches the user agent used for this request
|
|
|
|
|
*
|
|
|
|
|
* The value will be the combination of the 'Api-User-Agent' header (if
|
|
|
|
|
* any) and the standard User-Agent header (if any).
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getUserAgent() {
|
|
|
|
|
return trim(
|
|
|
|
|
$this->getRequest()->getHeader( 'Api-user-agent' ) . ' ' .
|
|
|
|
|
$this->getRequest()->getHeader( 'User-agent' )
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
API: HTMLize and internationalize the help, add Special:ApiHelp
The existing API help, formatted as basically a plain-text document
embedded in XML and with a little bolding and a few links
syntax-highlighted in after the fact, works ok for experienced programmers
but isn't at all newbie-friendly. Further, all the help is hard-coded in
English, which isn't very friendly to non-English speakers.
So let's rewrite it. The help text is now obtained from i18n messages
and output in HTML, with the default display consisting of help for a
single module with links to help for other modules. This, of course,
necessitates deprecating many of the existing help-related methods and
hooks and replacing them with new ones, but backwards compatibility is
maintained for almost everything.
At the same time, action=paraminfo also needs to support the
'description' and other help-related fields being output in wikitext or
HTML, and I11cb063d (to access all modules via the 'modules' parameter
instead of having 'modules', 'formatmodules', 'querymodules', and so on)
is folded in.
And we also add Special:ApiHelp. When directly accessed, it simply
redirects to api.php with appropriate parameters. But it's also
transcludable to allow up-to-date API help text to be included within
the on-wiki documentation.
Note this patch doesn't actually add i18n messages for any API modules
besides ApiMain and ApiHelp. That will come in a followup patch, but for
the moment the backwards-compatibility code handles them nicely.
While we're messing with the documentation, we may as well add the
"internal" flag requested in bug 62905 (although the 'includeinternal'
parameter it also requests doesn't make much sense anymore) and a
"deprecated" flag that's needed by several modules now.
Bug: 30936
Bug: 38126
Bug: 42343
Bug: 45641
Bug: 62905
Bug: 63211
Change-Id: Ib14c00df06d85c2f6364d83b2b10ce34c7f513cc
2014-09-16 17:54:01 +00:00
|
|
|
/************************************************************************//**
|
|
|
|
|
* @name Deprecated
|
|
|
|
|
* @{
|
|
|
|
|
*/
|
|
|
|
|
|
2010-05-08 11:45:41 +00:00
|
|
|
/**
|
|
|
|
|
* Sets whether the pretty-printer should format *bold* and $italics$
|
2011-05-08 16:48:30 +00:00
|
|
|
*
|
API: HTMLize and internationalize the help, add Special:ApiHelp
The existing API help, formatted as basically a plain-text document
embedded in XML and with a little bolding and a few links
syntax-highlighted in after the fact, works ok for experienced programmers
but isn't at all newbie-friendly. Further, all the help is hard-coded in
English, which isn't very friendly to non-English speakers.
So let's rewrite it. The help text is now obtained from i18n messages
and output in HTML, with the default display consisting of help for a
single module with links to help for other modules. This, of course,
necessitates deprecating many of the existing help-related methods and
hooks and replacing them with new ones, but backwards compatibility is
maintained for almost everything.
At the same time, action=paraminfo also needs to support the
'description' and other help-related fields being output in wikitext or
HTML, and I11cb063d (to access all modules via the 'modules' parameter
instead of having 'modules', 'formatmodules', 'querymodules', and so on)
is folded in.
And we also add Special:ApiHelp. When directly accessed, it simply
redirects to api.php with appropriate parameters. But it's also
transcludable to allow up-to-date API help text to be included within
the on-wiki documentation.
Note this patch doesn't actually add i18n messages for any API modules
besides ApiMain and ApiHelp. That will come in a followup patch, but for
the moment the backwards-compatibility code handles them nicely.
While we're messing with the documentation, we may as well add the
"internal" flag requested in bug 62905 (although the 'includeinternal'
parameter it also requests doesn't make much sense anymore) and a
"deprecated" flag that's needed by several modules now.
Bug: 30936
Bug: 38126
Bug: 42343
Bug: 45641
Bug: 62905
Bug: 63211
Change-Id: Ib14c00df06d85c2f6364d83b2b10ce34c7f513cc
2014-09-16 17:54:01 +00:00
|
|
|
* @deprecated since 1.25
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param bool $help
|
2010-05-08 11:45:41 +00:00
|
|
|
*/
|
|
|
|
|
public function setHelp( $help = true ) {
|
API: HTMLize and internationalize the help, add Special:ApiHelp
The existing API help, formatted as basically a plain-text document
embedded in XML and with a little bolding and a few links
syntax-highlighted in after the fact, works ok for experienced programmers
but isn't at all newbie-friendly. Further, all the help is hard-coded in
English, which isn't very friendly to non-English speakers.
So let's rewrite it. The help text is now obtained from i18n messages
and output in HTML, with the default display consisting of help for a
single module with links to help for other modules. This, of course,
necessitates deprecating many of the existing help-related methods and
hooks and replacing them with new ones, but backwards compatibility is
maintained for almost everything.
At the same time, action=paraminfo also needs to support the
'description' and other help-related fields being output in wikitext or
HTML, and I11cb063d (to access all modules via the 'modules' parameter
instead of having 'modules', 'formatmodules', 'querymodules', and so on)
is folded in.
And we also add Special:ApiHelp. When directly accessed, it simply
redirects to api.php with appropriate parameters. But it's also
transcludable to allow up-to-date API help text to be included within
the on-wiki documentation.
Note this patch doesn't actually add i18n messages for any API modules
besides ApiMain and ApiHelp. That will come in a followup patch, but for
the moment the backwards-compatibility code handles them nicely.
While we're messing with the documentation, we may as well add the
"internal" flag requested in bug 62905 (although the 'includeinternal'
parameter it also requests doesn't make much sense anymore) and a
"deprecated" flag that's needed by several modules now.
Bug: 30936
Bug: 38126
Bug: 42343
Bug: 45641
Bug: 62905
Bug: 63211
Change-Id: Ib14c00df06d85c2f6364d83b2b10ce34c7f513cc
2014-09-16 17:54:01 +00:00
|
|
|
wfDeprecated( __METHOD__, '1.25' );
|
2010-05-08 11:45:41 +00:00
|
|
|
$this->mPrinter->setHelp( $help );
|
|
|
|
|
}
|
2006-10-01 04:38:31 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Override the parent to generate help messages for all available modules.
|
2011-05-08 16:48:30 +00:00
|
|
|
*
|
API: HTMLize and internationalize the help, add Special:ApiHelp
The existing API help, formatted as basically a plain-text document
embedded in XML and with a little bolding and a few links
syntax-highlighted in after the fact, works ok for experienced programmers
but isn't at all newbie-friendly. Further, all the help is hard-coded in
English, which isn't very friendly to non-English speakers.
So let's rewrite it. The help text is now obtained from i18n messages
and output in HTML, with the default display consisting of help for a
single module with links to help for other modules. This, of course,
necessitates deprecating many of the existing help-related methods and
hooks and replacing them with new ones, but backwards compatibility is
maintained for almost everything.
At the same time, action=paraminfo also needs to support the
'description' and other help-related fields being output in wikitext or
HTML, and I11cb063d (to access all modules via the 'modules' parameter
instead of having 'modules', 'formatmodules', 'querymodules', and so on)
is folded in.
And we also add Special:ApiHelp. When directly accessed, it simply
redirects to api.php with appropriate parameters. But it's also
transcludable to allow up-to-date API help text to be included within
the on-wiki documentation.
Note this patch doesn't actually add i18n messages for any API modules
besides ApiMain and ApiHelp. That will come in a followup patch, but for
the moment the backwards-compatibility code handles them nicely.
While we're messing with the documentation, we may as well add the
"internal" flag requested in bug 62905 (although the 'includeinternal'
parameter it also requests doesn't make much sense anymore) and a
"deprecated" flag that's needed by several modules now.
Bug: 30936
Bug: 38126
Bug: 42343
Bug: 45641
Bug: 62905
Bug: 63211
Change-Id: Ib14c00df06d85c2f6364d83b2b10ce34c7f513cc
2014-09-16 17:54:01 +00:00
|
|
|
* @deprecated since 1.25
|
2011-05-08 16:48:30 +00:00
|
|
|
* @return string
|
2006-10-01 04:38:31 +00:00
|
|
|
*/
|
|
|
|
|
public function makeHelpMsg() {
|
API: HTMLize and internationalize the help, add Special:ApiHelp
The existing API help, formatted as basically a plain-text document
embedded in XML and with a little bolding and a few links
syntax-highlighted in after the fact, works ok for experienced programmers
but isn't at all newbie-friendly. Further, all the help is hard-coded in
English, which isn't very friendly to non-English speakers.
So let's rewrite it. The help text is now obtained from i18n messages
and output in HTML, with the default display consisting of help for a
single module with links to help for other modules. This, of course,
necessitates deprecating many of the existing help-related methods and
hooks and replacing them with new ones, but backwards compatibility is
maintained for almost everything.
At the same time, action=paraminfo also needs to support the
'description' and other help-related fields being output in wikitext or
HTML, and I11cb063d (to access all modules via the 'modules' parameter
instead of having 'modules', 'formatmodules', 'querymodules', and so on)
is folded in.
And we also add Special:ApiHelp. When directly accessed, it simply
redirects to api.php with appropriate parameters. But it's also
transcludable to allow up-to-date API help text to be included within
the on-wiki documentation.
Note this patch doesn't actually add i18n messages for any API modules
besides ApiMain and ApiHelp. That will come in a followup patch, but for
the moment the backwards-compatibility code handles them nicely.
While we're messing with the documentation, we may as well add the
"internal" flag requested in bug 62905 (although the 'includeinternal'
parameter it also requests doesn't make much sense anymore) and a
"deprecated" flag that's needed by several modules now.
Bug: 30936
Bug: 38126
Bug: 42343
Bug: 45641
Bug: 62905
Bug: 63211
Change-Id: Ib14c00df06d85c2f6364d83b2b10ce34c7f513cc
2014-09-16 17:54:01 +00:00
|
|
|
wfDeprecated( __METHOD__, '1.25' );
|
2014-01-24 02:51:11 +00:00
|
|
|
global $wgMemc;
|
2010-05-08 11:45:41 +00:00
|
|
|
$this->setHelp();
|
2009-08-27 18:25:51 +00:00
|
|
|
// Get help text from cache if present
|
2010-10-18 09:19:20 +00:00
|
|
|
$key = wfMemcKey( 'apihelp', $this->getModuleName(),
|
2013-08-14 22:23:30 +00:00
|
|
|
str_replace( ' ', '_', SpecialVersion::getVersion( 'nodb' ) ) );
|
2014-01-24 02:51:11 +00:00
|
|
|
|
|
|
|
|
$cacheHelpTimeout = $this->getConfig()->get( 'APICacheHelpTimeout' );
|
|
|
|
|
if ( $cacheHelpTimeout > 0 ) {
|
2009-09-09 12:54:56 +00:00
|
|
|
$cached = $wgMemc->get( $key );
|
2010-02-23 18:05:46 +00:00
|
|
|
if ( $cached ) {
|
2009-09-09 12:54:56 +00:00
|
|
|
return $cached;
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2009-09-09 12:54:56 +00:00
|
|
|
}
|
2009-08-27 18:25:51 +00:00
|
|
|
$retval = $this->reallyMakeHelpMsg();
|
2014-01-24 02:51:11 +00:00
|
|
|
if ( $cacheHelpTimeout > 0 ) {
|
|
|
|
|
$wgMemc->set( $key, $retval, $cacheHelpTimeout );
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2013-11-14 12:42:04 +00:00
|
|
|
|
2009-08-27 18:25:51 +00:00
|
|
|
return $retval;
|
|
|
|
|
}
|
2010-01-22 03:14:52 +00:00
|
|
|
|
2011-05-08 16:48:30 +00:00
|
|
|
/**
|
API: HTMLize and internationalize the help, add Special:ApiHelp
The existing API help, formatted as basically a plain-text document
embedded in XML and with a little bolding and a few links
syntax-highlighted in after the fact, works ok for experienced programmers
but isn't at all newbie-friendly. Further, all the help is hard-coded in
English, which isn't very friendly to non-English speakers.
So let's rewrite it. The help text is now obtained from i18n messages
and output in HTML, with the default display consisting of help for a
single module with links to help for other modules. This, of course,
necessitates deprecating many of the existing help-related methods and
hooks and replacing them with new ones, but backwards compatibility is
maintained for almost everything.
At the same time, action=paraminfo also needs to support the
'description' and other help-related fields being output in wikitext or
HTML, and I11cb063d (to access all modules via the 'modules' parameter
instead of having 'modules', 'formatmodules', 'querymodules', and so on)
is folded in.
And we also add Special:ApiHelp. When directly accessed, it simply
redirects to api.php with appropriate parameters. But it's also
transcludable to allow up-to-date API help text to be included within
the on-wiki documentation.
Note this patch doesn't actually add i18n messages for any API modules
besides ApiMain and ApiHelp. That will come in a followup patch, but for
the moment the backwards-compatibility code handles them nicely.
While we're messing with the documentation, we may as well add the
"internal" flag requested in bug 62905 (although the 'includeinternal'
parameter it also requests doesn't make much sense anymore) and a
"deprecated" flag that's needed by several modules now.
Bug: 30936
Bug: 38126
Bug: 42343
Bug: 45641
Bug: 62905
Bug: 63211
Change-Id: Ib14c00df06d85c2f6364d83b2b10ce34c7f513cc
2014-09-16 17:54:01 +00:00
|
|
|
* @deprecated since 1.25
|
2011-05-08 16:48:30 +00:00
|
|
|
* @return mixed|string
|
|
|
|
|
*/
|
2009-08-27 18:25:51 +00:00
|
|
|
public function reallyMakeHelpMsg() {
|
API: HTMLize and internationalize the help, add Special:ApiHelp
The existing API help, formatted as basically a plain-text document
embedded in XML and with a little bolding and a few links
syntax-highlighted in after the fact, works ok for experienced programmers
but isn't at all newbie-friendly. Further, all the help is hard-coded in
English, which isn't very friendly to non-English speakers.
So let's rewrite it. The help text is now obtained from i18n messages
and output in HTML, with the default display consisting of help for a
single module with links to help for other modules. This, of course,
necessitates deprecating many of the existing help-related methods and
hooks and replacing them with new ones, but backwards compatibility is
maintained for almost everything.
At the same time, action=paraminfo also needs to support the
'description' and other help-related fields being output in wikitext or
HTML, and I11cb063d (to access all modules via the 'modules' parameter
instead of having 'modules', 'formatmodules', 'querymodules', and so on)
is folded in.
And we also add Special:ApiHelp. When directly accessed, it simply
redirects to api.php with appropriate parameters. But it's also
transcludable to allow up-to-date API help text to be included within
the on-wiki documentation.
Note this patch doesn't actually add i18n messages for any API modules
besides ApiMain and ApiHelp. That will come in a followup patch, but for
the moment the backwards-compatibility code handles them nicely.
While we're messing with the documentation, we may as well add the
"internal" flag requested in bug 62905 (although the 'includeinternal'
parameter it also requests doesn't make much sense anymore) and a
"deprecated" flag that's needed by several modules now.
Bug: 30936
Bug: 38126
Bug: 42343
Bug: 45641
Bug: 62905
Bug: 63211
Change-Id: Ib14c00df06d85c2f6364d83b2b10ce34c7f513cc
2014-09-16 17:54:01 +00:00
|
|
|
wfDeprecated( __METHOD__, '1.25' );
|
2010-05-08 11:45:41 +00:00
|
|
|
$this->setHelp();
|
2006-10-01 04:38:31 +00:00
|
|
|
|
|
|
|
|
// Use parent to make default message for the main module
|
2010-02-23 18:05:46 +00:00
|
|
|
$msg = parent::makeHelpMsg();
|
2006-10-01 04:38:31 +00:00
|
|
|
|
2011-01-07 03:04:03 +00:00
|
|
|
$astriks = str_repeat( '*** ', 14 );
|
2006-10-01 04:38:31 +00:00
|
|
|
$msg .= "\n\n$astriks Modules $astriks\n\n";
|
2013-02-05 06:52:55 +00:00
|
|
|
|
|
|
|
|
foreach ( $this->mModuleMgr->getNames( 'action' ) as $name ) {
|
|
|
|
|
$module = $this->mModuleMgr->getModule( $name );
|
2010-01-11 15:55:52 +00:00
|
|
|
$msg .= self::makeHelpMsgHeader( $module, 'action' );
|
2013-01-12 06:50:48 +00:00
|
|
|
|
2006-10-01 04:38:31 +00:00
|
|
|
$msg2 = $module->makeHelpMsg();
|
2010-02-23 18:05:46 +00:00
|
|
|
if ( $msg2 !== false ) {
|
2006-10-01 04:38:31 +00:00
|
|
|
$msg .= $msg2;
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2006-10-01 04:38:31 +00:00
|
|
|
$msg .= "\n";
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-04 14:26:20 +00:00
|
|
|
$msg .= "\n$astriks Permissions $astriks\n\n";
|
2010-02-23 18:05:46 +00:00
|
|
|
foreach ( self::$mRights as $right => $rightMsg ) {
|
API: HTMLize and internationalize the help, add Special:ApiHelp
The existing API help, formatted as basically a plain-text document
embedded in XML and with a little bolding and a few links
syntax-highlighted in after the fact, works ok for experienced programmers
but isn't at all newbie-friendly. Further, all the help is hard-coded in
English, which isn't very friendly to non-English speakers.
So let's rewrite it. The help text is now obtained from i18n messages
and output in HTML, with the default display consisting of help for a
single module with links to help for other modules. This, of course,
necessitates deprecating many of the existing help-related methods and
hooks and replacing them with new ones, but backwards compatibility is
maintained for almost everything.
At the same time, action=paraminfo also needs to support the
'description' and other help-related fields being output in wikitext or
HTML, and I11cb063d (to access all modules via the 'modules' parameter
instead of having 'modules', 'formatmodules', 'querymodules', and so on)
is folded in.
And we also add Special:ApiHelp. When directly accessed, it simply
redirects to api.php with appropriate parameters. But it's also
transcludable to allow up-to-date API help text to be included within
the on-wiki documentation.
Note this patch doesn't actually add i18n messages for any API modules
besides ApiMain and ApiHelp. That will come in a followup patch, but for
the moment the backwards-compatibility code handles them nicely.
While we're messing with the documentation, we may as well add the
"internal" flag requested in bug 62905 (although the 'includeinternal'
parameter it also requests doesn't make much sense anymore) and a
"deprecated" flag that's needed by several modules now.
Bug: 30936
Bug: 38126
Bug: 42343
Bug: 45641
Bug: 62905
Bug: 63211
Change-Id: Ib14c00df06d85c2f6364d83b2b10ce34c7f513cc
2014-09-16 17:54:01 +00:00
|
|
|
$rightsMsg = $this->msg( $rightMsg['msg'], $rightMsg['params'] )
|
|
|
|
|
->useDatabase( false )
|
|
|
|
|
->inLanguage( 'en' )
|
|
|
|
|
->text();
|
2008-08-04 14:26:20 +00:00
|
|
|
$groups = User::getGroupsWithPermission( $right );
|
API: HTMLize and internationalize the help, add Special:ApiHelp
The existing API help, formatted as basically a plain-text document
embedded in XML and with a little bolding and a few links
syntax-highlighted in after the fact, works ok for experienced programmers
but isn't at all newbie-friendly. Further, all the help is hard-coded in
English, which isn't very friendly to non-English speakers.
So let's rewrite it. The help text is now obtained from i18n messages
and output in HTML, with the default display consisting of help for a
single module with links to help for other modules. This, of course,
necessitates deprecating many of the existing help-related methods and
hooks and replacing them with new ones, but backwards compatibility is
maintained for almost everything.
At the same time, action=paraminfo also needs to support the
'description' and other help-related fields being output in wikitext or
HTML, and I11cb063d (to access all modules via the 'modules' parameter
instead of having 'modules', 'formatmodules', 'querymodules', and so on)
is folded in.
And we also add Special:ApiHelp. When directly accessed, it simply
redirects to api.php with appropriate parameters. But it's also
transcludable to allow up-to-date API help text to be included within
the on-wiki documentation.
Note this patch doesn't actually add i18n messages for any API modules
besides ApiMain and ApiHelp. That will come in a followup patch, but for
the moment the backwards-compatibility code handles them nicely.
While we're messing with the documentation, we may as well add the
"internal" flag requested in bug 62905 (although the 'includeinternal'
parameter it also requests doesn't make much sense anymore) and a
"deprecated" flag that's needed by several modules now.
Bug: 30936
Bug: 38126
Bug: 42343
Bug: 45641
Bug: 62905
Bug: 63211
Change-Id: Ib14c00df06d85c2f6364d83b2b10ce34c7f513cc
2014-09-16 17:54:01 +00:00
|
|
|
$msg .= "* " . $right . " *\n $rightsMsg" .
|
2013-11-14 12:42:04 +00:00
|
|
|
"\nGranted to:\n " . str_replace( '*', 'all', implode( ', ', $groups ) ) . "\n\n";
|
2008-08-04 14:26:20 +00:00
|
|
|
}
|
|
|
|
|
|
2006-10-01 04:38:31 +00:00
|
|
|
$msg .= "\n$astriks Formats $astriks\n\n";
|
2013-02-05 06:52:55 +00:00
|
|
|
foreach ( $this->mModuleMgr->getNames( 'format' ) as $name ) {
|
|
|
|
|
$module = $this->mModuleMgr->getModule( $name );
|
2010-01-11 15:55:52 +00:00
|
|
|
$msg .= self::makeHelpMsgHeader( $module, 'format' );
|
2006-10-01 04:38:31 +00:00
|
|
|
$msg2 = $module->makeHelpMsg();
|
2010-02-23 18:05:46 +00:00
|
|
|
if ( $msg2 !== false ) {
|
2006-10-01 04:38:31 +00:00
|
|
|
$msg .= $msg2;
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2006-10-01 04:38:31 +00:00
|
|
|
$msg .= "\n";
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
API: HTMLize and internationalize the help, add Special:ApiHelp
The existing API help, formatted as basically a plain-text document
embedded in XML and with a little bolding and a few links
syntax-highlighted in after the fact, works ok for experienced programmers
but isn't at all newbie-friendly. Further, all the help is hard-coded in
English, which isn't very friendly to non-English speakers.
So let's rewrite it. The help text is now obtained from i18n messages
and output in HTML, with the default display consisting of help for a
single module with links to help for other modules. This, of course,
necessitates deprecating many of the existing help-related methods and
hooks and replacing them with new ones, but backwards compatibility is
maintained for almost everything.
At the same time, action=paraminfo also needs to support the
'description' and other help-related fields being output in wikitext or
HTML, and I11cb063d (to access all modules via the 'modules' parameter
instead of having 'modules', 'formatmodules', 'querymodules', and so on)
is folded in.
And we also add Special:ApiHelp. When directly accessed, it simply
redirects to api.php with appropriate parameters. But it's also
transcludable to allow up-to-date API help text to be included within
the on-wiki documentation.
Note this patch doesn't actually add i18n messages for any API modules
besides ApiMain and ApiHelp. That will come in a followup patch, but for
the moment the backwards-compatibility code handles them nicely.
While we're messing with the documentation, we may as well add the
"internal" flag requested in bug 62905 (although the 'includeinternal'
parameter it also requests doesn't make much sense anymore) and a
"deprecated" flag that's needed by several modules now.
Bug: 30936
Bug: 38126
Bug: 42343
Bug: 45641
Bug: 62905
Bug: 63211
Change-Id: Ib14c00df06d85c2f6364d83b2b10ce34c7f513cc
2014-09-16 17:54:01 +00:00
|
|
|
$credits = $this->msg( 'api-credits' )->useDatabase( 'false' )->inLanguage( 'en' )->text();
|
|
|
|
|
$credits = str_replace( "\n", "\n ", $credits );
|
|
|
|
|
$msg .= "\n*** Credits: ***\n $credits\n";
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2006-10-01 04:38:31 +00:00
|
|
|
return $msg;
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-23 19:24:38 +00:00
|
|
|
/**
|
API: HTMLize and internationalize the help, add Special:ApiHelp
The existing API help, formatted as basically a plain-text document
embedded in XML and with a little bolding and a few links
syntax-highlighted in after the fact, works ok for experienced programmers
but isn't at all newbie-friendly. Further, all the help is hard-coded in
English, which isn't very friendly to non-English speakers.
So let's rewrite it. The help text is now obtained from i18n messages
and output in HTML, with the default display consisting of help for a
single module with links to help for other modules. This, of course,
necessitates deprecating many of the existing help-related methods and
hooks and replacing them with new ones, but backwards compatibility is
maintained for almost everything.
At the same time, action=paraminfo also needs to support the
'description' and other help-related fields being output in wikitext or
HTML, and I11cb063d (to access all modules via the 'modules' parameter
instead of having 'modules', 'formatmodules', 'querymodules', and so on)
is folded in.
And we also add Special:ApiHelp. When directly accessed, it simply
redirects to api.php with appropriate parameters. But it's also
transcludable to allow up-to-date API help text to be included within
the on-wiki documentation.
Note this patch doesn't actually add i18n messages for any API modules
besides ApiMain and ApiHelp. That will come in a followup patch, but for
the moment the backwards-compatibility code handles them nicely.
While we're messing with the documentation, we may as well add the
"internal" flag requested in bug 62905 (although the 'includeinternal'
parameter it also requests doesn't make much sense anymore) and a
"deprecated" flag that's needed by several modules now.
Bug: 30936
Bug: 38126
Bug: 42343
Bug: 45641
Bug: 62905
Bug: 63211
Change-Id: Ib14c00df06d85c2f6364d83b2b10ce34c7f513cc
2014-09-16 17:54:01 +00:00
|
|
|
* @deprecated since 1.25
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param ApiBase $module
|
2013-11-16 19:09:17 +00:00
|
|
|
* @param string $paramName What type of request is this? e.g. action,
|
|
|
|
|
* query, list, prop, meta, format
|
2010-12-23 19:24:38 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
public static function makeHelpMsgHeader( $module, $paramName ) {
|
API: HTMLize and internationalize the help, add Special:ApiHelp
The existing API help, formatted as basically a plain-text document
embedded in XML and with a little bolding and a few links
syntax-highlighted in after the fact, works ok for experienced programmers
but isn't at all newbie-friendly. Further, all the help is hard-coded in
English, which isn't very friendly to non-English speakers.
So let's rewrite it. The help text is now obtained from i18n messages
and output in HTML, with the default display consisting of help for a
single module with links to help for other modules. This, of course,
necessitates deprecating many of the existing help-related methods and
hooks and replacing them with new ones, but backwards compatibility is
maintained for almost everything.
At the same time, action=paraminfo also needs to support the
'description' and other help-related fields being output in wikitext or
HTML, and I11cb063d (to access all modules via the 'modules' parameter
instead of having 'modules', 'formatmodules', 'querymodules', and so on)
is folded in.
And we also add Special:ApiHelp. When directly accessed, it simply
redirects to api.php with appropriate parameters. But it's also
transcludable to allow up-to-date API help text to be included within
the on-wiki documentation.
Note this patch doesn't actually add i18n messages for any API modules
besides ApiMain and ApiHelp. That will come in a followup patch, but for
the moment the backwards-compatibility code handles them nicely.
While we're messing with the documentation, we may as well add the
"internal" flag requested in bug 62905 (although the 'includeinternal'
parameter it also requests doesn't make much sense anymore) and a
"deprecated" flag that's needed by several modules now.
Bug: 30936
Bug: 38126
Bug: 42343
Bug: 45641
Bug: 62905
Bug: 63211
Change-Id: Ib14c00df06d85c2f6364d83b2b10ce34c7f513cc
2014-09-16 17:54:01 +00:00
|
|
|
wfDeprecated( __METHOD__, '1.25' );
|
2007-07-07 03:05:09 +00:00
|
|
|
$modulePrefix = $module->getModulePrefix();
|
2010-02-23 18:05:46 +00:00
|
|
|
if ( strval( $modulePrefix ) !== '' ) {
|
2008-04-14 07:45:50 +00:00
|
|
|
$modulePrefix = "($modulePrefix) ";
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-07-07 03:05:09 +00:00
|
|
|
return "* $paramName={$module->getModuleName()} $modulePrefix*";
|
2008-04-14 07:45:50 +00:00
|
|
|
}
|
2007-05-21 06:32:32 +00:00
|
|
|
|
2008-05-10 09:29:34 +00:00
|
|
|
/**
|
|
|
|
|
* Check whether the user wants us to show version information in the API help
|
|
|
|
|
* @return bool
|
2013-01-14 22:01:42 +00:00
|
|
|
* @deprecated since 1.21, always returns false
|
2008-05-10 09:29:34 +00:00
|
|
|
*/
|
2006-10-14 07:18:08 +00:00
|
|
|
public function getShowVersions() {
|
2013-01-14 22:01:42 +00:00
|
|
|
wfDeprecated( __METHOD__, '1.21' );
|
2013-11-14 12:42:04 +00:00
|
|
|
|
2013-01-14 22:01:42 +00:00
|
|
|
return false;
|
2006-10-01 21:20:55 +00:00
|
|
|
}
|
2007-07-18 05:25:53 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add or overwrite a module in this ApiMain instance. Intended for use by extending
|
2008-04-14 07:45:50 +00:00
|
|
|
* classes who wish to add their own modules to their lexicon or override the
|
2007-07-18 05:25:53 +00:00
|
|
|
* behavior of inherent ones.
|
|
|
|
|
*
|
2013-02-05 06:52:55 +00:00
|
|
|
* @deprecated since 1.21, Use getModuleManager()->addModule() instead.
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $name The identifier for this module.
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param ApiBase $class The class where this module is implemented.
|
2007-07-18 05:25:53 +00:00
|
|
|
*/
|
2013-02-05 06:52:55 +00:00
|
|
|
protected function addModule( $name, $class ) {
|
|
|
|
|
$this->getModuleManager()->addModule( $name, 'action', $class );
|
2007-07-18 05:25:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add or overwrite an output format for this ApiMain. Intended for use by extending
|
|
|
|
|
* classes who wish to add to or modify current formatters.
|
|
|
|
|
*
|
2013-02-05 06:52:55 +00:00
|
|
|
* @deprecated since 1.21, Use getModuleManager()->addModule() instead.
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $name The identifier for this format.
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param ApiFormatBase $class The class implementing this format.
|
2007-07-18 05:25:53 +00:00
|
|
|
*/
|
2013-02-05 06:52:55 +00:00
|
|
|
protected function addFormat( $name, $class ) {
|
2013-03-07 20:31:43 +00:00
|
|
|
$this->getModuleManager()->addModule( $name, 'format', $class );
|
2007-07-18 05:25:53 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2008-01-23 18:40:40 +00:00
|
|
|
/**
|
|
|
|
|
* Get the array mapping module names to class names
|
2013-02-05 06:52:55 +00:00
|
|
|
* @deprecated since 1.21, Use getModuleManager()'s methods instead.
|
2011-01-30 08:16:13 +00:00
|
|
|
* @return array
|
2008-01-23 18:40:40 +00:00
|
|
|
*/
|
|
|
|
|
function getModules() {
|
2013-02-05 06:52:55 +00:00
|
|
|
return $this->getModuleManager()->getNamesWithClasses( 'action' );
|
2008-01-23 18:40:40 +00:00
|
|
|
}
|
2011-05-03 16:54:16 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the list of supported formats in form ( 'format' => 'ClassName' )
|
|
|
|
|
*
|
|
|
|
|
* @since 1.18
|
2013-02-05 06:52:55 +00:00
|
|
|
* @deprecated since 1.21, Use getModuleManager()'s methods instead.
|
2011-05-03 16:54:16 +00:00
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function getFormats() {
|
2013-02-05 06:52:55 +00:00
|
|
|
return $this->getModuleManager()->getNamesWithClasses( 'format' );
|
2011-05-03 16:54:16 +00:00
|
|
|
}
|
API: HTMLize and internationalize the help, add Special:ApiHelp
The existing API help, formatted as basically a plain-text document
embedded in XML and with a little bolding and a few links
syntax-highlighted in after the fact, works ok for experienced programmers
but isn't at all newbie-friendly. Further, all the help is hard-coded in
English, which isn't very friendly to non-English speakers.
So let's rewrite it. The help text is now obtained from i18n messages
and output in HTML, with the default display consisting of help for a
single module with links to help for other modules. This, of course,
necessitates deprecating many of the existing help-related methods and
hooks and replacing them with new ones, but backwards compatibility is
maintained for almost everything.
At the same time, action=paraminfo also needs to support the
'description' and other help-related fields being output in wikitext or
HTML, and I11cb063d (to access all modules via the 'modules' parameter
instead of having 'modules', 'formatmodules', 'querymodules', and so on)
is folded in.
And we also add Special:ApiHelp. When directly accessed, it simply
redirects to api.php with appropriate parameters. But it's also
transcludable to allow up-to-date API help text to be included within
the on-wiki documentation.
Note this patch doesn't actually add i18n messages for any API modules
besides ApiMain and ApiHelp. That will come in a followup patch, but for
the moment the backwards-compatibility code handles them nicely.
While we're messing with the documentation, we may as well add the
"internal" flag requested in bug 62905 (although the 'includeinternal'
parameter it also requests doesn't make much sense anymore) and a
"deprecated" flag that's needed by several modules now.
Bug: 30936
Bug: 38126
Bug: 42343
Bug: 45641
Bug: 62905
Bug: 63211
Change-Id: Ib14c00df06d85c2f6364d83b2b10ce34c7f513cc
2014-09-16 17:54:01 +00:00
|
|
|
|
|
|
|
|
/**@}*/
|
|
|
|
|
|
2006-10-01 04:38:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
Some small doc tweaks to reduce Doxygen warnings, namely:
* @link. You might think @link would surely mean "here comes a web URL" ... but @link is a valid command
in Doxygen, which means an entirely different kind of link (an internal link to somewhere, so that you can separate
documentation and implementation). The result is a mess, and the best solution I can see is to use "@see" instead of "@link".
* Warning: argument `nourl' of command @param is not found in the argument list of Linker::makeMediaLinkObj($title,$text='')
* Moving few class descriptions to right above classes, and/or formatting into Javadoc style.
* "@addtogroup Special Pages" --> "@addtogroup SpecialPage" so that all special pages have the same @addtogroup tag.
* @fixme --> @todo (must have missed these before)
* "@param $specialPage @see" remove the "@" in the "@see" to stop warning.
* @throws wants type, then a brief description, to stop warning.
This last one is for PHPdocumentor only, but it fixes something for PHPDocumentor, and should be neutral for Doxygen:
* WARNING in includes/api/ApiFormatYaml_spyc.php on line 860: docblock template never terminated with /**#@-*/
2007-04-18 09:50:10 +00:00
|
|
|
* This exception will be thrown when dieUsage is called to stop module execution.
|
2008-04-14 07:45:50 +00:00
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup API
|
Some small doc tweaks to reduce Doxygen warnings, namely:
* @link. You might think @link would surely mean "here comes a web URL" ... but @link is a valid command
in Doxygen, which means an entirely different kind of link (an internal link to somewhere, so that you can separate
documentation and implementation). The result is a mess, and the best solution I can see is to use "@see" instead of "@link".
* Warning: argument `nourl' of command @param is not found in the argument list of Linker::makeMediaLinkObj($title,$text='')
* Moving few class descriptions to right above classes, and/or formatting into Javadoc style.
* "@addtogroup Special Pages" --> "@addtogroup SpecialPage" so that all special pages have the same @addtogroup tag.
* @fixme --> @todo (must have missed these before)
* "@param $specialPage @see" remove the "@" in the "@see" to stop warning.
* @throws wants type, then a brief description, to stop warning.
This last one is for PHPdocumentor only, but it fixes something for PHPDocumentor, and should be neutral for Doxygen:
* WARNING in includes/api/ApiFormatYaml_spyc.php on line 860: docblock template never terminated with /**#@-*/
2007-04-18 09:50:10 +00:00
|
|
|
*/
|
2012-03-16 02:02:41 +00:00
|
|
|
class UsageException extends MWException {
|
2006-10-01 04:38:31 +00:00
|
|
|
|
2006-10-14 07:18:08 +00:00
|
|
|
private $mCodestr;
|
2012-07-12 15:53:00 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var null|array
|
|
|
|
|
*/
|
2009-07-12 12:38:03 +00:00
|
|
|
private $mExtraData;
|
2006-10-01 04:38:31 +00:00
|
|
|
|
2012-07-12 15:53:00 +00:00
|
|
|
/**
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param string $message
|
|
|
|
|
* @param string $codestr
|
|
|
|
|
* @param int $code
|
|
|
|
|
* @param array|null $extradata
|
2012-07-12 15:53:00 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
public function __construct( $message, $codestr, $code = 0, $extradata = null ) {
|
2010-02-23 18:05:46 +00:00
|
|
|
parent::__construct( $message, $code );
|
2006-10-14 07:18:08 +00:00
|
|
|
$this->mCodestr = $codestr;
|
2009-07-12 12:38:03 +00:00
|
|
|
$this->mExtraData = $extradata;
|
2006-10-14 07:18:08 +00:00
|
|
|
}
|
2010-02-23 18:05:46 +00:00
|
|
|
|
2011-06-05 15:10:11 +00:00
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2006-10-14 07:18:08 +00:00
|
|
|
public function getCodeString() {
|
|
|
|
|
return $this->mCodestr;
|
2006-10-01 04:38:31 +00:00
|
|
|
}
|
2010-02-23 18:05:46 +00:00
|
|
|
|
2011-06-05 15:10:11 +00:00
|
|
|
/**
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2009-07-12 12:38:03 +00:00
|
|
|
public function getMessageArray() {
|
2010-02-23 18:05:46 +00:00
|
|
|
$result = array(
|
|
|
|
|
'code' => $this->mCodestr,
|
|
|
|
|
'info' => $this->getMessage()
|
2009-07-12 12:38:03 +00:00
|
|
|
);
|
2010-02-23 18:05:46 +00:00
|
|
|
if ( is_array( $this->mExtraData ) ) {
|
2009-07-12 12:38:03 +00:00
|
|
|
$result = array_merge( $result, $this->mExtraData );
|
2010-02-23 18:05:46 +00:00
|
|
|
}
|
2013-11-14 12:42:04 +00:00
|
|
|
|
2009-07-12 12:38:03 +00:00
|
|
|
return $result;
|
|
|
|
|
}
|
2010-02-23 18:05:46 +00:00
|
|
|
|
2011-06-05 15:10:11 +00:00
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2006-10-01 04:38:31 +00:00
|
|
|
public function __toString() {
|
2006-10-14 07:18:08 +00:00
|
|
|
return "{$this->getCodeString()}: {$this->getMessage()}";
|
2006-10-01 04:38:31 +00:00
|
|
|
}
|
2009-05-20 20:07:33 +00:00
|
|
|
}
|
API: HTMLize and internationalize the help, add Special:ApiHelp
The existing API help, formatted as basically a plain-text document
embedded in XML and with a little bolding and a few links
syntax-highlighted in after the fact, works ok for experienced programmers
but isn't at all newbie-friendly. Further, all the help is hard-coded in
English, which isn't very friendly to non-English speakers.
So let's rewrite it. The help text is now obtained from i18n messages
and output in HTML, with the default display consisting of help for a
single module with links to help for other modules. This, of course,
necessitates deprecating many of the existing help-related methods and
hooks and replacing them with new ones, but backwards compatibility is
maintained for almost everything.
At the same time, action=paraminfo also needs to support the
'description' and other help-related fields being output in wikitext or
HTML, and I11cb063d (to access all modules via the 'modules' parameter
instead of having 'modules', 'formatmodules', 'querymodules', and so on)
is folded in.
And we also add Special:ApiHelp. When directly accessed, it simply
redirects to api.php with appropriate parameters. But it's also
transcludable to allow up-to-date API help text to be included within
the on-wiki documentation.
Note this patch doesn't actually add i18n messages for any API modules
besides ApiMain and ApiHelp. That will come in a followup patch, but for
the moment the backwards-compatibility code handles them nicely.
While we're messing with the documentation, we may as well add the
"internal" flag requested in bug 62905 (although the 'includeinternal'
parameter it also requests doesn't make much sense anymore) and a
"deprecated" flag that's needed by several modules now.
Bug: 30936
Bug: 38126
Bug: 42343
Bug: 45641
Bug: 62905
Bug: 63211
Change-Id: Ib14c00df06d85c2f6364d83b2b10ce34c7f513cc
2014-09-16 17:54:01 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* For really cool vim folding this needs to be at the end:
|
|
|
|
|
* vim: foldmarker=@{,@} foldmethod=marker
|
|
|
|
|
*/
|