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;
|
|
|
|
|
2017-07-05 19:56:20 +00:00
|
|
|
use ExtensionRegistry;
|
2016-10-13 08:14:18 +00:00
|
|
|
use IContextSource;
|
|
|
|
use InvalidArgumentException;
|
|
|
|
use LinkCache;
|
|
|
|
use Html;
|
|
|
|
use MediaWiki\Linker\LinkRenderer;
|
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
use TablePager;
|
|
|
|
use TitleValue;
|
|
|
|
use Title;
|
|
|
|
|
|
|
|
class LintErrorsPager extends TablePager {
|
|
|
|
|
2017-07-05 19:56:20 +00:00
|
|
|
private $categoryManager;
|
|
|
|
|
2016-10-13 08:14:18 +00:00
|
|
|
private $category;
|
2016-10-29 01:06:08 +00:00
|
|
|
|
|
|
|
private $categoryId;
|
|
|
|
|
2016-10-13 08:14:18 +00:00
|
|
|
/**
|
|
|
|
* @var LinkRenderer
|
|
|
|
*/
|
|
|
|
private $linkRenderer;
|
|
|
|
|
2017-08-22 23:08:50 +00:00
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
private $haveParserMigrationExt;
|
|
|
|
|
2017-04-14 03:49:21 +00:00
|
|
|
/**
|
|
|
|
* @var int|null
|
|
|
|
*/
|
|
|
|
private $namespace;
|
|
|
|
|
2016-12-15 01:07:40 +00:00
|
|
|
public function __construct( IContextSource $context, $category, LinkRenderer $linkRenderer,
|
2017-04-14 03:49:21 +00:00
|
|
|
CategoryManager $catManager, $namespace
|
2016-12-15 01:07:40 +00:00
|
|
|
) {
|
2016-10-13 08:14:18 +00:00
|
|
|
$this->category = $category;
|
2017-07-05 19:56:20 +00:00
|
|
|
$this->categoryManager = $catManager;
|
2016-12-15 01:07:40 +00:00
|
|
|
$this->categoryId = $catManager->getCategoryId( $this->category );
|
2016-10-13 08:14:18 +00:00
|
|
|
$this->linkRenderer = $linkRenderer;
|
2017-04-14 03:49:21 +00:00
|
|
|
$this->namespace = $namespace;
|
2017-07-05 19:56:20 +00:00
|
|
|
$this->haveParserMigrationExt = ExtensionRegistry::getInstance()->isLoaded( 'ParserMigration' );
|
2016-10-13 08:14:18 +00:00
|
|
|
parent::__construct( $context );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getQueryInfo() {
|
2017-04-14 03:49:21 +00:00
|
|
|
$conds = [ 'linter_cat' => $this->categoryId ];
|
|
|
|
if ( $this->namespace !== null ) {
|
|
|
|
$conds['page_namespace'] = $this->namespace;
|
|
|
|
}
|
2016-10-13 08:14:18 +00:00
|
|
|
return [
|
|
|
|
'tables' => [ 'page', 'linter' ],
|
|
|
|
'fields' => array_merge(
|
|
|
|
LinkCache::getSelectFields(),
|
|
|
|
[
|
|
|
|
'page_namespace', 'page_title',
|
|
|
|
'linter_id', 'linter_params',
|
2016-12-01 02:47:05 +00:00
|
|
|
'linter_start', 'linter_end',
|
2016-10-13 08:14:18 +00:00
|
|
|
]
|
|
|
|
),
|
2017-04-14 03:49:21 +00:00
|
|
|
'conds' => $conds,
|
2016-10-13 08:14:18 +00:00
|
|
|
'join_conds' => [ 'page' => [ 'INNER JOIN', 'page_id=linter_page' ] ]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function doBatchLookups() {
|
|
|
|
$linkCache = MediaWikiServices::getInstance()->getLinkCache();
|
|
|
|
foreach ( $this->mResult as $row ) {
|
|
|
|
$titleValue = new TitleValue( (int)$row->page_namespace, $row->page_title );
|
|
|
|
$linkCache->addGoodLinkObjFromRow( $titleValue, $row );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isFieldSortable( $field ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function formatValue( $name, $value ) {
|
|
|
|
$row = $this->mCurrentRow;
|
2016-10-29 01:06:08 +00:00
|
|
|
$row->linter_cat = $this->categoryId;
|
2016-10-13 08:14:18 +00:00
|
|
|
$lintError = Database::makeLintError( $row );
|
2017-10-31 17:42:07 +00:00
|
|
|
if ( !$lintError ) {
|
|
|
|
return '';
|
|
|
|
}
|
2017-07-05 19:56:20 +00:00
|
|
|
if ( $this->haveParserMigrationExt &&
|
2018-05-01 04:00:01 +00:00
|
|
|
$this->categoryManager->needsParserMigrationEdit( $this->category )
|
2017-07-05 19:56:20 +00:00
|
|
|
) {
|
|
|
|
$editAction = 'parsermigration-edit';
|
|
|
|
} else {
|
|
|
|
$editAction = 'edit';
|
|
|
|
}
|
2016-10-13 08:14:18 +00:00
|
|
|
switch ( $name ) {
|
|
|
|
case 'title':
|
|
|
|
$title = Title::makeTitle( $row->page_namespace, $row->page_title );
|
|
|
|
$viewLink = $this->linkRenderer->makeLink( $title );
|
2017-11-25 04:35:15 +00:00
|
|
|
$editMsgKey = $title->quickUserCan( 'edit', $this->getUser() ) ?
|
2017-11-25 04:38:25 +00:00
|
|
|
'linter-page-edit' : 'linter-page-viewsource';
|
2016-10-13 08:14:18 +00:00
|
|
|
$editLink = $this->linkRenderer->makeLink(
|
|
|
|
$title,
|
2017-11-25 04:35:15 +00:00
|
|
|
$this->msg( $editMsgKey )->text(),
|
2016-10-13 08:14:18 +00:00
|
|
|
[],
|
2017-07-05 19:56:20 +00:00
|
|
|
[ 'action' => $editAction, 'lintid' => $lintError->lintId, ]
|
2016-10-13 08:14:18 +00:00
|
|
|
);
|
|
|
|
|
2017-03-22 20:20:26 +00:00
|
|
|
$historyLink = $this->linkRenderer->makeLink(
|
|
|
|
$title,
|
2017-11-25 04:38:25 +00:00
|
|
|
$this->msg( 'linter-page-history' )->text(),
|
2017-03-22 20:20:26 +00:00
|
|
|
[],
|
|
|
|
[ 'action' => 'history' ]
|
|
|
|
);
|
|
|
|
|
|
|
|
$editHistLinks = $this->getLanguage()->pipeList( [ $editLink, $historyLink ] );
|
2017-11-25 04:38:25 +00:00
|
|
|
return $this->msg( 'linter-page-title-edit' )
|
2017-03-22 20:20:26 +00:00
|
|
|
->rawParams( $viewLink, $editHistLinks )
|
|
|
|
->escaped();
|
2016-10-13 08:14:18 +00:00
|
|
|
case 'details':
|
2017-12-07 21:42:13 +00:00
|
|
|
if ( $this->categoryManager->hasNameParam( $this->category ) &&
|
|
|
|
isset( $lintError->params['name'] ) ) {
|
2016-10-13 08:14:18 +00:00
|
|
|
return Html::element( 'code', [], $lintError->params['name'] );
|
|
|
|
} elseif ( $this->category === 'bogus-image-options' && isset( $lintError->params['items'] ) ) {
|
2017-06-20 07:10:41 +00:00
|
|
|
$list = array_map( function ( $in ) {
|
2016-10-13 08:14:18 +00:00
|
|
|
return Html::element( 'code', [], $in );
|
|
|
|
}, $lintError->params['items'] );
|
|
|
|
return $this->getLanguage()->commaList( $list );
|
2017-04-12 21:27:41 +00:00
|
|
|
} elseif ( $this->category === 'pwrap-bug-workaround' &&
|
|
|
|
isset( $lintError->params['root'] ) &&
|
|
|
|
isset( $lintError->params['child'] ) ) {
|
|
|
|
return Html::element( 'code', [],
|
|
|
|
$lintError->params['root'] . " > " . $lintError->params['child'] );
|
2017-08-10 16:20:09 +00:00
|
|
|
} elseif ( $this->category === 'tidy-whitespace-bug' &&
|
|
|
|
isset( $lintError->params['node'] ) &&
|
|
|
|
isset( $lintError->params['sibling'] ) ) {
|
|
|
|
return Html::element( 'code', [],
|
|
|
|
$lintError->params['node'] . " + " . $lintError->params['sibling'] );
|
2017-09-18 18:03:11 +00:00
|
|
|
} elseif ( $this->category === 'multi-colon-escape' &&
|
|
|
|
isset( $lintError->params['href'] ) ) {
|
|
|
|
return Html::element( 'code', [], $lintError->params['href'] );
|
2017-12-07 21:02:21 +00:00
|
|
|
} elseif ( $this->category === 'multiline-html-table-in-list' ) {
|
|
|
|
/* ancestor and name will be set */
|
|
|
|
return Html::element( 'code', [],
|
|
|
|
$lintError->params['ancestorName'] . " > " . $lintError->params['name'] );
|
|
|
|
} elseif ( $this->category === 'misc-tidy-replacement-issues' ) {
|
|
|
|
/* There will be a 'subtype' param to disambiguate */
|
|
|
|
return Html::element( 'code', [], $lintError->params['subtype'] );
|
2016-10-13 08:14:18 +00:00
|
|
|
}
|
|
|
|
return '';
|
|
|
|
case 'template':
|
|
|
|
if ( !$lintError->templateInfo ) {
|
|
|
|
return '—';
|
|
|
|
}
|
2017-05-08 21:45:21 +00:00
|
|
|
|
|
|
|
if ( isset( $lintError->templateInfo['multiPartTemplateBlock'] ) ) {
|
|
|
|
return $this->msg( 'multi-part-template-block' )->escaped();
|
|
|
|
} else {
|
|
|
|
$templateName = $lintError->templateInfo['name'];
|
2017-07-05 20:15:48 +00:00
|
|
|
// Parsoid provides us with fully qualified template title
|
|
|
|
// So, fallback to the default main namespace
|
|
|
|
$templateTitle = Title::newFromText( $templateName );
|
2017-05-08 21:45:21 +00:00
|
|
|
if ( !$templateTitle ) {
|
|
|
|
// Shouldn't be possible...???
|
|
|
|
return '—';
|
|
|
|
}
|
2016-10-13 08:14:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->linkRenderer->makeLink(
|
|
|
|
$templateTitle
|
|
|
|
);
|
|
|
|
default:
|
|
|
|
throw new InvalidArgumentException( "Unexpected name: $name" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDefaultSort() {
|
|
|
|
return 'linter_id';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFieldNames() {
|
|
|
|
$names = [
|
2016-11-22 09:18:29 +00:00
|
|
|
'title' => $this->msg( 'linter-pager-title' )->text(),
|
2016-10-13 08:14:18 +00:00
|
|
|
];
|
|
|
|
if ( $this->category !== 'fostered' ) {
|
|
|
|
// TODO: don't hardcode list of stuff with no parameters...?
|
2016-11-22 09:18:29 +00:00
|
|
|
$names['details'] = $this->msg( "linter-pager-{$this->category}-details" )->text();
|
2016-10-13 08:14:18 +00:00
|
|
|
}
|
2016-11-22 09:18:29 +00:00
|
|
|
$names['template'] = $this->msg( "linter-pager-template" )->text();
|
2016-10-13 08:14:18 +00:00
|
|
|
return $names;
|
|
|
|
}
|
|
|
|
}
|