示例#1
0
function Merge($newtext,$oldtext,$pagetext) {
  global $WorkDir,$SysMergeCmd, $SysMergePassthru;
  SDV($SysMergeCmd,"/usr/bin/diff3 -L '' -L '' -L '' -m -E");
  if (substr($newtext,-1,1)!="\n") $newtext.="\n";
  if (substr($oldtext,-1,1)!="\n") $oldtext.="\n";
  if (substr($pagetext,-1,1)!="\n") $pagetext.="\n";
  $tempnew = tempnam($WorkDir,"new");
  $tempold = tempnam($WorkDir,"old");
  $temppag = tempnam($WorkDir,"page");
  if ($newfp=fopen($tempnew,'w')) { fputs($newfp,$newtext); fclose($newfp); }
  if ($oldfp=fopen($tempold,'w')) { fputs($oldfp,$oldtext); fclose($oldfp); }
  if ($pagfp=fopen($temppag,'w')) { fputs($pagfp,$pagetext); fclose($pagfp); }
  $mergetext = '';
  if (IsEnabled($SysMergePassthru, 0)) {
    ob_start();
    passthru("$SysMergeCmd $tempnew $tempold $temppag");
    $mergetext = ob_get_clean();
  }
  else {
    $merge_handle = popen("$SysMergeCmd $tempnew $tempold $temppag",'r');
    if ($merge_handle) {
      while (!feof($merge_handle)) $mergetext .= fread($merge_handle,4096);
      pclose($merge_handle);
    }
  }
  @unlink($tempnew); @unlink($tempold); @unlink($temppag);
  return $mergetext;
}
function FastCacheUpdate($pagename, &$page, &$new)
{
    global $IsPagePosted;
    global $FastCacheDir, $FastCacheInvalidateAllOnUpdate;
    if (!$IsPagePosted || !$FastCacheDir) {
        return;
    }
    if (IsEnabled($FastCacheInvalidateAllOnUpdate, TRUE)) {
        if (is_dir($FastCacheDir) && ($fd = opendir($FastCacheDir))) {
            while (($fh = readdir($fd)) !== FALSE) {
                if ($fh[0] == '.') {
                    continue;
                }
                if (!unlink("{$FastCacheDir}/{$fh}")) {
                    StopWatch("FastCacheUpdate: error unlinking file {$FastCacheDir}/{$fh} > stopping");
                    return;
                }
            }
        } else {
            StopWatch("FastCacheUpdate: error opening directory {$FastCacheDir}");
            return;
        }
    } else {
        SDV($FastCacheSuffix, '.html');
        $fcfile = "{$FastCacheDir}/{$pagename}{$FastCacheSuffix}";
        if (is_file($fcfile)) {
            if (!unlink($fcfile)) {
                StopWatch("FastCacheUpdate: error unlinking file {$fcfile}");
            }
        }
    }
}
示例#3
0
function EditDraft(&$pagename, &$page, &$new)
{
    global $WikiDir, $DraftSuffix, $DeleteKeyPattern, $EnableDraftAtomicDiff, $DraftRecentChangesFmt, $RecentChangesFmt, $Now;
    SDV($DeleteKeyPattern, "^\\s*delete\\s*\$");
    $basename = preg_replace("/{$DraftSuffix}\$/", '', $pagename);
    $draftname = $basename . $DraftSuffix;
    if ($_POST['postdraft'] || $_POST['postedit']) {
        $pagename = $draftname;
    } else {
        if ($_POST['post'] && !preg_match("/{$DeleteKeyPattern}/", $new['text'])) {
            $pagename = $basename;
            if (IsEnabled($EnableDraftAtomicDiff, 0)) {
                $page = ReadPage($basename);
                foreach ($new as $k => $v) {
                    # delete draft history
                    if (preg_match('/:\\d+(:\\d+:)?$/', $k) && !preg_match("/:{$Now}(:\\d+:)?\$/", $k)) {
                        unset($new[$k]);
                    }
                }
                unset($new['rev']);
                SDVA($new, $page);
            }
            $WikiDir->delete($draftname);
        } else {
            if (PageExists($draftname) && $pagename != $draftname) {
                Redirect($draftname, '$PageUrl?action=edit');
                exit;
            }
        }
    }
    if ($pagename == $draftname && isset($DraftRecentChangesFmt)) {
        $RecentChangesFmt = $DraftRecentChangesFmt;
    }
}
示例#4
0
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&amp;upname={$file}'>&nbsp;&Delta;</a>", $pagename);
        }
        $out[] = "<tr><td class='dotted'> <a href='{$name}'>{$file}</a>{$overwrite} &nbsp;&nbsp;</td>" . "<td class='dotted' align=right><span class='nodots'>" . number_format($stat['size'] / 1024) . "Kb</span></td>" . "<td>&nbsp;&nbsp;&nbsp;" . strftime($FileListTimeFmt, $stat['mtime']) . "</td>" . "<tr>";
    }
    return implode("\n", $out);
}
示例#5
0
function LinkHTTP($pagename, $imap, $path, $title, $txt, $fmt = NULL)
{
    global $EnableUrlApprovalRequired, $IMap, $WhiteUrlPatterns, $FmtV, $UnapprovedLinkFmt;
    if (!IsEnabled($EnableUrlApprovalRequired, 1)) {
        return LinkIMap($pagename, $imap, $path, $title, $txt, $fmt);
    }
    static $havereadpages;
    if (!$havereadpages) {
        ReadApprovedUrls($pagename);
        $havereadpages = true;
    }
    $p = str_replace(' ', '%20', $path);
    $url = str_replace('$1', $p, $IMap[$imap]);
    foreach ((array) $WhiteUrlPatterns as $pat) {
        if (preg_match("!^{$pat}(/|\$)!", $url)) {
            return LinkIMap($pagename, $imap, $path, $title, $txt, $fmt);
        }
    }
    $FmtV['$LinkText'] = $txt;
    return FmtPageName($UnapprovedLinkFmt, $pagename);
}
示例#6
0
Markup('[[', 'links', "/(?>\\[\\[\\s*(.*?)\\]\\])({$SuffixPattern})/e", "Keep(MakeLink(\$pagename,PSS('\$1'),NULL,'\$2'),'L')");
## [[!Category]]
SDV($CategoryGroup, 'Category');
SDV($LinkCategoryFmt, "<a class='categorylink' href='\$LinkUrl'>\$LinkText</a>");
Markup('[[!', '<[[', '/\\[\\[!(.*?)\\]\\]/e', "Keep(MakeLink(\$pagename,PSS('{$CategoryGroup}/\$1'),NULL,'',\$GLOBALS['LinkCategoryFmt']),'L')");
# This is a temporary workaround for blank category pages.
# It may be removed in a future release (Pm, 2006-01-24)
if (preg_match("/^{$CategoryGroup}\\./", $pagename)) {
    SDV($DefaultPageTextFmt, '');
    SDV($PageNotFoundHeaderFmt, 'HTTP/1.1 200 Ok');
}
## [[target | text]]
Markup('[[|', '<[[', "/(?>\\[\\[([^|\\]]*)\\|\\s*)(.*?)\\s*\\]\\]({$SuffixPattern})/e", "Keep(MakeLink(\$pagename,PSS('\$1'),PSS('\$2'),'\$3'),'L')");
## [[text -> target ]]
Markup('[[->', '>[[|', "/(?>\\[\\[([^\\]]+?)\\s*-+&gt;\\s*)(.*?)\\]\\]({$SuffixPattern})/e", "Keep(MakeLink(\$pagename,PSS('\$2'),PSS('\$1'),'\$3'),'L')");
if (IsEnabled($EnableRelativePageLinks, 1)) {
    SDV($QualifyPatterns['/(\\[\\[(?>[^\\]]+?->)?\\s*)([-\\w\\s\']+([|#?].*?)?\\]\\])/e'], "PSS('\$1').\$group.PSS('/\$2')");
}
## [[#anchor]]
Markup('[[#', '<[[', '/(?>\\[\\[#([A-Za-z][-.:\\w]*))\\]\\]/e', "Keep(TrackAnchors('\$1') ? '' : \"<a name='\$1' id='\$1'></a>\", 'L')");
function TrackAnchors($x)
{
    global $SeenAnchor;
    return @$SeenAnchor[$x]++;
}
## [[target |#]] reference links
Markup('[[|#', '<[[|', "/(?>\\[\\[([^|\\]]+))\\|\\s*#\\s*\\]\\]/e", "Keep(MakeLink(\$pagename,PSS('\$1'),'['.++\$MarkupFrame[0]['ref'].']'),'L')");
## [[target |+]] title links
Markup('[[|+', '<[[|', "/(?>\\[\\[([^|\\]]+))\\|\\s*\\+\\s*]]/e", "Keep(MakeLink(\$pagename, PSS('\$1'),\n                 PageVar(MakePageName(\$pagename,PSS('\$1')), '\$Title')\n                ),'L')");
## bare urllinks
Markup('urllink', '>[[', "/\\b(?>(\\L))[^\\s{$UrlExcludeChars}]*[^\\s.,?!{$UrlExcludeChars}]/e", "Keep(MakeLink(\$pagename,'\$0','\$0'),'L')");
示例#7
0
function BlockUnapprovedPosts($pagename, &$page, &$new)
{
    global $EnableUrlApprovalRequired, $UnapprovedLinkCount, $UnapprovedLinkCountMax, $EnablePost, $MessagesFmt, $BlockMessageFmt;
    if (!IsEnabled($EnableUrlApprovalRequired, 1)) {
        return;
    }
    if ($UnapprovedLinkCount <= $UnapprovedLinkCountMax) {
        return;
    }
    if ($page['=auth']['admin']) {
        return;
    }
    $EnablePost = 0;
    $MessagesFmt[] = $BlockMessageFmt;
}
示例#8
0
function MakePageList($pagename, $opt)
{
    global $MakePageListOpt, $SearchPatterns, $EnablePageListProtect, $PCache, $FmtV;
    StopWatch('MakePageList begin');
    SDVA($MakePageListOpt, array('list' => 'default'));
    $opt = array_merge((array) $MakePageListOpt, $opt);
    $readf = $opt['readf'];
    # we have to read the page if order= is anything but name
    $order = $opt['order'];
    $readf |= $order && $order != 'name' && $order != '-name';
    $pats = @(array) $SearchPatterns[$opt['list']];
    if (@$opt['group']) {
        array_unshift($pats, "/^({$opt['group']})\\./i");
    }
    # inclp/exclp contain words to be included/excluded.
    $inclp = array();
    $exclp = array();
    foreach ((array) @$opt[''] as $i) {
        $inclp[] = '/' . preg_quote($i, '/') . '/i';
    }
    foreach ((array) @$opt['+'] as $i) {
        $inclp[] = '/' . preg_quote($i, '/') . '/i';
    }
    foreach ((array) @$opt['-'] as $i) {
        $exclp[] = '/' . preg_quote($i, '/') . '/i';
    }
    $searchterms = count($inclp) + count($exclp);
    $readf += $searchterms;
    # forced read if incl/excl
    if (@$opt['trail']) {
        $trail = ReadTrail($pagename, $opt['trail']);
        foreach ($trail as $tstop) {
            $pn = $tstop['pagename'];
            $list[] = $pn;
            $tstop['parentnames'] = array();
            PCache($pn, $tstop);
        }
        foreach ($trail as $tstop) {
            $PCache[$tstop['pagename']]['parentnames'][] = $trail[$tstop['parent']]['pagename'];
        }
    } else {
        $list = ListPages($pats);
    }
    if (IsEnabled($EnablePageListProtect, 0)) {
        $readf = 1000;
    }
    $matches = array();
    $FmtV['$MatchSearched'] = count($list);
    # link= (backlinks)
    if (@$opt['link']) {
        $link = MakePageName($pagename, $opt['link']);
        $linkpat = "/(^|,){$link}(,|\$)/i";
        $readf++;
        $xlist = BacklinksTo($link, false);
        $list = array_diff($list, $xlist);
    }
    $xlist = array();
    StopWatch('MakePageList scan');
    foreach ((array) $list as $pn) {
        if ($readf) {
            $page = $readf >= 1000 ? RetrieveAuthPage($pn, 'read', false, READPAGE_CURRENT) : ReadPage($pn, READPAGE_CURRENT);
            if (!$page) {
                continue;
            }
            if (@$linkpat && !preg_match($linkpat, @$page['targets'])) {
                $PCache[$pn]['targets'] = @$page['targets'];
                $xlist[] = $pn;
                continue;
            }
            if ($searchterms) {
                $text = $pn . "\n" . @$page['targets'] . "\n" . @$page['text'];
                foreach ($inclp as $i) {
                    if (!preg_match($i, $text)) {
                        continue 2;
                    }
                }
                foreach ($exclp as $i) {
                    if (preg_match($i, $text)) {
                        continue 2;
                    }
                }
            }
            $page['size'] = strlen(@$page['text']);
        } else {
            $page = array();
        }
        $page['pagename'] = $page['name'] = $pn;
        PCache($pn, $page);
        $matches[] =& $PCache[$pn];
    }
    StopWatch('MakePageList sort');
    SortPageList($matches, $order);
    StopWatch('MakePageList update');
    if ($xlist) {
        LinkIndexUpdate($xlist);
    }
    StopWatch('MakePageList end');
    return $matches;
}
示例#9
0
 function recode($pagename, $a) {
   if(!$a) return false;
   global $Charset, $PageRecodeFunction, $DefaultPageCharset, $EnableOldCharset;
   if (function_exists($PageRecodeFunction)) return $PageRecodeFunction($a);
   if (IsEnabled($EnableOldCharset)) $a['=oldcharset'] = @$a['charset'];
   SDVA($DefaultPageCharset, array(''=>@$Charset)); # pre-2.2.31 RecentChanges
   if (@$DefaultPageCharset[$a['charset']]>'')  # wrong pre-2.2.30 encs. *-2, *-9, *-13
     $a['charset'] = $DefaultPageCharset[@$a['charset']];
   if (!$a['charset'] || $Charset==$a['charset']) return $a;
   $from = ($a['charset']=='ISO-8859-1') ? 'WINDOWS-1252' : $a['charset'];
   $to = ($Charset=='ISO-8859-1') ? 'WINDOWS-1252' : $Charset;
   if ($this->recodefn) $F = $this->recodefn;
   elseif ($to=='UTF-8' && $from=='WINDOWS-1252') # utf8 wiki & pre-2.2.30 doc
     $F = create_function('$s,$from,$to', 'return utf8_encode($s);');
   elseif ($to=='WINDOWS-1252' && $from=='UTF-8') # 2.2.31+ documentation
     $F = create_function('$s,$from,$to', 'return utf8_decode($s);');
   else return $a;
   foreach($a as $k=>$v) $a[$k] = $F($v,$from,$to);
   $a['charset'] = $Charset;
   return $a;
 }
