Add support for write both for pagelinks

Bug: T345669
Change-Id: Ia099d092461aa12fc1bfac10c65cf79b391bafca
This commit is contained in:
Amir Sarabadani 2023-09-05 23:27:59 +02:00 committed by James D. Forrester
parent 4889d1d090
commit f405bbb5f2
9 changed files with 81 additions and 2 deletions

View file

@ -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 ====

View file

@ -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] }

View file

@ -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

View file

@ -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

View file

@ -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
/***************************************************************************/

View file

@ -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',

View file

@ -50,7 +50,10 @@ class LinksTableGroup {
'class' => LangLinksTable::class
],
'pagelinks' => [
'class' => PageLinksTable::class
'class' => PageLinksTable::class,
'services' => [
'MainConfig'
],
],
'page_props' => [
'class' => PagePropsTable::class,

View file

@ -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;
}
}

View file

@ -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',
];
/**