Fun little script to destroy your wiki
authorChad Horohoe <demon@users.mediawiki.org>
Sun, 20 Jun 2010 16:15:00 +0000 (16:15 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Sun, 20 Jun 2010 16:15:00 +0000 (16:15 +0000)
maintenance/nukeEntireWiki.php [new file with mode: 0644]

diff --git a/maintenance/nukeEntireWiki.php b/maintenance/nukeEntireWiki.php
new file mode 100644 (file)
index 0000000..8f0f084
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+/* 
+ * This script is designed to destroy your entire wiki so you can start over.
+ * THIS IS NOT RECOVERABLE IN ANY WAY SHAPE OR FORM. You have been warned.
+ *
+ * @ingroup Maintenance
+ */
+
+require_once( 'Maintenance.php' );
+
+class NukeEntireWiki extends Maintenance {
+
+       public function __construct() {
+               parent::__construct();
+               $this->mDescription = "Truncate all tables in your wiki. Skips user-related tables by default";
+               $this->addOption( 'users', 'Include the user-related tables' );
+       }
+
+       public function getDbType() {
+               return Maintenance::DB_ADMIN;
+       }
+
+       public function execute() {
+               $this->output( "This will truncate all tables in your MediaWiki installation. Press Ctrl+C to abort\n" );
+               wfCountDown( 5 );
+
+               $dbw = wfGetDB( DB_MASTER );
+
+               // Skip these tables unless the --users switch was given
+               if( !$this->hasOption( 'users' ) ) {
+                       $userTables = $dbw->tableNamesN( 'user', 'user_groups', 'user_properties' );
+               } else {
+                       $userTables = array();
+               }
+
+               $res = $dbw->query( "SHOW TABLES" );
+               while( $tbl = $dbw->fetchRow( $res ) ) {
+                       if( in_array( "`{$tbl[0]}`", $userTables ) )
+                               continue;
+                       $this->output( "Truncating table {$tbl[0]}..." );
+                       $dbw->query( "TRUNCATE TABLE {$tbl[0]}" );
+                       $this->output( "done\n" );
+               }
+       }
+}
+
+$maintClass = 'NukeEntireWiki';
+require_once( DO_MAINTENANCE );