示例#10
0
function HandlePostAttr($pagename)
{
    global $PageAttributes, $EnablePostAttrClearSession;
    Lock(2);
    $page = RetrieveAuthPage($pagename, 'attr', true, READPAGE_CURRENT);
    if (!$page) {
        Abort("?unable to read {$pagename}");
    }
    foreach ($PageAttributes as $attr => $p) {
        $v = @$_POST[$attr];
        if ($v == '') {
            continue;
        }
        if ($v == 'clear') {
            unset($page[$attr]);
        } else {
            if (strncmp($attr, 'passwd', 6) != 0) {
                $page[$attr] = $v;
            } else {
                $a = array();
                foreach (preg_split('/\\s+/', $v, -1, PREG_SPLIT_NO_EMPTY) as $pw) {
                    $a[] = preg_match('/^\\w+:/', $pw) ? $pw : crypt($pw);
                }
                if ($a) {
                    $page[$attr] = implode(' ', $a);
                }
            }
        }
    }
    WritePage($pagename, $page);
    Lock(0);
    if (IsEnabled($EnablePostAttrClearSession, 1)) {
        @session_start();
        unset($_SESSION['authid']);
        $_SESSION['authpw'] = array();
    }
    Redirect($pagename);
    exit;
}
示例#11
0
function NotifyUpdate($pagename, $dir = '')
{
    global $NotifyList, $NotifyListPageFmt, $NotifyFile, $IsPagePosted, $IsUploadPosted, $FmtV, $NotifyTimeFmt, $NotifyItemFmt, $SearchPatterns, $NotifySquelch, $NotifyDelay, $Now, $Charset, $EnableNotifySubjectEncode, $NotifySubjectFmt, $NotifyBodyFmt, $NotifyHeaders, $NotifyParameters;
    $abort = ignore_user_abort(true);
    if ($dir) {
        flush();
        chdir($dir);
    }
    $GLOBALS['EnableRedirect'] = 0;
    ##   Read in the current notify configuration
    $pn = FmtPageName($NotifyListPageFmt, $pagename);
    $npage = ReadPage($pn, READPAGE_CURRENT);
    preg_match_all('/^[\\s*:#->]*(notify[:=].*)/m', $npage['text'], $nlist);
    $nlist = array_merge((array) @$NotifyList, (array) @$nlist[1]);
    if (!$nlist) {
        return;
    }
    ##   make sure other processes are locked out
    Lock(2);
    ##   let's load the current .notifylist table
    $nfile = FmtPageName($NotifyFile, $pagename);
    $nfp = @fopen($nfile, 'r');
    if ($nfp) {
        ##   get our current squelch and delay timestamps
        clearstatcache();
        $sz = filesize($nfile);
        list($nextevent, $firstpost) = explode(' ', rtrim(fgets($nfp, $sz)));
        ##   restore our notify array
        $notify = unserialize(fgets($nfp, $sz));
        fclose($nfp);
    }
    if (!is_array($notify)) {
        $notify = array();
    }
    ##   if this is for a newly posted page, get its information
    if ($IsPagePosted || $IsUploadPosted) {
        $page = ReadPage($pagename, READPAGE_CURRENT);
        $FmtV['$PostTime'] = strftime($NotifyTimeFmt, $Now);
        $item = urlencode(FmtPageName($NotifyItemFmt, $pagename));
        if ($firstpost < 1) {
            $firstpost = $Now;
        }
    }
    foreach ($nlist as $n) {
        $opt = ParseArgs($n);
        $mailto = preg_split('/[\\s,]+/', $opt['notify']);
        if (!$mailto) {
            continue;
        }
        if ($opt['squelch']) {
            foreach ($mailto as $m) {
                $squelch[$m] = $opt['squelch'];
            }
        }
        if (!$IsPagePosted) {
            continue;
        }
        if ($opt['link']) {
            $link = MakePageName($pagename, $opt['link']);
            if (!preg_match("/(^|,){$link}(,|\$)/i", $page['targets'])) {
                continue;
            }
        }
        $pats = @(array) $SearchPatterns[$opt['list']];
        if ($opt['group']) {
            $pats[] = FixGlob($opt['group'], '$1$2.*');
        }
        if ($opt['name']) {
            $pats[] = FixGlob($opt['name'], '$1*.$2');
        }
        if ($pats && !MatchPageNames($pagename, $pats)) {
            continue;
        }
        if ($opt['trail']) {
            $trail = ReadTrail($pagename, $opt['trail']);
            for ($i = 0; $i < count($trail); $i++) {
                if ($trail[$i]['pagename'] == $pagename) {
                    break;
                }
            }
            if ($i >= count($trail)) {
                continue;
            }
        }
        foreach ($mailto as $m) {
            $notify[$m][] = $item;
        }
    }
    $nnow = time();
    if ($nnow < $firstpost + $NotifyDelay) {
        $nextevent = $firstpost + $NotifyDelay;
    } else {
        $firstpost = 0;
        $nextevent = $nnow + 86400;
        $mailto = array_keys($notify);
        $subject = FmtPageName($NotifySubjectFmt, $pagename);
        if (IsEnabled($EnableNotifySubjectEncode, 0) && preg_match("/[^ -~]/", $subject)) {
            $subject = strtoupper("=?{$Charset}?B?") . base64_encode($subject) . "?=";
        }
        $body = FmtPageName($NotifyBodyFmt, $pagename);
        foreach ($mailto as $m) {
            $msquelch = @$notify[$m]['lastmail'] + (@$squelch[$m] ? $squelch[$m] : $NotifySquelch);
            if ($nnow < $msquelch) {
                if ($msquelch < $nextevent && count($notify[$m]) > 1) {
                    $nextevent = $msquelch;
                }
                continue;
            }
            unset($notify[$m]['lastmail']);
            if (!$notify[$m]) {
                unset($notify[$m]);
                continue;
            }
            $mbody = str_replace('$NotifyItems', urldecode(implode("\n", $notify[$m])), $body);
            if ($NotifyParameters && !@ini_get('safe_mode')) {
                mail($m, $subject, $mbody, $NotifyHeaders, $NotifyParameters);
            } else {
                mail($m, $subject, $mbody, $NotifyHeaders);
            }
            $notify[$m] = array('lastmail' => $nnow);
        }
    }
    ##   save the updated notify status
    $nfp = @fopen($nfile, "w");
    if ($nfp) {
        fputs($nfp, "{$nextevent} {$firstpost}\n");
        fputs($nfp, serialize($notify) . "\n");
        fclose($nfp);
    }
    Lock(0);
    return true;
}
示例#12
0
function MakePageList($pagename, $opt, $retpages = 1)
{
    global $MakePageListOpt, $SearchPatterns, $EnablePageListProtect, $PCache, $FmtV;
    StopWatch('MakePageList begin');
    SDVA($MakePageListOpt, array('list' => 'default'));
    $opt = array_merge((array) $MakePageListOpt, $opt);
    $readf = @$opt['readf'];
    # we have to read the page if order= is anything but name
    $order = @$opt['order'];
    $readf |= $order && $order != 'name' && $order != '-name';
    $pats = @(array) $SearchPatterns[$opt['list']];
    if (@$opt['group']) {
        $pats[] = FixGlob($opt['group'], '$1$2.*');
    }
    if (@$opt['name']) {
        $pats[] = FixGlob($opt['name'], '$1*.$2');
    }
    # inclp/exclp contain words to be included/excluded.
    $incl = array();
    $inclp = array();
    $inclx = false;
    $excl = array();
    $exclp = '';
    foreach ((array) @$opt[''] as $i) {
        $incl[] = $i;
    }
    foreach ((array) @$opt['+'] as $i) {
        $incl[] = $i;
    }
    foreach ((array) @$opt['-'] as $i) {
        $excl[] = $i;
    }
    foreach ($incl as $i) {
        $inclp[] = '$' . preg_quote($i) . '$i';
        $inclx |= preg_match('[^\\w\\x80-\\xff]', $i);
    }
    if ($excl) {
        $exclp = '$' . implode('|', array_map('preg_quote', $excl)) . '$i';
    }
    $searchterms = count($incl) + count($excl);
    $readf += $searchterms;
    # forced read if incl/excl
    if (@$opt['trail']) {
        $trail = ReadTrail($pagename, $opt['trail']);
        $list = array();
        foreach ($trail as $tstop) {
            $pn = $tstop['pagename'];
            $list[] = $pn;
            $tstop['parentnames'] = array();
            PCache($pn, $tstop);
        }
        foreach ($trail as $tstop) {
            $PCache[$tstop['pagename']]['parentnames'][] = @$trail[$tstop['parent']]['pagename'];
        }
    } else {
        $list = ListPages($pats);
    }
    if (IsEnabled($EnablePageListProtect, 1)) {
        $readf = 1000;
    }
    $matches = array();
    $FmtV['$MatchSearched'] = count($list);
    $terms = $incl ? PageIndexTerms($incl) : array();
    if (@$opt['link']) {
        $link = MakePageName($pagename, $opt['link']);
        $linkp = "/(^|,){$link}(,|\$)/i";
        $terms[] = " {$link} ";
        $readf++;
    }
    if ($terms) {
        $xlist = PageIndexGrep($terms, true);
        $a = count($list);
        $list = array_diff($list, $xlist);
        $a -= count($list);
        StopWatch("MakePageList: PageIndex filtered {$a} pages");
    }
    $xlist = array();
    StopWatch('MakePageList scanning ' . count($list) . " pages, readf={$readf}");
    foreach ((array) $list as $pn) {
        if ($readf) {
            $page = $readf >= 1000 ? RetrieveAuthPage($pn, 'read', false, READPAGE_CURRENT) : ReadPage($pn, READPAGE_CURRENT);
            if (!$page) {
                continue;
            }
            if (@$linkp && !preg_match($linkp, @$page['targets'])) {
                $xlist[] = $pn;
                continue;
            }
            if ($searchterms) {
                $text = $pn . "\n" . @$page['targets'] . "\n" . @$page['text'];
                if ($exclp && preg_match($exclp, $text)) {
                    continue;
                }
                foreach ($inclp as $i) {
                    if (!preg_match($i, $text)) {
                        if (!$inclx) {
                            $xlist[] = $pn;
                        }
                        continue 2;
                    }
                }
            }
            $page['size'] = strlen(@$page['text']);
        } else {
            $page = array();
        }
        $page['pagename'] = $page['name'] = $pn;
        PCache($pn, $page);
        $matches[] = $pn;
    }
    StopWatch('MakePageList sort');
    if ($order) {
        SortPageList($matches, $order);
    }
    if ($xlist) {
        register_shutdown_function('flush');
        register_shutdown_function('PageIndexUpdate', $xlist, getcwd());
    }
    StopWatch('MakePageList end');
    if ($retpages) {
        for ($i = 0; $i < count($matches); $i++) {
            $matches[$i] =& $PCache[$matches[$i]];
        }
    }
    return $matches;
}
示例#13
0
function PageListProtect(&$list, &$opt, $pn, &$page)
{
    global $EnablePageListProtect;
    switch ($opt['=phase']) {
        case PAGELIST_PRE:
            if (!IsEnabled($EnablePageListProtect, 1) && @$opt['readf'] < 1000) {
                return 0;
            }
            StopWatch("PageListProtect enabled");
            $opt['=protectexclude'] = array();
            $opt['=protectsafe'] = (array) @$opt['=protectsafe'];
            return PAGELIST_ITEM | PAGELIST_POST;
        case PAGELIST_ITEM:
            if (@$opt['=protectsafe'][$pn]) {
                return 1;
            }
            $page = RetrieveAuthPage($pn, 'ALWAYS', false, READPAGE_CURRENT);
            $opt['=readc']++;
            if (!$page['=auth']['read']) {
                $opt['=protectexclude'][$pn] = 1;
            }
            if (!$page['=passwd']['read']) {
                $opt['=protectsafe'][$pn] = 1;
            }
            return 1;
        case PAGELIST_POST:
            $excl = array_keys($opt['=protectexclude']);
            $safe = array_keys($opt['=protectsafe']);
            StopWatch("PageListProtect excluded=" . count($excl) . ", safe=" . count($safe));
            $list = array_diff($list, $excl);
            return 1;
    }
}
示例#14
0
    $FmtP to hide any "?action=" url parameters in page urls
    generated by PmWiki for actions that robots aren't allowed to
    access.  This can greatly reduce the load on the server by 
    not providing the robot with links to pages that it will be 
    forbidden to index anyway.  
