mDescription = "Get serialized MediaWiki site configuration"; $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 ); } public function execute() { $res = array(); foreach ( explode( ' ', $this->getOption( 'settings' ) ) 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." ); } $res[$name] = $GLOBALS[$name]; } $out = null; switch( $this->getOption( 'format' ) ) { case 'PHP': $out = serialize( $res ); break; case 'JSON': $out = FormatJson::encode( $res ); break; default: throw new MWException( "Invalid serialization format given." ); } if ( !is_string( $out ) ) { throw new MWException( "Failed to serialize the requested settings." ); } $this->output( $out . "\n" ); } private function isAllowedVariable( $value ) { if ( is_array( $value ) ) { foreach ( $value as $k => $v ) { if ( !$this->isAllowedVariable( $v ) ) { return false; } } return true; } elseif ( is_scalar( $value ) ) { return true; } return false; } } $maintClass = "GetConfiguration"; require_once( RUN_MAINTENANCE_IF_MAIN );