From 5ff7ffe312d2881725293deb994c863103923271 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Sun, 2 Aug 2009 21:42:47 +0000 Subject: [PATCH] * Add way to get full input from stdin() without having to check the length * Missing global --- maintenance/Maintenance.php | 11 ++++++++--- maintenance/edit.php | 2 +- maintenance/initEditCount.php | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index edfbe79394..b1f0a8d7d9 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -45,6 +45,9 @@ abstract class Maintenance { const DB_NONE = 0; const DB_STD = 1; const DB_ADMIN = 2; + + // Const for getStdin() + const STDIN_ALL = 'all'; // This is the desired params private $mParams = array(); @@ -178,14 +181,16 @@ abstract class Maintenance { /** * Return input from stdin. * @param $length int The number of bytes to read. If null, - * just return the handle + * just return the handle. Maintenance::STDIN_ALL returns + * the full length * @return mixed */ protected function getStdin( $len = null ) { + if ( $len == Maintenance::STDIN_ALL ) + return file_get_contents( 'php://stdin' ); $f = fopen( 'php://stdin', 'rt' ); - if( !$len ) { + if( !$len ) return $f; - } $input = fgets( $f, $len ); fclose ( $f ); return rtrim( $input ); diff --git a/maintenance/edit.php b/maintenance/edit.php index 9fdce24fa0..704909adf7 100644 --- a/maintenance/edit.php +++ b/maintenance/edit.php @@ -61,7 +61,7 @@ class EditCLI extends Maintenance { $wgArticle = new Article( $wgTitle ); # Read the text - $text = $this->getStdin(); + $text = $this->getStdin( Maintenance::STDIN_ALL ); # Do the edit $this->output( "Saving... " ); diff --git a/maintenance/initEditCount.php b/maintenance/initEditCount.php index da60763522..c8bc58639b 100644 --- a/maintenance/initEditCount.php +++ b/maintenance/initEditCount.php @@ -35,6 +35,7 @@ in $wgDBservers, usually indicating a replication environment.' ); } public function execute() { + global $wgDBservers; $dbw = wfGetDB( DB_MASTER ); $user = $dbw->tableName( 'user' ); $revision = $dbw->tableName( 'revision' ); -- 2.20.1