*/
## $MetaRobots provides the value for the <meta name='robots' ...> tag.
SDV($MetaRobots, $action != 'browse' || preg_match('#^PmWiki[./](?!PmWiki$)|^Site[./]#', $pagename) ? 'noindex,nofollow' : 'index,follow');
if ($MetaRobots) {
    $HTMLHeaderFmt['robots'] = "  <meta name='robots' content='\$MetaRobots' />\n";
}
## $RobotPattern is used to identify robots.
SDV($RobotPattern, 'Googlebot|Slurp|msnbot|Teoma|ia_archiver|BecomeBot|HTTrack|MJ12bot');
SDV($IsRobotAgent, $RobotPattern && preg_match("!{$RobotPattern}!", @$_SERVER['HTTP_USER_AGENT']));
if (!$IsRobotAgent) {
    return;
}
## $RobotActions indicates which actions a robot is allowed to perform.
SDVA($RobotActions, array('browse' => 1, 'rss' => 1, 'dc' => 1));
if (!@$RobotActions[$action]) {
    header("HTTP/1.1 403 Forbidden");
    print "<h1>Forbidden</h1>";
    exit;
}
## The following removes any ?action= parameters that robots aren't
## allowed to access.
if (IsEnabled($EnableRobotCloakActions, 0)) {
    $p = create_function('$a', 'return (boolean)$a;');
    $p = join('|', array_keys(array_filter($RobotActions, $p)));
    $FmtP["/(\\\$ScriptUrl[^#\"'\\s<>]+)\\?action=(?!{$p})\\w+/"] = '$1';
}
示例#15
0
    For example, to create customizations for the 'Demo' group, place 
    them in a file called local/Demo.php.  To customize a single page, 
    use the full page name (e.g., local/Demo.MyPage.php).  
    Per-page/per-group customizations can be handled at any time by adding
	include_once("scripts/pgcust.php");
    to config.php.  It is automatically included by scripts/stdconfig.php
    unless $EnablePGCust is set to zero in config.php.

    A page's customization is loaded first, followed by any group
    customization.  If no page or group customizations are loaded,
    then 'local/default.php' is loaded.  

    A per-page configuration file can prevent its group's config from 
    loading by setting $EnablePGCust=0;.  A per-page configuration file 
    can force group customizations to be loaded first by using include_once
    on the group customization file.
    
