Remove linter tag and template dual mode config and code

* Removed the write and user interface config variables and
  fixed the tests affected by their removal.

Bug: T331883
Change-Id: If44ceedae7278f498158b8cdd528dfa32be609eb
This commit is contained in:
sbailey 2024-06-04 14:31:37 -07:00 committed by Arlo Breault
parent 72653441b2
commit 0dfaa5523e
7 changed files with 68 additions and 84 deletions

View file

@ -240,12 +240,6 @@
"LinterStatsdSampleFactor": {
"value": false
},
"LinterWriteTagAndTemplateColumnsStage": {
"value": false
},
"LinterUserInterfaceTagAndTemplateStage": {
"value": false
},
"LinterParseOnDerivedDataUpdate": {
"value": true
}

View file

@ -33,9 +33,7 @@ use Wikimedia\Rdbms\SelectQueryBuilder;
* Database logic
*/
class Database {
public const CONSTRUCTOR_OPTIONS = [
'LinterWriteTagAndTemplateColumnsStage',
];
public const CONSTRUCTOR_OPTIONS = [];
/**
* Maximum number of errors to save per category,
@ -179,23 +177,20 @@ class Database {
'linter_namespace' => $namespaceId
];
// To enable 720130
if ( $this->options->get( 'LinterWriteTagAndTemplateColumnsStage' ) ) {
$templateInfo = $error->templateInfo ?? '';
if ( is_array( $templateInfo ) ) {
if ( isset( $templateInfo[ 'multiPartTemplateBlock' ] ) ) {
$templateInfo = 'multi-part-template-block';
} else {
$templateInfo = $templateInfo[ 'name' ] ?? '';
}
$templateInfo = $error->templateInfo ?? '';
if ( is_array( $templateInfo ) ) {
if ( isset( $templateInfo[ 'multiPartTemplateBlock' ] ) ) {
$templateInfo = 'multi-part-template-block';
} else {
$templateInfo = $templateInfo[ 'name' ] ?? '';
}
$templateInfo = mb_strcut( $templateInfo, 0, self::MAX_TEMPLATE_LENGTH );
$result[ 'linter_template' ] = $templateInfo;
$tagInfo = $error->tagInfo ?? '';
$tagInfo = mb_strcut( $tagInfo, 0, self::MAX_TAG_LENGTH );
$result[ 'linter_tag' ] = $tagInfo;
}
$templateInfo = mb_strcut( $templateInfo, 0, self::MAX_TEMPLATE_LENGTH );
$result[ 'linter_template' ] = $templateInfo;
$tagInfo = $error->tagInfo ?? '';
$tagInfo = mb_strcut( $tagInfo, 0, self::MAX_TAG_LENGTH );
$result[ 'linter_tag' ] = $tagInfo;
return $result;
}
@ -486,18 +481,11 @@ class Database {
*
* @param int $batchSize
* @param int $sleep
* @param bool $bypassConfig
* @return int
*/
public function migrateTemplateAndTagInfo(
int $batchSize, int $sleep, bool $bypassConfig = false
int $batchSize, int $sleep
): int {
// code used by phpunit test, bypassed when run as a maintenance script
if ( !$bypassConfig ) {
if ( !$this->options->get( 'LinterWriteTagAndTemplateColumnsStage' ) ) {
return 0;
}
}
if ( gettype( $sleep ) !== 'integer' || $sleep < 0 ) {
$sleep = 0;
}

View file

@ -136,14 +136,12 @@ class LintErrorsPager extends TablePager {
$queryBuilder->where( [ 'linter_namespace' => $this->namespaces ] );
}
if ( $mainConfig->get( 'LinterUserInterfaceTagAndTemplateStage' ) ) {
if ( $this->throughTemplate !== 'all' ) {
$op = ( $this->throughTemplate === 'with' ) ? '!=' : '=';
$queryBuilder->where( $this->mDb->expr( 'linter_template', $op, '' ) );
}
if ( $this->tag !== 'all' && ( new HtmlTags( $this ) )->checkAllowedHTMLTags( $this->tag ) ) {
$queryBuilder->where( [ 'linter_tag' => $this->tag ] );
}
if ( $this->throughTemplate !== 'all' ) {
$op = ( $this->throughTemplate === 'with' ) ? '!=' : '=';
$queryBuilder->where( $this->mDb->expr( 'linter_template', $op, '' ) );
}
if ( $this->tag !== 'all' && ( new HtmlTags( $this ) )->checkAllowedHTMLTags( $this->tag ) ) {
$queryBuilder->where( [ 'linter_tag' => $this->tag ] );
}
}

View file

@ -104,31 +104,27 @@ class SpecialLintErrors extends SpecialPage {
]
];
$enableUserInterfaceTagAndTemplateStage =
$this->getConfig()->get( 'LinterUserInterfaceTagAndTemplateStage' );
if ( $enableUserInterfaceTagAndTemplateStage ) {
$selectTemplateOptions = [
(string)$this->msg( 'linter-form-template-option-all' )->escaped() => 'all',
(string)$this->msg( 'linter-form-template-option-with' )->escaped() => 'with',
(string)$this->msg( 'linter-form-template-option-without' )->escaped() => 'without',
];
$htmlTags = new HtmlTags( $this );
$tagAndTemplateFields = [
'tag' => [
'type' => 'select',
'name' => 'tag',
'label-message' => 'linter-form-tag',
'options' => $htmlTags->getAllowedHTMLTags()
],
'template' => [
'type' => 'select',
'name' => 'template',
'label-message' => 'linter-form-template',
'options' => $selectTemplateOptions
]
];
$fields = array_merge( $fields, $tagAndTemplateFields );
}
$selectTemplateOptions = [
(string)$this->msg( 'linter-form-template-option-all' )->escaped() => 'all',
(string)$this->msg( 'linter-form-template-option-with' )->escaped() => 'with',
(string)$this->msg( 'linter-form-template-option-without' )->escaped() => 'without',
];
$htmlTags = new HtmlTags( $this );
$tagAndTemplateFields = [
'tag' => [
'type' => 'select',
'name' => 'tag',
'label-message' => 'linter-form-tag',
'options' => $htmlTags->getAllowedHTMLTags()
],
'template' => [
'type' => 'select',
'name' => 'template',
'label-message' => 'linter-form-template',
'options' => $selectTemplateOptions
]
];
$fields = array_merge( $fields, $tagAndTemplateFields );
$form = HTMLForm::factory( 'ooui', $fields, $this->getContext() );
$form->setWrapperLegend( true );

View file

@ -2,8 +2,9 @@
/**
* Maintenance script that migrates the linter_params field value to the new tag and template fields
* note: This should be run once the tag and template write functionality in linter
* recordLintJob has been enabled by setting LinterWriteTagAndTemplateColumnsStage true.
* Note: The schema migration "patch-linter-add-template-tag-fields.json" is expected to have been done.
* The extension now populates these new fields by default. This script will migrate any data
* in existing records to the new fields.
*/
$IP = getenv( 'MW_INSTALL_PATH' );
@ -37,13 +38,6 @@ class MigrateTagTemplate extends LoggedUpdateMaintenance {
* @inheritDoc
*/
protected function doDBUpdates() {
$config = $this->getConfig();
$enableMigrateTagAndTemplateStage = $config->get( 'LinterWriteTagAndTemplateColumnsStage' );
if ( !$enableMigrateTagAndTemplateStage ) {
$this->output( "LinterWriteTagAndTemplateColumnsStage config value is false, code disabled\n" );
return false;
}
$this->output( "Running linter migrate linter_params to tag and template function, this may take a while\n" );
$batchSize = $this->getBatchSize();
@ -58,7 +52,7 @@ class MigrateTagTemplate extends LoggedUpdateMaintenance {
$this->output( "Migrating the linter_params field to the linter_tag and linter_template fields...\n" );
$database = $this->getServiceContainer()->get( 'Linter.Database' );
$updated = $database->migrateTemplateAndTagInfo( $batchSize, $sleep, false );
$updated = $database->migrateTemplateAndTagInfo( $batchSize, $sleep );
$this->output(
"Completed migration of linter_params data in the linter table, $updated rows updated.\n"

View file

@ -150,7 +150,6 @@ class RecordLintJobTest extends MediaWikiIntegrationTestCase {
}
public function testWriteTagAndTemplate() {
$this->overrideConfigValue( 'LinterWriteTagAndTemplateColumnsStage', true );
$error = [
'type' => 'obsolete-tag',
'location' => [ 0, 10 ],
@ -181,8 +180,6 @@ class RecordLintJobTest extends MediaWikiIntegrationTestCase {
}
public function testWriteTagAndTemplateLengthExceeded() {
$this->overrideConfigValue( 'LinterWriteTagAndTemplateColumnsStage', true );
// Verify special case test for write code encountering params with tag and template string lengths exceeded
$tagWithMoreThan30Characters = "center tag exceeding 30 characters";
$tagTruncated = "center tag exceeding 30 charac";
@ -310,6 +307,22 @@ class RecordLintJobTest extends MediaWikiIntegrationTestCase {
return $titleAndPage;
}
/**
* Set the linter_tag and linter_template field values to an empty string for a page
* to test that the database migration code handles existing records with fields set
* and records where the fields are not yet set, and need migration.
* @param int $pageId
*/
private function setTagAndTemplateForPageToEmptyString( int $pageId ) {
$queryLinterPageNamespace = new UpdateQueryBuilder( $this->db );
$queryLinterPageNamespace
->update( 'linter' )
->set( [ 'linter_template' => '', 'linter_tag' => '' ] )
->where( [ 'linter_page' => $pageId ] )
->caller( __METHOD__ )
->execute();
}
/**
* @param array $writeEnables
* @param array $error
@ -318,9 +331,12 @@ class RecordLintJobTest extends MediaWikiIntegrationTestCase {
private function createPagesWithTagAndTemplate( array $writeEnables, array $error ): array {
$titleAndPages = [];
foreach ( $writeEnables as $index => $enable ) {
// enable/disable writing the tag and template fields in the linter table during page creation
$this->overrideConfigValue( 'LinterWriteTagAndTemplateColumnsStage', $enable );
$titleAndPages[] = $this->createTitleAndPageForTagsAndRunJob( 'TestPage' . $index, $error );
$titleAndPage = $this->createTitleAndPageForTagsAndRunJob( 'TestPage' . $index, $error );
$titleAndPages[] = $titleAndPage;
// clear the tag and template field data for select test records
if ( !$enable ) {
$this->setTagAndTemplateForPageToEmptyString( $titleAndPage[ 'pageID' ] );
}
}
return $titleAndPages;
}
@ -353,7 +369,6 @@ class RecordLintJobTest extends MediaWikiIntegrationTestCase {
$titleAndPages = $this->createPagesWithTagAndTemplate( $writeEnables, $error );
// Create special case test of migrate code encountering brackets - linter_params = '[]'
$this->overrideConfigValue( 'LinterWriteTagAndTemplateColumnsStage', false );
$error = [
'type' => 'wikilink-in-extlink',
'location' => [ 0, 10 ],
@ -398,7 +413,7 @@ class RecordLintJobTest extends MediaWikiIntegrationTestCase {
// Migrate unpopulated tag and template info from the params field
$database = $this->getDatabase();
$database->migrateTemplateAndTagInfo( 3, 0, true );
$database->migrateTemplateAndTagInfo( 3, 0 );
// Verify all linter records have the proper tag and template field info migrated from the params field
$this->checkPagesTagAndTemplate( $titleAndPages );

View file

@ -77,7 +77,6 @@ class SpecialLintErrorsTest extends SpecialPageTestBase {
$this->executeSpecialPage( $category, null, 'qqx' )[0]
);
$this->overrideConfigValue( 'LinterUserInterfaceTagAndTemplateStage', true );
// Verify new tag and template interfaces are present
$html = $this->executeSpecialPage( 'misnested-tag', null, 'qqx' )[0];
$this->assertStringContainsString( 'linter-form-template', $html );