Manual:Hooks/DeleteUnknownPreferences
From Linux Web Expert
DeleteUnknownPreferences | |
---|---|
<translate> Available from <tvar name=1><translate> version <tvar </tvar></translate> Called by the cleanupPreferences.php maintenance script to build a WHERE clause with which to delete preferences that are not known about. | |
<translate> Define function:</translate> | public static function onDeleteUnknownPreferences( array &$where, \Wikimedia\Rdbms\IDatabase $db ) { ... }
|
<translate> Attach hook:</translate> | <translate> In <tvar name=1>extension.json</tvar>:</translate>
{
"Hooks": {
"DeleteUnknownPreferences": "MediaWiki\\Extension\\MyExtension\\Hooks::onDeleteUnknownPreferences"
}
}
|
<translate> Called from:</translate> | <translate> File(s):</translate> ../maintenance/cleanupPreferences.php |
<translate> Interface:</translate> | DeleteUnknownPreferencesHook.php |
<translate> For more information about attaching hooks, see <tvar name=1>Manual:Hooks </tvar>.</translate>
<translate> For examples of extensions using this hook, see <tvar name=cat>Category:DeleteUnknownPreferences extensions</tvar>.</translate>
This hook is 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.
Arguments
&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.
Example
To prevent the deletion of any preference whose name ends in -custom-pref
:
namespace MediaWiki\Extension\MyExtension;
class MyExtensionHooks {
public static function onDeleteUnknownPreferences( &$where, \Wikimedia\Rdbms\IDatabase $db ) {
$where[] = 'up_property NOT ' . $db->buildLike( $db->anyString(), '-custom-pref' );
}
}