X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FMaintenance.php;h=3925efe8deb4089b653e7c2714af114fabf3b62d;hb=3742b0b0819f488cd0872d2c455a06fe9678230b;hp=208cf1769cf0f97daebf188b6fb716a8ffd7b3e9;hpb=53779578b44575ef91feb3fad488f09b52f737d7;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index 208cf1769c..3925efe8de 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -459,7 +459,6 @@ abstract class Maintenance { * Add the default parameters to the scripts */ protected function addDefaultParams() { - # Generic (non script dependant) options: $this->addOption( 'help', 'Display this help message', false, false, 'h' ); @@ -499,7 +498,7 @@ abstract class Maintenance { */ public function getConfig() { if ( $this->config === null ) { - $this->config = ConfigFactory::getDefaultInstance()->makeConfig( 'main' ); + $this->config = MediaWikiServices::getInstance()->getMainConfig(); } return $this->config; @@ -546,7 +545,6 @@ abstract class Maintenance { . "for this script to run: $joined. Please enable them and then try again."; $this->error( $msg, 1 ); } - } /** @@ -1502,6 +1500,36 @@ abstract class Maintenance { return fgets( STDIN, 1024 ); } + /** + * Get the terminal size as a two-element array where the first element + * is the width (number of columns) and the second element is the height + * (number of rows). + * + * @return array + */ + public static function getTermSize() { + $default = [ 80, 50 ]; + if ( wfIsWindows() ) { + return $default; + } + // It's possible to get the screen size with VT-100 terminal escapes, + // but reading the responses is not possible without setting raw mode + // (unless you want to require the user to press enter), and that + // requires an ioctl(), which we can't do. So we have to shell out to + // something that can do the relevant syscalls. There are a few + // options. Linux and Mac OS X both have "stty size" which does the + // job directly. + $retval = false; + $size = wfShellExec( 'stty size', $retval ); + if ( $retval !== 0 ) { + return $default; + } + if ( !preg_match( '/^(\d+) (\d+)$/', $size, $m ) ) { + return $default; + } + return [ intval( $m[2] ), intval( $m[1] ) ]; + } + /** * Call this to set up the autoloader to allow classes to be used from the * tests directory.