- $sinks = array();
- foreach ( $args as $arg ) {
- $matches = array();
- if ( preg_match( '/^--(.+?)(?:=(.+?)(?::(.+?))?)?$/', $arg, $matches ) ) {
- MediaWiki\suppressWarnings();
- list( /* $full */, $opt, $val, $param ) = $matches;
- MediaWiki\restoreWarnings();
-
- switch ( $opt ) {
- case "plugin":
- $this->loadPlugin( $val, $param );
- break;
- case "output":
- if ( !is_null( $sink ) ) {
- $sinks[] = $sink;
- }
- if ( !isset( $this->outputTypes[$val] ) ) {
- $this->fatalError( "Unrecognized output sink type '$val'" );
- }
- $type = $this->outputTypes[$val];
- $sink = new $type( $param );
- break;
- case "filter":
- if ( is_null( $sink ) ) {
- $sink = new DumpOutput();
- }
- if ( !isset( $this->filterTypes[$val] ) ) {
- $this->fatalError( "Unrecognized filter type '$val'" );
- }
- $type = $this->filterTypes[$val];
- $filter = new $type( $sink, $param );
-
- // references are lame in php...
- unset( $sink );
- $sink = $filter;
-
- break;
- case "report":
- $this->reportingInterval = intval( $val );
- break;
- case "server":
- $this->server = $val;
- break;
- case "force-normal":
- if ( !function_exists( 'utf8_normalize' ) ) {
- $this->fatalError( "UTF-8 normalization extension not loaded. " .
- "Install or remove --force-normal parameter to use slower code." );
- }
- break;
- default:
- $this->processOption( $opt, $val, $param );
- }
+ $sinks = [];
+
+ $options = $this->orderedOptions;
+ foreach ( $options as $arg ) {
+ $opt = $arg[0];
+ $param = $arg[1];
+
+ switch ( $opt ) {
+ case 'plugin':
+ $val = explode( ':', $param );
+
+ if ( count( $val ) === 1 ) {
+ $this->loadPlugin( $val[0] );
+ } elseif ( count( $val ) === 2 ) {
+ $this->loadPlugin( $val[0], $val[1] );
+ } else {
+ $this->fatalError( 'Invalid plugin parameter' );
+ return;
+ }
+
+ break;
+ case 'output':
+ $split = explode( ':', $param, 2 );
+ if ( count( $split ) !== 2 ) {
+ $this->fatalError( 'Invalid output parameter' );
+ }
+ list( $type, $file ) = $split;
+ if ( !is_null( $sink ) ) {
+ $sinks[] = $sink;
+ }
+ if ( !isset( $this->outputTypes[$type] ) ) {
+ $this->fatalError( "Unrecognized output sink type '$type'" );
+ }
+ $class = $this->outputTypes[$type];
+ if ( $type === "7zip" ) {
+ $sink = new $class( $file, intval( $this->getOption( '7ziplevel' ) ) );
+ } else {
+ $sink = new $class( $file );
+ }
+
+ break;
+ case 'filter':
+ if ( is_null( $sink ) ) {
+ $sink = new DumpOutput();
+ }
+
+ $split = explode( ':', $param );
+ $key = $split[0];
+
+ if ( !isset( $this->filterTypes[$key] ) ) {
+ $this->fatalError( "Unrecognized filter type '$key'" );
+ }
+
+ $type = $this->filterTypes[$key];
+
+ if ( count( $split ) === 1 ) {
+ $filter = new $type( $sink );
+ } elseif ( count( $split ) === 2 ) {
+ $filter = new $type( $sink, $split[1] );
+ } else {
+ $this->fatalError( 'Invalid filter parameter' );
+ }
+
+ // references are lame in php...
+ unset( $sink );
+ $sink = $filter;
+
+ break;