r44923 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r44922‎ | r44923 | r44924 >
Date:04:32, 23 December 2008
Author:skizzerz
Status:deferred
Tags:
Comment:
* adding support for the eval and sql maintenance scripts
Modified paths:
  • /trunk/extensions/Maintenance/Maintenance.i18n.php (modified) (history)
  • /trunk/extensions/Maintenance/Maintenance.php (modified) (history)
  • /trunk/extensions/Maintenance/Maintenance_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maintenance/Maintenance_body.php
@@ -55,8 +55,10 @@
5656 //(minus the .php part... duh)
5757 $scripts = array(
5858 'changePassword', 'createAndPromote', 'deleteBatch', 'deleteRevision',
59 - 'initEditCount', 'initStats', 'moveBatch', 'runJobs', 'showJobs', 'stats'
 59+ 'initEditCount', 'initStats', 'moveBatch', 'runJobs', 'showJobs', 'stats',
 60+ 'sql', 'eval',
6061 );
 62+ sort($scripts);
6163 global $wgOut;
6264 wfLoadExtensionMessages('Maintenance');
6365 $this->setHeaders();
@@ -95,6 +97,9 @@
9698 case 'deleteRevision':
9799 $wgOut->addHTML('<textarea name="wpDelete" rows="25" cols="80"></textarea><br /><br />');
98100 break;
 101+ case 'eval':
 102+ $wgOut->addHTML('<textarea name="wpCode" rows="25" cols="80"></textarea><br /><br />');
 103+ break;
99104 case 'initEditCount':
100105 //just hit the button to start this, no additional settings are needed :)
101106 break;
@@ -115,6 +120,9 @@
116121 case 'stats':
117122 //just hit the button to start this, no additional settings are needed :)
118123 break;
 124+ case 'sql':
 125+ $wgOut->addHTML('<textarea name="wpQuery" rows="25" cols="80"></textarea><br /><br />');
 126+ break;
