r87142 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87141‎ | r87142 | r87143 >
Date:22:08, 29 April 2011
Author:demon
Status:ok
Tags:
Comment:
Add cdb.php for inspecting cdb cache files. Format is stolen from mcc.php
Modified paths:
  • /trunk/phase3/maintenance/cdb.php (added) (history)

Diff [purge]

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

Status & tagging log