Ejemplo n.º 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;
}
Ejemplo n.º 2
0
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>');
}
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
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;
    }
}
Ejemplo n.º 5
0
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']);
}
Ejemplo n.º 6
0
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;
}
Ejemplo n.º 7
0
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));
}
Ejemplo n.º 8
0
function VarLink($pagename,$tgt,$txt) {
  global $VarIndex,$FmtV,$VarLinkMissingFmt,$VarLinkExistsFmt;
  SDV($VarLinkMissingFmt,'$LinkText');
  SDV($VarLinkExistsFmt,"<a class='varlink' href='\$LinkUrl'><code class='varlink'>\$LinkText</code></a>");
  VarIndexLoad($pagename);
  $FmtV['$LinkText'] = str_replace('$', '&#36;', $txt);
  $FmtV['$LinkUrl'] = @$VarIndex[$tgt]['url'];
  if (@!$VarIndex[$tgt]['url'])
    return FmtPageName($VarLinkMissingFmt,$pagename);
  return FmtPageName($VarLinkExistsFmt,$pagename);
}
Ejemplo n.º 9
0
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;
}
Ejemplo n.º 10
0
function MergeSimulEdits($pagename, &$page, &$new)
{
    global $MessagesFmt, $WorkDir, $SysMergeCmd;
    SDV($SysMergeCmd, "/usr/bin/diff3 -L '' -L '' -L '' -m -E");
    if (@(!$_POST['basetime']) || !PageExists($pagename) || $_POST['basetime'] >= $page['time']) {
        return;
    }
    unset($_POST['post']);
    $MessagesFmt[] = "<p class='editconflict'>The page you are \n    editing has been modified since you started editing it.  \n    The modifications have been merged into the text below,\n    you may want to verify the results of the merge before\n    pressing save.  Conflicts the system couldn't resolve are\n    bracketed by &lt;&lt;&lt;&lt;&lt;&lt;&lt; and \n    &gt;&gt;&gt;&gt;&gt;&gt;&gt;.  (<a target='_blank' \n    href='\$PageUrl?action=diff'>View changes</a>)</p>\n";
    $old = array();
    RestorePage($pagename, $page, $old, "diff:{$_POST['basetime']}");
    $new['text'] = Merge($new['text'], $old['text'], $page['text']);
}
Ejemplo n.º 11
0
function dg_SetLogoHeightWidth($wPad, $hPad = 0)
{
    global $PageLogoUrl, $PageLogoUrlHeight, $PageLogoUrlWidth;
    if (!isset($PageLogoUrlWidth) || !isset($PageLogoUrlHeight)) {
        $size = @getimagesize($PageLogoUrl);
        if (!isset($PageLogoUrlWidth)) {
            SDV($PageLogoUrlWidth, ($size ? $size[0] + $wPad : 0) . 'px');
        }
        if (!isset($PageLogoUrlHeight)) {
            SDV($PageLogoUrlHeight, ($size ? $size[1] + $hPad : 0) . 'px');
        }
    }
}
Ejemplo n.º 12
0
function VarLink($pagename, $tgt, $txt)
{
    global $VarIndex, $FmtV, $VarLinkMissingFmt, $VarLinkExistsFmt;
    SDV($VarLinkMissingFmt, '$LinkText');
    SDV($VarLinkExistsFmt, "<a class='varlink' href='\$LinkUrl'><code class='varlink'>\$LinkText</code></a>");
    VarIndexLoad($pagename);
    $FmtV = array();
    $FmtV['$LinkText'] = $txt;
    $FmtV['$LinkUrl'] = @$VarIndex[$tgt]['url'];
    if (@(!$VarIndex[$tgt]['url'])) {
        return FmtPageName($VarLinkMissingFmt, $pagename);
    }
    return FmtPageName($VarLinkExistsFmt, $pagename);
}
Ejemplo n.º 13
0
function HandleUpload($pagename)
{
    global $FmtV, $UploadExtMax, $HandleUploadFmt, $PageStartFmt, $PageEndFmt, $PageUploadFmt;
    $page = RetrieveAuthPage($pagename, 'upload');
    if (!$page) {
        Abort("?cannot upload to {$pagename}");
    }
    SetPage($pagename, $page);
    $FmtV['$UploadName'] = MakeUploadName($pagename, @$_REQUEST['upname']);
    $upresult = @$_REQUEST['upresult'];
    $FmtV['$upext'] = @$_REQUEST['upext'];
    $FmtV['$upmax'] = @$_REQUEST['upmax'];
    $FmtV['$UploadResult'] = $upresult ? FmtPageName("<i>\$UploadName</i>: \$[UL{$upresult}]", $pagename) : '';
    SDV($HandleUploadFmt, array(&$PageStartFmt, &$PageUploadFmt, &$PageEndFmt));
    PrintFmt($pagename, $HandleUploadFmt);
}
Ejemplo n.º 14
0
function EditDraft(&$pagename, &$page, &$new) {
  global $WikiDir, $DraftSuffix, $DeleteKeyPattern, 
    $DraftRecentChangesFmt, $RecentChangesFmt;
  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; 
    # $page = ReadPage($basename); # breaks restores, PITS:01007, Test:DraftRestore
    $WikiDir->delete($draftname);
  }
  else if (PageExists($draftname) && $pagename != $draftname)
    { Redirect($draftname, '$PageUrl?action=edit'); exit(); }
  if ($pagename == $draftname && isset($DraftRecentChangesFmt))
    $RecentChangesFmt = $DraftRecentChangesFmt;
}
Ejemplo n.º 15
0
function Merge($newtext, $oldtext, $pagetext)
{
    global $WorkDir, $SysMergeCmd;
    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 = '';
    $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;
}
Ejemplo n.º 16
0
function EditDraft(&$pagename, &$page, &$new)
{
    global $WikiDir, $DraftSuffix, $DeleteKeyPattern;
    SDV($DeleteKeyPattern, "^\\s*delete\\s*\$");
    $basename = preg_replace("/{$DraftSuffix}\$/", '', $pagename);
    $draftname = $basename . $DraftSuffix;
    if ($_POST['postdraft']) {
        $pagename = $draftname;
        return;
    }
    if ($_POST['post'] && !preg_match("/{$DeleteKeyPattern}/", $new['text'])) {
        $pagename = $basename;
        $page = ReadPage($basename);
        $WikiDir->delete($draftname);
        return;
    }
    if (PageExists($draftname) && $pagename != $draftname) {
        Redirect($draftname, '$PageUrl?action=edit');
        exit;
    }
}
Ejemplo n.º 17
0
function EditDraft(&$pagename, &$page, &$new)
{
    global $WikiDir, $DraftSuffix, $DeleteKeyPattern, $DraftRecentChangesFmt, $RecentChangesFmt;
    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;
            $page = ReadPage($basename);
            $WikiDir->delete($draftname);
        } else {
            if (PageExists($draftname) && $pagename != $draftname) {
                Redirect($draftname, '$PageUrl?action=edit');
                exit;
            }
        }
    }
    if ($pagename == $draftname && isset($DraftRecentChangesFmt)) {
        $RecentChangesFmt = $DraftRecentChangesFmt;
    }
}
Ejemplo n.º 18
0
function HandleDownload($pagename, $auth = 'read') {
  global $UploadFileFmt, $UploadExts, $DownloadDisposition;
  SDV($DownloadDisposition, "inline");
  $page = RetrieveAuthPage($pagename, $auth, true, READPAGE_CURRENT);
  if (!$page) Abort("?cannot read $pagename");
  $upname = MakeUploadName($pagename, @$_REQUEST['upname']);
  $filepath = FmtPageName("$UploadFileFmt/$upname", $pagename);
  if (!$upname || !file_exists($filepath)) {
    header("HTTP/1.0 404 Not Found");
    Abort("?requested file not found");
    exit();
  }
  preg_match('/\\.([^.]+)$/',$filepath,$match); 
  if ($UploadExts[@$match[1]]) 
    header("Content-Type: {$UploadExts[@$match[1]]}");
  header("Content-Length: ".filesize($filepath));
  header("Content-disposition: $DownloadDisposition; filename=$upname");
  $fp = fopen($filepath, "r");
  if ($fp) {
    while (!feof($fp)) echo fread($fp, 4096);
    fclose($fp);
  }
  exit();
}  
Ejemplo n.º 19
0
function LinkIndexUpdate($pagelist)
{
    global $LinkIndexFile, $PCache, $LinkIndexTime;
    SDV($LinkIndexTime, 10);
    if (!$pagelist || !$LinkIndexFile) {
        return;
    }
    StopWatch('LinkIndexUpdate begin');
    $pagelist = (array) $pagelist;
    Lock(2);
    $ofp = fopen("{$LinkIndexFile},new", 'w');
    $timeout = time() + $LinkIndexTime;
    foreach ($pagelist as $n) {
        if (time() > $timeout) {
            break;
        }
        if (isset($PCache[$n]['targets'])) {
            $targets = $PCache[$n]['targets'];
        } else {
            $page = ReadPage($n, READPAGE_CURRENT);
            if (!$page) {
                continue;
            }
            $targets = @$page['targets'];
        }
        fputs($ofp, "{$n}={$targets}\n");
    }
    $ifp = @fopen($LinkIndexFile, '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 (in_array($n, $pagelist)) {
                continue;
            }
            fputs($ofp, $line);
        }
        fclose($ifp);
    }
    fclose($ofp);
    if (file_exists($LinkIndexFile)) {
        unlink($LinkIndexFile);
    }
    rename("{$LinkIndexFile},new", $LinkIndexFile);
    fixperms($LinkIndexFile);
    StopWatch('LinkIndexUpdate end');
}
Ejemplo n.º 20
0
function HandleLogoutA($pagename, $auth = 'read') {
  global $LogoutRedirectFmt, $LogoutCookies;
  SDV($LogoutRedirectFmt, '$FullName');
  SDV($LogoutCookies, array());
  @session_start();
  $_SESSION = array();
  if (isset($_COOKIE[session_name()]))
    setcookie(session_name(), '', time()-43200, '/');
  foreach ($LogoutCookies as $c)
    if (isset($_COOKIE[$c])) setcookie($c, '', time()-43200, '/');
  session_destroy();
  Redirect(FmtPageName($LogoutRedirectFmt, $pagename));
}
Ejemplo n.º 21
0
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($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);
}
Ejemplo n.º 22
0
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;
    if (!$Author) {
        $MessagesFmt[] = $AuthorRequiredFmt;
Ejemplo n.º 23
0
    By default, PmWiki is configured such that only the first occurrence
    of 'PmWiki' in a page is treated as a WikiWord.  If you want to
    restore 'PmWiki' to be treated like other WikiWords, uncomment the
    line below.
        unset($WikiWordCount['PmWiki']);

    If you want to disable WikiWords matching a pattern, you can use
    something like the following.  Note that the first argument has to
    be different for each call to Markup().  The example below disables
    WikiWord links like COM1, COM2, COM1234, etc.
        Markup('COM\d+', '<wikilink', '/\\bCOM\\d+/', "Keep('$0')");
    
    Script maintained by Petko YOTOV www.pmwiki.org/petko
*/
SDV($LinkWikiWords, 1);
## bare wikilinks
Markup_e('wikilink', '>urllink', "/\\b(?<![#&])({$GroupPattern}([\\/.]))?({$WikiWordPattern})/", "Keep('<span class=\\'wikiword\\'>'.WikiLink(\$pagename,\$m[0]).'</span>',\n        'L')");
function WikiLink($pagename, $word)
{
    global $LinkWikiWords, $WikiWordCount, $SpaceWikiWords, $AsSpacedFunction, $MarkupFrame, $WikiWordCountMax;
    if (!$LinkWikiWords || $WikiWordCount[$word] < 0) {
        return $word;
    }
    $text = $SpaceWikiWords ? $AsSpacedFunction($word) : $word;
    $text = preg_replace('!.*/!', '', $text);
    if (!isset($MarkupFrame[0]['wwcount'][$word])) {
        $MarkupFrame[0]['wwcount'][$word] = $WikiWordCountMax;
    }
    if ($MarkupFrame[0]['wwcount'][$word]-- < 1) {
        return $text;
Ejemplo n.º 24
0
function HandleAttr($pagename)
{
    global $PageAttrFmt, $PageStartFmt, $PageEndFmt;
    $page = RetrieveAuthPage($pagename, 'attr');
    if (!$page) {
        Abort("?unable to read {$pagename}");
    }
    PCache($pagename, $page);
    SDV($PageAttrFmt, "<h1 class='wikiaction'>\$[\$FullName Attributes]</h1>\n    <p>Enter new attributes for this page below.  Leaving a field blank\n    will leave the attribute unchanged.  To clear an attribute, enter\n    'clear'.</p>");
    SDV($HandleAttrFmt, array(&$PageStartFmt, &$PageAttrFmt, 'function:PrintAttrForm', &$PageEndFmt));
    PrintFmt($pagename, $HandleAttrFmt);
}
Ejemplo n.º 25
0
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;
}
Ejemplo n.º 26
0
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);
}
Ejemplo n.º 27
0
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;
}
Ejemplo n.º 28
0
        }
        $t1 = $match[3];
        if ($t1 == '') {
            $t1 = '20380101';
        }
    } else {
        $t0 = $t1 = $match[1];
    }
    $t0 = preg_replace('/\\D/', '', $t0);
    if (!preg_match('/^(\\d{4})(\\d\\d)(\\d\\d)$/', $t0, $m)) {
        return false;
    }
    $g0 = mktime(0, 0, 0, $m[2], $m[3], $m[1]);
    if ($Now < $g0) {
        return false;
    }
    $t1 = preg_replace('/\\D/', '', $t1);
    $t1++;
    if (!preg_match('/^(\\d{4})(\\d\\d)(\\d\\d)$/', $t1, $m)) {
        return false;
    }
    $g1 = mktime(0, 0, 0, $m[2], $m[3], $m[1]);
    if ($Now >= $g1) {
        return false;
    }
    return true;
}
# This pattern enables the (:encrypt <phrase>:) markup/replace-on-save
# pattern.
SDV($ROSPatterns['/\\(:encrypt\\s+([^\\s:=]+).*?:\\)/e'], "crypt(PSS('\$1'))");
Ejemplo n.º 29
0
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));
}
Ejemplo n.º 30
0
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 -&gt; $n1</li>";
  }

  if ($message) {
    $migrateurl = "$ScriptUrl?action=upgrade&amp;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);
}