r85558 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85557‎ | r85558 | r85559 >
Date:18:38, 6 April 2011
Author:ialex
Status:ok (Comments)
Tags:
Comment:
And I forgot to commit this file in r85557
Modified paths:
  • /trunk/phase3/maintenance/Maintenance.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/Maintenance.php
@@ -70,6 +70,9 @@
7171 // This is the desired params
7272 protected $mParams = array();
7373
 74+ // Array of mapping short parameters to long ones
 75+ protected $mShortParamsMap = array();
 76+
7477 // Array of desired args
7578 protected $mArgList = array();
7679
@@ -157,9 +160,13 @@
158161 * @param $description String: the description of the param to show on --help
159162 * @param $required Boolean: is the param required?
160163 * @param $withArg Boolean: is an argument required with this option?
 164+ * @param $shortName String: character to use as short name
161165 */
162 - protected function addOption( $name, $description, $required = false, $withArg = false ) {
163 - $this->mParams[$name] = array( 'desc' => $description, 'require' => $required, 'withArg' => $withArg );
 166+ protected function addOption( $name, $description, $required = false, $withArg = false, $shortName = false ) {
 167+ $this->mParams[$name] = array( 'desc' => $description, 'require' => $required, 'withArg' => $withArg, 'shortName' => $shortName );
 168+ if ( $shortName !== false ) {
 169+ $this->mShortParamsMap[$shortName] = $name;
 170+ }
164171 }
165172
166173 /**
@@ -391,8 +398,8 @@
392399
393400 # Generic (non script dependant) options:
394401
395 - $this->addOption( 'help', 'Display this help message' );
396 - $this->addOption( 'quiet', 'Whether to supress non-error output' );
 402+ $this->addOption( 'help', 'Display this help message', false, false, 'h' );
 403+ $this->addOption( 'quiet', 'Whether to supress non-error output', false, false, 'q' );
397404 $this->addOption( 'conf', 'Location of LocalSettings.php, if not default', false, true );
398405 $this->addOption( 'wiki', 'For specifying the wiki ID', false, true );
399406 $this->addOption( 'globals', 'Output globals at the end of processing for debugging' );
@@ -607,6 +614,9 @@
608615 # Short options
609616 for ( $p = 1; $p < strlen( $arg ); $p++ ) {
610617 $option = $arg { $p } ;
 618+ if ( !isset( $this->mParams[$option] ) && isset( $this->mShortParamsMap[$option] ) ) {
 619+ $option = $this->mShortParamsMap[$option];
 620+ }
611621 if ( isset( $this->mParams[$option]['withArg'] ) && $this->mParams[$option]['withArg'] ) {
612622 $param = next( $argv );
613623 if ( $param === false ) {
@@ -719,6 +729,9 @@
720730 // Generic parameters
721731 $this->output( "Generic maintenance parameters:\n" );
722732 foreach ( $this->mGenericParameters as $par => $info ) {
 733+ if ( $info['shortName'] !== false ) {
 734+ $par .= " (-{$info['shortName']})";
 735+ }
723736 $this->output(
724737 wordwrap( "$tab--$par: " . $info['desc'], $descWidth,
725738 "\n$tab$tab" ) . "\n"
@@ -731,6 +744,9 @@
732745 $this->output( "Script dependant parameters:\n" );
733746 // Parameters description
734747 foreach ( $scriptDependantParams as $par => $info ) {
 748+ if ( $info['shortName'] !== false ) {
 749+ $par .= " (-{$info['shortName']})";
 750+ }
735751 $this->output(
736752 wordwrap( "$tab--$par: " . $info['desc'], $descWidth,
737753 "\n$tab$tab" ) . "\n"
@@ -753,6 +769,9 @@
754770 $this->output( "Script specific parameters:\n" );
755771 // Parameters description
756772 foreach ( $scriptSpecificParams as $par => $info ) {
 773+ if ( $info['shortName'] !== false ) {
 774+ $par .= " (-{$info['shortName']})";
 775+ }
757776 $this->output(
758777 wordwrap( "$tab--$par: " . $info['desc'], $descWidth,
759778 "\n$tab$tab" ) . "\n"

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r85557* Added possibility to set short options aliases to long long options, added ...ialex18:37, 6 April 2011

Comments

#Comment by Ntx666 (talk | contribs)   18:32, 9 April 2011

Hi!

This results in a segfault when i call "php-cgi update.php" in /maintenance/ directory, whereas r85557 is the last one that works for me.

strace of it: http://foobar.nerdbase.de/wiki-strace-110409.txt

I´m using debian´s php-cgi 5.3.6-7

Thank you! nitrox (nick on freenode)

#Comment by Nikerabbit (talk | contribs)   06:33, 10 April 2011

Why are you using php-cgi? cgi is not meant for command line scripts.

#Comment by Ntx666 (talk | contribs)   12:26, 10 April 2011

So far i never needed cli and update.php worked pretty well with cgi for a couple of years now, i could try if you think cli works.

i´d like to see cgi working again tho.

#Comment by Ntx666 (talk | contribs)   12:29, 10 April 2011

Indeed, php cli works.

Status & tagging log