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;
|
2018-01-21 04:45:20 +00:00
|
|
|
use Wikimedia\IPSet;
|
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() {
|
|
|
|
global $wgLinterSubmitterWhitelist;
|
|
|
|
$ipSet = new IPSet(
|
|
|
|
array_keys( array_filter( $wgLinterSubmitterWhitelist ) )
|
|
|
|
);
|
|
|
|
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
|
|
|
}
|
2019-11-26 01:02:29 +00:00
|
|
|
if ( Hooks::onParserLogLinterData(
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAllowedParams() {
|
|
|
|
return [
|
2016-11-22 09:26:38 +00:00
|
|
|
'data' => [
|
|
|
|
ApiBase::PARAM_TYPE => 'string',
|
|
|
|
ApiBase::PARAM_REQUIRED => true,
|
|
|
|
],
|
|
|
|
'page' => [
|
|
|
|
ApiBase::PARAM_TYPE => 'string',
|
|
|
|
ApiBase::PARAM_REQUIRED => true,
|
|
|
|
],
|
|
|
|
'revision' => [
|
|
|
|
ApiBase::PARAM_TYPE => 'integer',
|
|
|
|
ApiBase::PARAM_REQUIRED => true,
|
|
|
|
],
|
2016-10-13 08:14:18 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|