39 parent::__construct();
40 $this->
addDescription(
'Clean up hidden preferences or removed preferences' );
42 $this->
addOption(
'dry-run',
'Print debug info instead of actually deleting' );
43 $this->
addOption(
'hidden',
'Drop hidden preferences ($wgHiddenPrefs)' );
45 'Drop unknown preferences (not in $wgDefaultUserOptions or prefixed with "userjs-")' );
61 if ( !$hidden && !$unknown ) {
62 $this->
output(
"Did not select one of --hidden, --unknown, exiting\n" );
68 $hiddenPrefs = $this->
getConfig()->get( MainConfigNames::HiddenPrefs );
69 if ( !$hiddenPrefs ) {
70 $this->
output(
"No hidden preferences, skipping\n" );
72 foreach ( $hiddenPrefs as $hiddenPref ) {
75 'Dropping hidden preferences',
76 [
'up_property' => $hiddenPref ]
83 $defaultUserOptions = MediaWikiServices::getInstance()->getUserOptionsLookup()->getDefaultOptions();
85 'up_property NOT' .
$dbr->buildLike(
'userjs-',
$dbr->anyString() ),
86 'up_property NOT IN (' .
$dbr->makeList( array_keys( $defaultUserOptions ) ) .
')',
90 $this->deleteByWhere(
$dbr,
'Dropping unknown preferences', $where );
94 private function deleteByWhere(
$dbr, $startMessage, $where ) {
95 $this->
output( $startMessage .
"...\n" );
101 [
'up_user',
'up_property' ],
105 $iterator->setFetchColumns( [
'up_user',
'up_property',
'up_value' ] );
107 $iterator->setFetchColumns( [
'up_user',
'up_property' ] );
109 $iterator->addConditions( $where );
110 $iterator->setCaller( __METHOD__ );
112 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
115 foreach ( $iterator as $batch ) {
116 $numRows = count( $batch );
119 $this->
output(
"..doing $numRows entries\n" );
123 foreach ( $batch as $row ) {
126 " DRY RUN, would drop: " .
127 "[up_user] => '{$row->up_user}' " .
128 "[up_property] => '{$row->up_property}' " .
129 "[up_value] => '{$row->up_value}'\n"
133 $deleteWhere[$row->up_user][$row->up_property] =
true;
135 if ( $deleteWhere && !$dryRun ) {
138 $dbw->makeWhereFrom2d( $deleteWhere,
'up_user',
'up_property' ),
142 $lbFactory->waitForReplication();
145 $this->
output(
"DONE! (handled $total entries)\n" );
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
getHookRunner()
Get a HookRunner for running core hooks.
hasOption( $name)
Checks to see if a particular option was set.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.