coding style updates

This commit is contained in:
Andreas Gohr 2012-03-16 12:09:30 +01:00
parent d086370fa9
commit 63703ba5bd
24 changed files with 1229 additions and 1220 deletions

View file

@ -29,7 +29,7 @@ class _DiffOp {
class _DiffOp_Copy extends _DiffOp {
var $type = 'copy';
function __construct($orig, $closing = false) {
if (!is_array($closing))
$closing = $orig;
@ -44,7 +44,7 @@ class _DiffOp_Copy extends _DiffOp {
class _DiffOp_Delete extends _DiffOp {
var $type = 'delete';
function __construct($lines) {
$this->orig = $lines;
$this->closing = false;
@ -57,7 +57,7 @@ class _DiffOp_Delete extends _DiffOp {
class _DiffOp_Add extends _DiffOp {
var $type = 'add';
function __construct($lines) {
$this->closing = $lines;
$this->orig = false;
@ -70,7 +70,7 @@ class _DiffOp_Add extends _DiffOp {
class _DiffOp_Change extends _DiffOp {
var $type = 'change';
function __construct($orig, $closing) {
$this->orig = $orig;
$this->closing = $closing;
@ -924,7 +924,7 @@ class WordLevelDiff extends MappedDiff {
}
class InlineWordLevelDiff extends MappedDiff {
function __construct($orig_lines, $closing_lines) {
list ($orig_words, $orig_stripped) = $this->_split($orig_lines);
list ($closing_words, $closing_stripped) = $this->_split($closing_lines);

View file

@ -22,7 +22,7 @@ class DokuHTTPClient extends HTTPClient {
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function DokuHTTPClient(){
function __construct(){
global $conf;
// call parent constructor
@ -121,7 +121,7 @@ class HTTPClient {
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function HTTPClient(){
function __construct(){
$this->agent = 'Mozilla/4.0 (compatible; DokuWiki HTTP Client; '.PHP_OS.')';
$this->timeout = 15;
$this->cookies = array();

View file

@ -88,7 +88,9 @@ class PassHash {
public function gen_salt($len=32){
$salt = '';
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
for($i=0;$i<$len;$i++) $salt .= $chars[mt_rand(0,61)];
for($i=0; $i<$len; $i++){
$salt .= $chars[mt_rand(0,61)];
}
return $salt;
}

View file

@ -1,17 +1,17 @@
<?php
/**
* Class to safely store UTF-8 in a Filename
* Class to safely store UTF-8 in a Filename
*
* Encodes a utf8 string using only the following characters 0-9a-z_.-%
* characters 0-9a-z in the original string are preserved, "plain".
* all other characters are represented in a substring that starts
* with '%' are "converted".
* The transition from converted substrings to plain characters is
* marked with a '.'
* Encodes a utf8 string using only the following characters 0-9a-z_.-%
* characters 0-9a-z in the original string are preserved, "plain".
* all other characters are represented in a substring that starts
* with '%' are "converted".
* The transition from converted substrings to plain characters is
* marked with a '.'
*
* @author Christopher Smith
* @date 2010-04-02
* @author Christopher Smith <chris@jalakai.co.uk>
* @date 2010-04-02
*/
class SafeFN {
@ -133,14 +133,15 @@ class SafeFN {
$converted = false;
foreach ($split as $sub) {
$len = strlen($sub);
if ($sub[0] != self::$pre_indicator) {
// plain (unconverted) characters, optionally starting with a post_indicator
// set initial value to skip any post_indicator
for ($i=($converted?1:0); $i < strlen($sub); $i++) {
for ($i=($converted?1:0); $i < $len; $i++) {
$unicode[] = ord($sub[$i]);
}
$converted = false;
} else if (strlen($sub)==1) {
} else if ($len==1) {
// a pre_indicator character in the real data
$unicode[] = ord($sub);
$converted = true;

View file

@ -10,7 +10,7 @@ if(!defined('DOKU_INC')) die('meh.');
/**
* A class for building sitemaps and pinging search engines with the sitemap URL.
*
*
* @author Michael Hamann
*/
class Sitemapper {
@ -55,7 +55,7 @@ class Sitemapper {
if(isHiddenPage($id)) continue;
if(auth_aclcheck($id,'','') < AUTH_READ) continue;
$item = SitemapItem::createFromID($id);
if ($item !== NULL)
if ($item !== null)
$items[] = $item;
}
@ -72,7 +72,7 @@ class Sitemapper {
/**
* Builds the sitemap XML string from the given array auf SitemapItems.
*
*
* @param $items array The SitemapItems that shall be included in the sitemap.
* @return string The sitemap XML.
* @author Michael Hamann
@ -92,7 +92,7 @@ class Sitemapper {
/**
* Helper function for getting the path to the sitemap file.
*
*
* @return The path to the sitemap file.
* @author Michael Hamann
*/
@ -108,9 +108,9 @@ class Sitemapper {
}
/**
* Pings search engines with the sitemap url. Plugins can add or remove
* Pings search engines with the sitemap url. Plugins can add or remove
* urls to ping using the SITEMAP_PING event.
*
*
* @author Michael Hamann
*/
public static function pingSearchEngines() {
@ -145,7 +145,7 @@ class Sitemapper {
/**
* An item of a sitemap.
*
*
* @author Michael Hamann
*/
class SitemapItem {
@ -156,7 +156,7 @@ class SitemapItem {
/**
* Create a new item.
*
*
* @param $url string The url of the item
* @param $lastmod int Timestamp of the last modification
* @param $changefreq string How frequently the item is likely to change. Valid values: always, hourly, daily, weekly, monthly, yearly, never.
@ -171,7 +171,7 @@ class SitemapItem {
/**
* Helper function for creating an item for a wikipage id.
*
*
* @param $id string A wikipage id.
* @param $changefreq string How frequently the item is likely to change. Valid values: always, hourly, daily, weekly, monthly, yearly, never.
* @param $priority float|string The priority of the item relative to other URLs on your site. Valid values range from 0.0 to 1.0.
@ -180,22 +180,22 @@ class SitemapItem {
public static function createFromID($id, $changefreq = null, $priority = null) {
$id = trim($id);
$date = @filemtime(wikiFN($id));
if(!$date) return NULL;
if(!$date) return null;
return new SitemapItem(wl($id, '', true), $date, $changefreq, $priority);
}
/**
* Get the XML representation of the sitemap item.
*
*
* @return The XML representation.
*/
public function toXML() {
$result = ' <url>'.NL
.' <loc>'.hsc($this->url).'</loc>'.NL
.' <lastmod>'.date_iso8601($this->lastmod).'</lastmod>'.NL;
if ($this->changefreq !== NULL)
if ($this->changefreq !== null)
$result .= ' <changefreq>'.hsc($this->changefreq).'</changefreq>'.NL;
if ($this->priority !== NULL)
if ($this->priority !== null)
$result .= ' <priority>'.hsc($this->priority).'</priority>'.NL;
$result .= ' </url>'.NL;
return $result;

View file

@ -108,7 +108,7 @@ class TarLib {
* represent the GZIP or BZIP compression level. 1 produce fast compression,
* and 9 produce smaller files. See the RFC 1952 for more infos.
*/
function tarlib($p_filen = TarLib::ARCHIVE_DYNAMIC , $p_comptype = TarLib::COMPRESS_AUTO, $p_complevel = 9) {
function __construct($p_filen = TarLib::ARCHIVE_DYNAMIC , $p_comptype = TarLib::COMPRESS_AUTO, $p_complevel = 9) {
$this->_initerror = 0;
$this->_nomf = $p_filen;
$flag=0;
@ -127,7 +127,7 @@ class TarLib {
}
switch($p_comptype) {
case TarLib::COMPRESS_GZIP:
case TarLib::COMPRESS_GZIP:
if(!extension_loaded('zlib')) $this->_initerror = -1;
$this->_comptype = TarLib::COMPRESS_GZIP;
break;

View file

@ -677,7 +677,7 @@ function auth_sendPassword($user,$password){
if(empty($conf['mailprefix'])) {
$subject = $lang['regpwmail'];
} else {
} else {
$subject = '['.$conf['mailprefix'].'] '.$lang['regpwmail'];
}
@ -883,7 +883,6 @@ function act_resendpwd(){
return false;
}
if(!$conf['autopasswd']){ // we let the user choose a password
// password given correctly?
if(!isset($_REQUEST['pass']) || $_REQUEST['pass'] == '') return false;
@ -950,10 +949,10 @@ function act_resendpwd(){
if(empty($conf['mailprefix'])) {
$subject = $lang['regpwmail'];
} else {
} else {
$subject = '['.$conf['mailprefix'].'] '.$lang['regpwmail'];
}
if(mail_send($userinfo['name'].' <'.$userinfo['mail'].'>',
$subject,
$text,

View file

@ -33,10 +33,10 @@
* // add a list of comma separated ldap contact fields.
* $conf['auth']['ad']['additional'] = 'field1,field2';
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author James Van Lommel <jamesvl@gmail.com>
* @link http://www.nosq.com/blog/2005/08/ldap-activedirectory-and-dokuwiki/
* @author Andreas Gohr <andi@splitbrain.org>
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author James Van Lommel <jamesvl@gmail.com>
* @link http://www.nosq.com/blog/2005/08/ldap-activedirectory-and-dokuwiki/
* @author Andreas Gohr <andi@splitbrain.org>
*/
require_once(DOKU_INC.'inc/adLDAP.php');
@ -51,11 +51,10 @@ class auth_ad extends auth_basic {
/**
* Constructor
*/
function auth_ad() {
function __construct() {
global $conf;
$this->cnf = $conf['auth']['ad'];
// additional information fields
if (isset($this->cnf['additional'])) {
$this->cnf['additional'] = str_replace(' ', '', $this->cnf['additional']);
@ -72,21 +71,21 @@ class auth_ad extends auth_basic {
// Prepare SSO
if($_SERVER['REMOTE_USER'] && $this->cnf['sso']){
// remove possible NTLM domain
list($dom,$usr) = explode('\\',$_SERVER['REMOTE_USER'],2);
if(!$usr) $usr = $dom;
// remove possible NTLM domain
list($dom,$usr) = explode('\\',$_SERVER['REMOTE_USER'],2);
if(!$usr) $usr = $dom;
// remove possible Kerberos domain
list($usr,$dom) = explode('@',$usr);
// remove possible Kerberos domain
list($usr,$dom) = explode('@',$usr);
$dom = strtolower($dom);
$_SERVER['REMOTE_USER'] = $usr;
$dom = strtolower($dom);
$_SERVER['REMOTE_USER'] = $usr;
// we need to simulate a login
if(empty($_COOKIE[DOKU_COOKIE])){
$_REQUEST['u'] = $_SERVER['REMOTE_USER'];
$_REQUEST['p'] = 'sso_only';
}
// we need to simulate a login
if(empty($_COOKIE[DOKU_COOKIE])){
$_REQUEST['u'] = $_SERVER['REMOTE_USER'];
$_REQUEST['p'] = 'sso_only';
}
}
// prepare adLDAP standard configuration
@ -147,7 +146,7 @@ class auth_ad extends auth_basic {
*
* @author James Van Lommel <james@nosq.com>
*/
function getUserData($user){
function getUserData($user){
global $conf;
global $lang;
global $ID;
@ -297,7 +296,7 @@ class auth_ad extends auth_basic {
* @param $user nick of the user to be changed
* @param $changes array of field/value pairs to be changed
* @return bool
*/
*/
function modifyUser($user, $changes) {
$return = true;
@ -380,7 +379,6 @@ class auth_ad extends auth_basic {
function _constructPattern($filter) {
$this->_pattern = array();
foreach ($filter as $item => $pattern) {
// $this->_pattern[$item] = '/'.preg_quote($pattern,"/").'/i'; // don't allow regex characters
$this->_pattern[$item] = '/'.str_replace('/','\/',$pattern).'/i'; // allow regex characters
}
}

View file

@ -9,395 +9,393 @@
*/
class auth_basic {
var $success = true;
var $success = true;
/**
* Posible things an auth backend module may be able to
* do. The things a backend can do need to be set to true
* in the constructor.
*/
var $cando = array (
'addUser' => false, // can Users be created?
'delUser' => false, // can Users be deleted?
'modLogin' => false, // can login names be changed?
'modPass' => false, // can passwords be changed?
'modName' => false, // can real names be changed?
'modMail' => false, // can emails be changed?
'modGroups' => false, // can groups be changed?
'getUsers' => false, // can a (filtered) list of users be retrieved?
'getUserCount'=> false, // can the number of users be retrieved?
'getGroups' => false, // can a list of available groups be retrieved?
'external' => false, // does the module do external auth checking?
'logout' => true, // can the user logout again? (eg. not possible with HTTP auth)
);
/**
* Constructor.
*
* Carry out sanity checks to ensure the object is
* able to operate. Set capabilities in $this->cando
* array here
*
* Set $this->success to false if checks fail
*
* @author Christopher Smith <chris@jalakai.co.uk>
*/
function auth_basic() {
// the base class constructor does nothing, derived class
// constructors do the real work
}
/**
* Capability check. [ DO NOT OVERRIDE ]
*
* Checks the capabilities set in the $this->cando array and
* some pseudo capabilities (shortcutting access to multiple
* ones)
*
* ususal capabilities start with lowercase letter
* shortcut capabilities start with uppercase letter
*
* @author Andreas Gohr <andi@splitbrain.org>
* @return bool
*/
function canDo($cap) {
switch($cap){
case 'Profile':
// can at least one of the user's properties be changed?
return ( $this->cando['modPass'] ||
$this->cando['modName'] ||
$this->cando['modMail'] );
break;
case 'UserMod':
// can at least anything be changed?
return ( $this->cando['modPass'] ||
$this->cando['modName'] ||
$this->cando['modMail'] ||
$this->cando['modLogin'] ||
$this->cando['modGroups'] ||
$this->cando['modMail'] );
break;
default:
// print a helping message for developers
if(!isset($this->cando[$cap])){
msg("Check for unknown capability '$cap' - Do you use an outdated Plugin?",-1);
}
return $this->cando[$cap];
}
}
/**
* Trigger the AUTH_USERDATA_CHANGE event and call the modification function. [ DO NOT OVERRIDE ]
*
* You should use this function instead of calling createUser, modifyUser or
* deleteUsers directly. The event handlers can prevent the modification, for
* example for enforcing a user name schema.
*
* @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
* @return mixed Result from the modification function or false if an event handler has canceled the action
*/
function triggerUserMod($type, $params)
{
$validTypes = array(
'create' => 'createUser',
'modify' => 'modifyUser',
'delete' => 'deleteUsers'
/**
* Posible things an auth backend module may be able to
* do. The things a backend can do need to be set to true
* in the constructor.
*/
var $cando = array (
'addUser' => false, // can Users be created?
'delUser' => false, // can Users be deleted?
'modLogin' => false, // can login names be changed?
'modPass' => false, // can passwords be changed?
'modName' => false, // can real names be changed?
'modMail' => false, // can emails be changed?
'modGroups' => false, // can groups be changed?
'getUsers' => false, // can a (filtered) list of users be retrieved?
'getUserCount'=> false, // can the number of users be retrieved?
'getGroups' => false, // can a list of available groups be retrieved?
'external' => false, // does the module do external auth checking?
'logout' => true, // can the user logout again? (eg. not possible with HTTP auth)
);
if(empty($validTypes[$type]))
return false;
$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]), $params);
$evt->data['modification_result'] = $result;
/**
* Constructor.
*
* Carry out sanity checks to ensure the object is
* able to operate. Set capabilities in $this->cando
* array here
*
* Set $this->success to false if checks fail
*
* @author Christopher Smith <chris@jalakai.co.uk>
*/
function __construct() {
// the base class constructor does nothing, derived class
// constructors do the real work
}
$evt->advise_after();
unset($evt);
return $result;
}
/**
* Log off the current user [ OPTIONAL ]
*
* Is run in addition to the ususal logoff method. Should
* only be needed when trustExternal is implemented.
*
* @see auth_logoff()
* @author Andreas Gohr <andi@splitbrain.org>
*/
function logOff(){
}
/**
* Capability check. [ DO NOT OVERRIDE ]
*
* Checks the capabilities set in the $this->cando array and
* some pseudo capabilities (shortcutting access to multiple
* ones)
*
* ususal capabilities start with lowercase letter
* shortcut capabilities start with uppercase letter
*
* @author Andreas Gohr <andi@splitbrain.org>
* @return bool
*/
function canDo($cap) {
switch($cap){
case 'Profile':
// can at least one of the user's properties be changed?
return ( $this->cando['modPass'] ||
$this->cando['modName'] ||
$this->cando['modMail'] );
break;
case 'UserMod':
// can at least anything be changed?
return ( $this->cando['modPass'] ||
$this->cando['modName'] ||
$this->cando['modMail'] ||
$this->cando['modLogin'] ||
$this->cando['modGroups'] ||
$this->cando['modMail'] );
break;
default:
// print a helping message for developers
if(!isset($this->cando[$cap])){
msg("Check for unknown capability '$cap' - Do you use an outdated Plugin?",-1);
}
return $this->cando[$cap];
}
}
/**
* Do all authentication [ OPTIONAL ]
*
* Set $this->cando['external'] = true when implemented
*
* If this function is implemented it will be used to
* authenticate a user - all other DokuWiki internals
* will not be used for authenticating, thus
* implementing the checkPass() function is not needed
* anymore.
*
* The function can be used to authenticate against third
* party cookies or Apache auth mechanisms and replaces
* the auth_login() function
*
* The function will be called with or without a set
* username. If the Username is given it was called
* from the login form and the given credentials might
* need to be checked. If no username was given it
* the function needs to check if the user is logged in
* by other means (cookie, environment).
*
* The function needs to set some globals needed by
* DokuWiki like auth_login() does.
*
* @see auth_login()
* @author Andreas Gohr <andi@splitbrain.org>
*
* @param string $user Username
* @param string $pass Cleartext Password
* @param bool $sticky Cookie should not expire
* @return bool true on successful auth
*/
function trustExternal($user,$pass,$sticky=false){
# // some example:
#
# global $USERINFO;
# global $conf;
# $sticky ? $sticky = true : $sticky = false; //sanity check
#
# // do the checking here
#
# // set the globals if authed
# $USERINFO['name'] = 'FIXME';
# $USERINFO['mail'] = 'FIXME';
# $USERINFO['grps'] = array('FIXME');
# $_SERVER['REMOTE_USER'] = $user;
# $_SESSION[DOKU_COOKIE]['auth']['user'] = $user;
# $_SESSION[DOKU_COOKIE]['auth']['pass'] = $pass;
# $_SESSION[DOKU_COOKIE]['auth']['info'] = $USERINFO;
# return true;
}
/**
* Trigger the AUTH_USERDATA_CHANGE event and call the modification function. [ DO NOT OVERRIDE ]
*
* You should use this function instead of calling createUser, modifyUser or
* deleteUsers directly. The event handlers can prevent the modification, for
* example for enforcing a user name schema.
*
* @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
* @return mixed Result from the modification function or false if an event handler has canceled the action
*/
function triggerUserMod($type, $params) {
$validTypes = array(
'create' => 'createUser',
'modify' => 'modifyUser',
'delete' => 'deleteUsers'
);
if(empty($validTypes[$type]))
return false;
$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]), $params);
$evt->data['modification_result'] = $result;
}
$evt->advise_after();
unset($evt);
return $result;
}
/**
* Check user+password [ MUST BE OVERRIDDEN ]
*
* Checks if the given user exists and the given
* plaintext password is correct
*
* May be ommited if trustExternal is used.
*
* @author Andreas Gohr <andi@splitbrain.org>
* @return bool
*/
function checkPass($user,$pass){
msg("no valid authorisation system in use", -1);
return false;
}
/**
* Log off the current user [ OPTIONAL ]
*
* Is run in addition to the ususal logoff method. Should
* only be needed when trustExternal is implemented.
*
* @see auth_logoff()
* @author Andreas Gohr <andi@splitbrain.org>
*/
function logOff(){
}
/**
* Return user info [ MUST BE OVERRIDDEN ]
*
* Returns info about the given user needs to contain
* at least these fields:
*
* name string full name of the user
* mail string email addres of the user
* grps array list of groups the user is in
*
* @author Andreas Gohr <andi@splitbrain.org>
* @return array containing user data or false
*/
function getUserData($user) {
if(!$this->cando['external']) msg("no valid authorisation system in use", -1);
return false;
}
/**
* Do all authentication [ OPTIONAL ]
*
* Set $this->cando['external'] = true when implemented
*
* If this function is implemented it will be used to
* authenticate a user - all other DokuWiki internals
* will not be used for authenticating, thus
* implementing the checkPass() function is not needed
* anymore.
*
* The function can be used to authenticate against third
* party cookies or Apache auth mechanisms and replaces
* the auth_login() function
*
* The function will be called with or without a set
* username. If the Username is given it was called
* from the login form and the given credentials might
* need to be checked. If no username was given it
* the function needs to check if the user is logged in
* by other means (cookie, environment).
*
* The function needs to set some globals needed by
* DokuWiki like auth_login() does.
*
* @see auth_login()
* @author Andreas Gohr <andi@splitbrain.org>
*
* @param string $user Username
* @param string $pass Cleartext Password
* @param bool $sticky Cookie should not expire
* @return bool true on successful auth
*/
function trustExternal($user,$pass,$sticky=false){
/* some example:
/**
* Create a new User [implement only where required/possible]
*
* Returns false if the user already exists, null when an error
* occurred and true if everything went well.
*
* The new user HAS TO be added to the default group by this
* function!
*
* Set addUser capability when implemented
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function createUser($user,$pass,$name,$mail,$grps=null){
msg("authorisation method does not allow creation of new users", -1);
return null;
}
global $USERINFO;
global $conf;
$sticky ? $sticky = true : $sticky = false; //sanity check
/**
* Modify user data [implement only where required/possible]
*
* Set the mod* capabilities according to the implemented features
*
* @author Chris Smith <chris@jalakai.co.uk>
* @param $user nick of the user to be changed
* @param $changes array of field/value pairs to be changed (password will be clear text)
* @return bool
*/
function modifyUser($user, $changes) {
msg("authorisation method does not allow modifying of user data", -1);
return false;
}
// do the checking here
/**
* Delete one or more users [implement only where required/possible]
*
* Set delUser capability when implemented
*
* @author Chris Smith <chris@jalakai.co.uk>
* @param array $users
* @return int number of users deleted
*/
function deleteUsers($users) {
msg("authorisation method does not allow deleting of users", -1);
return false;
}
// set the globals if authed
$USERINFO['name'] = 'FIXME';
$USERINFO['mail'] = 'FIXME';
$USERINFO['grps'] = array('FIXME');
$_SERVER['REMOTE_USER'] = $user;
$_SESSION[DOKU_COOKIE]['auth']['user'] = $user;
$_SESSION[DOKU_COOKIE]['auth']['pass'] = $pass;
$_SESSION[DOKU_COOKIE]['auth']['info'] = $USERINFO;
return true;
/**
* Return a count of the number of user which meet $filter criteria
* [should be implemented whenever retrieveUsers is implemented]
*
* Set getUserCount capability when implemented
*
* @author Chris Smith <chris@jalakai.co.uk>
*/
function getUserCount($filter=array()) {
msg("authorisation method does not provide user counts", -1);
return 0;
}
*/
}
/**
* Bulk retrieval of user data [implement only where required/possible]
*
* Set getUsers capability when implemented
*
* @author Chris Smith <chris@jalakai.co.uk>
* @param start index of first user to be returned
* @param limit max number of users to be returned
* @param 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=-1,$filter=null) {
msg("authorisation method does not support mass retrieval of user data", -1);
return array();
}
/**
* Check user+password [ MUST BE OVERRIDDEN ]
*
* Checks if the given user exists and the given
* plaintext password is correct
*
* May be ommited if trustExternal is used.
*
* @author Andreas Gohr <andi@splitbrain.org>
* @return bool
*/
function checkPass($user,$pass){
msg("no valid authorisation system in use", -1);
return false;
}
/**
* Define a group [implement only where required/possible]
*
* Set addGroup capability when implemented
*
* @author Chris Smith <chris@jalakai.co.uk>
* @return bool
*/
function addGroup($group) {
msg("authorisation method does not support independent group creation", -1);
return false;
}
/**
* Return user info [ MUST BE OVERRIDDEN ]
*
* Returns info about the given user needs to contain
* at least these fields:
*
* name string full name of the user
* mail string email addres of the user
* grps array list of groups the user is in
*
* @author Andreas Gohr <andi@splitbrain.org>
* @return array containing user data or false
*/
function getUserData($user) {
if(!$this->cando['external']) msg("no valid authorisation system in use", -1);
return false;
}
/**
* Retrieve groups [implement only where required/possible]
*
* Set getGroups capability when implemented
*
* @author Chris Smith <chris@jalakai.co.uk>
* @return array
*/
function retrieveGroups($start=0,$limit=0) {
msg("authorisation method does not support group list retrieval", -1);
return array();
}
/**
* Create a new User [implement only where required/possible]
*
* Returns false if the user already exists, null when an error
* occurred and true if everything went well.
*
* The new user HAS TO be added to the default group by this
* function!
*
* Set addUser capability when implemented
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function createUser($user,$pass,$name,$mail,$grps=null){
msg("authorisation method does not allow creation of new users", -1);
return null;
}
/**
* Return case sensitivity of the backend [OPTIONAL]
*
* When your backend is caseinsensitive (eg. you can login with USER and
* user) then you need to overwrite this method and return false
*/
function isCaseSensitive(){
return true;
}
/**
* Modify user data [implement only where required/possible]
*
* Set the mod* capabilities according to the implemented features
*
* @author Chris Smith <chris@jalakai.co.uk>
* @param $user nick of the user to be changed
* @param $changes array of field/value pairs to be changed (password will be clear text)
* @return bool
*/
function modifyUser($user, $changes) {
msg("authorisation method does not allow modifying of user data", -1);
return false;
}
/**
* Sanitize a given username [OPTIONAL]
*
* This function is applied to any user name that is given to
* the backend and should also be applied to any user name within
* the backend before returning it somewhere.
*
* This should be used to enforce username restrictions.
*
* @author Andreas Gohr <andi@splitbrain.org>
* @param string $user - username
* @param string - the cleaned username
*/
function cleanUser($user){
return $user;
}
/**
* Delete one or more users [implement only where required/possible]
*
* Set delUser capability when implemented
*
* @author Chris Smith <chris@jalakai.co.uk>
* @param array $users
* @return int number of users deleted
*/
function deleteUsers($users) {
msg("authorisation method does not allow deleting of users", -1);
return false;
}
/**
* Sanitize a given groupname [OPTIONAL]
*
* This function is applied to any groupname that is given to
* the backend and should also be applied to any groupname within
* the backend before returning it somewhere.
*
* This should be used to enforce groupname restrictions.
*
* Groupnames are to be passed without a leading '@' here.
*
* @author Andreas Gohr <andi@splitbrain.org>
* @param string $group - groupname
* @param string - the cleaned groupname
*/
function cleanGroup($group){
return $group;
}
/**
* Return a count of the number of user which meet $filter criteria
* [should be implemented whenever retrieveUsers is implemented]
*
* Set getUserCount capability when implemented
*
* @author Chris Smith <chris@jalakai.co.uk>
*/
function getUserCount($filter=array()) {
msg("authorisation method does not provide user counts", -1);
return 0;
}
/**
* Bulk retrieval of user data [implement only where required/possible]
*
* Set getUsers capability when implemented
*
* @author Chris Smith <chris@jalakai.co.uk>
* @param start index of first user to be returned
* @param limit max number of users to be returned
* @param 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=-1,$filter=null) {
msg("authorisation method does not support mass retrieval of user data", -1);
return array();
}
/**
* Define a group [implement only where required/possible]
*
* Set addGroup capability when implemented
*
* @author Chris Smith <chris@jalakai.co.uk>
* @return bool
*/
function addGroup($group) {
msg("authorisation method does not support independent group creation", -1);
return false;
}
/**
* Retrieve groups [implement only where required/possible]
*
* Set getGroups capability when implemented
*
* @author Chris Smith <chris@jalakai.co.uk>
* @return array
*/
function retrieveGroups($start=0,$limit=0) {
msg("authorisation method does not support group list retrieval", -1);
return array();
}
/**
* Return case sensitivity of the backend [OPTIONAL]
*
* When your backend is caseinsensitive (eg. you can login with USER and
* user) then you need to overwrite this method and return false
*/
function isCaseSensitive(){
return true;
}
/**
* Sanitize a given username [OPTIONAL]
*
* This function is applied to any user name that is given to
* the backend and should also be applied to any user name within
* the backend before returning it somewhere.
*
* This should be used to enforce username restrictions.
*
* @author Andreas Gohr <andi@splitbrain.org>
* @param string $user - username
* @param string - the cleaned username
*/
function cleanUser($user){
return $user;
}
/**
* Sanitize a given groupname [OPTIONAL]
*
* This function is applied to any groupname that is given to
* the backend and should also be applied to any groupname within
* the backend before returning it somewhere.
*
* This should be used to enforce groupname restrictions.
*
* Groupnames are to be passed without a leading '@' here.
*
* @author Andreas Gohr <andi@splitbrain.org>
* @param string $group - groupname
* @param string - the cleaned groupname
*/
function cleanGroup($group){
return $group;
}
/**
* Check Session Cache validity [implement only where required/possible]
*
* DokuWiki caches user info in the user's session for the timespan defined
* in $conf['auth_security_timeout'].
*
* This makes sure slow authentication backends do not slow down DokuWiki.
* This also means that changes to the user database will not be reflected
* on currently logged in users.
*
* To accommodate for this, the user manager plugin will touch a reference
* file whenever a change is submitted. This function compares the filetime
* of this reference file with the time stored in the session.
*
* This reference file mechanism does not reflect changes done directly in
* the backend's database through other means than the user manager plugin.
*
* Fast backends might want to return always false, to force rechecks on
* each page load. Others might want to use their own checking here. If
* unsure, do not override.
*
* @param string $user - The username
* @author Andreas Gohr <andi@splitbrain.org>
* @return bool
*/
function useSessionCache($user){
global $conf;
return ($_SESSION[DOKU_COOKIE]['auth']['time'] >= @filemtime($conf['cachedir'].'/sessionpurge'));
}
/**
* Check Session Cache validity [implement only where required/possible]
*
* DokuWiki caches user info in the user's session for the timespan defined
* in $conf['auth_security_timeout'].
*
* This makes sure slow authentication backends do not slow down DokuWiki.
* This also means that changes to the user database will not be reflected
* on currently logged in users.
*
* To accommodate for this, the user manager plugin will touch a reference
* file whenever a change is submitted. This function compares the filetime
* of this reference file with the time stored in the session.
*
* This reference file mechanism does not reflect changes done directly in
* the backend's database through other means than the user manager plugin.
*
* Fast backends might want to return always false, to force rechecks on
* each page load. Others might want to use their own checking here. If
* unsure, do not override.
*
* @param string $user - The username
* @author Andreas Gohr <andi@splitbrain.org>
* @return bool
*/
function useSessionCache($user){
global $conf;
return ($_SESSION[DOKU_COOKIE]['auth']['time'] >= @filemtime($conf['cachedir'].'/sessionpurge'));
}
}
//Setup VIM: ex: et ts=2 :

View file

@ -15,7 +15,7 @@ class auth_ldap extends auth_basic {
/**
* Constructor
*/
function auth_ldap(){
function __construct(){
global $conf;
$this->cnf = $conf['auth']['ldap'];
@ -307,8 +307,6 @@ class auth_ldap extends auth_basic {
}
}
return $result;
}
/**
@ -360,7 +358,6 @@ class auth_ldap extends auth_basic {
function _constructPattern($filter) {
$this->_pattern = array();
foreach ($filter as $item => $pattern) {
// $this->_pattern[$item] = '/'.preg_quote($pattern,"/").'/i'; // don't allow regex characters
$this->_pattern[$item] = '/'.str_replace('/','\/',$pattern).'/i'; // allow regex characters
}
}

File diff suppressed because it is too large Load diff

View file

@ -9,7 +9,7 @@
* @author Andreas Gohr <andi@splitbrain.org>
* @author Chris Smith <chris@jalakai.co.uk>
* @author Matthias Grimm <matthias.grimmm@sourceforge.net>
*/
*/
require_once(DOKU_INC.'inc/auth/mysql.class.php');
@ -24,63 +24,72 @@ class auth_pgsql extends auth_mysql {
* @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
* @author Andreas Gohr <andi@splitbrain.org>
*/
function auth_pgsql() {
global $conf;
$this->cnf = $conf['auth']['pgsql'];
if(!$this->cnf['port']) $this->cnf['port'] = 5432;
function __construct() {
global $conf;
$this->cnf = $conf['auth']['pgsql'];
if(!$this->cnf['port']){
$this->cnf['port'] = 5432;
}
if (method_exists($this, 'auth_basic'))
parent::auth_basic();
if (method_exists($this, 'auth_basic')){
parent::auth_basic();
}
if(!function_exists('pg_connect')) {
if ($this->cnf['debug'])
msg("PgSQL err: PHP Postgres extension not found.",-1);
$this->success = false;
return;
}
if(!function_exists('pg_connect')) {
if ($this->cnf['debug'])
msg("PgSQL err: PHP Postgres extension not found.",-1);
$this->success = false;
return;
}
$this->defaultgroup = $conf['defaultgroup'];
$this->defaultgroup = $conf['defaultgroup'];
// set capabilities based upon config strings set
if (empty($this->cnf['user']) ||
empty($this->cnf['password']) || empty($this->cnf['database'])){
if ($this->cnf['debug'])
msg("PgSQL err: insufficient configuration.",-1,__LINE__,__FILE__);
$this->success = false;
return;
}
// set capabilities based upon config strings set
if (empty($this->cnf['user']) ||
empty($this->cnf['password']) || empty($this->cnf['database'])){
if ($this->cnf['debug']){
msg("PgSQL err: insufficient configuration.",-1,__LINE__,__FILE__);
}
$this->success = false;
return;
}
$this->cando['addUser'] = $this->_chkcnf(array('getUserInfo',
'getGroups',
'addUser',
'getUserID',
'getGroupID',
'addGroup',
'addUserGroup'));
$this->cando['delUser'] = $this->_chkcnf(array('getUserID',
'delUser',
'delUserRefs'));
$this->cando['modLogin'] = $this->_chkcnf(array('getUserID',
'updateUser',
'UpdateTarget'));
$this->cando['modPass'] = $this->cando['modLogin'];
$this->cando['modName'] = $this->cando['modLogin'];
$this->cando['modMail'] = $this->cando['modLogin'];
$this->cando['modGroups'] = $this->_chkcnf(array('getUserID',
'getGroups',
'getGroupID',
'addGroup',
'addUserGroup',
'delGroup',
'getGroupID',
'delUserGroup'));
/* getGroups is not yet supported
$this->cando['getGroups'] = $this->_chkcnf(array('getGroups',
'getGroupID')); */
$this->cando['getUsers'] = $this->_chkcnf(array('getUsers',
'getUserInfo',
'getGroups'));
$this->cando['getUserCount'] = $this->_chkcnf(array('getUsers'));
$this->cando['addUser'] = $this->_chkcnf(array(
'getUserInfo',
'getGroups',
'addUser',
'getUserID',
'getGroupID',
'addGroup',
'addUserGroup'));
$this->cando['delUser'] = $this->_chkcnf(array(
'getUserID',
'delUser',
'delUserRefs'));
$this->cando['modLogin'] = $this->_chkcnf(array(
'getUserID',
'updateUser',
'UpdateTarget'));
$this->cando['modPass'] = $this->cando['modLogin'];
$this->cando['modName'] = $this->cando['modLogin'];
$this->cando['modMail'] = $this->cando['modLogin'];
$this->cando['modGroups'] = $this->_chkcnf(array(
'getUserID',
'getGroups',
'getGroupID',
'addGroup',
'addUserGroup',
'delGroup',
'getGroupID',
'delUserGroup'));
/* getGroups is not yet supported
$this->cando['getGroups'] = $this->_chkcnf(array('getGroups',
'getGroupID')); */
$this->cando['getUsers'] = $this->_chkcnf(array(
'getUsers',
'getUserInfo',
'getGroups'));
$this->cando['getUserCount'] = $this->_chkcnf(array('getUsers'));
}
/**
@ -90,10 +99,10 @@ class auth_pgsql extends auth_mysql {
* @return bool
*/
function _chkcnf($keys, $wop=false){
foreach ($keys as $key){
if (empty($this->cnf[$key])) return false;
}
return true;
foreach ($keys as $key){
if (empty($this->cnf[$key])) return false;
}
return true;
}
// @inherit function checkPass($user,$pass)
@ -114,18 +123,18 @@ class auth_pgsql extends auth_mysql {
* @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
*/
function getUserCount($filter=array()) {
$rc = 0;
$rc = 0;
if($this->_openDB()) {
$sql = $this->_createSQLFilter($this->cnf['getUsers'], $filter);
if($this->_openDB()) {
$sql = $this->_createSQLFilter($this->cnf['getUsers'], $filter);
// no equivalent of SQL_CALC_FOUND_ROWS in pgsql?
if (($result = $this->_queryDB($sql))){
$rc = count($result);
// no equivalent of SQL_CALC_FOUND_ROWS in pgsql?
if (($result = $this->_queryDB($sql))){
$rc = count($result);
}
$this->_closeDB();
}
$this->_closeDB();
}
return $rc;
return $rc;
}
/**
@ -139,22 +148,22 @@ class auth_pgsql extends auth_mysql {
* @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
*/
function retrieveUsers($first=0,$limit=10,$filter=array()) {
$out = array();
$out = array();
if($this->_openDB()) {
$this->_lockTables("READ");
$sql = $this->_createSQLFilter($this->cnf['getUsers'], $filter);
$sql .= " ".$this->cnf['SortOrder']." LIMIT $limit OFFSET $first";
$result = $this->_queryDB($sql);
if($this->_openDB()) {
$this->_lockTables("READ");
$sql = $this->_createSQLFilter($this->cnf['getUsers'], $filter);
$sql .= " ".$this->cnf['SortOrder']." LIMIT $limit OFFSET $first";
$result = $this->_queryDB($sql);
foreach ($result as $user)
if (($info = $this->_getUserInfo($user['user'])))
$out[$user['user']] = $info;
foreach ($result as $user)
if (($info = $this->_getUserInfo($user['user'])))
$out[$user['user']] = $info;
$this->_unlockTables();
$this->_closeDB();
}
return $out;
$this->_unlockTables();
$this->_closeDB();
}
return $out;
}
// @inherit function joinGroup($user, $group)
@ -177,38 +186,38 @@ class auth_pgsql extends auth_mysql {
* @author Andreas Gohr <andi@splitbrain.org>
*/
function _addUserToGroup($user, $group, $force=0) {
$newgroup = 0;
$newgroup = 0;
if (($this->dbcon) && ($user)) {
$gid = $this->_getGroupID($group);
if (!$gid) {
if ($force) { // create missing groups
$sql = str_replace('%{group}',addslashes($group),$this->cnf['addGroup']);
$this->_modifyDB($sql);
//group should now exists try again to fetch it
if (($this->dbcon) && ($user)) {
$gid = $this->_getGroupID($group);
$newgroup = 1; // group newly created
}
}
if (!$gid) return false; // group didn't exist and can't be created
if (!$gid) {
if ($force) { // create missing groups
$sql = str_replace('%{group}',addslashes($group),$this->cnf['addGroup']);
$this->_modifyDB($sql);
//group should now exists try again to fetch it
$gid = $this->_getGroupID($group);
$newgroup = 1; // group newly created
}
}
if (!$gid) return false; // group didn't exist and can't be created
$sql = $this->cnf['addUserGroup'];
if(strpos($sql,'%{uid}') !== false){
$uid = $this->_getUserID($user);
$sql = str_replace('%{uid}', addslashes($uid), $sql);
}
$sql = str_replace('%{user}', addslashes($user),$sql);
$sql = str_replace('%{gid}', addslashes($gid),$sql);
$sql = str_replace('%{group}',addslashes($group),$sql);
if ($this->_modifyDB($sql) !== false) return true;
$sql = $this->cnf['addUserGroup'];
if(strpos($sql,'%{uid}') !== false){
$uid = $this->_getUserID($user);
$sql = str_replace('%{uid}', addslashes($uid), $sql);
}
$sql = str_replace('%{user}', addslashes($user),$sql);
$sql = str_replace('%{gid}', addslashes($gid),$sql);
$sql = str_replace('%{group}',addslashes($group),$sql);
if ($this->_modifyDB($sql) !== false) return true;
if ($newgroup) { // remove previously created group on error
$sql = str_replace('%{gid}', addslashes($gid),$this->cnf['delGroup']);
$sql = str_replace('%{group}',addslashes($group),$sql);
$this->_modifyDB($sql);
if ($newgroup) { // remove previously created group on error
$sql = str_replace('%{gid}', addslashes($gid),$this->cnf['delGroup']);
$sql = str_replace('%{group}',addslashes($group),$sql);
$this->_modifyDB($sql);
}
}
}
return false;
return false;
}
// @inherit function _delUserFromGroup($user $group)
@ -234,37 +243,37 @@ class auth_pgsql extends auth_mysql {
* @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
*/
function _addUser($user,$pwd,$name,$mail,$grps){
if($this->dbcon && is_array($grps)) {
$sql = str_replace('%{user}', addslashes($user),$this->cnf['addUser']);
$sql = str_replace('%{pass}', addslashes($pwd),$sql);
$sql = str_replace('%{name}', addslashes($name),$sql);
$sql = str_replace('%{email}',addslashes($mail),$sql);
if($this->_modifyDB($sql)){
$uid = $this->_getUserID($user);
}else{
return false;
}
if($this->dbcon && is_array($grps)) {
$sql = str_replace('%{user}', addslashes($user),$this->cnf['addUser']);
$sql = str_replace('%{pass}', addslashes($pwd),$sql);
$sql = str_replace('%{name}', addslashes($name),$sql);
$sql = str_replace('%{email}',addslashes($mail),$sql);
if($this->_modifyDB($sql)){
$uid = $this->_getUserID($user);
}else{
return false;
}
if ($uid) {
foreach($grps as $group) {
$gid = $this->_addUserToGroup($user, $group, 1);
if ($gid === false) break;
}
if ($uid) {
foreach($grps as $group) {
$gid = $this->_addUserToGroup($user, $group, 1);
if ($gid === false) break;
}
if ($gid) return true;
else {
/* remove the new user and all group relations if a group can't
* be assigned. Newly created groups will remain in the database
* and won't be removed. This might create orphaned groups but
* is not a big issue so we ignore this problem here.
*/
$this->_delUser($user);
if ($this->cnf['debug'])
msg("PgSQL err: Adding user '$user' to group '$group' failed.",-1,__LINE__,__FILE__);
}
if ($gid) return true;
else {
/* remove the new user and all group relations if a group can't
* be assigned. Newly created groups will remain in the database
* and won't be removed. This might create orphaned groups but
* is not a big issue so we ignore this problem here.
*/
$this->_delUser($user);
if ($this->cnf['debug'])
msg("PgSQL err: Adding user '$user' to group '$group' failed.",-1,__LINE__,__FILE__);
}
}
}
}
return false;
return false;
}
// @inherit function _delUser($user)
@ -282,24 +291,24 @@ class auth_pgsql extends auth_mysql {
* @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
*/
function _openDB() {
if (!$this->dbcon) {
$dsn = $this->cnf['server'] ? 'host='.$this->cnf['server'] : '';
$dsn .= ' port='.$this->cnf['port'];
$dsn .= ' dbname='.$this->cnf['database'];
$dsn .= ' user='.$this->cnf['user'];
$dsn .= ' password='.$this->cnf['password'];
if (!$this->dbcon) {
$dsn = $this->cnf['server'] ? 'host='.$this->cnf['server'] : '';
$dsn .= ' port='.$this->cnf['port'];
$dsn .= ' dbname='.$this->cnf['database'];
$dsn .= ' user='.$this->cnf['user'];
$dsn .= ' password='.$this->cnf['password'];
$con = @pg_connect($dsn);
if ($con) {
$this->dbcon = $con;
return true; // connection and database successfully opened
} else if ($this->cnf['debug']){
msg ("PgSQL err: Connection to {$this->cnf['user']}@{$this->cnf['server']} not possible.",
-1,__LINE__,__FILE__);
$con = @pg_connect($dsn);
if ($con) {
$this->dbcon = $con;
return true; // connection and database successfully opened
} else if ($this->cnf['debug']){
msg ("PgSQL err: Connection to {$this->cnf['user']}@{$this->cnf['server']} not possible.",
-1,__LINE__,__FILE__);
}
return false; // connection failed
}
return false; // connection failed
}
return true; // connection already open
return true; // connection already open
}
/**
@ -308,10 +317,10 @@ class auth_pgsql extends auth_mysql {
* @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
*/
function _closeDB() {
if ($this->dbcon) {
pg_close ($this->dbcon);
$this->dbcon = 0;
}
if ($this->dbcon) {
pg_close ($this->dbcon);
$this->dbcon = 0;
}
}
/**
@ -327,17 +336,17 @@ class auth_pgsql extends auth_mysql {
* @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
*/
function _queryDB($query) {
if ($this->dbcon) {
$result = @pg_query($this->dbcon,$query);
if ($result) {
while (($t = pg_fetch_assoc($result)) !== false)
$resultarray[]=$t;
pg_free_result ($result);
return $resultarray;
}elseif ($this->cnf['debug'])
msg('PgSQL err: '.pg_last_error($this->dbcon),-1,__LINE__,__FILE__);
}
return false;
if ($this->dbcon) {
$result = @pg_query($this->dbcon,$query);
if ($result) {
while (($t = pg_fetch_assoc($result)) !== false)
$resultarray[]=$t;
pg_free_result ($result);
return $resultarray;
}elseif ($this->cnf['debug'])
msg('PgSQL err: '.pg_last_error($this->dbcon),-1,__LINE__,__FILE__);
}
return false;
}
/**
@ -347,17 +356,17 @@ class auth_pgsql extends auth_mysql {
* @author Andreas Gohr
*/
function _modifyDB($query) {
if ($this->dbcon) {
$result = @pg_query($this->dbcon,$query);
if ($result) {
pg_free_result ($result);
return true;
if ($this->dbcon) {
$result = @pg_query($this->dbcon,$query);
if ($result) {
pg_free_result ($result);
return true;
}
if ($this->cnf['debug']){
msg('PgSQL err: '.pg_last_error($this->dbcon),-1,__LINE__,__FILE__);
}
}
if ($this->cnf['debug']){
msg('PgSQL err: '.pg_last_error($this->dbcon),-1,__LINE__,__FILE__);
}
}
return false;
return false;
}
/**
@ -367,11 +376,11 @@ class auth_pgsql extends auth_mysql {
* @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
*/
function _lockTables($mode) {
if ($this->dbcon) {
$this->_modifyDB('BEGIN');
return true;
}
return false;
if ($this->dbcon) {
$this->_modifyDB('BEGIN');
return true;
}
return false;
}
/**
@ -380,11 +389,11 @@ class auth_pgsql extends auth_mysql {
* @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
*/
function _unlockTables() {
if ($this->dbcon) {
$this->_modifyDB('COMMIT');
return true;
}
return false;
if ($this->dbcon) {
$this->_modifyDB('COMMIT');
return true;
}
return false;
}
// @inherit function _createSQLFilter($sql, $filter)
@ -398,11 +407,11 @@ class auth_pgsql extends auth_mysql {
* @param boolean $like Escape wildcard chars as well?
*/
function _escape($string,$like=false){
$string = pg_escape_string($string);
if($like){
$string = addcslashes($string,'%_');
}
return $string;
$string = pg_escape_string($string);
if($like){
$string = addcslashes($string,'%_');
}
return $string;
}
}

View file

@ -20,24 +20,24 @@ class auth_plain extends auth_basic {
*
* @author Christopher Smith <chris@jalakai.co.uk>
*/
function auth_plain() {
global $config_cascade;
function __construct() {
global $config_cascade;
if (!@is_readable($config_cascade['plainauth.users']['default'])){
$this->success = false;
}else{
if(@is_writable($config_cascade['plainauth.users']['default'])){
$this->cando['addUser'] = true;
$this->cando['delUser'] = true;
$this->cando['modLogin'] = true;
$this->cando['modPass'] = true;
$this->cando['modName'] = true;
$this->cando['modMail'] = true;
$this->cando['modGroups'] = true;
if (!@is_readable($config_cascade['plainauth.users']['default'])){
$this->success = false;
}else{
if(@is_writable($config_cascade['plainauth.users']['default'])){
$this->cando['addUser'] = true;
$this->cando['delUser'] = true;
$this->cando['modLogin'] = true;
$this->cando['modPass'] = true;
$this->cando['modName'] = true;
$this->cando['modMail'] = true;
$this->cando['modGroups'] = true;
}
$this->cando['getUsers'] = true;
$this->cando['getUserCount'] = true;
}
$this->cando['getUsers'] = true;
$this->cando['getUserCount'] = true;
}
}
/**
@ -51,10 +51,10 @@ class auth_plain extends auth_basic {
*/
function checkPass($user,$pass){
$userinfo = $this->getUserData($user);
if ($userinfo === false) return false;
$userinfo = $this->getUserData($user);
if ($userinfo === false) return false;
return auth_verifyPassword($pass,$this->users[$user]['pass']);
return auth_verifyPassword($pass,$this->users[$user]['pass']);
}
/**
@ -71,8 +71,8 @@ class auth_plain extends auth_basic {
*/
function getUserData($user){
if($this->users === null) $this->_loadUserData();
return isset($this->users[$user]) ? $this->users[$user] : false;
if($this->users === null) $this->_loadUserData();
return isset($this->users[$user]) ? $this->users[$user] : false;
}
/**
@ -88,29 +88,29 @@ class auth_plain extends auth_basic {
* @author Chris Smith <chris@jalakai.co.uk>
*/
function createUser($user,$pwd,$name,$mail,$grps=null){
global $conf;
global $config_cascade;
global $conf;
global $config_cascade;
// user mustn't already exist
if ($this->getUserData($user) !== false) return false;
// user mustn't already exist
if ($this->getUserData($user) !== false) return false;
$pass = auth_cryptPassword($pwd);
$pass = auth_cryptPassword($pwd);
// set default group if no groups specified
if (!is_array($grps)) $grps = array($conf['defaultgroup']);
// set default group if no groups specified
if (!is_array($grps)) $grps = array($conf['defaultgroup']);
// prepare user line
$groups = join(',',$grps);
$userline = join(':',array($user,$pass,$name,$mail,$groups))."\n";
// prepare user line
$groups = join(',',$grps);
$userline = join(':',array($user,$pass,$name,$mail,$groups))."\n";
if (io_saveFile($config_cascade['plainauth.users']['default'],$userline,true)) {
$this->users[$user] = compact('pass','name','mail','grps');
return $pwd;
}
if (io_saveFile($config_cascade['plainauth.users']['default'],$userline,true)) {
$this->users[$user] = compact('pass','name','mail','grps');
return $pwd;
}
msg('The '.$config_cascade['plainauth.users']['default'].
' file is not writable. Please inform the Wiki-Admin',-1);
return null;
msg('The '.$config_cascade['plainauth.users']['default'].
' file is not writable. Please inform the Wiki-Admin',-1);
return null;
}
/**
@ -122,78 +122,78 @@ class auth_plain extends auth_basic {
* @return bool
*/
function modifyUser($user, $changes) {
global $conf;
global $ACT;
global $INFO;
global $config_cascade;
global $conf;
global $ACT;
global $INFO;
global $config_cascade;
// sanity checks, user must already exist and there must be something to change
if (($userinfo = $this->getUserData($user)) === false) return false;
if (!is_array($changes) || !count($changes)) return true;
// sanity checks, user must already exist and there must be something to change
if (($userinfo = $this->getUserData($user)) === false) return false;
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') {
$newuser = $value;
continue;
// update userinfo with new data, remembering to encrypt any password
$newuser = $user;
foreach ($changes as $field => $value) {
if ($field == 'user') {
$newuser = $value;
continue;
}
if ($field == 'pass') $value = auth_cryptPassword($value);
$userinfo[$field] = $value;
}
if ($field == 'pass') $value = auth_cryptPassword($value);
$userinfo[$field] = $value;
}
$groups = join(',',$userinfo['grps']);
$userline = join(':',array($newuser, $userinfo['pass'], $userinfo['name'], $userinfo['mail'], $groups))."\n";
$groups = join(',',$userinfo['grps']);
$userline = join(':',array($newuser, $userinfo['pass'], $userinfo['name'], $userinfo['mail'], $groups))."\n";
if (!$this->deleteUsers(array($user))) {
msg('Unable to modify user data. Please inform the Wiki-Admin',-1);
return false;
}
if (!$this->deleteUsers(array($user))) {
msg('Unable to modify user data. Please inform the Wiki-Admin',-1);
return false;
}
if (!io_saveFile($config_cascade['plainauth.users']['default'],$userline,true)) {
msg('There was an error modifying your user data. You should register again.',-1);
// FIXME, user has been deleted but not recreated, should force a logout and redirect to login page
$ACT == 'register';
return false;
}
if (!io_saveFile($config_cascade['plainauth.users']['default'],$userline,true)) {
msg('There was an error modifying your user data. You should register again.',-1);
// FIXME, user has been deleted but not recreated, should force a logout and redirect to login page
$ACT == 'register';
return false;
}
$this->users[$newuser] = $userinfo;
return true;
$this->users[$newuser] = $userinfo;
return true;
}
/**
* Remove one or more users from the list of registered users
* Remove one or more users from the list of registered users
*
* @author Christopher Smith <chris@jalakai.co.uk>
* @param array $users array of users to be deleted
* @return int the number of users deleted
* @author Christopher Smith <chris@jalakai.co.uk>
* @param array $users array of users to be deleted
* @return int the number of users deleted
*/
function deleteUsers($users) {
global $config_cascade;
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) {
if (isset($this->users[$user])) $deleted[] = preg_quote($user,'/');
}
$deleted = array();
foreach ($users as $user) {
if (isset($this->users[$user])) $deleted[] = preg_quote($user,'/');
}
if (empty($deleted)) return 0;
if (empty($deleted)) return 0;
$pattern = '/^('.join('|',$deleted).'):/';
$pattern = '/^('.join('|',$deleted).'):/';
if (io_deleteFromFile($config_cascade['plainauth.users']['default'],$pattern,true)) {
foreach ($deleted as $user) unset($this->users[$user]);
return count($deleted);
}
if (io_deleteFromFile($config_cascade['plainauth.users']['default'],$pattern,true)) {
foreach ($deleted as $user) unset($this->users[$user]);
return count($deleted);
}
// problem deleting, reload the user list and count the difference
$count = count($this->users);
$this->_loadUserData();
$count -= count($this->users);
return $count;
// problem deleting, reload the user list and count the difference
$count = count($this->users);
$this->_loadUserData();
$count -= count($this->users);
return $count;
}
/**
@ -203,18 +203,18 @@ class auth_plain extends auth_basic {
*/
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);
$count = 0;
$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;
return $count;
}
/**
@ -228,27 +228,27 @@ class auth_plain extends auth_basic {
*/
function retrieveUsers($start=0,$limit=0,$filter=array()) {
if ($this->users === null) $this->_loadUserData();
if ($this->users === null) $this->_loadUserData();
ksort($this->users);
ksort($this->users);
$i = 0;
$count = 0;
$out = array();
$this->_constructPattern($filter);
$i = 0;
$count = 0;
$out = array();
$this->_constructPattern($filter);
foreach ($this->users as $user => $info) {
if ($this->_filter($user, $info)) {
if ($i >= $start) {
$out[$user] = $info;
$count++;
if (($limit > 0) && ($count >= $limit)) break;
}
$i++;
foreach ($this->users as $user => $info) {
if ($this->_filter($user, $info)) {
if ($i >= $start) {
$out[$user] = $info;
$count++;
if (($limit > 0) && ($count >= $limit)) break;
}
$i++;
}
}
}
return $out;
return $out;
}
/**
@ -275,26 +275,26 @@ class auth_plain extends auth_basic {
* @author Andreas Gohr <andi@splitbrain.org>
*/
function _loadUserData(){
global $config_cascade;
global $config_cascade;
$this->users = array();
$this->users = array();
if(!@file_exists($config_cascade['plainauth.users']['default'])) return;
if(!@file_exists($config_cascade['plainauth.users']['default'])) return;
$lines = file($config_cascade['plainauth.users']['default']);
foreach($lines as $line){
$line = preg_replace('/#.*$/','',$line); //ignore comments
$line = trim($line);
if(empty($line)) continue;
$lines = file($config_cascade['plainauth.users']['default']);
foreach($lines as $line){
$line = preg_replace('/#.*$/','',$line); //ignore comments
$line = trim($line);
if(empty($line)) continue;
$row = explode(":",$line,5);
$groups = array_values(array_filter(explode(",",$row[4])));
$row = explode(":",$line,5);
$groups = array_values(array_filter(explode(",",$row[4])));
$this->users[$row[0]]['pass'] = $row[1];
$this->users[$row[0]]['name'] = urldecode($row[2]);
$this->users[$row[0]]['mail'] = $row[3];
$this->users[$row[0]]['grps'] = $groups;
}
$this->users[$row[0]]['pass'] = $row[1];
$this->users[$row[0]]['name'] = urldecode($row[2]);
$this->users[$row[0]]['mail'] = $row[3];
$this->users[$row[0]]['grps'] = $groups;
}
}
/**
@ -317,11 +317,11 @@ class auth_plain extends auth_basic {
}
function _constructPattern($filter) {
$this->_pattern = array();
foreach ($filter as $item => $pattern) {
// $this->_pattern[$item] = '/'.preg_quote($pattern,"/").'/i'; // don't allow regex characters
$this->_pattern[$item] = '/'.str_replace('/','\/',$pattern).'/i'; // allow regex characters
}
$this->_pattern = array();
foreach ($filter as $item => $pattern) {
// $this->_pattern[$item] = '/'.preg_quote($pattern,"/").'/i'; // don't allow regex characters
$this->_pattern[$item] = '/'.str_replace('/','\/',$pattern).'/i'; // allow regex characters
}
}
}

View file

@ -6,7 +6,7 @@
*
* Copyright (c) 1997-2004 The PHP Group
*
* LICENSE: This source file is subject to the New BSD license that is
* LICENSE: This source file is subject to the New BSD license that is
* available through the world-wide-web at the following URI:
* http://www.opensource.org/licenses/bsd-license.php. If you did not receive
* a copy of the New BSD License and are unable to obtain it through the web,
@ -297,9 +297,8 @@ class Doku_Cli_Opts {
* @access private
* @return bool
*/
function _isShortOpt($arg)
{
return strlen($arg) == 2 && $arg[0] == '-'
function _isShortOpt($arg){
return strlen($arg) == 2 && $arg[0] == '-'
&& preg_match('/[a-zA-Z]/', $arg[1]);
}
@ -311,8 +310,7 @@ class Doku_Cli_Opts {
* @access private
* @return bool
*/
function _isLongOpt($arg)
{
function _isLongOpt($arg){
return strlen($arg) > 2 && $arg[0] == '-' && $arg[1] == '-' &&
preg_match('/[a-zA-Z]+$/', substr($arg, 2));
}

View file

@ -1290,14 +1290,14 @@ function dformat($dt=null,$format=''){
*
* @author <ungu at terong dot com>
* @link http://www.php.net/manual/en/function.date.php#54072
* @param int $int_date: current date in UNIX timestamp
*/
function date_iso8601($int_date) {
//$int_date: current date in UNIX timestamp
$date_mod = date('Y-m-d\TH:i:s', $int_date);
$pre_timezone = date('O', $int_date);
$time_zone = substr($pre_timezone, 0, 3).":".substr($pre_timezone, 3, 2);
$date_mod .= $time_zone;
return $date_mod;
$date_mod = date('Y-m-d\TH:i:s', $int_date);
$pre_timezone = date('O', $int_date);
$time_zone = substr($pre_timezone, 0, 3).":".substr($pre_timezone, 3, 2);
$date_mod .= $time_zone;
return $date_mod;
}
/**
@ -1558,10 +1558,14 @@ function valid_input_set($param, $valid_values, $array, $exc = '') {
}
}
/**
* Read a preference from the DokuWiki cookie
*/
function get_doku_pref($pref, $default) {
if (strpos($_COOKIE['DOKU_PREFS'], $pref) !== false) {
$parts = explode('#', $_COOKIE['DOKU_PREFS']);
for ($i = 0; $i < count($parts); $i+=2){
$cnt = count($parts);
for ($i = 0; $i < $cnt; $i+=2){
if ($parts[$i] == $pref) {
return $parts[$i+1];
}

View file

@ -64,7 +64,7 @@ $config_cascade = array_merge(
'plainauth.users' => array(
'default' => DOKU_CONF.'users.auth.php',
),
'plugins' => array(
'local' => array(DOKU_CONF.'plugins.local.php'),
'protected' => array(

View file

@ -1141,8 +1141,6 @@ function html_diff($text='',$intro=true,$type=null){
$tdf = new TableDiffFormatter();
}
if($intro) print p_locale_xhtml('diff');
if (!$text) {
@ -1165,7 +1163,6 @@ function html_diff($text='',$intro=true,$type=null){
$form->addElement(form_makeButton('submit', 'diff','Go'));
$form->printForm();
$diffurl = wl($ID, array(
'do' => 'diff',
'rev2[0]' => $l_rev,
@ -1703,8 +1700,6 @@ function html_resendpwd() {
html_form('resendpwd', $form);
print '</div>'.NL;
}
}
/**

View file

@ -291,7 +291,6 @@ class Doku_Indexer {
$val_idx = array();
}
foreach ($values as $val) {
$val = (string)$val;
if ($val !== "") {

View file

@ -106,7 +106,7 @@ function _mail_send_action($data) {
// discard mail request if no recipients are available
if(trim($to) === '' && trim($cc) === '' && trim($bcc) === '') return false;
// end additional code to support event ... original mail_send() code from here
if(defined('MAILHEADER_ASCIIONLY')){
@ -208,9 +208,9 @@ function mail_encode_address($string,$header='',$names=true){
if(!utf8_isASCII($text)){
// put the quotes outside as in =?UTF-8?Q?"Elan Ruusam=C3=A4e"?= vs "=?UTF-8?Q?Elan Ruusam=C3=A4e?="
if (preg_match('/^"(.+)"$/', $text, $matches)) {
$text = '"=?UTF-8?Q?'.mail_quotedprintable_encode($matches[1], 0).'?="';
$text = '"=?UTF-8?Q?'.mail_quotedprintable_encode($matches[1], 0).'?="';
} else {
$text = '=?UTF-8?Q?'.mail_quotedprintable_encode($text, 0).'?=';
$text = '=?UTF-8?Q?'.mail_quotedprintable_encode($text, 0).'?=';
}
// additionally the space character should be encoded as =20 (or each
// word QP encoded separately).

View file

@ -175,10 +175,10 @@ define('DOKU_MEDIA_EMPTY_NS', 8);
*
* @author Andreas Gohr <andi@splitbrain.org>
* @return int One of: 0,
DOKU_MEDIA_DELETED,
DOKU_MEDIA_DELETED | DOKU_MEDIA_EMPTY_NS,
DOKU_MEDIA_NOT_AUTH,
DOKU_MEDIA_INUSE
* DOKU_MEDIA_DELETED,
* DOKU_MEDIA_DELETED | DOKU_MEDIA_EMPTY_NS,
* DOKU_MEDIA_NOT_AUTH,
* DOKU_MEDIA_INUSE
*/
function media_delete($id,$auth){
global $lang;

View file

@ -213,9 +213,9 @@ function sectionID($title,&$check) {
if(is_array($check)){
// make sure tiles are unique
if (!array_key_exists ($title,$check)) {
$check[$title] = 0;
$check[$title] = 0;
} else {
$title .= ++ $check[$title];
$title .= ++ $check[$title];
}
}
@ -347,8 +347,8 @@ function mediaFN($id, $rev=''){
if(empty($rev)){
$fn = $conf['mediadir'].'/'.utf8_encodeFN($id);
}else{
$ext = mimetype($id);
$name = substr($id,0, -1*strlen($ext[0])-1);
$ext = mimetype($id);
$name = substr($id,0, -1*strlen($ext[0])-1);
$fn = $conf['mediaolddir'].'/'.utf8_encodeFN($name .'.'.( (int) $rev ).'.'.$ext[0]);
}
return $fn;

View file

@ -137,6 +137,7 @@ class Doku_Plugin_Controller {
// the plugin was disabled by rc2009-01-26
// disabling mechanism was changed back very soon again
// to keep everything simple we just skip the plugin completely
continue;
} elseif (@file_exists(DOKU_PLUGIN.$plugin.'/disabled')) {
// treat this as a default disabled plugin(over-rideable by the plugin manager)
// deprecated 2011-09-10 (usage of disabled files)

View file

@ -994,7 +994,7 @@ function tpl_img($maxwidth=0,$maxheight=0,$link=true,$params=null){
/**
* Default action for TPL_IMG_DISPLAY
*/
function _tpl_img_action($data, $param=NULL) {
function _tpl_img_action($data, $param=null) {
global $lang;
$p = buildAttributes($data['params']);

View file

@ -526,7 +526,7 @@ if(!function_exists('utf8_decode_numeric')){
if(!class_exists('utf8_entity_decoder')){
class utf8_entity_decoder {
var $table;
function utf8_entity_decoder() {
function __construct() {
$table = get_html_translation_table(HTML_ENTITIES);
$table = array_flip($table);
$this->table = array_map(array(&$this,'makeutf8'), $table);