Difference between revisions of "Extension:Backup.php"

From Organic Design wiki
m
m
Line 1: Line 1:
 
<?php
 
<?php
# Extension:Backups{{Category:Extensions}}{{php}}
+
# Extension:Backup_&_Restore{{Category:Extensions}}{{php}}
 
# - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
 
# - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
 
# - Author:  [http://www.organicdesign.co.nz/nad User:Nad]{{Category:Extensions created with Template:SpecialPage}}
 
# - Author:  [http://www.organicdesign.co.nz/nad User:Nad]{{Category:Extensions created with Template:SpecialPage}}
Line 10: Line 10:
 
define('BACKUPS_VERSION','0.0.1, 2007-06-18');
 
define('BACKUPS_VERSION','0.0.1, 2007-06-18');
  
$wgExtensionFunctions[] = 'wfSetupBackups';
+
$wgExtensionFunctions[] = 'wfSetupBackup';
  
 
$wgExtensionCredits['specialpage'][] = array(
 
$wgExtensionCredits['specialpage'][] = array(
'name'        => 'Special:Backups',
+
'name'        => 'Special:Backup',
 
'author'      => '[http://www.organicdesign.co.nz/nad User:Nad]',
 
'author'      => '[http://www.organicdesign.co.nz/nad User:Nad]',
 
'description' => 'A special page for backing up and restoring multiple wikis on a server',
 
'description' => 'A special page for backing up and restoring multiple wikis on a server',
Line 23: Line 23:
  
 
# Define a new class based on the SpecialPage class
 
# Define a new class based on the SpecialPage class
class SpecialBackups extends SpecialPage {
+
class SpecialBackup extends SpecialPage {
  
 
var $title;
 
var $title;
Line 29: Line 29:
 
# Constructor
 
# Constructor
 
function SpecialSearchLog() {
 
function SpecialSearchLog() {
SpecialPage::SpecialPage('Backups','sysop');
+
SpecialPage::SpecialPage('Backup','sysop');
 
}
 
}
  
Line 36: Line 36:
 
function execute($param) {
 
function execute($param) {
 
global $wgOut,$wgRequest;
 
global $wgOut,$wgRequest;
$title = Title::makeTitle(NS_SPECIAL,'Backups');
+
$title = Title::makeTitle(NS_SPECIAL,'Backup');
  
 
# create a sortable table for all wiki's found and accessible in mysql
 
# create a sortable table for all wiki's found and accessible in mysql
Line 107: Line 107:
  
 
}
 
}
+
 
 
# Called from $wgExtensionFunctions array when initialising extensions
 
# Called from $wgExtensionFunctions array when initialising extensions
function wfSetupBackups() {
+
function wfSetupBackup() {
 
global $wgLanguageCode,$wgMessageCache;
 
global $wgLanguageCode,$wgMessageCache;
  
Line 115: Line 115:
 
if ($wgLanguageCode == 'en') {
 
if ($wgLanguageCode == 'en') {
 
$wgMessageCache->addMessages(array(
 
$wgMessageCache->addMessages(array(
'backups'           => "Backup & restore wikis",
+
'backup'           => "Backup & Restore",
 
'backup_wikilist'  => "=== List of wikis ===\n*''the '''ID''' is used for file/dir name and db-prefix\n",
 
'backup_wikilist'  => "=== List of wikis ===\n*''the '''ID''' is used for file/dir name and db-prefix\n",
 
'backup_backuplist' => "=== List of backups and templates ===",
 
'backup_backuplist' => "=== List of backups and templates ===",
Line 127: Line 127:
  
 
# Add the specialpage to the environment
 
# Add the specialpage to the environment
SpecialPage::addPage(new SpecialBackups());
+
SpecialPage::addPage(new SpecialBackup());
 
}
 
}
 
?>
 
?>

Revision as of 02:36, 18 June 2007

<?php

  1. Extension:Backup_&_Restore
Info.svg These are the MediaWiki extensions we're using and/or developing. Please refer to the information on the mediawiki.org wiki for installation and usage details. Extensions here which have no corresponding mediawiki article are either not ready for use or have been superseded. You can also browse our extension code in our local Subversion repository or our GitHub mirror.

Template:Php

  1. - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
  2. - Author: User:NadCategory:Extensions created with Template:SpecialPage
  3. - Started: 2007-06-09
  4. - This is a SpecialPage which acts as an in-wiki interface to backup.pl which reduces the backup/compress/distribute queue

if (!defined('MEDIAWIKI')) die('Not an entry point.');

define('BACKUPS_VERSION','0.0.1, 2007-06-18');

$wgExtensionFunctions[] = 'wfSetupBackup';

$wgExtensionCredits['specialpage'][] = array( 'name' => 'Special:Backup', 'author' => 'User:Nad', 'description' => 'A special page for backing up and restoring multiple wikis on a server', 'url' => 'http://www.mediawiki.org/wiki/Extension:Backup_&_Restore', 'version' => BACKUPS_VERSION );

require_once "$IP/includes/SpecialPage.php";

  1. Define a new class based on the SpecialPage class

class SpecialBackup extends SpecialPage {

var $title;

# Constructor function SpecialSearchLog() { SpecialPage::SpecialPage('Backup','sysop'); }

# Override SpecialPage::execute() # - $param is from the URL, eg Special:Backups/param function execute($param) { global $wgOut,$wgRequest; $title = Title::makeTitle(NS_SPECIAL,'Backup');

# create a sortable table for all wiki's found and accessible in mysql $cols = array('ID','Name','Domains','DB','Status','Version','Backup-cycle','Delete','Backup','Repair'); $wgOut->addWikiText(wfMsg('backup_wikilist'));

$wgOut->addHTML('<form>

');

foreach ($this->getWikiList() as $wiki) {

$wgOut->addHTML("$something"); } # create a sortable table of all backup files which could be restored # - each row has same cols as above +backup-filename -backup -delete $cols = array('File','ID','Name','Domains','DB','Status','Version','Backup-cycle','Delete','Backup'); $wgOut->addWikiText(wfMsg('backup_backuplist')); $wgOut->addHTML('<form>
'.join('',$cols).'
');

foreach ($backups as $backup) {

$wgOut->addHTML("$something"); } # "Next >" or "Commit" $wgOut->addHTML(wfElement('input',array('type' => 'submit','name' => 'backup_next', 'value' => wfMsg('backup_next')))); $wgOut->addHTML(wfElement('input',array('type' => 'submit','name' => 'backup_commit', 'value' => wfMsg('backup_commit')))); $wgOut->addHTML(wfElement('input',array('type' => 'hidden','name' => 'backup_title', 'value' => $this->title))); $wgOut->addHTML('
'.join('',$cols).'

</form>');

# Add list of jobs to be committed by changes (if submitted with "next") if ($wgRequest->getText('backup_next')) { $jobs = submit(); if (count($jobs) > 0) { $wgOut->addWikiText(wfMsg('backup_commitlist')); foreach ($jobs as $job) { $wgOut->addWikiText("*$job"); } } else $wgOut->addWikiText(wfMsg('backup_nojobs')); }

# Queue the jobs if form posted with "commit" if ($wgRequest->getText('backup_commit')) submit(true);

# add list of backup.pl job queue (and link to MW log of completed items) $wgOut->addWikiText(wfMsg('backup_activelist')); $jobs = file(dirname(__FILE__).'/jobs'); if (count($jobs) > 0) { foreach ($jobs as $job) { $wgOut->addWikiText("*$job"); } } else $wgOut->addWikiText(wfMsg('backup_nojobs')); }

# Process posted form function submit($queue = false) { $jobs = array(); foreach ($wikis as $wiki) { # todo: work out jobs from fields changed if ($queue) { # queue the job } } return $jobs; }

# Get list from DB's and tables function getWikiList() { $list = array(); $db = &wfGetDB(DB_SLAVE); return $list; }

}

  1. Called from $wgExtensionFunctions array when initialising extensions

function wfSetupBackup() { global $wgLanguageCode,$wgMessageCache;

# Add the messages used by the specialpage if ($wgLanguageCode == 'en') { $wgMessageCache->addMessages(array( 'backup' => "Backup & Restore", 'backup_wikilist' => "=== List of wikis ===\n*the ID is used for file/dir name and db-prefix\n", 'backup_backuplist' => "=== List of backups and templates ===", 'backup_commitlist' => "The changes you've submitted result in the following jobs:", 'backup_activelist' => "The following jobs are currently executing:", 'backup_next' => "Next >", 'backup_commit' => "Commit", 'backup_nojobs' => "There are no jobs in the list." )); }

# Add the specialpage to the environment SpecialPage::addPage(new SpecialBackup()); } ?>