* use the $option system
authorAntoine Musso <hashar@users.mediawiki.org>
Thu, 5 Jan 2006 23:16:11 +0000 (23:16 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Thu, 5 Jan 2006 23:16:11 +0000 (23:16 +0000)
* add '--help' (and die after showing the message)
* clean up parameter handling a bit

maintenance/removeUnusedAccounts.php

index 038875f..a3a8938 100644 (file)
@@ -8,22 +8,33 @@
  * @subpackage Maintenance
  * @author Rob Church <robchur@gmail.com>
  */
+
+# Options available
+$options = array( 'delete','help' );
  
 require_once( 'commandLine.inc' );
 require_once( 'removeUnusedAccounts.inc' );
-echo( "REMOVE UNUSED ACCOUNTS\nThis script will delete all users who have made no edits.\n\n" );
-echo( "Syntax: removeUnusedAccounts.php [delete]\n     * delete -> delete the accounts\n       * The first user (usually the site owner) is left alone\n\n" );
+
+# Default action (just report):
+$action = ACTION_REPORT;
 
 # Handle parameters
-if( isset( $args[0] ) ) {
-       $param = array_shift( $args );
-       if( $param == 'delete' ) {
-               $action = ACTION_DELETE;
-       } else {
-               $action = ACTION_REPORT;
-       }
-} else {
-       $action = ACTION_REPORT;
+if(@$options['help']) {
+echo <<<END
+This script will delete all users who have made no edits.
+
+usage:removeUnusedAccounts.php [--help|--delete]
+  --delete : delete the unused accounts
+  --help   : this help message
+
+NB: The first user (usually the site owner) is left alone
+
+END;
+die;
+}
+
+if(@$options['delete']) {
+       $action = ACTION_DELETE;
 }
 
 $count = 0;
@@ -45,11 +56,13 @@ foreach( $users as $user ) {
 echo( "done.\n" );
 
 # Purge the inactive accounts we found
-echo( $count . " inactive accounts found." );
+echo( $count . " inactive accounts found.\n" );
 if( ( $action == ACTION_DELETE ) && ( $count > 0 ) ) {
        echo( " Deleting..." );
        DeleteUsers( $del );
        echo( "done.\n" );
+} else {
+       echo "\nYou can delete them by using the '--delete' switch (see help).\n";
 }
 
-?>
\ No newline at end of file
+?>