diff --git a/extension.json b/extension.json index 422bc4f6..9de449fb 100644 --- a/extension.json +++ b/extension.json @@ -240,12 +240,6 @@ "LinterStatsdSampleFactor": { "value": false }, - "LinterWriteTagAndTemplateColumnsStage": { - "value": false - }, - "LinterUserInterfaceTagAndTemplateStage": { - "value": false - }, "LinterParseOnDerivedDataUpdate": { "value": true } diff --git a/includes/Database.php b/includes/Database.php index acac4c6c..f9f12781 100644 --- a/includes/Database.php +++ b/includes/Database.php @@ -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; } diff --git a/includes/LintErrorsPager.php b/includes/LintErrorsPager.php index 35ea3427..33b728a0 100644 --- a/includes/LintErrorsPager.php +++ b/includes/LintErrorsPager.php @@ -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 ] ); } } diff --git a/includes/SpecialLintErrors.php b/includes/SpecialLintErrors.php index da479097..285538e2 100644 --- a/includes/SpecialLintErrors.php +++ b/includes/SpecialLintErrors.php @@ -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 ); diff --git a/maintenance/migrateTagTemplate.php b/maintenance/migrateTagTemplate.php index 2027de75..5d127ac1 100644 --- a/maintenance/migrateTagTemplate.php +++ b/maintenance/migrateTagTemplate.php @@ -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" diff --git a/tests/phpunit/RecordLintJobTest.php b/tests/phpunit/RecordLintJobTest.php index 310183ee..cd39ff78 100644 --- a/tests/phpunit/RecordLintJobTest.php +++ b/tests/phpunit/RecordLintJobTest.php @@ -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 ); diff --git a/tests/phpunit/SpecialLintErrorsTest.php b/tests/phpunit/SpecialLintErrorsTest.php index 44e0d5a0..e3cdf214 100644 --- a/tests/phpunit/SpecialLintErrorsTest.php +++ b/tests/phpunit/SpecialLintErrorsTest.php @@ -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 );