- $this->addOption( 'settings', 'Space-separated list of wg* variables', true, true );
- $this->addOption( 'format', 'PHP or JSON', true, true );
- $this->addOption( 'wiki', 'Wiki ID', true, true );
+ $this->addOption( 'regex', 'regex to filter variables with', false, true );
+ $this->addOption( 'iregex', 'same as --regex but case insensitive', false, true );
+ $this->addOption( 'settings', 'Space-separated list of wg* variables', false, true );
+ $this->addOption( 'format', join( ', ', self::$outFormats ), false, true );
+ }
+
+ protected function validateParamsAndArgs() {
+ $error_out = false;
+
+ # Get the format and make sure it is set to a valid default value
+ $format = strtolower( $this->getOption( 'format', 'PHP' ) );
+
+ $validFormat = in_array( $format, self::$outFormats );
+ if( ! $validFormat ) {
+ $this->error("--format set to an unrecognized format", 0);
+ $error_out = true;
+ }
+
+ if( $this->getOption( 'regex' ) && $this->getOption( 'iregex' ) ) {
+ $this->error("Can only use either --regex or --iregex");
+ $error_out = true;
+ }
+
+ parent::validateParamsAndArgs();
+
+ if( $error_out ) {
+ # Force help and quit
+ $this->maybeHelp( true );
+ }
+ }
+
+ /**
+ * finalSetup() since we need MWException
+ */
+ public function finalSetup() {
+ parent::finalSetup();
+
+ $this->regex = $this->getOption( 'regex' ) ? : $this->getOption( 'iregex' );
+ if( $this->regex ) {
+ $this->regex = '/' . $this->regex . '/';
+ if ( $this->hasOption( 'iregex' ) ) {
+ $this->regex .= 'i'; # case insensitive regex
+ }
+ }
+
+ if( $this->hasOption( 'settings' ) ) {
+ $this->settings_list = explode( ' ', $this->getOption( 'settings' ) );
+ # Values validation
+ foreach ( $this->settings_list as $name ) {
+ if ( !preg_match( '/^wg[A-Z]/', $name ) ) {
+ throw new MWException( "Variable '$name' does start with 'wg'." );
+ } elseif ( !isset( $GLOBALS[$name] ) ) {
+ throw new MWException( "Variable '$name' is not set." );
+ } elseif ( !$this->isAllowedVariable( $GLOBALS[$name] ) ) {
+ throw new MWException( "Variable '$name' includes non-array, non-scalar, items." );
+ }
+ }
+ }