2016-10-13 08:14:18 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* 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.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace MediaWiki\Linter;
|
|
|
|
|
|
|
|
use ApiBase;
|
|
|
|
use FormatJson;
|
2022-08-03 16:49:19 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2018-01-21 04:45:20 +00:00
|
|
|
use Wikimedia\IPSet;
|
2022-04-03 23:27:56 +00:00
|
|
|
use Wikimedia\ParamValidator\ParamValidator;
|
2016-10-13 08:14:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* API module for an external service to record
|
|
|
|
* a lint error
|
|
|
|
*/
|
|
|
|
class ApiRecordLint extends ApiBase {
|
|
|
|
|
|
|
|
public function execute() {
|
2022-08-03 16:49:19 +00:00
|
|
|
$mwServices = MediaWikiServices::getInstance();
|
|
|
|
$linterSubmitterAllowlist = $mwServices->getMainConfig()->get( 'LinterSubmitterWhitelist' );
|
2016-10-13 08:14:18 +00:00
|
|
|
$ipSet = new IPSet(
|
2022-08-03 16:49:19 +00:00
|
|
|
array_keys( array_filter( $linterSubmitterAllowlist ) )
|
2016-10-13 08:14:18 +00:00
|
|
|
);
|
|
|
|
if ( !$ipSet->match( $this->getRequest()->getIP() ) ) {
|
2017-12-03 01:27:08 +00:00
|
|
|
$this->dieWithError( 'apierror-linter-invalid-ip', 'invalid-ip' );
|
2016-10-13 08:14:18 +00:00
|
|
|
}
|
|
|
|
$params = $this->extractRequestParams();
|
|
|
|
$data = FormatJson::decode( $params['data'], true );
|
|
|
|
if ( !is_array( $data ) ) {
|
2017-12-03 01:27:08 +00:00
|
|
|
$this->dieWithError( 'apierror-linter-invalid-data', 'invalid-data' );
|
2016-10-13 08:14:18 +00:00
|
|
|
}
|
2022-09-07 01:54:33 +00:00
|
|
|
if ( ( new Hooks )->onParserLogLinterData(
|
2019-11-26 01:02:29 +00:00
|
|
|
$params['page'], $params['revision'], $data
|
|
|
|
) ) {
|
|
|
|
$this->getResult()->addValue( $this->getModuleName(), 'success', true );
|
|
|
|
} else {
|
2017-12-03 01:27:08 +00:00
|
|
|
$this->dieWithError( 'apierror-linter-invalid-title', 'invalid-title' );
|
2016-10-13 08:14:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isInternal() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-04-06 16:54:41 +00:00
|
|
|
/** @inheritDoc */
|
2016-10-13 08:14:18 +00:00
|
|
|
public function getAllowedParams() {
|
|
|
|
return [
|
2016-11-22 09:26:38 +00:00
|
|
|
'data' => [
|
2022-04-03 23:27:56 +00:00
|
|
|
ParamValidator::PARAM_TYPE => 'string',
|
|
|
|
ParamValidator::PARAM_REQUIRED => true,
|
2016-11-22 09:26:38 +00:00
|
|
|
],
|
|
|
|
'page' => [
|
2022-04-03 23:27:56 +00:00
|
|
|
ParamValidator::PARAM_TYPE => 'string',
|
|
|
|
ParamValidator::PARAM_REQUIRED => true,
|
2016-11-22 09:26:38 +00:00
|
|
|
],
|
|
|
|
'revision' => [
|
2022-04-03 23:27:56 +00:00
|
|
|
ParamValidator::PARAM_TYPE => 'integer',
|
|
|
|
ParamValidator::PARAM_REQUIRED => true,
|
2016-11-22 09:26:38 +00:00
|
|
|
],
|
2016-10-13 08:14:18 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|