From 6c9a0a2a68561500f96ecdc5862ecb386d67a849 Mon Sep 17 00:00:00 2001 From: Sam Wilson Date: Tue, 3 Apr 2018 11:56:18 +0800 Subject: [PATCH] Add DeleteUnknownPreferences hook This makes it possible for extensions to add to the WHERE clause with which unknown preferences are deleted. Bug: T188966 Change-Id: Ifb22ca42207956f2b07333da026ff0b215a83930 --- docs/hooks.txt | 8 ++++++++ maintenance/cleanupPreferences.php | 17 ++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/docs/hooks.txt b/docs/hooks.txt index 4e8474bfd6..f35d610395 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -1209,6 +1209,14 @@ $row: the DB row for this line Currently only data attributes reserved to MediaWiki are allowed (see Sanitizer::isReservedDataAttribute). +'DeleteUnknownPreferences': Called by the cleanupPreferences.php maintenance script to build a WHERE clause with which +to delete preferences that are not known about. This hook is used by extensions that have dynamically-named preferences +that should not be deleted in the usual cleanup process. For example, the Gadgets extension creates preferences prefixed +with 'gadget-', and so anything with that prefix is excluded from the deletion. +&where: An array that will be passed as the $cond parameter to IDatabase::select() to determine what will be deleted + from the user_properties table. +$db: The IDatabase object, useful for accessing $db->buildLike() etc. + 'DifferenceEngineAfterLoadNewText': called in DifferenceEngine::loadNewText() after the new revision's content has been loaded into the class member variable $differenceEngine->mNewContent but before returning true from this function. diff --git a/maintenance/cleanupPreferences.php b/maintenance/cleanupPreferences.php index a21bc73704..33cc0ca27d 100644 --- a/maintenance/cleanupPreferences.php +++ b/maintenance/cleanupPreferences.php @@ -87,15 +87,14 @@ class CleanupPreferences extends Maintenance { // Remove unknown preferences. Special-case gadget- and userjs- as we can't // control those names. if ( $unknown ) { - $this->deleteByWhere( - $dbw, - 'Dropping unknown preferences', - [ - 'up_property NOT' . $dbw->buildLike( 'gadget-', $dbw->anyString() ), - 'up_property NOT' . $dbw->buildLike( 'userjs-', $dbw->anyString() ), - 'up_property NOT IN (' . $dbw->makeList( array_keys( $wgDefaultUserOptions ) ) . ')', - ] - ); + $where = [ + 'up_property NOT' . $dbw->buildLike( 'gadget-', $dbw->anyString() ), + 'up_property NOT' . $dbw->buildLike( 'userjs-', $dbw->anyString() ), + 'up_property NOT IN (' . $dbw->makeList( array_keys( $wgDefaultUserOptions ) ) . ')', + ]; + // Allow extensions to add to the where clause to prevent deletion of their own prefs. + Hooks::run( 'DeleteUnknownPreferences', [ &$where, $dbw ] ); + $this->deleteByWhere( $dbw, 'Dropping unknown preferences', $where ); } // Something something phase 3 -- 2.20.1