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 ApiQuery;
|
|
|
|
use ApiQueryBase;
|
|
|
|
use ApiResult;
|
2023-08-19 04:17:17 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2022-04-03 23:27:56 +00:00
|
|
|
use Wikimedia\ParamValidator\ParamValidator;
|
2022-04-03 20:15:33 +00:00
|
|
|
use Wikimedia\ParamValidator\TypeDef\IntegerDef;
|
2016-10-13 08:14:18 +00:00
|
|
|
|
|
|
|
class ApiQueryLintErrors extends ApiQueryBase {
|
2021-04-06 16:54:41 +00:00
|
|
|
/**
|
|
|
|
* @param ApiQuery $queryModule
|
|
|
|
* @param string $moduleName
|
|
|
|
*/
|
2016-10-13 08:14:18 +00:00
|
|
|
public function __construct( ApiQuery $queryModule, $moduleName ) {
|
|
|
|
parent::__construct( $queryModule, $moduleName, 'lnt' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute() {
|
|
|
|
$params = $this->extractRequestParams();
|
2016-11-22 09:03:02 +00:00
|
|
|
$categoryMgr = new CategoryManager();
|
2016-10-13 08:14:18 +00:00
|
|
|
|
2020-06-09 18:29:19 +00:00
|
|
|
$this->requireMaxOneParameter( $params, 'pageid', 'title' );
|
|
|
|
$this->requireMaxOneParameter( $params, 'namespace', 'title' );
|
|
|
|
|
2024-03-14 01:55:06 +00:00
|
|
|
$categories = $params['categories'];
|
|
|
|
if ( !$categories ) {
|
|
|
|
$categories = $categoryMgr->getVisibleCategories();
|
|
|
|
}
|
|
|
|
|
2016-10-13 08:14:18 +00:00
|
|
|
$this->addTables( 'linter' );
|
2016-11-22 09:34:50 +00:00
|
|
|
$this->addWhereFld( 'linter_cat', array_values( $categoryMgr->getCategoryIds(
|
2024-03-14 01:55:06 +00:00
|
|
|
$categories
|
2016-11-22 09:34:50 +00:00
|
|
|
) ) );
|
2016-10-13 08:14:18 +00:00
|
|
|
$db = $this->getDB();
|
|
|
|
if ( $params['from'] !== null ) {
|
2023-12-14 14:25:51 +00:00
|
|
|
$this->addWhere( $db->expr( "linter_id", '>=', $params['from'] ) );
|
2016-10-13 08:14:18 +00:00
|
|
|
}
|
2017-11-24 14:22:10 +00:00
|
|
|
if ( $params['pageid'] !== null ) {
|
2020-06-09 18:29:19 +00:00
|
|
|
// This can be an array or a single pageid
|
2017-11-24 14:22:10 +00:00
|
|
|
$this->addWhereFld( 'linter_page', $params['pageid'] );
|
|
|
|
}
|
2016-10-13 08:14:18 +00:00
|
|
|
if ( $params['namespace'] !== null ) {
|
|
|
|
$this->addWhereFld( 'page_namespace', $params['namespace'] );
|
|
|
|
}
|
2020-06-09 18:29:19 +00:00
|
|
|
if ( $params['title'] !== null ) {
|
|
|
|
$title = $this->getTitleFromTitleOrPageId( [ 'title' => $params['title'] ] );
|
|
|
|
$this->addWhereFld( 'page_namespace', $title->getNamespace() );
|
|
|
|
$this->addWhereFld( 'page_title', $title->getDBkey() );
|
|
|
|
}
|
2016-10-13 08:14:18 +00:00
|
|
|
$this->addTables( 'page' );
|
|
|
|
$this->addJoinConds( [ 'page' => [ 'INNER JOIN', 'page_id=linter_page' ] ] );
|
|
|
|
$this->addFields( [
|
|
|
|
'linter_id', 'linter_cat', 'linter_params',
|
2016-12-01 02:47:05 +00:00
|
|
|
'linter_start', 'linter_end',
|
2016-10-13 08:14:18 +00:00
|
|
|
'page_namespace', 'page_title',
|
|
|
|
] );
|
|
|
|
// Be explicit about ORDER BY
|
|
|
|
$this->addOption( 'ORDER BY', 'linter_id' );
|
|
|
|
// Add +1 to limit to know if there's another row for continuation
|
|
|
|
$this->addOption( 'LIMIT', $params['limit'] + 1 );
|
|
|
|
$rows = $this->select( __METHOD__ );
|
|
|
|
$result = $this->getResult();
|
|
|
|
$count = 0;
|
|
|
|
foreach ( $rows as $row ) {
|
|
|
|
$lintError = Database::makeLintError( $row );
|
2017-10-31 17:42:07 +00:00
|
|
|
if ( !$lintError ) {
|
|
|
|
continue;
|
|
|
|
}
|
2016-10-13 08:14:18 +00:00
|
|
|
$count++;
|
|
|
|
if ( $count > $params['limit'] ) {
|
|
|
|
$this->setContinueEnumParameter( 'from', $lintError->lintId );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$title = Title::makeTitle( $row->page_namespace, $row->page_title );
|
|
|
|
|
|
|
|
$data = [
|
2017-04-17 17:25:36 +00:00
|
|
|
'pageid' => $title->getArticleID(),
|
|
|
|
'ns' => $title->getNamespace(),
|
2016-10-13 08:14:18 +00:00
|
|
|
'title' => $title->getPrefixedText(),
|
|
|
|
'lintId' => $lintError->lintId,
|
|
|
|
'category' => $lintError->category,
|
|
|
|
'location' => $lintError->location,
|
|
|
|
'templateInfo' => $lintError->templateInfo,
|
|
|
|
'params' => $lintError->getExtraParams(),
|
|
|
|
];
|
|
|
|
// template info and params are an object
|
|
|
|
$data['params'][ApiResult::META_TYPE] = 'assoc';
|
|
|
|
$data['templateInfo'][ApiResult::META_TYPE] = 'assoc';
|
|
|
|
|
|
|
|
$fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $data );
|
|
|
|
if ( !$fit ) {
|
|
|
|
$this->setContinueEnumParameter( 'from', $lintError->lintId );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-06 16:54:41 +00:00
|
|
|
/** @inheritDoc */
|
2016-10-13 08:14:18 +00:00
|
|
|
public function getAllowedParams() {
|
2024-03-14 01:55:06 +00:00
|
|
|
$categoryMgr = new CategoryManager();
|
|
|
|
$visibleCats = $categoryMgr->getVisibleCategories();
|
|
|
|
$invisibleCats = $categoryMgr->getinvisibleCategories();
|
|
|
|
$categories = array_merge( $visibleCats, $invisibleCats );
|
2016-10-13 08:14:18 +00:00
|
|
|
return [
|
2016-11-22 09:34:50 +00:00
|
|
|
'categories' => [
|
2024-03-14 01:55:06 +00:00
|
|
|
ParamValidator::PARAM_TYPE => $categories,
|
2022-04-03 23:27:56 +00:00
|
|
|
ParamValidator::PARAM_ISMULTI => true,
|
2016-11-22 09:34:50 +00:00
|
|
|
// Default is to show all categories
|
2022-04-03 23:27:56 +00:00
|
|
|
ParamValidator::PARAM_DEFAULT => implode( '|', $visibleCats ),
|
2016-10-13 08:14:18 +00:00
|
|
|
],
|
|
|
|
'limit' => [
|
2022-04-03 23:27:56 +00:00
|
|
|
ParamValidator::PARAM_DEFAULT => 10,
|
|
|
|
ParamValidator::PARAM_TYPE => 'limit',
|
2022-04-03 20:15:33 +00:00
|
|
|
IntegerDef::PARAM_MIN => 1,
|
|
|
|
IntegerDef::PARAM_MAX => ApiBase::LIMIT_BIG1,
|
|
|
|
IntegerDef::PARAM_MAX2 => ApiBase::LIMIT_BIG2
|
2016-10-13 08:14:18 +00:00
|
|
|
],
|
|
|
|
'namespace' => [
|
2022-04-03 23:27:56 +00:00
|
|
|
ParamValidator::PARAM_TYPE => 'namespace',
|
|
|
|
ParamValidator::PARAM_ISMULTI => true,
|
2016-10-13 08:14:18 +00:00
|
|
|
],
|
2017-11-24 14:22:10 +00:00
|
|
|
'pageid' => [
|
2022-04-03 23:27:56 +00:00
|
|
|
ParamValidator::PARAM_TYPE => 'integer',
|
|
|
|
ParamValidator::PARAM_ISMULTI => true,
|
2017-11-24 14:22:10 +00:00
|
|
|
],
|
2020-06-09 18:29:19 +00:00
|
|
|
'title' => [
|
2022-04-03 23:27:56 +00:00
|
|
|
ParamValidator::PARAM_TYPE => 'string',
|
2020-06-09 18:29:19 +00:00
|
|
|
],
|
2016-10-13 08:14:18 +00:00
|
|
|
'from' => [
|
2022-04-03 23:27:56 +00:00
|
|
|
ParamValidator::PARAM_TYPE => 'integer',
|
2016-10-13 08:14:18 +00:00
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-04-06 16:54:41 +00:00
|
|
|
/** @inheritDoc */
|
2016-10-13 08:14:18 +00:00
|
|
|
public function getExamplesMessages() {
|
|
|
|
return [
|
2016-11-22 09:34:50 +00:00
|
|
|
'action=query&list=linterrors&lntcategories=obsolete-tag' =>
|
2016-10-13 08:14:18 +00:00
|
|
|
'apihelp-query+linterrors-example-1',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|