119127 default:
120128 $wgOut->addHTML('<p>'.wfMsg('maintenance-invalidtype').'</p></form>');
121129 return;
@@ -126,6 +134,7 @@
127135 function executeScript( $type ) {
128136 global $wgOut, $wgRequest, $wgUser;
129137 wfLoadExtensionMessages('Maintenance');
 138+ @set_time_limit(0); //if we can, disable the time limit
130139 $this->setHeaders();
131140 $title = Title::makeTitle( NS_SPECIAL, $this->getName() );
132141 $wgOut->addHTML('<a href="'.$title->getFullURL().'">'.wfMsg('maintenance-backlink').'</a><br />');
@@ -252,6 +261,24 @@
253262 $wgUser = $OldUser;
254263 $wgOut->addWikiMsg( 'maintenance-success', $type );
255264 break;
 265+ case 'eval':
 266+ $temp = error_reporting( E_ALL );
 267+ ob_start();
 268+ $str = eval( $wgRequest->getText( 'wpCode', 'return;' ) );
 269+ $ext = ob_get_clean();
 270+ error_reporting( 0 );
 271+ if( $ext ) {
 272+ $wgOut->addHTML( nl2br($ext) . '<hr />' );
 273+ }
 274+ if( !$str ) {
 275+ // do nothing
 276+ } elseif( is_string( $str ) ) {
 277+ $wgOut->addHTML( nl2br($str) . '<hr />' );
 278+ } else {
 279+ $wgOut->addHTML( nl2br( var_export( $str, true ) ) . '<hr />' );
 280+ }
 281+ $wgOut->addWikiMsg( 'maintenance-success', $type );
 282+ break;
256283 case 'initEditCount':
257284 global $wgDBservers;
258285 $dbw = wfGetDB( DB_MASTER );
@@ -431,6 +458,53 @@
432459 $wgOut->addWikiText($dcache);
433460 $wgOut->addWikiMsg( 'maintenance-success', $type );
434461 break;
 462+ case 'sql':
 463+ $db = wfGetDB( DB_MASTER );
 464+ $q = $wgRequest->getText('wpQuery', '');
 465+ $db->begin();
 466+ try {
 467+ $r = $db->query( $q, 'Maintenance::sql.php' );
 468+ } catch(DBQueryError $e) {
 469+ global $wgShowSQLErrors;
 470+ $temp = $wgShowSQLErrors;
 471+ $wgShowSQLErrors = true;
 472+ $wgOut->addWikiText( '<pre style="overflow: auto">' . $e->getText() . '</pre>' );
 473+ $wgShowSQLErrors = $temp;
 474+ $r = false;
 475+ }
 476+ if($r === true) {
 477+ $wgOut->addWikiMsg( 'maintenance-sql-aff', $db->affectedRows() );
 478+ } elseif( $r instanceOf ResultWrapper ) {
 479+ $res = array();
 480+ for( $i = 0; $i < $r->numRows(); $i++ ) {
 481+ $row = $r->fetchRow();
 482+ $res[] = $row;
 483+ foreach( $row as $key => $meh ) {
 484+ $names[] = $key;
 485+ }
 486+ }
 487+ $names = array_unique($names);
 488+ $rtable = '<table class="wikitable"><tr>';
 489+ foreach($names as $name) {
 490+ if( is_numeric($name) ) continue;
 491+ $rtable .= '<th>' . $name . '</th>';
 492+ }
 493+ $rtable .= '</tr>';
 494+ foreach( $res as $data ) {
 495+ $rtable .= '<tr>';
 496+ foreach( $data as $key => $value ) {
 497+ if( is_numeric($key) ) continue;
 498+ $rtable .= '<td><nowiki>' . $value . '</nowiki></td>';
 499+ }
 500+ $rtable .= '</tr>';
 501+ }
 502+ $rtable .= '</table>';
 503+ $wgOut->addWikiMsg( 'maintenance-sql-res', $r->numRows(), $rtable );
 504+ $db->freeResult($r);
 505+ }
 506+ $db->commit();
 507+ $wgOut->addWikiMsg( 'maintenance-success', $type );
 508+ break;
435509 default:
436510 $wgOut->addHTML('<p>'.wfMsg('maintenance-invalidtype').'</p></form>');
437511 return;
Index: trunk/extensions/Maintenance/Maintenance.i18n.php
@@ -21,11 +21,13 @@
2222 'maintenance-createAndPromote-desc' => 'Create a user and promote to sysop status',
2323 'maintenance-deleteBatch-desc' => 'Mass-delete pages',
2424 'maintenance-deleteRevision-desc' => 'Remove revisions from the database',
 25+ 'maintenance-eval-desc' => 'Evaluate PHP code in the MediaWiki environment',
2526 'maintenance-initEditCount-desc' => 'Recalculate the edit counts of users',
2627 'maintenance-initStats-desc' => 'Recalculate site statistics',
2728 'maintenance-moveBatch-desc' => 'Mass-move pages',
2829 'maintenance-runJobs-desc' => 'Run jobs in the job queue',
2930 'maintenance-showJobs-desc' => 'Show a list of jobs pending in the job queue',
 31+ 'maintenance-sql-desc' => 'Execute an SQL query',
3032 'maintenance-stats-desc' => 'Show Memcached statistics',
3133 'maintenance-changePassword' => "Use this form to change a user's password",
3234 'maintenance-createAndPromote' => 'Use this form to create a new user and promote it to sysop.
@@ -58,6 +60,10 @@
5961 'maintenance-deleted' => 'DELETED',
6062 'maintenance-revdelete' => 'Deleting revisions $1 from wiki $2',
6163 'maintenance-revnotfound' => 'Revision $1 not found!',
 64+ 'maintenance-sql' => 'Use this form to execute a SQL query on the database.',
 65+ 'maintenance-sql-aff' => 'Affected rows: $1',
 66+ 'maintenance-sql-res' => '$1 rows returned:
 67+$2',
6268 'maintenance-stats-edits' => 'Number of edits: $1',
6369 'maintenance-stats-articles' => 'Number of pages in the main namespace: $1',
6470 'maintenance-stats-pages' => 'Number of pages: $1',
@@ -86,6 +92,7 @@
8793 'maintenance-memc-updates' => 'updates:',
8894 'maintenance-memc-uncacheable' => 'uncacheable:',
8995 'maintenance-memc-diffcache' => 'Diff Cache',
 96+ 'maintenance-eval' => 'Use this form to evaluate PHP code in the MediaWiki environment.',
9097 );
9198
9299 /** Message documentation (Message documentation)
Index: trunk/extensions/Maintenance/Maintenance.php
@@ -19,7 +19,7 @@
2020 $wgExtensionCredits['specialpage'][] = array(
2121 'name' => 'Maintenance',
2222 'author' => 'Ryan Schmidt',
23 - 'version' => '1.0.1',
 23+ 'version' => '1.0.2',
2424 'description' => '[[Special:Maintenance|Web interface]] for various maintenance scripts',
2525 'descriptionmsg' => 'maintenance-desc',
2626 'url' => 'http://www.mediawiki.org/wiki/Extension:Maintenance',

Status & tagging log