Merge "Corrected grammatical error."
[lhc/web/wiklou.git] / maintenance / cleanupPreferences.php
index a21bc73..66fc6d3 100644 (file)
@@ -39,7 +39,7 @@ class CleanupPreferences extends Maintenance {
                $this->addOption( 'dry-run', 'Print debug info instead of actually deleting' );
                $this->addOption( 'hidden', 'Drop hidden preferences ($wgHiddenPrefs)' );
                $this->addOption( 'unknown',
-                       'Drop unknown preferences (not in $wgDefaultUserOptions or a gadget or userjs)' );
+                       'Drop unknown preferences (not in $wgDefaultUserOptions or prefixed with "userjs-")' );
                // TODO: actually implement this
                // $this->addOption( 'bogus', 'Drop preferences that have invalid/unaccepted values' );
        }
@@ -60,7 +60,6 @@ class CleanupPreferences extends Maintenance {
                global $wgHiddenPrefs, $wgDefaultUserOptions;
 
                $dbw = $this->getDB( DB_MASTER );
-               $didWork = false;
                $hidden = $this->hasOption( 'hidden' );
                $unknown = $this->hasOption( 'unknown' );
                $bogus = $this->hasOption( 'bogus' );
@@ -84,18 +83,15 @@ class CleanupPreferences extends Maintenance {
                        }
                }
 
-               // Remove unknown preferences. Special-case gadget- and userjs- as we can't
-               // control those names.
+               // Remove unknown preferences. Special-case '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( '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
@@ -103,9 +99,6 @@ class CleanupPreferences extends Maintenance {
                }
        }
 
-       /**
-        *
-        */
        private function deleteByWhere( $dbw, $startMessage, $where ) {
                $this->output( $startMessage . "...\n" );
                $total = 0;
@@ -121,7 +114,6 @@ class CleanupPreferences extends Maintenance {
                        $numRows = $res->numRows();
                        $total += $numRows;
                        if ( $res->numRows() <= 0 ) {
-                               // All done!
                                $this->output( "DONE! (handled $total entries)\n" );
                                break;
                        }