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__ );
114 foreach ( $iterator as $batch ) {
115 $numRows = count( $batch );
118 $this->
output(
"..doing $numRows entries\n" );
122 foreach ( $batch as $row ) {
125 " DRY RUN, would drop: " .
126 "[up_user] => '{$row->up_user}' " .
127 "[up_property] => '{$row->up_property}' " .
128 "[up_value] => '{$row->up_value}'\n"
132 $deleteWhere[$row->up_user][$row->up_property] =
true;
134 if ( $deleteWhere && !$dryRun ) {
137 $dbw->makeWhereFrom2d( $deleteWhere,
'up_user',
'up_property' ),
144 $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.
waitForReplication()
Wait for replica DBs to catch up.
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.