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 FormatJson;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Model to represent a LintError
|
|
|
|
*/
|
|
|
|
class LintError {
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $category;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var int[] [ start, end ]
|
|
|
|
*/
|
|
|
|
public $location;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
public $lintId;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $params;
|
|
|
|
|
|
|
|
/**
|
2022-08-03 18:48:32 +00:00
|
|
|
* @var array|null
|
2016-10-13 08:14:18 +00:00
|
|
|
*/
|
|
|
|
public $templateInfo;
|
|
|
|
|
2022-08-03 18:48:32 +00:00
|
|
|
/**
|
|
|
|
* @var string|null
|
|
|
|
*/
|
|
|
|
public $tagInfo;
|
|
|
|
|
2021-04-06 16:54:41 +00:00
|
|
|
/**
|
2017-12-07 22:30:14 +00:00
|
|
|
* Optional hint for the linter category ID.
|
|
|
|
* Passed through from Parsoid when a new category has been added
|
|
|
|
* that isn't known to PHP yet.
|
|
|
|
* @var int|null
|
|
|
|
*/
|
|
|
|
public $catId;
|
|
|
|
|
2016-10-13 08:14:18 +00:00
|
|
|
/**
|
|
|
|
* @param string $category
|
2016-12-01 02:47:05 +00:00
|
|
|
* @param int[] $location [ start, end ]
|
2016-10-13 08:14:18 +00:00
|
|
|
* @param string|array $params JSON string or already decoded array
|
2017-12-07 22:30:14 +00:00
|
|
|
* @param int|null $catId Optional category ID hint
|
|
|
|
* @param int $lintId Optional linter_id
|
2016-10-13 08:14:18 +00:00
|
|
|
*/
|
2017-12-07 22:30:14 +00:00
|
|
|
public function __construct( $category, $location, $params, $catId = null, $lintId = 0 ) {
|
2016-10-13 08:14:18 +00:00
|
|
|
$this->category = $category;
|
2017-12-07 22:30:14 +00:00
|
|
|
$this->catId = $catId;
|
|
|
|
|
2016-10-13 08:14:18 +00:00
|
|
|
if ( is_string( $params ) ) {
|
|
|
|
$params = FormatJson::decode( $params, true );
|
|
|
|
}
|
|
|
|
$this->params = $params;
|
|
|
|
$this->lintId = $lintId;
|
2016-12-01 02:47:05 +00:00
|
|
|
$this->location = $location;
|
2016-10-13 08:14:18 +00:00
|
|
|
// Convenient accessors for all errors
|
2019-03-11 02:01:24 +00:00
|
|
|
$this->templateInfo = $params['templateInfo'] ?? null;
|
2022-08-03 18:48:32 +00:00
|
|
|
$this->tagInfo = $params['name'] ?? null;
|
2016-10-13 08:14:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unique id to identify this error, for internal
|
|
|
|
* purposes
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function id() {
|
2016-12-03 00:15:17 +00:00
|
|
|
return $this->category . ",{$this->location[0]},{$this->location[1]},"
|
|
|
|
. FormatJson::encode( $this->params );
|
2016-10-13 08:14:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the params that are extra for this error,
|
|
|
|
* not part of the default set
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getExtraParams() {
|
|
|
|
$params = $this->params;
|
|
|
|
unset( $params['templateInfo'] );
|
|
|
|
|
|
|
|
return $params;
|
|
|
|
}
|
|
|
|
}
|