Update of /cvsroot/phpwiki/phpwiki/lib
In directory usw-pr-cvs1:/tmp/cvs-serv2684/lib
Modified Files:
config.php diff.php display.php editpage.php fullsearch.php
interwiki.php loadsave.php main.php pageinfo.php prepend.php
savepage.php search.php stdlib.php transform.php ziplib.php
Added Files:
ArchiveCleaner.php DbaDatabase.php DbaListSet.php
DbaPartition.php ErrorManager.php Request.php Template.php
TextSearchQuery.php WikiDB.php WikiPlugin.php WikiUser.php
Removed Files:
PhpWikiDatabase.php db_filesystem.php dbalib.php dbmlib.php
msql.php mysql.php pgsql.php userauth.php
Log Message:
Jeff's hacks II.
This is a major change, to say the least. Some highlights:
o Completely new database API.
WARNING: all database schemas (currently MySQL, Postgres and DBA
support is working) use completely revised schema, so you must
start this new code with a new blank database...
o WikiPlugins
o New template engine.
In addition, some more incremental changes:
o Cascading Style Sheets reworked.
o Expanded syntax for text search: e.g. "wiki OR wacky AND NOT page".
o PhpWiki should now work with register_globals off. (Security issue.)
o Edit preview button.
(and probably more, which I'm forgetting about now.)
Much of this code is still in a state of flux (particularly
the new template engine code, and to a lesser extent the API
for the plugins.)
Feel free to play and hack on this, just be warned that some of it may
still change quite a bit...
See pgsrc/ReleaseNotes for a few more notes.
And feel free to post questions or comments either publicly on
<php...@li...>, or privately, to
<da...@da...>.
***** Error reading new file: [Errno 2] No such file or directory: 'ArchiveCleaner.php'
***** Error reading new file: [Errno 2] No such file or directory: 'DbaDatabase.php'
***** Error reading new file: [Errno 2] No such file or directory: 'DbaListSet.php'
***** Error reading new file: [Errno 2] No such file or directory: 'DbaPartition.php'
***** Error reading new file: [Errno 2] No such file or directory: 'ErrorManager.php'
***** Error reading new file: [Errno 2] No such file or directory: 'Request.php'
***** Error reading new file: [Errno 2] No such file or directory: 'Template.php'
--- NEW FILE ---
<?php
/**
* A text search query.
*
* This represents "Google-like" text search queries like:
* <dl>
* <dt> wiki -test
* <dd> Match strings containing the substring 'wiki', and not containing the
* substring 'test'.
* <dt> wiki word or page
* <dd> Match strings containing the substring 'wiki' and either the substring
* 'word' or the substring 'page'.
* </dl>
*
* The full query syntax, in order of precedence, is roughly:
*
* The unary 'NOT' or '-' operator (they are equivalent) negates the
* following search clause.
*
* Search clauses may be joined with the (left-associative) binary operators
* 'AND' and 'OR'.
*
* Two adjoining search clauses are joined with an implicit 'AND'. This has
* lower precedence than either an explicit 'AND' or 'OR', so "a b OR c"
* parses as "a AND ( b OR c )", while "a AND b OR c" parses as
* "( a AND b ) OR c" (due to the left-associativity of 'AND' and 'OR'.)
*
* Search clauses can be grouped with parentheses.
*
* Phrases (or other things which don't look like words) can be forced to
* be interpreted as words by quoting them, either with single (') or double (")
* quotes. If you wan't to include the quote character within a quoted string,
* double-up on the quote character: 'I''m hungry' is equivalent to
* "I'm hungry".
*/
class TextSearchQuery {
/**
* Create a new query.
*
* @param $search_query string The query. Syntax is as described above.
* Note that an empty $search_query will match anything.
* @see TextSearchQuery
*/
function TextSearchQuery($search_query) {
$parser = new TextSearchQuery_Parser;
$this->_tree = $parser->parse($search_query);
$this->_optimize();
}
function _optimize() {
$this->_tree = $this->_tree->optimize();
}
/**
* Get a regexp which matches the query.
*/
function asRegexp() {
if (!isset($this->_regexp))
$this->_regexp = '/^' . $this->_tree->regexp() . '/isS';
return $this->_regexp;
}
/**
* Match query against string.
*
* @param $string string The string to match.
* @return boolean True if the string matches the query.
*/
function match($string) {
return preg_match($this->asRegexp(), $string);
}
/**
* Get a regular expression suitable for highlighting matched words.
*
* This returns a PCRE regular expression which matches any non-negated
* word in the query.
*
* @return string The PCRE regexp.
*/
function getHighlightRegexp() {
if (!isset($this->_hilight_regexp)) {
$words = array_unique($this->_tree->highlight_words());
if (!$words) {
$this->_hilight_regexp = false;
}
else {
foreach ($words as $key => $word)
$words[$key] = preg_quote($word, '/');
$this->_hilight_regexp = '(?:' . join('|', $words) . ')';
}
}
return $this->_hilight_regexp;
}
/**
* Make an SQL clause which matches the query.
*
* @param $make_sql_clause_func string,function or array
* A callback which takes a single word as an argument and
* returns an SQL clause which will match exactly those records
* containing the word. The word passed to the callback will always
* be in all lower case.
*
* If $make_sql_clause_func is an array, it is interpreted as a method
* callback. The first element of the array is the object, the second
* element (a string) is the name of the method.
*
* If $make_sql_clause_func is a string, it is taken to be the name
* of a global function to call.
*
* Otherwise, $make_sql_clause_func is assumed to be a function object
* (created by create_function()).
*
* Example usage:
* <pre>
* function sql_title_match($word) {
* return sprintf("LOWER(title) like '%s'",
* addslashes($word));
* }
*
* ...
*
* $query = new TextSearchQuery("wiki -page");
* $sql_clause = $query->makeSqlClause('sql_title_match');
* </pre>
* This will result in $sql_clause containing something like
* "(LOWER(title) like 'wiki') AND NOT (LOWER(title) like 'page')".
*
* @return string The PCRE regexp.
*/
function makeSqlClause($make_sql_clause_func) {
$this->_sql_clause_func = $make_sql_clause_func;
return $this->_sql_clause($this->_tree);
}
function _sql_clause($node) {
switch ($node->op) {
case 'WORD':
$callback = $this->_sql_clause_func;
if (is_array($callback)) {
list($object, $method) = $callback;
return call_user_method($method, $object, $node->word);
}
elseif (is_string($callback))
return call_user_func($callback, $node->word);
else
return $callback($node->word);
case 'NOT':
return "NOT (" . $this->_sql_clause($node->leaves[0]) . ")";
case 'AND':
case 'OR':
$subclauses = array();
foreach ($node->leaves as $leaf)
$subclauses[] = "(" . $this->_sql_clause($leaf) . ")";
return join(" $node->op ", $subclauses);
default:
assert($node->op == 'VOID');
return '1=1';
}
}
/**
* Get printable representation of the parse tree.
*
* This is for debugging only.
* @return string Printable parse tree.
*/
function asString() {
return $this->_as_string($this->_tree);
}
function _as_string($node, $indent = '') {
switch ($node->op) {
case 'WORD':
return $indent . "WORD: $node->word";
case 'VOID':
return $indent . "VOID";
default:
$lines = array($indent . $node->op . ":");
$indent .= " ";
foreach ($node->leaves as $leaf)
$lines[] = $this->_as_string($leaf, $indent);
return join("\n", $lines);
}
}
}
////////////////////////////////////////////////////////////////
//
// Remaining classes are private.
//
////////////////////////////////////////////////////////////////
/**
* Virtual base class for nodes in a TextSearchQuery parse tree.
*
* Also servers as a 'VOID' (contentless) node.
*/
class TextSearchQuery_node
{
var $op = 'VOID';
/**
* Optimize this node.
* @return object Optimized node.
*/
function optimize() {
return $this;
}
/**
* @return regexp matching this node.
*/
function regexp() {
return '';
}
/**
* @param bool True if this node has been negated (higher in the parse tree.)
* @return array A list of all non-negated words contained by this node.
*/
function highlight_words($negated = false) {
return array();
}
}
/**
* A word.
*/
class TextSearchQuery_node_word
extends TextSearchQuery_node
{
var $op = "WORD";
function TextSearchQuery_node_word($word) {
$this->word = $word;
}
function regexp() {
return '(?=.*' . preg_quote($this->word, '/') . ')';
}
function highlight_words($negated = false) {
return $negated ? array() : array($this->word);
}
}
/**
* A negated clause.
*/
class TextSearchQuery_node_not
extends TextSearchQuery_node
{
var $op = "NOT";
function TextSearchQuery_node_not($leaf) {
$this->leaves = array($leaf);
}
function optimize() {
$leaf = &$this->leaves[0];
$leaf = $leaf->optimize();
if ($leaf->op == 'NOT')
return $leaf->leaves[0]; // ( NOT ( NOT x ) ) -> x
return $this;
}
function regexp() {
$leaf = &$this->leaves[0];
return '(?!' . $leaf->regexp() . ')';
}
function highlight_words($negated = false) {
return $this->leaves[0]->highlight_words(!$negated);
}
}
/**
* Virtual base class for 'AND' and 'OR conjoins.
*/
class TextSearchQuery_node_binop
extends TextSearchQuery_node
{
function TextSearchQuery_node_binop($leaves) {
$this->leaves = $leaves;
}
function _flatten() {
// This flattens e.g. (AND (AND a b) (OR c d) e)
// to (AND a b e (OR c d))
$flat = array();
foreach ($this->leaves as $leaf) {
$leaf = $leaf->optimize();
if ($this->op == $leaf->op)
$flat = array_merge($flat, $leaf->leaves);
else
$flat[] = $leaf;
}
$this->leaves = $flat;
}
function optimize() {
$this->_flatten();
assert(!empty($this->leaves));
if (count($this->leaves) == 1)
return $this->leaves[0]; // (AND x) -> x
return $this;
}
function highlight_words($negated = false) {
$words = array();
foreach ($this->leaves as $leaf)
array_splice($words,0,0,
$leaf->highlight_words($negated));
return $words;
}
}
/**
* A (possibly multi-argument) 'AND' conjoin.
*/
class TextSearchQuery_node_and
extends TextSearchQuery_node_binop
{
var $op = "AND";
function optimize() {
$this->_flatten();
// Convert (AND (NOT a) (NOT b) c d) into (AND (NOT (OR a b)) c d).
// Since OR's are more efficient for regexp matching:
// (?!.*a)(?!.*b) vs (?!.*(?:a|b))
// Suck out the negated leaves.
$nots = array();
foreach ($this->leaves as $key => $leaf) {
if ($leaf->op == 'NOT') {
$nots[] = $leaf->leaves[0];
unset($this->leaves[$key]);
}
}
// Combine the negated leaves into a single negated or.
if ($nots) {
$node = ( new TextSearchQuery_node_not
(new TextSearchQuery_node_or($nots)) );
array_unshift($this->leaves, $node->optimize());
}
assert(!empty($this->leaves));
if (count($this->leaves) == 1)
return $this->leaves[0]; // (AND x) -> x
return $this;
}
function regexp() {
$regexp = '';
foreach ($this->leaves as $leaf)
$regexp .= $leaf->regexp();
return $regexp;
}
}
/**
* A (possibly multi-argument) 'OR' conjoin.
*/
class TextSearchQuery_node_or
extends TextSearchQuery_node_binop
{
var $op = "OR";
function regexp() {
// We will combine any of our direct descendents which are WORDs
// into a single (?=.*(?:word1|word2|...)) regexp.
$regexps = array();
$words = array();
foreach ($this->leaves as $leaf) {
if ($leaf->op == 'WORD')
$words[] = preg_quote($leaf->word, '/');
else
$regexps[] = $leaf->regexp();
}
if ($words)
array_unshift($regexps,
'(?=.*' . $this->_join($words) . ')');
return $this->_join($regexps);
}
function _join($regexps) {
assert(count($regexps) > 0);
if (count($regexps) > 1)
return '(?:' . join('|', $regexps) . ')';
else
return $regexps[0];
}
}
////////////////////////////////////////////////////////////////
//
// Parser:
//
////////////////////////////////////////////////////////////////
define ('TSQ_TOK_WORD', 1);
define ('TSQ_TOK_BINOP', 2);
define ('TSQ_TOK_NOT', 4);
define ('TSQ_TOK_LPAREN', 8);
define ('TSQ_TOK_RPAREN', 16);
class TextSearchQuery_Parser
{
/*
* This is a simple recursive descent parser, based on the following grammar:
*
* toplist :
* | toplist expr
* ;
*
*
* list : expr
* | list expr
* ;
*
* expr : atom
* | expr BINOP atom
* ;
*
* atom : '(' list ')'
* | NOT atom
* | WORD
* ;
*
* The terminal tokens are:
*
*
* and|or BINOP
* -|not NOT
* ( LPAREN
* ) RPAREN
* [^-()\s][^()\s]* WORD
* "[^"]*" WORD
* '[^']*' WORD
*/
function parse ($search_expr) {
$this->lexer = new TextSearchQuery_Lexer($search_expr);
$tree = $this->get_list('toplevel');
assert($this->lexer->eof());
unset($this->lexer);
return $tree;
}
function get_list ($is_toplevel = false) {
$list = array();
// token types we'll accept as words (and thus expr's) for the
// purpose of error recovery:
$accept_as_words = TSQ_TOK_NOT | TSQ_TOK_BINOP;
if ($is_toplevel)
$accept_as_words |= TSQ_TOK_LPAREN | TSQ_TOK_RPAREN;
while ( ($expr = $this->get_expr())
|| ($expr = $this->get_word($accept_as_words)) ) {
$list[] = $expr;
}
if (!$list) {
if ($is_toplevel)
return new TextSearchQuery_node;
else
return false;
}
return new TextSearchQuery_node_and($list);
}
function get_expr () {
if ( !($expr = $this->get_atom()) )
return false;
$savedpos = $this->lexer->tell();
while ( ($op = $this->lexer->get(TSQ_TOK_BINOP)) ) {
if ( ! ($right = $this->get_atom()) ) {
break;
}
if ($op == 'and')
$expr = new TextSearchQuery_node_and(array($expr, $right));
else {
assert($op == 'or');
$expr = new TextSearchQuery_node_or(array($expr, $right));
}
$savedpos = $this->lexer->tell();
}
$this->lexer->seek($savedpos);
return $expr;
}
function get_atom() {
if ($word = $this->get_word())
return $word;
$savedpos = $this->lexer->tell();
if ( $this->lexer->get(TSQ_TOK_LPAREN) ) {
if ( ($list = $this->get_list()) && $this->lexer->get(TSQ_TOK_RPAREN) )
return $list;
}
elseif ( $this->lexer->get(TSQ_TOK_NOT) ) {
if ( ($atom = $this->get_atom()) )
return new TextSearchQuery_node_not($atom);
}
$this->lexer->seek($savedpos);
return false;
}
function get_word($accept = TSQ_TOK_WORD) {
if ( ($word = $this->lexer->get($accept)) )
return new TextSearchQuery_node_word($word);
return false;
}
}
class TextSearchQuery_Lexer {
function TextSearchQuery_Lexer ($query_str) {
$this->tokens = $this->tokenize($query_str);
$this->pos = 0;
}
function tell() {
return $this->pos;
}
function seek($pos) {
$this->pos = $pos;
}
function eof() {
return $this->pos == count($this->tokens);
}
function tokenize($string) {
$tokens = array();
$buf = strtolower(ltrim($string));
while (!empty($buf)) {
if (preg_match('/^(and|or)\s*/', $buf, $m)) {
$val = $m[1];
$type = TSQ_TOK_BINOP;
}
elseif (preg_match('/^(-|not)\s*/', $buf, $m)) {
$val = $m[1];
$type = TSQ_TOK_NOT;
}
elseif (preg_match('/^([()])\s*/', $buf, $m)) {
$val = $m[1];
$type = $m[1] == '(' ? TSQ_TOK_LPAREN : TSQ_TOK_RPAREN;
}
elseif (preg_match('/^ " ( (?: [^"]+ | "" )* ) " \s*/x', $buf, $m)) {
$val = str_replace('""', '"', $m[1]);
$type = TSQ_TOK_WORD;
}
elseif (preg_match("/^ ' ( (?:[^']+|'')* ) ' \s*/x", $buf, $m)) {
$val = str_replace("''", "'", $m[1]);
$type = TSQ_TOK_WORD;
}
elseif (preg_match('/^([^-()][^()\s]*)\s*/', $buf, $m)) {
$val = $m[1];
$type = TSQ_TOK_WORD;
}
else {
assert(empty($buf));
break;
}
$buf = substr($buf, strlen($m[0]));
$tokens[] = array($type, $val);
}
return $tokens;
}
function get($accept) {
if ($this->pos >= count($this->tokens))
return false;
list ($type, $val) = $this->tokens[$this->pos];
if (($type & $accept) == 0)
return false;
$this->pos++;
return $val;
}
}
// Local Variables:
// mode: php
// tab-width: 8
// c-basic-offset: 4
// c-hanging-comment-ender-p: nil
// indent-tabs-mode: nil
// End:
?>
***** Error reading new file: [Errno 2] No such file or directory: 'WikiDB.php'
***** Error reading new file: [Errno 2] No such file or directory: 'WikiPlugin.php'
***** Error reading new file: [Errno 2] No such file or directory: 'WikiUser.php'
Index: config.php
===================================================================
RCS file: /cvsroot/phpwiki/phpwiki/lib/config.php,v
retrieving revision 1.40
retrieving revision 1.41
diff -C2 -r1.40 -r1.41
*** config.php 2001/05/31 17:39:02 1.40
--- config.php 2001/09/18 19:16:23 1.41
***************
*** 24,31 ****
$FieldSeparator = "\x81";
-
- // constants for flags in $pagehash
- define("FLAG_PAGE_LOCKED", 1);
-
// Search PHP's include_path to find file or directory.
function FindFile ($file, $missing_okay = false)
--- 24,27 ----
***************
*** 90,93 ****
--- 86,93 ----
}
+ // Setup localisation
+ setlocale(LC_ALL, "$LANG");
+ putenv("LC_ALL=$LANG");
+
if (!function_exists ('gettext'))
{
***************
*** 109,114 ****
{
// Setup localisation
- setlocale(LC_ALL, "$LANG");
- putenv("LC_ALL=$LANG");
bindtextdomain ("phpwiki", FindFile("locale"));
textdomain ("phpwiki");
--- 109,112 ----
***************
*** 187,193 ****
// Autodetect URL settings:
//
! if (!defined('SERVER_NAME')) define('SERVER_NAME', $SERVER_NAME);
! if (!defined('SERVER_PORT')) define('SERVER_PORT', $SERVER_PORT);
! if (!defined('SCRIPT_NAME')) define('SCRIPT_NAME', $SCRIPT_NAME);
if (!defined('DATA_PATH'))
define('DATA_PATH', dirname(SCRIPT_NAME));
--- 185,191 ----
// Autodetect URL settings:
//
! if (!defined('SERVER_NAME')) define('SERVER_NAME', $HTTP_SERVER_VARS['SERVER_NAME']);
! if (!defined('SERVER_PORT')) define('SERVER_PORT', $HTTP_SERVER_VARS['SERVER_PORT']);
! if (!defined('SCRIPT_NAME')) define('SCRIPT_NAME', $HTTP_SERVER_VARS['SCRIPT_NAME']);
if (!defined('DATA_PATH'))
define('DATA_PATH', dirname(SCRIPT_NAME));
***************
*** 220,224 ****
// e.g. /dir/index.php/HomePage.
! global $REQUEST_URI, $SCRIPT_NAME;
$requri = preg_quote($REQUEST_URI, '%');
--- 218,223 ----
// e.g. /dir/index.php/HomePage.
! //global $REQUEST_URI, $SCRIPT_NAME;
! extract($GLOBALS['HTTP_SERVER_VARS']);
$requri = preg_quote($REQUEST_URI, '%');
***************
*** 249,252 ****
--- 248,252 ----
//
+ $REDIRECT_URL = &$HTTP_SERVER_VARS['REDIRECT_URL'];
if (USE_PATH_INFO and isset($REDIRECT_URL)
and ! IsProbablyRedirectToIndex())
***************
*** 281,315 ****
if (empty($DBParams['dbtype']))
{
! if ( floor(phpversion()) == 3) {
! $DBParams['dbtype'] = 'dbm';
! } else {
! $DBParams['dbtype'] = 'dba';
! }
}
- switch ($DBParams['dbtype'])
- {
- case 'dbm':
- include 'lib/dbmlib.php';
- break;
- case 'dba':
- include 'lib/dbalib.php';
- break;
- case 'mysql':
- include 'lib/mysql.php';
- break;
- case 'pgsql':
- include 'lib/pgsql.php';
- break;
- case 'msql':
- include 'lib/msql.php';
- break;
- case 'file':
- include "lib/db_filesystem.php";
- break;
- default:
- ExitWiki($DBParams['dbtype'] . ": unknown DBTYPE");
- }
-
// InterWiki linking -- wiki-style links to other wikis on the web
//
--- 281,287 ----
if (empty($DBParams['dbtype']))
{
! $DBParams['dbtype'] = 'dba';
}
// InterWiki linking -- wiki-style links to other wikis on the web
//
***************
*** 319,329 ****
}
// Access log
if (!defined('ACCESS_LOG'))
define('ACCESS_LOG', '');
!
// Get remote host name, if apache hasn't done it for us
! if (empty($REMOTE_HOST) && ENABLE_REVERSE_DNS)
! $REMOTE_HOST = gethostbyaddr($REMOTE_ADDR);
--- 291,303 ----
}
+ // FIXME: delete
// Access log
if (!defined('ACCESS_LOG'))
define('ACCESS_LOG', '');
!
! // FIXME: delete
// Get remote host name, if apache hasn't done it for us
! if (empty($HTTP_SERVER_VARS['REMOTE_HOST']) && ENABLE_REVERSE_DNS)
! $HTTP_SERVER_VARS['REMOTE_HOST'] = gethostbyaddr($HTTP_SERVER_VARS['REMOTE_ADDR']);
Index: diff.php
===================================================================
RCS file: /cvsroot/phpwiki/phpwiki/lib/diff.php,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -r1.12 -r1.13
*** diff.php 2001/06/26 18:03:41 1.12
--- diff.php 2001/09/18 19:16:23 1.13
***************
*** 1025,1029 ****
/////////////////////////////////////////////////////////////////
! function PageInfoRow ($label, $hash)
{
global $datetimeformat;
--- 1025,1029 ----
/////////////////////////////////////////////////////////////////
! function PageInfoRow ($pagename, $label, $rev)
{
global $datetimeformat;
***************
*** 1031,1085 ****
$cols = QElement('td', array('align' => 'right'), $label);
! if (is_array($hash)) {
! extract($hash);
! $cols .= QElement('td',
! sprintf(gettext ("version %s"), $version));
! $cols .= QElement('td',
! sprintf(gettext ("last modified on %s"),
! strftime($datetimeformat, $lastmodified)));
! $cols .= QElement('td',
! sprintf(gettext ("by %s"), $author));
} else {
! $cols .= QElement('td', array('colspan' => '3'),
! gettext ("None"));
}
return Element('tr', $cols);
}
! if (isset($pagename))
! {
! if (!isset($ver1)) {
! if (isset($ver2)) $ver1 = $ver2 - 1;
! else {
! $ver1 = GetMaxVersionNumber($dbi, $pagename, $ArchivePageStore);
! $ver2 = 0;
! }
! }
! elseif (!isset($ver2)) $ver2 = 0;
!
! $older = RetrievePage($dbi, $pagename, SelectStore($dbi, $pagename, $ver1, $WikiPageStore, $ArchivePageStore), $ver1);
! $newer = RetrievePage($dbi, $pagename, SelectStore($dbi, $pagename, $ver2, $WikiPageStore, $ArchivePageStore), $ver2);
!
! $html = Element('table',
! PageInfoRow(gettext ("Newer page:"), $newer)
! . PageInfoRow(gettext ("Older page:"), $older));
!
! $html .= "<p>\n";
!
! if (is_array($newer) && is_array($older))
! {
! $diff = new WikiDiff($older['content'], $newer['content']);
! if ($diff->isEmpty()) {
! $html .= '<hr>[' . gettext ("Versions are identical") . ']';
! } else {
! //$fmt = new WikiDiffFormatter;
! $fmt = new WikiUnifiedDiffFormatter;
! $html .= $fmt->format($diff, $older['content']);
! }
}
! echo GeneratePage('MESSAGE', $html,
! sprintf(gettext ("Diff of %s."), $pagename), 0);
}
?>
--- 1031,1164 ----
$cols = QElement('td', array('align' => 'right'), $label);
+ if ($rev) {
+ $url = WikiURL($pagename, array('version' => $rev->getVersion()));
+ $linked_version = QElement('a', array('href' => $url), $rev->getVersion());
+ $cols .= Element('td',
+ gettext("version") . " " . $linked_version);
! $cols .= QElement('td',
! sprintf(gettext ("last modified on %s"),
! strftime($datetimeformat, $rev->get('mtime'))));
! $cols .= QElement('td',
! sprintf(gettext ("by %s"), $rev->get('author')));
} else {
! $cols .= QElement('td', array('colspan' => '3'),
! gettext ("None"));
}
return Element('tr', $cols);
}
! function showDiff ($dbi, $request) {
! $pagename = $request->getArg('pagename');
! $version = $request->getArg('version');
! $previous = $request->getArg('previous');
!
! $page = $dbi->getPage($pagename);
!
! if ($version) {
! if (!($new = $page->getRevision($version)))
! NoSuchRevision($page, $version);
! $new_version = sprintf(gettext("version %d"), $version);
! }
! else {
! $new = $page->getCurrentRevision();
! $new_version = gettext('current version');
! }
!
! if (preg_match('/^\d+$/', $previous)) {
! if ( !($old = $page->getRevision($previous)) )
! NoSuchRevision($page, $previous);
! $old_version = sprintf(gettext("version %d"), $previous);
! $others = array('major', 'minor', 'author');
! }
! else {
! switch ($previous) {
! case 'major':
! $old = $new;
! while ($old = $page->getRevisionBefore($old)) {
! if (! $old->get('is_minor_edit'))
! break;
! }
! $old_version = gettext("previous major revision");
! $others = array('minor', 'author');
! break;
! case 'author':
! $old = $new;
! while ($old = $page->getRevisionBefore($old)) {
! if ($old->get('author') != $new->get('author'))
! break;
! }
! $old_version = gettext("revision by previous author");
! $others = array('major', 'minor');
! break;
! case 'minor':
! default:
! $previous='minor';
! $old = $page->getRevisionBefore($new);
! $old_version = gettext("previous revision");
! $others = array('major', 'author');
! break;
! }
}
! $new_url = WikiURL($pagename, array('version' => $new->getVersion()));
! $new_link = QElement('a', array('href' => $new_url), $new_version);
! $old_url = WikiURL($pagename, array('version' => $old ? $old->getVersion() : 0));
! $old_link = QElement('a', array('href' => $old_url), $old_version);
! $page_link = LinkExistingWikiWord($pagename);
!
! $html = Element('p',
! sprintf(htmlspecialchars(gettext("Differences between %s and %s of %s.")),
! $new_link, $old_link, $page_link));
!
! $otherdiffs='';
! $label = array('major' => gettext("Previous Major Revision"),
! 'minor' => gettext("Previous Revision"),
! 'author'=> gettext("Previous Author"));
! foreach ($others as $other) {
! $args = array('action' => 'diff', 'previous' => $other);
! if ($version)
! $args['version'] = $version;
! $otherdiffs .= ' ' . QElement('a', array('href' => WikiURL($pagename, $args),
! 'class' => 'wikiaction'),
! $label[$other]);
! }
! $html .= Element('p',
! htmlspecialchars(gettext("Other diffs:"))
! . $otherdiffs);
!
!
! if ($old and $old->getVersion() == 0)
! $old = false;
!
! $html .= Element('table',
! PageInfoRow($pagename, gettext ("Newer page:"), $new)
! . PageInfoRow($pagename, gettext ("Older page:"), $old));
!
! $html .= "<p>\n";
!
! if ($new && $old) {
! $diff = new WikiDiff($old->getContent(), $new->getContent());
! if ($diff->isEmpty()) {
! $html .= '<hr>[' . gettext ("Versions are identical") . ']';
! }
! else {
! //$fmt = new WikiDiffFormatter;
! $fmt = new WikiUnifiedDiffFormatter;
! $html .= $fmt->format($diff, $old->getContent());
! }
! }
!
! include_once('lib/Template.php');
! echo GeneratePage('MESSAGE', $html,
! sprintf(gettext ("Diff: %s"), $pagename));
}
+
+ // Local Variables:
+ // mode: php
+ // tab-width: 8
+ // c-basic-offset: 4
+ // c-hanging-comment-ender-p: nil
+ // indent-tabs-mode: nil
+ // End:
?>
Index: display.php
===================================================================
RCS file: /cvsroot/phpwiki/phpwiki/lib/display.php,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** display.php 2001/06/26 18:04:54 1.9
--- display.php 2001/09/18 19:16:23 1.10
***************
*** 1,26 ****
<?php
! // display.php: fetch page or get default content
! // calls transform.php for actual transformation of wiki markup to HTML
! rcs_id('$Id$');
! if (!isset($version)) $version = 0;
! $pagestore = SelectStore($dbi, $pagename, $version, $WikiPageStore, $ArchivePageStore);
! $pagehash = RetrievePage($dbi, $pagename, $pagestore, $version);
!
! $html = "";
! // we render the page if it exists, else ask the user to write one.
! if (is_array($pagehash)) {
! // transform.php returns $html containing all the HTML markup
! include("lib/transform.php");
! } else {
! $html .= sprintf(gettext("Describe %s here."),
! LinkUnknownWikiWord($pagename));
}
! echo GeneratePage('BROWSE', $html, $pagename, $pagehash);
flush();
- IncreaseHitCount($dbi, $pagename);
// For emacs users
// Local Variables:
--- 1,32 ----
<?php
! // display.php: fetch page or get default content
! // calls transform.php for actual transformation of wiki markup to HTML
! rcs_id('$Id$');
! require_once('lib/Template.php');
! require_once('lib/transform.php');
! function displayPage($dbi, $request) {
! $pagename = $request->getArg('pagename');
! $version = $request->getArg('version');
!
! $page = $dbi->getPage($pagename);
! if ($version) {
! $revision = $page->getRevision($version);
! if (!$revision)
! NoSuchRevision($page, $version);
! }
! else {
! $revision = $page->getCurrentRevision();
}
! $template = new WikiTemplate('BROWSE');
! $template->setPageRevisionTokens($revision);
! $template->replace('CONTENT', do_transform($revision->getContent()));
! echo $template->getExpansion();
flush();
+ $page->increaseHitCount();
+ }
// For emacs users
// Local Variables:
Index: editpage.php
===================================================================
RCS file: /cvsroot/phpwiki/phpwiki/lib/editpage.php,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -r1.16 -r1.17
*** editpage.php 2001/06/26 18:08:32 1.16
--- editpage.php 2001/09/18 19:16:23 1.17
***************
*** 2,44 ****
rcs_id('$Id$');
! // editpage relies on $pagename, $version
! $currentpage = RetrievePage($dbi, $pagename, SelectStore($dbi, $pagename, $version, $WikiPageStore, $ArchivePageStore), $version);
- $banner = htmlspecialchars($pagename);
- $pagehash = $currentpage;
-
- if (is_array($pagehash)) {
- if (($pagehash['flags'] & FLAG_PAGE_LOCKED) && !$user->is_admin()) {
- $html = "<p>";
- $html .= gettext ("This page has been locked by the administrator and cannot be edited.");
- $html .= "\n<p>";
- $html .= gettext ("Sorry for the inconvenience.");
- $html .= "\n";
- echo GeneratePage('MESSAGE', $html, sprintf (gettext ("Problem while editing %s"), $pagename), 0);
- ExitWiki ("");
- }
-
- $textarea = htmlspecialchars(implode("\n", $pagehash["content"]));
- }
- else {
- if (preg_match("/^${WikiNameRegexp}\$/", $pagename)) $newpage = $pagename;
- else $newpage = "[$pagename]";
-
- $textarea = htmlspecialchars(sprintf(gettext("Describe %s here."), $newpage));
-
- unset($pagehash);
- $pagehash["version"] = 0;
- $pagehash["lastmodified"] = time();
- $pagehash["author"] = '';
- $currentpage = $pagehash;
- }
-
- echo GeneratePage('EDITPAGE', $textarea, $pagename, $pagehash);
-
- // For emacs users
// Local Variables:
// mode: php
! // c-file-style: "ellemtel"
// End:
?>
--- 2,62 ----
rcs_id('$Id$');
! require_once('lib/Template.php');
! function editPage($dbi, $request) {
! // editpage relies on $pagename, $version
! $pagename = $request->getArg('pagename');
! $version = $request->getArg('version');
!
! $page = $dbi->getPage($pagename);
! $current = $page->getCurrentRevision();
!
! if ($version === false) {
! $selected = $current;
! }
! else {
! $selected = $page->getRevision($version);
! if (!$selected)
! NoSuchRevision($page, $version); // noreturn
! }
!
! global $user; // FIXME: make this non-global.
! if ($page->get('locked') && !$user->is_admin()) {
! $html = "<p>";
! $html .= gettext ("This page has been locked by the administrator and cannot be edited.");
! $html .= "\n<p>";
! $html .= gettext ("Sorry for the inconvenience.");
! $html .= "\n";
!
! echo GeneratePage('MESSAGE', $html,
! sprintf(gettext("Problem while editing %s"), $args->pagename),
! $selected);
! ExitWiki ("");
! }
!
!
! $age = time() - $current->get('mtime');
! $minor_edit = ( $age < MINOR_EDIT_TIMEOUT && $current->get('author') == $user->id() );
!
! $formvars = array('content' => htmlspecialchars($selected->getPackedContent()),
! 'minor_edit' => $minor_edit ? 'checked' : '',
! 'version' => $selected->getVersion(),
! 'editversion' => $current->getVersion(),
! 'summary' => '',
! 'convert' => '',
! 'pagename' => htmlspecialchars($pagename));
!
! $template = new WikiTemplate('EDITPAGE');
! $template->setPageRevisionTokens($selected);
! $template->replace('FORMVARS', $formvars);
! echo $template->getExpansion();
! }
// Local Variables:
// mode: php
! // tab-width: 8
! // c-basic-offset: 4
! // c-hanging-comment-ender-p: nil
! // indent-tabs-mode: nil
// End:
?>
Index: fullsearch.php
===================================================================
RCS file: /cvsroot/phpwiki/phpwiki/lib/fullsearch.php,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** fullsearch.php 2001/02/12 01:43:10 1.6
--- fullsearch.php 2001/09/18 19:16:23 1.7
***************
*** 1,48 ****
<?php
! // Search the text of pages for a match.
! rcs_id('$Id$');
!
! if (empty($searchterm))
! $searchterm = ''; // FIXME: do something better here?
!
! fix_magic_quotes_gpc($searchterm);
!
! $html = "<P><B>"
! . sprintf(gettext ("Searching for \"%s\" ....."),
! htmlspecialchars($searchterm))
! . "</B></P>\n<DL>\n";
!
! // search matching pages
! $query = InitFullSearch($dbi, $searchterm);
!
! // quote regexp chars (space are treated as "or" operator)
! $qterm = preg_replace("/\s+/", "|", preg_quote($searchterm));
!
! $found = 0;
! $count = 0;
! while ($pagehash = FullSearchNextMatch($dbi, $query)) {
! $html .= "<DT><B>" . LinkExistingWikiWord($pagehash["pagename"]) . "</B>\n";
! $count++;
!
! // print out all matching lines, highlighting the match
! for ($j = 0; $j < (count($pagehash["content"])); $j++) {
! if ($hits = preg_match_all("/$qterm/i", $pagehash["content"][$j], $dummy)) {
! $matched = preg_replace("/$qterm/i",
! "${FieldSeparator}OT\\0${FieldSeparator}CT",
! $pagehash["content"][$j]);
! $matched = htmlspecialchars($matched);
! $matched = str_replace("${FieldSeparator}OT", '<b>', $matched);
! $matched = str_replace("${FieldSeparator}CT", '</b>', $matched);
! $html .= "<dd><small>$matched</small></dd>\n";
$found += $hits;
! }
! }
! }
!
! $html .= "</dl>\n<hr noshade>"
! . sprintf (gettext ("%d matches found in %d pages."),
! $found, $count)
! . "\n";
!
! echo GeneratePage('MESSAGE', $html, gettext ("Full Text Search Results"), 0);
?>
--- 1,51 ----
<?php
! // Search the text of pages for a match.
! rcs_id('$Id$');
! require_once('lib/Template.php');
! require_once('lib/TextSearchQuery.php');
!
! $query = new TextSearchQuery($args->get('searchterm'));
!
! $html = ("<p><b>"
! . sprintf(gettext ("Searching for \"%s\" ....."),
! htmlspecialchars($args->get('searchterm')))
! . "</b></p>\n<dl>\n" );
!
! // search matching pages
! $iter = $dbi->fullsearch($query);
!
! // quote regexp chars (space are treated as "or" operator)
! $hilight_re = $query->getHighlightRegexp();
!
! $found = 0;
! $count = 0;
! while ($page = $iter->next()) {
! $html .= "<dt><b>" . LinkExistingWikiWord($page->getName()) . "</b>\n";
! $count++;
! if (empty($hilight_re))
! continue; // nothing to highlight
!
! // print out all matching lines, highlighting the match
! $current = $page->getCurrentRevision();
! $matches = preg_grep("/$hilight_re/i", $current->getContent());
! foreach ($matches as $line) {
! if ($hits = preg_match_all("/$hilight_re/i", $line, $dummy)) {
! $line = preg_replace("/$hilight_re/i",
! "${FieldSeparator}OT\\0${FieldSeparator}CT",
! $line);
! $line = htmlspecialchars($line);
! $line = str_replace("${FieldSeparator}OT", '<b>', $line);
! $line = str_replace("${FieldSeparator}CT", '</b>', $line);
! $html .= "<dd><small>$line</small></dd>\n";
$found += $hits;
! }
! }
! }
!
! $html .= ( "</dl>\n<hr noshade>"
! . sprintf (gettext ("%d matches found in %d pages."),
! $found, $count)
! . "\n");
!
! echo GeneratePage('MESSAGE', $html, sprintf(gettext("Full Text Search: %s"), $searchterm));
?>
Index: interwiki.php
===================================================================
RCS file: /cvsroot/phpwiki/phpwiki/lib/interwiki.php,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** interwiki.php 2001/03/03 19:29:48 1.5
--- interwiki.php 2001/09/18 19:16:23 1.6
***************
*** 35,47 ****
$url .= $page;
! if ($linktext)
$linktext = htmlspecialchars($linktext);
! else
! $linktext = Element('span', array('class' => 'interwiki'),
! htmlspecialchars("$wiki:") .
! QElement('span', array('class' => 'wikiword'), $page));
return Element('a', array('href' => $url,
! 'class' => 'interwikilink'),
$linktext);
}
--- 35,50 ----
$url .= $page;
! if ($linktext) {
$linktext = htmlspecialchars($linktext);
! $class = 'named-interwiki';
! }
! else {
! $linktext = ( htmlspecialchars("$wiki:")
! . QElement('span', array('class' => 'wikipage'), $page) );
! $class = 'interwiki';
! }
return Element('a', array('href' => $url,
! 'class' => $class),
$linktext);
}
Index: loadsave.php
===================================================================
RCS file: /cvsroot/phpwiki/phpwiki/lib/loadsave.php,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** loadsave.php 2001/06/26 18:08:32 1.7
--- loadsave.php 2001/09/18 19:16:23 1.8
***************
*** 1,16 ****
<?php
rcs_id('$Id$');
- require "lib/ziplib.php";
-
function StartLoadDump($title, $html = '')
{
// FIXME: This is a hack
echo ereg_replace('</body>.*', '',
! GeneratePage('MESSAGE', $html, $title, 0));
}
function EndLoadDump()
{
// FIXME: This is a hack
echo Element('p', QElement('b', gettext("Complete.")));
echo Element('p', "Return to " . LinkExistingWikiWord($GLOBALS['pagename']));
--- 1,18 ----
<?php
rcs_id('$Id$');
+ require_once("lib/ziplib.php");
+ require_once("lib/Template.php");
function StartLoadDump($title, $html = '')
{
// FIXME: This is a hack
echo ereg_replace('</body>.*', '',
! GeneratePage('MESSAGE', $html, $title, 0));
}
+
function EndLoadDump()
{
// FIXME: This is a hack
+
echo Element('p', QElement('b', gettext("Complete.")));
echo Element('p', "Return to " . LinkExistingWikiWord($GLOBALS['pagename']));
***************
*** 25,47 ****
////////////////////////////////////////////////////////////////
! function MailifyPage ($pagehash, $oldpagehash = false)
{
! global $SERVER_ADMIN, $ArchivePageStore;
!
$from = isset($SERVER_ADMIN) ? $SERVER_ADMIN : 'foo@bar';
$head = "From $from " . ctime(time()) . "\r\n";
! $head .= "Subject: " . rawurlencode($pagehash['pagename']) . "\r\n";
$head .= "From: $from (PhpWiki)\r\n";
! $head .= "Date: " . rfc1123date($pagehash['lastmodified']) . "\r\n";
$head .= sprintf("Mime-Version: 1.0 (Produced by PhpWiki %s)\r\n", PHPWIKI_VERSION);
! if (is_array($oldpagehash))
! {
! return $head . MimeMultipart(array(MimeifyPage($oldpagehash),
! MimeifyPage($pagehash)));
! }
!
! return $head . MimeifyPage($pagehash);
}
--- 27,54 ----
////////////////////////////////////////////////////////////////
! function MailifyPage ($page, $nversions = 1)
{
! global $SERVER_ADMIN;
!
! $current = $page->getCurrentRevision();
$from = isset($SERVER_ADMIN) ? $SERVER_ADMIN : 'foo@bar';
$head = "From $from " . ctime(time()) . "\r\n";
! $head .= "Subject: " . rawurlencode($page->getName()) . "\r\n";
$head .= "From: $from (PhpWiki)\r\n";
! $head .= "Date: " . rfc1123date($current->get('mtime')) . "\r\n";
$head .= sprintf("Mime-Version: 1.0 (Produced by PhpWiki %s)\r\n", PHPWIKI_VERSION);
! $iter = $page->getAllRevisions();
! $parts = array();
! while ($revision = $iter->next()) {
! $parts[] = MimeifyPageRevision($revision);
! if ($nversions > 0 && count($parts) >= $nversions)
! break;
! }
! if (count($parts) > 1)
! return $head . MimeMultipart($parts);
! assert($parts);
! return $head . $parts[0];
}
***************
*** 53,142 ****
* included as well.
*/
! function MakeWikiZip ($dbi, $include_archive = false)
{
! global $WikiPageStore, $ArchivePageStore;
!
! $pages = GetAllWikiPageNames($dbi);
! $zipname = "wiki.zip";
!
! if ($include_archive) {
! $zipname = "wikidb.zip";
! }
!
! $zip = new ZipWriter("Created by PhpWiki", $zipname);
!
! for (reset($pages); $pagename = current($pages); next($pages))
! {
! set_time_limit(30); // Reset watchdog.
! $pagehash = RetrievePage($dbi, $pagename, $WikiPageStore, 0);
!
! if (! is_array($pagehash))
! continue;
!
! if ($include_archive)
! $oldpagehash = RetrievePage($dbi, $pagename, $ArchivePageStore, 0);
! else
! $oldpagehash = false;
!
! $attrib = array('mtime' => $pagehash['lastmodified'],
! 'is_ascii' => 1);
! if (($pagehash['flags'] & FLAG_PAGE_LOCKED) != 0)
! $attrib['write_protected'] = 1;
!
! $content = MailifyPage($pagehash, $oldpagehash);
! $zip->addRegularFile( rawurlencode($pagehash['pagename']),
! $content, $attrib);
! }
! $zip->finish();
! }
! function DumpToDir ($dbi, $directory)
! {
! global $WikiPageStore;
!
! if (empty($directory))
! ExitWiki(gettext("You must specify a directory to dump to"));
!
! // see if we can access the directory the user wants us to use
! if (! file_exists($directory)) {
! if (! mkdir($directory, 0755))
! ExitWiki("Cannot create directory '$directory'<br>\n");
! else
! $html = "Created directory '$directory' for the page dump...<br>\n";
! } else {
! $html = "Using directory '$directory'<br>\n";
! }
!
! StartLoadDump("Dumping Pages", $html);
!
! $pages = GetAllWikiPagenames($dbi);
!
! while (list ($i, $pagename) = each($pages))
! {
! $enc_name = htmlspecialchars($pagename);
! $filename = rawurlencode($pagename);
!
! echo "<br>$enc_name ... ";
! if($pagename != $filename)
! echo "<small>saved as $filename</small> ... ";
!
! $page = RetrievePage($dbi, $pagename, $WikiPageStore, 0);
!
! //$data = serialize($page);
! $data = MailifyPage($page);
! if ( !($fd = fopen("$directory/$filename", "w")) )
! ExitWiki("<b>couldn't open file '$directory/$filename' for writing</b>\n");
! $num = fwrite($fd, $data, strlen($data));
! echo "<small>$num bytes written</small>\n";
! flush();
! assert($num == strlen($data));
! fclose($fd);
! }
! EndLoadDump();
}
--- 60,146 ----
* included as well.
*/
! function MakeWikiZip ($dbi, $request)
{
! if ($request->getArg('include') == 'all') {
! $zipname = "wikidb.zip";
! $include_archive = true;
! }
! else {
! $zipname = "wiki.zip";
! $include_archive = false;
! }
!
!
!
! $zip = new ZipWriter("Created by PhpWiki", $zipname);
!
! $pages = $dbi->getAllPages();
! while ($page = $pages->next()) {
! set_time_limit(30); // Reset watchdog.
!
! $current = $page->getCurrentRevision();
! if ($current->getVersion() == 0)
! continue;
!
!
! $attrib = array('mtime' => $current->get('mtime'),
! 'is_ascii' => 1);
! if ($page->get('locked'))
! $attrib['write_protected'] = 1;
!
! if ($include_archive)
! $content = MailifyPage($page, 0);
! else
! $content = MailifyPage($page);
! $zip->addRegularFile( rawurlencode($page->getName()),
! $content, $attrib);
! }
! $zip->finish();
! }
!
! function DumpToDir ($dbi, $request)
! {
! $directory = $request->getArg('directory');
! if (empty($directory))
! ExitWiki(gettext("You must specify a directory to dump to"));
!
! // see if we can access the directory the user wants us to use
! if (! file_exists($directory)) {
! if (! mkdir($directory, 0755))
! ExitWiki("Cannot create directory '$directory'<br>\n");
! else
! $html = "Created directory '$directory' for the page dump...<br>\n";
! } else {
! $html = "Using directory '$directory'<br>\n";
! }
!
! StartLoadDump("Dumping Pages", $html);
!
! $pages = $dbi->getAllPages();
!
! while ($page = $pages->next()) {
!
! $enc_name = htmlspecialchars($page->getName());
! $filename = rawurlencode($page->getName());
!
! echo "<br>$enc_name ... ";
! if($pagename != $filename)
! echo "<small>saved as $filename</small> ... ";
! $data = MailifyPage($page);
! if ( !($fd = fopen("$directory/$filename", "w")) )
! ExitWiki("<b>couldn't open file '$directory/$filename' for writing</b>\n");
! $num = fwrite($fd, $data, strlen($data));
! echo "<small>$num bytes written</small>\n";
! flush();
! assert($num == strlen($data));
! fclose($fd);
! }
! EndLoadDump();
}
***************
*** 147,228 ****
////////////////////////////////////////////////////////////////
! function SavePage ($dbi, $page, $defaults, $source, $filename)
{
! global $WikiPageStore;
! // Fill in defaults for missing values?
! // Should we do more sanity checks here?
! while (list($key, $val) = each($defaults))
! if (empty($page[$key]))
! $page[$key] = $val;
!
! $pagename = $page['pagename'];
!
! if (empty($pagename))
! {
! echo Element('dd'). Element('dt', QElement('b', "Empty pagename!"));
! return;
! }
!
!
! $mesg = array();
! $version = $page['version'];
! $isnew = true;
!
! if ($version)
! $mesg[] = sprintf(gettext("version %s"), $version);
! if ($source)
! $mesg[] = sprintf(gettext("from %s"), $source);
!
! if (is_array($current = RetrievePage($dbi, $pagename, $WikiPageStore, 0)))
! {
! $isnew = false;
!
! if (arrays_equal($current['content'], $page['content'])
! && $current['author'] == $page['author']
! && $current['flags'] == $page['flags'])
! {
! $mesg[] = sprintf(gettext("is identical to current version %d"),
! $current['version']);
!
! if ( $version <= $current['version'] )
! {
! $mesg[] = gettext("- skipped");
! $page = false;
! }
! }
! else
! {
! SavePageToArchive($pagename, $current);
!
! if ( $version <= $current['version'] )
! $page['version'] = $current['version'] + 1;
! }
! }
! else if ($page['version'] < 1)
! $page['version'] = 1;
!
!
! if ($page)
! {
! ReplaceCurrentPage($pagename, $page);
! UpdateRecentChanges($dbi, $pagename, $isnew);
!
! $mesg[] = gettext("- saved");
! if ($version != $page['version'])
! $mesg[] = sprintf(gettext("as version %d"), $page['version']);
! }
!
! print( Element('dt', LinkExistingWikiWord($pagename))
! . QElement('dd', join(" ", $mesg))
! . "\n" );
! flush();
! }
!
! function ParseSerializedPage($text)
! {
! if (!preg_match('/^a:\d+:{[si]:\d+/', $text))
! return false;
! return unserialize($text);
}
--- 151,265 ----
////////////////////////////////////////////////////////////////
! function SavePage ($dbi, $pageinfo, $source, $filename)
{
! $pagedata = $pageinfo['pagedata']; // Page level meta-data.
! $versiondata = $pageinfo['versiondata']; // Revision level meta-data.
! if (empty($pageinfo['pagename'])) {
! echo Element('dd'). Element('dt', QElement('b', "Empty pagename!"));
! return;
! }
!
! if (empty($versiondata['author_id']))
! $versiondata['author_id'] = $versiondata['author'];
!
! $pagename = $pageinfo['pagename'];
! $content = $pageinfo['content'];
!
! $page = $dbi->getPage($pagename);
!
! foreach ($pagedata as $key => $value) {
! if (!empty($value))
! $page->set($key, $value);
! }
!
! $mesg = array();
! $skip = false;
! if ($source)
! $mesg[] = sprintf(gettext("from %s"), $source);
!
! $current = $page->getCurrentRevision();
! if ($current->getVersion() == 0) {
! $mesg[] = gettext("new page");
! $isnew = true;
! }
! else {
! if ($current->getPackedContent() == $content
! && $current->get('author') == $versiondata['author']) {
! $mesg[] = sprintf(gettext("is identical to current version %d"),
! $current->getVersion());
! $mesg[] = gettext("- skipped");
! $skip = true;
! }
! $isnew = false;
! }
!
! if (! $skip) {
! $new = $page->createRevision(WIKIDB_FORCE_CREATE, $content,
! $versiondata,
! ExtractWikiPageLinks($content));
!
! $mesg[] = gettext("- saved");
! $mesg[] = sprintf(gettext("- saved as version %d"), $new->getVersion());
! }
!
! print( Element('dt', LinkExistingWikiWord($pagename))
! . QElement('dd', join(" ", $mesg))
! . "\n" );
! flush();
! }
!
! function ParseSerializedPage($text, $default_pagename)
! {
! if (!preg_match('/^a:\d+:{[si]:\d+/', $text))
! return false;
!
! $pagehash = unserialize($text);
!
! // Split up pagehash into four parts:
! // pagename
! // content
! // page-level meta-data
! // revision-level meta-data
!
! if (!defined('FLAG_PAGE_LOCKED'))
! define('FLAG_PAGE_LOCKED', 1);
! $pageinfo = array('pagedata' => array(),
! 'versiondata' => array());
!
! $pagedata = &$pageinfo['pagedata'];
! $versiondata = &$pageinfo['versiondata'];
!
! // Fill in defaults.
! if (empty($pagehash['pagename']))
! $pagehash['pagename'] = $default_pagename;
! if (empty($pagehash['author']))
! $pagehash['author'] = $GLOBALS['user']->id();
!
!
! foreach ($pagehash as $key => $value) {
! switch($key) {
! case 'pagename':
! case 'version':
! $pageinfo[$key] = $value;
! break;
! case 'content':
! $pageinfo[$key] = join("\n", $value);
! case 'flags':
! if (($value & FLAG_PAGE_LOCKED) != 0)
! $pagedata['locked'] = 'yes';
! break;
! case 'created':
! $pagedata[$key] = $value;
! break;
! case 'lastmodified':
! $versiondata['mtime'] = $value;
! break;
! case 'author':
! $versiondata[$key] = $value;
! break;
! }
! }
! return $pageinfo;
}
***************
*** 233,275 ****
function LoadFile ($dbi, $filename, $text = false, $mtime = false)
{
! if (!is_string($text))
! {
! // Read the file.
! $stat = stat($filename);
! $mtime = $stat[9];
! $text = implode("", file($filename));
! }
!
! set_time_limit(30); // Reset watchdog.
!
! // FIXME: basename("filewithnoslashes") seems to return garbage sometimes.
! $basename = basename("/dummy/" . $filename);
!
! if (!$mtime)
! $mtime = time(); // Last resort.
!
! $defaults = array('author' => $GLOBALS['user']->id(),
! 'pagename' => rawurldecode($basename),
! 'flags' => 0,
! 'version' => 0,
! 'created' => $mtime,
! 'lastmodified' => $mtime);
!
! if ( ($parts = ParseMimeifiedPages($text)) )
! {
! usort($parts, 'SortByPageVersion');
! for (reset($parts); $page = current($parts); next($parts))
! SavePage($dbi, $page, $defaults, "MIME file $filename", $basename);
! }
! else if ( ($page = ParseSerializedPage($text)) )
! {
! SavePage($dbi, $page, $defaults, "Serialized file $filename", $basename);
! }
! else
! {
! // Assume plain text file.
! $page['content'] = preg_split('/[ \t\r]*\n/', chop($text));
! SavePage($dbi, $page, $defaults, "plain file $filename", $basename);
! }
}
--- 270,312 ----
function LoadFile ($dbi, $filename, $text = false, $mtime = false)
{
! if (!is_string($text)) {
! // Read the file.
! $stat = stat($filename);
! $mtime = $stat[9];
! $text = implode("", file($filename));
! }
!
! set_time_limit(30); // Reset watchdog.
!
! // FIXME: basename("filewithnoslashes") seems to return garbage sometimes.
! $basename = basename("/dummy/" . $filename);
!
! if (!$mtime)
! $mtime = time(); // Last resort.
!
! $defaults = array('author' => $GLOBALS['user']->id(),
! 'pagename' => rawurldecode($basename));
!
! $default_pagename = rawurldecode($basename);
!
! if ( ($parts = ParseMimeifiedPages($text)) ) {
! usort($parts, 'SortByPageVersion');
! foreach ($parts as $pageinfo)
! SavePage($dbi, $pageinfo, "MIME file $filename", $basename);
! }
! else if ( ($pageinfo = ParseSerializedPage($text, $default_pagename)) ) {
! SavePage($dbi, $pageinfo, "Serialized file $filename", $basename);
! }
! else {
! // Assume plain text file.
! $pageinfo = array('pagename' => $default_pagename,
! 'pagedata' => array(),
! 'versiondata'
! => array('author' => $GLOBALS['user']->id()),
! 'content'
! => preg_replace('/[ \t\r]*\n/', "\n", chop($text))
! );
! SavePage($dbi, $pageinfo, "plain file $filename", $basename);
! }
}
***************
*** 284,289 ****
|| ($exclude && in_array($fn, $exclude)) )
{
! print Element('dt', LinkExistingWikiWord($fn)) . QElement('dd', 'Skipping');
! continue;
}
--- 321,326 ----
|| ($exclude && in_array($fn, $exclude)) )
{
! print Element('dt', LinkExistingWikiWord($fn)) . QElement('dd', 'Skipping');
! continue;
}
***************
*** 354,362 ****
}
! function LoadFileOrDir ($dbi, $source)
{
StartLoadDump("Loading '$source'");
echo "<dl>\n";
! LoadAny($dbi, $source, false, array(gettext('RecentChanges')));
echo "</dl>\n";
EndLoadDump();
--- 391,400 ----
}
! function LoadFileOrDir ($dbi, $request)
{
+ $source = $request->getArg('source');
StartLoadDump("Loading '$source'");
echo "<dl>\n";
! LoadAny($dbi, $source/*, false, array(gettext('RecentChanges'))*/);
echo "</dl>\n";
EndLoadDump();
***************
*** 365,413 ****
function SetupWiki ($dbi)
{
! global $GenericPages, $LANG, $user;
! //FIXME: This is a hack
! $user->userid = 'The PhpWiki programming team';
! StartLoadDump('Loading up virgin wiki');
! echo "<dl>\n";
!
! $ignore = array(gettext('RecentChanges'));
! LoadAny($dbi, FindLocalizedFile(WIKI_PGSRC), false, $ignore);
! if ($LANG != "C")
! LoadAny($dbi, FindFile(DEFAULT_WIKI_PGSRC), $GenericPages, $ignore);
! echo "</dl>\n";
! EndLoadDump();
}
! function LoadPostFile ($dbi, $postname)
{
! global $HTTP_POST_FILES;
!
! extract($HTTP_POST_FILES[$postname]);
! fix_magic_quotes_gpc($tmp_name);
! fix_magic_quotes_gpc($name);
! if (!is_uploaded_file($tmp_name))
! ExitWiki('Bad file post'); // Possible malicious attack.
!
! // Dump http headers.
! $fd = fopen($tmp_na...
[truncated message content] |