From 15fae1076f4439c7cd1302494a48e24f707a3020 Mon Sep 17 00:00:00 2001 From: andi Date: Fri, 14 Jan 2005 17:40:57 +0100 Subject: phpdoc comments darcs-hash:20050114164057-9977f-e4936fde9037c65c3f32c30b31b2b7df35732f3a.gz --- doku.php | 7 ++ feed.php | 32 +++++-- inc/DifferenceEngine.php | 24 +++--- inc/auth.php | 137 +++++++++++++++++++++--------- inc/auth_ldap.php | 30 +++++-- inc/auth_mysql.php | 26 ++++-- inc/auth_plain.php | 35 +++++--- inc/common.php | 210 ++++++++++++++++++++++++++++++++++------------ inc/feedcreator.class.php | 2 +- inc/format.php | 64 ++++++++++++-- inc/html.php | 119 +++++++++++++++++++++++++- inc/io.php | 37 +++++--- inc/parser.php | 94 +++++++++++++++++---- inc/search.php | 38 ++++++++- index.php | 8 +- lang/da/lang.php | 7 ++ lang/de/lang.php | 8 ++ lang/en/lang.php | 7 ++ lang/es/lang.php | 6 ++ lang/eu/lang.php | 6 ++ lang/fi/lang.php | 6 ++ lang/fr/lang.php | 9 ++ lang/nl/lang.php | 8 +- lang/no/lang.php | 6 ++ lang/pl/lang.php | 6 ++ lang/pt/lang.php | 6 ++ lang/pt/register.txt | 2 +- lang/ru/lang.php | 6 ++ lang/sv/lang.php | 6 ++ lang/tw/lang.old.php | 99 ---------------------- lang/tw/lang.php | 7 +- 31 files changed, 781 insertions(+), 277 deletions(-) delete mode 100644 lang/tw/lang.old.php diff --git a/doku.php b/doku.php index aa38b95cc..a62ff85f7 100644 --- a/doku.php +++ b/doku.php @@ -1,4 +1,11 @@ + */ + define('DOKUWIKIVERSION','2004-01-13'); ini_set('short_open_tag',"1"); diff --git a/feed.php b/feed.php index 66d694f53..19d6729c2 100644 --- a/feed.php +++ b/feed.php @@ -1,4 +1,11 @@ + */ + ini_set('short_open_tag',"1"); require_once("inc/common.php"); require_once("inc/parser.php"); @@ -54,12 +61,14 @@ header('Content-Type: application/xml; charset='.$lang['encoding']); print $rss->createFeed($type,$lang['encoding']); +// ---------------------------------------------------------------- // - -/* some functions */ - +/** + * Add recent changed to a feed object + * + * @author Andreas Gohr + */ function rssRecentChanges(&$rss,$num){ - $recents = getRecents($num); foreach(array_keys($recents) as $id){ $desc = cleanDesc(parsedWiki($id)); @@ -84,7 +93,12 @@ function rssRecentChanges(&$rss,$num){ $rss->addItem($item); } } - + +/** + * Add all pages of a namespace to a feedobject + * + * @author Andreas Gohr + */ function rssListNamespace(&$rss,$ns){ require_once("inc/search.php"); global $conf; @@ -108,6 +122,14 @@ function rssListNamespace(&$rss,$ns){ } } +/** + * Clean description for feed inclusion + * + * Removes HTML tags and line breaks and trims the text to + * 250 chars + * + * @author Andreas Gohr + */ function cleanDesc($desc){ //remove TOC $desc = strip_tags($desc); diff --git a/inc/DifferenceEngine.php b/inc/DifferenceEngine.php index a4af4b193..6a0b6d176 100644 --- a/inc/DifferenceEngine.php +++ b/inc/DifferenceEngine.php @@ -1,11 +1,12 @@ -// You may copy this code freely under the conditions of the GPL. -// - +/** + * A PHP diff engine for phpwiki. (Taken from phpwiki-1.3.3) + * + * Additions by Axel Boldt for MediaWiki + * + * @copyright (C) 2000, 2001 Geoffrey T. Dairiki + * @license You may copy this code freely under the conditions of the GPL. + */ define('USE_ASSERTS', function_exists('assert')); class _DiffOp { @@ -191,7 +192,8 @@ class _DiffEngine } - /* Divide the Largest Common Subsequence (LCS) of the sequences + /** + * Divide the Largest Common Subsequence (LCS) of the sequences * [XOFF, XLIM) and [YOFF, YLIM) into NCHUNKS approximately equally * sized segments. * @@ -306,7 +308,8 @@ class _DiffEngine return $end; } - /* Find LCS of two sequences. + /** + * Find LCS of two sequences. * * The results are recorded in the vectors $this->{x,y}changed[], by * storing a 1 in the element for each line that is an insertion @@ -362,7 +365,8 @@ class _DiffEngine } } - /* Adjust inserts/deletes of identical lines to join changes + /** + * Adjust inserts/deletes of identical lines to join changes * as much as possible. * * We do something when a run of changed lines include a diff --git a/inc/auth.php b/inc/auth.php index a34fc0a47..3db9cc21a 100644 --- a/inc/auth.php +++ b/inc/auth.php @@ -1,40 +1,61 @@ + */ + + require_once("inc/common.php"); + require_once("inc/io.php"); + require_once("inc/blowfish.php"); + // load the the auth functions + require_once('inc/auth_'.$conf['authtype'].'.php'); + + // some ACL level defines + define('AUTH_NONE',0); + define('AUTH_READ',1); + define('AUTH_EDIT',2); + define('AUTH_CREATE',4); + define('AUTH_UPLOAD',8); + define('AUTH_GRANT',255); + + if($conf['useacl']){ + auth_login($_REQUEST['u'],$_REQUEST['p'],$_REQUEST['r']); + // load ACL into a global array + $AUTH_ACL = file('conf/acl.auth'); + } /** * This tries to login the user based on the sent auth credentials * - * FIXME: Description no longer valid! - * * The authentication works like this: if a username was given - * a new login is assumed and user/password are checked - if they - * are correct a random authtoken is created which is stored in - * the session _and_ in a cookie. - * The user stays logged in as long as the session and the cookie - * match. This still isn't the securest method but requires an - * attacker to steal an existing session _and_ the authtoken - * cookie. The actual password is only transfered once per login. - * + * a new login is assumed and user/password are checked. If they + * are correct the password is encrypted with blowfish and stored + * together with the username in a cookie - the same info is stored + * in the session, too. Additonally a browserID is stored in the + * session. + * + * If no username was given the cookie is checked: if the username, + * crypted password and browserID match between session and cookie + * no further testing is done and the user is accepted + * + * If a cookie was found but no session info was availabe the + * blowish encrypted password from the cookie is decrypted and + * together with username rechecked by calling this function again. + * * On a successful login $_SERVER[REMOTE_USER] and $USERINFO * are set. + * + * @author Andreas Gohr + * + * @param string $user Username + * @param string $pass Cleartext Password + * @param bool $sticky Cookie should not expire + * @return bool true on successful auth */ function auth_login($user,$pass,$sticky=false){ global $USERINFO; @@ -72,7 +93,7 @@ function auth_login($user,$pass,$sticky=false){ $cookie = base64_decode($_COOKIE['DokuWikiAUTH']); list($user,$sticky,$pass) = split('\|',$cookie,3); // get session info - $session = $_SESSION[$conf['title']]['auth']; + $session = $_SESSION[$conf['title']]['auth']; if($user && $pass){ // we got a cookie - see if we can trust it @@ -100,6 +121,10 @@ function auth_login($user,$pass,$sticky=false){ * * This is neither unique nor unfakable - still it adds some * security + * + * @author Andreas Gohr + * + * @return string a MD5 sum of various browser headers */ function auth_browseruid(){ $uid = ''; @@ -112,6 +137,15 @@ function auth_browseruid(){ /** * Creates a random key to encrypt the password in cookies + * + * This function tries to read the password for encrypting + * cookies from $conf['datadir'].'/.cache/cookiesalt' + * if no such file is found a random key is created and + * and stored in this file. + * + * @author Andreas Gohr + * + * @return string */ function auth_cookiesalt(){ global $conf; @@ -127,6 +161,8 @@ function auth_cookiesalt(){ /** * This clears all authenticationdata and thus log the user * off + * + * @author Andreas Gohr */ function auth_logoff(){ global $conf; @@ -140,7 +176,14 @@ function auth_logoff(){ } /** - * Convinience function for auth_aclcheck + * Convinience function for auth_aclcheck() + * + * This checks the permissions for the current user + * + * @author Andreas Gohr + * + * @param string $id page ID + * @return int permission level */ function auth_quickaclcheck($id){ global $conf; @@ -153,6 +196,13 @@ function auth_quickaclcheck($id){ /** * Returns the maximum rights a user has for * the given ID or its namespace + * + * @author Andreas Gohr + * + * @param string $id page ID + * @param string $user Username + * @param array $groups Array of groups the user is in + * @return int permission level */ function auth_aclcheck($id,$user,$groups){ global $conf; @@ -234,7 +284,10 @@ function auth_aclcheck($id,$user,$groups){ /** * Create a pronouncable password * - * @see: http://www.phpbuilder.com/annotate/message.php3?id=1014451 + * @author Andreas Gohr + * @link http://www.phpbuilder.com/annotate/message.php3?id=1014451 + * + * @return string pronouncable password */ function auth_pwgen(){ $pw = ''; @@ -257,7 +310,9 @@ function auth_pwgen(){ /** * Sends a password to the given user * - * returns true on success + * @author Andreas Gohr + * + * @return bool true on success */ function auth_sendPassword($user,$password){ global $conf; @@ -281,10 +336,13 @@ function auth_sendPassword($user,$password){ } /** - * The new user registration - we get our info directly from - * $_POST + * Register a new user + * + * This registers a new user - Data is read directly from $_POST * - * It returns true on success and false on any error + * @author Andreas Gohr + * + * @return bool true on success, false on any error */ function register(){ global $lang; @@ -333,9 +391,12 @@ function register(){ /** * Uses a regular expresion to check if a given mail address is valid * - * @see http://www.webmasterworld.com/forum88/135.htm - * * May not be completly RFC conform! + * + * @link http://www.webmasterworld.com/forum88/135.htm + * + * @param string $email the address to check + * @return bool true if address is valid */ function isvalidemail($email){ return eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,4}$", $email); diff --git a/inc/auth_ldap.php b/inc/auth_ldap.php index 2872e710f..c1ff55706 100644 --- a/inc/auth_ldap.php +++ b/inc/auth_ldap.php @@ -1,15 +1,21 @@ */ /** - * connects to the ldap server and holds the connection - * in global scope for multiple use + * Connect to the LDAP server + * + * Holds the connection in global scope for multiple use + * + * @author Andreas Gohr */ function auth_ldap_connect(){ global $LDAP_CONNECTION; @@ -34,12 +40,14 @@ function auth_ldap_connect(){ } /** - * required auth function + * Check user+password [required auth function] * * Checks if the given user exists and the given - * plaintext password is correct + * plaintext password is correct by trying to bind + * to the LDAP server * - * It does so by trying to connect to the LDAP server + * @author Andreas Gohr + * @return bool */ function auth_checkPass($user,$pass){ global $conf; @@ -62,7 +70,7 @@ function auth_checkPass($user,$pass){ } /** - * Required auth function + * Return user info [required auth function] * * Returns info about the given user needs to contain * at least these fields: @@ -72,10 +80,12 @@ function auth_checkPass($user,$pass){ * grps array list of groups the user is in * * This LDAP specific function returns the following - * addional fields + * addional fields: * * dn string distinguished name (DN) * uid string Posix User ID + * + * @author Andreas Gohr */ function auth_getUserData($user){ global $conf; @@ -125,9 +135,11 @@ function auth_getUserData($user){ } /** - * Required auth function + * Create a new User [required auth function] * * Not implemented + * + * @author Andreas Gohr */ function auth_createUser($user,$name,$mail){ msg("Sorry. Creating users is not supported by the LDAP backend",-1); diff --git a/inc/auth_mysql.php b/inc/auth_mysql.php index 213c4a852..46e175c17 100644 --- a/inc/auth_mysql.php +++ b/inc/auth_mysql.php @@ -1,14 +1,21 @@ */ /** + * Execute SQL + * * Executes SQL statements and returns the results as list * of hashes. Returns false on error. Returns auto_increment * IDs on INSERT statements. + * + * @author Andreas Gohr */ function auth_mysql_runsql($sql_string) { global $conf; @@ -41,9 +48,13 @@ function auth_mysql_runsql($sql_string) { } /** - * required auth function + * Check user+password [required auth function] * - * Checks if a user with the given password exists + * Checks if the given user exists and the given + * plaintext password is correct + * + * @author Andreas Gohr + * @return bool */ function auth_checkPass($user,$pass){ global $conf; @@ -56,7 +67,7 @@ function auth_checkPass($user,$pass){ } /** - * Required auth function + * Return user info [required auth function] * * Returns info about the given user needs to contain * at least these fields: @@ -65,6 +76,7 @@ function auth_checkPass($user,$pass){ * mail string email addres of the user * grps array list of groups the user is in * + * @author Andreas Gohr */ function auth_getUserData($user){ global $conf; @@ -86,9 +98,11 @@ function auth_getUserData($user){ } /** - * Required auth function + * Create a new User [required auth function] * * Not implemented + * + * @author Andreas Gohr */ function auth_createUser($user,$name,$mail){ msg("Sorry. Creating users is not supported by the MySQL backend, yet",-1); diff --git a/inc/auth_plain.php b/inc/auth_plain.php index 2b45b94ca..4213b8dcc 100644 --- a/inc/auth_plain.php +++ b/inc/auth_plain.php @@ -1,21 +1,28 @@ */ /** - * required auth function + * Check user+password [required auth function] * * Checks if the given user exists and the given * plaintext password is correct + * + * @author Andreas Gohr + * @return bool */ function auth_checkPass($user,$pass){ - $users = auth_loadUserData(); + $users = auth_plain_loadUserData(); $pass = md5($pass); //encode pass if($users[$user]['pass'] == $pass){ @@ -26,7 +33,7 @@ function auth_checkPass($user,$pass){ } /** - * Required auth function + * Return user info [required auth function] * * Returns info about the given user needs to contain * at least these fields: @@ -34,16 +41,16 @@ function auth_checkPass($user,$pass){ * 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 */ function auth_getUserData($user){ - $users = auth_loadUserData(); + $users = auth_plain_loadUserData(); return $users[$user]; } /** - * Required auth function - * - * Creates a new user. + * Create a new User [required auth function] * * Returns false if the user already exists, null when an error * occured and the cleartext password of the new user if @@ -51,11 +58,13 @@ function auth_getUserData($user){ * * The new user HAS TO be added to the default group by this * function! + * + * @author Andreas Gohr */ function auth_createUser($user,$name,$mail){ global $conf; - $users = auth_loadUserData(); + $users = auth_plain_loadUserData(); if(isset($users[$user])) return false; $pass = auth_pwgen(); @@ -76,10 +85,14 @@ function auth_createUser($user,$name,$mail){ } /** - * used by the plaintext auth functions + * Load all user data + * + * Used by the plaintext auth functions * loads the user file into a datastructure + * + * @author Andreas Gohr */ -function auth_loadUserData(){ +function auth_plain_loadUserData(){ $data = array(); $lines = file('conf/users.auth'); foreach($lines as $line){ diff --git a/inc/common.php b/inc/common.php index c64d08898..5098b76de 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1,29 +1,46 @@ + */ -//set up error reporting to sane values -error_reporting(E_ALL ^ E_NOTICE); + require_once("conf/dokuwiki.php"); + require_once("inc/io.php"); -//make session rewrites XHTML compliant -ini_set('arg_separator.output', '&'); + //set up error reporting to sane values + error_reporting(E_ALL ^ E_NOTICE); -//init session -session_name("DokuWiki"); -session_start(); + //make session rewrites XHTML compliant + ini_set('arg_separator.output', '&'); -//kill magic quotes -if (get_magic_quotes_gpc()) { - if (!empty($_GET)) remove_magic_quotes($_GET); - if (!empty($_POST)) remove_magic_quotes($_POST); - if (!empty($_COOKIE)) remove_magic_quotes($_COOKIE); - if (!empty($_REQUEST)) remove_magic_quotes($_REQUEST); - if (!empty($_SESSION)) remove_magic_quotes($_SESSION); - ini_set('magic_quotes_gpc', 0); -} -set_magic_quotes_runtime(0); -ini_set('magic_quotes_sybase',0); + //init session + session_name("DokuWiki"); + session_start(); + + //kill magic quotes + if (get_magic_quotes_gpc()) { + if (!empty($_GET)) remove_magic_quotes($_GET); + if (!empty($_POST)) remove_magic_quotes($_POST); + if (!empty($_COOKIE)) remove_magic_quotes($_COOKIE); + if (!empty($_REQUEST)) remove_magic_quotes($_REQUEST); + if (!empty($_SESSION)) remove_magic_quotes($_SESSION); + ini_set('magic_quotes_gpc', 0); + } + set_magic_quotes_runtime(0); + ini_set('magic_quotes_sybase',0); + + //disable gzip if not available + if($conf['usegzip'] && !function_exists('gzopen')){ + $conf['usegzip'] = 0; + } +/** + * remove magic quotes recursivly + * + * @author Andreas Gohr + */ function remove_magic_quotes(&$array) { foreach (array_keys($array) as $key) { if (is_array($array[$key])) { @@ -34,16 +51,11 @@ function remove_magic_quotes(&$array) { } } -//disable gzip if not available -if($conf['usegzip'] && !function_exists('gzopen')){ - $conf['usegzip'] = 0; -} - -/* ---------------------------------------------------------------------------------- */ - /** - * This returns the full absolute URL to the directory where + * Returns the full absolute URL to the directory where * DokuWiki is installed in (includes a trailing slash) + * + * @author Andreas Gohr */ function getBaseURL($abs=false){ global $conf; @@ -83,8 +95,10 @@ function getBaseURL($abs=false){ } /** - * Returns info about the current document as associative + * Return info about the current document as associative * array. + * + * @author Andreas Gohr */ function pageinfo(){ global $ID; @@ -134,6 +148,8 @@ function pageinfo(){ * -1 error * 0 info * 1 success + * + * @author Andreas Gohr */ function msg($message,$lvl=0){ global $MSG; @@ -146,7 +162,9 @@ function msg($message,$lvl=0){ } /** - * This builds the breadcrumbstrail and returns it as array + * This builds the breadcrumb trail and returns it as array + * + * @author Andreas Gohr */ function breadcrumbs(){ global $ID; @@ -181,9 +199,13 @@ function breadcrumbs(){ } /** + * Filter for page IDs + * * This is run on a ID before it is outputted somewhere * currently used to replace the colon with something else * on Windows systems and to have proper URL encoding + * + * @author Andreas Gohr */ function idfilter($id){ global $conf; @@ -201,6 +223,8 @@ function idfilter($id){ /** * This builds a link to a wikipage (using getBaseURL) + * + * @author Andreas Gohr */ function wl($id='',$more='',$script='doku.php',$canonical=false){ global $conf; @@ -223,6 +247,8 @@ function wl($id='',$more='',$script='doku.php',$canonical=false){ /** * Just builds a link to a script + * + * @author Andreas Gohr */ function script($script='doku.php'){ $link = getBaseURL(); @@ -232,6 +258,8 @@ function script($script='doku.php'){ /** * Return namespacepart of a wiki ID + * + * @author Andreas Gohr */ function getNS($id){ if(strpos($id,':')!==false){ @@ -241,15 +269,21 @@ function getNS($id){ } /** - * Returns the id without the namespace + * Returns the ID without the namespace + * + * @author Andreas Gohr */ function noNS($id){ return preg_replace('/.*:/','',$id); } /** + * Spamcheck against wordlist + * * Checks the wikitext against a list of blocked expressions * returns true if the text contains any bad words + * + * @author Andreas Gohr */ function checkwordblock(){ global $TEXT; @@ -271,8 +305,11 @@ function checkwordblock(){ } /** - * Returns the IP of the client including X-Forwarded-For - * Proxy Headers + * Return the IP of the client + * + * Honours X-Forwarded-For Proxy Headers + * + * @author Andreas Gohr */ function clientIP(){ $my = $_SERVER['REMOTE_ADDR']; @@ -283,8 +320,11 @@ function clientIP(){ } /** - * Checks if a given page is currently locked by anyone for editing. + * Checks if a given page is currently locked. + * * removes stale lockfiles + * + * @author Andreas Gohr */ function checklock($id){ global $conf; @@ -309,7 +349,9 @@ function checklock($id){ } /** - * Locks a page for editing + * Lock a page for editing + * + * @author Andreas Gohr */ function lock($id){ $lock = wikiFN($id).'.lock'; @@ -321,9 +363,10 @@ function lock($id){ } /** - * Unlocks a page if it was locked by the user + * Unlock a page if it was locked by the user * - * return true if a lock was removed + * @author Andreas Gohr + * @return bool true if a lock was removed */ function unlock($id){ $lock = wikiFN($id).'.lock'; @@ -338,8 +381,12 @@ function unlock($id){ } /** + * Remove unwanted chars from ID + * * Cleans a given ID to only use allowed characters. Accented characters are * converted to unaccented ones + * + * @author Andreas Gohr */ function cleanID($id){ global $conf; @@ -382,6 +429,8 @@ function cleanID($id){ /** * returns the full path to the datafile specified by ID and * optional revision + * + * @author Andreas Gohr */ function wikiFN($id,$rev=''){ global $conf; @@ -403,6 +452,8 @@ function wikiFN($id,$rev=''){ /** * Returns the full filepath to a localized textfile if local * version isn't found the english one is returned + * + * @author Andreas Gohr */ function localeFN($id){ global $conf; @@ -417,7 +468,8 @@ function localeFN($id){ /** * convert line ending to unix format * - * @see: formText() for 2crlf conversion + * @see formText() for 2crlf conversion + * @author Andreas Gohr */ function cleanText($text){ $text = preg_replace("/(\015\012)|(\015)/","\012",$text); @@ -429,7 +481,8 @@ function cleanText($text){ * It also converts line endings to Windows format which is * pseudo standard for webforms. * - * @see: cleanText() for 2unix conversion + * @see cleanText() for 2unix conversion + * @author Andreas Gohr */ function formText($text){ $text = preg_replace("/\012/","\015\012",$text); @@ -437,7 +490,9 @@ function formText($text){ } /** - * Returns the specified textfile in parsed format + * Returns the specified local text in parsed format + * + * @author Andreas Gohr */ function parsedLocale($id){ //disable section editing @@ -452,7 +507,9 @@ function parsedLocale($id){ } /** - * Returns the specified textfile in parsed format + * Returns the specified local text in raw format + * + * @author Andreas Gohr */ function rawLocale($id){ return io_readFile(localeFN($id)); @@ -460,8 +517,12 @@ function rawLocale($id){ /** - * Returns the parsed Wikitext for the given id and revision. If $excuse - * is true an explanation is returned if the file wasn't found + * Returns the parsed Wikitext for the given id and revision. + * + * If $excuse is true an explanation is returned if the file + * wasn't found + * + * @author Andreas Gohr */ function parsedWiki($id,$rev='',$excuse=true){ $file = wikiFN($id,$rev); @@ -489,15 +550,21 @@ function parsedWiki($id,$rev='',$excuse=true){ /** * Returns the raw WikiText + * + * @author Andreas Gohr */ function rawWiki($id,$rev=''){ return io_readFile(wikiFN($id,$rev)); } /** - * Returns the raw Wiki Text in three slices. The range parameter - * Need to have the form "from-to" and gives the range of the section. + * Returns the raw Wiki Text in three slices. + * + * The range parameter needs to have the form "from-to" + * and gives the range of the section. * The returned order is prefix, section and suffix. + * + * @author Andreas Gohr */ function rawWikiSlices($range,$id,$rev=''){ list($from,$to) = split('-',$range,2); @@ -514,9 +581,13 @@ function rawWikiSlices($range,$id,$rev=''){ } /** + * Joins wiki text slices + * * function to join the text slices with correct lineendings again. * When the pretty parameter is set to true it adds additional empty * lines between sections if needed (used on saving). + * + * @author Andreas Gohr */ function con($pre,$text,$suf,$pretty=false){ @@ -531,7 +602,11 @@ function con($pre,$text,$suf,$pretty=false){ } /** + * print debug messages + * * little function to print the content of a var + * + * @author Andreas Gohr */ function dbg($msg,$hidden=false){ (!$hidden) ? print '
' : print "