2016-11-15 19:31:45 +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 Job;
|
2024-05-22 19:06:50 +00:00
|
|
|
use MediaWiki\Logger\LoggerFactory;
|
2024-04-04 22:10:50 +00:00
|
|
|
use MediaWiki\Page\PageReference;
|
2016-11-15 19:31:45 +00:00
|
|
|
|
|
|
|
class RecordLintJob extends Job {
|
2024-04-05 02:20:45 +00:00
|
|
|
private TotalsLookup $totalsLookup;
|
2024-04-11 01:20:43 +00:00
|
|
|
private Database $database;
|
2024-04-04 22:10:50 +00:00
|
|
|
|
2016-11-15 19:31:45 +00:00
|
|
|
/**
|
|
|
|
* RecordLintJob constructor.
|
2024-04-04 22:10:50 +00:00
|
|
|
* @param PageReference $page
|
2016-11-15 19:31:45 +00:00
|
|
|
* @param array $params
|
2024-04-05 02:20:45 +00:00
|
|
|
* @param TotalsLookup $totalsLookup
|
2024-04-11 01:20:43 +00:00
|
|
|
* @param Database $database
|
2016-11-15 19:31:45 +00:00
|
|
|
*/
|
2024-04-04 22:10:50 +00:00
|
|
|
public function __construct(
|
|
|
|
PageReference $page,
|
|
|
|
array $params,
|
2024-04-05 02:20:45 +00:00
|
|
|
TotalsLookup $totalsLookup,
|
2024-04-11 01:20:43 +00:00
|
|
|
Database $database
|
2024-04-04 22:10:50 +00:00
|
|
|
) {
|
|
|
|
parent::__construct( 'RecordLintJob', $page, $params );
|
2024-04-05 02:20:45 +00:00
|
|
|
$this->totalsLookup = $totalsLookup;
|
2024-04-11 01:20:43 +00:00
|
|
|
$this->database = $database;
|
2016-11-15 19:31:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function run() {
|
2022-01-10 21:22:30 +00:00
|
|
|
if ( $this->title->getLatestRevID() != $this->params['revision'] ) {
|
2016-11-15 19:31:45 +00:00
|
|
|
// Outdated now, let a later job handle it
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-08-18 03:36:06 +00:00
|
|
|
// [ 'id' => LintError ]
|
2016-11-15 19:31:45 +00:00
|
|
|
$errors = [];
|
2016-11-24 03:47:04 +00:00
|
|
|
foreach ( $this->params['errors'] as $errorInfo ) {
|
2022-01-17 18:51:10 +00:00
|
|
|
if ( $errorInfo['type'] === 'inline-media-caption' ) {
|
|
|
|
// Drop lints of this type for now
|
|
|
|
continue;
|
|
|
|
}
|
2016-11-24 03:47:04 +00:00
|
|
|
$error = new LintError(
|
|
|
|
$errorInfo['type'],
|
2016-12-01 02:47:05 +00:00
|
|
|
$errorInfo['location'],
|
2017-12-07 22:30:14 +00:00
|
|
|
$errorInfo['params'],
|
|
|
|
$errorInfo['dbid']
|
2016-11-15 19:31:45 +00:00
|
|
|
);
|
2016-11-24 03:47:04 +00:00
|
|
|
// Use unique id as key to get rid of exact dupes
|
|
|
|
// (e.g. same category of error in same template)
|
2018-08-18 03:36:06 +00:00
|
|
|
$errors[$error->id()] = $error;
|
2016-11-15 19:31:45 +00:00
|
|
|
}
|
2024-04-02 21:12:24 +00:00
|
|
|
|
2024-05-22 19:06:50 +00:00
|
|
|
LoggerFactory::getInstance( 'Linter' )->debug(
|
|
|
|
'{method}: Recording {numErrors} errors for {page}',
|
|
|
|
[
|
|
|
|
'method' => __METHOD__,
|
|
|
|
'numErrors' => count( $errors ),
|
|
|
|
'page' => $this->title->getPrefixedDBkey()
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2024-04-10 20:52:53 +00:00
|
|
|
$this->totalsLookup->updateStats(
|
2024-04-11 01:20:43 +00:00
|
|
|
$this->database->setForPage(
|
2024-04-10 20:52:53 +00:00
|
|
|
$this->title->getArticleID(),
|
|
|
|
$this->title->getNamespace(),
|
|
|
|
$errors
|
|
|
|
)
|
2024-04-04 22:55:43 +00:00
|
|
|
);
|
2016-12-09 00:05:45 +00:00
|
|
|
|
2016-11-15 19:31:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|