*/
$f = 1;
for ($p = $pagename; $p; $p = preg_replace('/\\.*[^.]*$/', '', $p)) {
    if (!IsEnabled($EnablePGCust, 1)) {
        return;
    }
    if (file_exists("{$LocalDir}/{$p}.php")) {
        include_once "{$LocalDir}/{$p}.php";
        $f = 0;
    }
}
if ($f && IsEnabled($EnablePGCust, 1) && file_exists("{$LocalDir}/default.php")) {
    include_once "{$LocalDir}/default.php";
}
示例#16
0
function InputDefault($pagename, $type, $args) {
  global $InputValues, $PageTextVarPatterns, $PCache;
  $args = ParseArgs($args);
  $args[''] = (array)@$args[''];
  $name = (isset($args['name'])) ? $args['name'] : array_shift($args['']);
  $name = preg_replace('/^\\$:/', 'ptv_', $name);
  $value = (isset($args['value'])) ? $args['value'] : array_shift($args['']);
  if (!isset($InputValues[$name])) $InputValues[$name] = $value;
  if (@$args['request']) {
    $req = array_merge($_GET, $_POST);
    foreach($req as $k => $v) 
      if (!isset($InputValues[$k])) 
        $InputValues[$k] = htmlspecialchars(stripmagic($v), ENT_NOQUOTES);
  }
  $source = @$args['source'];
  if ($source) {
    $source = MakePageName($pagename, $source);
    $page = RetrieveAuthPage($source, 'read', false, READPAGE_CURRENT);
    if ($page) {
      foreach((array)$PageTextVarPatterns as $pat)
        if (preg_match_all($pat, IsEnabled($PCache[$source]['=preview'], $page['text']), 
          $match, PREG_SET_ORDER))
          foreach($match as $m)
            if (!isset($InputValues['ptv_'.$m[2]]))
              $InputValues['ptv_'.$m[2]] = 
                htmlspecialchars(Qualify($source, $m[3]), ENT_NOQUOTES);
    }
  }
  return '';
}
示例#17
0
SDV($AuthorRequiredFmt, "<h3 class='wikimessage'>\$[An author name is required.]</h3>");
Markup('[[~', '<[[', '/\\[\\[~(.*?)\\]\\]/', "[[{$AuthorGroup}/\$1]]");
"[[{$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);
}
$k = MakePageName($pagename, $Author);
SDV($AuthorPage, "{$AuthorGroup}/{$k}");
SDV($AuthorLink, "[[~{$Author}]]");
if (IsEnabled($EnableAuthorSignature, 1)) {
    $ROSPatterns['/~~~~/'] = '[[~$Author]] $CurrentTime';
    $ROSPatterns['/~~~/'] = '[[~$Author]]';
}
if (IsEnabled($EnableAuthorRequired, 0)) {
    array_unshift($EditFunctions, 'RequireAuthor');
}
## RequireAuthor forces an author to enter a name before posting.
function RequireAuthor($pagename, &$page, &$new)
{
    global $Author, $EditMessageFmt, $AuthorRequiredFmt;
    if (!$Author) {
        $EditMessageFmt .= $AuthorRequiredFmt;
        $_REQUEST['post'] = '';
    }
}
示例#18
0
function PageIndexUpdate($pagelist = NULL, $dir = '') {
  global $EnableReadOnly, $PageIndexUpdateList, $PageIndexFile, 
    $PageIndexTime, $Now;
  if (IsEnabled($EnableReadOnly, 0)) return;
  $abort = ignore_user_abort(true);
  if ($dir) { flush(); chdir($dir); }
  if (is_null($pagelist)) 
    { $pagelist = (array)$PageIndexUpdateList; $PageIndexUpdateList = array(); }
  if (!$pagelist || !$PageIndexFile) return;
  SDV($PageIndexTime, 10);
  $c = count($pagelist); $updatecount = 0;
  StopWatch("PageIndexUpdate begin ($c pages to update)");
  $pagelist = (array)$pagelist;
  $timeout = time() + $PageIndexTime;
  $cmpfn = create_function('$a,$b', 'return strlen($b)-strlen($a);');
  Lock(2);
  $ofp = fopen("$PageIndexFile,new", 'w');
  foreach($pagelist as $pn) {
    if (@$updated[$pn]) continue;
    @$updated[$pn]++;
    if (time() > $timeout) continue;
    $page = ReadPage($pn, READPAGE_CURRENT);
    if ($page) {
      $targets = str_replace(',', ' ', @$page['targets']);
      $terms = PageIndexTerms(array(@$page['text'], $targets, $pn));
      usort($terms, $cmpfn);
      $x = '';
      foreach($terms as $t) { if (strpos($x, $t) === false) $x .= " $t"; }
      fputs($ofp, "$pn:$Now: $targets :$x\n");
    }
    $updatecount++;
  }
  $ifp = @fopen($PageIndexFile, 'r');
  if ($ifp) {
    while (!feof($ifp)) {
      $line = fgets($ifp, 4096);
      while (substr($line, -1, 1) != "\n" && !feof($ifp)) 
        $line .= fgets($ifp, 4096);
      $i = strpos($line, ':');
      if ($i === false) continue;
      $n = substr($line, 0, $i);
      if (@$updated[$n]) continue;
      fputs($ofp, $line);
    }
    fclose($ifp);
  }
  fclose($ofp);
  if (file_exists($PageIndexFile)) unlink($PageIndexFile); 
  rename("$PageIndexFile,new", $PageIndexFile);
  fixperms($PageIndexFile);
  StopWatch("PageIndexUpdate end ($updatecount updated)");
  ignore_user_abort($abort);
}
示例#19
0
<?php

