function add_to_category($page, $catlist) { global $pagestore, $Entity, $UserName, $REMOTE_ADDR, $FlgChr; // Parse the category list for category names. $parsed = parseText($catlist, array('parse_wikiname', 'parse_freelink'), ''); $pagenames = array(); preg_replace('/' . $FlgChr . '(\\d+)' . $FlgChr . '/e', '$pagenames[]=$Entity[\\1][1]', $parsed); if (validate_page($page) == 2) { $page = '((' . $page . '))'; } // Add it to each category. foreach ($pagenames as $category) { $pg = $pagestore->page($category); $pg->read(); if ($pg->exists) { if (preg_match('/\\[\\[!.*\\]\\]/', $pg->text)) { if (!preg_match("/\\[\\[!.*{$page}.*\\]\\]/", $pg->text)) { $pg->text = preg_replace('/(\\[\\[!.*)\\]\\]/', "\\1 {$page}]]", $pg->text); } else { continue; } } else { $pg->text = $pg->text . "\n[[! {$page}]]\n"; } $pg->text = str_replace("\\", "\\\\", $pg->text); $pg->text = str_replace("'", "\\'", $pg->text); $pg->version++; $pg->comment = ''; $pg->hostname = gethostbyaddr($REMOTE_ADDR); $pg->username = $UserName; $pg->write(); } } }
function parse($args, $page) { global $pagestore, $ParseEngine, $ParseObject; static $visited_array = array(); static $visited_count = 0; if (!validate_page($args)) { return '[[Transclude ' . $args . ']]'; } $visited_array[$visited_count++] = $ParseObject; for ($i = 0; $i < $visited_count; $i++) { if ($visited_array[$i] == $args) { $visited_count--; return '[[Transclude ' . $args . ']]'; } } $pg = $pagestore->page($args); $pg->read(); if (!$pg->exists) { $visited_count--; return '[[Transclude ' . $args . ']]'; } $result = parseText($pg->text, $ParseEngine, $args); $visited_count--; return $result; }
function action_prefs() { global $Save, $referrer, $user, $rows, $cols, $days, $min, $auth, $hist; global $CookieName, $tzoff; if (!empty($Save)) { if (!empty($user)) { if (!validate_page($user)) { die(ACTION_ErrorNameMatch); } } ereg("([[:digit:]]*)", $rows, $result); if (($rows = $result[1]) <= 0) { $rows = 20; } ereg("([[:digit:]]*)", $cols, $result); if (($cols = $result[1]) <= 0) { $cols = 65; } if (strcmp($auth, "") != 0) { $auth = 1; } else { $auth = 0; } $value = "rows={$rows}&cols={$cols}&auth={$auth}"; if (strcmp($user, "") != 0) { $value = $value . "&user="******"") != 0) { $value = $value . "&days={$days}"; } if (strcmp($min, "") != 0) { $value = $value . "&min={$min}"; } if (strcmp($hist, "") != 0) { $value = $value . "&hist={$hist}"; } if (strcmp($tzoff, "") != 0) { $value = $value . "&tzoff={$tzoff}"; } setcookie($CookieName, $value, time() + 157680000, "/", ""); header("Location: {$referrer}"); } else { template_prefs(); } }
function action_prefs() { global $CookieName, $days, $ErrorNameMatch, $hist, $hotpages, $min, $nickname; global $referrer, $rows, $Save, $tzoff, $user; if (!empty($Save)) { if (!empty($user)) { if (!validate_page($user)) { die($ErrorNameMatch); } } // make sure the nickname is not a valid username if (posix_getpwnam($nickname) !== false) { $referrer = '?action=prefs&invalid_nick=' . rawurlencode($nickname) . '&prefs_from=' . rawurlencode($referrer); $nickname = ''; } ereg("([[:digit:]]*)", $rows, $result); if (($rows = $result[1]) <= 0) { $rows = 20; } $hotpages = strcmp($hotpages, "") != 0 ? 1 : 0; $value = "rows={$rows}&hotpages={$hotpages}"; if (strcmp($nickname, '') != 0) { $value .= "&nickname=" . rawurlencode(trim($nickname)); } if (strcmp($days, "") != 0) { $value = $value . "&days={$days}"; } if (strcmp($min, "") != 0) { $value = $value . "&min={$min}"; } if (strcmp($hist, "") != 0) { $value = $value . "&hist={$hist}"; } if (strcmp($tzoff, "") != 0) { $value = $value . "&tzoff={$tzoff}"; } setcookie($CookieName, $value, time() + 157680000, "/", ""); header("Location: {$referrer}"); } else { template_prefs(); } }
function html_split_name($page) { global $UpperPtn, $LowerPtn; $title = get_title($page); if (validate_page($page) != 1) { return $title; } $page = preg_replace("/(?<={$UpperPtn}|{$LowerPtn})({$UpperPtn}{$LowerPtn})/", ' \\1', $title, -1); $page = preg_replace("/({$LowerPtn})({$UpperPtn})/", '\\1 \\2', $title, -1); return $page; }
function transclude_token($text) { global $pagestore, $ParseEngine, $ParseObject; static $visited_array = array(); static $visited_count = 0; if (!validate_page($text)) { return '%%' . $text . '%%'; } $visited_array[$visited_count++] = $ParseObject; for ($i = 0; $i < $visited_count; $i++) { if ($visited_array[$i] == $text) { $visited_count--; return '%%' . $text . '%%'; } } $pg = $pagestore->page($text); $pg->read(); if (!$pg->exists) { $visited_count--; return '%%' . $text . '%%'; } $result = new_entity(array('raw', parseText($pg->text, $ParseEngine, $text))); $visited_count--; return $result; }
function odt_ref($refPage, $appearance, $hover = '', $anchor = '', $anchor_appearance = '') { global $db, $SeparateLinkWords, $page, $pagestore, $ScriptBase; if ($page == 'RecentChanges') { $p_exists = $pagestore->page_exists($refPage); } else { $p = new WikiPage($db, $refPage); $p_exists = $p->exists(); // automatically handle plurals if (!$p_exists) { foreach (array('s', 'es') as $plural) { if (substr($refPage, -strlen($plural)) == $plural) { $temp_refPage = substr($refPage, 0, strlen($refPage) - strlen($plural)); $p = new WikiPage($db, $temp_refPage); if ($p_exists = $p->exists()) { $refPage = $temp_refPage; break; } } } } } if ($p_exists) { if ($SeparateLinkWords && $refPage == $appearance) { $appearance = html_split_name($refPage); } $url = $ScriptBase . '?page=' . urlencode($refPage) . $anchor; $result = odt_url($url, $appearance . $anchor_appearance); } else { $result = ""; if (validate_page($refPage) == 1 && $appearance == $refPage) { $result = $refPage; } else { // Free link. // Puts the appearance between parenthesis if there's a space in it. if (strpos($appearance, ' ') === false) { $tempAppearance = $appearance; } else { $tempAppearance = "({$appearance})"; } $result = $tempAppearance; } } return $result; }
$find = $q; } if ($action == 'find' && $find == '%s') { // small hack for browser bookmarklets $action = 'view'; $page = 'RecentChanges'; } if (empty($page) && empty($action)) { $page = $QUERY_STRING; } if (empty($action)) { $action = 'view'; } if (empty($page)) { $page = $HomePage; } // Confirm we have a valid page name. if (!validate_page($page)) { die($ErrorInvalidPage); } // Don't let people do too many things too quickly. if ($ActionList[$action][2] != '') { rateCheck($pagestore->dbh, $ActionList[$action][2]); } // Dispatch the appropriate action. if (!empty($ActionList[$action])) { include $ActionList[$action][0]; $ActionList[$action][1](); } // Expire old versions, etc. $pagestore->maintain();
function parse_redirect($text) { global $action, $no_redirect, $page, $version; if (preg_match('/^#redirect\\s+\\[?(.*?)\\]?\\s*$/i', $text, $matches) && validate_page($matches[1])) { if ($no_redirect || $action != 'view' || isset($version)) { $text = new_entity(array('raw', '#redirect ')) . wikiname_token($matches[1], ''); } else { header('Location: ' . viewUrl($matches[1]) . '&redirect_from=' . $page); exit; } } return $text; }