* Add way to get full input from stdin() without having to check the length
authorChad Horohoe <demon@users.mediawiki.org>
Sun, 2 Aug 2009 21:42:47 +0000 (21:42 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Sun, 2 Aug 2009 21:42:47 +0000 (21:42 +0000)
* Missing global

maintenance/Maintenance.php
maintenance/edit.php
maintenance/initEditCount.php

index edfbe79..b1f0a8d 100644 (file)
@@ -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 );
index 9fdce24..704909a 100644 (file)
@@ -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... " );
index da60763..c8bc586 100644 (file)
@@ -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' );