* @desc Allow farm administration through the DokuWiki admin interface, * handle a farm command from $_REQUEST['farm_cmd'], loads a handler class * form it then process request / display output html */ // must be run within Dokuwiki if(!defined('DOKU_INC')) die(); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); if(!defined('DOKU_FARM_PLUGIN')) define('DOKU_FARM_PLUGIN', DOKU_PLUGIN.'farm/'); if(!defined('DOKU_FARM_WWW')) define('DOKU_FARM_WWW', 'lib/plugins/farm/'); if(!defined('DOKU_FARMPLUGINLOADED')) define('DOKU_FARMPLUGINLOADED', true); require_once(DOKU_PLUGIN.'admin.php'); /** * Version string, will be used to check whether we need to upgrade the farm or not, * it can be in the case of a new installation or if we updated the plugin from * plugin manager / fs and the downloaded version is higher than the installed one, * in this case we update structure / config if needed. */ define('DOKU_FARM_VERSION', '1'); /** * All DokuWiki plugins to extend the admin function * need to inherit from this class */ class admin_plugin_farm extends DokuWiki_Admin_Plugin { var $disabled = 0; var $cmd = ''; var $opt = array(); var $conf = array(); var $handler = null; var $lang = array(); var $localised = false; var $errors = array(); var $success = array(); var $version = null; function __construct() { global $conf; if(defined('DOKU_IS_FARMER')) $this->getConf(); $this->disabled = (isset($conf['pluginfarm']) && ($conf['pluginfarm'] == 0)); } /** * Return some info */ function getInfo() { return array( 'author' => 'Etienne Meleard', 'email' => 'etienne.meleard@cru.fr', 'date' => '2009-12-16', 'name' => 'Farm Manager', 'desc' => 'Manage Wiki farm'.($this->disabled ? ' (disabled)' : ''), 'url' => 'http://wiki.splitbrain.org/plugin:farm', ); } /** * Return prompt for admin menu * @param $l language identifier * @return nothing if not in farmer context, menu title otherwise */ function getMenuText($l) { if(!defined('DOKU_IS_FARMER')) { @touch(DOKU_CONF.'local.php'); return $this->getLang('menu'); // not installed } if(!DOKU_IS_FARMER) return; // don't display farm management item in the animals' admin page if(!$this->disabled) return $this->getLang('menu'); return ''; } /** * Return sort order for position in admin menu * @return integer */ function getMenuSort() { return 20; } /** * Get localized string * @param $code lang string identifier * @param $data string or array used to replace %s occurences in the localized string * @param $opt option to postprocess localized string * @return localized string */ function getLang($code, $data = null, $opt='') { if(!$this->localised) $this->setupLocale(); if(!isset($this->lang[$code])) return '{'.strtoupper($code).'}'; $str = $this->lang[$code]; if(!is_null($data)) if(!is_array($data)) $data = array($data); if(is_array($data)) foreach($data as $d) $str = preg_replace('`%s`', $d, $str, 1); switch($opt) { case 'js': $str = htmlentities(str_replace('\'', '\\\'', $str)); break; } return $str; } /** * Get farm config * @return array of farm config parameters */ function getConf() { $farmconf = array(); include DOKU_FARM_PLUGIN.'config.php'; $this->conf = $farmconf; return $this->conf; } /** * Add error to error list * @param $family error familly identifier (lang string identifier) * @param $e error code (lang string identifier) or array containing 'code' => string and 'data => array entries */ function error($family, $e) { if($family == '') $family = 'not_classified_errors'; if(!isset($this->errors[$family])) $this->errors[$family] = array(); $this->errors[$family][] = $e; } /** * Print errors */ function putErrors() { if(!count($this->errors)) return; foreach($this->errors as $c => $list) { ptln('