function MakeUTF8PageName($basepage, $x) { global $PagePathFmt; $PageNameChars = '-\\w\\x80-\\xff'; if (!preg_match('/(?:([^.\\/]+)[.\\/])?([^.\\/]+)$/', $x, $m)) { return ''; } $name = preg_replace("/[^{$PageNameChars}]+/", ' ', $m[2]); $name = preg_replace('/(?<=^| )(.)/eu', "mb_strtoupper('\$1','UTF-8')", $name); $name = str_replace(' ', '', $name); if ($m[1]) { $group = preg_replace("/[^{$PageNameChars}]+/", ' ', $m[1]); $group = preg_replace('/(?<=^| )(.)/eu', "mb_strtoupper('\$1','UTF-8')", $group); $group = str_replace(' ', '', $group); return "{$group}.{$name}"; } foreach ((array) $PagePathFmt as $pg) { $pn = FmtPageName(str_replace('$1', $name, $pg), $basepage); if (PageExists($pn)) { return $pn; } } $group = preg_replace('/[\\/.].*$/', '', $basepage); return "{$group}.{$name}"; }
function HandleCrypt($pagename, $auth='read') { global $ScriptUrl,$HTMLStartFmt,$HTMLEndFmt; PrintFmt($pagename,$HTMLStartFmt); $passwd = stripmagic(@$_POST["passwd"]); echo FmtPageName( "<form action='{\$ScriptUrl}' method='POST'><p> Enter password to encrypt: <input type='text' name='passwd' value='" . PHSC($passwd, ENT_QUOTES) ."' /> <input type='submit' /> <input type='hidden' name='n' value='{\$FullName}' /> <input type='hidden' name='action' value='crypt' /></p></form>", $pagename); if ($passwd) { $crypt = pmcrypt($passwd); echo "<p class='vspace'>Encrypted password = $crypt</p>"; echo "<p class='vspace'>To set a site-wide password, insert the line below in your <i>config.php</i> file, <br />replacing <tt>'type'</tt> with one of <tt>'admin'</tt>, <tt>'read'</tt>, <tt>'edit'</tt>, or <tt>'attr'</tt>. <br />See <a href='$ScriptUrl?n=PmWiki.PasswordsAdmin'>PasswordsAdmin</a> for more details.</p> <pre class='vspace'> \$DefaultPasswords['type']='$crypt';</pre>"; } PrintFmt($pagename,$HTMLEndFmt); }
function InputMarkup($pagename, $type, $args) { global $InputTags, $InputAttrs, $InputValues, $FmtV; if (!@$InputTags[$type]) { return "(:input {$type} {$args}:)"; } $opt = array_merge($InputTags[$type], ParseArgs($args)); $args = @$opt[':args']; if (!$args) { $args = array('name', 'value'); } while (count(@$opt['']) > 0 && count($args) > 0) { $opt[array_shift($args)] = array_shift($opt['']); } foreach ((array) @$opt[''] as $a) { if (!isset($opt[$a])) { $opt[$a] = $a; } } if (!isset($opt['value']) && isset($InputValues[@$opt['name']])) { $opt['value'] = $InputValues[$opt['name']]; } $attr = array(); foreach ($InputAttrs as $a) { if (!isset($opt[$a])) { continue; } $attr[] = "{$a}='" . str_replace("'", ''', $opt[$a]) . "'"; } $FmtV['$InputFormArgs'] = implode(' ', $attr); $out = FmtPageName($opt[':html'], $pagename); return preg_replace('/<(\\w+\\s)(.*)$/es', "'<\$1'.Keep(PSS('\$2'))", $out); }
function HandleApprove($pagename) { global $ApproveUrlPattern, $WhiteUrlPatterns, $ApprovedUrlPagesFmt, $action; Lock(2); $page = ReadPage($pagename); $text = preg_replace('/[()]/', '', $page['text']); preg_match_all("/{$ApproveUrlPattern}/", $text, $match); ReadApprovedUrls($pagename); $addpat = array(); foreach ($match[0] as $a) { foreach ((array) $WhiteUrlPatterns as $pat) { if (preg_match("!^{$pat}(/|\$)!", $a)) { continue 2; } } if ($action == 'approvesites') { $a = preg_replace("!^([^:]+://[^/]+).*\$!", '$1', $a); } $addpat[] = $a; } if (count($addpat) > 0) { $aname = FmtPageName($ApprovedUrlPagesFmt[0], $pagename); $apage = ReadPage($aname, ''); $new = $apage; if (substr($new['text'], -1, 1) != "\n") { $new['text'] .= "\n"; } foreach ($addpat as $pat) { $new['text'] .= " {$pat}\n"; } $_REQUEST['post'] = 'y'; PostPage($aname, $apage, $new); } Redirect($pagename); }
function LoadPageTemplate($pagename, $tfilefmt) { global $PageStartFmt, $PageEndFmt, $BasicLayoutVars, $HTMLHeaderFmt; SDV($BasicLayoutVars, array('HeaderText', 'PageHeaderFmt', 'PageLeftFmt', 'PageTitleFmt', 'PageText', 'PageRightFmt', 'PageFooterFmt')); $k = implode('', file(FmtPageName($tfilefmt, $pagename))); $sect = preg_split('#[[<]!--(/?Page[A-Za-z]+Fmt|PageText|HeaderText)--[]>]#', $k, 0, PREG_SPLIT_DELIM_CAPTURE); $PageStartFmt = array_merge(array('headers:'), preg_split('/[[<]!--((?:wiki|file|function|markup):.*?)--[]>]/s', array_shift($sect), 0, PREG_SPLIT_DELIM_CAPTURE)); $PageEndFmt = array(); $ps = 'PageStartFmt'; while (count($sect) > 0) { $k = array_shift($sect); $v = preg_split('/[[<]!--((?:wiki|file|function|markup):.*?)--[]>]/', array_shift($sect), 0, PREG_SPLIT_DELIM_CAPTURE); if (substr($k, 0, 1) == '/') { $GLOBALS[$ps][] = "<!--{$k}-->"; $GLOBALS[$ps][] = count($v) > 1 ? $v : $v[0]; continue; } $GLOBALS[$k] = count($v) > 1 ? $v : $v[0]; if (in_array($k, $BasicLayoutVars)) { $GLOBALS[$ps][] = "<!--{$k}-->"; if ($k == 'PageText') { $ps = 'PageEndFmt'; } if ($k == 'HeaderText') { $GLOBALS[$ps][] =& $HTMLHeaderFmt; } $GLOBALS[$ps][] =& $GLOBALS[$k]; } } array_push($PageStartFmt, "\n<div id='wikitext'>\n"); array_unshift($PageEndFmt, '</div>'); }
function FPLByGroup($pagename, &$matches, $opt) { global $FPLByGroupStartFmt, $FPLByGroupEndFmt, $FPLByGroupGFmt, $FPLByGroupIFmt, $FPLByGroupOpt; SDV($FPLByGroupStartFmt, "<dl class='fplbygroup'>"); SDV($FPLByGroupEndFmt, '</dl>'); SDV($FPLByGroupGFmt, "<dt><a href='\$ScriptUrl/\$Group'>\$Group</a> /</dt>\n"); SDV($FPLByGroupIFmt, "<dd><a href='\$PageUrl'>\$Name</a></dd>\n"); SDVA($FPLByGroupOpt, array('readf' => 0, 'order' => 'name')); $matches = MakePageList($pagename, array_merge((array) $FPLByGroupOpt, $opt), 0); if (@$opt['count']) { array_splice($matches, $opt['count']); } if (count($matches) < 1) { return ''; } $out = ''; foreach ($matches as $pn) { $pgroup = FmtPageName($FPLByGroupGFmt, $pn); if ($pgroup != @$lgroup) { $out .= $pgroup; $lgroup = $pgroup; } $out .= FmtPageName($FPLByGroupIFmt, $pn); } return FmtPageName($FPLByGroupStartFmt, $pagename) . $out . FmtPageName($FPLByGroupEndFmt, $pagename); }
function NewPageBox($pagename, $opt) { global $ScriptUrl; $defaults = array('base' => $pagename, 'template' => '', 'button' => 'left', 'value' => '', 'label' => FmtPageName(' $[Create a new page called:] ', $pagename)); $opt = array_merge($defaults, ParseArgs($opt)); $buttonHTML = "<input class='inputbutton newpagebutton' type='submit' value='{$opt['label']}' />"; return "<form class='newpage' action='{$ScriptUrl}' method='post'>\r\n <input type='hidden' name='n' value='{$pagename}' />\r\n <input type='hidden' name='action' value='new' />\r\n <input type='hidden' name='base' value='{$opt['base']}' />\r\n <input type='hidden' name='template' value='{$opt['template']}' />" . ($opt['button'] == "left" ? $buttonHTML : "") . "<input class='inputbox newpagetext' type='text' name='name' size='16' value=' {$opt['value']} '\r\n onfocus=\"if(this.value='{$opt['value']}') {this.value=''}\"\r\n onblur=\"if(this.value=='') {this.value='{$opt['value']}'}\" />" . ($opt['button'] == "right" ? $buttonHTML : "") . "</form>"; }
function AuthUserId($pagename, $id, $pw = NULL) { global $AuthUser, $AuthUserPageFmt, $AuthUserFunctions, $AuthId, $AuthList, $MessagesFmt; $auth = $AuthUser; $authid = ''; # load information from Site.AuthUser (or page in $AuthUserPageFmt) SDV($AuthUserPageFmt, '$SiteGroup.AuthUser'); SDVA($AuthUserFunctions, array('htpasswd' => 'AuthUserHtPasswd', 'ldap' => 'AuthUserLDAP', $id => 'AuthUserConfig')); $pn = FmtPageName($AuthUserPageFmt, $pagename); $apage = ReadPage($pn, READPAGE_CURRENT); if ($apage && preg_match_all("/\n\\s*([@\\w][^\\s:]*):(.*)/", $apage['text'], $matches, PREG_SET_ORDER)) { foreach ($matches as $m) { if (!preg_match_all('/\\bldap:\\S+|[^\\s,]+/', $m[2], $v)) { continue; } if ($m[1][0] == '@') { foreach ($v[0] as $g) { $auth[$g][] = $m[1]; } } else { $auth[$m[1]] = array_merge((array) @$auth[$m[1]], $v[0]); } } } if (is_null($pw)) { $authid = $id; } else { foreach ($AuthUserFunctions as $k => $fn) { if ($auth[$k] && $fn($pagename, $id, $pw, $auth[$k])) { $authid = $id; break; } } } if (!$authid) { $GLOBALS['InvalidLogin'] = 1; return; } if (!isset($AuthId)) { $AuthId = $authid; } @session_start(); $_SESSION['authid'] = $authid; $_SESSION['authlist']["id:{$authid}"] = 1; $_SESSION['authlist']["id:-{$authid}"] = -1; $_SESSION['authlist']["id:*"] = 1; foreach ((array) @$auth[$authid] as $g) { if ($g[0] == '@') { @($_SESSION['authlist'][$g] = 1); } } foreach ((array) @$auth['*'] as $g) { if ($g[0] == '@') { @($_SESSION['authlist'][$g] = 1); } } $AuthList = array_merge($AuthList, $_SESSION['authlist']); }
function HTTPBasicAuth($pagename, $level, $authprompt = true) { global $AuthRealmFmt, $AuthDeniedFmt, $DefaultPasswords, $AllowPassword, $GroupAttributesFmt; SDV($GroupAttributesFmt, '$Group/GroupAttributes'); SDV($AllowPassword, 'nopass'); SDV($AuthRealmFmt, $GLOBALS['WikiTitle']); SDV($AuthDeniedFmt, 'A valid password is required to access this feature.'); $page = ReadPage($pagename); if (!$page) { return false; } $passwd = @$page["passwd{$level}"]; if ($passwd == "") { $grouppg = ReadPage(FmtPageName($GroupAttributesFmt, $pagename)); $passwd = @$grouppg["passwd{$level}"]; if ($passwd == '') { $passwd = @$DefaultPasswords[$level]; } if ($passwd == '') { $passwd = @$page["passwdread"]; } if ($passwd == '') { $passwd = @$grouppg["passwdread"]; } if ($passwd == '') { $passwd = @$DefaultPasswords['read']; } } if ($passwd == '') { return $page; } if (crypt($AllowPassword, $passwd) == $passwd) { return $page; } @session_start(); if (@$_SERVER['PHP_AUTH_PW']) { @$_SESSION['authpw'][$_SERVER['PHP_AUTH_PW']]++; } $authpw = array_keys((array) @$_SESSION['authpw']); foreach (array_merge((array) $DefaultPasswords['admin'], (array) $passwd) as $pwchal) { foreach ($authpw as $pwresp) { if (@crypt($pwresp, $pwchal) == $pwchal) { return $page; } } } if (!$authprompt) { return false; } $realm = FmtPageName($AuthRealmFmt, $pagename); header("WWW-Authenticate: Basic realm=\"{$realm}\""); header("Status: 401 Unauthorized"); header("HTTP-Status: 401 Unauthorized"); PrintFmt($pagename, $AuthDeniedFmt); exit; }
function AuthUserId($pagename, $id, $pw=NULL) { global $AuthUser, $AuthUserPageFmt, $AuthUserFunctions, $AuthId, $MessagesFmt, $AuthUserPat; $auth = array(); foreach((array)$AuthUser as $k=>$v) $auth[$k] = (array)$v; $authid = ''; # load information from SiteAdmin.AuthUser (or page in $AuthUserPageFmt) SDV($AuthUserPageFmt, '$SiteAdminGroup.AuthUser'); SDVA($AuthUserFunctions, array( 'htpasswd' => 'AuthUserHtPasswd', 'ldap' => 'AuthUserLDAP', # 'mysql' => 'AuthUserMySQL', $id => 'AuthUserConfig')); SDV($AuthUserPat, "/^\\s*([@\\w][^\\s:]*):(.*)/m"); $pn = FmtPageName($AuthUserPageFmt, $pagename); $apage = ReadPage($pn, READPAGE_CURRENT); if ($apage && preg_match_all($AuthUserPat, $apage['text'], $matches, PREG_SET_ORDER)) { foreach($matches as $m) { if (!preg_match_all('/\\bldaps?:\\S+|[^\\s,]+/', $m[2], $v)) continue; if ($m[1]{0} == '@') foreach($v[0] as $g) $auth[$g][] = $m[1]; else $auth[$m[1]] = array_merge((array)@$auth[$m[1]], $v[0]); } } if (func_num_args()==2) $authid = $id; else foreach($AuthUserFunctions as $k => $fn) if (@$auth[$k] && $fn($pagename, $id, $pw, $auth[$k], $authlist)) { $authid = $id; break; } if (!$authid) { $GLOBALS['InvalidLogin'] = 1; return; } if (!isset($AuthId)) $AuthId = $authid; $authlist["id:$authid"] = 1; $authlist["id:-$authid"] = -1; foreach(preg_grep('/^@/', (array)@$auth[$authid]) as $g) $authlist[$g] = 1; foreach(preg_grep('/^@/', (array)@$auth['*']) as $g) $authlist[$g] = 1; foreach(preg_grep('/^@/', array_keys($auth)) as $g) # useless? PITS:01201 if (in_array($authid, $auth[$g])) $authlist[$g] = 1; if ($auth['htgroup']) { foreach(AuthUserHtGroup($pagename, $id, $pw, $auth['htgroup']) as $g) $authlist["@$g"] = 1; } foreach(preg_grep('/^@/', (array)@$auth["-$authid"]) as $g) unset($authlist[$g]); SessionAuth($pagename, array('authid' => $authid, 'authlist' => $authlist)); }
function HTTPBasicAuthPrompt($pagename) { global $AuthRealmFmt, $AuthDeniedFmt; SDV($AuthRealmFmt, $GLOBALS['WikiTitle']); SDV($AuthDeniedFmt, 'A valid password is required to access this feature.'); $realm = FmtPageName($AuthRealmFmt, $pagename); header("WWW-Authenticate: Basic realm=\"{$realm}\""); header("Status: 401 Unauthorized"); header("HTTP-Status: 401 Unauthorized"); PrintFmt($pagename, $AuthDeniedFmt); exit; }
function VarIndexList($pagename) { global $VarIndex; if (!isset($VarIndex)) VarIndexLoad($pagename); ksort($VarIndex); $out = "<table><tr><th>Variable</th><th>Documented in</th></tr>\n"; foreach($VarIndex as $v=>$a) $out .= FmtPageName("<tr><td><a class='varlink' href='{$a['url']}'><code>$$v</code></a></td><td><a href='{\$PageUrl}'>{\$Name}</a></td></tr>\n",$a['pagename']); $out .= "</table>"; return $out; }
function MailPosts($pagename, &$page, &$new) { global $IsPagePosted, $MailPostsFile, $MailPostsTimeFmt, $Now, $MailPostsItemFmt, $PostTime; if (!$IsPagePosted) { return; } $fp = @fopen($MailPostsFile, "a"); if ($fp) { $PostTime = strftime($MailPostsTimeFmt, $Now); fputs($fp, urlencode(FmtPageName("{$Now} {$MailPostsItemFmt}", $pagename)) . "\n"); fclose($fp); } }
function VarIndexList() { global $VarIndex; if (!isset($VarIndex)) { VarIndexLoad(); } ksort($VarIndex); $out = "<table><tr><th>Variable</th><th>Documented in</th></tr>\n"; foreach ($VarIndex as $v => $a) { $out .= FmtPageName("<tr><td><a class='varlink' \n href='{$a['url']}'><code>${$v}</code></a></td><td><a \n href='\$PageUrl'>\$Name</a></td></tr>\n", $a['pagename']); } $out .= "</table>"; return $out; }
function FmtUploadList2($pagename, $args) { global $UploadDir, $UploadPrefixFmt, $UploadUrlFmt, $EnableUploadOverwrite, $FileListTimeFmt, $EnableDirectDownload, $HTMLStylesFmt, $FarmPubDirUrl; $HTMLStylesFmt['filelist'] = "\r\n table.filelist { padding:0; margin:0; border-spacing:0; }\r\n table.filelist td { padding:3px 0 0 0; margin:0; }\r\n .filelist a { text-decoration:underline; }\r\n .dotted { background:url({$FarmPubDirUrl}/images/dot3.png) repeat-x bottom; }\r\n .nodots { background:#feffff; }\r\n "; $opt = ParseArgs($args); if (@$opt[''][0]) { $pagename = MakePageName($pagename, $opt[''][0]); } if (@$opt['re']) { $matchre = '/^(' . $opt['re'] . ')$/i'; } if (@$opt['ext']) { $matchext = '/\\.(' . implode('|', preg_split('/\\W+/', $opt['ext'], -1, PREG_SPLIT_NO_EMPTY)) . ')$/i'; } $uploaddir = FmtPageName("{$UploadDir}{$UploadPrefixFmt}", $pagename); $uploadurl = FmtPageName(IsEnabled($EnableDirectDownload, 1) ? "{$UploadUrlFmt}{$UploadPrefixFmt}/" : "\$PageUrl?action=download&upname=", $pagename); $dirp = @opendir($uploaddir); if (!$dirp) { return ''; } $filelist = array(); while (($file = readdir($dirp)) !== false) { if ($file[0] == '.') { continue; } if (@$matchext && !preg_match(@$matchext, $file)) { continue; } if (@$matchre && !preg_match(@$matchre, $file)) { continue; } $filelist[$file] = $file; } closedir($dirp); $out = array(); #asort($filelist); $overwrite = ''; foreach ($filelist as $file => $x) { $name = PUE("{$uploadurl}{$file}"); $stat = stat("{$uploaddir}/{$file}"); if ($EnableUploadOverwrite) { $overwrite = FmtPageName("<a class='createlink'\r\n href='\$PageUrl?action=upload&upname={$file}'> Δ</a>", $pagename); } $out[] = "<tr><td class='dotted'> <a href='{$name}'>{$file}</a>{$overwrite} </td>" . "<td class='dotted' align=right><span class='nodots'>" . number_format($stat['size'] / 1024) . "Kb</span></td>" . "<td> " . strftime($FileListTimeFmt, $stat['mtime']) . "</td>" . "<tr>"; } return implode("\n", $out); }
function PmFormConfig($pagename, $target) { global $PmForm, $PmFormPageFmt; $target_args = @$PmForm[$target]; if (!$target_args) { $page = ReadPage(FmtPageName($PmFormPageFmt, $pagename)); $pat = preg_quote($target, '/'); if (preg_match("/^\\s*{$pat}\\s*:(.*)/m", @$page['text'], $match)) { $target_args = $match[1]; } } $target_args = trim($target_args); if (!$target_args) { return array(); } return ParseArgs(FmtPageName($target_args, $pagename)); }
function FPLFauxTrail($pagename, &$matches, $opt) { $matches = MakePageList($pagename, $opt, 0); // make the matches array into a number-indexed array $matches = array_values($matches); // check for a minimum count if (@$opt['min']) { if (count($matches) < $opt['min']) { return ''; } } $trailpage = '{$Group}'; if (@$opt['trailpage']) { $trailpage = $opt['trailpage']; } $label = '{$Title}'; if (@$opt['label']) { $label = $opt['label']; } $index_itemfmt = "<a href='{\$PageUrl}'>{$label}</a>"; $tp_val = FmtPageName($trailpage, $pagename); $tp_page = MakePageName($pagename, $tp_val); $itemfmt = "<a href='{\$PageUrl}'>{\$Title}</a>"; $prev_link = ''; $next_link = ''; $out = ''; for ($i = 0; $i < count($matches); $i++) { if ($matches[$i] == $pagename) { if ($i > 0) { $prev_page = $matches[$i - 1]; $prev_link = FmtPageName($itemfmt, $prev_page); } $trailindex = FmtPageName($index_itemfmt, $tp_page); if ($i + 1 < count($matches)) { $next_page = $matches[$i + 1]; $next_link = FmtPageName($itemfmt, $next_page); } $out = "<p><< {$prev_link} | {$trailindex} | {$next_link} >></p>"; break; } } return $out; }
function InputMarkup($pagename, $type, $args) { global $InputTags, $InputAttrs, $InputValues, $FmtV; if (!@$InputTags[$type]) return "(:input $type $args:)"; $opt = array_merge($InputTags[$type], ParseArgs($args)); $args = @$opt[':args']; if (!$args) $args = array('name', 'value'); while (count(@$opt['']) > 0 && count($args) > 0) $opt[array_shift($args)] = array_shift($opt['']); foreach ((array)@$opt[''] as $a) if (!isset($opt[$a])) $opt[$a] = $a; if (!isset($opt['value']) && isset($InputValues[@$opt['name']])) $opt['value'] = $InputValues[$opt['name']]; $attr = array(); foreach ($InputAttrs as $a) { if (!isset($opt[$a])) continue; $attr[] = "$a='".str_replace("'", ''', $opt[$a])."'"; } $FmtV['$InputFormArgs'] = implode(' ', $attr); $out = FmtPageName($opt[':html'], $pagename); return Keep($out); }
function linkUploadedFile ($fname) { if ($this->isRemote()) return; global $FarmD, $UploadFileFmt; $fmt = preg_replace('/\$Group\b/', '@Group@', $UploadFileFmt); $group = $this->group; if (preg_match('#^//(.*?)/(.*)$#', $fname, $m)) { $group = $m[1]; $fname = $m[2]; } else $fname = preg_replace('#^/([^/].*)$#', '$1', $fname); // remove single leading slashes $uplfname = realpath(preg_replace('/@Group@/', $group, FmtPageName($fmt, $this->pagename))) . "/$fname"; if (!$this->exists() && file_exists($uplfname)) { recursive_mkdir($this->dir()); @unlink($this->path()); // remove previous link @@ kann weg? @symlink($uplfname, $this->path()); } }
function FPLGroup($pagename, &$matches, $opt) { global $FPLGroupStartFmt, $FPLGroupIFmt, $FPLGroupEndFmt, $FPLGroupOpt; SDV($FPLGroupStartFmt, "<ul class='fplgroup'>"); SDV($FPLGroupEndFmt, "</ul>"); SDV($FPLGroupIFmt, "<li><a href='\$ScriptUrl/\$Group'>\$Group</a></li>"); SDVA($FPLGroupOpt, array('readf' => 0, 'order' => 'name')); $matches = MakePageList($pagename, array_merge((array) $FPLGroupOpt, $opt)); $out = array(); foreach ($matches as $pc) { $group = preg_replace('/\\.[^.]+$/', '', $pc['pagename']); if (@(!$seen[$group]++)) { $out[] = FmtPageName($FPLGroupIFmt, $pc['pagename']); if ($opt['count'] && count($out) >= $opt['count']) { break; } } } return FmtPageName($FPLGroupStartFmt, $pagename) . implode('', $out) . FmtPageName($FPLGroupEndFmt, $pagename); }
function AttachExist($pagename) { global $UploadDir, $UploadPrefixFmt; $uploaddir = FmtPageName("$UploadDir$UploadPrefixFmt", $pagename); $count = 0; $dirp = @opendir($uploaddir); if ($dirp) { while (($file = readdir($dirp)) !== false) if ($file{0} != '.') $count++; closedir($dirp); } return $count; }
SDV($AuthorCookieExpires, $Now + 60 * 60 * 24 * 30); SDV($AuthorCookieDir, '/'); SDV($AuthorGroup, 'Profiles'); SDV($AuthorRequiredFmt, "<h3 class='wikimessage'>\$[An author name is required.]</h3>"); Markup('[[~', '<[[', '/\\[\\[~(.*?)\\]\\]/', "[[{$AuthorGroup}/\$1]]"); if (!isset($Author)) { if (isset($_POST['author'])) { $Author = htmlspecialchars(stripmagic($_POST['author']), ENT_QUOTES); setcookie('author', $Author, $AuthorCookieExpires, $AuthorCookieDir); } else { $Author = htmlspecialchars(stripmagic(@$_COOKIE['author']), ENT_QUOTES); } $Author = preg_replace('/(^[^[:alpha:]]+)|[^-\\w ]/', '', $Author); } if (!isset($AuthorPage)) { $AuthorPage = FmtPageName('$AuthorGroup/$Name', MakePageName($pagename, $Author)); } SDV($AuthorLink, $Author ? "[[~{$Author}]]" : '?'); if (IsEnabled($EnableAuthorSignature, 1)) { $ROSPatterns['/~~~~/'] = '[[~$Author]] $CurrentTime'; $ROSPatterns['/~~~/'] = '[[~$Author]]'; Markup('~~~~', '<links', '/~~~~/', "[[~{$Author}]] {$CurrentTime}"); Markup('~~~', '>~~~~', '/~~~/', "[[~{$Author}]]"); } if (IsEnabled($EnablePostAuthorRequired, 0)) { array_unshift($EditFunctions, 'RequireAuthor'); } ## RequireAuthor forces an author to enter a name before posting. function RequireAuthor($pagename, &$page, &$new) { global $Author, $MessagesFmt, $AuthorRequiredFmt;
function pagefile($pagename) { global $FarmD; $dfmt = $this->dirfmt; if ($pagename > '') { $pagename = str_replace('/', '.', $pagename); if ($dfmt == 'wiki.d/{$FullName}') # optimizations for return "wiki.d/$pagename"; # standard locations if ($dfmt == '$FarmD/wikilib.d/{$FullName}') # return "$FarmD/wikilib.d/$pagename"; # if ($dfmt == 'wiki.d/{$Group}/{$FullName}') return preg_replace('/([^.]+).*/', 'wiki.d/$1/$0', $pagename); } return FmtPageName($dfmt, $pagename); }
function HandleRss($pagename) { global $RssMaxItems, $RssSourceSize, $RssDescSize, $RssChannelFmt, $RssChannelDesc, $RssTimeFmt, $RssChannelBuildDate, $RssItemsRDFList, $RssItemsRDFListFmt, $RssItems, $RssItemFmt, $HandleRssFmt, $FmtV; $t = ReadTrail($pagename, $pagename); $page = RetrieveAuthPage($pagename, 'read', false); if (!$page) { Abort("?cannot read {$pagename}"); } $cbgmt = $page['time']; $r = array(); for ($i = 0; $i < count($t) && count($r) < $RssMaxItems; $i++) { if (!PageExists($t[$i]['pagename'])) { continue; } $page = RetrieveAuthPage($t[$i]['pagename'], 'read', false); Lock(0); if (!$page) { continue; } $text = MarkupToHTML($t[$i]['pagename'], substr($page['text'], 0, $RssSourceSize)); $text = entityencode(preg_replace("/<.*?>/s", "", $text)); preg_match("/^(.{0,{$RssDescSize}}\\s)/s", $text, $match); $r[] = array('name' => $t[$i]['pagename'], 'time' => $page['time'], 'desc' => $match[1] . " ...", 'author' => $page['author']); if ($page['time'] > $cbgmt) { $cbgmt = $page['time']; } } SDV($RssChannelBuildDate, entityencode(gmdate('D, d M Y H:i:s \\G\\M\\T', $cbgmt))); SDV($RssChannelDesc, entityencode(FmtPageName('$Group.$Title', $pagename))); foreach ($r as $page) { $FmtV['$RssItemPubDate'] = gmstrftime($RssTimeFmt, $page['time']); $FmtV['$RssItemDesc'] = $page['desc']; $FmtV['$RssItemAuthor'] = $page['author']; $RssItemsRDFList[] = entityencode(FmtPageName($RssItemsRDFListFmt, $page['name'])); $RssItems[] = entityencode(FmtPageName($RssItemFmt, $page['name'])); } header("Content-type: text/xml"); PrintFmt($pagename, $HandleRssFmt); exit; }
function ls($pats = NULL) { global $GroupPattern, $NamePattern; $pats = (array) $pats; array_unshift($pats, "/^{$GroupPattern}\\.{$NamePattern}\$/"); $dir = FmtPageName($this->dirfmt, ''); $dirlist = array(preg_replace('!/?[^/]*\\$.*$!', '', $dir)); $out = array(); while (count($dirlist) > 0) { $dir = array_shift($dirlist); $dfp = opendir($dir); if (!$dfp) { continue; } while (($pagefile = readdir($dfp)) != false) { if (substr($pagefile, 0, 1) == '.') { continue; } if (is_dir("{$dir}/{$pagefile}")) { array_push($dirlist, "{$dir}/{$pagefile}"); continue; } if (@$seen[$pagefile]++) { continue; } foreach ($pats as $p) { if (substr($p, 0, 1) == '!') { if (preg_match($p, $pagefile)) { continue 2; } } else { if (!preg_match($p, $pagefile)) { continue 2; } } } $out[] = $pagefile; } } return $out; }
function BlocklistDownload($pagename, $dir = '') { global $BlocklistDownloadFmt, $BlocklistDownload, $FmtV; if ($dir) { flush(); chdir($dir); } SDV($BlocklistDownloadFmt, " [@ ## blocklist-note: NOTE: This page is automatically generated by blocklist.php ## blocklist-note: NOTE: Any edits to this page may be lost! ## blocklist-url: \$BlocklistDownloadUrl ## blocklist-when: \$CurrentTimeISO # blocklist-format: \$BlocklistFormat \$BlocklistData @] "); ## get the existing blocklist page $bd = &$BlocklistDownload[$pagename]; $page = ReadPage($pagename, READPAGE_CURRENT); ## try to retrieve the remote data $blocklistdata = @file($bd['url']); ## if we didn't get it, and we don't already have text, save a ## note in the page so we know what happened if (!$blocklistdata && !@$page['text']) { $auf = ini_get('allow_url_fopen'); $blocklistdata = "#### Unable to download blocklist (allow_url_fopen=$auf)"; } ## if we have some new text to save, let's format it and save it if ($blocklistdata) { $blocklistdata = implode('', (array)$blocklistdata); $blocklistdata = preg_replace('/^##blocklist.*/m', '', $blocklistdata); $FmtV['$BlocklistData'] = $blocklistdata; $FmtV['$BlocklistDownloadUrl'] = $bd['url']; $FmtV['$BlocklistFormat'] = $bd['format']; $page['text'] = FmtPageName($BlocklistDownloadFmt, $pagename); SDV($page['passwdread'], '@lock'); } ## save our updated(?) blocklist page WritePage($pagename, $page); }
function RSSEnclosure($pagename, &$page, $k) { global $RSSEnclosureFmt, $UploadFileFmt, $UploadExts; if (!function_exists('MakeUploadName')) { return ''; } SDV($RSSEnclosureFmt, array('$Name.mp3')); $encl = ''; foreach ((array) $RSSEnclosureFmt as $fmt) { $path = FmtPageName($fmt, $pagename); $upname = MakeUploadName($pagename, $path); $filepath = FmtPageName("{$UploadFileFmt}/{$upname}", $pagename); if (file_exists($filepath)) { $length = filesize($filepath); $type = @$UploadExts[preg_replace('/.*\\./', '', $filepath)]; $url = LinkUpload($pagename, 'Attach:', $path, '', '', '$LinkUrl'); $encl .= "<{$k} url='{$url}' length='{$length}' type='{$type}' />"; } } return $encl; }
function AuthUserId($pagename, $id, $pw = NULL) { global $AuthUser, $AuthUserPageFmt, $AuthUserFunctions, $AuthId, $MessagesFmt; foreach ((array) $AuthUser as $k => $v) { $auth[$k] = (array) $v; } $authid = ''; # load information from Site.AuthUser (or page in $AuthUserPageFmt) SDV($AuthUserPageFmt, '$SiteGroup.AuthUser'); SDVA($AuthUserFunctions, array('htpasswd' => 'AuthUserHtPasswd', 'ldap' => 'AuthUserLDAP', $id => 'AuthUserConfig')); $pn = FmtPageName($AuthUserPageFmt, $pagename); $apage = ReadPage($pn, READPAGE_CURRENT); if ($apage && preg_match_all("/^\\s*([@\\w][^\\s:]*):(.*)/m", $apage['text'], $matches, PREG_SET_ORDER)) { foreach ($matches as $m) { if (!preg_match_all('/\\bldaps?:\\S+|[^\\s,]+/', $m[2], $v)) { continue; } if ($m[1][0] == '@') { foreach ($v[0] as $g) { $auth[$g][] = $m[1]; } } else { $auth[$m[1]] = array_merge((array) @$auth[$m[1]], $v[0]); } } } if (is_null($pw)) { $authid = $id; } else { foreach ($AuthUserFunctions as $k => $fn) { if ($auth[$k] && $fn($pagename, $id, $pw, $auth[$k])) { $authid = $id; break; } } } if (!$authid) { $GLOBALS['InvalidLogin'] = 1; return; } if (!isset($AuthId)) { $AuthId = $authid; } $authlist["id:{$authid}"] = 1; $authlist["id:-{$authid}"] = -1; foreach (preg_grep('/^@/', (array) @$auth[$authid]) as $g) { $authlist[$g] = 1; } foreach (preg_grep('/^@/', (array) @$auth['*']) as $g) { $authlist[$g] = 1; } foreach (preg_grep('/^@/', array_keys($auth)) as $g) { if (in_array($authid, $auth[$g])) { $authlist[$g] = 1; } } if ($auth['htgroup']) { foreach (AuthUserHtGroup($pagename, $id, $pw, $auth['htgroup']) as $g) { $authlist["@{$g}"] = 1; } } SessionAuth($pagename, array('authid' => $authid, 'authlist' => $authlist)); }
function HandleUpgrade($pagename, $auth = 'ALWAYS') { global $SiteGroup, $SiteAdminGroup, $StatusPageName, $ScriptUrl, $AuthUserPageFmt, $VersionNum, $Version; StopWatch('HandleUpgrade: begin'); $message = ''; $done = ''; ## check for Site.* --> SiteAdmin.* foreach(array('AuthUser', 'NotifyList', 'Blocklist', 'ApprovedUrls') as $n) { $n0 = "$SiteGroup.$n"; $n1 = "$SiteAdminGroup.$n"; StopWatch("HandleUpgrade: checking $n0 -> $n1"); ## checking AuthUser is special, because Site.AuthUser comes with the ## distribution. if ($n == 'AuthUser') { ## if we already have a user-modified SiteAdmin.AuthUser, we can skip SDV($AuthUserPageFmt, '$SiteAdminGroup.AuthUser'); $n1 = FmtPageName($AuthUserPageFmt, $pagename); $page = ReadPage($n1, READPAGE_CURRENT); if (@$page['time'] > 1000000000) continue; ## if there's not a user-modified Site.AuthUser, we can skip $page = ReadPage($n0, READPAGE_CURRENT); if (@$page['time'] == 1000000000) continue; } else if (!PageExists($n0) || PageExists($n1)) continue; if (@$_REQUEST['migrate'] == 'yes') { ## if the admin wants PmWiki to migrate, do it. $page = RetrieveAuthPage($n0, 'admin', true); StopWatch("HandleUpgrade: copying $n0 -> $n1"); if ($page) { WritePage($n1, $page); $done .= "<li>Copied $n0 to $n1</li>"; continue; } } $message .= "<li>$n0 -> $n1</li>"; } if ($message) { $migrateurl = "$ScriptUrl?action=upgrade&migrate=yes"; $infourl = 'http://www.pmwiki.org/wiki/PmWiki/UpgradeToSiteAdmin'; $message = "<h2>Upgrade notice -- SiteAdmin group</h2> <p>This version of PmWiki expects several administrative pages from the <em>Site</em> group to be found in a new <em>SiteAdmin</em> group. On this site, the following pages appear to need to be relocated:</p> <ul>$message</ul> <p>For more information about this change, including the various options for proceeding, see</p> <blockquote><a target='_blank' href='$infourl'>$infourl</a></blockquote> <form action='$ScriptUrl' method='post'> <p>If you would like PmWiki to attempt to automatically copy these pages into their new <br /> locations for you, try <input type='hidden' name='action' value='upgrade' /> <input type='hidden' name='migrate' value='yes' /> <input type='submit' value='Relocate pages listed above' /> (admin password required) </p> </form> <p>If you want to configure PmWiki so that it continues to look for the above pages in <em>$SiteGroup</em>, add the following line near the top of <em>local/config.php</em>:</p> <blockquote><pre>\$SiteAdminGroup = \$SiteGroup;</pre></blockquote> $Version "; print $message; exit; } StopWatch("UpgradeCheck: writing $StatusPageName"); Lock(2); SDV($StatusPageName, "$SiteAdminGroup.Status"); $page = ReadPage($StatusPageName); $page['updatedto'] = $VersionNum; WritePage($StatusPageName, $page); if ($done) { $done .= "<li>Updated $StatusPageName</li>"; echo "<h2>Upgrade to $Version ... ok</h2><ul>$done</ul>"; $GLOBALS['EnableRedirect'] = 0; } Redirect($pagename); }
function PrintDiff($pagename) { global $DiffShow, $DiffStartFmt, $TimeFmt, $DiffDelFmt, $DiffAddFmt, $DiffEndDelAddFmt, $DiffEndFmt, $DiffRestoreFmt, $FmtV, $LinkFunctions; $page = ReadPage($pagename); if (!$page) { return; } krsort($page); reset($page); $lf = $LinkFunctions; $LinkFunctions['http:'] = 'LinkSuppress'; $LinkFunctions['https:'] = 'LinkSuppress'; foreach ($page as $k => $v) { if (!preg_match("/^diff:(\\d+):(\\d+):?([^:]*)/", $k, $match)) { continue; } $diffclass = $match[3]; if ($diffclass == 'minor' && $DiffShow['minor'] != 'y') { continue; } $diffgmt = $match[1]; $FmtV['$DiffTime'] = strftime($TimeFmt, $diffgmt); $diffauthor = @$page["author:{$diffgmt}"]; if (!$diffauthor) { @($diffauthor = $page["host:{$diffgmt}"]); } if (!$diffauthor) { $diffauthor = "unknown"; } $FmtV['$DiffChangeSum'] = htmlspecialchars(@$page["csum:{$diffgmt}"]); $FmtV['$DiffHost'] = @$page["host:{$diffgmt}"]; $FmtV['$DiffAuthor'] = $diffauthor; $FmtV['$DiffId'] = $k; echo FmtPageName($DiffStartFmt, $pagename); $difflines = explode("\n", $v . "\n"); $in = array(); $out = array(); $dtype = ''; foreach ($difflines as $d) { if ($d > '') { if ($d[0] == '-' || $d[0] == '\\') { continue; } if ($d[0] == '<') { $out[] = substr($d, 2); continue; } if ($d[0] == '>') { $in[] = substr($d, 2); continue; } } if (preg_match("/^(\\d+)(,(\\d+))?([adc])(\\d+)(,(\\d+))?/", $dtype, $match)) { if (@$match[7] > '') { $lines = 'lines'; $count = $match[1] . '-' . ($match[1] + $match[7] - $match[5]); } elseif ($match[3] > '') { $lines = 'lines'; $count = $match[1] . '-' . $match[3]; } else { $lines = 'line'; $count = $match[1]; } if ($match[4] == 'a' || $match[4] == 'c') { $txt = str_replace('line', $lines, $DiffDelFmt[$match[4]]); $FmtV['$DiffLines'] = $count; echo FmtPageName($txt, $pagename); if ($DiffShow['source'] == 'y') { echo "<div class='diffmarkup'>", str_replace("\n", "<br />", htmlspecialchars(join("\n", $in))), "</div>"; } else { echo MarkupToHTML($pagename, preg_replace('/\\(:(.*?):\\)/', '[@$1@]', join("\n", $in))); } } if ($match[4] == 'd' || $match[4] == 'c') { $txt = str_replace('line', $lines, $DiffAddFmt[$match[4]]); $FmtV['$DiffLines'] = $count; echo FmtPageName($txt, $pagename); if ($DiffShow['source'] == 'y') { echo "<div class='diffmarkup'>", str_replace("\n", "<br />", htmlspecialchars(join("\n", $out))), "</div>"; } else { echo MarkupToHTML($pagename, preg_replace('/(\\(:.*?:\\))/', '[@$1@]', join("\n", $out))); } } echo FmtPageName($DiffEndDelAddFmt, $pagename); } $in = array(); $out = array(); $dtype = $d; } echo FmtPageName($DiffEndFmt, $pagename); echo FmtPageName($DiffRestoreFmt, $pagename); } $LinkFunctions = $lf; }