if (!defined('PmWiki')) {
    exit;
}
/*  Copyright 2004 Patrick R. Michaud (pmichaud@pobox.com)
    This file is part of PmWiki; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published
    by the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.  See pmwiki.php for full details.
*/
## %% markup
Markup('%%', 'style', '%', 'return ApplyStyles($x);');
## restore links before applying styles
Markup('restorelinks', '<%%', "/{$KeepToken}(\\d+L){$KeepToken}/e", '$GLOBALS[\'KPV\'][\'$1\']');
if (IsEnabled($EnableStdWikiStyles, 1)) {
    ## standard colors
    foreach (array('black', 'white', 'red', 'yellow', 'blue', 'gray', 'silver', 'maroon', 'green', 'navy', 'purple') as $c) {
        SDV($WikiStyle[$c]['color'], $c);
    }
    ## %newwin% style opens links in a new window
    SDV($WikiStyle['newwin']['target'], '_blank');
    ## %comment% style turns markup into a comment via display:none css
    SDV($WikiStyle['comment']['display'], 'none');
    ## display, margin, padding, and border css properties
    $WikiStyleCSS[] = 'display|(margin|padding|border)(-(left|right|top|bottom))?';
    ## list-styles
    $WikiStyleCSS[] = 'list-style';
    foreach (array('decimal' => 'decimal', 'roman' => 'lower-roman', 'ROMAN' => 'upper-roman', 'alpha' => 'lower-alpha', 'ALPHA' => 'upper-alpha') as $k => $v) {
        SDV($WikiStyle[$k], array('apply' => 'list', 'list-style' => $v));
    }
示例#20
0
if ($action == 'diff' && @(!$HandleActions['diff'])) {
    include_once "{$FarmD}/scripts/pagerev.php";
}
if (IsEnabled($EnableWikiTrails, 1)) {
    include_once "{$FarmD}/scripts/trails.php";
}
if (IsEnabled($EnableStdWikiStyles, 1)) {
    include_once "{$FarmD}/scripts/wikistyles.php";
}
if (IsEnabled($EnableMailPosts, 0)) {
    include_once "{$FarmD}/scripts/mailposts.php";
}
if (IsEnabled($EnableUpload, 0)) {
    include_once "{$FarmD}/scripts/upload.php";
}
if (IsEnabled($EnablePageList, 1)) {
    include_once "{$FarmD}/scripts/pagelist.php";
}
if (IsEnabled($EnableDiag, 0)) {
    include_once "{$FarmD}/scripts/diag.php";
}
if (IsEnabled($EnableVarMarkup, 1)) {
    include_once "{$FarmD}/scripts/vardoc.php";
}
if ($action == 'crypt') {
    include_once "{$FarmD}/scripts/crypt.php";
}
SDV($MetaRobots, $action != 'browse' || preg_match('#^PmWiki[./](?!PmWiki$)#', $pagename) ? 'noindex,nofollow' : 'index,follow');
if ($MetaRobots) {
    $HTMLHeaderFmt[] = "  <meta name='robots' content='{$MetaRobots}' />\n";
}
示例#21
0
    include_once "{$FarmD}/scripts/wikistyles.php";
}
if (IsEnabled($EnableMailPosts, 0)) {
    include_once "{$FarmD}/scripts/mailposts.php";
}
if (IsEnabled($EnablePageList, 1)) {
    include_once "{$FarmD}/scripts/pagelist.php";
}
if (IsEnabled($EnableVarMarkup, 1)) {
    include_once "{$FarmD}/scripts/vardoc.php";
}
if (!function_exists(@$DiffFunction)) {
    include_once "{$FarmD}/scripts/phpdiff.php";
}
if ($action == 'crypt') {
    include_once "{$FarmD}/scripts/crypt.php";
}
if ($action == 'edit' && IsEnabled($EnableGUIButtons, 0)) {
    include_once "{$FarmD}/scripts/guiedit.php";
}
if (IsEnabled($EnableForms, 1)) {
    include_once "{$FarmD}/scripts/forms.php";
}
# must come after prefs
if (IsEnabled($EnableUpload, 0)) {
    include_once "{$FarmD}/scripts/upload.php";
}
# must come after forms
if (IsEnabled($EnableDiag, 0)) {
    include_once "{$FarmD}/scripts/diag.php";
}
示例#22
0
function Blocklist($pagename, $text) {
  global $BlocklistPages, $BlockedMessagesFmt, $BlocklistDownload,
    $BlocklistDownloadRefresh, $Now, $EnablePost, $WhyBlockedFmt,
    $MessagesFmt, $BlocklistMessageFmt, $EnableWhyBlocked, $IsBlocked;

  StopWatch("Blocklist: begin $pagename");

  $BlocklistDownload = (array)@$BlocklistDownload;
  SDV($BlocklistPages, 
    array_merge(array('$SiteAdminGroup.Blocklist', 
                      '$SiteAdminGroup.Blocklist-Farm'),
                array_keys($BlocklistDownload)));
  SDV($BlocklistMessageFmt, "<h3 class='wikimessage'>$[This post has been blocked by the administrator]</h3>");
  SDVA($BlockedMessagesFmt, array(
    'ip' => '$[Address blocked from posting]: ',
    'text' => '$[Text blocked from posting]: '));
  SDV($BlocklistDownloadRefresh, 86400);

  ##  Loop over all blocklist pages
  foreach((array)$BlocklistPages as $b) {

    ##  load the current blocklist page
    $pn = FmtPageName($b, $pagename);
    $page = ReadPage($pn, READPAGE_CURRENT);
    if (!$page) continue;

    ##  if the page being checked is a blocklist page, stop blocking
    if ($pagename == $pn) return;

    ##  If the blocklist page is managed by automatic download,
    ##  schedule any new downloads here
    if (@$BlocklistDownload[$pn]) {
      $bd = &$BlocklistDownload[$pn];
      SDVA($bd, array(
        'refresh' => $BlocklistDownloadRefresh,
        'url' => "http://www.pmwiki.org/blocklists/$pn" ));
      if (!@$page['text'] || $page['time'] < $Now - $bd['refresh'])
        register_shutdown_function('BlocklistDownload', $pn, getcwd());
    }

    ##  If the blocklist is simply a list of regexes to be matched, load 
    ##  them into $terms['block'] and continue to the next blocklist page.
    ##  Some regexes from remote sites aren't well-formed, so we have
    ##  to escape any slashes that aren't already escaped.
    if (strpos(@$page['text'], 'blocklist-format: regex') !==false) {
      if (preg_match_all('/^([^\\s#].+)/m', $page['text'], $match)) 
        foreach($match[0] as $m) {
          $m = preg_replace('#(?<!\\\\)/#', '\\/', trim($m));
          $terms['block'][] = "/$m/";
        }
      continue;
    }

    ##  Treat the page as a pmwiki-format blocklist page, with
    ##  IP addresses and "block:"-style declarations.  First, see
    ##  if we need to block the author based on a.b.c.d or a.b.c.*
    ##  IP addresses.
    $ip = preg_quote($_SERVER['REMOTE_ADDR']);
    $ip = preg_replace('/\\d+$/', '($0\\b|\\*)', $ip);
    if (preg_match("/\\b$ip/", @$page['text'], $match)) {
      $EnablePost = 0;
      $IsBlocked = 1;
      $WhyBlockedFmt[] = $BlockedMessagesFmt['ip'] . $match[0];
    }

    ##  Now we'll load any "block:" or "unblock:" specifications
    ##  from the page text.
    if (preg_match_all('/(un)?(?:block|regex):(.*)/', @$page['text'], 
                       $match, PREG_SET_ORDER)) 
      foreach($match as $m) $terms[$m[1].'block'][] = trim($m[2]);
  }

  ##  okay, we've loaded all of the terms, now subtract any 'unblock'
  ##  terms from the block set.
  StopWatch("Blocklist: diff unblock");
  $blockterms = array_diff((array)@$terms['block'], (array)@$terms['unblock']);

  ##  go through each of the remaining blockterms and see if it matches the
  ##  text -- if so, disable posting and add a message to $WhyBlockedFmt.
  StopWatch('Blocklist: blockterms (count='.count($blockterms).')');
  $itext = strtolower($text);
  foreach($blockterms as $b) {
    if ($b{0} == '/') {
      if (!preg_match($b, $text)) continue;
    } else if (strpos($itext, strtolower($b)) === false) continue;
    $EnablePost = 0;
    $IsBlocked = 1;
    $WhyBlockedFmt[] = $BlockedMessagesFmt['text'] . $b;
  }
  StopWatch('Blocklist: blockterms done');

  ##  If we came across any reasons to block, let's provide a message
  ##  to the author that it was blocked.  If $EnableWhyBlocked is set,
  ##  we'll even tell the author why.  :-)
  if (@$WhyBlockedFmt) {
    $MessagesFmt[] = $BlocklistMessageFmt;
    if (IsEnabled($EnableWhyBlocked, 0)) 
      foreach((array)$WhyBlockedFmt as $why) 
        $MessagesFmt[] = "<pre class='blocklistmessage'>$why</pre>\n";
  }
  StopWatch("Blocklist: end $pagename");
}
示例#23
0
      $[This is a minor edit]<br />
    <input type='submit' name='post' value=' $[Save] ' />
    <input type='submit' name='preview' value=' $[Preview] ' />
    <input type='reset' value=' $[Reset] ' /></form></div>");
  if (@$_POST['preview']) 
    SDV($PagePreviewFmt, "<div id='wikipreview'>
      <h2 class='wikiaction'>$[Preview \$FullName]</h2>
      <p><b>$[Page is unsaved]</b></p>
      \$PreviewText
      <hr /><p><b>$[End of preview -- remember to save]</b><br />
      <a href='#top'>$[Top]</a></p></div>");
  SDV($HandleEditFmt, array(&$PageStartFmt,
    &$PageEditFmt, 'wiki:$[PmWiki.EditQuickReference]', &$PagePreviewFmt,
    &$PageEndFmt));
  $EditMessageFmt = implode('', $MessagesFmt) . $EditMessageFmt;
  if ($action=='edit' && IsEnabled($EnableGUIButtons, 0)) 
    array_push($EditFunctions, 'GUIEdit');
} else $MessagesFmt[] = @$EditMessageFmt;

    
function GUIEdit($pagename, &$page, &$new) {
  global $EditMessageFmt;
  $EditMessageFmt .= GUIButtonCode($pagename);
}

