From f405bbb5f21bbeab144c568caaf7fed67b024fa8 Mon Sep 17 00:00:00 2001 From: Amir Sarabadani Date: Tue, 5 Sep 2023 23:27:59 +0200 Subject: [PATCH] Add support for write both for pagelinks Bug: T345669 Change-Id: Ia099d092461aa12fc1bfac10c65cf79b391bafca --- RELEASE-NOTES-1.41 | 2 ++ docs/config-schema.yaml | 10 ++++++++ docs/config-vars.php | 6 +++++ includes/MainConfigNames.php | 6 +++++ includes/MainConfigSchema.php | 16 ++++++++++++ includes/config-schema.php | 2 ++ .../deferred/LinksUpdate/LinksTableGroup.php | 5 +++- .../deferred/LinksUpdate/PageLinksTable.php | 25 +++++++++++++++++++ includes/linker/LinksMigration.php | 11 +++++++- 9 files changed, 81 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES-1.41 b/RELEASE-NOTES-1.41 index c8cdd3d4f0f..cce1e6ab3c4 100644 --- a/RELEASE-NOTES-1.41 +++ b/RELEASE-NOTES-1.41 @@ -27,6 +27,8 @@ For notes on 1.40.x and older releases, see HISTORY. ==== New configuration ==== * $wgPrivilegedGroups – Users belonging in some of the listed groups will be audited more aggressively. +* $wgPageLinksSchemaMigrationStage – This temporary flag lets you control the + migration stage for converting the pagelinks database table into normal form. * … ==== Changed configuration ==== diff --git a/docs/config-schema.yaml b/docs/config-schema.yaml index 2049d283bc7..a6a7b7a1d34 100755 --- a/docs/config-schema.yaml +++ b/docs/config-schema.yaml @@ -1984,6 +1984,16 @@ config-schema: - 1.38: Added - 1.39: Default has changed to SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD and support for SCHEMA_COMPAT_OLD is dropped. + PageLinksSchemaMigrationStage: + default: 3 + type: integer + description: |- + Pagelinks table schema migration stage, for normalizing pl_namespace and pl_title fields. + Use the SCHEMA_COMPAT_XXX flags. Supported values: + - SCHEMA_COMPAT_WRITE_OLD | SCHEMA_COMPAT_READ_OLD + - SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD + History: + - 1.41: Added ContentHandlers: default: wikitext: { class: WikitextContentHandler, services: [TitleFactory, ParserFactory, GlobalIdGenerator, LanguageNameUtils, MagicWordFactory, ParsoidParserFactory] } diff --git a/docs/config-vars.php b/docs/config-vars.php index 161e22d32a5..a0b31b83638 100755 --- a/docs/config-vars.php +++ b/docs/config-vars.php @@ -1229,6 +1229,12 @@ $wgMaxExecutionTimeForExpensiveQueries = null; */ $wgTemplateLinksSchemaMigrationStage = null; +/** + * Config variable stub for the PageLinksSchemaMigrationStage setting, for use by phpdoc and IDEs. + * @see MediaWiki\MainConfigSchema::PageLinksSchemaMigrationStage + */ +$wgPageLinksSchemaMigrationStage = null; + /** * Config variable stub for the ContentHandlers setting, for use by phpdoc and IDEs. * @see MediaWiki\MainConfigSchema::ContentHandlers diff --git a/includes/MainConfigNames.php b/includes/MainConfigNames.php index 7e9fe977472..cce861c2a83 100755 --- a/includes/MainConfigNames.php +++ b/includes/MainConfigNames.php @@ -1244,6 +1244,12 @@ class MainConfigNames { */ public const TemplateLinksSchemaMigrationStage = 'TemplateLinksSchemaMigrationStage'; + /** + * Name constant for the PageLinksSchemaMigrationStage setting, for use with Config::get() + * @see MainConfigSchema::PageLinksSchemaMigrationStage + */ + public const PageLinksSchemaMigrationStage = 'PageLinksSchemaMigrationStage'; + /** * Name constant for the ContentHandlers setting, for use with Config::get() * @see MainConfigSchema::ContentHandlers diff --git a/includes/MainConfigSchema.php b/includes/MainConfigSchema.php index dfdd5d232cc..45c2c3eb0eb 100644 --- a/includes/MainConfigSchema.php +++ b/includes/MainConfigSchema.php @@ -3243,6 +3243,22 @@ class MainConfigSchema { 'type' => 'integer', ]; + /** + * Pagelinks table schema migration stage, for normalizing pl_namespace and pl_title fields. + * + * Use the SCHEMA_COMPAT_XXX flags. Supported values: + * + * - SCHEMA_COMPAT_WRITE_OLD | SCHEMA_COMPAT_READ_OLD + * - SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD + * + * History: + * - 1.41: Added + */ + public const PageLinksSchemaMigrationStage = [ + 'default' => SCHEMA_COMPAT_WRITE_OLD | SCHEMA_COMPAT_READ_OLD, + 'type' => 'integer', + ]; + // endregion -- End of DB settings /***************************************************************************/ diff --git a/includes/config-schema.php b/includes/config-schema.php index 1c3fc3aa577..c7eed1ffe1f 100755 --- a/includes/config-schema.php +++ b/includes/config-schema.php @@ -385,6 +385,7 @@ return [ 'DatabaseReplicaLagCritical' => 30, 'MaxExecutionTimeForExpensiveQueries' => 0, 'TemplateLinksSchemaMigrationStage' => 768, + 'PageLinksSchemaMigrationStage' => 3, 'ContentHandlers' => [ 'wikitext' => [ 'class' => 'WikitextContentHandler', @@ -2608,6 +2609,7 @@ return [ 'LBFactoryConf' => 'object', 'LocalDatabases' => 'array', 'TemplateLinksSchemaMigrationStage' => 'integer', + 'PageLinksSchemaMigrationStage' => 'integer', 'ContentHandlers' => 'object', 'NamespaceContentModels' => 'object', 'TextModelsToParse' => 'array', diff --git a/includes/deferred/LinksUpdate/LinksTableGroup.php b/includes/deferred/LinksUpdate/LinksTableGroup.php index 61f8e83a373..695d17cd2e4 100644 --- a/includes/deferred/LinksUpdate/LinksTableGroup.php +++ b/includes/deferred/LinksUpdate/LinksTableGroup.php @@ -50,7 +50,10 @@ class LinksTableGroup { 'class' => LangLinksTable::class ], 'pagelinks' => [ - 'class' => PageLinksTable::class + 'class' => PageLinksTable::class, + 'services' => [ + 'MainConfig' + ], ], 'page_props' => [ 'class' => PagePropsTable::class, diff --git a/includes/deferred/LinksUpdate/PageLinksTable.php b/includes/deferred/LinksUpdate/PageLinksTable.php index 15bd18fc72b..1951b8f6a31 100644 --- a/includes/deferred/LinksUpdate/PageLinksTable.php +++ b/includes/deferred/LinksUpdate/PageLinksTable.php @@ -2,12 +2,29 @@ namespace MediaWiki\Deferred\LinksUpdate; +use Config; +use MediaWiki\Config\ServiceOptions; +use MediaWiki\MainConfigNames; use ParserOutput; /** * pagelinks */ class PageLinksTable extends GenericPageLinksTable { + private const CONSTRUCTOR_OPTIONS = [ + MainConfigNames::PageLinksSchemaMigrationStage, + ]; + + /** @var int */ + private $migrationStage; + + public function __construct( Config $config ) { + $options = new ServiceOptions( self::CONSTRUCTOR_OPTIONS, $config ); + $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS ); + + $this->migrationStage = $options->get( MainConfigNames::PageLinksSchemaMigrationStage ); + } + public function setParserOutput( ParserOutput $parserOutput ) { $this->newLinks = $parserOutput->getLinks(); } @@ -35,4 +52,12 @@ class PageLinksTable extends GenericPageLinksTable { protected function getTargetIdField() { return 'pl_target_id'; } + + /** + * Normalization stage of the links table (see T222224) + * @return int + */ + protected function linksTargetNormalizationStage(): int { + return $this->migrationStage; + } } diff --git a/includes/linker/LinksMigration.php b/includes/linker/LinksMigration.php index 0f30e2db5f5..b14166dac3d 100644 --- a/includes/linker/LinksMigration.php +++ b/includes/linker/LinksMigration.php @@ -46,10 +46,19 @@ class LinksMigration { 'target_id' => 'tl_target_id', 'deprecated_configs' => [ SCHEMA_COMPAT_OLD ], ], + 'pagelinks' => [ + 'config' => MainConfigNames::PageLinksSchemaMigrationStage, + 'page_id' => 'pl_from', + 'ns' => 'pl_namespace', + 'title' => 'pl_title', + 'target_id' => 'pl_target_id', + 'deprecated_configs' => [], + ], ]; public static $prefixToTableMapping = [ - 'tl' => 'templatelinks' + 'tl' => 'templatelinks', + 'pl' => 'pagelinks', ]; /**