Expose $wgMaxArticleSize in siteinfo query api
[mediawiki.git] / includes / api / ApiLinkAccount.php
blob14347d81d0912b540881b422bc8de1f769a86f62
1 <?php
2 /**
3 * Copyright © 2016 Brad Jorsch <bjorsch@wikimedia.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
23 use MediaWiki\Auth\AuthManager;
24 use MediaWiki\Auth\AuthenticationRequest;
25 use MediaWiki\Auth\AuthenticationResponse;
27 /**
28 * Link an account with AuthManager
30 * @ingroup API
32 class ApiLinkAccount extends ApiBase {
34 public function __construct( ApiMain $main, $action ) {
35 parent::__construct( $main, $action, 'link' );
38 public function getFinalDescription() {
39 // A bit of a hack to append 'api-help-authmanager-general-usage'
40 $msgs = parent::getFinalDescription();
41 $msgs[] = ApiBase::makeMessage( 'api-help-authmanager-general-usage', $this->getContext(), [
42 $this->getModulePrefix(),
43 $this->getModuleName(),
44 $this->getModulePath(),
45 AuthManager::ACTION_LINK,
46 self::needsToken(),
47 ] );
48 return $msgs;
51 public function execute() {
52 if ( !$this->getUser()->isLoggedIn() ) {
53 $this->dieUsage( 'Must be logged in to link accounts', 'notloggedin' );
56 $params = $this->extractRequestParams();
58 $this->requireAtLeastOneParameter( $params, 'continue', 'returnurl' );
60 if ( $params['returnurl'] !== null ) {
61 $bits = wfParseUrl( $params['returnurl'] );
62 if ( !$bits || $bits['scheme'] === '' ) {
63 $encParamName = $this->encodeParamName( 'returnurl' );
64 $this->dieUsage(
65 "Invalid value '{$params['returnurl']}' for url parameter $encParamName",
66 "badurl_{$encParamName}"
71 $helper = new ApiAuthManagerHelper( $this );
72 $manager = AuthManager::singleton();
74 // Check security-sensitive operation status
75 $helper->securitySensitiveOperation( 'LinkAccounts' );
77 // Make sure it's possible to link accounts
78 if ( !$manager->canLinkAccounts() ) {
79 $this->getResult()->addValue( null, 'linkaccount', $helper->formatAuthenticationResponse(
80 AuthenticationResponse::newFail( $this->msg( 'userlogin-cannot-' . AuthManager::ACTION_LINK ) )
81 ) );
82 return;
85 // Perform the link step
86 if ( $params['continue'] ) {
87 $reqs = $helper->loadAuthenticationRequests( AuthManager::ACTION_LINK_CONTINUE );
88 $res = $manager->continueAccountLink( $reqs );
89 } else {
90 $reqs = $helper->loadAuthenticationRequests( AuthManager::ACTION_LINK );
91 $res = $manager->beginAccountLink( $this->getUser(), $reqs, $params['returnurl'] );
94 $this->getResult()->addValue( null, 'linkaccount',
95 $helper->formatAuthenticationResponse( $res ) );
98 public function isReadMode() {
99 return false;
102 public function isWriteMode() {
103 return true;
106 public function needsToken() {
107 return 'csrf';
110 public function getAllowedParams() {
111 return ApiAuthManagerHelper::getStandardParams( AuthManager::ACTION_LINK,
112 'requests', 'messageformat', 'mergerequestfields', 'returnurl', 'continue'
116 public function dynamicParameterDocumentation() {
117 return [ 'api-help-authmanagerhelper-additional-params', AuthManager::ACTION_LINK ];
120 protected function getExamplesMessages() {
121 return [
122 'action=linkaccount&provider=Example&linkreturnurl=http://example.org/&linktoken=123ABC'
123 => 'apihelp-linkaccount-example-link',
127 public function getHelpUrls() {
128 return 'https://www.mediawiki.org/wiki/API:Linkaccount';