diff options
Diffstat (limited to 'lib')
44 files changed, 2698 insertions, 2206 deletions
diff --git a/lib/exe/css.php b/lib/exe/css.php index 40eaf99a6..a557f79cc 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -67,7 +67,8 @@ function css_out(){ // load jQuery-UI theme if ($mediatype == 'screen') { - $files[DOKU_INC.'lib/scripts/jquery/jquery-ui-theme/smoothness.css'] = DOKU_BASE.'lib/scripts/jquery/jquery-ui-theme/'; + $files[DOKU_INC.'lib/scripts/jquery/jquery-ui-theme/smoothness.css'] = + DOKU_BASE.'lib/scripts/jquery/jquery-ui-theme/'; } // load plugin styles $files = array_merge($files, css_pluginstyles($mediatype)); @@ -99,7 +100,16 @@ function css_out(){ } // The generated script depends on some dynamic options - $cache = new cache('styles'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].$INPUT->bool('preview').DOKU_BASE.$tpl.$type,'.css'); + $cache = new cache( + 'styles' . + $_SERVER['HTTP_HOST'] . + $_SERVER['SERVER_PORT'] . + $INPUT->bool('preview') . + DOKU_BASE . + $tpl . + $type, + '.css' + ); $cache->_event = 'CSS_CACHE_USE'; // check cache age & handle conditional request @@ -547,18 +557,50 @@ function css_compress($css){ $css = preg_replace('/ ?: /',':',$css); // number compression - $css = preg_replace('/([: ])0+(\.\d+?)0*((?:pt|pc|in|mm|cm|em|ex|px)\b|%)(?=[^\{]*[;\}])/', '$1$2$3', $css); // "0.1em" to ".1em", "1.10em" to "1.1em" - $css = preg_replace('/([: ])\.(0)+((?:pt|pc|in|mm|cm|em|ex|px)\b|%)(?=[^\{]*[;\}])/', '$1$2', $css); // ".0em" to "0" - $css = preg_replace('/([: ]0)0*(\.0*)?((?:pt|pc|in|mm|cm|em|ex|px)(?=[^\{]*[;\}])\b|%)/', '$1', $css); // "0.0em" to "0" - $css = preg_replace('/([: ]\d+)(\.0*)((?:pt|pc|in|mm|cm|em|ex|px)(?=[^\{]*[;\}])\b|%)/', '$1$3', $css); // "1.0em" to "1em" - $css = preg_replace('/([: ])0+(\d+|\d*\.\d+)((?:pt|pc|in|mm|cm|em|ex|px)(?=[^\{]*[;\}])\b|%)/', '$1$2$3', $css); // "001em" to "1em" + $css = preg_replace( + '/([: ])0+(\.\d+?)0*((?:pt|pc|in|mm|cm|em|ex|px)\b|%)(?=[^\{]*[;\}])/', + '$1$2$3', + $css + ); // "0.1em" to ".1em", "1.10em" to "1.1em" + $css = preg_replace( + '/([: ])\.(0)+((?:pt|pc|in|mm|cm|em|ex|px)\b|%)(?=[^\{]*[;\}])/', + '$1$2', + $css + ); // ".0em" to "0" + $css = preg_replace( + '/([: ]0)0*(\.0*)?((?:pt|pc|in|mm|cm|em|ex|px)(?=[^\{]*[;\}])\b|%)/', + '$1', + $css + ); // "0.0em" to "0" + $css = preg_replace( + '/([: ]\d+)(\.0*)((?:pt|pc|in|mm|cm|em|ex|px)(?=[^\{]*[;\}])\b|%)/', + '$1$3', + $css + ); // "1.0em" to "1em" + $css = preg_replace( + '/([: ])0+(\d+|\d*\.\d+)((?:pt|pc|in|mm|cm|em|ex|px)(?=[^\{]*[;\}])\b|%)/', + '$1$2$3', + $css + ); // "001em" to "1em" // shorten attributes (1em 1em 1em 1em -> 1em) - $css = preg_replace('/(?<![\w\-])((?:margin|padding|border|border-(?:width|radius)):)([\w\.]+)( \2)+(?=[;\}]| !)/', '$1$2', $css); // "1em 1em 1em 1em" to "1em" - $css = preg_replace('/(?<![\w\-])((?:margin|padding|border|border-(?:width)):)([\w\.]+) ([\w\.]+) \2 \3(?=[;\}]| !)/', '$1$2 $3', $css); // "1em 2em 1em 2em" to "1em 2em" + $css = preg_replace( + '/(?<![\w\-])((?:margin|padding|border|border-(?:width|radius)):)([\w\.]+)( \2)+(?=[;\}]| !)/', + '$1$2', + $css + ); // "1em 1em 1em 1em" to "1em" + $css = preg_replace( + '/(?<![\w\-])((?:margin|padding|border|border-(?:width)):)([\w\.]+) ([\w\.]+) \2 \3(?=[;\}]| !)/', + '$1$2 $3', + $css + ); // "1em 2em 1em 2em" to "1em 2em" // shorten colors - $css = preg_replace("/#([0-9a-fA-F]{1})\\1([0-9a-fA-F]{1})\\2([0-9a-fA-F]{1})\\3(?=[^\{]*[;\}])/", "#\\1\\2\\3", $css); + $css = preg_replace( + "/#([0-9a-fA-F]{1})\\1([0-9a-fA-F]{1})\\2([0-9a-fA-F]{1})\\3(?=[^\{]*[;\}])/", + "#\\1\\2\\3", + $css + ); return $css; } diff --git a/lib/exe/js.php b/lib/exe/js.php index 7b76efabb..b63a8598e 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -100,8 +100,12 @@ function js_out(){ 'secure' => $conf['securecookie'] && is_ssl() )).";"; // FIXME: Move those to JSINFO - print "Object.defineProperty(window, 'DOKU_UHN', { get: function() { console.warn('Using DOKU_UHN is deprecated. Please use JSINFO.useHeadingNavigation instead'); return JSINFO.useHeadingNavigation; } });"; - print "Object.defineProperty(window, 'DOKU_UHC', { get: function() { console.warn('Using DOKU_UHC is deprecated. Please use JSINFO.useHeadingContent instead'); return JSINFO.useHeadingContent; } });"; + print "Object.defineProperty(window, 'DOKU_UHN', { get: function() {". + "console.warn('Using DOKU_UHN is deprecated. Please use JSINFO.useHeadingNavigation instead');". + "return JSINFO.useHeadingNavigation; } });"; + print "Object.defineProperty(window, 'DOKU_UHC', { get: function() {". + "console.warn('Using DOKU_UHC is deprecated. Please use JSINFO.useHeadingContent instead');". + "return JSINFO.useHeadingContent; } });"; // load JS specific translations $lang['js']['plugins'] = js_pluginstrings(); diff --git a/lib/exe/xmlrpc.php b/lib/exe/xmlrpc.php index 3046f47e9..dc0438ee1 100644 --- a/lib/exe/xmlrpc.php +++ b/lib/exe/xmlrpc.php @@ -1,67 +1,15 @@ <?php -if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../'); - -require_once(DOKU_INC.'inc/init.php'); -session_write_close(); //close session - -if(!$conf['remote']) die((new IXR_Error(-32605, "XML-RPC server not enabled."))->getXml()); - /** - * Contains needed wrapper functions and registers all available - * XMLRPC functions. + * XMLRPC API backend */ -class dokuwiki_xmlrpc_server extends IXR_Server { - protected $remote; - - /** - * Constructor. Register methods and run Server - */ - public function __construct(){ - $this->remote = new RemoteAPI(); - $this->remote->setDateTransformation(array($this, 'toDate')); - $this->remote->setFileTransformation(array($this, 'toFile')); - parent::__construct(); - } - /** - * @param string $methodname - * @param array $args - * @return IXR_Error|mixed - */ - public function call($methodname, $args){ - try { - $result = $this->remote->call($methodname, $args); - return $result; - } catch (RemoteAccessDeniedException $e) { - if (!isset($_SERVER['REMOTE_USER'])) { - http_status(401); - return new IXR_Error(-32603, "server error. not authorized to call method $methodname"); - } else { - http_status(403); - return new IXR_Error(-32604, "server error. forbidden to call the method $methodname"); - } - } catch (RemoteException $e) { - return new IXR_Error($e->getCode(), $e->getMessage()); - } - } +use dokuwiki\Remote\XmlRpcServer; - /** - * @param string|int $data iso date(yyyy[-]mm[-]dd[ hh:mm[:ss]]) or timestamp - * @return IXR_Date - */ - public function toDate($data) { - return new IXR_Date($data); - } +if(!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__).'/../../'); - /** - * @param string $data - * @return IXR_Base64 - */ - public function toFile($data) { - return new IXR_Base64($data); - } -} +require_once(DOKU_INC.'inc/init.php'); +session_write_close(); //close session -$server = new dokuwiki_xmlrpc_server(); +if(!$conf['remote']) die((new IXR_Error(-32605, "XML-RPC server not enabled."))->getXml()); -// vim:ts=4:sw=4:et: +$server = new XmlRpcServer(); diff --git a/lib/plugins/acl/action.php b/lib/plugins/acl/action.php index a7226f598..b895d0b5a 100644 --- a/lib/plugins/acl/action.php +++ b/lib/plugins/acl/action.php @@ -6,13 +6,11 @@ * @author Andreas Gohr <andi@splitbrain.org> */ -// must be run within Dokuwiki -if(!defined('DOKU_INC')) die(); - /** * Register handler */ -class action_plugin_acl extends DokuWiki_Action_Plugin { +class action_plugin_acl extends DokuWiki_Action_Plugin +{ /** * Registers a callback function for a given event @@ -20,10 +18,10 @@ class action_plugin_acl extends DokuWiki_Action_Plugin { * @param Doku_Event_Handler $controller DokuWiki's event controller object * @return void */ - public function register(Doku_Event_Handler $controller) { - - $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax_call_acl'); + public function register(Doku_Event_Handler $controller) + { + $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handleAjaxCallAcl'); } /** @@ -34,8 +32,9 @@ class action_plugin_acl extends DokuWiki_Action_Plugin { * @return void */ - public function handle_ajax_call_acl(Doku_Event &$event, $param) { - if($event->data !== 'plugin_acl') { + public function handleAjaxCallAcl(Doku_Event $event, $param) + { + if ($event->data !== 'plugin_acl') { return; } $event->stopPropagation(); @@ -44,11 +43,11 @@ class action_plugin_acl extends DokuWiki_Action_Plugin { global $ID; global $INPUT; - if(!auth_isadmin()) { + if (!auth_isadmin()) { echo 'for admins only'; return; } - if(!checkSecurityToken()) { + if (!checkSecurityToken()) { echo 'CRSF Attack'; return; } @@ -62,26 +61,27 @@ class action_plugin_acl extends DokuWiki_Action_Plugin { $ajax = $INPUT->str('ajax'); header('Content-Type: text/html; charset=utf-8'); - if($ajax == 'info') { - $acl->_html_info(); - } elseif($ajax == 'tree') { - + if ($ajax == 'info') { + $acl->printInfo(); + } elseif ($ajax == 'tree') { $ns = $INPUT->str('ns'); - if($ns == '*') { + if ($ns == '*') { $ns = ''; } $ns = cleanID($ns); $lvl = count(explode(':', $ns)); $ns = utf8_encodeFN(str_replace(':', '/', $ns)); - $data = $acl->_get_tree($ns, $ns); + $data = $acl->makeTree($ns, $ns); - foreach(array_keys($data) as $item) { + foreach (array_keys($data) as $item) { $data[$item]['level'] = $lvl + 1; } echo html_buildlist( - $data, 'acl', array($acl, '_html_list_acl'), - array($acl, '_html_li_acl') + $data, + 'acl', + array($acl, 'makeTreeItem'), + array($acl, 'makeListItem') ); } } diff --git a/lib/plugins/acl/admin.php b/lib/plugins/acl/admin.php index 6edc6c621..9dee059a3 100644 --- a/lib/plugins/acl/admin.php +++ b/lib/plugins/acl/admin.php @@ -7,16 +7,15 @@ * @author Anika Henke <anika@selfthinker.org> (concepts) * @author Frank Schubert <frank@schokilade.de> (old version) */ -// must be run within Dokuwiki -if(!defined('DOKU_INC')) die(); /** * All DokuWiki plugins to extend the admin function * need to inherit from this class */ -class admin_plugin_acl extends DokuWiki_Admin_Plugin { - var $acl = null; - var $ns = null; +class admin_plugin_acl extends DokuWiki_Admin_Plugin +{ + public $acl = null; + protected $ns = null; /** * The currently selected item, associative array with id and type. * Populated from (in this order): @@ -25,22 +24,24 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { * $ns * $ID */ - var $current_item = null; - var $who = ''; - var $usersgroups = array(); - var $specials = array(); + protected $current_item = null; + protected $who = ''; + protected $usersgroups = array(); + protected $specials = array(); /** * return prompt for admin menu */ - function getMenuText($language) { + public function getMenuText($language) + { return $this->getLang('admin_acl'); } /** * return sort order for position in admin menu */ - function getMenuSort() { + public function getMenuSort() + { return 1; } @@ -51,7 +52,8 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { * * @author Andreas Gohr <andi@splitbrain.org> */ - function handle() { + public function handle() + { global $AUTH_ACL; global $ID; global $auth; @@ -62,9 +64,9 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { $AUTH_ACL = file($config_cascade['acl']['default']); // namespace given? - if($INPUT->str('ns') == '*'){ + if ($INPUT->str('ns') == '*') { $this->ns = '*'; - }else{ + } else { $this->ns = cleanID($INPUT->str('ns')); } @@ -80,78 +82,78 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { // user or group choosen? $who = trim($INPUT->str('acl_w')); - if($INPUT->str('acl_t') == '__g__' && $who){ - $this->who = '@'.ltrim($auth->cleanGroup($who),'@'); - }elseif($INPUT->str('acl_t') == '__u__' && $who){ - $this->who = ltrim($who,'@'); - if($this->who != '%USER%' && $this->who != '%GROUP%'){ #keep wildcard as is + if ($INPUT->str('acl_t') == '__g__' && $who) { + $this->who = '@'.ltrim($auth->cleanGroup($who), '@'); + } elseif ($INPUT->str('acl_t') == '__u__' && $who) { + $this->who = ltrim($who, '@'); + if ($this->who != '%USER%' && $this->who != '%GROUP%') { #keep wildcard as is $this->who = $auth->cleanUser($this->who); } - }elseif($INPUT->str('acl_t') && + } elseif ($INPUT->str('acl_t') && $INPUT->str('acl_t') != '__u__' && - $INPUT->str('acl_t') != '__g__'){ + $INPUT->str('acl_t') != '__g__') { $this->who = $INPUT->str('acl_t'); - }elseif($who){ + } elseif ($who) { $this->who = $who; } // handle modifications - if($INPUT->has('cmd') && checkSecurityToken()){ + if ($INPUT->has('cmd') && checkSecurityToken()) { $cmd = $INPUT->extract('cmd')->str('cmd'); // scope for modifications - if($this->ns){ - if($this->ns == '*'){ + if ($this->ns) { + if ($this->ns == '*') { $scope = '*'; - }else{ + } else { $scope = $this->ns.':*'; } - }else{ + } else { $scope = $ID; } - if($cmd == 'save' && $scope && $this->who && $INPUT->has('acl')){ + if ($cmd == 'save' && $scope && $this->who && $INPUT->has('acl')) { // handle additions or single modifications - $this->_acl_del($scope, $this->who); - $this->_acl_add($scope, $this->who, $INPUT->int('acl')); - }elseif($cmd == 'del' && $scope && $this->who){ + $this->deleteACL($scope, $this->who); + $this->addACL($scope, $this->who, $INPUT->int('acl')); + } elseif ($cmd == 'del' && $scope && $this->who) { // handle single deletions - $this->_acl_del($scope, $this->who); - }elseif($cmd == 'update'){ + $this->deleteACL($scope, $this->who); + } elseif ($cmd == 'update') { $acl = $INPUT->arr('acl'); // handle update of the whole file - foreach($INPUT->arr('del') as $where => $names){ + foreach ($INPUT->arr('del') as $where => $names) { // remove all rules marked for deletion - foreach($names as $who) + foreach ($names as $who) unset($acl[$where][$who]); } // prepare lines $lines = array(); // keep header - foreach($AUTH_ACL as $line){ - if($line{0} == '#'){ + foreach ($AUTH_ACL as $line) { + if ($line{0} == '#') { $lines[] = $line; - }else{ + } else { break; } } // re-add all rules - foreach($acl as $where => $opt){ - foreach($opt as $who => $perm){ + foreach ($acl as $where => $opt) { + foreach ($opt as $who => $perm) { if ($who[0]=='@') { if ($who!='@ALL') { - $who = '@'.ltrim($auth->cleanGroup($who),'@'); + $who = '@'.ltrim($auth->cleanGroup($who), '@'); } - } elseif ($who != '%USER%' && $who != '%GROUP%'){ #keep wildcard as is + } elseif ($who != '%USER%' && $who != '%GROUP%') { #keep wildcard as is $who = $auth->cleanUser($who); } - $who = auth_nameencode($who,true); + $who = auth_nameencode($who, true); $lines[] = "$where\t$who\t$perm\n"; } } // save it - io_saveFile($config_cascade['acl']['default'], join('',$lines)); + io_saveFile($config_cascade['acl']['default'], join('', $lines)); } // reload ACL config @@ -159,7 +161,7 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { } // initialize ACL array - $this->_init_acl_config(); + $this->initAclConfig(); } /** @@ -171,24 +173,25 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { * @author Frank Schubert <frank@schokilade.de> * @author Andreas Gohr <andi@splitbrain.org> */ - function html() { + public function html() + { echo '<div id="acl_manager">'.NL; echo '<h1>'.$this->getLang('admin_acl').'</h1>'.NL; echo '<div class="level1">'.NL; echo '<div id="acl__tree">'.NL; - $this->_html_explorer(); + $this->makeExplorer(); echo '</div>'.NL; echo '<div id="acl__detail">'.NL; - $this->_html_detail(); + $this->printDetail(); echo '</div>'.NL; echo '</div>'.NL; echo '<div class="clearer"></div>'; echo '<h2>'.$this->getLang('current').'</h2>'.NL; echo '<div class="level2">'.NL; - $this->_html_table(); + $this->printAclTable(); echo '</div>'.NL; echo '<div class="footnotes"><div class="fn">'.NL; @@ -204,15 +207,16 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { * * @author Andreas Gohr <andi@splitbrain.org> */ - function _get_opts($addopts=null){ + protected function getLinkOptions($addopts = null) + { $opts = array( 'do'=>'admin', 'page'=>'acl', ); - if($this->ns) $opts['ns'] = $this->ns; - if($this->who) $opts['acl_w'] = $this->who; + if ($this->ns) $opts['ns'] = $this->ns; + if ($this->who) $opts['acl_w'] = $this->who; - if(is_null($addopts)) return $opts; + if (is_null($addopts)) return $opts; return array_merge($opts, $addopts); } @@ -221,54 +225,61 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { * * @author Andreas Gohr <andi@splitbrain.org> */ - function _html_explorer(){ + protected function makeExplorer() + { global $conf; global $ID; global $lang; $ns = $this->ns; - if(empty($ns)){ - $ns = dirname(str_replace(':','/',$ID)); - if($ns == '.') $ns =''; - }elseif($ns == '*'){ + if (empty($ns)) { + $ns = dirname(str_replace(':', '/', $ID)); + if ($ns == '.') $ns =''; + } elseif ($ns == '*') { $ns =''; } - $ns = utf8_encodeFN(str_replace(':','/',$ns)); + $ns = utf8_encodeFN(str_replace(':', '/', $ns)); - $data = $this->_get_tree($ns); + $data = $this->makeTree($ns); // wrap a list with the root level around the other namespaces array_unshift($data, array( 'level' => 0, 'id' => '*', 'type' => 'd', 'open' =>'true', 'label' => '['.$lang['mediaroot'].']')); - echo html_buildlist($data,'acl', - array($this,'_html_list_acl'), - array($this,'_html_li_acl')); - + echo html_buildlist( + $data, + 'acl', + array($this, 'makeTreeItem'), + array($this, 'makeListItem') + ); } /** * get a combined list of media and page files * + * also called via AJAX + * * @param string $folder an already converted filesystem folder of the current namespace - * @param string $limit limit the search to this folder + * @param string $limit limit the search to this folder + * @return array */ - function _get_tree($folder,$limit=''){ + public function makeTree($folder, $limit = '') + { global $conf; // read tree structure from pages and media $data = array(); - search($data,$conf['datadir'],'search_index',array('ns' => $folder),$limit); + search($data, $conf['datadir'], 'search_index', array('ns' => $folder), $limit); $media = array(); - search($media,$conf['mediadir'],'search_index',array('ns' => $folder, 'nofiles' => true),$limit); - $data = array_merge($data,$media); + search($media, $conf['mediadir'], 'search_index', array('ns' => $folder, 'nofiles' => true), $limit); + $data = array_merge($data, $media); unset($media); // combine by sorting and removing duplicates - usort($data,array($this,'_tree_sort')); + usort($data, array($this, 'treeSort')); $count = count($data); - if($count>0) for($i=1; $i<$count; $i++){ - if($data[$i-1]['id'] == $data[$i]['id'] && $data[$i-1]['type'] == $data[$i]['type']) { + if ($count>0) for ($i=1; $i<$count; $i++) { + if ($data[$i-1]['id'] == $data[$i]['id'] && $data[$i-1]['type'] == $data[$i]['type']) { unset($data[$i]); $i++; // duplicate found, next $i can't be a duplicate, so skip forward one } @@ -281,7 +292,8 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { * * Sorts the combined trees of media and page files */ - function _tree_sort($a,$b){ + public function treeSort($a, $b) + { // handle the trivial cases first if ($a['id'] == '') return -1; if ($b['id'] == '') return 1; @@ -315,6 +327,7 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { // before that other part. if (empty($a_ids)) return ($a['type'] == 'd') ? -1 : 1; if (empty($b_ids)) return ($b['type'] == 'd') ? 1 : -1; + return 0; //shouldn't happen } /** @@ -323,20 +336,21 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { * * @author Andreas Gohr <andi@splitbrain.org> */ - function _html_detail(){ + protected function printDetail() + { global $ID; echo '<form action="'.wl().'" method="post" accept-charset="utf-8"><div class="no">'.NL; echo '<div id="acl__user">'; echo $this->getLang('acl_perms').' '; - $inl = $this->_html_select(); - echo '<input type="text" name="acl_w" class="edit" value="'.(($inl)?'':hsc(ltrim($this->who,'@'))).'" />'.NL; + $inl = $this->makeSelect(); + echo '<input type="text" name="acl_w" class="edit" value="'.(($inl)?'':hsc(ltrim($this->who, '@'))).'" />'.NL; echo '<button type="submit">'.$this->getLang('btn_select').'</button>'.NL; echo '</div>'.NL; echo '<div id="acl__info">'; - $this->_html_info(); + $this->printInfo(); echo '</div>'; echo '<input type="hidden" name="ns" value="'.hsc($this->ns).'" />'.NL; @@ -349,23 +363,26 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { /** * Print info and editor + * + * also loaded via Ajax */ - function _html_info(){ + public function printInfo() + { global $ID; - if($this->who){ - $current = $this->_get_exact_perm(); + if ($this->who) { + $current = $this->getExactPermisson(); // explain current permissions - $this->_html_explain($current); + $this->printExplanation($current); // load editor - $this->_html_acleditor($current); - }else{ + $this->printAclEditor($current); + } else { echo '<p>'; - if($this->ns){ - printf($this->getLang('p_choose_ns'),hsc($this->ns)); - }else{ - printf($this->getLang('p_choose_id'),hsc($ID)); + if ($this->ns) { + printf($this->getLang('p_choose_ns'), hsc($this->ns)); + } else { + printf($this->getLang('p_choose_id'), hsc($ID)); } echo '</p>'; @@ -378,21 +395,22 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { * * @author Andreas Gohr <andi@splitbrain.org> */ - function _html_acleditor($current){ + protected function printAclEditor($current) + { global $lang; echo '<fieldset>'; - if(is_null($current)){ + if (is_null($current)) { echo '<legend>'.$this->getLang('acl_new').'</legend>'; - }else{ + } else { echo '<legend>'.$this->getLang('acl_mod').'</legend>'; } - echo $this->_html_checkboxes($current,empty($this->ns),'acl'); + echo $this->makeCheckboxes($current, empty($this->ns), 'acl'); - if(is_null($current)){ + if (is_null($current)) { echo '<button type="submit" name="cmd[save]">'.$lang['btn_save'].'</button>'.NL; - }else{ + } else { echo '<button type="submit" name="cmd[save]">'.$lang['btn_update'].'</button>'.NL; echo '<button type="submit" name="cmd[del]">'.$lang['btn_delete'].'</button>'.NL; } @@ -405,7 +423,8 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { * * @author Andreas Gohr <andi@splitbrain.org> */ - function _html_explain($current){ + protected function printExplanation($current) + { global $ID; global $auth; @@ -413,69 +432,69 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { $ns = $this->ns; // prepare where to check - if($ns){ - if($ns == '*'){ + if ($ns) { + if ($ns == '*') { $check='*'; - }else{ + } else { $check=$ns.':*'; } - }else{ + } else { $check = $ID; } // prepare who to check - if($who{0} == '@'){ + if ($who{0} == '@') { $user = ''; - $groups = array(ltrim($who,'@')); - }else{ + $groups = array(ltrim($who, '@')); + } else { $user = $who; $info = $auth->getUserData($user); - if($info === false){ + if ($info === false) { $groups = array(); - }else{ + } else { $groups = $info['grps']; } } // check the permissions - $perm = auth_aclcheck($check,$user,$groups); + $perm = auth_aclcheck($check, $user, $groups); // build array of named permissions $names = array(); - if($perm){ - if($ns){ - if($perm >= AUTH_DELETE) $names[] = $this->getLang('acl_perm16'); - if($perm >= AUTH_UPLOAD) $names[] = $this->getLang('acl_perm8'); - if($perm >= AUTH_CREATE) $names[] = $this->getLang('acl_perm4'); + if ($perm) { + if ($ns) { + if ($perm >= AUTH_DELETE) $names[] = $this->getLang('acl_perm16'); + if ($perm >= AUTH_UPLOAD) $names[] = $this->getLang('acl_perm8'); + if ($perm >= AUTH_CREATE) $names[] = $this->getLang('acl_perm4'); } - if($perm >= AUTH_EDIT) $names[] = $this->getLang('acl_perm2'); - if($perm >= AUTH_READ) $names[] = $this->getLang('acl_perm1'); + if ($perm >= AUTH_EDIT) $names[] = $this->getLang('acl_perm2'); + if ($perm >= AUTH_READ) $names[] = $this->getLang('acl_perm1'); $names = array_reverse($names); - }else{ + } else { $names[] = $this->getLang('acl_perm0'); } // print permission explanation echo '<p>'; - if($user){ - if($ns){ - printf($this->getLang('p_user_ns'),hsc($who),hsc($ns),join(', ',$names)); - }else{ - printf($this->getLang('p_user_id'),hsc($who),hsc($ID),join(', ',$names)); + if ($user) { + if ($ns) { + printf($this->getLang('p_user_ns'), hsc($who), hsc($ns), join(', ', $names)); + } else { + printf($this->getLang('p_user_id'), hsc($who), hsc($ID), join(', ', $names)); } - }else{ - if($ns){ - printf($this->getLang('p_group_ns'),hsc(ltrim($who,'@')),hsc($ns),join(', ',$names)); - }else{ - printf($this->getLang('p_group_id'),hsc(ltrim($who,'@')),hsc($ID),join(', ',$names)); + } else { + if ($ns) { + printf($this->getLang('p_group_ns'), hsc(ltrim($who, '@')), hsc($ns), join(', ', $names)); + } else { + printf($this->getLang('p_group_id'), hsc(ltrim($who, '@')), hsc($ID), join(', ', $names)); } } echo '</p>'; // add note if admin - if($perm == AUTH_ADMIN){ + if ($perm == AUTH_ADMIN) { echo '<p>'.$this->getLang('p_isadmin').'</p>'; - }elseif(is_null($current)){ + } elseif (is_null($current)) { echo '<p>'.$this->getLang('p_inherited').'</p>'; } } @@ -488,46 +507,57 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { * * @author Andreas Gohr <andi@splitbrain.org> */ - function _html_list_acl($item){ + protected function makeTreeItem($item) + { $ret = ''; // what to display - if(!empty($item['label'])){ + if (!empty($item['label'])) { $base = $item['label']; - }else{ + } else { $base = ':'.$item['id']; - $base = substr($base,strrpos($base,':')+1); + $base = substr($base, strrpos($base, ':')+1); } // highlight? - if( ($item['type']== $this->current_item['type'] && $item['id'] == $this->current_item['id'])) { + if (($item['type']== $this->current_item['type'] && $item['id'] == $this->current_item['id'])) { $cl = ' cur'; } else { $cl = ''; } // namespace or page? - if($item['type']=='d'){ - if($item['open']){ + if ($item['type']=='d') { + if ($item['open']) { $img = DOKU_BASE.'lib/images/minus.gif'; $alt = '−'; - }else{ + } else { $img = DOKU_BASE.'lib/images/plus.gif'; $alt = '+'; } $ret .= '<img src="'.$img.'" alt="'.$alt.'" />'; - $ret .= '<a href="'.wl('',$this->_get_opts(array('ns'=>$item['id'],'sectok'=>getSecurityToken()))).'" class="idx_dir'.$cl.'">'; + $ret .= '<a href="'. + wl('', $this->getLinkOptions(array('ns'=> $item['id'], 'sectok'=>getSecurityToken()))). + '" class="idx_dir'.$cl.'">'; $ret .= $base; $ret .= '</a>'; - }else{ - $ret .= '<a href="'.wl('',$this->_get_opts(array('id'=>$item['id'],'ns'=>'','sectok'=>getSecurityToken()))).'" class="wikilink1'.$cl.'">'; + } else { + $ret .= '<a href="'. + wl('', $this->getLinkOptions(array('id'=> $item['id'], 'ns'=>'', 'sectok'=>getSecurityToken()))). + '" class="wikilink1'.$cl.'">'; $ret .= noNS($item['id']); $ret .= '</a>'; } return $ret; } - - function _html_li_acl($item){ + /** + * List Item formatter + * + * @param array $item + * @return string + */ + public function makeListItem($item) + { return '<li class="level' . $item['level'] . ' ' . ($item['open'] ? 'open' : 'closed') . '">'; } @@ -538,7 +568,8 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { * * @author Andreas Gohr <andi@splitbrain.org> */ - function _init_acl_config(){ + public function initAclConfig() + { global $AUTH_ACL; global $conf; $acl_config=array(); @@ -547,20 +578,24 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { // get special users and groups $this->specials[] = '@ALL'; $this->specials[] = '@'.$conf['defaultgroup']; - if($conf['manager'] != '!!not set!!'){ - $this->specials = array_merge($this->specials, - array_map('trim', - explode(',',$conf['manager']))); + if ($conf['manager'] != '!!not set!!') { + $this->specials = array_merge( + $this->specials, + array_map( + 'trim', + explode(',', $conf['manager']) + ) + ); } $this->specials = array_filter($this->specials); $this->specials = array_unique($this->specials); sort($this->specials); - foreach($AUTH_ACL as $line){ - $line = trim(preg_replace('/#.*$/','',$line)); //ignore comments - if(!$line) continue; + foreach ($AUTH_ACL as $line) { + $line = trim(preg_replace('/#.*$/', '', $line)); //ignore comments + if (!$line) continue; - $acl = preg_split('/[ \t]+/',$line); + $acl = preg_split('/[ \t]+/', $line); //0 is pagename, 1 is user, 2 is acl $acl[1] = rawurldecode($acl[1]); @@ -568,7 +603,7 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { // store non-special users and groups for later selection dialog $ug = $acl[1]; - if(in_array($ug,$this->specials)) continue; + if (in_array($ug, $this->specials)) continue; $usersgroups[] = $ug; } @@ -585,14 +620,15 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { * * @author Andreas Gohr <andi@splitbrain.org> */ - function _html_table(){ + protected function printAclTable() + { global $lang; global $ID; echo '<form action="'.wl().'" method="post" accept-charset="utf-8"><div class="no">'.NL; - if($this->ns){ + if ($this->ns) { echo '<input type="hidden" name="ns" value="'.hsc($this->ns).'" />'.NL; - }else{ + } else { echo '<input type="hidden" name="id" value="'.hsc($ID).'" />'.NL; } echo '<input type="hidden" name="acl_w" value="'.hsc($this->who).'" />'.NL; @@ -607,29 +643,29 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { echo '<th>'.$this->getLang('perm').'<sup><a id="fnt__1" class="fn_top" href="#fn__1">1)</a></sup></th>'; echo '<th>'.$lang['btn_delete'].'</th>'; echo '</tr>'; - foreach($this->acl as $where => $set){ - foreach($set as $who => $perm){ + foreach ($this->acl as $where => $set) { + foreach ($set as $who => $perm) { echo '<tr>'; echo '<td>'; - if(substr($where,-1) == '*'){ + if (substr($where, -1) == '*') { echo '<span class="aclns">'.hsc($where).'</span>'; $ispage = false; - }else{ + } else { echo '<span class="aclpage">'.hsc($where).'</span>'; $ispage = true; } echo '</td>'; echo '<td>'; - if($who{0} == '@'){ + if ($who{0} == '@') { echo '<span class="aclgroup">'.hsc($who).'</span>'; - }else{ + } else { echo '<span class="acluser">'.hsc($who).'</span>'; } echo '</td>'; echo '<td>'; - echo $this->_html_checkboxes($perm,$ispage,'acl['.$where.']['.$who.']'); + echo $this->makeCheckboxes($perm, $ispage, 'acl['.$where.']['.$who.']'); echo '</td>'; echo '<td class="check">'; @@ -655,21 +691,22 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { * * @author Andreas Gohr <andi@splitbrain.org> */ - function _get_exact_perm(){ + protected function getExactPermisson() + { global $ID; - if($this->ns){ - if($this->ns == '*'){ + if ($this->ns) { + if ($this->ns == '*') { $check = '*'; - }else{ + } else { $check = $this->ns.':*'; } - }else{ + } else { $check = $ID; } - if(isset($this->acl[$check][$this->who])){ + if (isset($this->acl[$check][$this->who])) { return $this->acl[$check][$this->who]; - }else{ + } else { return null; } } @@ -679,13 +716,14 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { * * @author Frank Schubert <frank@schokilade.de> */ - function _acl_add($acl_scope, $acl_user, $acl_level){ + public function addACL($acl_scope, $acl_user, $acl_level) + { global $config_cascade; - $acl_user = auth_nameencode($acl_user,true); + $acl_user = auth_nameencode($acl_user, true); // max level for pagenames is edit - if(strpos($acl_scope,'*') === false) { - if($acl_level > AUTH_EDIT) $acl_level = AUTH_EDIT; + if (strpos($acl_scope, '*') === false) { + if ($acl_level > AUTH_EDIT) $acl_level = AUTH_EDIT; } $new_acl = "$acl_scope\t$acl_user\t$acl_level\n"; @@ -698,11 +736,12 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { * * @author Frank Schubert <frank@schokilade.de> */ - function _acl_del($acl_scope, $acl_user){ + public function deleteACL($acl_scope, $acl_user) + { global $config_cascade; - $acl_user = auth_nameencode($acl_user,true); + $acl_user = auth_nameencode($acl_user, true); - $acl_pattern = '^'.preg_quote($acl_scope,'/').'[ \t]+'.$acl_user.'[ \t]+[0-8].*$'; + $acl_pattern = '^'.preg_quote($acl_scope, '/').'[ \t]+'.$acl_user.'[ \t]+[0-8].*$'; return io_deleteFromFile($config_cascade['acl']['default'], "/$acl_pattern/", true); } @@ -713,15 +752,16 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { * @author Frank Schubert <frank@schokilade.de> * @author Andreas Gohr <andi@splitbrain.org> */ - function _html_checkboxes($setperm,$ispage,$name){ + protected function makeCheckboxes($setperm, $ispage, $name) + { global $lang; static $label = 0; //number labels $ret = ''; - if($ispage && $setperm > AUTH_EDIT) $setperm = AUTH_EDIT; + if ($ispage && $setperm > AUTH_EDIT) $setperm = AUTH_EDIT; - foreach(array(AUTH_NONE,AUTH_READ,AUTH_EDIT,AUTH_CREATE,AUTH_UPLOAD,AUTH_DELETE) as $perm){ + foreach (array(AUTH_NONE,AUTH_READ,AUTH_EDIT,AUTH_CREATE,AUTH_UPLOAD,AUTH_DELETE) as $perm) { $label += 1; //general checkbox attributes @@ -730,11 +770,11 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { 'name' => $name, 'value' => $perm ); //dynamic attributes - if(!is_null($setperm) && $setperm == $perm) $atts['checked'] = 'checked'; - if($ispage && $perm > AUTH_EDIT){ + if (!is_null($setperm) && $setperm == $perm) $atts['checked'] = 'checked'; + if ($ispage && $perm > AUTH_EDIT) { $atts['disabled'] = 'disabled'; $class = ' class="disabled"'; - }else{ + } else { $class = ''; } @@ -752,21 +792,21 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { * * @author Andreas Gohr <andi@splitbrain.org> */ - function _html_select(){ + protected function makeSelect() + { $inlist = false; $usel = ''; $gsel = ''; - if($this->who && - !in_array($this->who,$this->usersgroups) && - !in_array($this->who,$this->specials)){ - - if($this->who{0} == '@'){ + if ($this->who && + !in_array($this->who, $this->usersgroups) && + !in_array($this->who, $this->specials)) { + if ($this->who{0} == '@') { $gsel = ' selected="selected"'; - }else{ + } else { $usel = ' selected="selected"'; } - }else{ + } else { $inlist = true; } @@ -775,17 +815,17 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { echo ' <option value="__u__" class="acluser"'.$usel.'>'.$this->getLang('acl_user').'</option>'.NL; if (!empty($this->specials)) { echo ' <optgroup label=" ">'.NL; - foreach($this->specials as $ug){ - if($ug == $this->who){ + foreach ($this->specials as $ug) { + if ($ug == $this->who) { $sel = ' selected="selected"'; $inlist = true; - }else{ + } else { $sel = ''; } - if($ug{0} == '@'){ + if ($ug{0} == '@') { echo ' <option value="'.hsc($ug).'" class="aclgroup"'.$sel.'>'.hsc($ug).'</option>'.NL; - }else{ + } else { echo ' <option value="'.hsc($ug).'" class="acluser"'.$sel.'>'.hsc($ug).'</option>'.NL; } } @@ -793,17 +833,17 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { } if (!empty($this->usersgroups)) { echo ' <optgroup label=" ">'.NL; - foreach($this->usersgroups as $ug){ - if($ug == $this->who){ + foreach ($this->usersgroups as $ug) { + if ($ug == $this->who) { $sel = ' selected="selected"'; $inlist = true; - }else{ + } else { $sel = ''; } - if($ug{0} == '@'){ + if ($ug{0} == '@') { echo ' <option value="'.hsc($ug).'" class="aclgroup"'.$sel.'>'.hsc($ug).'</option>'.NL; - }else{ + } else { echo ' <option value="'.hsc($ug).'" class="acluser"'.$sel.'>'.hsc($ug).'</option>'.NL; } } diff --git a/lib/plugins/acl/remote.php b/lib/plugins/acl/remote.php index 27c5c162a..31a8cde53 100644 --- a/lib/plugins/acl/remote.php +++ b/lib/plugins/acl/remote.php @@ -1,16 +1,20 @@ <?php +use dokuwiki\Remote\AccessDeniedException; + /** * Class remote_plugin_acl */ -class remote_plugin_acl extends DokuWiki_Remote_Plugin { +class remote_plugin_acl extends DokuWiki_Remote_Plugin +{ /** * Returns details about the remote plugin methods * - * @return array Information about all provided methods. {@see RemoteAPI} + * @return array Information about all provided methods. {@see dokuwiki\Remote\RemoteAPI} */ - public function _getMethods() { + public function _getMethods() + { return array( 'listAcls' => array( 'args' => array(), @@ -34,16 +38,20 @@ class remote_plugin_acl extends DokuWiki_Remote_Plugin { /** * List all ACL config entries * - * @throws RemoteAccessDeniedException + * @throws AccessDeniedException * @return dictionary {Scope: ACL}, where ACL = dictionnary {user/group: permissions_int} */ - public function listAcls(){ - if(!auth_isadmin()) { - throw new RemoteAccessDeniedException('You are not allowed to access ACLs, superuser permission is required', 114); + public function listAcls() + { + if (!auth_isadmin()) { + throw new AccessDeniedException( + 'You are not allowed to access ACLs, superuser permission is required', + 114 + ); } /** @var admin_plugin_acl $apa */ $apa = plugin_load('admin', 'acl'); - $apa->_init_acl_config(); + $apa->initAclConfig(); return $apa->acl; } @@ -53,17 +61,21 @@ class remote_plugin_acl extends DokuWiki_Remote_Plugin { * @param string $scope * @param string $user * @param int $level see also inc/auth.php - * @throws RemoteAccessDeniedException + * @throws AccessDeniedException * @return bool */ - public function addAcl($scope, $user, $level){ - if(!auth_isadmin()) { - throw new RemoteAccessDeniedException('You are not allowed to access ACLs, superuser permission is required', 114); + public function addAcl($scope, $user, $level) + { + if (!auth_isadmin()) { + throw new AccessDeniedException( + 'You are not allowed to access ACLs, superuser permission is required', + 114 + ); } /** @var admin_plugin_acl $apa */ $apa = plugin_load('admin', 'acl'); - return $apa->_acl_add($scope, $user, $level); + return $apa->addACL($scope, $user, $level); } /** @@ -71,17 +83,20 @@ class remote_plugin_acl extends DokuWiki_Remote_Plugin { * * @param string $scope * @param string $user - * @throws RemoteAccessDeniedException + * @throws AccessDeniedException * @return bool */ - public function delAcl($scope, $user){ - if(!auth_isadmin()) { - throw new RemoteAccessDeniedException('You are not allowed to access ACLs, superuser permission is required', 114); + public function delAcl($scope, $user) + { + if (!auth_isadmin()) { + throw new AccessDeniedException( + 'You are not allowed to access ACLs, superuser permission is required', + 114 + ); } /** @var admin_plugin_acl $apa */ $apa = plugin_load('admin', 'acl'); - return $apa->_acl_del($scope, $user); + return $apa->deleteACL($scope, $user); } } - diff --git a/lib/plugins/action.php b/lib/plugins/action.php index 23d94a509..496c56926 100644 --- a/lib/plugins/action.php +++ b/lib/plugins/action.php @@ -2,24 +2,18 @@ /** * Action Plugin Prototype * - * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) - * @author Christopher Smith <chris@jalakai.co.uk> - */ -// must be run within Dokuwiki -if(!defined('DOKU_INC')) die(); - -/** * All DokuWiki plugins to interfere with the event system * need to inherit from this class + * + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * @author Christopher Smith <chris@jalakai.co.uk> */ -class DokuWiki_Action_Plugin extends DokuWiki_Plugin { +abstract class DokuWiki_Action_Plugin extends DokuWiki_Plugin { /** * Registers a callback function for a given event * * @param Doku_Event_Handler $controller */ - public function register(Doku_Event_Handler $controller) { - trigger_error('register() not implemented in '.get_class($this), E_USER_WARNING); - } + abstract public function register(Doku_Event_Handler $controller); } diff --git a/lib/plugins/admin.php b/lib/plugins/admin.php index 4e1cbbb33..a1d99a412 100644 --- a/lib/plugins/admin.php +++ b/lib/plugins/admin.php @@ -2,17 +2,13 @@ /** * Admin Plugin Prototype * - * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) - * @author Christopher Smith <chris@jalakai.co.uk> - */ -// must be run within Dokuwiki -if(!defined('DOKU_INC')) die(); - -/** * All DokuWiki plugins to extend the admin function * need to inherit from this class + * + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * @author Christopher Smith <chris@jalakai.co.uk> */ -class DokuWiki_Admin_Plugin extends DokuWiki_Plugin { +abstract class DokuWiki_Admin_Plugin extends DokuWiki_Plugin { /** * Return the text that is displayed at the main admin menu @@ -62,15 +58,13 @@ class DokuWiki_Admin_Plugin extends DokuWiki_Plugin { * Carry out required processing */ public function handle() { - trigger_error('handle() not implemented in '.get_class($this), E_USER_WARNING); + // some plugins might not need this } /** * Output html of the admin page */ - public function html() { - trigger_error('html() not implemented in '.get_class($this), E_USER_WARNING); - } + abstract public function html(); /** * Return true for access only by admins (config:superuser) or false if managers are allowed as well diff --git a/lib/plugins/auth.php b/lib/plugins/auth.php index 0cd965b72..442580b23 100644 --- a/lib/plugins/auth.php +++ b/lib/plugins/auth.php @@ -1,7 +1,4 @@ <?php -// must be run within Dokuwiki -if(!defined('DOKU_INC')) die(); - /** * Auth Plugin Prototype * @@ -12,7 +9,7 @@ if(!defined('DOKU_INC')) die(); * @author Chris Smith <chris@jalakai.co.uk> * @author Jan Schumann <js@jschumann-it.com> */ -class DokuWiki_Auth_Plugin extends DokuWiki_Plugin { +abstract class DokuWiki_Auth_Plugin extends DokuWiki_Plugin { public $success = true; /** @@ -115,7 +112,8 @@ class DokuWiki_Auth_Plugin extends DokuWiki_Plugin { * * @author Gabriel Birke <birke@d-scribe.de> * @param string $type Modification type ('create', 'modify', 'delete') - * @param array $params Parameters for the createUser, modifyUser or deleteUsers method. The content of this array depends on the modification type + * @param array $params Parameters for the createUser, modifyUser or deleteUsers method. + * The content of this array depends on the modification type * @return bool|null|int Result from the modification function or false if an event handler has canceled the action */ public function triggerUserMod($type, $params) { @@ -132,7 +130,7 @@ class DokuWiki_Auth_Plugin extends DokuWiki_Plugin { $eventdata = array('type' => $type, 'params' => $params, 'modification_result' => null); $evt = new Doku_Event('AUTH_USER_CHANGE', $eventdata); if($evt->advise_before(true)) { - $result = call_user_func_array(array($this, $validTypes[$type]), $evt->data['params']); + $result = call_user_func_array(array($this, $validTypes[$type]), $evt->data['params']); $evt->data['modification_result'] = $result; } $evt->advise_after(); diff --git a/lib/plugins/authad/action.php b/lib/plugins/authad/action.php index bc0f90c7e..a9fc01c1b 100644 --- a/lib/plugins/authad/action.php +++ b/lib/plugins/authad/action.php @@ -6,22 +6,20 @@ * @author Andreas Gohr <gohr@cosmocode.de> */ -// must be run within Dokuwiki -if(!defined('DOKU_INC')) die(); - /** * Class action_plugin_addomain */ -class action_plugin_authad extends DokuWiki_Action_Plugin { +class action_plugin_authad extends DokuWiki_Action_Plugin +{ /** * Registers a callback function for a given event */ - public function register(Doku_Event_Handler $controller) { - - $controller->register_hook('AUTH_LOGIN_CHECK', 'BEFORE', $this, 'handle_auth_login_check'); - $controller->register_hook('HTML_LOGINFORM_OUTPUT', 'BEFORE', $this, 'handle_html_loginform_output'); + public function register(Doku_Event_Handler $controller) + { + $controller->register_hook('AUTH_LOGIN_CHECK', 'BEFORE', $this, 'handleAuthLoginCheck'); + $controller->register_hook('HTML_LOGINFORM_OUTPUT', 'BEFORE', $this, 'handleHtmlLoginformOutput'); } /** @@ -30,17 +28,18 @@ class action_plugin_authad extends DokuWiki_Action_Plugin { * @param Doku_Event $event * @param array $param */ - public function handle_auth_login_check(Doku_Event &$event, $param) { + public function handleAuthLoginCheck(Doku_Event $event, $param) + { global $INPUT; /** @var auth_plugin_authad $auth */ global $auth; - if(!is_a($auth, 'auth_plugin_authad')) return; // AD not even used + if (!is_a($auth, 'auth_plugin_authad')) return; // AD not even used - if($INPUT->str('dom')) { + if ($INPUT->str('dom')) { $usr = $auth->cleanUser($event->data['user']); - $dom = $auth->_userDomain($usr); - if(!$dom) { + $dom = $auth->getUserDomain($usr); + if (!$dom) { $usr = "$usr@".$INPUT->str('dom'); } $INPUT->post->set('u', $usr); @@ -54,26 +53,27 @@ class action_plugin_authad extends DokuWiki_Action_Plugin { * @param Doku_Event $event * @param array $param */ - public function handle_html_loginform_output(Doku_Event &$event, $param) { + public function handleHtmlLoginformOutput(Doku_Event $event, $param) + { global $INPUT; /** @var auth_plugin_authad $auth */ global $auth; - if(!is_a($auth, 'auth_plugin_authad')) return; // AD not even used - $domains = $auth->_getConfiguredDomains(); - if(count($domains) <= 1) return; // no choice at all + if (!is_a($auth, 'auth_plugin_authad')) return; // AD not even used + $domains = $auth->getConfiguredDomains(); + if (count($domains) <= 1) return; // no choice at all /** @var Doku_Form $form */ $form =& $event->data; // any default? $dom = ''; - if($INPUT->has('u')) { + if ($INPUT->has('u')) { $usr = $auth->cleanUser($INPUT->str('u')); - $dom = $auth->_userDomain($usr); + $dom = $auth->getUserDomain($usr); // update user field value - if($dom) { - $usr = $auth->_userName($usr); + if ($dom) { + $usr = $auth->getUserName($usr); $pos = $form->findElementByAttribute('name', 'u'); $ele =& $form->getElementAt($pos); $ele['value'] = $usr; @@ -85,7 +85,6 @@ class action_plugin_authad extends DokuWiki_Action_Plugin { $pos = $form->findElementByAttribute('name', 'p'); $form->insertElement($pos + 1, $element); } - } -// vim:ts=4:sw=4:et:
\ No newline at end of file +// vim:ts=4:sw=4:et: diff --git a/lib/plugins/authad/auth.php b/lib/plugins/authad/auth.php index 50f708456..30c128792 100644 --- a/lib/plugins/authad/auth.php +++ b/lib/plugins/authad/auth.php @@ -1,9 +1,4 @@ <?php -// must be run within Dokuwiki -if(!defined('DOKU_INC')) die(); - -require_once(DOKU_PLUGIN.'authad/adLDAP/adLDAP.php'); -require_once(DOKU_PLUGIN.'authad/adLDAP/classes/adLDAPUtils.php'); /** * Active Directory authentication backend for DokuWiki @@ -41,7 +36,8 @@ require_once(DOKU_PLUGIN.'authad/adLDAP/classes/adLDAPUtils.php'); * @author Andreas Gohr <andi@splitbrain.org> * @author Jan Schumann <js@schumann-it.com> */ -class auth_plugin_authad extends DokuWiki_Auth_Plugin { +class auth_plugin_authad extends DokuWiki_Auth_Plugin +{ /** * @var array hold connection data for a specific AD domain @@ -66,52 +62,55 @@ class auth_plugin_authad extends DokuWiki_Auth_Plugin { /** * @var array filter patterns for listing users */ - protected $_pattern = array(); + protected $pattern = array(); - protected $_actualstart = 0; + protected $actualstart = 0; - protected $_grpsusers = array(); + protected $grpsusers = array(); /** * Constructor */ - public function __construct() { + public function __construct() + { global $INPUT; parent::__construct(); + require_once(DOKU_PLUGIN.'authad/adLDAP/adLDAP.php'); + require_once(DOKU_PLUGIN.'authad/adLDAP/classes/adLDAPUtils.php'); + // we load the config early to modify it a bit here $this->loadConfig(); // additional information fields - if(isset($this->conf['additional'])) { + if (isset($this->conf['additional'])) { $this->conf['additional'] = str_replace(' ', '', $this->conf['additional']); $this->conf['additional'] = explode(',', $this->conf['additional']); } else $this->conf['additional'] = array(); // ldap extension is needed - if(!function_exists('ldap_connect')) { - if($this->conf['debug']) + if (!function_exists('ldap_connect')) { + if ($this->conf['debug']) msg("AD Auth: PHP LDAP extension not found.", -1); $this->success = false; return; } // Prepare SSO - if(!empty($_SERVER['REMOTE_USER'])) { - + if (!empty($_SERVER['REMOTE_USER'])) { // make sure the right encoding is used - if($this->getConf('sso_charset')) { + if ($this->getConf('sso_charset')) { $_SERVER['REMOTE_USER'] = iconv($this->getConf('sso_charset'), 'UTF-8', $_SERVER['REMOTE_USER']); - } elseif(!utf8_check($_SERVER['REMOTE_USER'])) { + } elseif (!utf8_check($_SERVER['REMOTE_USER'])) { $_SERVER['REMOTE_USER'] = utf8_encode($_SERVER['REMOTE_USER']); } // trust the incoming user - if($this->conf['sso']) { + if ($this->conf['sso']) { $_SERVER['REMOTE_USER'] = $this->cleanUser($_SERVER['REMOTE_USER']); // we need to simulate a login - if(empty($_COOKIE[DOKU_COOKIE])) { + if (empty($_COOKIE[DOKU_COOKIE])) { $INPUT->set('u', $_SERVER['REMOTE_USER']); $INPUT->set('p', 'sso_only'); } @@ -130,10 +129,11 @@ class auth_plugin_authad extends DokuWiki_Auth_Plugin { * @param string $cap * @return bool */ - public function canDo($cap) { + public function canDo($cap) + { //capabilities depend on config, which may change depending on domain - $domain = $this->_userDomain($_SERVER['REMOTE_USER']); - $this->_loadServerConfig($domain); + $domain = $this->getUserDomain($_SERVER['REMOTE_USER']); + $this->loadServerConfig($domain); return parent::canDo($cap); } @@ -149,16 +149,22 @@ class auth_plugin_authad extends DokuWiki_Auth_Plugin { * @param string $pass * @return bool */ - public function checkPass($user, $pass) { - if($_SERVER['REMOTE_USER'] && + public function checkPass($user, $pass) + { + if ($_SERVER['REMOTE_USER'] && $_SERVER['REMOTE_USER'] == $user && $this->conf['sso'] ) return true; - $adldap = $this->_adldap($this->_userDomain($user)); - if(!$adldap) return false; + $adldap = $this->initAdLdap($this->getUserDomain($user)); + if (!$adldap) return false; - return $adldap->authenticate($this->_userName($user), $pass); + try { + return $adldap->authenticate($this->getUserName($user), $pass); + } catch (adLDAPException $e) { + // shouldn't really happen + return false; + } } /** @@ -186,14 +192,15 @@ class auth_plugin_authad extends DokuWiki_Auth_Plugin { * @param bool $requireGroups (optional) - ignored, groups are always supplied by this plugin * @return array */ - public function getUserData($user, $requireGroups=true) { + public function getUserData($user, $requireGroups = true) + { global $conf; global $lang; global $ID; - $adldap = $this->_adldap($this->_userDomain($user)); - if(!$adldap) return false; + $adldap = $this->initAdLdap($this->getUserDomain($user)); + if (!$adldap) return array(); - if($user == '') return array(); + if ($user == '') return array(); $fields = array('mail', 'displayname', 'samaccountname', 'lastpwd', 'pwdlastset', 'useraccountcontrol'); @@ -203,8 +210,8 @@ class auth_plugin_authad extends DokuWiki_Auth_Plugin { $fields = array_filter($fields); //get info for given user - $result = $adldap->user()->info($this->_userName($user), $fields); - if($result == false){ + $result = $adldap->user()->info($this->getUserName($user), $fields); + if ($result == false) { return array(); } @@ -220,52 +227,56 @@ class auth_plugin_authad extends DokuWiki_Auth_Plugin { $info['expires'] = !($result[0]['useraccountcontrol'][0] & 0x10000); //ADS_UF_DONT_EXPIRE_PASSWD // additional information - foreach($this->conf['additional'] as $field) { - if(isset($result[0][strtolower($field)])) { + foreach ($this->conf['additional'] as $field) { + if (isset($result[0][strtolower($field)])) { $info[$field] = $result[0][strtolower($field)][0]; } } // handle ActiveDirectory memberOf - $info['grps'] = $adldap->user()->groups($this->_userName($user),(bool) $this->opts['recursive_groups']); + $info['grps'] = $adldap->user()->groups($this->getUserName($user), (bool) $this->opts['recursive_groups']); - if(is_array($info['grps'])) { - foreach($info['grps'] as $ndx => $group) { + if (is_array($info['grps'])) { + foreach ($info['grps'] as $ndx => $group) { $info['grps'][$ndx] = $this->cleanGroup($group); } } // always add the default group to the list of groups - if(!is_array($info['grps']) || !in_array($conf['defaultgroup'], $info['grps'])) { + if (!is_array($info['grps']) || !in_array($conf['defaultgroup'], $info['grps'])) { $info['grps'][] = $conf['defaultgroup']; } // add the user's domain to the groups - $domain = $this->_userDomain($user); - if($domain && !in_array("domain-$domain", (array) $info['grps'])) { + $domain = $this->getUserDomain($user); + if ($domain && !in_array("domain-$domain", (array) $info['grps'])) { $info['grps'][] = $this->cleanGroup("domain-$domain"); } // check expiry time - if($info['expires'] && $this->conf['expirywarn']){ - $expiry = $adldap->user()->passwordExpiry($user); - if(is_array($expiry)){ - $info['expiresat'] = $expiry['expiryts']; - $info['expiresin'] = round(($info['expiresat'] - time())/(24*60*60)); - - // if this is the current user, warn him (once per request only) - if(($_SERVER['REMOTE_USER'] == $user) && - ($info['expiresin'] <= $this->conf['expirywarn']) && - !$this->msgshown - ) { - $msg = sprintf($this->getLang('authpwdexpire'), $info['expiresin']); - if($this->canDo('modPass')) { - $url = wl($ID, array('do'=> 'profile')); - $msg .= ' <a href="'.$url.'">'.$lang['btn_profile'].'</a>'; + if ($info['expires'] && $this->conf['expirywarn']) { + try { + $expiry = $adldap->user()->passwordExpiry($user); + if (is_array($expiry)) { + $info['expiresat'] = $expiry['expiryts']; + $info['expiresin'] = round(($info['expiresat'] - time())/(24*60*60)); + + // if this is the current user, warn him (once per request only) + if (($_SERVER['REMOTE_USER'] == $user) && + ($info['expiresin'] <= $this->conf['expirywarn']) && + !$this->msgshown + ) { + $msg = sprintf($this->getLang('authpwdexpire'), $info['expiresin']); + if ($this->canDo('modPass')) { + $url = wl($ID, array('do'=> 'profile')); + $msg .= ' <a href="'.$url.'">'.$lang['btn_profile'].'</a>'; + } + msg($msg); + $this->msgshown = true; } - msg($msg); - $this->msgshown = true; } + } catch (adLDAPException $e) { + // ignore. should usually not happen } } @@ -281,7 +292,8 @@ class auth_plugin_authad extends DokuWiki_Auth_Plugin { * @param string $group * @return string */ - public function cleanGroup($group) { + public function cleanGroup($group) + { $group = str_replace('\\', '', $group); $group = str_replace('#', '', $group); $group = preg_replace('[\s]', '_', $group); @@ -298,27 +310,28 @@ class auth_plugin_authad extends DokuWiki_Auth_Plugin { * @param string $user * @return string */ - public function cleanUser($user) { + public function cleanUser($user) + { $domain = ''; // get NTLM or Kerberos domain part list($dom, $user) = explode('\\', $user, 2); - if(!$user) $user = $dom; - if($dom) $domain = $dom; + if (!$user) $user = $dom; + if ($dom) $domain = $dom; list($user, $dom) = explode('@', $user, 2); - if($dom) $domain = $dom; + if ($dom) $domain = $dom; // clean up both $domain = utf8_strtolower(trim($domain)); $user = utf8_strtolower(trim($user)); // is this a known, valid domain? if not discard - if(!is_array($this->conf[$domain])) { + if (!is_array($this->conf[$domain])) { $domain = ''; } // reattach domain - if($domain) $user = "$user@$domain"; + if ($domain) $user = "$user@$domain"; return $user; } @@ -327,7 +340,8 @@ class auth_plugin_authad extends DokuWiki_Auth_Plugin { * * @return bool */ - public function isCaseSensitive() { + public function isCaseSensitive() + { return false; } @@ -337,11 +351,12 @@ class auth_plugin_authad extends DokuWiki_Auth_Plugin { * @param array $filter * @return string */ - protected function _constructSearchString($filter){ - if (!$filter){ + protected function constructSearchString($filter) + { + if (!$filter) { return '*'; } - $adldapUtils = new adLDAPUtils($this->_adldap(null)); + $adldapUtils = new adLDAPUtils($this->initAdLdap(null)); $result = '*'; if (isset($filter['name'])) { $result .= ')(displayname=*' . $adldapUtils->ldapSlashes($filter['name']) . '*'; @@ -366,32 +381,41 @@ class auth_plugin_authad extends DokuWiki_Auth_Plugin { * @param array $filter $filter array of field/pattern pairs, empty array for no filter * @return int number of users */ - public function getUserCount($filter = array()) { - $adldap = $this->_adldap(null); - if(!$adldap) { + public function getUserCount($filter = array()) + { + $adldap = $this->initAdLdap(null); + if (!$adldap) { dbglog("authad/auth.php getUserCount(): _adldap not set."); return -1; } if ($filter == array()) { $result = $adldap->user()->all(); } else { - $searchString = $this->_constructSearchString($filter); + $searchString = $this->constructSearchString($filter); $result = $adldap->user()->all(false, $searchString); if (isset($filter['grps'])) { $this->users = array_fill_keys($result, false); + /** @var admin_plugin_usermanager $usermanager */ $usermanager = plugin_load("admin", "usermanager", false); $usermanager->setLastdisabled(true); - if (!isset($this->_grpsusers[$this->_filterToString($filter)])){ - $this->_fillGroupUserArray($filter,$usermanager->getStart() + 3*$usermanager->getPagesize()); - } elseif (count($this->_grpsusers[$this->_filterToString($filter)]) < $usermanager->getStart() + 3*$usermanager->getPagesize()) { - $this->_fillGroupUserArray($filter,$usermanager->getStart() + 3*$usermanager->getPagesize() - count($this->_grpsusers[$this->_filterToString($filter)])); + if (!isset($this->grpsusers[$this->filterToString($filter)])) { + $this->fillGroupUserArray($filter, $usermanager->getStart() + 3*$usermanager->getPagesize()); + } elseif (count($this->grpsusers[$this->filterToString($filter)]) < + $usermanager->getStart() + 3*$usermanager->getPagesize() + ) { + $this->fillGroupUserArray( + $filter, + $usermanager->getStart() + + 3*$usermanager->getPagesize() - + count($this->grpsusers[$this->filterToString($filter)]) + ); } - $result = $this->_grpsusers[$this->_filterToString($filter)]; + $result = $this->grpsusers[$this->filterToString($filter)]; } else { + /** @var admin_plugin_usermanager $usermanager */ $usermanager = plugin_load("admin", "usermanager", false); $usermanager->setLastdisabled(false); } - } if (!$result) { @@ -407,7 +431,8 @@ class auth_plugin_authad extends DokuWiki_Auth_Plugin { * @param array $filter * @return string */ - protected function _filterToString ($filter) { + protected function filterToString($filter) + { $result = ''; if (isset($filter['user'])) { $result .= 'user-' . $filter['user']; @@ -433,24 +458,25 @@ class auth_plugin_authad extends DokuWiki_Auth_Plugin { * @param int $numberOfAdds additional number of users requested * @return int number of Users actually add to Array */ - protected function _fillGroupUserArray($filter, $numberOfAdds){ - $this->_grpsusers[$this->_filterToString($filter)]; + protected function fillGroupUserArray($filter, $numberOfAdds) + { + $this->grpsusers[$this->filterToString($filter)]; $i = 0; $count = 0; - $this->_constructPattern($filter); + $this->constructPattern($filter); foreach ($this->users as $user => &$info) { - if($i++ < $this->_actualstart) { + if ($i++ < $this->actualstart) { continue; } - if($info === false) { + if ($info === false) { $info = $this->getUserData($user); } - if($this->_filter($user, $info)) { - $this->_grpsusers[$this->_filterToString($filter)][$user] = $info; - if(($numberOfAdds > 0) && (++$count >= $numberOfAdds)) break; + if ($this->filter($user, $info)) { + $this->grpsusers[$this->filterToString($filter)][$user] = $info; + if (($numberOfAdds > 0) && (++$count >= $numberOfAdds)) break; } } - $this->_actualstart = $i; + $this->actualstart = $i; return $count; } @@ -464,13 +490,14 @@ class auth_plugin_authad extends DokuWiki_Auth_Plugin { * @param array $filter array of field/pattern pairs, null for no filter * @return array userinfo (refer getUserData for internal userinfo details) */ - public function retrieveUsers($start = 0, $limit = 0, $filter = array()) { - $adldap = $this->_adldap(null); - if(!$adldap) return false; + public function retrieveUsers($start = 0, $limit = 0, $filter = array()) + { + $adldap = $this->initAdLdap(null); + if (!$adldap) return array(); - if(!$this->users) { + if (!$this->users) { //get info for given user - $result = $adldap->user()->all(false, $this->_constructSearchString($filter)); + $result = $adldap->user()->all(false, $this->constructSearchString($filter)); if (!$result) return array(); $this->users = array_fill_keys($result, false); } @@ -480,34 +507,40 @@ class auth_plugin_authad extends DokuWiki_Auth_Plugin { $result = array(); if (!isset($filter['grps'])) { + /** @var admin_plugin_usermanager $usermanager */ $usermanager = plugin_load("admin", "usermanager", false); $usermanager->setLastdisabled(false); - $this->_constructPattern($filter); - foreach($this->users as $user => &$info) { - if($i++ < $start) { + $this->constructPattern($filter); + foreach ($this->users as $user => &$info) { + if ($i++ < $start) { continue; } - if($info === false) { + if ($info === false) { $info = $this->getUserData($user); } $result[$user] = $info; - if(($limit > 0) && (++$count >= $limit)) break; + if (($limit > 0) && (++$count >= $limit)) break; } } else { + /** @var admin_plugin_usermanager $usermanager */ $usermanager = plugin_load("admin", "usermanager", false); $usermanager->setLastdisabled(true); - if (!isset($this->_grpsusers[$this->_filterToString($filter)]) || count($this->_grpsusers[$this->_filterToString($filter)]) < ($start+$limit)) { - $this->_fillGroupUserArray($filter,$start+$limit - count($this->_grpsusers[$this->_filterToString($filter)]) +1); + if (!isset($this->grpsusers[$this->filterToString($filter)]) || + count($this->grpsusers[$this->filterToString($filter)]) < ($start+$limit) + ) { + $this->fillGroupUserArray( + $filter, + $start+$limit - count($this->grpsusers[$this->filterToString($filter)]) +1 + ); } - if (!$this->_grpsusers[$this->_filterToString($filter)]) return false; - foreach($this->_grpsusers[$this->_filterToString($filter)] as $user => &$info) { - if($i++ < $start) { + if (!$this->grpsusers[$this->filterToString($filter)]) return array(); + foreach ($this->grpsusers[$this->filterToString($filter)] as $user => &$info) { + if ($i++ < $start) { continue; } $result[$user] = $info; - if(($limit > 0) && (++$count >= $limit)) break; + if (($limit > 0) && (++$count >= $limit)) break; } - } return $result; } @@ -519,45 +552,46 @@ class auth_plugin_authad extends DokuWiki_Auth_Plugin { * @param array $changes array of field/value pairs to be changed * @return bool */ - public function modifyUser($user, $changes) { + public function modifyUser($user, $changes) + { $return = true; - $adldap = $this->_adldap($this->_userDomain($user)); - if(!$adldap) { + $adldap = $this->initAdLdap($this->getUserDomain($user)); + if (!$adldap) { msg($this->getLang('connectfail'), -1); return false; } // password changing - if(isset($changes['pass'])) { + if (isset($changes['pass'])) { try { - $return = $adldap->user()->password($this->_userName($user),$changes['pass']); + $return = $adldap->user()->password($this->getUserName($user), $changes['pass']); } catch (adLDAPException $e) { if ($this->conf['debug']) msg('AD Auth: '.$e->getMessage(), -1); $return = false; } - if(!$return) msg($this->getLang('passchangefail'), -1); + if (!$return) msg($this->getLang('passchangefail'), -1); } // changing user data $adchanges = array(); - if(isset($changes['name'])) { + if (isset($changes['name'])) { // get first and last name $parts = explode(' ', $changes['name']); $adchanges['surname'] = array_pop($parts); $adchanges['firstname'] = join(' ', $parts); $adchanges['display_name'] = $changes['name']; } - if(isset($changes['mail'])) { + if (isset($changes['mail'])) { $adchanges['email'] = $changes['mail']; } - if(count($adchanges)) { + if (count($adchanges)) { try { - $return = $return & $adldap->user()->modify($this->_userName($user),$adchanges); + $return = $return & $adldap->user()->modify($this->getUserName($user), $adchanges); } catch (adLDAPException $e) { if ($this->conf['debug']) msg('AD Auth: '.$e->getMessage(), -1); $return = false; } - if(!$return) msg($this->getLang('userchangefail'), -1); + if (!$return) msg($this->getLang('userchangefail'), -1); } return $return; @@ -573,20 +607,21 @@ class auth_plugin_authad extends DokuWiki_Auth_Plugin { * @param string|null $domain The AD domain to use * @return adLDAP|bool true if a connection was established */ - protected function _adldap($domain) { - if(is_null($domain) && is_array($this->opts)) { + protected function initAdLdap($domain) + { + if (is_null($domain) && is_array($this->opts)) { $domain = $this->opts['domain']; } - $this->opts = $this->_loadServerConfig((string) $domain); - if(isset($this->adldap[$domain])) return $this->adldap[$domain]; + $this->opts = $this->loadServerConfig((string) $domain); + if (isset($this->adldap[$domain])) return $this->adldap[$domain]; // connect try { $this->adldap[$domain] = new adLDAP($this->opts); return $this->adldap[$domain]; - } catch(adLDAPException $e) { - if($this->conf['debug']) { + } catch (Exception $e) { + if ($this->conf['debug']) { msg('AD Auth: '.$e->getMessage(), -1); } $this->success = false; @@ -601,7 +636,8 @@ class auth_plugin_authad extends DokuWiki_Auth_Plugin { * @param string $user * @return string */ - public function _userDomain($user) { + public function getUserDomain($user) + { list(, $domain) = explode('@', $user, 2); return $domain; } @@ -612,7 +648,8 @@ class auth_plugin_authad extends DokuWiki_Auth_Plugin { * @param string $user * @return string */ - public function _userName($user) { + public function getUserName($user) + { list($name) = explode('@', $user, 2); return $name; } @@ -623,14 +660,15 @@ class auth_plugin_authad extends DokuWiki_Auth_Plugin { * @param string $domain current AD domain * @return array */ - protected function _loadServerConfig($domain) { + protected function loadServerConfig($domain) + { // prepare adLDAP standard configuration $opts = $this->conf; $opts['domain'] = $domain; // add possible domain specific configuration - if($domain && is_array($this->conf[$domain])) foreach($this->conf[$domain] as $key => $val) { + if ($domain && is_array($this->conf[$domain])) foreach ($this->conf[$domain] as $key => $val) { $opts[$key] = $val; } @@ -640,23 +678,27 @@ class auth_plugin_authad extends DokuWiki_Auth_Plugin { $opts['domain_controllers'] = array_filter($opts['domain_controllers']); // compatibility with old option name - if(empty($opts['admin_username']) && !empty($opts['ad_username'])) $opts['admin_username'] = $opts['ad_username']; - if(empty($opts['admin_password']) && !empty($opts['ad_password'])) $opts['admin_password'] = $opts['ad_password']; + if (empty($opts['admin_username']) && !empty($opts['ad_username'])) { + $opts['admin_username'] = $opts['ad_username']; + } + if (empty($opts['admin_password']) && !empty($opts['ad_password'])) { + $opts['admin_password'] = $opts['ad_password']; + } $opts['admin_password'] = conf_decodeString($opts['admin_password']); // deobfuscate // we can change the password if SSL is set - if($opts['use_ssl'] || $opts['use_tls']) { + if ($opts['use_ssl'] || $opts['use_tls']) { $this->cando['modPass'] = true; } else { $this->cando['modPass'] = false; } // adLDAP expects empty user/pass as NULL, we're less strict FS#2781 - if(empty($opts['admin_username'])) $opts['admin_username'] = null; - if(empty($opts['admin_password'])) $opts['admin_password'] = null; + if (empty($opts['admin_username'])) $opts['admin_username'] = null; + if (empty($opts['admin_password'])) $opts['admin_password'] = null; // user listing needs admin priviledges - if(!empty($opts['admin_username']) && !empty($opts['admin_password'])) { + if (!empty($opts['admin_username']) && !empty($opts['admin_password'])) { $this->cando['getUsers'] = true; } else { $this->cando['getUsers'] = false; @@ -672,16 +714,17 @@ class auth_plugin_authad extends DokuWiki_Auth_Plugin { * * @return array associative array(key => domain) */ - public function _getConfiguredDomains() { + public function getConfiguredDomains() + { $domains = array(); - if(empty($this->conf['account_suffix'])) return $domains; // not configured yet + if (empty($this->conf['account_suffix'])) return $domains; // not configured yet // add default domain, using the name from account suffix $domains[''] = ltrim($this->conf['account_suffix'], '@'); // find additional domains - foreach($this->conf as $key => $val) { - if(is_array($val) && isset($val['account_suffix'])) { + foreach ($this->conf as $key => $val) { + if (is_array($val) && isset($val['account_suffix'])) { $domains[$key] = ltrim($val['account_suffix'], '@'); } } @@ -701,14 +744,15 @@ class auth_plugin_authad extends DokuWiki_Auth_Plugin { * @param array $info * @return bool */ - protected function _filter($user, $info) { - foreach($this->_pattern as $item => $pattern) { - if($item == 'user') { - if(!preg_match($pattern, $user)) return false; - } else if($item == 'grps') { - if(!count(preg_grep($pattern, $info['grps']))) return false; + protected function filter($user, $info) + { + foreach ($this->pattern as $item => $pattern) { + if ($item == 'user') { + if (!preg_match($pattern, $user)) return false; + } elseif ($item == 'grps') { + if (!count(preg_grep($pattern, $info['grps']))) return false; } else { - if(!preg_match($pattern, $info[$item])) return false; + if (!preg_match($pattern, $info[$item])) return false; } } return true; @@ -721,10 +765,11 @@ class auth_plugin_authad extends DokuWiki_Auth_Plugin { * * @param array $filter */ - protected function _constructPattern($filter) { - $this->_pattern = array(); - foreach($filter as $item => $pattern) { - $this->_pattern[$item] = '/'.str_replace('/', '\/', $pattern).'/i'; // allow regex characters + protected function constructPattern($filter) + { + $this->pattern = array(); + foreach ($filter as $item => $pattern) { + $this->pattern[$item] = '/'.str_replace('/', '\/', $pattern).'/i'; // allow regex characters } } } diff --git a/lib/plugins/authldap/auth.php b/lib/plugins/authldap/auth.php index 52f9ba50d..e71faa3c5 100644 --- a/lib/plugins/authldap/auth.php +++ b/lib/plugins/authldap/auth.php @@ -1,6 +1,4 @@ <?php -// must be run within Dokuwiki -if(!defined('DOKU_INC')) die(); /** * LDAP authentication backend @@ -10,8 +8,9 @@ if(!defined('DOKU_INC')) die(); * @author Chris Smith <chris@jalakaic.co.uk> * @author Jan Schumann <js@schumann-it.com> */ -class auth_plugin_authldap extends DokuWiki_Auth_Plugin { - /* @var resource $con holds the LDAP connection*/ +class auth_plugin_authldap extends DokuWiki_Auth_Plugin +{ + /* @var resource $con holds the LDAP connection */ protected $con = null; /* @var int $bound What type of connection does already exist? */ @@ -20,18 +19,19 @@ class auth_plugin_authldap extends DokuWiki_Auth_Plugin { /* @var array $users User data cache */ protected $users = null; - /* @var array $_pattern User filter pattern */ - protected $_pattern = null; + /* @var array $pattern User filter pattern */ + protected $pattern = null; /** * Constructor */ - public function __construct() { + public function __construct() + { parent::__construct(); // ldap extension is needed - if(!function_exists('ldap_connect')) { - $this->_debug("LDAP err: PHP LDAP extension not found.", -1, __LINE__, __FILE__); + if (!function_exists('ldap_connect')) { + $this->debug("LDAP err: PHP LDAP extension not found.", -1, __LINE__, __FILE__); $this->success = false; return; } @@ -52,68 +52,67 @@ class auth_plugin_authldap extends DokuWiki_Auth_Plugin { * @param string $pass * @return bool */ - public function checkPass($user, $pass) { + public function checkPass($user, $pass) + { // reject empty password - if(empty($pass)) return false; - if(!$this->_openLDAP()) return false; + if (empty($pass)) return false; + if (!$this->openLDAP()) return false; // indirect user bind - if($this->getConf('binddn') && $this->getConf('bindpw')) { + if ($this->getConf('binddn') && $this->getConf('bindpw')) { // use superuser credentials - if(!@ldap_bind($this->con, $this->getConf('binddn'), conf_decodeString($this->getConf('bindpw')))) { - $this->_debug('LDAP bind as superuser: '.htmlspecialchars(ldap_error($this->con)), 0, __LINE__, __FILE__); + if (!@ldap_bind($this->con, $this->getConf('binddn'), conf_decodeString($this->getConf('bindpw')))) { + $this->debug('LDAP bind as superuser: ' . hsc(ldap_error($this->con)), 0, __LINE__, __FILE__); return false; } $this->bound = 2; - } else if($this->getConf('binddn') && + } elseif ($this->getConf('binddn') && $this->getConf('usertree') && $this->getConf('userfilter') ) { // special bind string - $dn = $this->_makeFilter( + $dn = $this->makeFilter( $this->getConf('binddn'), - array('user'=> $user, 'server'=> $this->getConf('server')) + array('user' => $user, 'server' => $this->getConf('server')) ); - - } else if(strpos($this->getConf('usertree'), '%{user}')) { + } elseif (strpos($this->getConf('usertree'), '%{user}')) { // direct user bind - $dn = $this->_makeFilter( + $dn = $this->makeFilter( $this->getConf('usertree'), - array('user'=> $user, 'server'=> $this->getConf('server')) + array('user' => $user, 'server' => $this->getConf('server')) ); - } else { // Anonymous bind - if(!@ldap_bind($this->con)) { + if (!@ldap_bind($this->con)) { msg("LDAP: can not bind anonymously", -1); - $this->_debug('LDAP anonymous bind: '.htmlspecialchars(ldap_error($this->con)), 0, __LINE__, __FILE__); + $this->debug('LDAP anonymous bind: ' . hsc(ldap_error($this->con)), 0, __LINE__, __FILE__); return false; } } // Try to bind to with the dn if we have one. - if(!empty($dn)) { + if (!empty($dn)) { // User/Password bind - if(!@ldap_bind($this->con, $dn, $pass)) { - $this->_debug("LDAP: bind with $dn failed", -1, __LINE__, __FILE__); - $this->_debug('LDAP user dn bind: '.htmlspecialchars(ldap_error($this->con)), 0, __LINE__, __FILE__); + if (!@ldap_bind($this->con, $dn, $pass)) { + $this->debug("LDAP: bind with $dn failed", -1, __LINE__, __FILE__); + $this->debug('LDAP user dn bind: ' . hsc(ldap_error($this->con)), 0, __LINE__, __FILE__); return false; } $this->bound = 1; return true; } else { // See if we can find the user - $info = $this->_getUserData($user, true); - if(empty($info['dn'])) { + $info = $this->fetchUserData($user, true); + if (empty($info['dn'])) { return false; } else { $dn = $info['dn']; } // Try to bind with the dn provided - if(!@ldap_bind($this->con, $dn, $pass)) { - $this->_debug("LDAP: bind with $dn failed", -1, __LINE__, __FILE__); - $this->_debug('LDAP user bind: '.htmlspecialchars(ldap_error($this->con)), 0, __LINE__, __FILE__); + if (!@ldap_bind($this->con, $dn, $pass)) { + $this->debug("LDAP: bind with $dn failed", -1, __LINE__, __FILE__); + $this->debug('LDAP user bind: ' . hsc(ldap_error($this->con)), 0, __LINE__, __FILE__); return false; } $this->bound = 1; @@ -146,105 +145,110 @@ class auth_plugin_authldap extends DokuWiki_Auth_Plugin { * @author Steffen Schoch <schoch@dsb.net> * * @param string $user - * @param bool $requireGroups (optional) - ignored, groups are always supplied by this plugin + * @param bool $requireGroups (optional) - ignored, groups are always supplied by this plugin * @return array containing user data or false */ - public function getUserData($user, $requireGroups=true) { - return $this->_getUserData($user); + public function getUserData($user, $requireGroups = true) + { + return $this->fetchUserData($user); } /** * @param string $user - * @param bool $inbind authldap specific, true if in bind phase + * @param bool $inbind authldap specific, true if in bind phase * @return array containing user data or false */ - protected function _getUserData($user, $inbind = false) { + protected function fetchUserData($user, $inbind = false) + { global $conf; - if(!$this->_openLDAP()) return false; + if (!$this->openLDAP()) return array(); // force superuser bind if wanted and not bound as superuser yet - if($this->getConf('binddn') && $this->getConf('bindpw') && $this->bound < 2) { + if ($this->getConf('binddn') && $this->getConf('bindpw') && $this->bound < 2) { // use superuser credentials - if(!@ldap_bind($this->con, $this->getConf('binddn'), conf_decodeString($this->getConf('bindpw')))) { - $this->_debug('LDAP bind as superuser: '.htmlspecialchars(ldap_error($this->con)), 0, __LINE__, __FILE__); - return false; + if (!@ldap_bind($this->con, $this->getConf('binddn'), conf_decodeString($this->getConf('bindpw')))) { + $this->debug('LDAP bind as superuser: ' . hsc(ldap_error($this->con)), 0, __LINE__, __FILE__); + return array(); } $this->bound = 2; - } elseif($this->bound == 0 && !$inbind) { + } elseif ($this->bound == 0 && !$inbind) { // in some cases getUserData is called outside the authentication workflow // eg. for sending email notification on subscribed pages. This data might not // be accessible anonymously, so we try to rebind the current user here list($loginuser, $loginsticky, $loginpass) = auth_getCookie(); - if($loginuser && $loginpass) { + if ($loginuser && $loginpass) { $loginpass = auth_decrypt($loginpass, auth_cookiesalt(!$loginsticky, true)); $this->checkPass($loginuser, $loginpass); } } $info = array(); - $info['user'] = $user; - $this->_debug('LDAP user to find: '.htmlspecialchars($info['user']), 0, __LINE__, __FILE__); + $info['user'] = $user; + $this->debug('LDAP user to find: ' . hsc($info['user']), 0, __LINE__, __FILE__); $info['server'] = $this->getConf('server'); - $this->_debug('LDAP Server: '.htmlspecialchars($info['server']), 0, __LINE__, __FILE__); - + $this->debug('LDAP Server: ' . hsc($info['server']), 0, __LINE__, __FILE__); //get info for given user - $base = $this->_makeFilter($this->getConf('usertree'), $info); - if($this->getConf('userfilter')) { - $filter = $this->_makeFilter($this->getConf('userfilter'), $info); + $base = $this->makeFilter($this->getConf('usertree'), $info); + if ($this->getConf('userfilter')) { + $filter = $this->makeFilter($this->getConf('userfilter'), $info); } else { $filter = "(ObjectClass=*)"; } - $this->_debug('LDAP Filter: '.htmlspecialchars($filter), 0, __LINE__, __FILE__); + $this->debug('LDAP Filter: ' . hsc($filter), 0, __LINE__, __FILE__); - $this->_debug('LDAP user search: '.htmlspecialchars(ldap_error($this->con)), 0, __LINE__, __FILE__); - $this->_debug('LDAP search at: '.htmlspecialchars($base.' '.$filter), 0, __LINE__, __FILE__); - $sr = $this->_ldapsearch($this->con, $base, $filter, $this->getConf('userscope')); + $this->debug('LDAP user search: ' . hsc(ldap_error($this->con)), 0, __LINE__, __FILE__); + $this->debug('LDAP search at: ' . hsc($base . ' ' . $filter), 0, __LINE__, __FILE__); + $sr = $this->ldapSearch($this->con, $base, $filter, $this->getConf('userscope')); - $result = @ldap_get_entries($this->con, $sr); + $result = @ldap_get_entries($this->con, $sr); // if result is not an array - if(!is_array($result)) { - // no objects found - $this->_debug('LDAP search returned non-array result: '.htmlspecialchars(print($result)), -1, __LINE__, __FILE__); - return false; + if (!is_array($result)) { + // no objects found + $this->debug('LDAP search returned non-array result: ' . hsc(print($result)), -1, __LINE__, __FILE__); + return array(); } - // Don't accept more or less than one response - if ($result['count'] != 1) { - $this->_debug('LDAP search returned '.htmlspecialchars($result['count']).' results while it should return 1!', -1, __LINE__, __FILE__); - //for($i = 0; $i < $result["count"]; $i++) { - //$this->_debug('result: '.htmlspecialchars(print_r($result[$i])), 0, __LINE__, __FILE__); - //} - return false; - } - + // Don't accept more or less than one response + if ($result['count'] != 1) { + $this->debug( + 'LDAP search returned ' . hsc($result['count']) . ' results while it should return 1!', + -1, + __LINE__, + __FILE__ + ); + //for($i = 0; $i < $result["count"]; $i++) { + //$this->_debug('result: '.hsc(print_r($result[$i])), 0, __LINE__, __FILE__); + //} + return array(); + } - $this->_debug('LDAP search found single result !', 0, __LINE__, __FILE__); + $this->debug('LDAP search found single result !', 0, __LINE__, __FILE__); $user_result = $result[0]; ldap_free_result($sr); // general user info - $info['dn'] = $user_result['dn']; - $info['gid'] = $user_result['gidnumber'][0]; + $info['dn'] = $user_result['dn']; + $info['gid'] = $user_result['gidnumber'][0]; $info['mail'] = $user_result['mail'][0]; $info['name'] = $user_result['cn'][0]; $info['grps'] = array(); // overwrite if other attribs are specified. - if(is_array($this->getConf('mapping'))) { - foreach($this->getConf('mapping') as $localkey => $key) { - if(is_array($key)) { + if (is_array($this->getConf('mapping'))) { + foreach ($this->getConf('mapping') as $localkey => $key) { + if (is_array($key)) { // use regexp to clean up user_result // $key = array($key=>$regexp), only handles the first key-value $regexp = current($key); $key = key($key); - if($user_result[$key]) foreach($user_result[$key] as $grpkey => $grp) { - if($grpkey !== 'count' && preg_match($regexp, $grp, $match)) { - if($localkey == 'grps') { + if ($user_result[$key]) foreach ($user_result[$key] as $grpkey => $grp) { + if ($grpkey !== 'count' && preg_match($regexp, $grp, $match)) { + if ($localkey == 'grps') { $info[$localkey][] = $match[1]; } else { $info[$localkey] = $match[1]; @@ -259,38 +263,44 @@ class auth_plugin_authldap extends DokuWiki_Auth_Plugin { $user_result = array_merge($info, $user_result); //get groups for given user if grouptree is given - if($this->getConf('grouptree') || $this->getConf('groupfilter')) { - $base = $this->_makeFilter($this->getConf('grouptree'), $user_result); - $filter = $this->_makeFilter($this->getConf('groupfilter'), $user_result); - $sr = $this->_ldapsearch($this->con, $base, $filter, $this->getConf('groupscope'), array($this->getConf('groupkey'))); - $this->_debug('LDAP group search: '.htmlspecialchars(ldap_error($this->con)), 0, __LINE__, __FILE__); - $this->_debug('LDAP search at: '.htmlspecialchars($base.' '.$filter), 0, __LINE__, __FILE__); - - if(!$sr) { + if ($this->getConf('grouptree') || $this->getConf('groupfilter')) { + $base = $this->makeFilter($this->getConf('grouptree'), $user_result); + $filter = $this->makeFilter($this->getConf('groupfilter'), $user_result); + $sr = $this->ldapSearch( + $this->con, + $base, + $filter, + $this->getConf('groupscope'), + array($this->getConf('groupkey')) + ); + $this->debug('LDAP group search: ' . hsc(ldap_error($this->con)), 0, __LINE__, __FILE__); + $this->debug('LDAP search at: ' . hsc($base . ' ' . $filter), 0, __LINE__, __FILE__); + + if (!$sr) { msg("LDAP: Reading group memberships failed", -1); - return false; + return array(); } $result = ldap_get_entries($this->con, $sr); ldap_free_result($sr); - if(is_array($result)) foreach($result as $grp) { - if(!empty($grp[$this->getConf('groupkey')])) { + if (is_array($result)) foreach ($result as $grp) { + if (!empty($grp[$this->getConf('groupkey')])) { $group = $grp[$this->getConf('groupkey')]; - if(is_array($group)){ + if (is_array($group)) { $group = $group[0]; } else { - $this->_debug('groupkey did not return a detailled result', 0, __LINE__, __FILE__); + $this->debug('groupkey did not return a detailled result', 0, __LINE__, __FILE__); } - if($group === '') continue; + if ($group === '') continue; - $this->_debug('LDAP usergroup: '.htmlspecialchars($group), 0, __LINE__, __FILE__); + $this->debug('LDAP usergroup: ' . hsc($group), 0, __LINE__, __FILE__); $info['grps'][] = $group; } } } // always add the default group to the list of groups - if(!$info['grps'] or !in_array($conf['defaultgroup'], $info['grps'])) { + if (!$info['grps'] or !in_array($conf['defaultgroup'], $info['grps'])) { $info['grps'][] = $conf['defaultgroup']; } return $info; @@ -299,47 +309,51 @@ class auth_plugin_authldap extends DokuWiki_Auth_Plugin { /** * Definition of the function modifyUser in order to modify the password * - * @param string $user nick of the user to be changed - * @param array $changes array of field/value pairs to be changed (password will be clear text) + * @param string $user nick of the user to be changed + * @param array $changes array of field/value pairs to be changed (password will be clear text) * @return bool true on success, false on error */ - - function modifyUser($user,$changes){ + public function modifyUser($user, $changes) + { // open the connection to the ldap - if(!$this->_openLDAP()){ - $this->_debug('LDAP cannot connect: '. htmlspecialchars(ldap_error($this->con)), 0, __LINE__, __FILE__); + if (!$this->openLDAP()) { + $this->debug('LDAP cannot connect: ' . hsc(ldap_error($this->con)), 0, __LINE__, __FILE__); return false; } // find the information about the user, in particular the "dn" - $info = $this->getUserData($user,true); - if(empty($info['dn'])) { - $this->_debug('LDAP cannot find your user dn', 0, __LINE__, __FILE__); + $info = $this->getUserData($user, true); + if (empty($info['dn'])) { + $this->debug('LDAP cannot find your user dn', 0, __LINE__, __FILE__); return false; } $dn = $info['dn']; // find the old password of the user - list($loginuser,$loginsticky,$loginpass) = auth_getCookie(); + list($loginuser, $loginsticky, $loginpass) = auth_getCookie(); if ($loginuser !== null) { // the user is currently logged in $secret = auth_cookiesalt(!$loginsticky, true); - $pass = auth_decrypt($loginpass, $secret); + $pass = auth_decrypt($loginpass, $secret); // bind with the ldap - if(!@ldap_bind($this->con, $dn, $pass)){ - $this->_debug('LDAP user bind failed: '. htmlspecialchars($dn) .': '.htmlspecialchars(ldap_error($this->con)), 0, __LINE__, __FILE__); + if (!@ldap_bind($this->con, $dn, $pass)) { + $this->debug( + 'LDAP user bind failed: ' . hsc($dn) . ': ' . hsc(ldap_error($this->con)), + 0, + __LINE__, + __FILE__ + ); return false; } } elseif ($this->getConf('binddn') && $this->getConf('bindpw')) { // we are changing the password on behalf of the user (eg: forgotten password) // bind with the superuser ldap - if (!@ldap_bind($this->con, $this->getConf('binddn'), conf_decodeString($this->getConf('bindpw')))){ - $this->_debug('LDAP bind as superuser: '.htmlspecialchars(ldap_error($this->con)), 0, __LINE__, __FILE__); + if (!@ldap_bind($this->con, $this->getConf('binddn'), conf_decodeString($this->getConf('bindpw')))) { + $this->debug('LDAP bind as superuser: ' . hsc(ldap_error($this->con)), 0, __LINE__, __FILE__); return false; } - } - else { + } else { return false; // no otherway } @@ -348,8 +362,13 @@ class auth_plugin_authldap extends DokuWiki_Auth_Plugin { $hash = $phash->hash_ssha($changes['pass']); // change the password - if(!@ldap_mod_replace($this->con, $dn,array('userpassword' => $hash))){ - $this->_debug('LDAP mod replace failed: '. htmlspecialchars($dn) .': '.htmlspecialchars(ldap_error($this->con)), 0, __LINE__, __FILE__); + if (!@ldap_mod_replace($this->con, $dn, array('userpassword' => $hash))) { + $this->debug( + 'LDAP mod replace failed: ' . hsc($dn) . ': ' . hsc(ldap_error($this->con)), + 0, + __LINE__, + __FILE__ + ); return false; } @@ -361,7 +380,8 @@ class auth_plugin_authldap extends DokuWiki_Auth_Plugin { * * @return bool */ - public function isCaseSensitive() { + public function isCaseSensitive() + { return false; } @@ -369,48 +389,49 @@ class auth_plugin_authldap extends DokuWiki_Auth_Plugin { * Bulk retrieval of user data * * @author Dominik Eckelmann <dokuwiki@cosmocode.de> - * @param int $start index of first user to be returned - * @param int $limit max number of users to be returned - * @param array $filter array of field/pattern pairs, null for no filter + * @param int $start index of first user to be returned + * @param int $limit max number of users to be returned + * @param array $filter array of field/pattern pairs, null for no filter * @return array of userinfo (refer getUserData for internal userinfo details) */ - function retrieveUsers($start = 0, $limit = 0, $filter = array()) { - if(!$this->_openLDAP()) return false; + public function retrieveUsers($start = 0, $limit = 0, $filter = array()) + { + if (!$this->openLDAP()) return array(); - if(is_null($this->users)) { + if (is_null($this->users)) { // Perform the search and grab all their details - if($this->getConf('userfilter')) { + if ($this->getConf('userfilter')) { $all_filter = str_replace('%{user}', '*', $this->getConf('userfilter')); } else { $all_filter = "(ObjectClass=*)"; } - $sr = ldap_search($this->con, $this->getConf('usertree'), $all_filter); - $entries = ldap_get_entries($this->con, $sr); + $sr = ldap_search($this->con, $this->getConf('usertree'), $all_filter); + $entries = ldap_get_entries($this->con, $sr); $users_array = array(); - $userkey = $this->getConf('userkey'); - for($i = 0; $i < $entries["count"]; $i++) { + $userkey = $this->getConf('userkey'); + for ($i = 0; $i < $entries["count"]; $i++) { array_push($users_array, $entries[$i][$userkey][0]); } asort($users_array); $result = $users_array; - if(!$result) return array(); + if (!$result) return array(); $this->users = array_fill_keys($result, false); } - $i = 0; + $i = 0; $count = 0; - $this->_constructPattern($filter); + $this->constructPattern($filter); $result = array(); - foreach($this->users as $user => &$info) { - if($i++ < $start) { + foreach ($this->users as $user => &$info) { + if ($i++ < $start) { continue; } - if($info === false) { + if ($info === false) { $info = $this->getUserData($user); } - if($this->_filter($user, $info)) { + if ($this->filter($user, $info)) { $result[$user] = $info; - if(($limit > 0) && (++$count >= $limit)) break; + if (($limit > 0) && (++$count >= $limit)) break; } } return $result; @@ -424,21 +445,22 @@ class auth_plugin_authldap extends DokuWiki_Auth_Plugin { * * @author Troels Liebe Bentsen <tlb@rapanden.dk> * @param string $filter ldap search filter with placeholders - * @param array $placeholders placeholders to fill in + * @param array $placeholders placeholders to fill in * @return string */ - protected function _makeFilter($filter, $placeholders) { + protected function makeFilter($filter, $placeholders) + { preg_match_all("/%{([^}]+)/", $filter, $matches, PREG_PATTERN_ORDER); //replace each match - foreach($matches[1] as $match) { + foreach ($matches[1] as $match) { //take first element if array - if(is_array($placeholders[$match])) { + if (is_array($placeholders[$match])) { $value = $placeholders[$match][0]; } else { $value = $placeholders[$match]; } - $value = $this->_filterEscape($value); - $filter = str_replace('%{'.$match.'}', $value, $filter); + $value = $this->filterEscape($value); + $filter = str_replace('%{' . $match . '}', $value, $filter); } return $filter; } @@ -449,17 +471,18 @@ class auth_plugin_authldap extends DokuWiki_Auth_Plugin { * @author Chris Smith <chris@jalakai.co.uk> * * @param string $user the user's login name - * @param array $info the user's userinfo array + * @param array $info the user's userinfo array * @return bool */ - protected function _filter($user, $info) { - foreach($this->_pattern as $item => $pattern) { - if($item == 'user') { - if(!preg_match($pattern, $user)) return false; - } else if($item == 'grps') { - if(!count(preg_grep($pattern, $info['grps']))) return false; + protected function filter($user, $info) + { + foreach ($this->pattern as $item => $pattern) { + if ($item == 'user') { + if (!preg_match($pattern, $user)) return false; + } elseif ($item == 'grps') { + if (!count(preg_grep($pattern, $info['grps']))) return false; } else { - if(!preg_match($pattern, $info[$item])) return false; + if (!preg_match($pattern, $info[$item])) return false; } } return true; @@ -473,10 +496,11 @@ class auth_plugin_authldap extends DokuWiki_Auth_Plugin { * @param $filter * @return void */ - protected function _constructPattern($filter) { - $this->_pattern = array(); - foreach($filter as $item => $pattern) { - $this->_pattern[$item] = '/'.str_replace('/', '\/', $pattern).'/i'; // allow regex characters + protected function constructPattern($filter) + { + $this->pattern = array(); + foreach ($filter as $item => $pattern) { + $this->pattern[$item] = '/' . str_replace('/', '\/', $pattern) . '/i'; // allow regex characters } } @@ -489,12 +513,13 @@ class auth_plugin_authldap extends DokuWiki_Auth_Plugin { * @param string $string * @return string */ - protected function _filterEscape($string) { + protected function filterEscape($string) + { // see https://github.com/adldap/adLDAP/issues/22 return preg_replace_callback( '/([\x00-\x1F\*\(\)\\\\])/', function ($matches) { - return "\\".join("", unpack("H2", $matches[1])); + return "\\" . join("", unpack("H2", $matches[1])); }, $string ); @@ -506,22 +531,23 @@ class auth_plugin_authldap extends DokuWiki_Auth_Plugin { * * @author Andreas Gohr <andi@splitbrain.org> */ - protected function _openLDAP() { - if($this->con) return true; // connection already established + protected function openLDAP() + { + if ($this->con) return true; // connection already established - if($this->getConf('debug')) { - ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7); + if ($this->getConf('debug')) { + ldap_set_option(null, LDAP_OPT_DEBUG_LEVEL, 7); } $this->bound = 0; - $port = $this->getConf('port'); - $bound = false; + $port = $this->getConf('port'); + $bound = false; $servers = explode(',', $this->getConf('server')); - foreach($servers as $server) { - $server = trim($server); + foreach ($servers as $server) { + $server = trim($server); $this->con = @ldap_connect($server, $port); - if(!$this->con) { + if (!$this->con) { continue; } @@ -534,62 +560,64 @@ class auth_plugin_authldap extends DokuWiki_Auth_Plugin { */ //set protocol version and dependend options - if($this->getConf('version')) { - if(!@ldap_set_option( - $this->con, LDAP_OPT_PROTOCOL_VERSION, + if ($this->getConf('version')) { + if (!@ldap_set_option( + $this->con, + LDAP_OPT_PROTOCOL_VERSION, $this->getConf('version') ) ) { - msg('Setting LDAP Protocol version '.$this->getConf('version').' failed', -1); - $this->_debug('LDAP version set: '.htmlspecialchars(ldap_error($this->con)), 0, __LINE__, __FILE__); + msg('Setting LDAP Protocol version ' . $this->getConf('version') . ' failed', -1); + $this->debug('LDAP version set: ' . hsc(ldap_error($this->con)), 0, __LINE__, __FILE__); } else { //use TLS (needs version 3) - if($this->getConf('starttls')) { - if(!@ldap_start_tls($this->con)) { + if ($this->getConf('starttls')) { + if (!@ldap_start_tls($this->con)) { msg('Starting TLS failed', -1); - $this->_debug('LDAP TLS set: '.htmlspecialchars(ldap_error($this->con)), 0, __LINE__, __FILE__); + $this->debug('LDAP TLS set: ' . hsc(ldap_error($this->con)), 0, __LINE__, __FILE__); } } // needs version 3 - if($this->getConf('referrals') > -1) { - if(!@ldap_set_option( - $this->con, LDAP_OPT_REFERRALS, + if ($this->getConf('referrals') > -1) { + if (!@ldap_set_option( + $this->con, + LDAP_OPT_REFERRALS, $this->getConf('referrals') ) ) { msg('Setting LDAP referrals failed', -1); - $this->_debug('LDAP referal set: '.htmlspecialchars(ldap_error($this->con)), 0, __LINE__, __FILE__); + $this->debug('LDAP referal set: ' . hsc(ldap_error($this->con)), 0, __LINE__, __FILE__); } } } } //set deref mode - if($this->getConf('deref')) { - if(!@ldap_set_option($this->con, LDAP_OPT_DEREF, $this->getConf('deref'))) { - msg('Setting LDAP Deref mode '.$this->getConf('deref').' failed', -1); - $this->_debug('LDAP deref set: '.htmlspecialchars(ldap_error($this->con)), 0, __LINE__, __FILE__); + if ($this->getConf('deref')) { + if (!@ldap_set_option($this->con, LDAP_OPT_DEREF, $this->getConf('deref'))) { + msg('Setting LDAP Deref mode ' . $this->getConf('deref') . ' failed', -1); + $this->debug('LDAP deref set: ' . hsc(ldap_error($this->con)), 0, __LINE__, __FILE__); } } /* As of PHP 5.3.0 we can set timeout to speedup skipping of invalid servers */ - if(defined('LDAP_OPT_NETWORK_TIMEOUT')) { + if (defined('LDAP_OPT_NETWORK_TIMEOUT')) { ldap_set_option($this->con, LDAP_OPT_NETWORK_TIMEOUT, 1); } - if($this->getConf('binddn') && $this->getConf('bindpw')) { + if ($this->getConf('binddn') && $this->getConf('bindpw')) { $bound = @ldap_bind($this->con, $this->getConf('binddn'), conf_decodeString($this->getConf('bindpw'))); $this->bound = 2; } else { $bound = @ldap_bind($this->con); } - if($bound) { + if ($bound) { break; } } - if(!$bound) { + if (!$bound) { msg("LDAP: couldn't connect to LDAP server", -1); - $this->_debug(ldap_error($this->con), 0, __LINE__, __FILE__); + $this->debug(ldap_error($this->con), 0, __LINE__, __FILE__); return false; } @@ -601,33 +629,52 @@ class auth_plugin_authldap extends DokuWiki_Auth_Plugin { * Wraps around ldap_search, ldap_list or ldap_read depending on $scope * * @author Andreas Gohr <andi@splitbrain.org> - * @param resource $link_identifier - * @param string $base_dn - * @param string $filter - * @param string $scope can be 'base', 'one' or 'sub' + * @param resource $link_identifier + * @param string $base_dn + * @param string $filter + * @param string $scope can be 'base', 'one' or 'sub' * @param null|array $attributes - * @param int $attrsonly - * @param int $sizelimit + * @param int $attrsonly + * @param int $sizelimit * @return resource */ - protected function _ldapsearch($link_identifier, $base_dn, $filter, $scope = 'sub', $attributes = null, - $attrsonly = 0, $sizelimit = 0) { - if(is_null($attributes)) $attributes = array(); - - if($scope == 'base') { + protected function ldapSearch( + $link_identifier, + $base_dn, + $filter, + $scope = 'sub', + $attributes = null, + $attrsonly = 0, + $sizelimit = 0 + ) { + if (is_null($attributes)) $attributes = array(); + + if ($scope == 'base') { return @ldap_read( - $link_identifier, $base_dn, $filter, $attributes, - $attrsonly, $sizelimit + $link_identifier, + $base_dn, + $filter, + $attributes, + $attrsonly, + $sizelimit ); - } elseif($scope == 'one') { + } elseif ($scope == 'one') { return @ldap_list( - $link_identifier, $base_dn, $filter, $attributes, - $attrsonly, $sizelimit + $link_identifier, + $base_dn, + $filter, + $attributes, + $attrsonly, + $sizelimit ); } else { return @ldap_search( - $link_identifier, $base_dn, $filter, $attributes, - $attrsonly, $sizelimit + $link_identifier, + $base_dn, + $filter, + $attributes, + $attrsonly, + $sizelimit ); } } @@ -636,14 +683,14 @@ class auth_plugin_authldap extends DokuWiki_Auth_Plugin { * Wrapper around msg() but outputs only when debug is enabled * * @param string $message - * @param int $err - * @param int $line + * @param int $err + * @param int $line * @param string $file * @return void */ - protected function _debug($message, $err, $line, $file) { - if(!$this->getConf('debug')) return; + protected function debug($message, $err, $line, $file) + { + if (!$this->getConf('debug')) return; msg($message, $err, $line, $file); } - } diff --git a/lib/plugins/authpdo/_test/sqlite.test.php b/lib/plugins/authpdo/_test/sqlite.test.php index 35b612604..89cc9f60d 100644 --- a/lib/plugins/authpdo/_test/sqlite.test.php +++ b/lib/plugins/authpdo/_test/sqlite.test.php @@ -10,8 +10,8 @@ class testable_auth_plugin_authpdo extends auth_plugin_authpdo { return 'authpdo'; } - public function _selectGroups() { - return parent::_selectGroups(); + public function selectGroups() { + return parent::selectGroups(); } public function addGroup($group) { @@ -96,7 +96,7 @@ class sqlite_plugin_authpdo_test extends DokuWikiTest { public function test_internals() { $auth = new testable_auth_plugin_authpdo(); - $groups = $auth->_selectGroups(); + $groups = $auth->selectGroups(); $this->assertArrayHasKey('user', $groups); $this->assertEquals(1, $groups['user']['gid']); $this->assertArrayHasKey('admin', $groups); @@ -104,7 +104,7 @@ class sqlite_plugin_authpdo_test extends DokuWikiTest { $ok = $auth->addGroup('test'); $this->assertTrue($ok); - $groups = $auth->_selectGroups(); + $groups = $auth->selectGroups(); $this->assertArrayHasKey('test', $groups); $this->assertEquals(3, $groups['test']['gid']); } diff --git a/lib/plugins/authpdo/auth.php b/lib/plugins/authpdo/auth.php index dfe125473..2b01ba752 100644 --- a/lib/plugins/authpdo/auth.php +++ b/lib/plugins/authpdo/auth.php @@ -6,13 +6,11 @@ * @author Andreas Gohr <andi@splitbrain.org> */ -// must be run within Dokuwiki -if(!defined('DOKU_INC')) die(); - /** * Class auth_plugin_authpdo */ -class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { +class auth_plugin_authpdo extends DokuWiki_Auth_Plugin +{ /** @var PDO */ protected $pdo; @@ -23,17 +21,18 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { /** * Constructor. */ - public function __construct() { + public function __construct() + { parent::__construct(); // for compatibility - if(!class_exists('PDO')) { - $this->_debug('PDO extension for PHP not found.', -1, __LINE__); + if (!class_exists('PDO')) { + $this->debugMsg('PDO extension for PHP not found.', -1, __LINE__); $this->success = false; return; } - if(!$this->getConf('dsn')) { - $this->_debug('No DSN specified', -1, __LINE__); + if (!$this->getConf('dsn')) { + $this->debugMsg('No DSN specified', -1, __LINE__); $this->success = false; return; } @@ -49,15 +48,15 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, // we want exceptions, not error codes ) ); - } catch(PDOException $e) { - $this->_debug($e); + } catch (PDOException $e) { + $this->debugMsg($e); msg($this->getLang('connectfail'), -1); $this->success = false; return; } // can Users be created? - $this->cando['addUser'] = $this->_chkcnf( + $this->cando['addUser'] = $this->checkConfig( array( 'select-user', 'select-user-groups', @@ -69,7 +68,7 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { ); // can Users be deleted? - $this->cando['delUser'] = $this->_chkcnf( + $this->cando['delUser'] = $this->checkConfig( array( 'select-user', 'select-user-groups', @@ -80,7 +79,7 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { ); // can login names be changed? - $this->cando['modLogin'] = $this->_chkcnf( + $this->cando['modLogin'] = $this->checkConfig( array( 'select-user', 'select-user-groups', @@ -89,7 +88,7 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { ); // can passwords be changed? - $this->cando['modPass'] = $this->_chkcnf( + $this->cando['modPass'] = $this->checkConfig( array( 'select-user', 'select-user-groups', @@ -98,7 +97,7 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { ); // can real names be changed? - $this->cando['modName'] = $this->_chkcnf( + $this->cando['modName'] = $this->checkConfig( array( 'select-user', 'select-user-groups', @@ -107,7 +106,7 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { ); // can real email be changed? - $this->cando['modMail'] = $this->_chkcnf( + $this->cando['modMail'] = $this->checkConfig( array( 'select-user', 'select-user-groups', @@ -116,7 +115,7 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { ); // can groups be changed? - $this->cando['modGroups'] = $this->_chkcnf( + $this->cando['modGroups'] = $this->checkConfig( array( 'select-user', 'select-user-groups', @@ -128,21 +127,21 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { ); // can a filtered list of users be retrieved? - $this->cando['getUsers'] = $this->_chkcnf( + $this->cando['getUsers'] = $this->checkConfig( array( 'list-users' ) ); // can the number of users be retrieved? - $this->cando['getUserCount'] = $this->_chkcnf( + $this->cando['getUserCount'] = $this->checkConfig( array( 'count-users' ) ); // can a list of available groups be retrieved? - $this->cando['getGroups'] = $this->_chkcnf( + $this->cando['getGroups'] = $this->checkConfig( array( 'select-groups' ) @@ -158,22 +157,23 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { * @param string $pass the clear text password * @return bool */ - public function checkPass($user, $pass) { + public function checkPass($user, $pass) + { - $userdata = $this->_selectUser($user); - if($userdata == false) return false; + $userdata = $this->selectUser($user); + if ($userdata == false) return false; // password checking done in SQL? - if($this->_chkcnf(array('check-pass'))) { + if ($this->checkConfig(array('check-pass'))) { $userdata['clear'] = $pass; $userdata['hash'] = auth_cryptPassword($pass); - $result = $this->_query($this->getConf('check-pass'), $userdata); - if($result === false) return false; + $result = $this->query($this->getConf('check-pass'), $userdata); + if ($result === false) return false; return (count($result) == 1); } // we do password checking on our own - if(isset($userdata['hash'])) { + if (isset($userdata['hash'])) { // hashed password $passhash = new PassHash(); return $passhash->verify_hash($pass, $userdata['hash']); @@ -197,16 +197,17 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { * @param bool $requireGroups whether or not the returned data must include groups * @return array|bool containing user data or false */ - public function getUserData($user, $requireGroups = true) { - $data = $this->_selectUser($user); - if($data == false) return false; + public function getUserData($user, $requireGroups = true) + { + $data = $this->selectUser($user); + if ($data == false) return false; - if(isset($data['hash'])) unset($data['hash']); - if(isset($data['clean'])) unset($data['clean']); + if (isset($data['hash'])) unset($data['hash']); + if (isset($data['clean'])) unset($data['clean']); - if($requireGroups) { - $data['grps'] = $this->_selectUserGroups($data); - if($data['grps'] === false) return false; + if ($requireGroups) { + $data['grps'] = $this->selectUserGroups($data); + if ($data['grps'] === false) return false; } return $data; @@ -230,16 +231,17 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { * @param null|array $grps * @return bool|null */ - public function createUser($user, $clear, $name, $mail, $grps = null) { + public function createUser($user, $clear, $name, $mail, $grps = null) + { global $conf; - if(($info = $this->getUserData($user, false)) !== false) { + if (($info = $this->getUserData($user, false)) !== false) { msg($this->getLang('userexists'), -1); return false; // user already exists } // prepare data - if($grps == null) $grps = array(); + if ($grps == null) $grps = array(); array_unshift($grps, $conf['defaultgroup']); $grps = array_unique($grps); $hash = auth_cryptPassword($clear); @@ -249,26 +251,26 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { $this->pdo->beginTransaction(); { // insert the user - $ok = $this->_query($this->getConf('insert-user'), $userdata); - if($ok === false) goto FAIL; + $ok = $this->query($this->getConf('insert-user'), $userdata); + if ($ok === false) goto FAIL; $userdata = $this->getUserData($user, false); - if($userdata === false) goto FAIL; + if ($userdata === false) goto FAIL; // create all groups that do not exist, the refetch the groups - $allgroups = $this->_selectGroups(); - foreach($grps as $group) { - if(!isset($allgroups[$group])) { - $ok = $this->addGroup($group); - if($ok === false) goto FAIL; - } + $allgroups = $this->selectGroups(); + foreach ($grps as $group) { + if (!isset($allgroups[$group])) { + $ok = $this->addGroup($group); + if ($ok === false) goto FAIL; } - $allgroups = $this->_selectGroups(); + } + $allgroups = $this->selectGroups(); // add user to the groups - foreach($grps as $group) { - $ok = $this->_joinGroup($userdata, $allgroups[$group]); - if($ok === false) goto FAIL; - } + foreach ($grps as $group) { + $ok = $this->joinGroup($userdata, $allgroups[$group]); + if ($ok === false) goto FAIL; + } } $this->pdo->commit(); return true; @@ -276,7 +278,7 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { // something went wrong, rollback FAIL: $this->pdo->rollBack(); - $this->_debug('Transaction rolled back', 0, __LINE__); + $this->debugMsg('Transaction rolled back', 0, __LINE__); msg($this->getLang('writefail'), -1); return null; // return error } @@ -288,7 +290,8 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { * @param array $changes array of field/value pairs to be changed (password will be clear text) * @return bool */ - public function modifyUser($user, $changes) { + public function modifyUser($user, $changes) + { // secure everything in transaction $this->pdo->beginTransaction(); { @@ -297,67 +300,67 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { unset($olddata['grps']); // changing the user name? - if(isset($changes['user'])) { - if($this->getUserData($changes['user'], false)) goto FAIL; - $params = $olddata; - $params['newlogin'] = $changes['user']; + if (isset($changes['user'])) { + if ($this->getUserData($changes['user'], false)) goto FAIL; + $params = $olddata; + $params['newlogin'] = $changes['user']; - $ok = $this->_query($this->getConf('update-user-login'), $params); - if($ok === false) goto FAIL; - } + $ok = $this->query($this->getConf('update-user-login'), $params); + if ($ok === false) goto FAIL; + } // changing the password? - if(isset($changes['pass'])) { - $params = $olddata; - $params['clear'] = $changes['pass']; - $params['hash'] = auth_cryptPassword($changes['pass']); + if (isset($changes['pass'])) { + $params = $olddata; + $params['clear'] = $changes['pass']; + $params['hash'] = auth_cryptPassword($changes['pass']); - $ok = $this->_query($this->getConf('update-user-pass'), $params); - if($ok === false) goto FAIL; - } + $ok = $this->query($this->getConf('update-user-pass'), $params); + if ($ok === false) goto FAIL; + } // changing info? - if(isset($changes['mail']) || isset($changes['name'])) { - $params = $olddata; - if(isset($changes['mail'])) $params['mail'] = $changes['mail']; - if(isset($changes['name'])) $params['name'] = $changes['name']; + if (isset($changes['mail']) || isset($changes['name'])) { + $params = $olddata; + if (isset($changes['mail'])) $params['mail'] = $changes['mail']; + if (isset($changes['name'])) $params['name'] = $changes['name']; - $ok = $this->_query($this->getConf('update-user-info'), $params); - if($ok === false) goto FAIL; - } + $ok = $this->query($this->getConf('update-user-info'), $params); + if ($ok === false) goto FAIL; + } // changing groups? - if(isset($changes['grps'])) { - $allgroups = $this->_selectGroups(); - - // remove membership for previous groups - foreach($oldgroups as $group) { - if(!in_array($group, $changes['grps']) && isset($allgroups[$group])) { - $ok = $this->_leaveGroup($olddata, $allgroups[$group]); - if($ok === false) goto FAIL; - } + if (isset($changes['grps'])) { + $allgroups = $this->selectGroups(); + + // remove membership for previous groups + foreach ($oldgroups as $group) { + if (!in_array($group, $changes['grps']) && isset($allgroups[$group])) { + $ok = $this->leaveGroup($olddata, $allgroups[$group]); + if ($ok === false) goto FAIL; } + } - // create all new groups that are missing - $added = 0; - foreach($changes['grps'] as $group) { - if(!isset($allgroups[$group])) { - $ok = $this->addGroup($group); - if($ok === false) goto FAIL; - $added++; - } + // create all new groups that are missing + $added = 0; + foreach ($changes['grps'] as $group) { + if (!isset($allgroups[$group])) { + $ok = $this->addGroup($group); + if ($ok === false) goto FAIL; + $added++; } - // reload group info - if($added > 0) $allgroups = $this->_selectGroups(); - - // add membership for new groups - foreach($changes['grps'] as $group) { - if(!in_array($group, $oldgroups)) { - $ok = $this->_joinGroup($olddata, $allgroups[$group]); - if($ok === false) goto FAIL; - } + } + // reload group info + if ($added > 0) $allgroups = $this->selectGroups(); + + // add membership for new groups + foreach ($changes['grps'] as $group) { + if (!in_array($group, $oldgroups)) { + $ok = $this->joinGroup($olddata, $allgroups[$group]); + if ($ok === false) goto FAIL; } } + } } $this->pdo->commit(); @@ -366,7 +369,7 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { // something went wrong, rollback FAIL: $this->pdo->rollBack(); - $this->_debug('Transaction rolled back', 0, __LINE__); + $this->debugMsg('Transaction rolled back', 0, __LINE__); msg($this->getLang('writefail'), -1); return false; // return error } @@ -379,10 +382,11 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { * @param array $users * @return int number of users deleted */ - public function deleteUsers($users) { + public function deleteUsers($users) + { $count = 0; - foreach($users as $user) { - if($this->_deleteUser($user)) $count++; + foreach ($users as $user) { + if ($this->deleteUser($user)) $count++; } return $count; } @@ -397,13 +401,14 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { * @param array $filter array of field/pattern pairs, null for no filter * @return array list of userinfo (refer getUserData for internal userinfo details) */ - public function retrieveUsers($start = 0, $limit = -1, $filter = null) { - if($limit < 0) $limit = 10000; // we don't support no limit - if(is_null($filter)) $filter = array(); - - if(isset($filter['grps'])) $filter['group'] = $filter['grps']; - foreach(array('user', 'name', 'mail', 'group') as $key) { - if(!isset($filter[$key])) { + public function retrieveUsers($start = 0, $limit = -1, $filter = null) + { + if ($limit < 0) $limit = 10000; // we don't support no limit + if (is_null($filter)) $filter = array(); + + if (isset($filter['grps'])) $filter['group'] = $filter['grps']; + foreach (array('user', 'name', 'mail', 'group') as $key) { + if (!isset($filter[$key])) { $filter[$key] = '%'; } else { $filter[$key] = '%' . $filter[$key] . '%'; @@ -413,12 +418,12 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { $filter['end'] = (int) $start + $limit; $filter['limit'] = (int) $limit; - $result = $this->_query($this->getConf('list-users'), $filter); - if(!$result) return array(); + $result = $this->query($this->getConf('list-users'), $filter); + if (!$result) return array(); $users = array(); - foreach($result as $row) { - if(!isset($row['user'])) { - $this->_debug("Statement did not return 'user' attribute", -1, __LINE__); + foreach ($result as $row) { + if (!isset($row['user'])) { + $this->debugMsg("Statement did not return 'user' attribute", -1, __LINE__); return array(); } $users[] = $this->getUserData($row['user']); @@ -432,21 +437,22 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { * @param array $filter array of field/pattern pairs, empty array for no filter * @return int */ - public function getUserCount($filter = array()) { - if(is_null($filter)) $filter = array(); + public function getUserCount($filter = array()) + { + if (is_null($filter)) $filter = array(); - if(isset($filter['grps'])) $filter['group'] = $filter['grps']; - foreach(array('user', 'name', 'mail', 'group') as $key) { - if(!isset($filter[$key])) { + if (isset($filter['grps'])) $filter['group'] = $filter['grps']; + foreach (array('user', 'name', 'mail', 'group') as $key) { + if (!isset($filter[$key])) { $filter[$key] = '%'; } else { $filter[$key] = '%' . $filter[$key] . '%'; } } - $result = $this->_query($this->getConf('count-users'), $filter); - if(!$result || !isset($result[0]['count'])) { - $this->_debug("Statement did not return 'count' attribute", -1, __LINE__); + $result = $this->query($this->getConf('count-users'), $filter); + if (!$result || !isset($result[0]['count'])) { + $this->debugMsg("Statement did not return 'count' attribute", -1, __LINE__); } return (int) $result[0]['count']; } @@ -457,12 +463,13 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { * @param string $group * @return bool */ - public function addGroup($group) { + public function addGroup($group) + { $sql = $this->getConf('insert-group'); - $result = $this->_query($sql, array(':group' => $group)); - $this->_clearGroupCache(); - if($result === false) return false; + $result = $this->query($sql, array(':group' => $group)); + $this->clearGroupCache(); + if ($result === false) return false; return true; } @@ -475,11 +482,12 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { * @param int $limit * @return array */ - public function retrieveGroups($start = 0, $limit = 0) { - $groups = array_keys($this->_selectGroups()); - if($groups === false) return array(); + public function retrieveGroups($start = 0, $limit = 0) + { + $groups = array_keys($this->selectGroups()); + if ($groups === false) return array(); - if(!$limit) { + if (!$limit) { return array_splice($groups, $start); } else { return array_splice($groups, $start, $limit); @@ -492,38 +500,39 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { * @param string $user the user name * @return bool|array user data, false on error */ - protected function _selectUser($user) { + protected function selectUser($user) + { $sql = $this->getConf('select-user'); - $result = $this->_query($sql, array(':user' => $user)); - if(!$result) return false; + $result = $this->query($sql, array(':user' => $user)); + if (!$result) return false; - if(count($result) > 1) { - $this->_debug('Found more than one matching user', -1, __LINE__); + if (count($result) > 1) { + $this->debugMsg('Found more than one matching user', -1, __LINE__); return false; } $data = array_shift($result); $dataok = true; - if(!isset($data['user'])) { - $this->_debug("Statement did not return 'user' attribute", -1, __LINE__); + if (!isset($data['user'])) { + $this->debugMsg("Statement did not return 'user' attribute", -1, __LINE__); $dataok = false; } - if(!isset($data['hash']) && !isset($data['clear']) && !$this->_chkcnf(array('check-pass'))) { - $this->_debug("Statement did not return 'clear' or 'hash' attribute", -1, __LINE__); + if (!isset($data['hash']) && !isset($data['clear']) && !$this->checkConfig(array('check-pass'))) { + $this->debugMsg("Statement did not return 'clear' or 'hash' attribute", -1, __LINE__); $dataok = false; } - if(!isset($data['name'])) { - $this->_debug("Statement did not return 'name' attribute", -1, __LINE__); + if (!isset($data['name'])) { + $this->debugMsg("Statement did not return 'name' attribute", -1, __LINE__); $dataok = false; } - if(!isset($data['mail'])) { - $this->_debug("Statement did not return 'mail' attribute", -1, __LINE__); + if (!isset($data['mail'])) { + $this->debugMsg("Statement did not return 'mail' attribute", -1, __LINE__); $dataok = false; } - if(!$dataok) return false; + if (!$dataok) return false; return $data; } @@ -533,22 +542,23 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { * @param string $user * @return bool true when the user was deleted */ - protected function _deleteUser($user) { + protected function deleteUser($user) + { $this->pdo->beginTransaction(); { $userdata = $this->getUserData($user); - if($userdata === false) goto FAIL; - $allgroups = $this->_selectGroups(); + if ($userdata === false) goto FAIL; + $allgroups = $this->selectGroups(); // remove group memberships (ignore errors) - foreach($userdata['grps'] as $group) { - if(isset($allgroups[$group])) { - $this->_leaveGroup($userdata, $allgroups[$group]); - } + foreach ($userdata['grps'] as $group) { + if (isset($allgroups[$group])) { + $this->leaveGroup($userdata, $allgroups[$group]); } + } - $ok = $this->_query($this->getConf('delete-user'), $userdata); - if($ok === false) goto FAIL; + $ok = $this->query($this->getConf('delete-user'), $userdata); + if ($ok === false) goto FAIL; } $this->pdo->commit(); return true; @@ -564,16 +574,17 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { * @param array $userdata The userdata as returned by _selectUser() * @return array|bool list of group names, false on error */ - protected function _selectUserGroups($userdata) { + protected function selectUserGroups($userdata) + { global $conf; $sql = $this->getConf('select-user-groups'); - $result = $this->_query($sql, $userdata); - if($result === false) return false; + $result = $this->query($sql, $userdata); + if ($result === false) return false; $groups = array($conf['defaultgroup']); // always add default config - foreach($result as $row) { - if(!isset($row['group'])) { - $this->_debug("No 'group' field returned in select-user-groups statement"); + foreach ($result as $row) { + if (!isset($row['group'])) { + $this->debugMsg("No 'group' field returned in select-user-groups statement"); return false; } $groups[] = $row['group']; @@ -589,17 +600,18 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { * * @return array|bool list of all available groups and their properties */ - protected function _selectGroups() { - if($this->groupcache) return $this->groupcache; + protected function selectGroups() + { + if ($this->groupcache) return $this->groupcache; $sql = $this->getConf('select-groups'); - $result = $this->_query($sql); - if($result === false) return false; + $result = $this->query($sql); + if ($result === false) return false; $groups = array(); - foreach($result as $row) { - if(!isset($row['group'])) { - $this->_debug("No 'group' field returned from select-groups statement", -1, __LINE__); + foreach ($result as $row) { + if (!isset($row['group'])) { + $this->debugMsg("No 'group' field returned from select-groups statement", -1, __LINE__); return false; } @@ -615,7 +627,8 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { /** * Remove all entries from the group cache */ - protected function _clearGroupCache() { + protected function clearGroupCache() + { $this->groupcache = null; } @@ -626,11 +639,12 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { * @param array $groupdata all the group data * @return bool */ - protected function _joinGroup($userdata, $groupdata) { + protected function joinGroup($userdata, $groupdata) + { $data = array_merge($userdata, $groupdata); $sql = $this->getConf('join-group'); - $result = $this->_query($sql, $data); - if($result === false) return false; + $result = $this->query($sql, $data); + if ($result === false) return false; return true; } @@ -641,11 +655,12 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { * @param array $groupdata all the group data * @return bool */ - protected function _leaveGroup($userdata, $groupdata) { + protected function leaveGroup($userdata, $groupdata) + { $data = array_merge($userdata, $groupdata); $sql = $this->getConf('leave-group'); - $result = $this->_query($sql, $data); - if($result === false) return false; + $result = $this->query($sql, $data); + if ($result === false) return false; return true; } @@ -656,10 +671,11 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { * @param array $arguments Named parameters to be used in the statement * @return array|int|bool The result as associative array for SELECTs, affected rows for others, false on error */ - protected function _query($sql, $arguments = array()) { + protected function query($sql, $arguments = array()) + { $sql = trim($sql); - if(empty($sql)) { - $this->_debug('No SQL query given', -1, __LINE__); + if (empty($sql)) { + $this->debugMsg('No SQL query given', -1, __LINE__); return false; } @@ -668,13 +684,13 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { $sth = $this->pdo->prepare($sql); try { // prepare parameters - we only use those that exist in the SQL - foreach($arguments as $key => $value) { - if(is_array($value)) continue; - if(is_object($value)) continue; - if($key[0] != ':') $key = ":$key"; // prefix with colon if needed - if(strpos($sql, $key) === false) continue; // skip if parameter is missing + foreach ($arguments as $key => $value) { + if (is_array($value)) continue; + if (is_object($value)) continue; + if ($key[0] != ':') $key = ":$key"; // prefix with colon if needed + if (strpos($sql, $key) === false) continue; // skip if parameter is missing - if(is_int($value)) { + if (is_int($value)) { $sth->bindValue($key, $value, PDO::PARAM_INT); } else { $sth->bindValue($key, $value); @@ -683,18 +699,18 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { } $sth->execute(); - if(strtolower(substr($sql, 0, 6)) == 'select') { + if (strtolower(substr($sql, 0, 6)) == 'select') { $result = $sth->fetchAll(); } else { $result = $sth->rowCount(); } - } catch(Exception $e) { + } catch (Exception $e) { // report the caller's line $trace = debug_backtrace(); $line = $trace[0]['line']; - $dsql = $this->_debugSQL($sql, $params, !defined('DOKU_UNITTEST')); - $this->_debug($e, -1, $line); - $this->_debug("SQL: <pre>$dsql</pre>", -1, $line); + $dsql = $this->debugSQL($sql, $params, !defined('DOKU_UNITTEST')); + $this->debugMsg($e, -1, $line); + $this->debugMsg("SQL: <pre>$dsql</pre>", -1, $line); $result = false; } $sth->closeCursor(); @@ -710,17 +726,18 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { * @param int $err * @param int $line */ - protected function _debug($message, $err = 0, $line = 0) { - if(!$this->getConf('debug')) return; - if(is_a($message, 'Exception')) { + protected function debugMsg($message, $err = 0, $line = 0) + { + if (!$this->getConf('debug')) return; + if (is_a($message, 'Exception')) { $err = -1; $msg = $message->getMessage(); - if(!$line) $line = $message->getLine(); + if (!$line) $line = $message->getLine(); } else { $msg = $message; } - if(defined('DOKU_UNITTEST')) { + if (defined('DOKU_UNITTEST')) { printf("\n%s, %s:%d\n", $msg, __FILE__, $line); } else { msg('authpdo: ' . $msg, $err, $line, __FILE__); @@ -735,17 +752,18 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { * @param string[] $keys * @return bool */ - protected function _chkcnf($keys) { - foreach($keys as $key) { + protected function checkConfig($keys) + { + foreach ($keys as $key) { $params = explode(':', $key); $key = array_shift($params); $sql = trim($this->getConf($key)); // check if sql is set - if(!$sql) return false; + if (!$sql) return false; // check if needed params are there - foreach($params as $param) { - if(strpos($sql, ":$param") === false) return false; + foreach ($params as $param) { + if (strpos($sql, ":$param") === false) return false; } } @@ -760,20 +778,21 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin { * @param bool $htmlescape Should the result be escaped for output in HTML? * @return string */ - protected function _debugSQL($sql, $params, $htmlescape = true) { - foreach($params as $key => $val) { - if(is_int($val)) { + protected function debugSQL($sql, $params, $htmlescape = true) + { + foreach ($params as $key => $val) { + if (is_int($val)) { $val = $this->pdo->quote($val, PDO::PARAM_INT); - } elseif(is_bool($val)) { + } elseif (is_bool($val)) { $val = $this->pdo->quote($val, PDO::PARAM_BOOL); - } elseif(is_null($val)) { + } elseif (is_null($val)) { $val = 'NULL'; } else { $val = $this->pdo->quote($val); } $sql = str_replace($key, $val, $sql); } - if($htmlescape) $sql = hsc($sql); + if ($htmlescape) $sql = hsc($sql); return $sql; } } diff --git a/lib/plugins/authpdo/conf/metadata.php b/lib/plugins/authpdo/conf/metadata.php index 7c2ee8cdc..34e60a40e 100644 --- a/lib/plugins/authpdo/conf/metadata.php +++ b/lib/plugins/authpdo/conf/metadata.php @@ -23,5 +23,3 @@ $meta['update-user-pass'] = array('', '_caution' => 'danger'); $meta['insert-group'] = array('', '_caution' => 'danger'); $meta['join-group'] = array('', '_caution' => 'danger'); $meta['leave-group'] = array('', '_caution' => 'danger'); - - diff --git a/lib/plugins/authplain/_test/escaping.test.php b/lib/plugins/authplain/_test/escaping.test.php index a38940e1a..be4d06b4e 100644 --- a/lib/plugins/authplain/_test/escaping.test.php +++ b/lib/plugins/authplain/_test/escaping.test.php @@ -114,14 +114,14 @@ class auth_plugin_authplainharness extends auth_plugin_authplain { * @param boolean $bool */ public function setPregsplit_safe($bool) { - $this->_pregsplit_safe = $bool; + $this->pregsplit_safe = $bool; } /** * @return bool|mixed */ public function getPregsplit_safe(){ - return $this->_pregsplit_safe; + return $this->pregsplit_safe; } /** @@ -129,6 +129,6 @@ class auth_plugin_authplainharness extends auth_plugin_authplain { * @return array */ public function splitUserData($line){ - return $this->_splitUserData($line); + return parent::splitUserData($line); } } diff --git a/lib/plugins/authplain/auth.php b/lib/plugins/authplain/auth.php index 7dfa43a4f..374e7179c 100644 --- a/lib/plugins/authplain/auth.php +++ b/lib/plugins/authplain/auth.php @@ -1,6 +1,4 @@ <?php -// must be run within Dokuwiki -if(!defined('DOKU_INC')) die(); /** * Plaintext authentication backend @@ -10,15 +8,16 @@ if(!defined('DOKU_INC')) die(); * @author Chris Smith <chris@jalakai.co.uk> * @author Jan Schumann <js@schumann-it.com> */ -class auth_plugin_authplain extends DokuWiki_Auth_Plugin { +class auth_plugin_authplain extends DokuWiki_Auth_Plugin +{ /** @var array user cache */ protected $users = null; /** @var array filter pattern */ - protected $_pattern = array(); + protected $pattern = array(); /** @var bool safe version of preg_split */ - protected $_pregsplit_safe = false; + protected $pregsplit_safe = false; /** * Constructor @@ -28,14 +27,15 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { * * @author Christopher Smith <chris@jalakai.co.uk> */ - public function __construct() { + public function __construct() + { parent::__construct(); global $config_cascade; - if(!@is_readable($config_cascade['plainauth.users']['default'])) { + if (!@is_readable($config_cascade['plainauth.users']['default'])) { $this->success = false; } else { - if(@is_writable($config_cascade['plainauth.users']['default'])) { + if (@is_writable($config_cascade['plainauth.users']['default'])) { $this->cando['addUser'] = true; $this->cando['delUser'] = true; $this->cando['modLogin'] = true; @@ -48,7 +48,7 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { $this->cando['getUserCount'] = true; } - $this->_pregsplit_safe = version_compare(PCRE_VERSION,'6.7','>='); + $this->pregsplit_safe = version_compare(PCRE_VERSION, '6.7', '>='); } /** @@ -62,9 +62,10 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { * @param string $pass * @return bool */ - public function checkPass($user, $pass) { + public function checkPass($user, $pass) + { $userinfo = $this->getUserData($user); - if($userinfo === false) return false; + if ($userinfo === false) return false; return auth_verifyPassword($pass, $this->users[$user]['pass']); } @@ -84,8 +85,9 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { * @param bool $requireGroups (optional) ignored by this plugin, grps info always supplied * @return array|false */ - public function getUserData($user, $requireGroups=true) { - if($this->users === null) $this->_loadUserData(); + public function getUserData($user, $requireGroups = true) + { + if ($this->users === null) $this->loadUserData(); return isset($this->users[$user]) ? $this->users[$user] : false; } @@ -101,7 +103,8 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { * @param array $grps list of groups the user is in * @return string */ - protected function _createUserLine($user, $pass, $name, $mail, $grps) { + protected function createUserLine($user, $pass, $name, $mail, $grps) + { $groups = join(',', $grps); $userline = array($user, $pass, $name, $mail, $groups); $userline = str_replace('\\', '\\\\', $userline); // escape \ as \\ @@ -129,12 +132,13 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { * @param array $grps * @return bool|null|string */ - public function createUser($user, $pwd, $name, $mail, $grps = null) { + public function createUser($user, $pwd, $name, $mail, $grps = null) + { global $conf; global $config_cascade; // user mustn't already exist - if($this->getUserData($user) !== false) { + if ($this->getUserData($user) !== false) { msg($this->getLang('userexists'), -1); return false; } @@ -142,12 +146,12 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { $pass = auth_cryptPassword($pwd); // set default group if no groups specified - if(!is_array($grps)) $grps = array($conf['defaultgroup']); + if (!is_array($grps)) $grps = array($conf['defaultgroup']); // prepare user line - $userline = $this->_createUserLine($user, $pass, $name, $mail, $grps); + $userline = $this->createUserLine($user, $pass, $name, $mail, $grps); - if(!io_saveFile($config_cascade['plainauth.users']['default'], $userline, true)) { + if (!io_saveFile($config_cascade['plainauth.users']['default'], $userline, true)) { msg($this->getLang('writefail'), -1); return null; } @@ -164,38 +168,45 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { * @param array $changes array of field/value pairs to be changed (password will be clear text) * @return bool */ - public function modifyUser($user, $changes) { + public function modifyUser($user, $changes) + { global $ACT; global $config_cascade; // sanity checks, user must already exist and there must be something to change - if(($userinfo = $this->getUserData($user)) === false) { + if (($userinfo = $this->getUserData($user)) === false) { msg($this->getLang('usernotexists'), -1); return false; } // don't modify protected users - if(!empty($userinfo['protected'])) { + if (!empty($userinfo['protected'])) { msg(sprintf($this->getLang('protected'), hsc($user)), -1); return false; } - if(!is_array($changes) || !count($changes)) return true; + if (!is_array($changes) || !count($changes)) return true; // update userinfo with new data, remembering to encrypt any password $newuser = $user; - foreach($changes as $field => $value) { - if($field == 'user') { + foreach ($changes as $field => $value) { + if ($field == 'user') { $newuser = $value; continue; } - if($field == 'pass') $value = auth_cryptPassword($value); + if ($field == 'pass') $value = auth_cryptPassword($value); $userinfo[$field] = $value; } - $userline = $this->_createUserLine($newuser, $userinfo['pass'], $userinfo['name'], $userinfo['mail'], $userinfo['grps']); + $userline = $this->createUserLine( + $newuser, + $userinfo['pass'], + $userinfo['name'], + $userinfo['mail'], + $userinfo['grps'] + ); - if(!io_replaceInFile($config_cascade['plainauth.users']['default'], '/^'.$user.':/', $userline, true)) { + if (!io_replaceInFile($config_cascade['plainauth.users']['default'], '/^'.$user.':/', $userline, true)) { msg('There was an error modifying your user data. You may need to register again.', -1); // FIXME, io functions should be fail-safe so existing data isn't lost $ACT = 'register'; @@ -213,24 +224,25 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { * @param array $users array of users to be deleted * @return int the number of users deleted */ - public function deleteUsers($users) { + public function deleteUsers($users) + { global $config_cascade; - if(!is_array($users) || empty($users)) return 0; + if (!is_array($users) || empty($users)) return 0; - if($this->users === null) $this->_loadUserData(); + if ($this->users === null) $this->loadUserData(); $deleted = array(); - foreach($users as $user) { + foreach ($users as $user) { // don't delete protected users - if(!empty($this->users[$user]['protected'])) { + if (!empty($this->users[$user]['protected'])) { msg(sprintf($this->getLang('protected'), hsc($user)), -1); continue; } - if(isset($this->users[$user])) $deleted[] = preg_quote($user, '/'); + if (isset($this->users[$user])) $deleted[] = preg_quote($user, '/'); } - if(empty($deleted)) return 0; + if (empty($deleted)) return 0; $pattern = '/^('.join('|', $deleted).'):/'; if (!io_deleteFromFile($config_cascade['plainauth.users']['default'], $pattern, true)) { @@ -240,7 +252,7 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { // reload the user list and count the difference $count = count($this->users); - $this->_loadUserData(); + $this->loadUserData(); $count -= count($this->users); return $count; } @@ -253,17 +265,18 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { * @param array $filter * @return int */ - public function getUserCount($filter = array()) { + public function getUserCount($filter = array()) + { - if($this->users === null) $this->_loadUserData(); + if ($this->users === null) $this->loadUserData(); - if(!count($filter)) return count($this->users); + if (!count($filter)) return count($this->users); $count = 0; - $this->_constructPattern($filter); + $this->constructPattern($filter); - foreach($this->users as $user => $info) { - $count += $this->_filter($user, $info); + foreach ($this->users as $user => $info) { + $count += $this->filter($user, $info); } return $count; @@ -279,23 +292,24 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { * @param array $filter array of field/pattern pairs * @return array userinfo (refer getUserData for internal userinfo details) */ - public function retrieveUsers($start = 0, $limit = 0, $filter = array()) { + public function retrieveUsers($start = 0, $limit = 0, $filter = array()) + { - if($this->users === null) $this->_loadUserData(); + if ($this->users === null) $this->loadUserData(); ksort($this->users); $i = 0; $count = 0; $out = array(); - $this->_constructPattern($filter); + $this->constructPattern($filter); - foreach($this->users as $user => $info) { - if($this->_filter($user, $info)) { - if($i >= $start) { + foreach ($this->users as $user => $info) { + if ($this->filter($user, $info)) { + if ($i >= $start) { $out[$user] = $info; $count++; - if(($limit > 0) && ($count >= $limit)) break; + if (($limit > 0) && ($count >= $limit)) break; } $i++; } @@ -310,7 +324,8 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { * @param string $user * @return string */ - public function cleanUser($user) { + public function cleanUser($user) + { global $conf; return cleanID(str_replace(':', $conf['sepchar'], $user)); } @@ -321,7 +336,8 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { * @param string $group * @return string */ - public function cleanGroup($group) { + public function cleanGroup($group) + { global $conf; return cleanID(str_replace(':', $conf['sepchar'], $group)); } @@ -333,15 +349,16 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { * * @author Andreas Gohr <andi@splitbrain.org> */ - protected function _loadUserData() { + protected function loadUserData() + { global $config_cascade; - $this->users = $this->_readUserFile($config_cascade['plainauth.users']['default']); + $this->users = $this->readUserFile($config_cascade['plainauth.users']['default']); // support protected users - if(!empty($config_cascade['plainauth.users']['protected'])) { - $protected = $this->_readUserFile($config_cascade['plainauth.users']['protected']); - foreach(array_keys($protected) as $key) { + if (!empty($config_cascade['plainauth.users']['protected'])) { + $protected = $this->readUserFile($config_cascade['plainauth.users']['protected']); + foreach (array_keys($protected) as $key) { $protected[$key]['protected'] = true; } $this->users = array_merge($this->users, $protected); @@ -356,17 +373,18 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { * @param string $file the file to load data from * @return array */ - protected function _readUserFile($file) { + protected function readUserFile($file) + { $users = array(); - if(!file_exists($file)) return $users; + if (!file_exists($file)) return $users; $lines = file($file); - foreach($lines as $line) { + foreach ($lines as $line) { $line = preg_replace('/#.*$/', '', $line); //ignore comments $line = trim($line); - if(empty($line)) continue; + if (empty($line)) continue; - $row = $this->_splitUserData($line); + $row = $this->splitUserData($line); $row = str_replace('\\:', ':', $row); $row = str_replace('\\\\', '\\', $row); @@ -380,22 +398,29 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { return $users; } - protected function _splitUserData($line){ + /** + * Get the user line split into it's parts + * + * @param string $line + * @return string[] + */ + protected function splitUserData($line) + { // due to a bug in PCRE 6.6, preg_split will fail with the regex we use here // refer github issues 877 & 885 - if ($this->_pregsplit_safe){ + if ($this->pregsplit_safe) { return preg_split('/(?<![^\\\\]\\\\)\:/', $line, 5); // allow for : escaped as \: } $row = array(); $piece = ''; $len = strlen($line); - for($i=0; $i<$len; $i++){ - if ($line[$i]=='\\'){ + for ($i=0; $i<$len; $i++) { + if ($line[$i]=='\\') { $piece .= $line[$i]; $i++; if ($i>=$len) break; - } else if ($line[$i]==':'){ + } elseif ($line[$i]==':') { $row[] = $piece; $piece = ''; continue; @@ -416,14 +441,15 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { * @param array $info User's userinfo array * @return bool */ - protected function _filter($user, $info) { - foreach($this->_pattern as $item => $pattern) { - if($item == 'user') { - if(!preg_match($pattern, $user)) return false; - } else if($item == 'grps') { - if(!count(preg_grep($pattern, $info['grps']))) return false; + protected function filter($user, $info) + { + foreach ($this->pattern as $item => $pattern) { + if ($item == 'user') { + if (!preg_match($pattern, $user)) return false; + } elseif ($item == 'grps') { + if (!count(preg_grep($pattern, $info['grps']))) return false; } else { - if(!preg_match($pattern, $info[$item])) return false; + if (!preg_match($pattern, $info[$item])) return false; } } return true; @@ -434,10 +460,11 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { * * @param array $filter */ - protected function _constructPattern($filter) { - $this->_pattern = array(); - foreach($filter as $item => $pattern) { - $this->_pattern[$item] = '/'.str_replace('/', '\/', $pattern).'/i'; // allow regex characters + protected function constructPattern($filter) + { + $this->pattern = array(); + foreach ($filter as $item => $pattern) { + $this->pattern[$item] = '/'.str_replace('/', '\/', $pattern).'/i'; // allow regex characters } } } diff --git a/lib/plugins/config/_test/configuration.test.php b/lib/plugins/config/_test/configuration.test.php index 7455461a4..62ac23433 100644 --- a/lib/plugins/config/_test/configuration.test.php +++ b/lib/plugins/config/_test/configuration.test.php @@ -25,7 +25,7 @@ class plugin_config_configuration_test extends DokuWikiTest { function test_readconfig() { $confmgr = new configuration($this->meta); - $conf = $confmgr->_read_config($this->config); + $conf = $this->callInaccessibleMethod($confmgr, '_read_config', [$this->config]); // var_dump($conf); @@ -44,7 +44,7 @@ class plugin_config_configuration_test extends DokuWikiTest { function test_readconfig_onoff() { $confmgr = new configuration($this->meta); - $conf = $confmgr->_read_config($this->config); + $conf = $this->callInaccessibleMethod($confmgr, '_read_config', [$this->config]); // var_dump($conf); diff --git a/lib/plugins/config/admin.php b/lib/plugins/config/admin.php index 76ecae24c..e2fb622ab 100644 --- a/lib/plugins/config/admin.php +++ b/lib/plugins/config/admin.php @@ -6,8 +6,6 @@ * @author Christopher Smith <chris@jalakai.co.uk> * @author Ben Coburn <btcoburn@silicodon.net> */ -// must be run within Dokuwiki -if(!defined('DOKU_INC')) die(); define('CM_KEYMARKER','____'); // used for settings with multiple dimensions of array indices @@ -150,9 +148,16 @@ class admin_plugin_config extends DokuWiki_Admin_Plugin { // config settings list($label,$input) = $setting->html($this, $this->_error); - $class = $setting->is_default() ? ' class="default"' : ($setting->is_protected() ? ' class="protected"' : ''); - $error = $setting->error() ? ' class="value error"' : ' class="value"'; - $icon = $setting->caution() ? '<img src="'.DOKU_PLUGIN_IMAGES.$setting->caution().'.png" alt="'.$setting->caution().'" title="'.$this->getLang($setting->caution()).'" />' : ''; + $class = $setting->is_default() + ? ' class="default"' + : ($setting->is_protected() ? ' class="protected"' : ''); + $error = $setting->error() + ? ' class="value error"' + : ' class="value"'; + $icon = $setting->caution() + ? '<img src="'.DOKU_PLUGIN_IMAGES.$setting->caution().'.png" '. + 'alt="'.$setting->caution().'" title="'.$this->getLang($setting->caution()).'" />' + : ''; ptln(' <tr'.$class.'>'); ptln(' <td class="label">'); @@ -190,13 +195,20 @@ class admin_plugin_config extends DokuWiki_Admin_Plugin { ptln('<table class="inline">'); $undefined_setting_match = array(); foreach($undefined_settings as $setting) { - if (preg_match('/^(?:plugin|tpl)'.CM_KEYMARKER.'.*?'.CM_KEYMARKER.'(.*)$/', $setting->_key, $undefined_setting_match)) { + if ( + preg_match( + '/^(?:plugin|tpl)'.CM_KEYMARKER.'.*?'.CM_KEYMARKER.'(.*)$/', + $setting->_key, + $undefined_setting_match + ) + ) { $undefined_setting_key = $undefined_setting_match[1]; } else { $undefined_setting_key = $setting->_key; } ptln(' <tr>'); - ptln(' <td class="label"><span title="$meta[\''.$undefined_setting_key.'\']">$'.$this->_config->_name.'[\''.$setting->_out_key().'\']</span></td>'); + ptln(' <td class="label"><span title="$meta[\''.$undefined_setting_key.'\']">$'. + $this->_config->_name.'[\''.$setting->_out_key().'\']</span></td>'); ptln(' <td>'.$this->getLang('_msg_'.get_class($setting)).'</td>'); ptln(' </tr>'); } diff --git a/lib/plugins/config/settings/config.class.php b/lib/plugins/config/settings/config.class.php index 3196d7527..0d39eb2c5 100644 --- a/lib/plugins/config/settings/config.class.php +++ b/lib/plugins/config/settings/config.class.php @@ -15,22 +15,22 @@ if (!class_exists('configuration')) { */ class configuration { - var $_name = 'conf'; // name of the config variable found in the files (overridden by $config['varname']) - var $_format = 'php'; // format of the config file, supported formats - php (overridden by $config['format']) - var $_heading = ''; // heading string written at top of config file - don't include comment indicators - var $_loaded = false; // set to true after configuration files are loaded - var $_metadata = array(); // holds metadata describing the settings + protected $_name = 'conf'; // name of the config variable found in the files (overridden by $config['varname']) + protected $_format = 'php'; // format of the config file, supported formats - php (overridden by $config['format']) + protected $_heading = ''; // heading string written at top of config file - don't include comment indicators + protected $_loaded = false; // set to true after configuration files are loaded + protected $_metadata = array();// holds metadata describing the settings /** @var setting[] */ - var $setting = array(); // array of setting objects - var $locked = false; // configuration is considered locked if it can't be updated - var $show_disabled_plugins = false; + public $setting = array(); // array of setting objects + public $locked = false; // configuration is considered locked if it can't be updated + public $show_disabled_plugins = false; // configuration filenames - var $_default_files = array(); - var $_local_files = array(); // updated configuration is written to the first file - var $_protected_files = array(); + protected $_default_files = array(); + protected $_local_files = array(); // updated configuration is written to the first file + protected $_protected_files = array(); - var $_plugin_list = null; + protected $_plugin_list = null; /** * constructor @@ -45,6 +45,7 @@ if (!class_exists('configuration')) { return; } $meta = array(); + /** @var array $config gets loaded via include here */ include($datafile); if (isset($config['varname'])) $this->_name = $config['varname']; @@ -68,11 +69,19 @@ if (!class_exists('configuration')) { $no_default_check = array('setting_fieldset', 'setting_undefined', 'setting_no_class'); if (!$this->_loaded) { - $default = array_merge($this->get_plugintpl_default($conf['template']), $this->_read_config_group($this->_default_files)); + $default = array_merge( + $this->get_plugintpl_default($conf['template']), + $this->_read_config_group($this->_default_files) + ); $local = $this->_read_config_group($this->_local_files); $protected = $this->_read_config_group($this->_protected_files); - $keys = array_merge(array_keys($this->_metadata),array_keys($default), array_keys($local), array_keys($protected)); + $keys = array_merge( + array_keys($this->_metadata), + array_keys($default), + array_keys($local), + array_keys($protected) + ); $keys = array_unique($keys); $param = null; @@ -188,7 +197,7 @@ if (!class_exists('configuration')) { * @param string $file file path * @return array config settings */ - function _read_config($file) { + protected function _read_config($file) { if (!$file) return array(); @@ -345,7 +354,7 @@ if (!class_exists('configuration')) { * @return array plugin names * @triggers PLUGIN_CONFIG_PLUGINLIST event */ - function get_plugin_list() { + protected function get_plugin_list() { if (is_null($this->_plugin_list)) { $list = plugin_list('',$this->show_disabled_plugins); @@ -366,7 +375,7 @@ if (!class_exists('configuration')) { * @param string $tpl name of active template * @return array metadata of settings */ - function get_plugintpl_metadata($tpl){ + protected function get_plugintpl_metadata($tpl){ $file = '/conf/metadata.php'; $class = '/conf/settings.class.php'; $metadata = array(); @@ -378,7 +387,7 @@ if (!class_exists('configuration')) { @include(DOKU_PLUGIN.$plugin_dir.$file); @include(DOKU_PLUGIN.$plugin_dir.$class); if (!empty($meta)) { - $metadata['plugin'.CM_KEYMARKER.$plugin.CM_KEYMARKER.'plugin_settings_name'] = array('fieldset'); + $metadata['plugin'.CM_KEYMARKER.$plugin.CM_KEYMARKER.'plugin_settings_name'] = ['fieldset']; } foreach ($meta as $key => $value){ if ($value[0]=='fieldset') { continue; } //plugins only get one fieldset @@ -410,7 +419,7 @@ if (!class_exists('configuration')) { * @param string $tpl name of active template * @return array default settings */ - function get_plugintpl_default($tpl){ + protected function get_plugintpl_default($tpl){ $file = '/conf/default.php'; $default = array(); @@ -444,17 +453,17 @@ if (!class_exists('setting')) { */ class setting { - var $_key = ''; - var $_default = null; - var $_local = null; - var $_protected = null; + protected $_key = ''; + protected $_default = null; + protected $_local = null; + protected $_protected = null; - var $_pattern = ''; - var $_error = false; // only used by those classes which error check - var $_input = null; // only used by those classes which error check - var $_caution = null; // used by any setting to provide an alert along with the setting - // valid alerts, 'warning', 'danger', 'security' - // images matching the alerts are in the plugin's images directory + protected $_pattern = ''; + protected $_error = false; // only used by those classes which error check + protected $_input = null; // only used by those classes which error check + protected $_caution = null; // used by any setting to provide an alert along with the setting + // valid alerts, 'warning', 'danger', 'security' + // images matching the alerts are in the plugin's images directory static protected $_validCautions = array('warning','danger','security'); @@ -535,7 +544,8 @@ if (!class_exists('setting')) { $value = formText($value); $label = '<label for="config___'.$key.'">'.$this->prompt($plugin).'</label>'; - $input = '<textarea rows="3" cols="40" id="config___'.$key.'" name="config['.$key.']" class="edit" '.$disable.'>'.$value.'</textarea>'; + $input = '<textarea rows="3" cols="40" id="config___'.$key. + '" name="config['.$key.']" class="edit" '.$disable.'>'.$value.'</textarea>'; return array($label,$input); } @@ -603,7 +613,10 @@ if (!class_exists('setting')) { public function caution() { if (!empty($this->_caution)) { if (!in_array($this->_caution, setting::$_validCautions)) { - trigger_error('Invalid caution string ('.$this->_caution.') in metadata for setting "'.$this->_key.'"', E_USER_WARNING); + trigger_error( + 'Invalid caution string ('.$this->_caution.') in metadata for setting "'.$this->_key.'"', + E_USER_WARNING + ); return false; } return $this->_caution; @@ -681,7 +694,7 @@ if (!class_exists('setting_array')) { * @param string $input * @return bool true if changed, false otherwise (incl. on error) */ - function update($input) { + public function update($input) { if (is_null($input)) return false; if ($this->is_protected()) return false; @@ -720,7 +733,7 @@ if (!class_exists('setting_array')) { * @param string $fmt save format * @return string */ - function out($var, $fmt='php') { + public function out($var, $fmt='php') { if ($this->is_protected()) return ''; if (is_null($this->_local) || ($this->_default == $this->_local)) return ''; @@ -742,7 +755,7 @@ if (!class_exists('setting_array')) { * @param bool $echo true: show inputted value, when error occurred, otherwise the stored setting * @return string[] with content array(string $label_html, string $input_html) */ - function html(admin_plugin_config $plugin, $echo=false) { + public function html(admin_plugin_config $plugin, $echo=false) { $disable = ''; if ($this->is_protected()) { @@ -760,7 +773,8 @@ if (!class_exists('setting_array')) { $value = htmlspecialchars($this->_from_array($value)); $label = '<label for="config___'.$key.'">'.$this->prompt($plugin).'</label>'; - $input = '<input id="config___'.$key.'" name="config['.$key.']" type="text" class="edit" value="'.$value.'" '.$disable.'/>'; + $input = '<input id="config___'.$key.'" name="config['.$key. + ']" type="text" class="edit" value="'.$value.'" '.$disable.'/>'; return array($label,$input); } } @@ -778,7 +792,7 @@ if (!class_exists('setting_string')) { * @param bool $echo true: show inputted value, when error occurred, otherwise the stored setting * @return string[] with content array(string $label_html, string $input_html) */ - function html(admin_plugin_config $plugin, $echo=false) { + public function html(admin_plugin_config $plugin, $echo=false) { $disable = ''; if ($this->is_protected()) { @@ -796,7 +810,8 @@ if (!class_exists('setting_string')) { $value = htmlspecialchars($value); $label = '<label for="config___'.$key.'">'.$this->prompt($plugin).'</label>'; - $input = '<input id="config___'.$key.'" name="config['.$key.']" type="text" class="edit" value="'.$value.'" '.$disable.'/>'; + $input = '<input id="config___'.$key.'" name="config['.$key. + ']" type="text" class="edit" value="'.$value.'" '.$disable.'/>'; return array($label,$input); } } @@ -808,7 +823,7 @@ if (!class_exists('setting_password')) { */ class setting_password extends setting_string { - var $_code = 'plain'; // mechanism to be used to obscure passwords + protected $_code = 'plain'; // mechanism to be used to obscure passwords /** * update changed setting with user provided value $input @@ -818,7 +833,7 @@ if (!class_exists('setting_password')) { * @param mixed $input the new value * @return boolean true if changed, false otherwise (also on error) */ - function update($input) { + public function update($input) { if ($this->is_protected()) return false; if (!$input) return false; @@ -839,14 +854,15 @@ if (!class_exists('setting_password')) { * @param bool $echo true: show inputted value, when error occurred, otherwise the stored setting * @return string[] with content array(string $label_html, string $input_html) */ - function html(admin_plugin_config $plugin, $echo=false) { + public function html(admin_plugin_config $plugin, $echo=false) { $disable = $this->is_protected() ? 'disabled="disabled"' : ''; $key = htmlspecialchars($this->_key); $label = '<label for="config___'.$key.'">'.$this->prompt($plugin).'</label>'; - $input = '<input id="config___'.$key.'" name="config['.$key.']" autocomplete="off" type="password" class="edit" value="" '.$disable.' />'; + $input = '<input id="config___'.$key.'" name="config['.$key. + ']" autocomplete="off" type="password" class="edit" value="" '.$disable.' />'; return array($label,$input); } } @@ -857,8 +873,8 @@ if (!class_exists('setting_email')) { * Class setting_email */ class setting_email extends setting_string { - var $_multiple = false; - var $_placeholders = false; + protected $_multiple = false; + protected $_placeholders = false; /** * update setting with user provided value $input @@ -867,7 +883,7 @@ if (!class_exists('setting_email')) { * @param mixed $input * @return boolean true if changed, false otherwise (incl. on error) */ - function update($input) { + public function update($input) { if (is_null($input)) return false; if ($this->is_protected()) return false; @@ -923,9 +939,9 @@ if (!class_exists('setting_numeric')) { // This allows for many PHP syntax errors... // var $_pattern = '/^[-+\/*0-9 ]*$/'; // much more restrictive, but should eliminate syntax errors. - var $_pattern = '/^[-+]? *[0-9]+ *(?:[-+*] *[0-9]+ *)*$/'; - var $_min = null; - var $_max = null; + protected $_pattern = '/^[-+]? *[0-9]+ *(?:[-+*] *[0-9]+ *)*$/'; + protected $_min = null; + protected $_max = null; /** * update changed setting with user provided value $input @@ -935,7 +951,7 @@ if (!class_exists('setting_numeric')) { * @param mixed $input the new value * @return boolean true if changed, false otherwise (also on error) */ - function update($input) { + public function update($input) { $local = $this->_local; $valid = parent::update($input); if ($valid && !(is_null($this->_min) && is_null($this->_max))) { @@ -958,7 +974,7 @@ if (!class_exists('setting_numeric')) { * @param string $fmt save format * @return string */ - function out($var, $fmt='php') { + public function out($var, $fmt='php') { if ($this->is_protected()) return ''; if (is_null($this->_local) || ($this->_default == $this->_local)) return ''; @@ -981,7 +997,7 @@ if (!class_exists('setting_numericopt')) { */ class setting_numericopt extends setting_numeric { // just allow an empty config - var $_pattern = '/^(|[-]?[0-9]+(?:[-+*][0-9]+)*)$/'; + protected $_pattern = '/^(|[-]?[0-9]+(?:[-+*][0-9]+)*)$/'; /** @@ -991,7 +1007,7 @@ if (!class_exists('setting_numericopt')) { * * @return bool */ - function update($input) { + public function update($input) { if ($input === '') { return true; } @@ -1013,7 +1029,7 @@ if (!class_exists('setting_onoff')) { * @param bool $echo true: show inputted value, when error occurred, otherwise the stored setting * @return string[] with content array(string $label_html, string $input_html) */ - function html(admin_plugin_config $plugin, $echo = false) { + public function html(admin_plugin_config $plugin, $echo = false) { $disable = ''; if ($this->is_protected()) { @@ -1027,7 +1043,8 @@ if (!class_exists('setting_onoff')) { $checked = ($value) ? ' checked="checked"' : ''; $label = '<label for="config___'.$key.'">'.$this->prompt($plugin).'</label>'; - $input = '<div class="input"><input id="config___'.$key.'" name="config['.$key.']" type="checkbox" class="checkbox" value="1"'.$checked.$disable.'/></div>'; + $input = '<div class="input"><input id="config___'.$key.'" name="config['.$key. + ']" type="checkbox" class="checkbox" value="1"'.$checked.$disable.'/></div>'; return array($label,$input); } @@ -1039,7 +1056,7 @@ if (!class_exists('setting_onoff')) { * @param mixed $input the new value * @return boolean true if changed, false otherwise (also on error) */ - function update($input) { + public function update($input) { if ($this->is_protected()) return false; $input = ($input) ? 1 : 0; @@ -1057,8 +1074,8 @@ if (!class_exists('setting_multichoice')) { * Class setting_multichoice */ class setting_multichoice extends setting_string { - var $_choices = array(); - var $lang; //some custom language strings are stored in setting + protected $_choices = array(); + public $lang; //some custom language strings are stored in setting /** * Build html for label and input of setting @@ -1067,7 +1084,7 @@ if (!class_exists('setting_multichoice')) { * @param bool $echo true: show inputted value, when error occurred, otherwise the stored setting * @return string[] with content array(string $label_html, string $input_html) */ - function html(admin_plugin_config $plugin, $echo = false) { + public function html(admin_plugin_config $plugin, $echo = false) { $disable = ''; $nochoice = ''; @@ -1097,7 +1114,9 @@ if (!class_exists('setting_multichoice')) { foreach ($this->_choices as $choice) { $selected = ($value == $choice) ? ' selected="selected"' : ''; $option = $plugin->getLang($this->_key.'_o_'.$choice); - if (!$option && isset($this->lang[$this->_key.'_o_'.$choice])) $option = $this->lang[$this->_key.'_o_'.$choice]; + if (!$option && isset($this->lang[$this->_key.'_o_'.$choice])) { + $option = $this->lang[$this->_key . '_o_' . $choice]; + } if (!$option) $option = $choice; $choice = htmlspecialchars($choice); @@ -1118,7 +1137,7 @@ if (!class_exists('setting_multichoice')) { * @param mixed $input the new value * @return boolean true if changed, false otherwise (also on error) */ - function update($input) { + public function update($input) { if (is_null($input)) return false; if ($this->is_protected()) return false; @@ -1140,7 +1159,7 @@ if (!class_exists('setting_dirchoice')) { */ class setting_dirchoice extends setting_multichoice { - var $_dir = ''; + protected $_dir = ''; /** * Receives current values for the setting $key @@ -1149,7 +1168,7 @@ if (!class_exists('setting_dirchoice')) { * @param mixed $local local setting value * @param mixed $protected protected setting value */ - function initialize($default,$local,$protected) { + public function initialize($default,$local,$protected) { // populate $this->_choices with a list of directories $list = array(); @@ -1228,9 +1247,9 @@ if (!class_exists('setting_multicheckbox')) { */ class setting_multicheckbox extends setting_string { - var $_choices = array(); - var $_combine = array(); - var $_other = 'always'; + protected $_choices = array(); + protected $_combine = array(); + protected $_other = 'always'; /** * update changed setting with user provided value $input @@ -1240,7 +1259,7 @@ if (!class_exists('setting_multicheckbox')) { * @param mixed $input the new value * @return boolean true if changed, false otherwise (also on error) */ - function update($input) { + public function update($input) { if ($this->is_protected()) return false; // split any combined values + convert from array to comma separated string @@ -1267,7 +1286,7 @@ if (!class_exists('setting_multicheckbox')) { * @param bool $echo true: show input value, when error occurred, otherwise the stored setting * @return string[] with content array(string $label_html, string $input_html) */ - function html(admin_plugin_config $plugin, $echo=false) { + public function html(admin_plugin_config $plugin, $echo=false) { $disable = ''; @@ -1303,7 +1322,8 @@ if (!class_exists('setting_multicheckbox')) { $input .= '<div class="selection'.$class.'">'."\n"; $input .= '<label for="config___'.$key.'_'.$choice.'">'.$prompt."</label>\n"; - $input .= '<input id="config___'.$key.'_'.$choice.'" name="config['.$key.'][]" type="checkbox" class="checkbox" value="'.$choice.'" '.$disable.' '.$checked."/>\n"; + $input .= '<input id="config___'.$key.'_'.$choice.'" name="config['.$key. + '][]" type="checkbox" class="checkbox" value="'.$choice.'" '.$disable.' '.$checked."/>\n"; $input .= "</div>\n"; // remove this action from the disabledactions array @@ -1318,12 +1338,16 @@ if (!class_exists('setting_multicheckbox')) { // use != 'exists' rather than == 'always' to ensure invalid values default to 'always' if ($this->_other != 'exists' || $other) { - $class = ((count($default) == count($value)) && (count($value) == count(array_intersect($value,$default)))) ? + $class = ( + (count($default) == count($value)) && + (count($value) == count(array_intersect($value,$default))) + ) ? " selectiondefault" : ""; $input .= '<div class="other'.$class.'">'."\n"; $input .= '<label for="config___'.$key.'_other">'.$plugin->getLang($key.'_other')."</label>\n"; - $input .= '<input id="config___'.$key.'_other" name="config['.$key.'][other]" type="text" class="edit" value="'.htmlspecialchars($other).'" '.$disable." />\n"; + $input .= '<input id="config___'.$key.'_other" name="config['.$key. + '][other]" type="text" class="edit" value="'.htmlspecialchars($other).'" '.$disable." />\n"; $input .= "</div>\n"; } } @@ -1337,7 +1361,7 @@ if (!class_exists('setting_multicheckbox')) { * @param string $str * @return array */ - function _str2array($str) { + protected function _str2array($str) { $array = explode(',',$str); if (!empty($this->_combine)) { @@ -1363,7 +1387,7 @@ if (!class_exists('setting_multicheckbox')) { * @param array $input * @return string */ - function _array2str($input) { + protected function _array2str($input) { // handle other $other = trim($input['other']); @@ -1395,8 +1419,8 @@ if (!class_exists('setting_regex')){ */ class setting_regex extends setting_string { - var $_delimiter = '/'; // regex delimiter to be used in testing input - var $_pregflags = 'ui'; // regex pattern modifiers to be used in testing input + protected $_delimiter = '/'; // regex delimiter to be used in testing input + protected $_pregflags = 'ui'; // regex pattern modifiers to be used in testing input /** * update changed setting with user provided value $input @@ -1406,7 +1430,7 @@ if (!class_exists('setting_regex')){ * @param mixed $input the new value * @return boolean true if changed, false otherwise (incl. on error) */ - function update($input) { + public function update($input) { // let parent do basic checks, value, not changed, etc. $local = $this->_local; diff --git a/lib/plugins/config/settings/config.metadata.php b/lib/plugins/config/settings/config.metadata.php index acdf93ba7..8c1add7d1 100644 --- a/lib/plugins/config/settings/config.metadata.php +++ b/lib/plugins/config/settings/config.metadata.php @@ -122,7 +122,10 @@ $meta['fullpath'] = array('onoff','_caution' => 'security'); $meta['typography'] = array('multichoice','_choices' => array(0,1,2)); $meta['dformat'] = array('string'); $meta['signature'] = array('string'); -$meta['showuseras'] = array('multichoice','_choices' => array('loginname','username','username_link','email','email_link')); +$meta['showuseras'] = array( + 'multichoice', + '_choices' => array('loginname', 'username', 'username_link', 'email', 'email_link') +); $meta['toptoclevel'] = array('multichoice','_choices' => array(1,2,3,4,5)); // 5 toc levels $meta['tocminheads'] = array('multichoice','_choices' => array(0,1,2,3,4,5,10,15,20)); $meta['maxtoclevel'] = array('multichoice','_choices' => array(0,1,2,3,4,5)); @@ -146,9 +149,29 @@ $meta['superuser'] = array('string','_caution' => 'danger'); $meta['manager'] = array('string'); $meta['profileconfirm'] = array('onoff'); $meta['rememberme'] = array('onoff'); -$meta['disableactions'] = array('disableactions', - '_choices' => array('backlink','index','recent','revisions','search','subscription','register','resendpwd','profile','profile_delete','edit','wikicode','check', 'rss'), - '_combine' => array('subscription' => array('subscribe','unsubscribe'), 'wikicode' => array('source','export_raw'))); +$meta['disableactions'] = array( + 'disableactions', + '_choices' => array( + 'backlink', + 'index', + 'recent', + 'revisions', + 'search', + 'subscription', + 'register', + 'resendpwd', + 'profile', + 'profile_delete', + 'edit', + 'wikicode', + 'check', + 'rss' + ), + '_combine' => array( + 'subscription' => array('subscribe', 'unsubscribe'), + 'wikicode' => array('source', 'export_raw') + ) +); $meta['auth_security_timeout'] = array('numeric'); $meta['securecookie'] = array('onoff'); $meta['remote'] = array('onoff','_caution' => 'security'); diff --git a/lib/plugins/config/settings/extra.class.php b/lib/plugins/config/settings/extra.class.php index 41af42247..5f963fb81 100644 --- a/lib/plugins/config/settings/extra.class.php +++ b/lib/plugins/config/settings/extra.class.php @@ -15,7 +15,7 @@ if (!class_exists('setting_sepchar')) { * @param string $key * @param array|null $param array with metadata of setting */ - function __construct($key,$param=null) { + public function __construct($key,$param=null) { $str = '_-.'; for ($i=0;$i<strlen($str);$i++) $this->_choices[] = $str{$i}; @@ -39,7 +39,7 @@ if (!class_exists('setting_savedir')) { * @param mixed $input the new value * @return boolean true if changed, false otherwise (also on error) */ - function update($input) { + public function update($input) { if ($this->is_protected()) return false; $value = is_null($this->_local) ? $this->_default : $this->_local; @@ -70,7 +70,7 @@ if (!class_exists('setting_authtype')) { * @param mixed $local local setting value * @param mixed $protected protected setting value */ - function initialize($default,$local,$protected) { + public function initialize($default,$local,$protected) { /** @var $plugin_controller Doku_Plugin_Controller */ global $plugin_controller; @@ -90,7 +90,7 @@ if (!class_exists('setting_authtype')) { * @param mixed $input the new value * @return boolean true if changed, false otherwise (also on error) */ - function update($input) { + public function update($input) { /** @var $plugin_controller Doku_Plugin_Controller */ global $plugin_controller; @@ -143,7 +143,7 @@ if (!class_exists('setting_im_convert')) { * @param mixed $input the new value * @return boolean true if changed, false otherwise (also on error) */ - function update($input) { + public function update($input) { if ($this->is_protected()) return false; $input = trim($input); @@ -176,7 +176,7 @@ if (!class_exists('setting_disableactions')) { * @param bool $echo true: show inputted value, when error occurred, otherwise the stored setting * @return array with content array(string $label_html, string $input_html) */ - function html(admin_plugin_config $plugin, $echo=false) { + public function html(admin_plugin_config $plugin, $echo=false) { global $lang; // make some language adjustments (there must be a better way) @@ -197,7 +197,7 @@ if (!class_exists('setting_compression')) { */ class setting_compression extends setting_multichoice { - var $_choices = array('0'); // 0 = no compression, always supported + protected $_choices = array('0'); // 0 = no compression, always supported /** * Receives current values for the setting $key @@ -206,7 +206,7 @@ if (!class_exists('setting_compression')) { * @param mixed $local local setting value * @param mixed $protected protected setting value */ - function initialize($default,$local,$protected) { + public function initialize($default,$local,$protected) { // populate _choices with the compression methods supported by this php installation if (function_exists('gzopen')) $this->_choices[] = 'gz'; @@ -223,7 +223,7 @@ if (!class_exists('setting_license')) { */ class setting_license extends setting_multichoice { - var $_choices = array(''); // none choosen + protected $_choices = array(''); // none choosen /** * Receives current values for the setting $key @@ -232,7 +232,7 @@ if (!class_exists('setting_license')) { * @param mixed $local local setting value * @param mixed $protected protected setting value */ - function initialize($default,$local,$protected) { + public function initialize($default,$local,$protected) { global $license; foreach($license as $key => $data){ @@ -251,8 +251,8 @@ if (!class_exists('setting_renderer')) { * Class setting_renderer */ class setting_renderer extends setting_multichoice { - var $_prompts = array(); - var $_format = null; + protected $_prompts = array(); + protected $_format = null; /** * Receives current values for the setting $key @@ -261,7 +261,7 @@ if (!class_exists('setting_renderer')) { * @param mixed $local local setting value * @param mixed $protected protected setting value */ - function initialize($default,$local,$protected) { + public function initialize($default,$local,$protected) { $format = $this->_format; foreach (plugin_list('renderer') as $plugin) { @@ -284,7 +284,7 @@ if (!class_exists('setting_renderer')) { * @param bool $echo true: show inputted value, when error occurred, otherwise the stored setting * @return array with content array(string $label_html, string $input_html) */ - function html(admin_plugin_config $plugin, $echo=false) { + public function html(admin_plugin_config $plugin, $echo=false) { // make some language adjustments (there must be a better way) // transfer some plugin names to the config plugin diff --git a/lib/plugins/extension/_test/extension.test.php b/lib/plugins/extension/_test/extension.test.php index d4f13201d..1f8e2fca7 100644 --- a/lib/plugins/extension/_test/extension.test.php +++ b/lib/plugins/extension/_test/extension.test.php @@ -6,8 +6,8 @@ * makes protected methods accessible */ class mock_helper_plugin_extension_extension extends helper_plugin_extension_extension { - public function find_folders(&$result, $base, $default_type = 'plugin', $dir = '') { - return parent::find_folders($result, $base, $default_type, $dir); + public function findFolders(&$result, $base, $default_type = 'plugin', $dir = '') { + return parent::findFolders($result, $base, $default_type, $dir); } } @@ -78,7 +78,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest { $tdir = dirname(__FILE__).'/testdata'; $result = array('old' => array(), 'new' => array()); - $ok = $extension->find_folders($result, "$tdir/plugin1", 'plugin'); + $ok = $extension->findFolders($result, "$tdir/plugin1", 'plugin'); $this->assertTrue($ok); $this->assertEquals(0, count($result['new'])); $this->assertEquals(1, count($result['old'])); @@ -86,7 +86,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest { $this->assertEquals('plugin1', $this->extdir($result['old'][0]['tmp'])); $result = array('old' => array(), 'new' => array()); - $ok = $extension->find_folders($result, "$tdir/plugin2", 'plugin'); + $ok = $extension->findFolders($result, "$tdir/plugin2", 'plugin'); $this->assertTrue($ok); $this->assertEquals(1, count($result['new'])); $this->assertEquals('plugin', $result['new'][0]['type']); @@ -94,7 +94,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest { $this->assertEquals('plugin2', $this->extdir($result['new'][0]['tmp'])); $result = array('old' => array(), 'new' => array()); - $ok = $extension->find_folders($result, "$tdir/plgsub3", 'plugin'); + $ok = $extension->findFolders($result, "$tdir/plgsub3", 'plugin'); $this->assertTrue($ok); $this->assertEquals(0, count($result['new'])); $this->assertEquals(1, count($result['old'])); @@ -102,7 +102,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest { $this->assertEquals('plgsub3/plugin3', $this->extdir($result['old'][0]['tmp'])); $result = array('old' => array(), 'new' => array()); - $ok = $extension->find_folders($result, "$tdir/plgsub4", 'plugin'); + $ok = $extension->findFolders($result, "$tdir/plgsub4", 'plugin'); $this->assertTrue($ok); $this->assertEquals(1, count($result['new'])); $this->assertEquals('plugin', $result['new'][0]['type']); @@ -110,7 +110,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest { $this->assertEquals('plgsub4/plugin4', $this->extdir($result['new'][0]['tmp'])); $result = array('old' => array(), 'new' => array()); - $ok = $extension->find_folders($result, "$tdir/plgfoo5", 'plugin'); + $ok = $extension->findFolders($result, "$tdir/plgfoo5", 'plugin'); $this->assertTrue($ok); $this->assertEquals(1, count($result['new'])); $this->assertEquals('plugin', $result['new'][0]['type']); @@ -118,7 +118,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest { $this->assertEquals('plgfoo5', $this->extdir($result['new'][0]['tmp'])); $result = array('old' => array(), 'new' => array()); - $ok = $extension->find_folders($result, "$tdir/plgsub6/plgfoo6", 'plugin'); + $ok = $extension->findFolders($result, "$tdir/plgsub6/plgfoo6", 'plugin'); $this->assertTrue($ok); $this->assertEquals(1, count($result['new'])); $this->assertEquals('plugin', $result['new'][0]['type']); @@ -126,7 +126,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest { $this->assertEquals('plgsub6/plgfoo6', $this->extdir($result['new'][0]['tmp'])); $result = array('old' => array(), 'new' => array()); - $ok = $extension->find_folders($result, "$tdir/either1", 'plugin'); + $ok = $extension->findFolders($result, "$tdir/either1", 'plugin'); $this->assertTrue($ok); $this->assertEquals(0, count($result['new'])); $this->assertEquals(1, count($result['old'])); @@ -134,7 +134,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest { $this->assertEquals('either1', $this->extdir($result['old'][0]['tmp'])); $result = array('old' => array(), 'new' => array()); - $ok = $extension->find_folders($result, "$tdir/eithersub2/either2", 'plugin'); + $ok = $extension->findFolders($result, "$tdir/eithersub2/either2", 'plugin'); $this->assertTrue($ok); $this->assertEquals(0, count($result['new'])); $this->assertEquals(1, count($result['old'])); @@ -147,7 +147,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest { $tdir = dirname(__FILE__).'/testdata'; $result = array('old' => array(), 'new' => array()); - $ok = $extension->find_folders($result, "$tdir/template1", 'template'); + $ok = $extension->findFolders($result, "$tdir/template1", 'template'); $this->assertTrue($ok); $this->assertEquals(0, count($result['new'])); $this->assertEquals(1, count($result['old'])); @@ -155,7 +155,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest { $this->assertEquals('template1', $this->extdir($result['old'][0]['tmp'])); $result = array('old' => array(), 'new' => array()); - $ok = $extension->find_folders($result, "$tdir/template2", 'template'); + $ok = $extension->findFolders($result, "$tdir/template2", 'template'); $this->assertTrue($ok); $this->assertEquals(1, count($result['new'])); $this->assertEquals('template', $result['new'][0]['type']); @@ -163,7 +163,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest { $this->assertEquals('template2', $this->extdir($result['new'][0]['tmp'])); $result = array('old' => array(), 'new' => array()); - $ok = $extension->find_folders($result, "$tdir/tplsub3", 'template'); + $ok = $extension->findFolders($result, "$tdir/tplsub3", 'template'); $this->assertTrue($ok); $this->assertEquals(0, count($result['new'])); $this->assertEquals(1, count($result['old'])); @@ -171,7 +171,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest { $this->assertEquals('tplsub3/template3', $this->extdir($result['old'][0]['tmp'])); $result = array('old' => array(), 'new' => array()); - $ok = $extension->find_folders($result, "$tdir/tplsub4", 'template'); + $ok = $extension->findFolders($result, "$tdir/tplsub4", 'template'); $this->assertTrue($ok); $this->assertEquals(1, count($result['new'])); $this->assertEquals('template', $result['new'][0]['type']); @@ -179,7 +179,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest { $this->assertEquals('tplsub4/template4', $this->extdir($result['new'][0]['tmp'])); $result = array('old' => array(), 'new' => array()); - $ok = $extension->find_folders($result, "$tdir/tplfoo5", 'template'); + $ok = $extension->findFolders($result, "$tdir/tplfoo5", 'template'); $this->assertTrue($ok); $this->assertEquals(1, count($result['new'])); $this->assertEquals('template', $result['new'][0]['type']); @@ -187,7 +187,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest { $this->assertEquals('tplfoo5', $this->extdir($result['new'][0]['tmp'])); $result = array('old' => array(), 'new' => array()); - $ok = $extension->find_folders($result, "$tdir/tplsub6/tplfoo6", 'template'); + $ok = $extension->findFolders($result, "$tdir/tplsub6/tplfoo6", 'template'); $this->assertTrue($ok); $this->assertEquals(1, count($result['new'])); $this->assertEquals('template', $result['new'][0]['type']); @@ -195,7 +195,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest { $this->assertEquals('tplsub6/tplfoo6', $this->extdir($result['new'][0]['tmp'])); $result = array('old' => array(), 'new' => array()); - $ok = $extension->find_folders($result, "$tdir/either1", 'template'); + $ok = $extension->findFolders($result, "$tdir/either1", 'template'); $this->assertTrue($ok); $this->assertEquals(0, count($result['new'])); $this->assertEquals(1, count($result['old'])); @@ -203,7 +203,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest { $this->assertEquals('either1', $this->extdir($result['old'][0]['tmp'])); $result = array('old' => array(), 'new' => array()); - $ok = $extension->find_folders($result, "$tdir/eithersub2/either2", 'template'); + $ok = $extension->findFolders($result, "$tdir/eithersub2/either2", 'template'); $this->assertTrue($ok); $this->assertEquals(0, count($result['new'])); $this->assertEquals(1, count($result['old'])); @@ -216,7 +216,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest { $tdir = dirname(__FILE__).'/testdata'; $result = array('old' => array(), 'new' => array()); - $ok = $extension->find_folders($result, "$tdir/template1"); + $ok = $extension->findFolders($result, "$tdir/template1"); $this->assertTrue($ok); $this->assertEquals(0, count($result['new'])); $this->assertEquals(1, count($result['old'])); @@ -224,7 +224,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest { $this->assertEquals('template1', $this->extdir($result['old'][0]['tmp'])); $result = array('old' => array(), 'new' => array()); - $ok = $extension->find_folders($result, "$tdir/template2"); + $ok = $extension->findFolders($result, "$tdir/template2"); $this->assertTrue($ok); $this->assertEquals(1, count($result['new'])); $this->assertEquals('template', $result['new'][0]['type']); @@ -232,7 +232,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest { $this->assertEquals('template2', $this->extdir($result['new'][0]['tmp'])); $result = array('old' => array(), 'new' => array()); - $ok = $extension->find_folders($result, "$tdir/tplsub3"); + $ok = $extension->findFolders($result, "$tdir/tplsub3"); $this->assertTrue($ok); $this->assertEquals(0, count($result['new'])); $this->assertEquals(1, count($result['old'])); @@ -240,7 +240,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest { $this->assertEquals('tplsub3/template3', $this->extdir($result['old'][0]['tmp'])); $result = array('old' => array(), 'new' => array()); - $ok = $extension->find_folders($result, "$tdir/tplsub4"); + $ok = $extension->findFolders($result, "$tdir/tplsub4"); $this->assertTrue($ok); $this->assertEquals(1, count($result['new'])); $this->assertEquals('template', $result['new'][0]['type']); @@ -248,7 +248,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest { $this->assertEquals('tplsub4/template4', $this->extdir($result['new'][0]['tmp'])); $result = array('old' => array(), 'new' => array()); - $ok = $extension->find_folders($result, "$tdir/tplfoo5"); + $ok = $extension->findFolders($result, "$tdir/tplfoo5"); $this->assertTrue($ok); $this->assertEquals(1, count($result['new'])); $this->assertEquals('template', $result['new'][0]['type']); @@ -256,7 +256,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest { $this->assertEquals('tplfoo5', $this->extdir($result['new'][0]['tmp'])); $result = array('old' => array(), 'new' => array()); - $ok = $extension->find_folders($result, "$tdir/tplsub6/tplfoo6"); + $ok = $extension->findFolders($result, "$tdir/tplsub6/tplfoo6"); $this->assertTrue($ok); $this->assertEquals(1, count($result['new'])); $this->assertEquals('template', $result['new'][0]['type']); @@ -264,7 +264,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest { $this->assertEquals('tplsub6/tplfoo6', $this->extdir($result['new'][0]['tmp'])); $result = array('old' => array(), 'new' => array()); - $ok = $extension->find_folders($result, "$tdir/either1"); + $ok = $extension->findFolders($result, "$tdir/either1"); $this->assertTrue($ok); $this->assertEquals(0, count($result['new'])); $this->assertEquals(1, count($result['old'])); @@ -272,7 +272,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest { $this->assertEquals('either1', $this->extdir($result['old'][0]['tmp'])); $result = array('old' => array(), 'new' => array()); - $ok = $extension->find_folders($result, "$tdir/eithersub2/either2"); + $ok = $extension->findFolders($result, "$tdir/eithersub2/either2"); $this->assertTrue($ok); $this->assertEquals(0, count($result['new'])); $this->assertEquals(1, count($result['old'])); @@ -292,4 +292,4 @@ class helper_plugin_extension_extension_test extends DokuWikiTest { $dir = trim(substr($dir, $len), '/'); return $dir; } -}
\ No newline at end of file +} diff --git a/lib/plugins/extension/action.php b/lib/plugins/extension/action.php index 9e48f134b..75f5009ed 100644 --- a/lib/plugins/extension/action.php +++ b/lib/plugins/extension/action.php @@ -5,10 +5,8 @@ * @author Andreas Gohr <andi@splitbrain.org> */ -// must be run within Dokuwiki -if(!defined('DOKU_INC')) die(); - -class action_plugin_extension extends DokuWiki_Action_Plugin { +class action_plugin_extension extends DokuWiki_Action_Plugin +{ /** * Registers a callback function for a given event @@ -16,10 +14,10 @@ class action_plugin_extension extends DokuWiki_Action_Plugin { * @param Doku_Event_Handler $controller DokuWiki's event controller object * @return void */ - public function register(Doku_Event_Handler $controller) { + public function register(Doku_Event_Handler $controller) + { $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'info'); - } /** @@ -28,22 +26,23 @@ class action_plugin_extension extends DokuWiki_Action_Plugin { * @param Doku_Event $event * @param $param */ - public function info(Doku_Event &$event, $param) { + public function info(Doku_Event &$event, $param) + { global $USERINFO; global $INPUT; - if($event->data != 'plugin_extension') return; + if ($event->data != 'plugin_extension') return; $event->preventDefault(); $event->stopPropagation(); - if(empty($_SERVER['REMOTE_USER']) || !auth_isadmin($_SERVER['REMOTE_USER'], $USERINFO['grps'])) { + if (empty($_SERVER['REMOTE_USER']) || !auth_isadmin($_SERVER['REMOTE_USER'], $USERINFO['grps'])) { http_status(403); echo 'Forbidden'; exit; } $ext = $INPUT->str('ext'); - if(!$ext) { + if (!$ext) { http_status(400); echo 'no extension given'; return; @@ -54,7 +53,7 @@ class action_plugin_extension extends DokuWiki_Action_Plugin { $extension->setExtension($ext); $act = $INPUT->str('act'); - switch($act) { + switch ($act) { case 'enable': case 'disable': $json = new JSON(); @@ -77,9 +76,7 @@ class action_plugin_extension extends DokuWiki_Action_Plugin { /** @var helper_plugin_extension_list $list */ $list = plugin_load('helper', 'extension_list'); header('Content-Type: text/html; charset=utf-8'); - echo $list->make_info($extension); + echo $list->makeInfo($extension); } } - } - diff --git a/lib/plugins/extension/admin.php b/lib/plugins/extension/admin.php index 71257cf43..eb2009b4c 100644 --- a/lib/plugins/extension/admin.php +++ b/lib/plugins/extension/admin.php @@ -6,13 +6,11 @@ * @author Michael Hamann <michael@content-space.de> */ -// must be run within Dokuwiki -if(!defined('DOKU_INC')) die(); - /** * Admin part of the extension manager */ -class admin_plugin_extension extends DokuWiki_Admin_Plugin { +class admin_plugin_extension extends DokuWiki_Admin_Plugin +{ protected $infoFor = null; /** @var helper_plugin_extension_gui */ protected $gui; @@ -22,39 +20,43 @@ class admin_plugin_extension extends DokuWiki_Admin_Plugin { * * loads additional helpers */ - public function __construct() { + public function __construct() + { $this->gui = plugin_load('helper', 'extension_gui'); } /** * @return int sort number in admin menu */ - public function getMenuSort() { + public function getMenuSort() + { return 0; } /** * @return bool true if only access for superuser, false is for superusers and moderators */ - public function forAdminOnly() { + public function forAdminOnly() + { return true; } /** * Execute the requested action(s) and initialize the plugin repository */ - public function handle() { + public function handle() + { global $INPUT; // initialize the remote repository /* @var helper_plugin_extension_repository $repository */ $repository = $this->loadHelper('extension_repository'); - if(!$repository->hasAccess()) { + if (!$repository->hasAccess()) { $url = $this->gui->tabURL('', array('purge' => 1)); msg($this->getLang('repo_error').' [<a href="'.$url.'">'.$this->getLang('repo_retry').'</a>]', -1); } - if(!in_array('ssl', stream_get_transports())) { + if (!in_array('ssl', stream_get_transports())) { msg($this->getLang('nossl'), -1); } @@ -62,42 +64,60 @@ class admin_plugin_extension extends DokuWiki_Admin_Plugin { $extension = $this->loadHelper('extension_extension'); try { - if($INPUT->post->has('fn') && checkSecurityToken()) { + if ($INPUT->post->has('fn') && checkSecurityToken()) { $actions = $INPUT->post->arr('fn'); - foreach($actions as $action => $extensions) { - foreach($extensions as $extname => $label) { - switch($action) { + foreach ($actions as $action => $extensions) { + foreach ($extensions as $extname => $label) { + switch ($action) { case 'install': case 'reinstall': case 'update': $extension->setExtension($extname); $installed = $extension->installOrUpdate(); - foreach($installed as $ext => $info) { - msg(sprintf($this->getLang('msg_'.$info['type'].'_'.$info['action'].'_success'), $info['base']), 1); + foreach ($installed as $ext => $info) { + msg( + sprintf( + $this->getLang('msg_' . $info['type'] . '_' . $info['action'] . '_success'), + $info['base'] + ), + 1 + ); } break; case 'uninstall': $extension->setExtension($extname); $status = $extension->uninstall(); - if($status) { - msg(sprintf($this->getLang('msg_delete_success'), hsc($extension->getDisplayName())), 1); + if ($status) { + msg( + sprintf( + $this->getLang('msg_delete_success'), + hsc($extension->getDisplayName()) + ), + 1 + ); } else { - msg(sprintf($this->getLang('msg_delete_failed'), hsc($extension->getDisplayName())), -1); + msg( + sprintf( + $this->getLang('msg_delete_failed'), + hsc($extension->getDisplayName()) + ), + -1 + ); } break; - case 'enable'; + case 'enable': $extension->setExtension($extname); $status = $extension->enable(); - if($status !== true) { + if ($status !== true) { msg($status, -1); } else { msg(sprintf($this->getLang('msg_enabled'), hsc($extension->getDisplayName())), 1); } break; - case 'disable'; + case 'disable': $extension->setExtension($extname); $status = $extension->disable(); - if($status !== true) { + if ($status !== true) { msg($status, -1); } else { msg(sprintf($this->getLang('msg_disabled'), hsc($extension->getDisplayName())), 1); @@ -107,37 +127,36 @@ class admin_plugin_extension extends DokuWiki_Admin_Plugin { } } send_redirect($this->gui->tabURL('', array(), '&', true)); - } elseif($INPUT->post->str('installurl') && checkSecurityToken()) { + } elseif ($INPUT->post->str('installurl') && checkSecurityToken()) { $installed = $extension->installFromURL($INPUT->post->str('installurl')); - foreach($installed as $ext => $info) { + foreach ($installed as $ext => $info) { msg(sprintf($this->getLang('msg_'.$info['type'].'_'.$info['action'].'_success'), $info['base']), 1); } send_redirect($this->gui->tabURL('', array(), '&', true)); - } elseif(isset($_FILES['installfile']) && checkSecurityToken()) { + } elseif (isset($_FILES['installfile']) && checkSecurityToken()) { $installed = $extension->installFromUpload('installfile'); - foreach($installed as $ext => $info) { + foreach ($installed as $ext => $info) { msg(sprintf($this->getLang('msg_'.$info['type'].'_'.$info['action'].'_success'), $info['base']), 1); } send_redirect($this->gui->tabURL('', array(), '&', true)); } - - } catch(Exception $e) { + } catch (Exception $e) { msg($e->getMessage(), -1); send_redirect($this->gui->tabURL('', array(), '&', true)); } - } /** * Render HTML output */ - public function html() { + public function html() + { ptln('<h1>'.$this->getLang('menu').'</h1>'); ptln('<div id="extension__manager">'); $this->gui->tabNavigation(); - switch($this->gui->currentTab()) { + switch ($this->gui->currentTab()) { case 'search': $this->gui->tabSearch(); break; @@ -156,4 +175,4 @@ class admin_plugin_extension extends DokuWiki_Admin_Plugin { } } -// vim:ts=4:sw=4:et:
\ No newline at end of file +// vim:ts=4:sw=4:et: diff --git a/lib/plugins/extension/helper/extension.php b/lib/plugins/extension/helper/extension.php index e77528b97..a80a8244b 100644 --- a/lib/plugins/extension/helper/extension.php +++ b/lib/plugins/extension/helper/extension.php @@ -6,14 +6,11 @@ * @author Michael Hamann <michael@content-space.de> */ -// must be run within Dokuwiki -if(!defined('DOKU_INC')) die(); -if(!defined('DOKU_TPLLIB')) define('DOKU_TPLLIB', DOKU_INC.'lib/tpl/'); - /** * Class helper_plugin_extension_extension represents a single extension (plugin or template) */ -class helper_plugin_extension_extension extends DokuWiki_Plugin { +class helper_plugin_extension_extension extends DokuWiki_Plugin +{ private $id; private $base; private $is_template = false; @@ -26,13 +23,25 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { /** @var array list of temporary directories */ private $temporary = array(); + /** @var string where templates are installed to */ + private $tpllib = ''; + + /** + * helper_plugin_extension_extension constructor. + */ + public function __construct() + { + $this->tpllib = dirname(tpl_incdir()).'/'; + } + /** * Destructor * * deletes any dangling temporary directories */ - public function __destruct() { - foreach($this->temporary as $dir){ + public function __destruct() + { + foreach ($this->temporary as $dir) { io_rmdir($dir, true); } } @@ -40,7 +49,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { /** * @return bool false, this component is not a singleton */ - public function isSingleton() { + public function isSingleton() + { return false; } @@ -50,12 +60,13 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * @param string $id The id of the extension (prefixed with template: for templates) * @return bool If some (local or remote) data was found */ - public function setExtension($id) { + public function setExtension($id) + { $id = cleanID($id); $this->id = $id; $this->base = $id; - if(substr($id, 0 , 9) == 'template:'){ + if (substr($id, 0, 9) == 'template:') { $this->base = substr($id, 9); $this->is_template = true; } else { @@ -85,7 +96,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return bool If the extension is installed locally */ - public function isInstalled() { + public function isInstalled() + { return is_dir($this->getInstallDir()); } @@ -94,8 +106,9 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return bool */ - public function isGitControlled() { - if(!$this->isInstalled()) return false; + public function isGitControlled() + { + if (!$this->isInstalled()) return false; return is_dir($this->getInstallDir().'/.git'); } @@ -104,12 +117,16 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return bool If the extension is bundled */ - public function isBundled() { + public function isBundled() + { if (!empty($this->remoteInfo['bundled'])) return $this->remoteInfo['bundled']; - return in_array($this->id, - array( - 'authad', 'authldap', 'authmysql', 'authpdo', 'authpgsql', 'authplain', 'acl', 'info', 'extension', - 'revert', 'popularity', 'config', 'safefnrecode', 'styling', 'testing', 'template:dokuwiki' + return in_array( + $this->id, + array( + 'authad', 'authldap', 'authmysql', 'authpdo', + 'authpgsql', 'authplain', 'acl', 'info', 'extension', + 'revert', 'popularity', 'config', 'safefnrecode', 'styling', + 'testing', 'template:dokuwiki' ) ); } @@ -119,7 +136,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return bool if the extension is protected */ - public function isProtected() { + public function isProtected() + { // never allow deinstalling the current auth plugin: global $conf; if ($this->id == $conf['authtype']) return true; @@ -135,7 +153,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return bool If the extension is installed in the correct directory */ - public function isInWrongFolder() { + public function isInWrongFolder() + { return $this->base != $this->getBase(); } @@ -144,9 +163,10 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return bool If the extension is enabled */ - public function isEnabled() { + public function isEnabled() + { global $conf; - if($this->isTemplate()){ + if ($this->isTemplate()) { return ($conf['template'] == $this->getBase()); } @@ -160,9 +180,10 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return bool If an update is available */ - public function updateAvailable() { - if(!$this->isInstalled()) return false; - if($this->isBundled()) return false; + public function updateAvailable() + { + if (!$this->isInstalled()) return false; + if ($this->isBundled()) return false; $lastupdate = $this->getLastUpdate(); if ($lastupdate === false) return false; $installed = $this->getInstalledVersion(); @@ -175,7 +196,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return bool If this extension is a template */ - public function isTemplate() { + public function isTemplate() + { return $this->is_template; } @@ -186,7 +208,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return string */ - public function getID() { + public function getID() + { return $this->id; } @@ -195,7 +218,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return string The name of the installation directory */ - public function getInstallName() { + public function getInstallName() + { return $this->base; } @@ -205,7 +229,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return string The basename */ - public function getBase() { + public function getBase() + { if (!empty($this->localInfo['base'])) return $this->localInfo['base']; return $this->base; } @@ -215,7 +240,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return string The display name */ - public function getDisplayName() { + public function getDisplayName() + { if (!empty($this->localInfo['name'])) return $this->localInfo['name']; if (!empty($this->remoteInfo['name'])) return $this->remoteInfo['name']; return $this->base; @@ -226,7 +252,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return string|bool The name of the author or false if there is none */ - public function getAuthor() { + public function getAuthor() + { if (!empty($this->localInfo['author'])) return $this->localInfo['author']; if (!empty($this->remoteInfo['author'])) return $this->remoteInfo['author']; return false; @@ -237,7 +264,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return string|bool The email address or false if there is none */ - public function getEmail() { + public function getEmail() + { // email is only in the local data if (!empty($this->localInfo['email'])) return $this->localInfo['email']; return false; @@ -248,7 +276,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return string|bool The md5sum of the email if there is any, false otherwise */ - public function getEmailID() { + public function getEmailID() + { if (!empty($this->remoteInfo['emailid'])) return $this->remoteInfo['emailid']; if (!empty($this->localInfo['email'])) return md5($this->localInfo['email']); return false; @@ -259,7 +288,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return string The description */ - public function getDescription() { + public function getDescription() + { if (!empty($this->localInfo['desc'])) return $this->localInfo['desc']; if (!empty($this->remoteInfo['description'])) return $this->remoteInfo['description']; return ''; @@ -270,7 +300,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return string The URL */ - public function getURL() { + public function getURL() + { if (!empty($this->localInfo['url'])) return $this->localInfo['url']; return 'https://www.dokuwiki.org/'.($this->isTemplate() ? 'template' : 'plugin').':'.$this->getBase(); } @@ -280,7 +311,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return string|bool The version, usually in the form yyyy-mm-dd if there is any */ - public function getInstalledVersion() { + public function getInstalledVersion() + { if (!empty($this->localInfo['date'])) return $this->localInfo['date']; if ($this->isInstalled()) return $this->getLang('unknownversion'); return false; @@ -291,7 +323,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return string|bool The date of the last update or false if not available */ - public function getUpdateDate() { + public function getUpdateDate() + { if (!empty($this->managerData['updated'])) return $this->managerData['updated']; return $this->getInstallDate(); } @@ -301,7 +334,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return string|bool The date of the installation or false if not available */ - public function getInstallDate() { + public function getInstallDate() + { if (!empty($this->managerData['installed'])) return $this->managerData['installed']; return false; } @@ -311,7 +345,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return array The base names of the dependencies */ - public function getDependencies() { + public function getDependencies() + { if (!empty($this->remoteInfo['dependencies'])) return $this->remoteInfo['dependencies']; return array(); } @@ -321,7 +356,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return array The base names of the missing dependencies */ - public function getMissingDependencies() { + public function getMissingDependencies() + { /* @var Doku_Plugin_Controller $plugin_controller */ global $plugin_controller; $dependencies = $this->getDependencies(); @@ -339,7 +375,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return array The names of the conflicting extensions */ - public function getConflicts() { + public function getConflicts() + { if (!empty($this->remoteInfo['conflicts'])) return $this->remoteInfo['conflicts']; return array(); } @@ -349,7 +386,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return array The names of similar extensions */ - public function getSimilarExtensions() { + public function getSimilarExtensions() + { if (!empty($this->remoteInfo['similar'])) return $this->remoteInfo['similar']; return array(); } @@ -359,7 +397,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return array The names of the tags of the extension */ - public function getTags() { + public function getTags() + { if (!empty($this->remoteInfo['tags'])) return $this->remoteInfo['tags']; return array(); } @@ -369,7 +408,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return float|bool The popularity information or false if it isn't available */ - public function getPopularity() { + public function getPopularity() + { if (!empty($this->remoteInfo['popularity'])) return $this->remoteInfo['popularity']; return false; } @@ -380,7 +420,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return string|bool The security warning if there is any, false otherwise */ - public function getSecurityWarning() { + public function getSecurityWarning() + { if (!empty($this->remoteInfo['securitywarning'])) return $this->remoteInfo['securitywarning']; return false; } @@ -390,7 +431,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return string|bool The security issue if there is any, false otherwise */ - public function getSecurityIssue() { + public function getSecurityIssue() + { if (!empty($this->remoteInfo['securityissue'])) return $this->remoteInfo['securityissue']; return false; } @@ -400,7 +442,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return string|bool The screenshot URL if there is any, false otherwise */ - public function getScreenshotURL() { + public function getScreenshotURL() + { if (!empty($this->remoteInfo['screenshoturl'])) return $this->remoteInfo['screenshoturl']; return false; } @@ -410,7 +453,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return string|bool The thumbnail URL if there is any, false otherwise */ - public function getThumbnailURL() { + public function getThumbnailURL() + { if (!empty($this->remoteInfo['thumbnailurl'])) return $this->remoteInfo['thumbnailurl']; return false; } @@ -419,7 +463,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return string|bool The previously used download URL, false if the extension has been installed manually */ - public function getLastDownloadURL() { + public function getLastDownloadURL() + { if (!empty($this->managerData['downloadurl'])) return $this->managerData['downloadurl']; return false; } @@ -429,7 +474,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return string|bool The download URL if there is any, false otherwise */ - public function getDownloadURL() { + public function getDownloadURL() + { if (!empty($this->remoteInfo['downloadurl'])) return $this->remoteInfo['downloadurl']; return false; } @@ -439,7 +485,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return bool If the download URL has changed */ - public function hasDownloadURLChanged() { + public function hasDownloadURLChanged() + { $lasturl = $this->getLastDownloadURL(); $currenturl = $this->getDownloadURL(); return ($lasturl && $currenturl && $lasturl != $currenturl); @@ -450,7 +497,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return string|bool The bug tracker URL if there is any, false otherwise */ - public function getBugtrackerURL() { + public function getBugtrackerURL() + { if (!empty($this->remoteInfo['bugtracker'])) return $this->remoteInfo['bugtracker']; return false; } @@ -460,7 +508,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return string|bool The URL of the source repository if there is any, false otherwise */ - public function getSourcerepoURL() { + public function getSourcerepoURL() + { if (!empty($this->remoteInfo['sourcerepo'])) return $this->remoteInfo['sourcerepo']; return false; } @@ -470,7 +519,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return string|bool The donation URL if there is any, false otherwise */ - public function getDonationURL() { + public function getDonationURL() + { if (!empty($this->remoteInfo['donationurl'])) return $this->remoteInfo['donationurl']; return false; } @@ -480,7 +530,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return array The type(s) as array of strings */ - public function getTypes() { + public function getTypes() + { if (!empty($this->remoteInfo['types'])) return $this->remoteInfo['types']; if ($this->isTemplate()) return array(32 => 'template'); return array(); @@ -491,7 +542,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return array The versions in the form yyyy-mm-dd => ('label' => label, 'implicit' => implicit) */ - public function getCompatibleVersions() { + public function getCompatibleVersions() + { if (!empty($this->remoteInfo['compatible'])) return $this->remoteInfo['compatible']; return array(); } @@ -501,7 +553,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return string|bool The last available update in the form yyyy-mm-dd if there is any, false otherwise */ - public function getLastUpdate() { + public function getLastUpdate() + { if (!empty($this->remoteInfo['lastupdate'])) return $this->remoteInfo['lastupdate']; return false; } @@ -511,9 +564,10 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return string The base path of the extension */ - public function getInstallDir() { + public function getInstallDir() + { if ($this->isTemplate()) { - return DOKU_TPLLIB.$this->base; + return $this->tpllib.$this->base; } else { return DOKU_PLUGIN.$this->base; } @@ -524,7 +578,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return string One of "none", "manual", "git" or "automatic" */ - public function getInstallType() { + public function getInstallType() + { if (!$this->isInstalled()) return 'none'; if (!empty($this->managerData)) return 'automatic'; if (is_dir($this->getInstallDir().'/.git')) return 'git'; @@ -536,17 +591,17 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return bool|string True or error string */ - public function canModify() { - if($this->isInstalled()) { - if(!is_writable($this->getInstallDir())) { + public function canModify() + { + if ($this->isInstalled()) { + if (!is_writable($this->getInstallDir())) { return 'noperms'; } } - if($this->isTemplate() && !is_writable(DOKU_TPLLIB)) { + if ($this->isTemplate() && !is_writable($this->tpllib)) { return 'notplperms'; - - } elseif(!is_writable(DOKU_PLUGIN)) { + } elseif (!is_writable(DOKU_PLUGIN)) { return 'nopluginperms'; } return true; @@ -559,20 +614,21 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * @throws Exception when something goes wrong * @return array The list of installed extensions */ - public function installFromUpload($field){ - if($_FILES[$field]['error']){ + public function installFromUpload($field) + { + if ($_FILES[$field]['error']) { throw new Exception($this->getLang('msg_upload_failed').' ('.$_FILES[$field]['error'].')'); } $tmp = $this->mkTmpDir(); - if(!$tmp) throw new Exception($this->getLang('error_dircreate')); + if (!$tmp) throw new Exception($this->getLang('error_dircreate')); // filename may contain the plugin name for old style plugins... $basename = basename($_FILES[$field]['name']); $basename = preg_replace('/\.(tar\.gz|tar\.bz|tar\.bz2|tar|tgz|tbz|zip)$/', '', $basename); $basename = preg_replace('/[\W]+/', '', $basename); - if(!move_uploaded_file($_FILES[$field]['tmp_name'], "$tmp/upload.archive")){ + if (!move_uploaded_file($_FILES[$field]['tmp_name'], "$tmp/upload.archive")) { throw new Exception($this->getLang('msg_upload_failed')); } @@ -582,7 +638,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { $this->removeDeletedfiles($installed); // purge cache $this->purgeCache(); - }catch (Exception $e){ + } catch (Exception $e) { throw $e; } return $installed; @@ -595,7 +651,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * @throws Exception when something goes wrong * @return array The list of installed extensions */ - public function installFromURL($url){ + public function installFromURL($url) + { try { $path = $this->download($url); $installed = $this->installArchive($path, true); @@ -604,7 +661,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { // purge cache $this->purgeCache(); - }catch (Exception $e){ + } catch (Exception $e) { throw $e; } return $installed; @@ -616,7 +673,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * @throws \Exception when something goes wrong * @return array The list of installed extensions */ - public function installOrUpdate() { + public function installOrUpdate() + { $url = $this->getDownloadURL(); $path = $this->download($url); $installed = $this->installArchive($path, $this->isInstalled(), $this->getBase()); @@ -637,7 +695,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return bool If the plugin was sucessfully uninstalled */ - public function uninstall() { + public function uninstall() + { $this->purgeCache(); return io_rmdir($this->getInstallDir(), true); } @@ -647,7 +706,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return bool|string True or an error message */ - public function enable() { + public function enable() + { if ($this->isTemplate()) return $this->getLang('notimplemented'); if (!$this->isInstalled()) return $this->getLang('notinstalled'); if ($this->isEnabled()) return $this->getLang('alreadyenabled'); @@ -667,7 +727,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return bool|string True or an error message */ - public function disable() { + public function disable() + { if ($this->isTemplate()) return $this->getLang('notimplemented'); /* @var Doku_Plugin_Controller $plugin_controller */ @@ -685,7 +746,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { /** * Purge the cache by touching the main configuration file */ - protected function purgeCache() { + protected function purgeCache() + { global $config_cascade; // expire dokuwiki caches @@ -696,7 +758,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { /** * Read local extension data either from info.txt or getInfo() */ - protected function readLocalData() { + protected function readLocalData() + { if ($this->isTemplate()) { $infopath = $this->getInstallDir().'/template.info.txt'; } else { @@ -710,15 +773,15 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { $path = $this->getInstallDir().'/'; $plugin = null; - foreach($plugin_types as $type) { - if(file_exists($path.$type.'.php')) { + foreach ($plugin_types as $type) { + if (file_exists($path.$type.'.php')) { $plugin = plugin_load($type, $this->base); if ($plugin) break; } - if($dh = @opendir($path.$type.'/')) { - while(false !== ($cp = readdir($dh))) { - if($cp == '.' || $cp == '..' || strtolower(substr($cp, -4)) != '.php') continue; + if ($dh = @opendir($path.$type.'/')) { + while (false !== ($cp = readdir($dh))) { + if ($cp == '.' || $cp == '..' || strtolower(substr($cp, -4)) != '.php') continue; $plugin = plugin_load($type, $this->base.'_'.substr($cp, 0, -4)); if ($plugin) break; @@ -741,21 +804,22 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * @param string $url Where the extension was downloaded from. (empty for manual installs via upload) * @param array $installed Optional list of installed plugins */ - protected function updateManagerData($url = '', $installed = null) { + protected function updateManagerData($url = '', $installed = null) + { $origID = $this->getID(); - if(is_null($installed)) { + if (is_null($installed)) { $installed = array($origID); } - foreach($installed as $ext => $info) { - if($this->getID() != $ext) $this->setExtension($ext); - if($url) { + foreach ($installed as $ext => $info) { + if ($this->getID() != $ext) $this->setExtension($ext); + if ($url) { $this->managerData['downloadurl'] = $url; - } elseif(isset($this->managerData['downloadurl'])) { + } elseif (isset($this->managerData['downloadurl'])) { unset($this->managerData['downloadurl']); } - if(isset($this->managerData['installed'])) { + if (isset($this->managerData['installed'])) { $this->managerData['updated'] = date('r'); } else { $this->managerData['installed'] = date('r'); @@ -763,23 +827,24 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { $this->writeManagerData(); } - if($this->getID() != $origID) $this->setExtension($origID); + if ($this->getID() != $origID) $this->setExtension($origID); } /** * Read the manager.dat file */ - protected function readManagerData() { + protected function readManagerData() + { $managerpath = $this->getInstallDir().'/manager.dat'; if (is_readable($managerpath)) { $file = @file($managerpath); - if(!empty($file)) { - foreach($file as $line) { + if (!empty($file)) { + foreach ($file as $line) { list($key, $value) = explode('=', trim($line, DOKU_LF), 2); $key = trim($key); $value = trim($value); // backwards compatible with old plugin manager - if($key == 'url') $key = 'downloadurl'; + if ($key == 'url') $key = 'downloadurl'; $this->managerData[$key] = $value; } } @@ -789,7 +854,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { /** * Write the manager.data file */ - protected function writeManagerData() { + protected function writeManagerData() + { $managerpath = $this->getInstallDir().'/manager.dat'; $data = ''; foreach ($this->managerData as $k => $v) { @@ -805,9 +871,10 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @return false|string */ - protected function mkTmpDir(){ + protected function mkTmpDir() + { $dir = io_mktmpdir(); - if(!$dir) return false; + if (!$dir) return false; $this->temporary[] = $dir; return $dir; } @@ -819,27 +886,28 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * @throws Exception when something goes wrong * @return string The path where the archive was saved */ - public function download($url) { + public function download($url) + { // check the url - if(!preg_match('/https?:\/\//i', $url)){ + if (!preg_match('/https?:\/\//i', $url)) { throw new Exception($this->getLang('error_badurl')); } // try to get the file from the path (used as plugin name fallback) $file = parse_url($url, PHP_URL_PATH); - if(is_null($file)){ + if (is_null($file)) { $file = md5($url); - }else{ + } else { $file = utf8_basename($file); } // create tmp directory for download - if(!($tmp = $this->mkTmpDir())) { + if (!($tmp = $this->mkTmpDir())) { throw new Exception($this->getLang('error_dircreate')); } // download - if(!$file = io_download($url, $tmp.'/', true, $file, 0)) { + if (!$file = io_download($url, $tmp.'/', true, $file, 0)) { io_rmdir($tmp, true); throw new Exception(sprintf($this->getLang('error_download'), '<bdi>'.hsc($url).'</bdi>')); } @@ -854,16 +922,17 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * @throws Exception when something went wrong * @return array list of installed extensions */ - public function installArchive($file, $overwrite=false, $base = '') { + public function installArchive($file, $overwrite = false, $base = '') + { $installed_extensions = array(); // create tmp directory for decompression - if(!($tmp = $this->mkTmpDir())) { + if (!($tmp = $this->mkTmpDir())) { throw new Exception($this->getLang('error_dircreate')); } // add default base folder if specified to handle case where zip doesn't contain this - if($base && !@mkdir($tmp.'/'.$base)) { + if ($base && !@mkdir($tmp.'/'.$base)) { throw new Exception($this->getLang('error_dircreate')); } @@ -874,33 +943,33 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { // move the folder(s) to lib/.. $result = array('old'=>array(), 'new'=>array()); $default = ($this->isTemplate() ? 'template' : 'plugin'); - if(!$this->find_folders($result, $tmp.'/'.$base, $default)) { + if (!$this->findFolders($result, $tmp.'/'.$base, $default)) { throw new Exception($this->getLang('error_findfolder')); } // choose correct result array - if(count($result['new'])) { + if (count($result['new'])) { $install = $result['new']; - }else{ + } else { $install = $result['old']; } - if(!count($install)){ + if (!count($install)) { throw new Exception($this->getLang('error_findfolder')); } // now install all found items - foreach($install as $item) { + foreach ($install as $item) { // where to install? - if($item['type'] == 'template') { - $target_base_dir = DOKU_TPLLIB; - }else{ + if ($item['type'] == 'template') { + $target_base_dir = $this->tpllib; + } else { $target_base_dir = DOKU_PLUGIN; } - if(!empty($item['base'])) { + if (!empty($item['base'])) { // use base set in info.txt - } elseif($base && count($install) == 1) { + } elseif ($base && count($install) == 1) { $item['base'] = $base; } else { // default - use directory as found in zip @@ -911,7 +980,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { // check to make sure we aren't overwriting anything $target = $target_base_dir.$item['base']; - if(!$overwrite && file_exists($target)) { + if (!$overwrite && file_exists($target)) { // TODO remember our settings, ask the user to confirm overwrite continue; } @@ -919,10 +988,10 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { $action = file_exists($target) ? 'update' : 'install'; // copy action - if($this->dircopy($item['tmp'], $target)) { + if ($this->dircopy($item['tmp'], $target)) { // return info $id = $item['base']; - if($item['type'] == 'template') { + if ($item['type'] == 'template') { $id = 'template:'.$id; } $installed_extensions[$id] = array( @@ -936,7 +1005,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { } // cleanup - if($tmp) io_rmdir($tmp, true); + if ($tmp) io_rmdir($tmp, true); return $installed_extensions; } @@ -962,20 +1031,20 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * @param string $subdir - a subdirectory. do not set. used by recursion * @return bool - false on error */ - protected function find_folders(&$result, $directory, $default_type='plugin', $subdir='') { + protected function findFolders(&$result, $directory, $default_type = 'plugin', $subdir = '') + { $this_dir = "$directory$subdir"; $dh = @opendir($this_dir); - if(!$dh) return false; + if (!$dh) return false; $found_dirs = array(); $found_files = 0; $found_template_parts = 0; while (false !== ($f = readdir($dh))) { - if($f == '.' || $f == '..') continue; + if ($f == '.' || $f == '..') continue; - if(is_dir("$this_dir/$f")) { + if (is_dir("$this_dir/$f")) { $found_dirs[] = "$subdir/$f"; - } else { // it's a file -> check for config $found_files++; @@ -1004,11 +1073,11 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { closedir($dh); // files where found but no info.txt - use old method - if($found_files){ + if ($found_files) { $info = array(); $info['tmp'] = $this_dir; // does this look like a template or should we use the default type? - if($found_template_parts >= 2) { + if ($found_template_parts >= 2) { $info['type'] = 'template'; } else { $info['type'] = $default_type; @@ -1020,7 +1089,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { // we have no files yet -> recurse foreach ($found_dirs as $found_dir) { - $this->find_folders($result, $directory, $default_type, "$found_dir"); + $this->findFolders($result, $directory, $default_type, "$found_dir"); } return true; } @@ -1035,13 +1104,13 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * @throws Exception * @return bool */ - private function decompress($file, $target) { + private function decompress($file, $target) + { // decompression library doesn't like target folders ending in "/" - if(substr($target, -1) == "/") $target = substr($target, 0, -1); - - $ext = $this->guess_archive($file); - if(in_array($ext, array('tar', 'bz', 'gz'))) { + if (substr($target, -1) == "/") $target = substr($target, 0, -1); + $ext = $this->guessArchiveType($file); + if (in_array($ext, array('tar', 'bz', 'gz'))) { try { $tar = new \splitbrain\PHPArchive\Tar(); $tar->open($file); @@ -1051,8 +1120,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { } return true; - } elseif($ext == 'zip') { - + } elseif ($ext == 'zip') { try { $zip = new \splitbrain\PHPArchive\Zip(); $zip->open($file); @@ -1078,15 +1146,16 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * @param string $file The file to analyze * @return string|false false if the file can't be read, otherwise an "extension" */ - private function guess_archive($file) { + private function guessArchiveType($file) + { $fh = fopen($file, 'rb'); - if(!$fh) return false; + if (!$fh) return false; $magic = fread($fh, 5); fclose($fh); - if(strpos($magic, "\x42\x5a") === 0) return 'bz'; - if(strpos($magic, "\x1f\x8b") === 0) return 'gz'; - if(strpos($magic, "\x50\x4b\x03\x04") === 0) return 'zip'; + if (strpos($magic, "\x42\x5a") === 0) return 'bz'; + if (strpos($magic, "\x1f\x8b") === 0) return 'gz'; + if (strpos($magic, "\x50\x4b\x03\x04") === 0) return 'zip'; return 'tar'; } @@ -1097,27 +1166,27 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * @param string $dst filename path to file * @return bool|int|string */ - private function dircopy($src, $dst) { + private function dircopy($src, $dst) + { global $conf; - if(is_dir($src)) { - if(!$dh = @opendir($src)) return false; + if (is_dir($src)) { + if (!$dh = @opendir($src)) return false; - if($ok = io_mkdir_p($dst)) { + if ($ok = io_mkdir_p($dst)) { while ($ok && (false !== ($f = readdir($dh)))) { - if($f == '..' || $f == '.') continue; + if ($f == '..' || $f == '.') continue; $ok = $this->dircopy("$src/$f", "$dst/$f"); } } closedir($dh); return $ok; - } else { $exists = file_exists($dst); - if(!@copy($src, $dst)) return false; - if(!$exists && !empty($conf['fperm'])) chmod($dst, $conf['fperm']); + if (!@copy($src, $dst)) return false; + if (!$exists && !empty($conf['fperm'])) chmod($dst, $conf['fperm']); @touch($dst, filemtime($src)); } @@ -1129,29 +1198,30 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @param array $installed */ - private function removeDeletedfiles($installed) { - foreach($installed as $id => $extension) { + private function removeDeletedfiles($installed) + { + foreach ($installed as $id => $extension) { // only on update - if($extension['action'] == 'install') continue; + if ($extension['action'] == 'install') continue; // get definition file - if($extension['type'] == 'template') { - $extensiondir = DOKU_TPLLIB; - }else{ + if ($extension['type'] == 'template') { + $extensiondir = $this->tpllib; + } else { $extensiondir = DOKU_PLUGIN; } $extensiondir = $extensiondir . $extension['base'] .'/'; $definitionfile = $extensiondir . 'deleted.files'; - if(!file_exists($definitionfile)) continue; + if (!file_exists($definitionfile)) continue; // delete the old files $list = file($definitionfile); - foreach($list as $line) { + foreach ($list as $line) { $line = trim(preg_replace('/#.*$/', '', $line)); - if(!$line) continue; + if (!$line) continue; $file = $extensiondir . $line; - if(!file_exists($file)) continue; + if (!file_exists($file)) continue; io_rmdir($file, true); } diff --git a/lib/plugins/extension/helper/gui.php b/lib/plugins/extension/helper/gui.php index 4ec6fec85..f646b9cd1 100644 --- a/lib/plugins/extension/helper/gui.php +++ b/lib/plugins/extension/helper/gui.php @@ -6,13 +6,11 @@ * @author Andreas Gohr <andi@splitbrain.org> */ -// must be run within Dokuwiki -if(!defined('DOKU_INC')) die(); - /** * Class helper_plugin_extension_list takes care of the overall GUI */ -class helper_plugin_extension_gui extends DokuWiki_Plugin { +class helper_plugin_extension_gui extends DokuWiki_Plugin +{ protected $tabs = array('plugins', 'templates', 'search', 'install'); @@ -24,7 +22,8 @@ class helper_plugin_extension_gui extends DokuWiki_Plugin { * * initializes requested info window */ - public function __construct() { + public function __construct() + { global $INPUT; $this->infoFor = $INPUT->str('info'); } @@ -32,7 +31,8 @@ class helper_plugin_extension_gui extends DokuWiki_Plugin { /** * display the plugin tab */ - public function tabPlugins() { + public function tabPlugins() + { /* @var Doku_Plugin_Controller $plugin_controller */ global $plugin_controller; @@ -46,19 +46,20 @@ class helper_plugin_extension_gui extends DokuWiki_Plugin { $extension = $this->loadHelper('extension_extension'); /* @var helper_plugin_extension_list $list */ $list = $this->loadHelper('extension_list'); - $list->start_form(); - foreach($pluginlist as $name) { + $list->startForm(); + foreach ($pluginlist as $name) { $extension->setExtension($name); - $list->add_row($extension, $extension->getID() == $this->infoFor); + $list->addRow($extension, $extension->getID() == $this->infoFor); } - $list->end_form(); + $list->endForm(); $list->render(); } /** * Display the template tab */ - public function tabTemplates() { + public function tabTemplates() + { echo '<div class="panelHeader">'; echo $this->locale_xhtml('intro_templates'); echo '</div>'; @@ -72,19 +73,20 @@ class helper_plugin_extension_gui extends DokuWiki_Plugin { $extension = $this->loadHelper('extension_extension'); /* @var helper_plugin_extension_list $list */ $list = $this->loadHelper('extension_list'); - $list->start_form(); - foreach($tpllist as $name) { + $list->startForm(); + foreach ($tpllist as $name) { $extension->setExtension("template:$name"); - $list->add_row($extension, $extension->getID() == $this->infoFor); + $list->addRow($extension, $extension->getID() == $this->infoFor); } - $list->end_form(); + $list->endForm(); $list->render(); } /** * Display the search tab */ - public function tabSearch() { + public function tabSearch() + { global $INPUT; echo '<div class="panelHeader">'; echo $this->locale_xhtml('intro_search'); @@ -95,7 +97,7 @@ class helper_plugin_extension_gui extends DokuWiki_Plugin { $form->addElement(form_makeButton('submit', '', $this->getLang('search'))); $form->printForm(); - if(!$INPUT->bool('q')) return; + if (!$INPUT->bool('q')) return; /* @var helper_plugin_extension_repository $repository FIXME should we use some gloabl instance? */ $repository = $this->loadHelper('extension_repository'); @@ -105,29 +107,35 @@ class helper_plugin_extension_gui extends DokuWiki_Plugin { $extension = $this->loadHelper('extension_extension'); /* @var helper_plugin_extension_list $list */ $list = $this->loadHelper('extension_list'); - $list->start_form(); - if($result){ - foreach($result as $name) { + $list->startForm(); + if ($result) { + foreach ($result as $name) { $extension->setExtension($name); - $list->add_row($extension, $extension->getID() == $this->infoFor); + $list->addRow($extension, $extension->getID() == $this->infoFor); } } else { - $list->nothing_found(); + $list->nothingFound(); } - $list->end_form(); + $list->endForm(); $list->render(); - } /** * Display the template tab */ - public function tabInstall() { + public function tabInstall() + { echo '<div class="panelHeader">'; echo $this->locale_xhtml('intro_install'); echo '</div>'; - $form = new Doku_Form(array('action' => $this->tabURL('', array(), '&'), 'enctype' => 'multipart/form-data', 'class' => 'install')); + $form = new Doku_Form( + array( + 'action' => $this->tabURL('', array(), '&'), + 'enctype' => 'multipart/form-data', + 'class' => 'install' + ) + ); $form->addElement(form_makeTextField('installurl', '', $this->getLang('install_url'), '', 'block')); $form->addElement(form_makeFileField('installfile', $this->getLang('install_upload'), '', 'block')); $form->addElement(form_makeButton('submit', '', $this->getLang('btn_install'))); @@ -139,11 +147,12 @@ class helper_plugin_extension_gui extends DokuWiki_Plugin { * * @fixme style active one */ - public function tabNavigation() { + public function tabNavigation() + { echo '<ul class="tabs">'; - foreach($this->tabs as $tab) { + foreach ($this->tabs as $tab) { $url = $this->tabURL($tab); - if($this->currentTab() == $tab) { + if ($this->currentTab() == $tab) { $class = ' active'; } else { $class = ''; @@ -158,11 +167,12 @@ class helper_plugin_extension_gui extends DokuWiki_Plugin { * * @return string */ - public function currentTab() { + public function currentTab() + { global $INPUT; $tab = $INPUT->str('tab', 'plugins', true); - if(!in_array($tab, $this->tabs)) $tab = 'plugins'; + if (!in_array($tab, $this->tabs)) $tab = 'plugins'; return $tab; } @@ -175,19 +185,19 @@ class helper_plugin_extension_gui extends DokuWiki_Plugin { * @param bool $absolute create absolute URLs? * @return string */ - public function tabURL($tab = '', $params = array(), $sep = '&', $absolute = false) { + public function tabURL($tab = '', $params = array(), $sep = '&', $absolute = false) + { global $ID; global $INPUT; - if(!$tab) $tab = $this->currentTab(); + if (!$tab) $tab = $this->currentTab(); $defaults = array( 'do' => 'admin', 'page' => 'extension', 'tab' => $tab, ); - if($tab == 'search') $defaults['q'] = $INPUT->str('q'); + if ($tab == 'search') $defaults['q'] = $INPUT->str('q'); return wl($ID, array_merge($defaults, $params), $absolute, $sep); } - } diff --git a/lib/plugins/extension/helper/list.php b/lib/plugins/extension/helper/list.php index 656b4ea09..d895941cb 100644 --- a/lib/plugins/extension/helper/list.php +++ b/lib/plugins/extension/helper/list.php @@ -6,13 +6,11 @@ * @author Michael Hamann <michael@content-space.de> */ -// must be run within Dokuwiki -if(!defined('DOKU_INC')) die(); - /** * Class helper_plugin_extension_list takes care of creating a HTML list of extensions */ -class helper_plugin_extension_list extends DokuWiki_Plugin { +class helper_plugin_extension_list extends DokuWiki_Plugin +{ protected $form = ''; /** @var helper_plugin_extension_gui */ protected $gui; @@ -22,30 +20,38 @@ class helper_plugin_extension_list extends DokuWiki_Plugin { * * loads additional helpers */ - public function __construct(){ + public function __construct() + { $this->gui = plugin_load('helper', 'extension_gui'); } - function start_form() { + /** + * Initialize the extension table form + */ + public function startForm() + { $this->form .= '<form id="extension__list" accept-charset="utf-8" method="post" action="">'; $hidden = array( 'do'=>'admin', 'page'=>'extension', 'sectok'=>getSecurityToken() ); - $this->add_hidden($hidden); + $this->addHidden($hidden); $this->form .= '<ul class="extensionList">'; } + /** * Build single row of extension table + * * @param helper_plugin_extension_extension $extension The extension that shall be added * @param bool $showinfo Show the info area */ - function add_row(helper_plugin_extension_extension $extension, $showinfo = false) { - $this->start_row($extension); - $this->populate_column('legend', $this->make_legend($extension, $showinfo)); - $this->populate_column('actions', $this->make_actions($extension)); - $this->end_row(); + public function addRow(helper_plugin_extension_extension $extension, $showinfo = false) + { + $this->startRow($extension); + $this->populateColumn('legend', $this->makeLegend($extension, $showinfo)); + $this->populateColumn('actions', $this->makeActions($extension)); + $this->endRow(); } /** @@ -55,7 +61,8 @@ class helper_plugin_extension_list extends DokuWiki_Plugin { * @param string $header The content of the header * @param int $level The level of the header */ - function add_header($id, $header, $level = 2) { + public function addHeader($id, $header, $level = 2) + { $this->form .='<h'.$level.' id="'.$id.'">'.hsc($header).'</h'.$level.'>'.DOKU_LF; } @@ -64,17 +71,20 @@ class helper_plugin_extension_list extends DokuWiki_Plugin { * * @param string $data The content */ - function add_p($data) { + public function addParagraph($data) + { $this->form .= '<p>'.hsc($data).'</p>'.DOKU_LF; } /** * Add hidden fields to the form with the given data - * @param array $array + * + * @param array $data key-value list of fields and their values to add */ - function add_hidden(array $array) { + public function addHidden(array $data) + { $this->form .= '<div class="no">'; - foreach ($array as $key => $value) { + foreach ($data as $key => $value) { $this->form .= '<input type="hidden" name="'.hsc($key).'" value="'.hsc($value).'" />'; } $this->form .= '</div>'.DOKU_LF; @@ -83,7 +93,8 @@ class helper_plugin_extension_list extends DokuWiki_Plugin { /** * Add closing tags */ - function end_form() { + public function endForm() + { $this->form .= '</ul>'; $this->form .= '</form>'.DOKU_LF; } @@ -91,7 +102,8 @@ class helper_plugin_extension_list extends DokuWiki_Plugin { /** * Show message when no results are found */ - function nothing_found() { + public function nothingFound() + { global $lang; $this->form .= '<li class="notfound">'.$lang['nothingfound'].'</li>'; } @@ -99,7 +111,8 @@ class helper_plugin_extension_list extends DokuWiki_Plugin { /** * Print the form */ - function render() { + public function render() + { echo $this->form; } @@ -108,8 +121,10 @@ class helper_plugin_extension_list extends DokuWiki_Plugin { * * @param helper_plugin_extension_extension $extension The extension */ - private function start_row(helper_plugin_extension_extension $extension) { - $this->form .= '<li id="extensionplugin__'.hsc($extension->getID()).'" class="'.$this->make_class($extension).'">'; + private function startRow(helper_plugin_extension_extension $extension) + { + $this->form .= '<li id="extensionplugin__'.hsc($extension->getID()). + '" class="'.$this->makeClass($extension).'">'; } /** @@ -117,14 +132,16 @@ class helper_plugin_extension_list extends DokuWiki_Plugin { * @param string $class The class name * @param string $html The content */ - private function populate_column($class, $html) { + private function populateColumn($class, $html) + { $this->form .= '<div class="'.$class.' col">'.$html.'</div>'.DOKU_LF; } /** * End the row */ - private function end_row() { + private function endRow() + { $this->form .= '</li>'.DOKU_LF; } @@ -134,7 +151,8 @@ class helper_plugin_extension_list extends DokuWiki_Plugin { * @param helper_plugin_extension_extension $extension The extension * @return string The HTML code */ - function make_homepagelink(helper_plugin_extension_extension $extension) { + public function makeHomepageLink(helper_plugin_extension_extension $extension) + { $text = $this->getLang('homepage_link'); $url = hsc($extension->getURL()); return '<a href="'.$url.'" title="'.$url.'" class ="urlextern">'.$text.'</a> '; @@ -146,15 +164,16 @@ class helper_plugin_extension_list extends DokuWiki_Plugin { * @param helper_plugin_extension_extension $extension The extension object * @return string The class name */ - function make_class(helper_plugin_extension_extension $extension) { + public function makeClass(helper_plugin_extension_extension $extension) + { $class = ($extension->isTemplate()) ? 'template' : 'plugin'; - if($extension->isInstalled()) { + if ($extension->isInstalled()) { $class.=' installed'; $class.= ($extension->isEnabled()) ? ' enabled':' disabled'; - if($extension->updateAvailable()) $class .= ' updatable'; + if ($extension->updateAvailable()) $class .= ' updatable'; } - if(!$extension->canModify()) $class.= ' notselect'; - if($extension->isProtected()) $class.= ' protected'; + if (!$extension->canModify()) $class.= ' notselect'; + if ($extension->isProtected()) $class.= ' protected'; //if($this->showinfo) $class.= ' showinfo'; return $class; } @@ -165,17 +184,16 @@ class helper_plugin_extension_list extends DokuWiki_Plugin { * @param helper_plugin_extension_extension $extension The extension object * @return string The HTML code of the link */ - function make_author(helper_plugin_extension_extension $extension) { - global $ID; - - if($extension->getAuthor()) { - + public function makeAuthor(helper_plugin_extension_extension $extension) + { + if ($extension->getAuthor()) { $mailid = $extension->getEmailID(); - if($mailid){ + if ($mailid) { $url = $this->gui->tabURL('search', array('q' => 'authorid:'.$mailid)); - return '<bdi><a href="'.$url.'" class="author" title="'.$this->getLang('author_hint').'" ><img src="//www.gravatar.com/avatar/'.$mailid.'?s=20&d=mm" width="20" height="20" alt="" /> '.hsc($extension->getAuthor()).'</a></bdi>'; - - }else{ + return '<bdi><a href="'.$url.'" class="author" title="'.$this->getLang('author_hint').'" >'. + '<img src="//www.gravatar.com/avatar/'.$mailid.'?s=20&d=mm" width="20" height="20" alt="" /> '. + hsc($extension->getAuthor()).'</a></bdi>'; + } else { return '<bdi><span class="author">'.hsc($extension->getAuthor()).'</span></bdi>'; } } @@ -188,11 +206,12 @@ class helper_plugin_extension_list extends DokuWiki_Plugin { * @param helper_plugin_extension_extension $extension The extension object * @return string The HTML code */ - function make_screenshot(helper_plugin_extension_extension $extension) { + public function makeScreenshot(helper_plugin_extension_extension $extension) + { $screen = $extension->getScreenshotURL(); $thumb = $extension->getThumbnailURL(); - if($screen) { + if ($screen) { // use protocol independent URLs for images coming from us #595 $screen = str_replace('http://www.dokuwiki.org', '//www.dokuwiki.org', $screen); $thumb = str_replace('http://www.dokuwiki.org', '//www.dokuwiki.org', $thumb); @@ -201,11 +220,12 @@ class helper_plugin_extension_list extends DokuWiki_Plugin { $img = '<a href="'.hsc($screen).'" target="_blank" class="extension_screenshot">'. '<img alt="'.$title.'" width="120" height="70" src="'.hsc($thumb).'" />'. '</a>'; - } elseif($extension->isTemplate()) { - $img = '<img alt="" width="120" height="70" src="'.DOKU_BASE.'lib/plugins/extension/images/template.png" />'; - + } elseif ($extension->isTemplate()) { + $img = '<img alt="" width="120" height="70" src="'.DOKU_BASE. + 'lib/plugins/extension/images/template.png" />'; } else { - $img = '<img alt="" width="120" height="70" src="'.DOKU_BASE.'lib/plugins/extension/images/plugin.png" />'; + $img = '<img alt="" width="120" height="70" src="'.DOKU_BASE. + 'lib/plugins/extension/images/plugin.png" />'; } return '<div class="screenshot" >'.$img.'<span></span></div>'.DOKU_LF; } @@ -217,41 +237,51 @@ class helper_plugin_extension_list extends DokuWiki_Plugin { * @param bool $showinfo Show the info section * @return string The HTML code */ - function make_legend(helper_plugin_extension_extension $extension, $showinfo = false) { + public function makeLegend(helper_plugin_extension_extension $extension, $showinfo = false) + { $return = '<div>'; $return .= '<h2>'; - $return .= sprintf($this->getLang('extensionby'), '<bdi>'.hsc($extension->getDisplayName()).'</bdi>', $this->make_author($extension)); + $return .= sprintf( + $this->getLang('extensionby'), + '<bdi>'.hsc($extension->getDisplayName()).'</bdi>', + $this->makeAuthor($extension) + ); $return .= '</h2>'.DOKU_LF; - $return .= $this->make_screenshot($extension); + $return .= $this->makeScreenshot($extension); $popularity = $extension->getPopularity(); if ($popularity !== false && !$extension->isBundled()) { $popularityText = sprintf($this->getLang('popularity'), round($popularity*100, 2)); - $return .= '<div class="popularity" title="'.$popularityText.'"><div style="width: '.($popularity * 100).'%;"><span class="a11y">'.$popularityText.'</span></div></div>'.DOKU_LF; + $return .= '<div class="popularity" title="'.$popularityText.'">'. + '<div style="width: '.($popularity * 100).'%;">'. + '<span class="a11y">'.$popularityText.'</span>'. + '</div></div>'.DOKU_LF; } - if($extension->getDescription()) { + if ($extension->getDescription()) { $return .= '<p><bdi>'; $return .= hsc($extension->getDescription()).' '; $return .= '</bdi></p>'.DOKU_LF; } - $return .= $this->make_linkbar($extension); + $return .= $this->makeLinkbar($extension); - if($showinfo){ + if ($showinfo) { $url = $this->gui->tabURL(''); $class = 'close'; - }else{ + } else { $url = $this->gui->tabURL('', array('info' => $extension->getID())); $class = ''; } - $return .= ' <a href="'.$url.'#extensionplugin__'.$extension->getID().'" class="info '.$class.'" title="'.$this->getLang('btn_info').'" data-extid="'.$extension->getID().'">'.$this->getLang('btn_info').'</a>'; + $return .= ' <a href="'.$url.'#extensionplugin__'.$extension->getID(). + '" class="info '.$class.'" title="'.$this->getLang('btn_info'). + '" data-extid="'.$extension->getID().'">'.$this->getLang('btn_info').'</a>'; if ($showinfo) { - $return .= $this->make_info($extension); + $return .= $this->makeInfo($extension); } - $return .= $this->make_noticearea($extension); + $return .= $this->makeNoticeArea($extension); $return .= '</div>'.DOKU_LF; return $return; } @@ -262,17 +292,20 @@ class helper_plugin_extension_list extends DokuWiki_Plugin { * @param helper_plugin_extension_extension $extension The extension instance * @return string The HTML code */ - function make_linkbar(helper_plugin_extension_extension $extension) { + public function makeLinkbar(helper_plugin_extension_extension $extension) + { $return = '<div class="linkbar">'; - $return .= $this->make_homepagelink($extension); + $return .= $this->makeHomepageLink($extension); if ($extension->getBugtrackerURL()) { - $return .= ' <a href="'.hsc($extension->getBugtrackerURL()).'" title="'.hsc($extension->getBugtrackerURL()).'" class ="bugs">'.$this->getLang('bugs_features').'</a> '; + $return .= ' <a href="'.hsc($extension->getBugtrackerURL()). + '" title="'.hsc($extension->getBugtrackerURL()).'" class ="bugs">'. + $this->getLang('bugs_features').'</a> '; } - if ($extension->getTags()){ + if ($extension->getTags()) { $first = true; $return .= '<span class="tags">'.$this->getLang('tags').' '; foreach ($extension->getTags() as $tag) { - if (!$first){ + if (!$first) { $return .= ', '; } else { $first = false; @@ -292,37 +325,49 @@ class helper_plugin_extension_list extends DokuWiki_Plugin { * @param helper_plugin_extension_extension $extension The extension * @return string The HTML code */ - function make_noticearea(helper_plugin_extension_extension $extension) { + public function makeNoticeArea(helper_plugin_extension_extension $extension) + { $return = ''; $missing_dependencies = $extension->getMissingDependencies(); - if(!empty($missing_dependencies)) { - $return .= '<div class="msg error">'. - sprintf($this->getLang('missing_dependency'), '<bdi>'.implode(', ', /*array_map(array($this->helper, 'make_extensionsearchlink'),*/ $missing_dependencies).'</bdi>'). + if (!empty($missing_dependencies)) { + $return .= '<div class="msg error">' . + sprintf( + $this->getLang('missing_dependency'), + '<bdi>' . implode(', ', $missing_dependencies) . '</bdi>' + ) . '</div>'; } - if($extension->isInWrongFolder()) { - $return .= '<div class="msg error">'. - sprintf($this->getLang('wrong_folder'), '<bdi>'.hsc($extension->getInstallName()).'</bdi>', '<bdi>'.hsc($extension->getBase()).'</bdi>'). + if ($extension->isInWrongFolder()) { + $return .= '<div class="msg error">' . + sprintf( + $this->getLang('wrong_folder'), + '<bdi>' . hsc($extension->getInstallName()) . '</bdi>', + '<bdi>' . hsc($extension->getBase()) . '</bdi>' + ) . '</div>'; } - if(($securityissue = $extension->getSecurityIssue()) !== false) { + if (($securityissue = $extension->getSecurityIssue()) !== false) { $return .= '<div class="msg error">'. sprintf($this->getLang('security_issue'), '<bdi>'.hsc($securityissue).'</bdi>'). '</div>'; } - if(($securitywarning = $extension->getSecurityWarning()) !== false) { + if (($securitywarning = $extension->getSecurityWarning()) !== false) { $return .= '<div class="msg notify">'. sprintf($this->getLang('security_warning'), '<bdi>'.hsc($securitywarning).'</bdi>'). '</div>'; } - if($extension->updateAvailable()) { + if ($extension->updateAvailable()) { $return .= '<div class="msg notify">'. sprintf($this->getLang('update_available'), hsc($extension->getLastUpdate())). '</div>'; } - if($extension->hasDownloadURLChanged()) { - $return .= '<div class="msg notify">'. - sprintf($this->getLang('url_change'), '<bdi>'.hsc($extension->getDownloadURL()).'</bdi>', '<bdi>'.hsc($extension->getLastDownloadURL()).'</bdi>'). + if ($extension->hasDownloadURLChanged()) { + $return .= '<div class="msg notify">' . + sprintf( + $this->getLang('url_change'), + '<bdi>' . hsc($extension->getDownloadURL()) . '</bdi>', + '<bdi>' . hsc($extension->getLastDownloadURL()) . '</bdi>' + ) . '</div>'; } return $return.DOKU_LF; @@ -336,13 +381,14 @@ class helper_plugin_extension_list extends DokuWiki_Plugin { * @param string $url * @return string HTML link */ - function shortlink($url){ + public function shortlink($url) + { $link = parse_url($url); $base = $link['host']; - if(!empty($link['port'])) $base .= $base.':'.$link['port']; + if (!empty($link['port'])) $base .= $base.':'.$link['port']; $long = $link['path']; - if(!empty($link['query'])) $long .= $link['query']; + if (!empty($link['query'])) $long .= $link['query']; $name = shorten($base, $long, 55); @@ -355,17 +401,19 @@ class helper_plugin_extension_list extends DokuWiki_Plugin { * @param helper_plugin_extension_extension $extension The extension * @return string The HTML code */ - function make_info(helper_plugin_extension_extension $extension) { + public function makeInfo(helper_plugin_extension_extension $extension) + { $default = $this->getLang('unknown'); $return = '<dl class="details">'; $return .= '<dt>'.$this->getLang('status').'</dt>'; - $return .= '<dd>'.$this->make_status($extension).'</dd>'; + $return .= '<dd>'.$this->makeStatus($extension).'</dd>'; if ($extension->getDonationURL()) { $return .= '<dt>'.$this->getLang('donate').'</dt>'; $return .= '<dd>'; - $return .= '<a href="'.$extension->getDonationURL().'" class="donate">'.$this->getLang('donate_action').'</a>'; + $return .= '<a href="'.$extension->getDonationURL().'" class="donate">'. + $this->getLang('donate_action').'</a>'; $return .= '</dd>'; } @@ -407,7 +455,7 @@ class helper_plugin_extension_list extends DokuWiki_Plugin { $return .= ($extension->getTypes() ? hsc(implode(', ', $extension->getTypes())) : $default); $return .= '</bdi></dd>'; - if(!$extension->isBundled() && $extension->getCompatibleVersions()) { + if (!$extension->isBundled() && $extension->getCompatibleVersions()) { $return .= '<dt>'.$this->getLang('compatible').'</dt>'; $return .= '<dd>'; foreach ($extension->getCompatibleVersions() as $date => $version) { @@ -416,24 +464,24 @@ class helper_plugin_extension_list extends DokuWiki_Plugin { $return = rtrim($return, ', '); $return .= '</dd>'; } - if($extension->getDependencies()) { + if ($extension->getDependencies()) { $return .= '<dt>'.$this->getLang('depends').'</dt>'; $return .= '<dd>'; - $return .= $this->make_linklist($extension->getDependencies()); + $return .= $this->makeLinkList($extension->getDependencies()); $return .= '</dd>'; } - if($extension->getSimilarExtensions()) { + if ($extension->getSimilarExtensions()) { $return .= '<dt>'.$this->getLang('similar').'</dt>'; $return .= '<dd>'; - $return .= $this->make_linklist($extension->getSimilarExtensions()); + $return .= $this->makeLinkList($extension->getSimilarExtensions()); $return .= '</dd>'; } - if($extension->getConflicts()) { + if ($extension->getConflicts()) { $return .= '<dt>'.$this->getLang('conflicts').'</dt>'; $return .= '<dd>'; - $return .= $this->make_linklist($extension->getConflicts()); + $return .= $this->makeLinkList($extension->getConflicts()); $return .= '</dd>'; } $return .= '</dl>'.DOKU_LF; @@ -446,10 +494,12 @@ class helper_plugin_extension_list extends DokuWiki_Plugin { * @param array $ext The extensions * @return string The HTML code */ - function make_linklist($ext) { + public function makeLinkList($ext) + { $return = ''; foreach ($ext as $link) { - $return .= '<bdi><a href="'.$this->gui->tabURL('search', array('q'=>'ext:'.$link)).'">'.hsc($link).'</a></bdi>, '; + $return .= '<bdi><a href="'. + $this->gui->tabURL('search', array('q'=>'ext:'.$link)).'">'.hsc($link).'</a></bdi>, '; } return rtrim($return, ', '); } @@ -460,7 +510,8 @@ class helper_plugin_extension_list extends DokuWiki_Plugin { * @param helper_plugin_extension_extension $extension The extension * @return string The HTML code */ - function make_actions(helper_plugin_extension_extension $extension) { + public function makeActions(helper_plugin_extension_extension $extension) + { global $conf; $return = ''; $errors = ''; @@ -468,48 +519,52 @@ class helper_plugin_extension_list extends DokuWiki_Plugin { if ($extension->isInstalled()) { if (($canmod = $extension->canModify()) === true) { if (!$extension->isProtected()) { - $return .= $this->make_action('uninstall', $extension); + $return .= $this->makeAction('uninstall', $extension); } if ($extension->getDownloadURL()) { if ($extension->updateAvailable()) { - $return .= $this->make_action('update', $extension); + $return .= $this->makeAction('update', $extension); } else { - $return .= $this->make_action('reinstall', $extension); + $return .= $this->makeAction('reinstall', $extension); } } - }else{ + } else { $errors .= '<p class="permerror">'.$this->getLang($canmod).'</p>'; } if (!$extension->isProtected() && !$extension->isTemplate()) { // no enable/disable for templates if ($extension->isEnabled()) { - $return .= $this->make_action('disable', $extension); + $return .= $this->makeAction('disable', $extension); } else { - $return .= $this->make_action('enable', $extension); + $return .= $this->makeAction('enable', $extension); } } - if ($extension->isGitControlled()){ + if ($extension->isGitControlled()) { $errors .= '<p class="permerror">'.$this->getLang('git').'</p>'; } - if ($extension->isEnabled() && in_array('Auth', $extension->getTypes()) && $conf['authtype'] != $extension->getID()) { + if ($extension->isEnabled() && + in_array('Auth', $extension->getTypes()) && + $conf['authtype'] != $extension->getID() + ) { $errors .= '<p class="permerror">'.$this->getLang('auth').'</p>'; } - - }else{ + } else { if (($canmod = $extension->canModify()) === true) { if ($extension->getDownloadURL()) { - $return .= $this->make_action('install', $extension); + $return .= $this->makeAction('install', $extension); } - }else{ + } else { $errors .= '<div class="permerror">'.$this->getLang($canmod).'</div>'; } } if (!$extension->isInstalled() && $extension->getDownloadURL()) { $return .= ' <span class="version">'.$this->getLang('available_version').' '; - $return .= ($extension->getLastUpdate() ? hsc($extension->getLastUpdate()) : $this->getLang('unknown')).'</span>'; + $return .= ($extension->getLastUpdate() + ? hsc($extension->getLastUpdate()) + : $this->getLang('unknown')).'</span>'; } return $return.' '.$errors.DOKU_LF; @@ -522,7 +577,8 @@ class helper_plugin_extension_list extends DokuWiki_Plugin { * @param helper_plugin_extension_extension $extension The extension * @return string The HTML code */ - function make_action($action, $extension) { + public function makeAction($action, $extension) + { $title = ''; switch ($action) { @@ -535,7 +591,8 @@ class helper_plugin_extension_list extends DokuWiki_Plugin { $classes = 'button '.$action; $name = 'fn['.$action.']['.hsc($extension->getID()).']'; - return '<button class="'.$classes.'" name="'.$name.'" type="submit" '.$title.'>'.$this->getLang('btn_'.$action).'</button> '; + return '<button class="'.$classes.'" name="'.$name.'" type="submit" '.$title.'>'. + $this->getLang('btn_'.$action).'</button> '; } /** @@ -544,7 +601,8 @@ class helper_plugin_extension_list extends DokuWiki_Plugin { * @param helper_plugin_extension_extension $extension The extension * @return string The description of all relevant statusses */ - function make_status(helper_plugin_extension_extension $extension) { + public function makeStatus(helper_plugin_extension_extension $extension) + { $status = array(); @@ -553,15 +611,16 @@ class helper_plugin_extension_list extends DokuWiki_Plugin { if ($extension->isProtected()) { $status[] = $this->getLang('status_protected'); } else { - $status[] = $extension->isEnabled() ? $this->getLang('status_enabled') : $this->getLang('status_disabled'); + $status[] = $extension->isEnabled() + ? $this->getLang('status_enabled') + : $this->getLang('status_disabled'); } } else { $status[] = $this->getLang('status_not_installed'); } - if(!$extension->canModify()) $status[] = $this->getLang('status_unmodifiable'); - if($extension->isBundled()) $status[] = $this->getLang('status_bundled'); + if (!$extension->canModify()) $status[] = $this->getLang('status_unmodifiable'); + if ($extension->isBundled()) $status[] = $this->getLang('status_bundled'); $status[] = $extension->isTemplate() ? $this->getLang('status_template') : $this->getLang('status_plugin'); return join(', ', $status); } - } diff --git a/lib/plugins/extension/helper/repository.php b/lib/plugins/extension/helper/repository.php index 5dc2707cf..afe413a58 100644 --- a/lib/plugins/extension/helper/repository.php +++ b/lib/plugins/extension/helper/repository.php @@ -6,24 +6,22 @@ * @author Michael Hamann <michael@content-space.de> */ -#define('EXTENSION_REPOSITORY_API', 'http://localhost/dokuwiki/lib/plugins/pluginrepo/api.php'); - -if (!defined('EXTENSION_REPOSITORY_API_ENDPOINT')) - define('EXTENSION_REPOSITORY_API', 'http://www.dokuwiki.org/lib/plugins/pluginrepo/api.php'); - -// must be run within Dokuwiki -if(!defined('DOKU_INC')) die(); - /** * Class helper_plugin_extension_repository provides access to the extension repository on dokuwiki.org */ -class helper_plugin_extension_repository extends DokuWiki_Plugin { +class helper_plugin_extension_repository extends DokuWiki_Plugin +{ + + const EXTENSION_REPOSITORY_API = 'http://www.dokuwiki.org/lib/plugins/pluginrepo/api.php'; + private $loaded_extensions = array(); private $has_access = null; + /** * Initialize the repository (cache), fetches data for all installed plugins */ - public function init() { + public function init() + { /* @var Doku_Plugin_Controller $plugin_controller */ global $plugin_controller; if ($this->hasAccess()) { @@ -33,7 +31,10 @@ class helper_plugin_extension_repository extends DokuWiki_Plugin { foreach ($list as $name) { $cache = new cache('##extension_manager##'.$name, '.repo'); - if (!isset($this->loaded_extensions[$name]) && $this->hasAccess() && !$cache->useCache(array('age' => 3600 * 24))) { + if (!isset($this->loaded_extensions[$name]) && + $this->hasAccess() && + !$cache->useCache(array('age' => 3600 * 24)) + ) { $this->loaded_extensions[$name] = true; $request_data['ext'][] = $name; $request_needed = true; @@ -42,7 +43,7 @@ class helper_plugin_extension_repository extends DokuWiki_Plugin { if ($request_needed) { $httpclient = new DokuHTTPClient(); - $data = $httpclient->post(EXTENSION_REPOSITORY_API, $request_data); + $data = $httpclient->post(self::EXTENSION_REPOSITORY_API, $request_data); if ($data !== false) { $extensions = unserialize($data); foreach ($extensions as $extension) { @@ -61,14 +62,15 @@ class helper_plugin_extension_repository extends DokuWiki_Plugin { * * @return bool If repository access is available */ - public function hasAccess() { + public function hasAccess() + { if ($this->has_access === null) { $cache = new cache('##extension_manager###hasAccess', '.repo'); if (!$cache->useCache(array('age' => 3600 * 24, 'purge'=>1))) { $httpclient = new DokuHTTPClient(); $httpclient->timeout = 5; - $data = $httpclient->get(EXTENSION_REPOSITORY_API.'?cmd=ping'); + $data = $httpclient->get(self::EXTENSION_REPOSITORY_API.'?cmd=ping'); if ($data !== false) { $this->has_access = true; $cache->storeCache(1); @@ -89,13 +91,17 @@ class helper_plugin_extension_repository extends DokuWiki_Plugin { * @param string $name The plugin name to get the data for, template names need to be prefix by 'template:' * @return array The data or null if nothing was found (possibly no repository access) */ - public function getData($name) { + public function getData($name) + { $cache = new cache('##extension_manager##'.$name, '.repo'); - if (!isset($this->loaded_extensions[$name]) && $this->hasAccess() && !$cache->useCache(array('age' => 3600 * 24))) { + if (!isset($this->loaded_extensions[$name]) && + $this->hasAccess() && + !$cache->useCache(array('age' => 3600 * 24)) + ) { $this->loaded_extensions[$name] = true; $httpclient = new DokuHTTPClient(); - $data = $httpclient->get(EXTENSION_REPOSITORY_API.'?fmt=php&ext[]='.urlencode($name)); + $data = $httpclient->get(self::EXTENSION_REPOSITORY_API.'?fmt=php&ext[]='.urlencode($name)); if ($data !== false) { $result = unserialize($data); $cache->storeCache(serialize($result[0])); @@ -116,19 +122,20 @@ class helper_plugin_extension_repository extends DokuWiki_Plugin { * @param string $q the query string * @return array a list of matching extensions */ - public function search($q){ - $query = $this->parse_query($q); + public function search($q) + { + $query = $this->parseQuery($q); $query['fmt'] = 'php'; $httpclient = new DokuHTTPClient(); - $data = $httpclient->post(EXTENSION_REPOSITORY_API, $query); + $data = $httpclient->post(self::EXTENSION_REPOSITORY_API, $query); if ($data === false) return array(); $result = unserialize($data); $ids = array(); // store cache info for each extension - foreach($result as $ext){ + foreach ($result as $ext) { $name = $ext['plugin']; $cache = new cache('##extension_manager##'.$name, '.repo'); $cache->storeCache(serialize($ext)); @@ -144,7 +151,8 @@ class helper_plugin_extension_repository extends DokuWiki_Plugin { * @param string $q * @return array */ - protected function parse_query($q){ + protected function parseQuery($q) + { $parameters = array( 'tag' => array(), 'mail' => array(), @@ -153,29 +161,29 @@ class helper_plugin_extension_repository extends DokuWiki_Plugin { ); // extract tags - if(preg_match_all('/(^|\s)(tag:([\S]+))/', $q, $matches, PREG_SET_ORDER)){ - foreach($matches as $m){ + if (preg_match_all('/(^|\s)(tag:([\S]+))/', $q, $matches, PREG_SET_ORDER)) { + foreach ($matches as $m) { $q = str_replace($m[2], '', $q); $parameters['tag'][] = $m[3]; } } // extract author ids - if(preg_match_all('/(^|\s)(authorid:([\S]+))/', $q, $matches, PREG_SET_ORDER)){ - foreach($matches as $m){ + if (preg_match_all('/(^|\s)(authorid:([\S]+))/', $q, $matches, PREG_SET_ORDER)) { + foreach ($matches as $m) { $q = str_replace($m[2], '', $q); $parameters['mail'][] = $m[3]; } } // extract extensions - if(preg_match_all('/(^|\s)(ext:([\S]+))/', $q, $matches, PREG_SET_ORDER)){ - foreach($matches as $m){ + if (preg_match_all('/(^|\s)(ext:([\S]+))/', $q, $matches, PREG_SET_ORDER)) { + foreach ($matches as $m) { $q = str_replace($m[2], '', $q); $parameters['ext'][] = $m[3]; } } // extract types - if(preg_match_all('/(^|\s)(type:([\S]+))/', $q, $matches, PREG_SET_ORDER)){ - foreach($matches as $m){ + if (preg_match_all('/(^|\s)(type:([\S]+))/', $q, $matches, PREG_SET_ORDER)) { + foreach ($matches as $m) { $q = str_replace($m[2], '', $q); $parameters['type'][] = $m[3]; } diff --git a/lib/plugins/info/syntax.php b/lib/plugins/info/syntax.php index 773256faf..3fa35e733 100644 --- a/lib/plugins/info/syntax.php +++ b/lib/plugins/info/syntax.php @@ -6,33 +6,30 @@ * @author Andreas Gohr <andi@splitbrain.org> * @author Esther Brunner <wikidesign@gmail.com> */ -// must be run within Dokuwiki -if(!defined('DOKU_INC')) die(); - -/** - * All DokuWiki plugins to extend the parser/rendering mechanism - * need to inherit from this class - */ -class syntax_plugin_info extends DokuWiki_Syntax_Plugin { +class syntax_plugin_info extends DokuWiki_Syntax_Plugin +{ /** * What kind of syntax are we? */ - function getType(){ + public function getType() + { return 'substition'; } /** * What about paragraphs? */ - function getPType(){ + public function getPType() + { return 'block'; } /** * Where to sort in? */ - function getSort(){ + public function getSort() + { return 155; } @@ -40,8 +37,9 @@ class syntax_plugin_info extends DokuWiki_Syntax_Plugin { /** * Connect pattern to lexer */ - function connectTo($mode) { - $this->Lexer->addSpecialPattern('~~INFO:\w+~~',$mode,'plugin_info'); + public function connectTo($mode) + { + $this->Lexer->addSpecialPattern('~~INFO:\w+~~', $mode, 'plugin_info'); } /** @@ -53,8 +51,9 @@ class syntax_plugin_info extends DokuWiki_Syntax_Plugin { * @param Doku_Handler $handler The Doku_Handler object * @return array Return an array with all data you want to use in render */ - function handle($match, $state, $pos, Doku_Handler $handler){ - $match = substr($match,7,-2); //strip ~~INFO: from start and ~~ from end + public function handle($match, $state, $pos, Doku_Handler $handler) + { + $match = substr($match, 7, -2); //strip ~~INFO: from start and ~~ from end return array(strtolower($match)); } @@ -66,40 +65,41 @@ class syntax_plugin_info extends DokuWiki_Syntax_Plugin { * @param array $data data created by handler() * @return boolean rendered correctly? */ - function render($format, Doku_Renderer $renderer, $data) { - if($format == 'xhtml'){ + public function render($format, Doku_Renderer $renderer, $data) + { + if ($format == 'xhtml') { /** @var Doku_Renderer_xhtml $renderer */ //handle various info stuff - switch ($data[0]){ + switch ($data[0]) { case 'syntaxmodes': - $renderer->doc .= $this->_syntaxmodes_xhtml(); + $renderer->doc .= $this->renderSyntaxModes(); break; case 'syntaxtypes': - $renderer->doc .= $this->_syntaxtypes_xhtml(); + $renderer->doc .= $this->renderSyntaxTypes(); break; case 'syntaxplugins': - $this->_plugins_xhtml('syntax', $renderer); + $this->renderPlugins('syntax', $renderer); break; case 'adminplugins': - $this->_plugins_xhtml('admin', $renderer); + $this->renderPlugins('admin', $renderer); break; case 'actionplugins': - $this->_plugins_xhtml('action', $renderer); + $this->renderPlugins('action', $renderer); break; case 'rendererplugins': - $this->_plugins_xhtml('renderer', $renderer); + $this->renderPlugins('renderer', $renderer); break; case 'helperplugins': - $this->_plugins_xhtml('helper', $renderer); + $this->renderPlugins('helper', $renderer); break; case 'authplugins': - $this->_plugins_xhtml('auth', $renderer); + $this->renderPlugins('auth', $renderer); break; case 'remoteplugins': - $this->_plugins_xhtml('remote', $renderer); + $this->renderPlugins('remote', $renderer); break; case 'helpermethods': - $this->_helpermethods_xhtml($renderer); + $this->renderHelperMethods($renderer); break; default: $renderer->doc .= "no info about ".htmlspecialchars($data[0]); @@ -117,7 +117,8 @@ class syntax_plugin_info extends DokuWiki_Syntax_Plugin { * @param string $type * @param Doku_Renderer_xhtml $renderer */ - function _plugins_xhtml($type, Doku_Renderer_xhtml $renderer){ + protected function renderPlugins($type, Doku_Renderer_xhtml $renderer) + { global $lang; $renderer->doc .= '<ul>'; @@ -125,24 +126,24 @@ class syntax_plugin_info extends DokuWiki_Syntax_Plugin { $plginfo = array(); // remove subparts - foreach($plugins as $p){ - if (!$po = plugin_load($type,$p)) continue; - list($name,/* $part */) = explode('_',$p,2); + foreach ($plugins as $p) { + if (!$po = plugin_load($type, $p)) continue; + list($name,/* $part */) = explode('_', $p, 2); $plginfo[$name] = $po->getInfo(); } // list them - foreach($plginfo as $info){ + foreach ($plginfo as $info) { $renderer->doc .= '<li><div class="li">'; - $renderer->externallink($info['url'],$info['name']); + $renderer->externallink($info['url'], $info['name']); $renderer->doc .= ' '; $renderer->doc .= '<em>'.$info['date'].'</em>'; $renderer->doc .= ' '; $renderer->doc .= $lang['by']; $renderer->doc .= ' '; - $renderer->emaillink($info['email'],$info['author']); + $renderer->emaillink($info['email'], $info['author']); $renderer->doc .= '<br />'; - $renderer->doc .= strtr(hsc($info['desc']),array("\n"=>"<br />")); + $renderer->doc .= strtr(hsc($info['desc']), array("\n"=>"<br />")); $renderer->doc .= '</div></li>'; unset($po); } @@ -157,39 +158,40 @@ class syntax_plugin_info extends DokuWiki_Syntax_Plugin { * * @param Doku_Renderer_xhtml $renderer */ - function _helpermethods_xhtml(Doku_Renderer_xhtml $renderer){ + protected function renderHelperMethods(Doku_Renderer_xhtml $renderer) + { $plugins = plugin_list('helper'); - foreach($plugins as $p){ - if (!$po = plugin_load('helper',$p)) continue; + foreach ($plugins as $p) { + if (!$po = plugin_load('helper', $p)) continue; if (!method_exists($po, 'getMethods')) continue; $methods = $po->getMethods(); $info = $po->getInfo(); - $hid = $this->_addToTOC($info['name'], 2, $renderer); + $hid = $this->addToToc($info['name'], 2, $renderer); $doc = '<h2><a name="'.$hid.'" id="'.$hid.'">'.hsc($info['name']).'</a></h2>'; $doc .= '<div class="level2">'; $doc .= '<p>'.strtr(hsc($info['desc']), array("\n"=>"<br />")).'</p>'; $doc .= '<pre class="code">$'.$p." = plugin_load('helper', '".$p."');</pre>"; $doc .= '</div>'; - foreach ($methods as $method){ + foreach ($methods as $method) { $title = '$'.$p.'->'.$method['name'].'()'; - $hid = $this->_addToTOC($title, 3, $renderer); + $hid = $this->addToToc($title, 3, $renderer); $doc .= '<h3><a name="'.$hid.'" id="'.$hid.'">'.hsc($title).'</a></h3>'; $doc .= '<div class="level3">'; $doc .= '<div class="table"><table class="inline"><tbody>'; $doc .= '<tr><th>Description</th><td colspan="2">'.$method['desc']. '</td></tr>'; - if ($method['params']){ + if ($method['params']) { $c = count($method['params']); $doc .= '<tr><th rowspan="'.$c.'">Parameters</th><td>'; $params = array(); - foreach ($method['params'] as $desc => $type){ + foreach ($method['params'] as $desc => $type) { $params[] = hsc($desc).'</td><td>'.hsc($type); } $doc .= join($params, '</td></tr><tr><td>').'</td></tr>'; } - if ($method['return']){ + if ($method['return']) { $doc .= '<tr><th>Return value</th><td>'.hsc(key($method['return'])). '</td><td>'.hsc(current($method['return'])).'</td></tr>'; } @@ -207,18 +209,19 @@ class syntax_plugin_info extends DokuWiki_Syntax_Plugin { * * @return string */ - function _syntaxtypes_xhtml(){ + protected function renderSyntaxTypes() + { global $PARSER_MODES; $doc = ''; $doc .= '<div class="table"><table class="inline"><tbody>'; - foreach($PARSER_MODES as $mode => $modes){ + foreach ($PARSER_MODES as $mode => $modes) { $doc .= '<tr>'; $doc .= '<td class="leftalign">'; $doc .= $mode; $doc .= '</td>'; $doc .= '<td class="leftalign">'; - $doc .= join(', ',$modes); + $doc .= join(', ', $modes); $doc .= '</td>'; $doc .= '</tr>'; } @@ -231,29 +234,30 @@ class syntax_plugin_info extends DokuWiki_Syntax_Plugin { * * @return string */ - function _syntaxmodes_xhtml(){ + protected function renderSyntaxModes() + { $modes = p_get_parsermodes(); $compactmodes = array(); - foreach($modes as $mode){ + foreach ($modes as $mode) { $compactmodes[$mode['sort']][] = $mode['mode']; } $doc = ''; $doc .= '<div class="table"><table class="inline"><tbody>'; - foreach($compactmodes as $sort => $modes){ + foreach ($compactmodes as $sort => $modes) { $rowspan = ''; - if(count($modes) > 1) { + if (count($modes) > 1) { $rowspan = ' rowspan="'.count($modes).'"'; } - foreach($modes as $index => $mode) { + foreach ($modes as $index => $mode) { $doc .= '<tr>'; $doc .= '<td class="leftalign">'; $doc .= $mode; $doc .= '</td>'; - if($index === 0) { + if ($index === 0) { $doc .= '<td class="rightalign" '.$rowspan.'>'; $doc .= $sort; $doc .= '</td>'; @@ -274,11 +278,12 @@ class syntax_plugin_info extends DokuWiki_Syntax_Plugin { * @param Doku_Renderer_xhtml $renderer * @return string */ - protected function _addToTOC($text, $level, Doku_Renderer_xhtml $renderer){ + protected function addToToc($text, $level, Doku_Renderer_xhtml $renderer) + { global $conf; $hid = ''; - if (($level >= $conf['toptoclevel']) && ($level <= $conf['maxtoclevel'])){ + if (($level >= $conf['toptoclevel']) && ($level <= $conf['maxtoclevel'])) { $hid = $renderer->_headerToLink($text, true); $renderer->toc[] = array( 'hid' => $hid, diff --git a/lib/plugins/popularity/action.php b/lib/plugins/popularity/action.php index d5ec0f5c5..fac610735 100644 --- a/lib/plugins/popularity/action.php +++ b/lib/plugins/popularity/action.php @@ -5,44 +5,49 @@ * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) */ -require_once(DOKU_PLUGIN.'action.php'); -require_once(DOKU_PLUGIN.'popularity/admin.php'); - -class action_plugin_popularity extends Dokuwiki_Action_Plugin { +class action_plugin_popularity extends DokuWiki_Action_Plugin +{ /** * @var helper_plugin_popularity */ - var $helper; + protected $helper; - function __construct(){ + public function __construct() + { $this->helper = $this->loadHelper('popularity', false); } - /** - * Register its handlers with the dokuwiki's event controller - */ - function register(Doku_Event_Handler $controller) { - $controller->register_hook('INDEXER_TASKS_RUN', 'AFTER', $this, '_autosubmit', array()); + /** @inheritdoc */ + public function register(Doku_Event_Handler $controller) + { + $controller->register_hook('INDEXER_TASKS_RUN', 'AFTER', $this, 'autosubmit', array()); } - function _autosubmit(Doku_Event &$event, $param){ + /** + * Event handler + * + * @param Doku_Event $event + * @param $param + */ + public function autosubmit(Doku_Event &$event, $param) + { //Do we have to send the data now - if ( !$this->helper->isAutosubmitEnabled() || $this->_isTooEarlyToSubmit() ){ + if (!$this->helper->isAutosubmitEnabled() || $this->isTooEarlyToSubmit()) { return; } //Actually send it - $status = $this->helper->sendData( $this->helper->gatherAsString() ); + $status = $this->helper->sendData($this->helper->gatherAsString()); - if ( $status !== '' ){ + if ($status !== '') { //If an error occured, log it - io_saveFile( $this->helper->autosubmitErrorFile, $status ); + io_saveFile($this->helper->autosubmitErrorFile, $status); } else { //If the data has been sent successfully, previous log of errors are useless @unlink($this->helper->autosubmitErrorFile); //Update the last time we sent data - touch ( $this->helper->autosubmitFile ); + touch($this->helper->autosubmitFile); } $event->stopPropagation(); @@ -53,7 +58,8 @@ class action_plugin_popularity extends Dokuwiki_Action_Plugin { * Check if it's time to send autosubmit data * (we should have check if autosubmit is enabled first) */ - function _isTooEarlyToSubmit(){ + protected function isTooEarlyToSubmit() + { $lastSubmit = $this->helper->lastSentTime(); return $lastSubmit + 24*60*60*30 > time(); } diff --git a/lib/plugins/popularity/admin.php b/lib/plugins/popularity/admin.php index 0cf174e0d..61d8cc3bf 100644 --- a/lib/plugins/popularity/admin.php +++ b/lib/plugins/popularity/admin.php @@ -5,43 +5,44 @@ * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Andreas Gohr <andi@splitbrain.org> */ -// must be run within Dokuwiki -if(!defined('DOKU_INC')) die(); +class admin_plugin_popularity extends DokuWiki_Admin_Plugin +{ -/** - * All DokuWiki plugins to extend the admin function - * need to inherit from this class - */ -class admin_plugin_popularity extends DokuWiki_Admin_Plugin { + /** @var helper_plugin_popularity */ + protected $helper; + protected $sentStatus = null; /** - * @var helper_plugin_popularity + * admin_plugin_popularity constructor. */ - var $helper; - var $sentStatus = null; - - function __construct(){ + public function __construct() + { $this->helper = $this->loadHelper('popularity', false); } /** * return prompt for admin menu + * @param $language + * @return string */ - function getMenuText($language) { + public function getMenuText($language) + { return $this->getLang('name'); } /** * return sort order for position in admin menu */ - function getMenuSort() { + public function getMenuSort() + { return 2000; } /** * Accessible for managers */ - function forAdminOnly() { + public function forAdminOnly() + { return false; } @@ -49,18 +50,19 @@ class admin_plugin_popularity extends DokuWiki_Admin_Plugin { /** * handle user request */ - function handle() { + public function handle() + { global $INPUT; //Send the data - if ( $INPUT->has('data') ){ - $this->sentStatus = $this->helper->sendData( $INPUT->str('data') ); - if ( $this->sentStatus === '' ){ + if ($INPUT->has('data')) { + $this->sentStatus = $this->helper->sendData($INPUT->str('data')); + if ($this->sentStatus === '') { //Update the last time we sent the data - touch ( $this->helper->popularityLastSubmitFile ); + touch($this->helper->popularityLastSubmitFile); } //Deal with the autosubmit option - $this->_enableAutosubmit( $INPUT->has('autosubmit') ); + $this->enableAutosubmit($INPUT->has('autosubmit')); } } @@ -68,9 +70,10 @@ class admin_plugin_popularity extends DokuWiki_Admin_Plugin { * Enable or disable autosubmit * @param bool $enable If TRUE, it will enable autosubmit. Else, it will disable it. */ - function _enableAutosubmit( $enable ){ - if ( $enable ){ - io_saveFile( $this->helper->autosubmitFile, ' '); + protected function enableAutosubmit($enable) + { + if ($enable) { + io_saveFile($this->helper->autosubmitFile, ' '); } else { @unlink($this->helper->autosubmitFile); } @@ -79,17 +82,18 @@ class admin_plugin_popularity extends DokuWiki_Admin_Plugin { /** * Output HTML form */ - function html() { + public function html() + { global $INPUT; - if ( ! $INPUT->has('data') ){ + if (! $INPUT->has('data')) { echo $this->locale_xhtml('intro'); //If there was an error the last time we tried to autosubmit, warn the user - if ( $this->helper->isAutoSubmitEnabled() ){ - if ( file_exists($this->helper->autosubmitErrorFile) ){ + if ($this->helper->isAutoSubmitEnabled()) { + if (file_exists($this->helper->autosubmitErrorFile)) { echo $this->getLang('autosubmitError'); - echo io_readFile( $this->helper->autosubmitErrorFile ); + echo io_readFile($this->helper->autosubmitErrorFile); } } @@ -98,12 +102,12 @@ class admin_plugin_popularity extends DokuWiki_Admin_Plugin { //Print the last time the data was sent $lastSent = $this->helper->lastSentTime(); - if ( $lastSent !== 0 ){ + if ($lastSent !== 0) { echo $this->getLang('lastSent') . ' ' . datetime_h($lastSent); } } else { //If we just submitted the form - if ( $this->sentStatus === '' ){ + if ($this->sentStatus === '') { //If we successfully sent the data echo $this->locale_xhtml('submitted'); } else { @@ -122,9 +126,10 @@ class admin_plugin_popularity extends DokuWiki_Admin_Plugin { * @param string $data The popularity data, if it has already been computed. NULL otherwise. * @return string The form, as an html string */ - function buildForm($submissionMode, $data = null){ + protected function buildForm($submissionMode, $data = null) + { $url = ($submissionMode === 'browser' ? $this->helper->submitUrl : script()); - if ( is_null($data) ){ + if (is_null($data)) { $data = $this->helper->gatherAsString(); } @@ -135,7 +140,7 @@ class admin_plugin_popularity extends DokuWiki_Admin_Plugin { .'</textarea><br />'; //If we submit via the server, we give the opportunity to suscribe to the autosubmission option - if ( $submissionMode !== 'browser' ){ + if ($submissionMode !== 'browser') { $form .= '<label for="autosubmit">' .'<input type="checkbox" name="autosubmit" id="autosubmit" ' .($this->helper->isAutosubmitEnabled() ? 'checked' : '' ) diff --git a/lib/plugins/popularity/helper.php b/lib/plugins/popularity/helper.php index b81ab7005..05e2ccb74 100644 --- a/lib/plugins/popularity/helper.php +++ b/lib/plugins/popularity/helper.php @@ -5,32 +5,36 @@ * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) */ -class helper_plugin_popularity extends Dokuwiki_Plugin { +class helper_plugin_popularity extends Dokuwiki_Plugin +{ /** * The url where the data should be sent */ - var $submitUrl = 'http://update.dokuwiki.org/popularity.php'; + public $submitUrl = 'http://update.dokuwiki.org/popularity.php'; /** * Name of the file which determine if the the autosubmit is enabled, * and when it was submited for the last time */ - var $autosubmitFile; + public $autosubmitFile; /** * File where the last error which happened when we tried to autosubmit, will be log */ - var $autosubmitErrorFile; + public $autosubmitErrorFile; /** * Name of the file which determine when the popularity data was manually * submitted for the last time * (If this file doesn't exist, the data has never been sent) */ - var $popularityLastSubmitFile; + public $popularityLastSubmitFile; - - function __construct(){ + /** + * helper_plugin_popularity constructor. + */ + public function __construct() + { global $conf; $this->autosubmitFile = $conf['cachedir'].'/autosubmit.txt'; $this->autosubmitErrorFile = $conf['cachedir'].'/autosubmitError.txt'; @@ -38,46 +42,12 @@ class helper_plugin_popularity extends Dokuwiki_Plugin { } /** - * Return methods of this helper - * - * @return array with methods description - */ - function getMethods(){ - $result = array(); - $result[] = array( - 'name' => 'isAutoSubmitEnabled', - 'desc' => 'Check if autosubmit is enabled', - 'params' => array(), - 'return' => array('result' => 'bool') - ); - $result[] = array( - 'name' => 'sendData', - 'desc' => 'Send the popularity data', - 'params' => array('data' => 'string'), - 'return' => array() - ); - $result[] = array( - 'name' => 'gatherAsString', - 'desc' => 'Gather the popularity data', - 'params' => array(), - 'return' => array('data' => 'string') - ); - $result[] = array( - 'name' => 'lastSentTime', - 'desc' => 'Compute the last time popularity data was sent', - 'params' => array(), - 'return' => array('data' => 'int') - ); - return $result; - - } - - /** * Check if autosubmit is enabled * * @return boolean TRUE if we should send data once a month, FALSE otherwise */ - function isAutoSubmitEnabled(){ + public function isAutoSubmitEnabled() + { return file_exists($this->autosubmitFile); } @@ -87,11 +57,12 @@ class helper_plugin_popularity extends Dokuwiki_Plugin { * @param string $data The popularity data * @return string An empty string if everything worked fine, a string describing the error otherwise */ - function sendData($data){ + public function sendData($data) + { $error = ''; $httpClient = new DokuHTTPClient(); $status = $httpClient->sendRequest($this->submitUrl, array('data' => $data), 'POST'); - if ( ! $status ){ + if (! $status) { $error = $httpClient->error; } return $error; @@ -102,7 +73,8 @@ class helper_plugin_popularity extends Dokuwiki_Plugin { * * @return int */ - function lastSentTime(){ + public function lastSentTime() + { $manualSubmission = @filemtime($this->popularityLastSubmitFile); $autoSubmission = @filemtime($this->autosubmitFile); @@ -114,13 +86,14 @@ class helper_plugin_popularity extends Dokuwiki_Plugin { * * @return string The popularity data as a string */ - function gatherAsString(){ - $data = $this->_gather(); + public function gatherAsString() + { + $data = $this->gather(); $string = ''; - foreach($data as $key => $val){ - if(is_array($val)) foreach($val as $v){ + foreach ($data as $key => $val) { + if (is_array($val)) foreach ($val as $v) { $string .= hsc($key)."\t".hsc($v)."\n"; - }else{ + } else { $string .= hsc($key)."\t".hsc($val)."\n"; } } @@ -132,7 +105,8 @@ class helper_plugin_popularity extends Dokuwiki_Plugin { * * @return array The popularity data as an array */ - function _gather(){ + protected function gather() + { global $conf; /** @var $auth DokuWiki_Auth_Plugin */ global $auth; @@ -156,81 +130,81 @@ class helper_plugin_popularity extends Dokuwiki_Plugin { // number and size of pages $list = array(); - search($list,$conf['datadir'],array($this,'_search_count'),array('all'=>false),''); + search($list, $conf['datadir'], array($this, 'searchCountCallback'), array('all'=>false), ''); $data['page_count'] = $list['file_count']; $data['page_size'] = $list['file_size']; $data['page_biggest'] = $list['file_max']; $data['page_smallest'] = $list['file_min']; $data['page_nscount'] = $list['dir_count']; $data['page_nsnest'] = $list['dir_nest']; - if($list['file_count']) $data['page_avg'] = $list['file_size'] / $list['file_count']; + if ($list['file_count']) $data['page_avg'] = $list['file_size'] / $list['file_count']; $data['page_oldest'] = $list['file_oldest']; unset($list); // number and size of media $list = array(); - search($list,$conf['mediadir'],array($this,'_search_count'),array('all'=>true)); + search($list, $conf['mediadir'], array($this, 'searchCountCallback'), array('all'=>true)); $data['media_count'] = $list['file_count']; $data['media_size'] = $list['file_size']; $data['media_biggest'] = $list['file_max']; $data['media_smallest'] = $list['file_min']; $data['media_nscount'] = $list['dir_count']; $data['media_nsnest'] = $list['dir_nest']; - if($list['file_count']) $data['media_avg'] = $list['file_size'] / $list['file_count']; + if ($list['file_count']) $data['media_avg'] = $list['file_size'] / $list['file_count']; unset($list); // number and size of cache $list = array(); - search($list,$conf['cachedir'],array($this,'_search_count'),array('all'=>true)); + search($list, $conf['cachedir'], array($this, 'searchCountCallback'), array('all'=>true)); $data['cache_count'] = $list['file_count']; $data['cache_size'] = $list['file_size']; $data['cache_biggest'] = $list['file_max']; $data['cache_smallest'] = $list['file_min']; - if($list['file_count']) $data['cache_avg'] = $list['file_size'] / $list['file_count']; + if ($list['file_count']) $data['cache_avg'] = $list['file_size'] / $list['file_count']; unset($list); // number and size of index $list = array(); - search($list,$conf['indexdir'],array($this,'_search_count'),array('all'=>true)); + search($list, $conf['indexdir'], array($this, 'searchCountCallback'), array('all'=>true)); $data['index_count'] = $list['file_count']; $data['index_size'] = $list['file_size']; $data['index_biggest'] = $list['file_max']; $data['index_smallest'] = $list['file_min']; - if($list['file_count']) $data['index_avg'] = $list['file_size'] / $list['file_count']; + if ($list['file_count']) $data['index_avg'] = $list['file_size'] / $list['file_count']; unset($list); // number and size of meta $list = array(); - search($list,$conf['metadir'],array($this,'_search_count'),array('all'=>true)); + search($list, $conf['metadir'], array($this, 'searchCountCallback'), array('all'=>true)); $data['meta_count'] = $list['file_count']; $data['meta_size'] = $list['file_size']; $data['meta_biggest'] = $list['file_max']; $data['meta_smallest'] = $list['file_min']; - if($list['file_count']) $data['meta_avg'] = $list['file_size'] / $list['file_count']; + if ($list['file_count']) $data['meta_avg'] = $list['file_size'] / $list['file_count']; unset($list); // number and size of attic $list = array(); - search($list,$conf['olddir'],array($this,'_search_count'),array('all'=>true)); + search($list, $conf['olddir'], array($this, 'searchCountCallback'), array('all'=>true)); $data['attic_count'] = $list['file_count']; $data['attic_size'] = $list['file_size']; $data['attic_biggest'] = $list['file_max']; $data['attic_smallest'] = $list['file_min']; - if($list['file_count']) $data['attic_avg'] = $list['file_size'] / $list['file_count']; + if ($list['file_count']) $data['attic_avg'] = $list['file_size'] / $list['file_count']; $data['attic_oldest'] = $list['file_oldest']; unset($list); // user count - if($auth && $auth->canDo('getUserCount')){ + if ($auth && $auth->canDo('getUserCount')) { $data['user_count'] = $auth->getUserCount(); } // calculate edits per day $list = @file($conf['metadir'].'/_dokuwiki.changes'); $count = count($list); - if($count > 2){ - $first = (int) substr(array_shift($list),0,10); - $last = (int) substr(array_pop($list),0,10); + if ($count > 2) { + $first = (int) substr(array_shift($list), 0, 10); + $last = (int) substr(array_pop($list), 0, 10); $dur = ($last - $first)/(60*60*24); // number of days in the changelog $data['edits_per_day'] = $count/$dur; } @@ -240,7 +214,7 @@ class helper_plugin_popularity extends Dokuwiki_Plugin { $data['plugin'] = plugin_list(); // pcre info - if(defined('PCRE_VERSION')) $data['pcre_version'] = PCRE_VERSION; + if (defined('PCRE_VERSION')) $data['pcre_version'] = PCRE_VERSION; $data['pcre_backtrack'] = ini_get('pcre.backtrack_limit'); $data['pcre_recursion'] = ini_get('pcre.recursion_limit'); @@ -249,27 +223,33 @@ class helper_plugin_popularity extends Dokuwiki_Plugin { $data['webserver'] = $_SERVER['SERVER_SOFTWARE']; $data['php_version'] = phpversion(); $data['php_sapi'] = php_sapi_name(); - $data['php_memory'] = $this->_to_byte(ini_get('memory_limit')); + $data['php_memory'] = php_to_byte(ini_get('memory_limit')); $data['php_exectime'] = $phptime; $data['php_extension'] = get_loaded_extensions(); // plugin usage data - $this->_add_plugin_usage_data($data); + $this->addPluginUsageData($data); return $data; } - protected function _add_plugin_usage_data(&$data){ + /** + * Triggers event to let plugins add their own data + * + * @param $data + */ + protected function addPluginUsageData(&$data) + { $pluginsData = array(); trigger_event('PLUGIN_POPULARITY_DATA_SETUP', $pluginsData); - foreach($pluginsData as $plugin => $d){ - if ( is_array($d) ) { - foreach($d as $key => $value){ - $data['plugin_' . $plugin . '_' . $key] = $value; - } - } else { - $data['plugin_' . $plugin] = $d; - } + foreach ($pluginsData as $plugin => $d) { + if (is_array($d)) { + foreach ($d as $key => $value) { + $data['plugin_' . $plugin . '_' . $key] = $value; + } + } else { + $data['plugin_' . $plugin] = $d; + } } } @@ -284,57 +264,26 @@ class helper_plugin_popularity extends Dokuwiki_Plugin { * @param array $opts option array as given to search() * @return bool */ - function _search_count(&$data,$base,$file,$type,$lvl,$opts){ + protected function searchCountCallback(&$data, $base, $file, $type, $lvl, $opts) + { // traverse - if($type == 'd'){ - if($data['dir_nest'] < $lvl) $data['dir_nest'] = $lvl; + if ($type == 'd') { + if ($data['dir_nest'] < $lvl) $data['dir_nest'] = $lvl; $data['dir_count']++; return true; } //only search txt files if 'all' option not set - if($opts['all'] || substr($file,-4) == '.txt'){ + if ($opts['all'] || substr($file, -4) == '.txt') { $size = filesize($base.'/'.$file); $date = filemtime($base.'/'.$file); $data['file_count']++; $data['file_size'] += $size; - if(!isset($data['file_min']) || $data['file_min'] > $size) $data['file_min'] = $size; - if($data['file_max'] < $size) $data['file_max'] = $size; - if(!isset($data['file_oldest']) || $data['file_oldest'] > $date) $data['file_oldest'] = $date; + if (!isset($data['file_min']) || $data['file_min'] > $size) $data['file_min'] = $size; + if ($data['file_max'] < $size) $data['file_max'] = $size; + if (!isset($data['file_oldest']) || $data['file_oldest'] > $date) $data['file_oldest'] = $date; } return false; } - - /** - * Convert php.ini shorthands to byte - * - * @author <gilthans dot NO dot SPAM at gmail dot com> - * @link http://php.net/manual/en/ini.core.php#79564 - * - * @param string $v - * @return int|string - */ - function _to_byte($v){ - $l = substr($v, -1); - $ret = substr($v, 0, -1); - switch(strtoupper($l)){ - /** @noinspection PhpMissingBreakStatementInspection */ - case 'P': - $ret *= 1024; - /** @noinspection PhpMissingBreakStatementInspection */ - case 'T': - $ret *= 1024; - /** @noinspection PhpMissingBreakStatementInspection */ - case 'G': - $ret *= 1024; - /** @noinspection PhpMissingBreakStatementInspection */ - case 'M': - $ret *= 1024; - case 'K': - $ret *= 1024; - break; - } - return $ret; - } } diff --git a/lib/plugins/remote.php b/lib/plugins/remote.php index c2253dbd5..d63f82aee 100644 --- a/lib/plugins/remote.php +++ b/lib/plugins/remote.php @@ -1,5 +1,7 @@ <?php +use dokuwiki\Remote\Api; + /** * Class DokuWiki_Remote_Plugin */ @@ -11,7 +13,7 @@ abstract class DokuWiki_Remote_Plugin extends DokuWiki_Plugin { * Constructor */ public function __construct() { - $this->api = new RemoteAPI(); + $this->api = new Api(); } /** @@ -20,7 +22,8 @@ abstract class DokuWiki_Remote_Plugin extends DokuWiki_Plugin { * By default it exports all public methods of a remote plugin. Methods beginning * with an underscore are skipped. * - * @return array Information about all provided methods. {@see RemoteAPI}. + * @return array Information about all provided methods. {@see dokuwiki\Remote\RemoteAPI}. + * @throws ReflectionException */ public function _getMethods() { $result = array(); @@ -95,7 +98,7 @@ abstract class DokuWiki_Remote_Plugin extends DokuWiki_Plugin { } /** - * @return RemoteAPI + * @return Api */ protected function getApi() { return $this->api; diff --git a/lib/plugins/revert/admin.php b/lib/plugins/revert/admin.php index 1a0300585..e6790a962 100644 --- a/lib/plugins/revert/admin.php +++ b/lib/plugins/revert/admin.php @@ -1,66 +1,70 @@ <?php -// must be run within Dokuwiki -if(!defined('DOKU_INC')) die(); - /** * All DokuWiki plugins to extend the admin function * need to inherit from this class */ -class admin_plugin_revert extends DokuWiki_Admin_Plugin { - var $cmd; +class admin_plugin_revert extends DokuWiki_Admin_Plugin +{ + protected $cmd; // some vars which might need tuning later - var $max_lines = 800; // lines to read from changelog - var $max_revs = 20; // numer of old revisions to check + protected $max_lines = 800; // lines to read from changelog + protected $max_revs = 20; // numer of old revisions to check /** * Constructor */ - function __construct(){ + public function __construct() + { $this->setupLocale(); } /** * access for managers */ - function forAdminOnly(){ + public function forAdminOnly() + { return false; } /** * return sort order for position in admin menu */ - function getMenuSort() { + public function getMenuSort() + { return 40; } /** * handle user request */ - function handle() { + public function handle() + { } /** * output appropriate html */ - function html() { + public function html() + { global $INPUT; echo $this->locale_xhtml('intro'); - $this->_searchform(); + $this->printSearchForm(); - if(is_array($INPUT->param('revert')) && checkSecurityToken()){ - $this->_revert($INPUT->arr('revert'),$INPUT->str('filter')); - }elseif($INPUT->has('filter')){ - $this->_list($INPUT->str('filter')); + if (is_array($INPUT->param('revert')) && checkSecurityToken()) { + $this->revertEdits($INPUT->arr('revert'), $INPUT->str('filter')); + } elseif ($INPUT->has('filter')) { + $this->listEdits($INPUT->str('filter')); } } /** * Display the form for searching spam pages */ - function _searchform(){ + protected function printSearchForm() + { global $lang, $INPUT; echo '<form action="" method="post"><div class="no">'; echo '<label>'.$this->getLang('filter').': </label>'; @@ -73,31 +77,32 @@ class admin_plugin_revert extends DokuWiki_Admin_Plugin { /** * Start the reversion process */ - function _revert($revert,$filter){ + protected function revertEdits($revert, $filter) + { echo '<hr /><br />'; echo '<p>'.$this->getLang('revstart').'</p>'; echo '<ul>'; - foreach($revert as $id){ + foreach ($revert as $id) { global $REV; // find the last non-spammy revision $data = ''; $pagelog = new PageChangeLog($id); $old = $pagelog->getRevisions(0, $this->max_revs); - if(count($old)){ - foreach($old as $REV){ - $data = rawWiki($id,$REV); - if(strpos($data,$filter) === false) break; + if (count($old)) { + foreach ($old as $REV) { + $data = rawWiki($id, $REV); + if (strpos($data, $filter) === false) break; } } - if($data){ - saveWikiText($id,$data,'old revision restored',false); - printf('<li><div class="li">'.$this->getLang('reverted').'</div></li>',$id,$REV); - }else{ - saveWikiText($id,'','',false); - printf('<li><div class="li">'.$this->getLang('removed').'</div></li>',$id); + if ($data) { + saveWikiText($id, $data, 'old revision restored', false); + printf('<li><div class="li">'.$this->getLang('reverted').'</div></li>', $id, $REV); + } else { + saveWikiText($id, '', '', false); + printf('<li><div class="li">'.$this->getLang('removed').'</div></li>', $id); } @set_time_limit(10); flush(); @@ -110,7 +115,8 @@ class admin_plugin_revert extends DokuWiki_Admin_Plugin { /** * List recent edits matching the given filter */ - function _list($filter){ + protected function listEdits($filter) + { global $conf; global $lang; echo '<hr /><br />'; @@ -118,13 +124,13 @@ class admin_plugin_revert extends DokuWiki_Admin_Plugin { echo '<input type="hidden" name="filter" value="'.hsc($filter).'" />'; formSecurityToken(); - $recents = getRecents(0,$this->max_lines); + $recents = getRecents(0, $this->max_lines); echo '<ul>'; $cnt = 0; - foreach($recents as $recent){ - if($filter){ - if(strpos(rawWiki($recent['id']),$filter) === false) continue; + foreach ($recents as $recent) { + if ($filter) { + if (strpos(rawWiki($recent['id']), $filter) === false) continue; } $cnt++; @@ -132,10 +138,11 @@ class admin_plugin_revert extends DokuWiki_Admin_Plugin { echo ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) ? '<li class="minor">' : '<li>'; echo '<div class="li">'; - echo '<input type="checkbox" name="revert[]" value="'.hsc($recent['id']).'" checked="checked" id="revert__'.$cnt.'" />'; + echo '<input type="checkbox" name="revert[]" value="'.hsc($recent['id']). + '" checked="checked" id="revert__'.$cnt.'" />'; echo ' <label for="revert__'.$cnt.'">'.$date.'</label> '; - echo '<a href="'.wl($recent['id'],"do=diff").'">'; + echo '<a href="'.wl($recent['id'], "do=diff").'">'; $p = array(); $p['src'] = DOKU_BASE.'lib/images/diff.png'; $p['width'] = 15; @@ -146,7 +153,7 @@ class admin_plugin_revert extends DokuWiki_Admin_Plugin { echo "<img $att />"; echo '</a> '; - echo '<a href="'.wl($recent['id'],"do=revisions").'">'; + echo '<a href="'.wl($recent['id'], "do=revisions").'">'; $p = array(); $p['src'] = DOKU_BASE.'lib/images/history.png'; $p['width'] = 12; @@ -157,7 +164,7 @@ class admin_plugin_revert extends DokuWiki_Admin_Plugin { echo "<img $att />"; echo '</a> '; - echo html_wikilink(':'.$recent['id'],(useHeading('navigation'))?null:$recent['id']); + echo html_wikilink(':'.$recent['id'], (useHeading('navigation'))?null:$recent['id']); echo ' – '.htmlspecialchars($recent['sum']); echo ' <span class="user">'; @@ -174,11 +181,10 @@ class admin_plugin_revert extends DokuWiki_Admin_Plugin { echo '<p>'; echo '<button type="submit">'.$this->getLang('revert').'</button> '; - printf($this->getLang('note2'),hsc($filter)); + printf($this->getLang('note2'), hsc($filter)); echo '</p>'; echo '</div></form>'; } - } //Setup VIM: ex: et ts=4 : diff --git a/lib/plugins/safefnrecode/action.php b/lib/plugins/safefnrecode/action.php index 9127f8df2..952d95c90 100644 --- a/lib/plugins/safefnrecode/action.php +++ b/lib/plugins/safefnrecode/action.php @@ -6,63 +6,63 @@ * @author Andreas Gohr <andi@splitbrain.org> */ -// must be run within Dokuwiki -if (!defined('DOKU_INC')) die(); - -require_once DOKU_PLUGIN.'action.php'; - -class action_plugin_safefnrecode extends DokuWiki_Action_Plugin { - - public function register(Doku_Event_Handler $controller) { - - $controller->register_hook('INDEXER_TASKS_RUN', 'BEFORE', $this, 'handle_indexer_tasks_run'); +class action_plugin_safefnrecode extends DokuWiki_Action_Plugin +{ + /** @inheritdoc */ + public function register(Doku_Event_Handler $controller) + { + $controller->register_hook('INDEXER_TASKS_RUN', 'BEFORE', $this, 'handleIndexerTasksRun'); } - public function handle_indexer_tasks_run(Doku_Event &$event, $param) { + /** + * Handle indexer event + * + * @param Doku_Event $event + * @param $param + */ + public function handleIndexerTasksRun(Doku_Event $event, $param) + { global $conf; - if($conf['fnencode'] != 'safe') return; + if ($conf['fnencode'] != 'safe') return; - if(!file_exists($conf['datadir'].'_safefn.recoded')){ + if (!file_exists($conf['datadir'].'_safefn.recoded')) { $this->recode($conf['datadir']); touch($conf['datadir'].'_safefn.recoded'); } - if(!file_exists($conf['olddir'].'_safefn.recoded')){ + if (!file_exists($conf['olddir'].'_safefn.recoded')) { $this->recode($conf['olddir']); touch($conf['olddir'].'_safefn.recoded'); } - if(!file_exists($conf['metadir'].'_safefn.recoded')){ + if (!file_exists($conf['metadir'].'_safefn.recoded')) { $this->recode($conf['metadir']); touch($conf['metadir'].'_safefn.recoded'); } - if(!file_exists($conf['mediadir'].'_safefn.recoded')){ + if (!file_exists($conf['mediadir'].'_safefn.recoded')) { $this->recode($conf['mediadir']); touch($conf['mediadir'].'_safefn.recoded'); } - } /** * Recursive function to rename all safe encoded files to use the new * square bracket post indicator */ - private function recode($dir){ + private function recode($dir) + { $dh = opendir($dir); - if(!$dh) return; + if (!$dh) return; while (($file = readdir($dh)) !== false) { - if($file == '.' || $file == '..') continue; # cur and upper dir - if(is_dir("$dir/$file")) $this->recode("$dir/$file"); #recurse - if(strpos($file,'%') === false) continue; # no encoding used - $new = preg_replace('/(%[^\]]*?)\./','\1]',$file); # new post indicator - if(preg_match('/%[^\]]+$/',$new)) $new .= ']'; # fix end FS#2122 - rename("$dir/$file","$dir/$new"); # rename it + if ($file == '.' || $file == '..') continue; # cur and upper dir + if (is_dir("$dir/$file")) $this->recode("$dir/$file"); #recurse + if (strpos($file, '%') === false) continue; # no encoding used + $new = preg_replace('/(%[^\]]*?)\./', '\1]', $file); # new post indicator + if (preg_match('/%[^\]]+$/', $new)) $new .= ']'; # fix end FS#2122 + rename("$dir/$file", "$dir/$new"); # rename it } closedir($dh); } - } - -// vim:ts=4:sw=4:et: diff --git a/lib/plugins/styling/action.php b/lib/plugins/styling/action.php index 896e14bef..8b9db6979 100644 --- a/lib/plugins/styling/action.php +++ b/lib/plugins/styling/action.php @@ -5,19 +5,8 @@ * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html * @author Andreas Gohr <andi@splitbrain.org> */ - -// must be run within Dokuwiki -if(!defined('DOKU_INC')) die(); - -/** - * Class action_plugin_styling - * - * This handles all the save actions and loading the interface - * - * All this usually would be done within an admin plugin, but we want to have this available outside - * the admin interface using our floating dialog. - */ -class action_plugin_styling extends DokuWiki_Action_Plugin { +class action_plugin_styling extends DokuWiki_Action_Plugin +{ /** * Registers a callback functions @@ -25,8 +14,9 @@ class action_plugin_styling extends DokuWiki_Action_Plugin { * @param Doku_Event_Handler $controller DokuWiki's event controller object * @return void */ - public function register(Doku_Event_Handler $controller) { - $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handle_header'); + public function register(Doku_Event_Handler $controller) + { + $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handleHeader'); } /** @@ -37,24 +27,23 @@ class action_plugin_styling extends DokuWiki_Action_Plugin { * handler was registered] * @return void */ - public function handle_header(Doku_Event &$event, $param) { + public function handleHeader(Doku_Event &$event, $param) + { global $ACT; global $INPUT; - if($ACT != 'admin' || $INPUT->str('page') != 'styling') return; - if(!auth_isadmin()) return; + if ($ACT != 'admin' || $INPUT->str('page') != 'styling') return; + if (!auth_isadmin()) return; // set preview $len = count($event->data['link']); - for($i = 0; $i < $len; $i++) { - if( - $event->data['link'][$i]['rel'] == 'stylesheet' && + for ($i = 0; $i < $len; $i++) { + if ($event->data['link'][$i]['rel'] == 'stylesheet' && strpos($event->data['link'][$i]['href'], 'lib/exe/css.php') !== false ) { $event->data['link'][$i]['href'] .= '&preview=1&tseed='.time(); } } } - } // vim:ts=4:sw=4:et: diff --git a/lib/plugins/styling/admin.php b/lib/plugins/styling/admin.php index 055ac2279..2cc2618ca 100644 --- a/lib/plugins/styling/admin.php +++ b/lib/plugins/styling/admin.php @@ -5,45 +5,46 @@ * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html * @author Andreas Gohr <andi@splitbrain.org> */ - -// must be run within Dokuwiki -if(!defined('DOKU_INC')) die(); - -class admin_plugin_styling extends DokuWiki_Admin_Plugin { +class admin_plugin_styling extends DokuWiki_Admin_Plugin +{ public $ispopup = false; /** * @return int sort number in admin menu */ - public function getMenuSort() { + public function getMenuSort() + { return 1000; } /** * @return bool true if only access for superuser, false is for superusers and moderators */ - public function forAdminOnly() { + public function forAdminOnly() + { return true; } /** * handle the different actions (also called from ajax) */ - public function handle() { + public function handle() + { global $INPUT; $run = $INPUT->extract('run')->str('run'); - if(!$run) return; - $run = "run_$run"; + if (!$run) return; + $run = 'run'.ucfirst($run); $this->$run(); } /** * Render HTML output, e.g. helpful text and a form */ - public function html() { + public function html() + { $class = 'nopopup'; - if($this->ispopup) $class = 'ispopup page'; + if ($this->ispopup) $class = 'ispopup page'; echo '<div id="plugin__styling" class="'.$class.'">'; ptln('<h1>'.$this->getLang('menu').'</h1>'); @@ -54,7 +55,8 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { /** * Create the actual editing form */ - public function form() { + public function form() + { global $conf; global $ID; @@ -62,13 +64,13 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { $styleini = $styleUtil->cssStyleini($conf['template'], true); $replacements = $styleini['replacements']; - if($this->ispopup) { + if ($this->ispopup) { $target = DOKU_BASE.'lib/plugins/styling/popup.php'; } else { $target = wl($ID, array('do' => 'admin', 'page' => 'styling')); } - if(empty($replacements)) { + if (empty($replacements)) { echo '<p class="error">'.$this->getLang('error').'</p>'; } else { echo $this->locale_xhtml('intro'); @@ -76,21 +78,24 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { echo '<form class="styling" method="post" action="'.$target.'">'; echo '<table><tbody>'; - foreach($replacements as $key => $value) { + foreach ($replacements as $key => $value) { $name = tpl_getLang($key); - if(empty($name)) $name = $this->getLang($key); - if(empty($name)) $name = $key; + if (empty($name)) $name = $this->getLang($key); + if (empty($name)) $name = $key; echo '<tr>'; echo '<td><label for="tpl__'.hsc($key).'">'.$name.'</label></td>'; - echo '<td><input type="text" name="tpl['.hsc($key).']" id="tpl__'.hsc($key).'" value="'.hsc($value).'" '.$this->colorClass($key).' dir="ltr" /></td>'; + echo '<td><input type="text" name="tpl['.hsc($key).']" id="tpl__'.hsc($key).'" + value="'.hsc($value).'" '.$this->colorClass($key).' dir="ltr" /></td>'; echo '</tr>'; } echo '</tbody></table>'; echo '<p>'; - echo '<button type="submit" name="run[preview]" class="btn_preview primary">'.$this->getLang('btn_preview').'</button> '; - echo '<button type="submit" name="run[reset]">'.$this->getLang('btn_reset').'</button>'; #FIXME only if preview.ini exists + echo '<button type="submit" name="run[preview]" class="btn_preview primary">'. + $this->getLang('btn_preview').'</button> '; + #FIXME only if preview.ini exists: + echo '<button type="submit" name="run[reset]">'.$this->getLang('btn_reset').'</button>'; echo '</p>'; echo '<p>'; @@ -98,20 +103,21 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { echo '</p>'; echo '<p>'; - echo '<button type="submit" name="run[revert]">'.$this->getLang('btn_revert').'</button>'; #FIXME only if local.ini exists + #FIXME only if local.ini exists: + echo '<button type="submit" name="run[revert]">'.$this->getLang('btn_revert').'</button>'; echo '</p>'; echo '</form>'; echo tpl_locale_xhtml('style'); - } } /** * set the color class attribute */ - protected function colorClass($key) { + protected function colorClass($key) + { static $colors = array( 'text', 'background', @@ -127,7 +133,7 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { 'missing', ); - if(preg_match('/colou?r/', $key) || in_array(trim($key,'_'), $colors)) { + if (preg_match('/colou?r/', $key) || in_array(trim($key, '_'), $colors)) { return 'class="color"'; } else { return ''; @@ -137,7 +143,8 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { /** * saves the preview.ini (alos called from ajax directly) */ - public function run_preview() { + public function runPreview() + { global $conf; $ini = $conf['cachedir'].'/preview.ini'; io_saveFile($ini, $this->makeini()); @@ -146,7 +153,8 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { /** * deletes the preview.ini */ - protected function run_reset() { + protected function runReset() + { global $conf; $ini = $conf['cachedir'].'/preview.ini'; io_saveFile($ini, ''); @@ -155,17 +163,19 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { /** * deletes the local style.ini replacements */ - protected function run_revert() { - $this->replaceini(''); - $this->run_reset(); + protected function runRevert() + { + $this->replaceIni(''); + $this->runReset(); } /** * save the local style.ini replacements */ - protected function run_save() { - $this->replaceini($this->makeini()); - $this->run_reset(); + protected function runSave() + { + $this->replaceIni($this->makeini()); + $this->runReset(); } /** @@ -173,13 +183,14 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { * * @return string */ - protected function makeini() { + protected function makeini() + { global $INPUT; $ini = "[replacements]\n"; $ini .= ";These overwrites have been generated from the Template styling Admin interface\n"; $ini .= ";Any values in this section will be overwritten by that tool again\n"; - foreach($INPUT->arr('tpl') as $key => $val) { + foreach ($INPUT->arr('tpl') as $key => $val) { $ini .= $key.' = "'.addslashes($val).'"'."\n"; } @@ -191,10 +202,11 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { * * @param string $new the new ini contents */ - protected function replaceini($new) { + protected function replaceIni($new) + { global $conf; $ini = DOKU_CONF."tpl/".$conf['template']."/style.ini"; - if(file_exists($ini)) { + if (file_exists($ini)) { $old = io_readFile($ini); $old = preg_replace('/\[replacements\]\n.*?(\n\[.*]|$)/s', '\\1', $old); $old = trim($old); @@ -205,7 +217,6 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { io_makeFileDir($ini); io_saveFile($ini, "$old\n\n$new"); } - } // vim:ts=4:sw=4:et: diff --git a/lib/plugins/styling/popup.php b/lib/plugins/styling/popup.php index 964b19e29..b78f1af06 100644 --- a/lib/plugins/styling/popup.php +++ b/lib/plugins/styling/popup.php @@ -1,5 +1,6 @@ <?php -if(!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__) . '/../../../'); +// phpcs:disable PSR1.Files.SideEffects +if (!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__) . '/../../../'); require_once(DOKU_INC . 'inc/init.php'); //close session session_write_close(); @@ -8,7 +9,7 @@ header('X-UA-Compatible: IE=edge,chrome=1'); /** @var admin_plugin_styling $plugin */ $plugin = plugin_load('admin', 'styling'); -if(!auth_isadmin()) die('only admins allowed'); +if (!auth_isadmin()) die('only admins allowed'); $plugin->ispopup = true; // handle posts diff --git a/lib/plugins/syntax.php b/lib/plugins/syntax.php index 9e2913d78..b74bb5bf0 100644 --- a/lib/plugins/syntax.php +++ b/lib/plugins/syntax.php @@ -2,42 +2,36 @@ /** * Syntax Plugin Prototype * - * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) - * @author Andreas Gohr <andi@splitbrain.org> - */ -// must be run within Dokuwiki -if(!defined('DOKU_INC')) die(); - -/** * All DokuWiki plugins to extend the parser/rendering mechanism * need to inherit from this class + * + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * @author Andreas Gohr <andi@splitbrain.org> */ -class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode_Plugin { +abstract class DokuWiki_Syntax_Plugin extends \dokuwiki\Parsing\ParserMode\Plugin { + use DokuWiki_PluginTrait; - var $allowedModesSetup = false; + protected $allowedModesSetup = false; /** * Syntax Type * - * Needs to return one of the mode types defined in $PARSER_MODES in parser.php + * Needs to return one of the mode types defined in $PARSER_MODES in Parser.php * * @return string */ - function getType(){ - trigger_error('getType() not implemented in '.get_class($this), E_USER_WARNING); - return ''; - } + abstract public function getType(); /** * Allowed Mode Types * * Defines the mode types for other dokuwiki markup that maybe nested within the * plugin's own markup. Needs to return an array of one or more of the mode types - * defined in $PARSER_MODES in parser.php + * defined in $PARSER_MODES in Parser.php * * @return array */ - function getAllowedTypes() { + public function getAllowedTypes() { return array(); } @@ -55,7 +49,7 @@ class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode_Plugin { * * @return string */ - function getPType(){ + public function getPType(){ return 'normal'; } @@ -73,9 +67,7 @@ class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode_Plugin { * @param Doku_Handler $handler The Doku_Handler object * @return bool|array Return an array with all data you want to use in render, false don't add an instruction */ - function handle($match, $state, $pos, Doku_Handler $handler){ - trigger_error('handle() not implemented in '.get_class($this), E_USER_WARNING); - } + abstract public function handle($match, $state, $pos, Doku_Handler $handler); /** * Handles the actual output creation. @@ -100,10 +92,7 @@ class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode_Plugin { * @param array $data data created by handler() * @return boolean rendered correctly? (however, returned value is not used at the moment) */ - function render($format, Doku_Renderer $renderer, $data) { - trigger_error('render() not implemented in '.get_class($this), E_USER_WARNING); - - } + abstract public function render($format, Doku_Renderer $renderer, $data); /** * There should be no need to override this function @@ -111,7 +100,7 @@ class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode_Plugin { * @param string $mode * @return bool */ - function accepts($mode) { + public function accepts($mode) { if (!$this->allowedModesSetup) { global $PARSER_MODES; diff --git a/lib/plugins/testing/action.php b/lib/plugins/testing/action.php index a242ab0b7..d34ef1858 100644 --- a/lib/plugins/testing/action.php +++ b/lib/plugins/testing/action.php @@ -8,11 +8,12 @@ */ class action_plugin_testing extends DokuWiki_Action_Plugin { - function register(Doku_Event_Handler $controller) { + /** @inheritdoc */ + public function register(Doku_Event_Handler $controller) { $controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'dokuwikiStarted'); } - function dokuwikiStarted() { + public function dokuwikiStarted() { $param = array(); trigger_event('TESTING_PLUGIN_INSTALLED', $param); msg('The testing plugin is enabled and should be disabled.',-1); diff --git a/lib/plugins/usermanager/_test/mocks.class.php b/lib/plugins/usermanager/_test/mocks.class.php index e524e451b..75ac51422 100644 --- a/lib/plugins/usermanager/_test/mocks.class.php +++ b/lib/plugins/usermanager/_test/mocks.class.php @@ -16,30 +16,30 @@ class admin_mock_usermanager extends admin_plugin_usermanager { public $lang; public function getImportFailures() { - return $this->_import_failures; + return $this->import_failures; } public function tryExport() { ob_start(); - $this->_export(); + $this->exportCSV(); return ob_get_clean(); } public function tryImport() { - return $this->_import(); + return $this->importCSV(); } // no need to send email notifications (mostly) - protected function _notifyUser($user, $password, $status_alert=true) { + protected function notifyUser($user, $password, $status_alert=true) { if ($this->mock_email_notifications) { $this->mock_email_notifications_sent++; return true; } else { - return parent::_notifyUser($user, $password, $status_alert); + return parent::notifyUser($user, $password, $status_alert); } } - protected function _isUploadedFile($file) { + protected function isUploadedFile($file) { return file_exists($file); } } diff --git a/lib/plugins/usermanager/admin.php b/lib/plugins/usermanager/admin.php index 6d9bf3b20..8e5670db3 100644 --- a/lib/plugins/usermanager/admin.php +++ b/lib/plugins/usermanager/admin.php @@ -10,52 +10,49 @@ * @author neolao <neolao@neolao.com> * @author Chris Smith <chris@jalakai.co.uk> */ -// must be run within Dokuwiki -if(!defined('DOKU_INC')) die(); - -if(!defined('DOKU_PLUGIN_IMAGES')) define('DOKU_PLUGIN_IMAGES',DOKU_BASE.'lib/plugins/usermanager/images/'); /** * All DokuWiki plugins to extend the admin function * need to inherit from this class */ -class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { - - protected $_auth = null; // auth object - protected $_user_total = 0; // number of registered users - protected $_filter = array(); // user selection filter(s) - protected $_start = 0; // index of first user to be displayed - protected $_last = 0; // index of the last user to be displayed - protected $_pagesize = 20; // number of users to list on one page - protected $_edit_user = ''; // set to user selected for editing - protected $_edit_userdata = array(); - protected $_disabled = ''; // if disabled set to explanatory string - protected $_import_failures = array(); - protected $_lastdisabled = false; // set to true if last user is unknown and last button is hence buggy +class admin_plugin_usermanager extends DokuWiki_Admin_Plugin +{ + const IMAGE_DIR = DOKU_BASE.'lib/plugins/usermanager/images/'; + + protected $auth = null; // auth object + protected $users_total = 0; // number of registered users + protected $filter = array(); // user selection filter(s) + protected $start = 0; // index of first user to be displayed + protected $last = 0; // index of the last user to be displayed + protected $pagesize = 20; // number of users to list on one page + protected $edit_user = ''; // set to user selected for editing + protected $edit_userdata = array(); + protected $disabled = ''; // if disabled set to explanatory string + protected $import_failures = array(); + protected $lastdisabled = false; // set to true if last user is unknown and last button is hence buggy /** * Constructor */ - public function __construct(){ + public function __construct() + { /** @var DokuWiki_Auth_Plugin $auth */ global $auth; $this->setupLocale(); if (!isset($auth)) { - $this->_disabled = $this->lang['noauth']; - } else if (!$auth->canDo('getUsers')) { - $this->_disabled = $this->lang['nosupport']; + $this->disabled = $this->lang['noauth']; + } elseif (!$auth->canDo('getUsers')) { + $this->disabled = $this->lang['nosupport']; } else { - // we're good to go - $this->_auth = & $auth; - + $this->auth = & $auth; } // attempt to retrieve any import failures from the session - if (!empty($_SESSION['import_failures'])){ - $this->_import_failures = $_SESSION['import_failures']; + if (!empty($_SESSION['import_failures'])) { + $this->import_failures = $_SESSION['import_failures']; } } @@ -65,12 +62,13 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { * @param string $language * @return string */ - public function getMenuText($language) { + public function getMenuText($language) + { - if (!is_null($this->_auth)) + if (!is_null($this->auth)) return parent::getMenuText($language); - return $this->getLang('menu').' '.$this->_disabled; + return $this->getLang('menu').' '.$this->disabled; } /** @@ -78,29 +76,33 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { * * @return int */ - public function getMenuSort() { + public function getMenuSort() + { return 2; } /** * @return int current start value for pageination */ - public function getStart() { - return $this->_start; + public function getStart() + { + return $this->start; } /** * @return int number of users per page */ - public function getPagesize() { - return $this->_pagesize; + public function getPagesize() + { + return $this->pagesize; } /** * @param boolean $lastdisabled */ - public function setLastdisabled($lastdisabled) { - $this->_lastdisabled = $lastdisabled; + public function setLastdisabled($lastdisabled) + { + $this->lastdisabled = $lastdisabled; } /** @@ -108,9 +110,10 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { * * @return bool */ - public function handle() { + public function handle() + { global $INPUT; - if (is_null($this->_auth)) return false; + if (is_null($this->auth)) return false; // extract the command and any specific parameters // submit button name is of the form - fn[cmd][param(s)] @@ -125,33 +128,56 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { } if ($cmd != "search") { - $this->_start = $INPUT->int('start', 0); - $this->_filter = $this->_retrieveFilter(); + $this->start = $INPUT->int('start', 0); + $this->filter = $this->retrieveFilter(); } - switch($cmd){ - case "add" : $this->_addUser(); break; - case "delete" : $this->_deleteUser(); break; - case "modify" : $this->_modifyUser(); break; - case "edit" : $this->_editUser($param); break; - case "search" : $this->_setFilter($param); - $this->_start = 0; - break; - case "export" : $this->_export(); break; - case "import" : $this->_import(); break; - case "importfails" : $this->_downloadImportFailures(); break; + switch ($cmd) { + case "add": + $this->addUser(); + break; + case "delete": + $this->deleteUser(); + break; + case "modify": + $this->modifyUser(); + break; + case "edit": + $this->editUser($param); + break; + case "search": + $this->setFilter($param); + $this->start = 0; + break; + case "export": + $this->exportCSV(); + break; + case "import": + $this->importCSV(); + break; + case "importfails": + $this->downloadImportFailures(); + break; } - $this->_user_total = $this->_auth->canDo('getUserCount') ? $this->_auth->getUserCount($this->_filter) : -1; + $this->users_total = $this->auth->canDo('getUserCount') ? $this->auth->getUserCount($this->filter) : -1; // page handling - switch($cmd){ - case 'start' : $this->_start = 0; break; - case 'prev' : $this->_start -= $this->_pagesize; break; - case 'next' : $this->_start += $this->_pagesize; break; - case 'last' : $this->_start = $this->_user_total; break; + switch ($cmd) { + case 'start': + $this->start = 0; + break; + case 'prev': + $this->start -= $this->pagesize; + break; + case 'next': + $this->start += $this->pagesize; + break; + case 'last': + $this->start = $this->users_total; + break; } - $this->_validatePagination(); + $this->validatePagination(); return true; } @@ -160,21 +186,22 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { * * @return bool */ - public function html() { + public function html() + { global $ID; - if(is_null($this->_auth)) { + if (is_null($this->auth)) { print $this->lang['badauth']; return false; } - $user_list = $this->_auth->retrieveUsers($this->_start, $this->_pagesize, $this->_filter); + $user_list = $this->auth->retrieveUsers($this->start, $this->pagesize, $this->filter); - $page_buttons = $this->_pagination(); - $delete_disable = $this->_auth->canDo('delUser') ? '' : 'disabled="disabled"'; + $page_buttons = $this->pagination(); + $delete_disable = $this->auth->canDo('delUser') ? '' : 'disabled="disabled"'; - $editable = $this->_auth->canDo('UserMod'); - $export_label = empty($this->_filter) ? $this->lang['export_all'] : $this->lang['export_filtered']; + $editable = $this->auth->canDo('UserMod'); + $export_label = empty($this->filter) ? $this->lang['export_all'] : $this->lang['export_filtered']; print $this->locale_xhtml('intro'); print $this->locale_xhtml('list'); @@ -182,13 +209,21 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { ptln("<div id=\"user__manager\">"); ptln("<div class=\"level2\">"); - if ($this->_user_total > 0) { - ptln("<p>".sprintf($this->lang['summary'],$this->_start+1,$this->_last,$this->_user_total,$this->_auth->getUserCount())."</p>"); + if ($this->users_total > 0) { + ptln( + "<p>" . sprintf( + $this->lang['summary'], + $this->start + 1, + $this->last, + $this->users_total, + $this->auth->getUserCount() + ) . "</p>" + ); } else { - if($this->_user_total < 0) { + if ($this->users_total < 0) { $allUserTotal = 0; } else { - $allUserTotal = $this->_auth->getUserCount(); + $allUserTotal = $this->auth->getUserCount(); } ptln("<p>".sprintf($this->lang['nonefound'], $allUserTotal)."</p>"); } @@ -198,19 +233,29 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { ptln(" <table class=\"inline\">"); ptln(" <thead>"); ptln(" <tr>"); - ptln(" <th> </th><th>".$this->lang["user_id"]."</th><th>".$this->lang["user_name"]."</th><th>".$this->lang["user_mail"]."</th><th>".$this->lang["user_groups"]."</th>"); + ptln(" <th> </th> + <th>".$this->lang["user_id"]."</th> + <th>".$this->lang["user_name"]."</th> + <th>".$this->lang["user_mail"]."</th> + <th>".$this->lang["user_groups"]."</th>"); ptln(" </tr>"); ptln(" <tr>"); - ptln(" <td class=\"rightalign\"><input type=\"image\" src=\"".DOKU_PLUGIN_IMAGES."search.png\" name=\"fn[search][new]\" title=\"".$this->lang['search_prompt']."\" alt=\"".$this->lang['search']."\" class=\"button\" /></td>"); - ptln(" <td><input type=\"text\" name=\"userid\" class=\"edit\" value=\"".$this->_htmlFilter('user')."\" /></td>"); - ptln(" <td><input type=\"text\" name=\"username\" class=\"edit\" value=\"".$this->_htmlFilter('name')."\" /></td>"); - ptln(" <td><input type=\"text\" name=\"usermail\" class=\"edit\" value=\"".$this->_htmlFilter('mail')."\" /></td>"); - ptln(" <td><input type=\"text\" name=\"usergroups\" class=\"edit\" value=\"".$this->_htmlFilter('grps')."\" /></td>"); + ptln(" <td class=\"rightalign\"><input type=\"image\" src=\"". + self::IMAGE_DIR."search.png\" name=\"fn[search][new]\" title=\"". + $this->lang['search_prompt']."\" alt=\"".$this->lang['search']."\" class=\"button\" /></td>"); + ptln(" <td><input type=\"text\" name=\"userid\" class=\"edit\" value=\"". + $this->htmlFilter('user')."\" /></td>"); + ptln(" <td><input type=\"text\" name=\"username\" class=\"edit\" value=\"". + $this->htmlFilter('name')."\" /></td>"); + ptln(" <td><input type=\"text\" name=\"usermail\" class=\"edit\" value=\"". + $this->htmlFilter('mail')."\" /></td>"); + ptln(" <td><input type=\"text\" name=\"usergroups\" class=\"edit\" value=\"". + $this->htmlFilter('grps')."\" /></td>"); ptln(" </tr>"); ptln(" </thead>"); - if ($this->_user_total) { + if ($this->users_total) { ptln(" <tbody>"); foreach ($user_list as $user => $userinfo) { extract($userinfo); @@ -220,11 +265,12 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { * @var string $mail * @var array $grps */ - $groups = join(', ',$grps); + $groups = join(', ', $grps); ptln(" <tr class=\"user_info\">"); - ptln(" <td class=\"centeralign\"><input type=\"checkbox\" name=\"delete[".hsc($user)."]\" ".$delete_disable." /></td>"); + ptln(" <td class=\"centeralign\"><input type=\"checkbox\" name=\"delete[".hsc($user). + "]\" ".$delete_disable." /></td>"); if ($editable) { - ptln(" <td><a href=\"".wl($ID,array('fn[edit]['.$user.']' => 1, + ptln(" <td><a href=\"".wl($ID, array('fn[edit]['.$user.']' => 1, 'do' => 'admin', 'page' => 'usermanager', 'sectok' => getSecurityToken())). @@ -241,22 +287,27 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { ptln(" <tbody>"); ptln(" <tr><td colspan=\"5\" class=\"centeralign\">"); ptln(" <span class=\"medialeft\">"); - ptln(" <button type=\"submit\" name=\"fn[delete]\" id=\"usrmgr__del\" ".$delete_disable.">".$this->lang['delete_selected']."</button>"); + ptln(" <button type=\"submit\" name=\"fn[delete]\" id=\"usrmgr__del\" ".$delete_disable.">". + $this->lang['delete_selected']."</button>"); ptln(" </span>"); ptln(" <span class=\"mediaright\">"); - ptln(" <button type=\"submit\" name=\"fn[start]\" ".$page_buttons['start'].">".$this->lang['start']."</button>"); - ptln(" <button type=\"submit\" name=\"fn[prev]\" ".$page_buttons['prev'].">".$this->lang['prev']."</button>"); - ptln(" <button type=\"submit\" name=\"fn[next]\" ".$page_buttons['next'].">".$this->lang['next']."</button>"); - ptln(" <button type=\"submit\" name=\"fn[last]\" ".$page_buttons['last'].">".$this->lang['last']."</button>"); + ptln(" <button type=\"submit\" name=\"fn[start]\" ".$page_buttons['start'].">". + $this->lang['start']."</button>"); + ptln(" <button type=\"submit\" name=\"fn[prev]\" ".$page_buttons['prev'].">". + $this->lang['prev']."</button>"); + ptln(" <button type=\"submit\" name=\"fn[next]\" ".$page_buttons['next'].">". + $this->lang['next']."</button>"); + ptln(" <button type=\"submit\" name=\"fn[last]\" ".$page_buttons['last'].">". + $this->lang['last']."</button>"); ptln(" </span>"); - if (!empty($this->_filter)) { + if (!empty($this->filter)) { ptln(" <button type=\"submit\" name=\"fn[search][clear]\">".$this->lang['clear']."</button>"); } ptln(" <button type=\"submit\" name=\"fn[export]\">".$export_label."</button>"); ptln(" <input type=\"hidden\" name=\"do\" value=\"admin\" />"); ptln(" <input type=\"hidden\" name=\"page\" value=\"usermanager\" />"); - $this->_htmlFilterSettings(2); + $this->htmlFilterSettings(2); ptln(" </td></tr>"); ptln(" </tbody>"); @@ -266,32 +317,32 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { ptln("</form>"); ptln("</div>"); - $style = $this->_edit_user ? " class=\"edit_user\"" : ""; + $style = $this->edit_user ? " class=\"edit_user\"" : ""; - if ($this->_auth->canDo('addUser')) { + if ($this->auth->canDo('addUser')) { ptln("<div".$style.">"); print $this->locale_xhtml('add'); ptln(" <div class=\"level2\">"); - $this->_htmlUserForm('add',null,array(),4); + $this->htmlUserForm('add', null, array(), 4); ptln(" </div>"); ptln("</div>"); } - if($this->_edit_user && $this->_auth->canDo('UserMod')){ + if ($this->edit_user && $this->auth->canDo('UserMod')) { ptln("<div".$style." id=\"scroll__here\">"); print $this->locale_xhtml('edit'); ptln(" <div class=\"level2\">"); - $this->_htmlUserForm('modify',$this->_edit_user,$this->_edit_userdata,4); + $this->htmlUserForm('modify', $this->edit_user, $this->edit_userdata, 4); ptln(" </div>"); ptln("</div>"); } - if ($this->_auth->canDo('addUser')) { - $this->_htmlImportForm(); + if ($this->auth->canDo('addUser')) { + $this->htmlImportForm(); } ptln("</div>"); return true; @@ -305,7 +356,8 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { * @param array $userdata array with name, mail, pass and grps * @param int $indent */ - protected function _htmlUserForm($cmd,$user='',$userdata=array(),$indent=0) { + protected function htmlUserForm($cmd, $user = '', $userdata = array(), $indent = 0) + { global $conf; global $ID; global $lang; @@ -315,28 +367,76 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { if ($user) { extract($userdata); - if (!empty($grps)) $groups = join(',',$grps); + if (!empty($grps)) $groups = join(',', $grps); } else { - $notes[] = sprintf($this->lang['note_group'],$conf['defaultgroup']); + $notes[] = sprintf($this->lang['note_group'], $conf['defaultgroup']); } - ptln("<form action=\"".wl($ID)."\" method=\"post\">",$indent); + ptln("<form action=\"".wl($ID)."\" method=\"post\">", $indent); formSecurityToken(); - ptln(" <div class=\"table\">",$indent); - ptln(" <table class=\"inline\">",$indent); - ptln(" <thead>",$indent); - ptln(" <tr><th>".$this->lang["field"]."</th><th>".$this->lang["value"]."</th></tr>",$indent); - ptln(" </thead>",$indent); - ptln(" <tbody>",$indent); - - $this->_htmlInputField($cmd."_userid", "userid", $this->lang["user_id"], $user, $this->_auth->canDo("modLogin"), true, $indent+6); - $this->_htmlInputField($cmd."_userpass", "userpass", $this->lang["user_pass"], "", $this->_auth->canDo("modPass"), false, $indent+6); - $this->_htmlInputField($cmd."_userpass2", "userpass2", $lang["passchk"], "", $this->_auth->canDo("modPass"), false, $indent+6); - $this->_htmlInputField($cmd."_username", "username", $this->lang["user_name"], $name, $this->_auth->canDo("modName"), true, $indent+6); - $this->_htmlInputField($cmd."_usermail", "usermail", $this->lang["user_mail"], $mail, $this->_auth->canDo("modMail"), true, $indent+6); - $this->_htmlInputField($cmd."_usergroups","usergroups",$this->lang["user_groups"],$groups,$this->_auth->canDo("modGroups"), false, $indent+6); - - if ($this->_auth->canDo("modPass")) { + ptln(" <div class=\"table\">", $indent); + ptln(" <table class=\"inline\">", $indent); + ptln(" <thead>", $indent); + ptln(" <tr><th>".$this->lang["field"]."</th><th>".$this->lang["value"]."</th></tr>", $indent); + ptln(" </thead>", $indent); + ptln(" <tbody>", $indent); + + $this->htmlInputField( + $cmd . "_userid", + "userid", + $this->lang["user_id"], + $user, + $this->auth->canDo("modLogin"), + true, + $indent + 6 + ); + $this->htmlInputField( + $cmd . "_userpass", + "userpass", + $this->lang["user_pass"], + "", + $this->auth->canDo("modPass"), + false, + $indent + 6 + ); + $this->htmlInputField( + $cmd . "_userpass2", + "userpass2", + $lang["passchk"], + "", + $this->auth->canDo("modPass"), + false, + $indent + 6 + ); + $this->htmlInputField( + $cmd . "_username", + "username", + $this->lang["user_name"], + $name, + $this->auth->canDo("modName"), + true, + $indent + 6 + ); + $this->htmlInputField( + $cmd . "_usermail", + "usermail", + $this->lang["user_mail"], + $mail, + $this->auth->canDo("modMail"), + true, + $indent + 6 + ); + $this->htmlInputField( + $cmd . "_usergroups", + "usergroups", + $this->lang["user_groups"], + $groups, + $this->auth->canDo("modGroups"), + false, + $indent + 6 + ); + + if ($this->auth->canDo("modPass")) { if ($cmd == 'add') { $notes[] = $this->lang['note_pass']; } @@ -344,37 +444,40 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { $notes[] = $this->lang['note_notify']; } - ptln("<tr><td><label for=\"".$cmd."_usernotify\" >".$this->lang["user_notify"].": </label></td><td><input type=\"checkbox\" id=\"".$cmd."_usernotify\" name=\"usernotify\" value=\"1\" /></td></tr>", $indent); + ptln("<tr><td><label for=\"".$cmd."_usernotify\" >". + $this->lang["user_notify"].": </label></td> + <td><input type=\"checkbox\" id=\"".$cmd."_usernotify\" name=\"usernotify\" value=\"1\" /> + </td></tr>", $indent); } - ptln(" </tbody>",$indent); - ptln(" <tbody>",$indent); - ptln(" <tr>",$indent); - ptln(" <td colspan=\"2\">",$indent); - ptln(" <input type=\"hidden\" name=\"do\" value=\"admin\" />",$indent); - ptln(" <input type=\"hidden\" name=\"page\" value=\"usermanager\" />",$indent); + ptln(" </tbody>", $indent); + ptln(" <tbody>", $indent); + ptln(" <tr>", $indent); + ptln(" <td colspan=\"2\">", $indent); + ptln(" <input type=\"hidden\" name=\"do\" value=\"admin\" />", $indent); + ptln(" <input type=\"hidden\" name=\"page\" value=\"usermanager\" />", $indent); // save current $user, we need this to access details if the name is changed if ($user) - ptln(" <input type=\"hidden\" name=\"userid_old\" value=\"".hsc($user)."\" />",$indent); + ptln(" <input type=\"hidden\" name=\"userid_old\" value=\"".hsc($user)."\" />", $indent); - $this->_htmlFilterSettings($indent+10); + $this->htmlFilterSettings($indent+10); - ptln(" <button type=\"submit\" name=\"fn[".$cmd."]\">".$this->lang[$cmd]."</button>",$indent); - ptln(" </td>",$indent); - ptln(" </tr>",$indent); - ptln(" </tbody>",$indent); - ptln(" </table>",$indent); + ptln(" <button type=\"submit\" name=\"fn[".$cmd."]\">".$this->lang[$cmd]."</button>", $indent); + ptln(" </td>", $indent); + ptln(" </tr>", $indent); + ptln(" </tbody>", $indent); + ptln(" </table>", $indent); if ($notes) { ptln(" <ul class=\"notes\">"); foreach ($notes as $note) { - ptln(" <li><span class=\"li\">".$note."</li>",$indent); + ptln(" <li><span class=\"li\">".$note."</li>", $indent); } ptln(" </ul>"); } - ptln(" </div>",$indent); - ptln("</form>",$indent); + ptln(" </div>", $indent); + ptln("</form>", $indent); } /** @@ -388,17 +491,18 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { * @param bool $required is this field required? * @param int $indent */ - protected function _htmlInputField($id, $name, $label, $value, $cando, $required, $indent=0) { + protected function htmlInputField($id, $name, $label, $value, $cando, $required, $indent = 0) + { $class = $cando ? '' : ' class="disabled"'; - echo str_pad('',$indent); + echo str_pad('', $indent); - if($name == 'userpass' || $name == 'userpass2'){ + if ($name == 'userpass' || $name == 'userpass2') { $fieldtype = 'password'; $autocomp = 'autocomplete="off"'; - }elseif($name == 'usermail'){ + } elseif ($name == 'usermail') { $fieldtype = 'email'; $autocomp = ''; - }else{ + } else { $fieldtype = 'text'; $autocomp = ''; } @@ -407,13 +511,15 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { echo "<tr $class>"; echo "<td><label for=\"$id\" >$label: </label></td>"; echo "<td>"; - if($cando){ + if ($cando) { $req = ''; - if($required) $req = 'required="required"'; - echo "<input type=\"$fieldtype\" id=\"$id\" name=\"$name\" value=\"$value\" class=\"edit\" $autocomp $req />"; - }else{ + if ($required) $req = 'required="required"'; + echo "<input type=\"$fieldtype\" id=\"$id\" name=\"$name\" + value=\"$value\" class=\"edit\" $autocomp $req />"; + } else { echo "<input type=\"hidden\" name=\"$name\" value=\"$value\" />"; - echo "<input type=\"$fieldtype\" id=\"$id\" name=\"$name\" value=\"$value\" class=\"edit disabled\" disabled=\"disabled\" />"; + echo "<input type=\"$fieldtype\" id=\"$id\" name=\"$name\" + value=\"$value\" class=\"edit disabled\" disabled=\"disabled\" />"; } echo "</td>"; echo "</tr>"; @@ -425,9 +531,10 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { * @param string $key name of search field * @return string html escaped value */ - protected function _htmlFilter($key) { - if (empty($this->_filter)) return ''; - return (isset($this->_filter[$key]) ? hsc($this->_filter[$key]) : ''); + protected function htmlFilter($key) + { + if (empty($this->filter)) return ''; + return (isset($this->filter[$key]) ? hsc($this->filter[$key]) : ''); } /** @@ -435,12 +542,13 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { * * @param int $indent */ - protected function _htmlFilterSettings($indent=0) { + protected function htmlFilterSettings($indent = 0) + { - ptln("<input type=\"hidden\" name=\"start\" value=\"".$this->_start."\" />",$indent); + ptln("<input type=\"hidden\" name=\"start\" value=\"".$this->start."\" />", $indent); - foreach ($this->_filter as $key => $filter) { - ptln("<input type=\"hidden\" name=\"filter[".$key."]\" value=\"".hsc($filter)."\" />",$indent); + foreach ($this->filter as $key => $filter) { + ptln("<input type=\"hidden\" name=\"filter[".$key."]\" value=\"".hsc($filter)."\" />", $indent); } } @@ -449,57 +557,57 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { * * @param int $indent */ - protected function _htmlImportForm($indent=0) { + protected function htmlImportForm($indent = 0) + { global $ID; - $failure_download_link = wl($ID,array('do'=>'admin','page'=>'usermanager','fn[importfails]'=>1)); + $failure_download_link = wl($ID, array('do'=>'admin','page'=>'usermanager','fn[importfails]'=>1)); - ptln('<div class="level2 import_users">',$indent); + ptln('<div class="level2 import_users">', $indent); print $this->locale_xhtml('import'); - ptln(' <form action="'.wl($ID).'" method="post" enctype="multipart/form-data">',$indent); + ptln(' <form action="'.wl($ID).'" method="post" enctype="multipart/form-data">', $indent); formSecurityToken(); - ptln(' <label>'.$this->lang['import_userlistcsv'].'<input type="file" name="import" /></label>',$indent); - ptln(' <button type="submit" name="fn[import]">'.$this->lang['import'].'</button>',$indent); - ptln(' <input type="hidden" name="do" value="admin" />',$indent); - ptln(' <input type="hidden" name="page" value="usermanager" />',$indent); + ptln(' <label>'.$this->lang['import_userlistcsv'].'<input type="file" name="import" /></label>', $indent); + ptln(' <button type="submit" name="fn[import]">'.$this->lang['import'].'</button>', $indent); + ptln(' <input type="hidden" name="do" value="admin" />', $indent); + ptln(' <input type="hidden" name="page" value="usermanager" />', $indent); - $this->_htmlFilterSettings($indent+4); - ptln(' </form>',$indent); + $this->htmlFilterSettings($indent+4); + ptln(' </form>', $indent); ptln('</div>'); // list failures from the previous import - if ($this->_import_failures) { - $digits = strlen(count($this->_import_failures)); - ptln('<div class="level3 import_failures">',$indent); + if ($this->import_failures) { + $digits = strlen(count($this->import_failures)); + ptln('<div class="level3 import_failures">', $indent); ptln(' <h3>'.$this->lang['import_header'].'</h3>'); - ptln(' <table class="import_failures">',$indent); - ptln(' <thead>',$indent); - ptln(' <tr>',$indent); - ptln(' <th class="line">'.$this->lang['line'].'</th>',$indent); - ptln(' <th class="error">'.$this->lang['error'].'</th>',$indent); - ptln(' <th class="userid">'.$this->lang['user_id'].'</th>',$indent); - ptln(' <th class="username">'.$this->lang['user_name'].'</th>',$indent); - ptln(' <th class="usermail">'.$this->lang['user_mail'].'</th>',$indent); - ptln(' <th class="usergroups">'.$this->lang['user_groups'].'</th>',$indent); - ptln(' </tr>',$indent); - ptln(' </thead>',$indent); - ptln(' <tbody>',$indent); - foreach ($this->_import_failures as $line => $failure) { - ptln(' <tr>',$indent); - ptln(' <td class="lineno"> '.sprintf('%0'.$digits.'d',$line).' </td>',$indent); + ptln(' <table class="import_failures">', $indent); + ptln(' <thead>', $indent); + ptln(' <tr>', $indent); + ptln(' <th class="line">'.$this->lang['line'].'</th>', $indent); + ptln(' <th class="error">'.$this->lang['error'].'</th>', $indent); + ptln(' <th class="userid">'.$this->lang['user_id'].'</th>', $indent); + ptln(' <th class="username">'.$this->lang['user_name'].'</th>', $indent); + ptln(' <th class="usermail">'.$this->lang['user_mail'].'</th>', $indent); + ptln(' <th class="usergroups">'.$this->lang['user_groups'].'</th>', $indent); + ptln(' </tr>', $indent); + ptln(' </thead>', $indent); + ptln(' <tbody>', $indent); + foreach ($this->import_failures as $line => $failure) { + ptln(' <tr>', $indent); + ptln(' <td class="lineno"> '.sprintf('%0'.$digits.'d', $line).' </td>', $indent); ptln(' <td class="error">' .$failure['error'].' </td>', $indent); - ptln(' <td class="field userid"> '.hsc($failure['user'][0]).' </td>',$indent); - ptln(' <td class="field username"> '.hsc($failure['user'][2]).' </td>',$indent); - ptln(' <td class="field usermail"> '.hsc($failure['user'][3]).' </td>',$indent); - ptln(' <td class="field usergroups"> '.hsc($failure['user'][4]).' </td>',$indent); - ptln(' </tr>',$indent); + ptln(' <td class="field userid"> '.hsc($failure['user'][0]).' </td>', $indent); + ptln(' <td class="field username"> '.hsc($failure['user'][2]).' </td>', $indent); + ptln(' <td class="field usermail"> '.hsc($failure['user'][3]).' </td>', $indent); + ptln(' <td class="field usergroups"> '.hsc($failure['user'][4]).' </td>', $indent); + ptln(' </tr>', $indent); } - ptln(' </tbody>',$indent); - ptln(' </table>',$indent); + ptln(' </tbody>', $indent); + ptln(' </table>', $indent); ptln(' <p><a href="'.$failure_download_link.'">'.$this->lang['import_downloadfailures'].'</a></p>'); ptln('</div>'); } - } /** @@ -507,17 +615,18 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { * * @return bool whether succesful */ - protected function _addUser(){ + protected function addUser() + { global $INPUT; if (!checkSecurityToken()) return false; - if (!$this->_auth->canDo('addUser')) return false; + if (!$this->auth->canDo('addUser')) return false; - list($user,$pass,$name,$mail,$grps,$passconfirm) = $this->_retrieveUser(); + list($user,$pass,$name,$mail,$grps,$passconfirm) = $this->retrieveUser(); if (empty($user)) return false; - if ($this->_auth->canDo('modPass')){ - if (empty($pass)){ - if($INPUT->has('usernotify')){ + if ($this->auth->canDo('modPass')) { + if (empty($pass)) { + if ($INPUT->has('usernotify')) { $pass = auth_pwgen($user); } else { msg($this->lang['add_fail'], -1); @@ -525,54 +634,53 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { return false; } } else { - if (!$this->_verifyPassword($pass,$passconfirm)) { + if (!$this->verifyPassword($pass, $passconfirm)) { msg($this->lang['add_fail'], -1); msg($this->lang['addUser_error_pass_not_identical'], -1); return false; } } } else { - if (!empty($pass)){ + if (!empty($pass)) { msg($this->lang['add_fail'], -1); msg($this->lang['addUser_error_modPass_disabled'], -1); return false; } } - if ($this->_auth->canDo('modName')){ - if (empty($name)){ + if ($this->auth->canDo('modName')) { + if (empty($name)) { msg($this->lang['add_fail'], -1); msg($this->lang['addUser_error_name_missing'], -1); return false; } } else { - if (!empty($name)){ + if (!empty($name)) { msg($this->lang['add_fail'], -1); msg($this->lang['addUser_error_modName_disabled'], -1); return false; } } - if ($this->_auth->canDo('modMail')){ - if (empty($mail)){ + if ($this->auth->canDo('modMail')) { + if (empty($mail)) { msg($this->lang['add_fail'], -1); msg($this->lang['addUser_error_mail_missing'], -1); return false; } } else { - if (!empty($mail)){ + if (!empty($mail)) { msg($this->lang['add_fail'], -1); msg($this->lang['addUser_error_modMail_disabled'], -1); return false; } } - if ($ok = $this->_auth->triggerUserMod('create', array($user,$pass,$name,$mail,$grps))) { - + if ($ok = $this->auth->triggerUserMod('create', array($user, $pass, $name, $mail, $grps))) { msg($this->lang['add_ok'], 1); if ($INPUT->has('usernotify') && $pass) { - $this->_notifyUser($user,$pass); + $this->notifyUser($user, $pass); } } else { msg($this->lang['add_fail'], -1); @@ -587,33 +695,34 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { * * @return bool whether succesful */ - protected function _deleteUser(){ + protected function deleteUser() + { global $conf, $INPUT; if (!checkSecurityToken()) return false; - if (!$this->_auth->canDo('delUser')) return false; + if (!$this->auth->canDo('delUser')) return false; $selected = $INPUT->arr('delete'); if (empty($selected)) return false; $selected = array_keys($selected); - if(in_array($_SERVER['REMOTE_USER'], $selected)) { + if (in_array($_SERVER['REMOTE_USER'], $selected)) { msg("You can't delete yourself!", -1); return false; } - $count = $this->_auth->triggerUserMod('delete', array($selected)); + $count = $this->auth->triggerUserMod('delete', array($selected)); if ($count == count($selected)) { $text = str_replace('%d', $count, $this->lang['delete_ok']); msg("$text.", 1); } else { $part1 = str_replace('%d', $count, $this->lang['delete_ok']); $part2 = str_replace('%d', (count($selected)-$count), $this->lang['delete_fail']); - msg("$part1, $part2",-1); + msg("$part1, $part2", -1); } // invalidate all sessions - io_saveFile($conf['cachedir'].'/sessionpurge',time()); + io_saveFile($conf['cachedir'].'/sessionpurge', time()); return true; } @@ -624,20 +733,21 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { * @param string $param id of the user * @return bool whether succesful */ - protected function _editUser($param) { + protected function editUser($param) + { if (!checkSecurityToken()) return false; - if (!$this->_auth->canDo('UserMod')) return false; - $user = $this->_auth->cleanUser(preg_replace('/.*[:\/]/','',$param)); - $userdata = $this->_auth->getUserData($user); + if (!$this->auth->canDo('UserMod')) return false; + $user = $this->auth->cleanUser(preg_replace('/.*[:\/]/', '', $param)); + $userdata = $this->auth->getUserData($user); // no user found? if (!$userdata) { - msg($this->lang['edit_usermissing'],-1); + msg($this->lang['edit_usermissing'], -1); return false; } - $this->_edit_user = $user; - $this->_edit_userdata = $userdata; + $this->edit_user = $user; + $this->edit_userdata = $userdata; return true; } @@ -647,39 +757,39 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { * * @return bool whether succesful */ - protected function _modifyUser(){ + protected function modifyUser() + { global $conf, $INPUT; if (!checkSecurityToken()) return false; - if (!$this->_auth->canDo('UserMod')) return false; + if (!$this->auth->canDo('UserMod')) return false; // get currently valid user data - $olduser = $this->_auth->cleanUser(preg_replace('/.*[:\/]/','',$INPUT->str('userid_old'))); - $oldinfo = $this->_auth->getUserData($olduser); + $olduser = $this->auth->cleanUser(preg_replace('/.*[:\/]/', '', $INPUT->str('userid_old'))); + $oldinfo = $this->auth->getUserData($olduser); // get new user data subject to change - list($newuser,$newpass,$newname,$newmail,$newgrps,$passconfirm) = $this->_retrieveUser(); + list($newuser,$newpass,$newname,$newmail,$newgrps,$passconfirm) = $this->retrieveUser(); if (empty($newuser)) return false; $changes = array(); if ($newuser != $olduser) { - - if (!$this->_auth->canDo('modLogin')) { // sanity check, shouldn't be possible - msg($this->lang['update_fail'],-1); + if (!$this->auth->canDo('modLogin')) { // sanity check, shouldn't be possible + msg($this->lang['update_fail'], -1); return false; } // check if $newuser already exists - if ($this->_auth->getUserData($newuser)) { - msg(sprintf($this->lang['update_exists'],$newuser),-1); + if ($this->auth->getUserData($newuser)) { + msg(sprintf($this->lang['update_exists'], $newuser), -1); $re_edit = true; } else { $changes['user'] = $newuser; } } - if ($this->_auth->canDo('modPass')) { + if ($this->auth->canDo('modPass')) { if ($newpass || $passconfirm) { - if ($this->_verifyPassword($newpass,$passconfirm)) { + if ($this->verifyPassword($newpass, $passconfirm)) { $changes['pass'] = $newpass; } else { return false; @@ -692,33 +802,32 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { } } - if (!empty($newname) && $this->_auth->canDo('modName') && $newname != $oldinfo['name']) { + if (!empty($newname) && $this->auth->canDo('modName') && $newname != $oldinfo['name']) { $changes['name'] = $newname; } - if (!empty($newmail) && $this->_auth->canDo('modMail') && $newmail != $oldinfo['mail']) { + if (!empty($newmail) && $this->auth->canDo('modMail') && $newmail != $oldinfo['mail']) { $changes['mail'] = $newmail; } - if (!empty($newgrps) && $this->_auth->canDo('modGroups') && $newgrps != $oldinfo['grps']) { + if (!empty($newgrps) && $this->auth->canDo('modGroups') && $newgrps != $oldinfo['grps']) { $changes['grps'] = $newgrps; } - if ($ok = $this->_auth->triggerUserMod('modify', array($olduser, $changes))) { - msg($this->lang['update_ok'],1); + if ($ok = $this->auth->triggerUserMod('modify', array($olduser, $changes))) { + msg($this->lang['update_ok'], 1); if ($INPUT->has('usernotify') && !empty($changes['pass'])) { $notify = empty($changes['user']) ? $olduser : $newuser; - $this->_notifyUser($notify,$changes['pass']); + $this->notifyUser($notify, $changes['pass']); } // invalidate all sessions - io_saveFile($conf['cachedir'].'/sessionpurge',time()); - + io_saveFile($conf['cachedir'].'/sessionpurge', time()); } else { - msg($this->lang['update_fail'],-1); + msg($this->lang['update_fail'], -1); } if (!empty($re_edit)) { - $this->_editUser($olduser); + $this->editUser($olduser); } return $ok; @@ -732,9 +841,10 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { * @param bool $status_alert whether status alert should be shown * @return bool whether succesful */ - protected function _notifyUser($user, $password, $status_alert=true) { + protected function notifyUser($user, $password, $status_alert = true) + { - if ($sent = auth_sendPassword($user,$password)) { + if ($sent = auth_sendPassword($user, $password)) { if ($status_alert) { msg($this->lang['notify_ok'], 1); } @@ -755,7 +865,8 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { * @param string $confirm repeated password for confirmation * @return bool true if meets requirements, false otherwise */ - protected function _verifyPassword($password, $confirm) { + protected function verifyPassword($password, $confirm) + { global $lang; if (empty($password) && empty($confirm)) { @@ -779,7 +890,8 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { * @param bool $clean whether the cleanUser method of the authentication backend is applied * @return array (user, password, full name, email, array(groups)) */ - protected function _retrieveUser($clean=true) { + protected function retrieveUser($clean = true) + { /** @var DokuWiki_Auth_Plugin $auth */ global $auth; global $INPUT; @@ -789,14 +901,14 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { $user[1] = $INPUT->str('userpass'); $user[2] = $INPUT->str('username'); $user[3] = $INPUT->str('usermail'); - $user[4] = explode(',',$INPUT->str('usergroups')); + $user[4] = explode(',', $INPUT->str('usergroups')); $user[5] = $INPUT->str('userpass2'); // repeated password for confirmation - $user[4] = array_map('trim',$user[4]); - if($clean) $user[4] = array_map(array($auth,'cleanGroup'),$user[4]); + $user[4] = array_map('trim', $user[4]); + if ($clean) $user[4] = array_map(array($auth,'cleanGroup'), $user[4]); $user[4] = array_filter($user[4]); $user[4] = array_unique($user[4]); - if(!count($user[4])) $user[4] = null; + if (!count($user[4])) $user[4] = null; return $user; } @@ -806,17 +918,18 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { * * @param string $op 'new' or 'clear' */ - protected function _setFilter($op) { + protected function setFilter($op) + { - $this->_filter = array(); + $this->filter = array(); if ($op == 'new') { - list($user,/* $pass */,$name,$mail,$grps) = $this->_retrieveUser(false); + list($user,/* $pass */,$name,$mail,$grps) = $this->retrieveUser(false); - if (!empty($user)) $this->_filter['user'] = $user; - if (!empty($name)) $this->_filter['name'] = $name; - if (!empty($mail)) $this->_filter['mail'] = $mail; - if (!empty($grps)) $this->_filter['grps'] = join('|',$grps); + if (!empty($user)) $this->filter['user'] = $user; + if (!empty($name)) $this->filter['name'] = $name; + if (!empty($mail)) $this->filter['mail'] = $mail; + if (!empty($grps)) $this->filter['grps'] = join('|', $grps); } } @@ -825,7 +938,8 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { * * @return array */ - protected function _retrieveFilter() { + protected function retrieveFilter() + { global $INPUT; $t_filter = $INPUT->arr('filter'); @@ -844,14 +958,15 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { /** * Validate and improve the pagination values */ - protected function _validatePagination() { + protected function validatePagination() + { - if ($this->_start >= $this->_user_total) { - $this->_start = $this->_user_total - $this->_pagesize; + if ($this->start >= $this->users_total) { + $this->start = $this->users_total - $this->pagesize; } - if ($this->_start < 0) $this->_start = 0; + if ($this->start < 0) $this->start = 0; - $this->_last = min($this->_user_total, $this->_start + $this->_pagesize); + $this->last = min($this->users_total, $this->start + $this->pagesize); } /** @@ -859,21 +974,23 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { * * @return array with enable/disable attributes */ - protected function _pagination() { + protected function pagination() + { $disabled = 'disabled="disabled"'; $buttons = array(); - $buttons['start'] = $buttons['prev'] = ($this->_start == 0) ? $disabled : ''; + $buttons['start'] = $buttons['prev'] = ($this->start == 0) ? $disabled : ''; - if ($this->_user_total == -1) { + if ($this->users_total == -1) { $buttons['last'] = $disabled; $buttons['next'] = ''; } else { - $buttons['last'] = $buttons['next'] = (($this->_start + $this->_pagesize) >= $this->_user_total) ? $disabled : ''; + $buttons['last'] = $buttons['next'] = + (($this->start + $this->pagesize) >= $this->users_total) ? $disabled : ''; } - if ($this->_lastdisabled) { + if ($this->lastdisabled) { $buttons['last'] = $disabled; } @@ -883,9 +1000,10 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { /** * Export a list of users in csv format using the current filter criteria */ - protected function _export() { + protected function exportCSV() + { // list of users for export - based on current filter criteria - $user_list = $this->_auth->retrieveUsers(0, 0, $this->_filter); + $user_list = $this->auth->retrieveUsers(0, 0, $this->filter); $column_headings = array( $this->lang["user_id"], $this->lang["user_name"], @@ -902,14 +1020,16 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { # header('Content-type: text/plain;charset=utf-8'); // output the csv - $fd = fopen('php://output','w'); + $fd = fopen('php://output', 'w'); fputcsv($fd, $column_headings); foreach ($user_list as $user => $info) { - $line = array($user, $info['name'], $info['mail'], join(',',$info['grps'])); + $line = array($user, $info['name'], $info['mail'], join(',', $info['grps'])); fputcsv($fd, $line); } fclose($fd); - if (defined('DOKU_UNITTEST')){ return; } + if (defined('DOKU_UNITTEST')) { + return; + } die; } @@ -921,24 +1041,27 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { * * @return bool whether successful */ - protected function _import() { + protected function importCSV() + { // check we are allowed to add users if (!checkSecurityToken()) return false; - if (!$this->_auth->canDo('addUser')) return false; + if (!$this->auth->canDo('addUser')) return false; // check file uploaded ok. - if (empty($_FILES['import']['size']) || !empty($_FILES['import']['error']) && $this->_isUploadedFile($_FILES['import']['tmp_name'])) { - msg($this->lang['import_error_upload'],-1); + if (empty($_FILES['import']['size']) || + !empty($_FILES['import']['error']) && $this->isUploadedFile($_FILES['import']['tmp_name']) + ) { + msg($this->lang['import_error_upload'], -1); return false; } // retrieve users from the file - $this->_import_failures = array(); + $this->import_failures = array(); $import_success_count = 0; $import_fail_count = 0; $line = 0; - $fd = fopen($_FILES['import']['tmp_name'],'r'); + $fd = fopen($_FILES['import']['tmp_name'], 'r'); if ($fd) { - while($csv = fgets($fd)){ + while ($csv = fgets($fd)) { if (!utf8_check($csv)) { $csv = utf8_encode($csv); } @@ -951,35 +1074,42 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { if (count($raw) < 4) { // need at least four fields $import_fail_count++; $error = sprintf($this->lang['import_error_fields'], count($raw)); - $this->_import_failures[$line] = array('error' => $error, 'user' => $raw, 'orig' => $csv); + $this->import_failures[$line] = array('error' => $error, 'user' => $raw, 'orig' => $csv); continue; } - array_splice($raw,1,0,auth_pwgen()); // splice in a generated password - $clean = $this->_cleanImportUser($raw, $error); - if ($clean && $this->_addImportUser($clean, $error)) { - $sent = $this->_notifyUser($clean[0],$clean[1],false); - if (!$sent){ - msg(sprintf($this->lang['import_notify_fail'],$clean[0],$clean[3]),-1); + array_splice($raw, 1, 0, auth_pwgen()); // splice in a generated password + $clean = $this->cleanImportUser($raw, $error); + if ($clean && $this->importUser($clean, $error)) { + $sent = $this->notifyUser($clean[0], $clean[1], false); + if (!$sent) { + msg(sprintf($this->lang['import_notify_fail'], $clean[0], $clean[3]), -1); } $import_success_count++; } else { $import_fail_count++; array_splice($raw, 1, 1); // remove the spliced in password - $this->_import_failures[$line] = array('error' => $error, 'user' => $raw, 'orig' => $csv); + $this->import_failures[$line] = array('error' => $error, 'user' => $raw, 'orig' => $csv); } } - msg(sprintf($this->lang['import_success_count'], ($import_success_count+$import_fail_count), $import_success_count),($import_success_count ? 1 : -1)); + msg( + sprintf( + $this->lang['import_success_count'], + ($import_success_count + $import_fail_count), + $import_success_count + ), + ($import_success_count ? 1 : -1) + ); if ($import_fail_count) { - msg(sprintf($this->lang['import_failure_count'], $import_fail_count),-1); + msg(sprintf($this->lang['import_failure_count'], $import_fail_count), -1); } } else { - msg($this->lang['import_error_readfail'],-1); + msg($this->lang['import_error_readfail'], -1); } // save import failures into the session if (!headers_sent()) { session_start(); - $_SESSION['import_failures'] = $this->_import_failures; + $_SESSION['import_failures'] = $this->import_failures; session_write_close(); } return true; @@ -992,17 +1122,18 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { * @param string $error * @return array|false cleaned data or false */ - protected function _cleanImportUser($candidate, & $error){ + protected function cleanImportUser($candidate, & $error) + { global $INPUT; - // kludgy .... + // FIXME kludgy .... $INPUT->set('userid', $candidate[0]); $INPUT->set('userpass', $candidate[1]); $INPUT->set('username', $candidate[2]); $INPUT->set('usermail', $candidate[3]); $INPUT->set('usergroups', $candidate[4]); - $cleaned = $this->_retrieveUser(); + $cleaned = $this->retrieveUser(); list($user,/* $pass */,$name,$mail,/* $grps */) = $cleaned; if (empty($user)) { $error = $this->lang['import_error_baduserid']; @@ -1011,12 +1142,12 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { // no need to check password, handled elsewhere - if (!($this->_auth->canDo('modName') xor empty($name))){ + if (!($this->auth->canDo('modName') xor empty($name))) { $error = $this->lang['import_error_badname']; return false; } - if ($this->_auth->canDo('modMail')) { + if ($this->auth->canDo('modMail')) { if (empty($mail) || !mail_isvalid($mail)) { $error = $this->lang['import_error_badmail']; return false; @@ -1040,8 +1171,9 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { * @param string &$error reference catched error message * @return bool whether successful */ - protected function _addImportUser($user, & $error){ - if (!$this->_auth->triggerUserMod('create', $user)) { + protected function importUser($user, &$error) + { + if (!$this->auth->triggerUserMod('create', $user)) { $error = $this->lang['import_error_create']; return false; } @@ -1052,7 +1184,8 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { /** * Downloads failures as csv file */ - protected function _downloadImportFailures(){ + protected function downloadImportFailures() + { // ============================================================================================== // GENERATE OUTPUT @@ -1063,8 +1196,8 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { # header('Content-type: text/plain;charset=utf-8'); // output the csv - $fd = fopen('php://output','w'); - foreach ($this->_import_failures as $fail) { + $fd = fopen('php://output', 'w'); + foreach ($this->import_failures as $fail) { fputs($fd, $fail['orig']); } fclose($fd); @@ -1077,7 +1210,8 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { * @param string $file filename * @return bool */ - protected function _isUploadedFile($file) { + protected function isUploadedFile($file) + { return is_uploaded_file($file); } } diff --git a/lib/tpl/dokuwiki/tpl_footer.php b/lib/tpl/dokuwiki/tpl_footer.php index 34e8b90f6..c7a04e155 100644 --- a/lib/tpl/dokuwiki/tpl_footer.php +++ b/lib/tpl/dokuwiki/tpl_footer.php @@ -25,7 +25,8 @@ if (!defined('DOKU_INC')) die(); <a href="//jigsaw.w3.org/css-validator/check/referer?profile=css3" title="Valid CSS" <?php echo $target?>><img src="<?php echo tpl_basedir(); ?>images/button-css.png" width="80" height="15" alt="Valid CSS" /></a> <a href="https://dokuwiki.org/" title="Driven by DokuWiki" <?php echo $target?>><img - src="<?php echo tpl_basedir(); ?>images/button-dw.png" width="80" height="15" alt="Driven by DokuWiki" /></a> + src="<?php echo tpl_basedir(); ?>images/button-dw.png" width="80" height="15" + alt="Driven by DokuWiki" /></a> </div> </div></div><!-- /footer --> |