[ Index ] |
PHP Cross Reference of MediaWiki-1.24.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * cdb inspector tool 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License along 16 * with this program; if not, write to the Free Software Foundation, Inc., 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 * http://www.gnu.org/copyleft/gpl.html 19 * 20 * @file 21 * @todo document 22 * @ingroup Maintenance 23 */ 24 25 /** */ 26 require_once __DIR__ . '/commandLine.inc'; 27 28 function cdbShowHelp( $command ) { 29 $commandList = array( 30 'load' => 'load a cdb file for reading', 31 'get' => 'get a value for a key', 32 'exit' => 'exit cdb', 33 'quit' => 'exit cdb', 34 'help' => 'help about a command', 35 ); 36 if ( !$command ) { 37 $command = 'fullhelp'; 38 } 39 if ( $command === 'fullhelp' ) { 40 $max_cmd_len = max( array_map( 'strlen', array_keys( $commandList ) ) ); 41 foreach ( $commandList as $cmd => $desc ) { 42 printf( "%-{$max_cmd_len}s: %s\n", $cmd, $desc ); 43 } 44 } elseif ( isset( $commandList[$command] ) ) { 45 print "$command: $commandList[$command]\n"; 46 } else { 47 print "$command: command does not exist or no help for it\n"; 48 } 49 } 50 51 do { 52 $bad = false; 53 $showhelp = false; 54 $quit = false; 55 static $fileHandle = false; 56 57 $line = Maintenance::readconsole(); 58 if ( $line === false ) { 59 exit; 60 } 61 62 $args = explode( ' ', $line ); 63 $command = array_shift( $args ); 64 65 // process command 66 switch ( $command ) { 67 case 'help': 68 // show an help message 69 cdbShowHelp( array_shift( $args ) ); 70 break; 71 case 'load': 72 if ( !isset( $args[0] ) ) { 73 print "Need a filename there buddy\n"; 74 break; 75 } 76 $file = $args[0]; 77 print "Loading cdb file $file..."; 78 try { 79 $fileHandle = CdbReader::open( $file ); 80 } catch ( CdbException $e ) { 81 } 82 83 if ( !$fileHandle ) { 84 print "not a cdb file or unable to read it\n"; 85 } else { 86 print "ok\n"; 87 } 88 break; 89 case 'get': 90 if ( !$fileHandle ) { 91 print "Need to load a cdb file first\n"; 92 break; 93 } 94 if ( !isset( $args[0] ) ) { 95 print "Need to specify a key, Luke\n"; 96 break; 97 } 98 try { 99 $res = $fileHandle->get( $args[0] ); 100 } catch ( CdbException $e ) { 101 print "Unable to read key from file\n"; 102 break; 103 } 104 if ( $res === false ) { 105 print "No such key/value pair\n"; 106 } elseif ( is_string( $res ) ) { 107 print "$res\n"; 108 } else { 109 var_dump( $res ); 110 } 111 break; 112 case 'quit': 113 case 'exit': 114 $quit = true; 115 break; 116 117 default: 118 $bad = true; 119 } // switch() end 120 121 if ( $bad ) { 122 if ( $command ) { 123 print "Bad command\n"; 124 } 125 } else { 126 if ( function_exists( 'readline_add_history' ) ) { 127 readline_add_history( $line ); 128 } 129 } 130 } while ( !$quit );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 14:03:12 2014 | Cross-referenced by PHPXref 0.7.1 |