From 24f6e2d82047a7f0798795bd395be356d4be7421 Mon Sep 17 00:00:00 2001 From: vargenau Date: Mon, 31 May 2010 12:38:21 +0000 Subject: [PATCH] Let's assume PHP >= 4.2 git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@7449 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/AccessLog.php | 5 +- lib/DbSession.php | 9 ---- lib/IniConfig.php | 6 +-- lib/Request.php | 18 +------ lib/config.php | 73 ++--------------------------- lib/loadsave.php | 24 +++------- lib/plugin/PhpHighlight.php | 9 +--- lib/prepend.php | 2 +- themes/default/templates/login.tmpl | 7 +-- 9 files changed, 16 insertions(+), 137 deletions(-) diff --git a/lib/AccessLog.php b/lib/AccessLog.php index 5250c276d..f5e3ee7b5 100644 --- a/lib/AccessLog.php +++ b/lib/AccessLog.php @@ -357,10 +357,7 @@ class Request_AccessLogEntry //$log_tbl =& $this->_accesslog->logtable; if ($request->get('REQUEST_METHOD') == "POST") { // strangely HTTP_POST_VARS doesn't contain all posted vars. - if (check_php_version(4,2)) - $args = $_POST; // copy not ref. clone not needed on hashes - else - $args = $GLOBALS['HTTP_POST_VARS']; + $args = $_POST; // copy not ref. clone not needed on hashes // garble passwords if (!empty($args['auth']['passwd'])) $args['auth']['passwd'] = ''; if (!empty($args['dbadmin']['passwd'])) $args['dbadmin']['passwd'] = ''; diff --git a/lib/DbSession.php b/lib/DbSession.php index 93a0da51f..4885426e2 100644 --- a/lib/DbSession.php +++ b/lib/DbSession.php @@ -28,15 +28,6 @@ class DbSession // Check for existing DbSession handler $db_type = $dbh->getParam('dbtype'); if (isa($dbh, 'WikiDB')) { - // will fail with php4 and case-sensitive filesystem - //$db_type = substr(get_class($dbh),7); - - // < 4.1.2 crash on dba sessions at session_write_close(). - // (Tested with 4.1.1 and 4.1.2) - // Didn't try postgres sessions. - if (!check_php_version(4,1,2) and $db_type == 'dba') - return false; - @include_once("lib/DbSession/".$db_type.".php"); $class = "DbSession_".$db_type; diff --git a/lib/IniConfig.php b/lib/IniConfig.php index af88b24d1..551ad721b 100644 --- a/lib/IniConfig.php +++ b/lib/IniConfig.php @@ -337,12 +337,8 @@ function IniConfig($file) { // USE_DB_SESSION default logic: if (!defined('USE_DB_SESSION')) { if ($DBParams['db_session_table'] - and in_array($DBParams['dbtype'], array('SQL','ADODB','PDO'))) { + and in_array($DBParams['dbtype'], array('SQL','ADODB','PDO','dba'))) { define('USE_DB_SESSION', true); - } elseif ($DBParams['dbtype'] == 'dba' and check_php_version(4,1,2)) { - define('USE_DB_SESSION', true); // Depends on db handler as well. - // BerkeleyDB on older php has problems - // with multiple db handles. } else { define('USE_DB_SESSION', false); } diff --git a/lib/Request.php b/lib/Request.php index ec0b679c6..ff0d88173 100644 --- a/lib/Request.php +++ b/lib/Request.php @@ -331,8 +331,6 @@ class Request { if (!COMPRESS_OUTPUT) $compress = false; } - elseif (!check_php_version(4,2,3)) - $compress = false; elseif (isCGI()) // necessary? $compress = false; @@ -443,17 +441,6 @@ class Request { } if (!empty($this->_is_buffering_output)) { - /* This cannot work because it might destroy xml markup */ - /* - if (0 and $GLOBALS['SearchHighLightQuery'] and check_php_version(4,2)) { - $html = str_replace($GLOBALS['SearchHighLightQuery'], - ''.$GLOBALS['SearchHighLightQuery'].'', - ob_get_contents()); - ob_clean(); - header(sprintf("Content-Length: %d", strlen($html))); - echo $html; - } else { - */ // if _is_compressing_output then ob_get_length() returns // the uncompressed length, not the gzip'ed as required. if (!headers_sent() and !$this->_is_compressing_output) { @@ -1137,10 +1124,7 @@ class Request_AccessLogEntry //$log_tbl =& $this->_accesslog->logtable; if ($request->get('REQUEST_METHOD') == "POST") { // strangely HTTP_POST_VARS doesn't contain all posted vars. - if (check_php_version(4,2)) - $args = $_POST; // copy not ref. clone not needed on hashes - else - $args = $GLOBALS['HTTP_POST_VARS']; + $args = $_POST; // copy not ref. clone not needed on hashes // garble passwords if (!empty($args['auth']['passwd'])) $args['auth']['passwd'] = ''; if (!empty($args['dbadmin']['passwd'])) $args['dbadmin']['passwd'] = ''; diff --git a/lib/config.php b/lib/config.php index 517c14ba6..1d08021ea 100644 --- a/lib/config.php +++ b/lib/config.php @@ -7,14 +7,8 @@ */ if (!defined("LC_ALL")) { - // Backward compatibility (for PHP < 4.0.5) - if (!check_php_version(4,0,5)) { - define("LC_ALL", "LC_ALL"); - define("LC_CTYPE", "LC_CTYPE"); - } else { - define("LC_ALL", 0); - define("LC_CTYPE", 2); - } + define("LC_ALL", 0); + define("LC_CTYPE", 2); } // debug flags: define ('_DEBUG_VERBOSE', 1); // verbose msgs and add validator links on footer @@ -524,69 +518,8 @@ if (!function_exists('array_diff_assoc')) { } } -/** - * wordwrap() might crash between 4.1.2 and php-4.3.0RC2, fixed in 4.3.0 - * See http://bugs.php.net/bug.php?id=20927 and - * http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2002-1396 - * Improved version of wordwrap2() in the comments at http://www.php.net/wordwrap - */ function safe_wordwrap($str, $width=80, $break="\n", $cut=false) { - if (check_php_version(4,3)) - return wordwrap($str, $width, $break, $cut); - elseif (!check_php_version(4,1,2)) - return wordwrap($str, $width, $break, $cut); - else { - $len = strlen($str); - $tag = 0; $result = ''; $wordlen = 0; - for ($i = 0; $i < $len; $i++) { - $chr = $str[$i]; - // don't break inside xml tags - if ($chr == '<') { - $tag++; - } elseif ($chr == '>') { - $tag--; - } elseif (!$tag) { - if (!function_exists('ctype_space')) { - if (preg_match('/^\s$/', $chr)) - $wordlen = 0; - else - $wordlen++; - } - elseif (ctype_space($chr)) { - $wordlen = 0; - } else { - $wordlen++; - } - } - if ((!$tag) && ($wordlen) && (!($wordlen % $width))) { - $chr .= $break; - } - $result .= $chr; - } - return $result; - /* - if (isset($str) && isset($width)) { - $ex = explode(" ", $str); // wrong: must use preg_split \s+ - $rp = array(); - for ($i=0; $i $width && !is_numeric($ex[$i])) { - $where = 0; - $rp[$i] = ""; - for($b=0; $b < (ceil(strlen($ex[$i]) / $width)); $b++) { - $rp[$i] .= substr($ex[$i], $where, $width).$break; - $where += $width; - } - } else { - $rp[$i] = $ex[$i]; - } - } - return implode(" ",$rp); - } - return $text; - */ - } + return wordwrap($str, $width, $break, $cut); } function getUploadFilePath() { diff --git a/lib/loadsave.php b/lib/loadsave.php index b3177474e..99d9707b8 100644 --- a/lib/loadsave.php +++ b/lib/loadsave.php @@ -225,6 +225,7 @@ function FilenameForPage ($pagename, $action = false) */ function MakeWikiZip (&$request) { + global $ErrorManager; if ($request->getArg('include') == 'all') { $zipname = WIKI_NAME . _("FullDump") . date('Ymd-Hi') . '.zip'; $include_archive = true; @@ -241,10 +242,7 @@ function MakeWikiZip (&$request) $zip = new ZipWriter("Created by PhpWiki " . PHPWIKI_VERSION, $zipname); /* ignore fatals in plugins */ - if (check_php_version(4,1)) { - global $ErrorManager; - $ErrorManager->pushErrorHandler(new WikiFunctionCb('_dump_error_handler')); - } + $ErrorManager->pushErrorHandler(new WikiFunctionCb('_dump_error_handler')); $dbi =& $request->_dbi; $thispage = $request->getArg('pagename'); // for "Return to ..." @@ -293,10 +291,8 @@ function MakeWikiZip (&$request) $content, $attrib); } $zip->finish(); - if (check_php_version(4,1)) { - global $ErrorManager; - $ErrorManager->popErrorHandler(); - } + + $ErrorManager->popErrorHandler(); } function DumpToDir (&$request) @@ -518,7 +514,7 @@ function MakeWikiZipHtml (&$request) */ function _DumpHtmlToDir ($target, $page_iter, $exclude = false) { - global $WikiTheme, $request; + global $WikiTheme, $request, $ErrorManager; $silent = true; $zip = false; $directory = false; if ($WikiTheme->DUMP_MODE == 'HTML') { $directory = $target; @@ -549,10 +545,7 @@ function _DumpHtmlToDir ($target, $page_iter, $exclude = false) $_bodyAttr = @$WikiTheme->_MoreAttr['body']; unset($WikiTheme->_MoreAttr['body']); - if (check_php_version(4,1)) { - global $ErrorManager; - $ErrorManager->pushErrorHandler(new WikiFunctionCb('_dump_error_handler')); - } + $ErrorManager->pushErrorHandler(new WikiFunctionCb('_dump_error_handler')); // check if the dumped file will be accessible from outside $doc_root = $request->get("DOCUMENT_ROOT"); @@ -862,10 +855,7 @@ function _DumpHtmlToDir ($target, $page_iter, $exclude = false) } } - if (check_php_version(4,1)) { - global $ErrorManager; - $ErrorManager->popErrorHandler(); - } + $ErrorManager->popErrorHandler(); $WikiTheme->HTML_DUMP_SUFFIX = ''; $WikiTheme->DUMP_MODE = false; diff --git a/lib/plugin/PhpHighlight.php b/lib/plugin/PhpHighlight.php index b49fc5c0e..55bfbec11 100644 --- a/lib/plugin/PhpHighlight.php +++ b/lib/plugin/PhpHighlight.php @@ -95,14 +95,7 @@ extends WikiPlugin array(''), $source); } - if (!check_php_version(4,2,0)) { - ob_start(); - highlight_string($source); - $str = ob_get_contents(); - ob_end_clean(); - } else { - $str = highlight_string($source, true); - } + $str = highlight_string($source, true); if ($wrap) /* Remove "" again: */ diff --git a/lib/prepend.php b/lib/prepend.php index 2d16eedb6..b10c8d185 100644 --- a/lib/prepend.php +++ b/lib/prepend.php @@ -10,7 +10,7 @@ define('PHPWIKI_VERSION', '1.4.0RC-20100415'); /** * Returns true if current php version is at mimimum a.b.c - * Called: check_php_version(4,1) + * Called: check_php_version(5,2) */ function check_php_version ($a = '0', $b = '0', $c = '0') { static $PHP_VERSION; diff --git a/themes/default/templates/login.tmpl b/themes/default/templates/login.tmpl index 83b6c8894..23faf57cc 100644 --- a/themes/default/templates/login.tmpl +++ b/themes/default/templates/login.tmpl @@ -41,12 +41,7 @@ if (DEBUG & _DEBUG_LOGIN) { if (ALLOW_BOGO_LOGIN && $require_level <= WIKIAUTH_BOGO) { require_once("lib/BlockParser.php"); // This iso-8859-1 sample covers French, Spanish, Italian, German, and probably others - if (check_php_version(4,3)) - $examplechars = htmlentities("ÀñíçéàÖãæôßøü", ENT_QUOTES, $charset); - elseif (check_php_version(4,0,3)) - $examplechars = htmlentities("ÀñíçéàÖãæôßøü", ENT_QUOTES); - else - $examplechars = htmlentities("ÀñíçéàÖãæôßøü"); + $examplechars = htmlentities("ÀñíçéàÖãæôßøü", ENT_QUOTES, $charset); // Japanese login requires utf-8 and ALLOW_NONWIKIWORD_LOGINS if (($charset == 'utf-8') && defined('ALLOW_NONWIKIWORD_LOGINS') && ALLOW_NONWIKIWORD_LOGINS) { //sample Japanese login name in unicode -- 2.45.0