r83041 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83040‎ | r83041 | r83042 >
Date:20:42, 1 March 2011
Author:hashar
Status:ok
Tags:
Comment:
generic and specific parameters separated in help output

Play with array_diff_key to output Maintenance class parameters separately
from the script specific parameters which are shown below. Will hopefully
make easier to find out in the list of supported parameters.

Example usage with maintenance/attachLatest.php:

$ php maintenance/attachLatest.php --help

Fix page_latest entries in the page table

Usage: php attachLatest.php [--conf|--dbpass|--dbuser|--fix|--globals|--help|--memory-limit|--quiet|--server|--wiki]

Generic maintenance parameters:
--help: Display this help message
--quiet: Whether to supress non-error output
--conf: Location of LocalSettings.php, if not default
--wiki: For specifying the wiki ID
--globals: Output globals at the end of processing for debugging
--memory-limit: Set a specific memory limit for the script, "max"
for no limit or "default" to avoid changing it
--server: The protocol and server name to use in URLs, e.g.
http://en.wikipedia.org. This is sometimes necessary because server name
detection may fail in command line scripts.

Script dependant parameters:
--dbuser: The DB user to use for this script
--dbpass: The password to use for this script

Script specific parameters:
--fix: Actually fix the entries, will dry run otherwise

$

Commit best viewed by ignoring white spaces:
svn diff -x -bu maintenance/Maintenance.php
Modified paths:
  • /trunk/phase3/maintenance/Maintenance.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/Maintenance.php
@@ -96,6 +96,11 @@
9797 // a default with setBatchSize()
9898 protected $mBatchSize = null;
9999
 100+ // Generic options added by addDefaultParams()
 101+ private $mGenericParameters = array();
 102+ // Generic options which might or not be supported by the script
 103+ private $mDependantParameters = array();
 104+
100105 /**
101106 * List of all the core maintenance scripts. This is added
102107 * to scripts added by extensions in $wgMaintenanceScripts
@@ -379,6 +384,9 @@
380385 * Add the default parameters to the scripts
381386 */
382387 protected function addDefaultParams() {
 388+
 389+ # Generic (non script dependant) options:
 390+
383391 $this->addOption( 'help', 'Display this help message' );
384392 $this->addOption( 'quiet', 'Whether to supress non-error output' );
385393 $this->addOption( 'conf', 'Location of LocalSettings.php, if not default', false, true );
@@ -388,6 +396,12 @@
389397 $this->addOption( 'server', "The protocol and server name to use in URLs, e.g. " .
390398 "http://en.wikipedia.org. This is sometimes necessary because " .
391399 "server name detection may fail in command line scripts.", false, true );
 400+
 401+ # Save generic options to display them separately in help
 402+ $this->mGenericParameters = $this->mParams ;
 403+
 404+ # Script dependant options:
 405+
392406 // If we support a DB, show the options
393407 if ( $this->getDbType() > 0 ) {
394408 $this->addOption( 'dbuser', 'The DB user to use for this script', false, true );
@@ -398,6 +412,9 @@
399413 $this->addOption( 'batch-size', 'Run this many operations ' .
400414 'per batch, default: ' . $this->mBatchSize, false, true );
401415 }
 416+ # Save additional script dependant options to display
 417+ # them separately in help
 418+ $this->mDependantParameters = array_diff_key( $this->mParams, $this->mGenericParameters );
402419 }
403420
404421 /**
@@ -693,24 +710,68 @@
694711 }
695712 $this->output( "$output\n\n" );
696713
697 - // Parameters description
698 - foreach ( $this->mParams as $par => $info ) {
 714+ # TODO abstract some repetitive code below
 715+
 716+ // Generic parameters
 717+ $this->output( "Generic maintenance parameters:\n" );
 718+ foreach ( $this->mGenericParameters as $par => $info ) {
699719 $this->output(
700720 wordwrap( "$tab--$par: " . $info['desc'], $descWidth,
701721 "\n$tab$tab" ) . "\n"
702722 );
703723 }
 724+ $this->output( "\n" );
704725
705 - // Arguments description
706 - foreach ( $this->mArgList as $info ) {
707 - $openChar = $info['require'] ? '<' : '[';
708 - $closeChar = $info['require'] ? '>' : ']';
709 - $this->output(
710 - wordwrap( "$tab$openChar" . $info['name'] . "$closeChar: " .
711 - $info['desc'], $descWidth, "\n$tab$tab" ) . "\n"
712 - );
 726+ $scriptDependantParams = $this->mDependantParameters;
 727+ if( count($scriptDependantParams) > 0 ) {
 728+ $this->output( "Script dependant parameters:\n" );
 729+ // Parameters description
 730+ foreach ( $scriptDependantParams as $par => $info ) {
 731+ $this->output(
 732+ wordwrap( "$tab--$par: " . $info['desc'], $descWidth,
 733+ "\n$tab$tab" ) . "\n"
 734+ );
 735+ }
 736+ $this->output( "\n" );
713737 }
714738
 739+
 740+ // Script specific parameters not defined on construction by
 741+ // Maintenance::addDefaultParams()
 742+ $scriptSpecificParams = array_diff_key(
 743+ # all script parameters:
 744+ $this->mParams,
 745+ # remove the Maintenance default parameters:
 746+ $this->mGenericParameters,
 747+ $this->mDependantParameters
 748+ );
 749+ if( count($scriptSpecificParams) > 0 ) {
 750+ $this->output( "Script specific parameters:\n" );
 751+ // Parameters description
 752+ foreach ( $scriptSpecificParams as $par => $info ) {
 753+ $this->output(
 754+ wordwrap( "$tab--$par: " . $info['desc'], $descWidth,
 755+ "\n$tab$tab" ) . "\n"
 756+ );
 757+ }
 758+ $this->output( "\n" );
 759+ }
 760+
 761+ // Print arguments
 762+ if( count( $this->mArgList ) > 0 ) {
 763+ $this->output( "Arguments:\n" );
 764+ // Arguments description
 765+ foreach ( $this->mArgList as $info ) {
 766+ $openChar = $info['require'] ? '<' : '[';
 767+ $closeChar = $info['require'] ? '>' : ']';
 768+ $this->output(
 769+ wordwrap( "$tab$openChar" . $info['name'] . "$closeChar: " .
 770+ $info['desc'], $descWidth, "\n$tab$tab" ) . "\n"
 771+ );
 772+ }
 773+ $this->output( "\n" );
 774+ }
 775+
715776 die( 1 );
716777 }
717778

Status & tagging log