## mainpages:
##   In 2.0.beta44 several utility pages change location to the new Site
##   group.  These settings cause some skins (that use translations)
##   to know to link to the new locations.
if ($Transition['mainpages']) {
  XLSDV('en', array(
示例#24
0
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;
    if (!$Author) {
        $MessagesFmt[] = $AuthorRequiredFmt;
        $_POST['post'] = '';
    }
}
示例#25
0
function Redirect($pagename, $urlfmt = '$PageUrl')
{
    # redirect the browser to $pagename
    global $EnableRedirect, $RedirectDelay;
    SDV($RedirectDelay, 0);
    clearstatcache();
    #if (!PageExists($pagename)) $pagename=$DefaultPage;
    $pageurl = FmtPageName($urlfmt, $pagename);
    if (IsEnabled($EnableRedirect, 1)) {
        header("Location: {$pageurl}");
        header("Content-type: text/html");
        echo "<html><head>\n      <meta http-equiv='Refresh' Content='{$RedirectDelay}; URL={$pageurl}' />\n     <title>Redirect</title></head><body></body></html>";
    } else {
        echo "<a href='{$pageurl}'>Redirect to {$pageurl}</a>";
    }
    exit;
}
示例#26
0
function DiffRenderSource($in, $out, $which) {
  global $WordDiffFunction, $EnableDiffInline;
  if (!IsEnabled($EnableDiffInline, 1)) {
    $a = $which? $out : $in;
    return str_replace("\n","<br />",htmlspecialchars(join("\n",$a)));  
  }
  $countdifflines = abs(count($in)-count($out));
  $lines = $cnt = $x2 = $y2 = array();
  foreach($in as $line) {
    $tmp = $countdifflines>20 ? array($line) : DiffPrepareInline($line);
    if(!$which) $cnt[] = array(count($x2), count($tmp));
    $x2 = array_merge($x2, $tmp);
  }
  foreach($out as $line) {
    $tmp = $countdifflines>20 ? array($line) : DiffPrepareInline($line);
    if($which) $cnt[] = array(count($y2), count($tmp));
    $y2 = array_merge($y2, $tmp);
  }
  $z = $WordDiffFunction(implode("\n", $x2), implode("\n", $y2));

  $z2 = array_map('htmlspecialchars', ($which? $y2 : $x2));
  array_unshift($z2, '');
  foreach (explode("\n", $z) as $zz) {
    if (preg_match('/^(\\d+)(,(\\d+))?([adc])(\\d+)(,(\\d+))?/',$zz,$m)) {
      $a1 = $a2 = $m[1];
      if ($m[3]) $a2=$m[3];
      $b1 = $b2 = $m[5];
      if ($m[7]) $b2=$m[7];

      if (!$which && ($m[4]=='c'||$m[4]=='d')) {
        $z2[$a1] = '<del>'. $z2[$a1];
        $z2[$a2] .= '</del>';
      }
      if ($which && ($m[4]=='c'||$m[4]=='a')) {
        $z2[$b1] = '<ins>'.$z2[$b1];
        $z2[$b2] .= '</ins>';
      }
    }
  }
  $line = array_shift($z2);
  $z2[0] = $line.$z2[0];
  foreach ($cnt as $a) $lines[] = implode('', array_slice($z2, $a[0], $a[1]));
  $ret = trim(implode("\n", $lines));
  $ret = preg_replace('!</(del|ins)> <\1>!', ' ', $ret);
  return str_replace("\n","<br />",$ret);
}
示例#27
0
function HandlePostAttr($pagename, $auth = 'attr') {
  global $PageAttributes, $EnablePostAttrClearSession;
  Lock(2);
  $page = RetrieveAuthPage($pagename, $auth, true);
  if (!$page) { Abort("?unable to read $pagename"); }
  foreach($PageAttributes as $attr=>$p) {
    $v = stripmagic(@$_POST[$attr]);
    if ($v == '') continue;
    if ($v=='clear') unset($page[$attr]);
    else if (strncmp($attr, 'passwd', 6) != 0) $page[$attr] = $v;
    else {
      $a = array();
      preg_match_all('/"[^"]*"|\'[^\']*\'|\\S+/', $v, $match);
      foreach($match[0] as $pw) 
        $a[] = preg_match('/^(@|\\w+:)/', $pw) ? $pw 
                   : crypt(preg_replace('/^([\'"])(.*)\\1$/', '$2', $pw));
      if ($a) $page[$attr] = implode(' ',$a);
    }
  }
  WritePage($pagename,$page);
  Lock(0);
  if (IsEnabled($EnablePostAttrClearSession, 1)) {
    @session_start();
    unset($_SESSION['authid']);
    unset($_SESSION['authlist']);
    $_SESSION['authpw'] = array();
  }
  Redirect($pagename);
  exit;
} 
示例#28
0
function FmtUploadList($pagename, $args)
{
    global $UploadDir, $UploadPrefixFmt, $UploadUrlFmt, $EnableUploadOverwrite, $TimeFmt, $EnableDirectDownload;
    $opt = ParseArgs($args);
    if (@$opt[''][0]) {
        $pagename = MakePageName($pagename, $opt[''][0]);
    }
    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&amp;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;
        }
        $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'\n        href='\$PageUrl?action=upload&amp;upname={$file}'>&nbsp;&Delta;</a>", $pagename);
        }
        $out[] = "<li> <a href='{$name}'>{$file}</a>{$overwrite} ... " . number_format($stat['size']) . " bytes ... " . strftime($TimeFmt, $stat['mtime']) . "</li>";
    }
    return implode("\n", $out);
}
示例#29
0
function FmtUploadList($pagename, $args) {
  global $UploadDir, $UploadPrefixFmt, $UploadUrlFmt, $EnableUploadOverwrite,
    $TimeFmt, $EnableDirectDownload;

  $opt = ParseArgs($args);
  if (@$opt[''][0]) $pagename = MakePageName($pagename, $opt[''][0]);
  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&amp;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;
    $filelist[$file] = $file;
  }
  closedir($dirp);
  $out = array();
  natcasesort($filelist);
  $overwrite = '';
  foreach($filelist as $file=>$x) {
    $name = PUE("$uploadurl$file");
    $stat = stat("$uploaddir/$file");
    if ($EnableUploadOverwrite) 
      $overwrite = FmtPageName("<a rel='nofollow' class='createlink'
        href='\$PageUrl?action=upload&amp;upname=$file'>&nbsp;&Delta;</a>", 
        $pagename);
    $out[] = "<li> <a href='$name'>$file</a>$overwrite ... ".
      number_format($stat['size']) . " bytes ... " . 
      strftime($TimeFmt, $stat['mtime']) . "</li>";
  }
  return implode("\n",$out);
}
示例#30
0
function HandlePostAttr($pagename)
{
    global $PageAttributes, $EnablePostAttrClearSession;
    $page = RetrieveAuthPage($pagename, 'attr');
    if (!$page) {
        Abort("?unable to read {$pagename}");
    }
    foreach ($PageAttributes as $attr => $p) {
        $newpw = @$_POST[$attr];
        if ($newpw == 'clear') {
            unset($page[$attr]);
        } else {
            if ($newpw > '') {
                $page[$attr] = crypt($newpw);
            }
        }
    }
    WritePage($pagename, $page);
    if (IsEnabled($EnablePostAttrClearSession, 1)) {
        $_SESSION['authpw'] = array();
    }
    Redirect($pagename);
    exit;
}