|
From: <var...@us...> - 2021-09-17 13:29:42
|
Revision: 10565
http://sourceforge.net/p/phpwiki/code/10565
Author: vargenau
Date: 2021-09-17 13:29:39 +0000 (Fri, 17 Sep 2021)
Log Message:
-----------
Windows 95 and Mac OS classic are dead, we use "/" as separator
Modified Paths:
--------------
trunk/lib/FileFinder.php
trunk/lib/IniConfig.php
trunk/lib/loadsave.php
trunk/lib/stdlib.php
trunk/lib/upgrade.php
Modified: trunk/lib/FileFinder.php
===================================================================
--- trunk/lib/FileFinder.php 2021-09-17 13:25:45 UTC (rev 10564)
+++ trunk/lib/FileFinder.php 2021-09-17 13:29:39 UTC (rev 10565)
@@ -37,14 +37,13 @@
*/
class FileFinder
{
- public $_pathsep, $_path;
+ public $_path;
/**
- * @param $path array A list of directories in which to search for files.
+ * @param array $path A list of directories in which to search for files.
*/
function __construct($path = array())
{
- $this->_pathsep = $this->_get_syspath_separator();
if (!isset($this->_path) and $path === false)
$path = $this->_get_include_path();
$this->_path = $path;
@@ -53,9 +52,9 @@
/**
* Find file.
*
- * @param $file string File to search for.
+ * @param string $file File to search for.
* @param bool $missing_okay
- * @return string The filename (including path), if found, otherwise false.
+ * @return string|bool The filename (including path), if found, otherwise false.
*/
public function findFile($file, $missing_okay = false)
{
@@ -63,7 +62,7 @@
if (file_exists($file))
return $file;
} elseif (($dir = $this->_search_path($file))) {
- return $dir . $this->_use_path_separator($dir) . $file;
+ return $dir . '/' . $file;
}
return $missing_okay ? false : $this->_not_found($file);
}
@@ -71,42 +70,37 @@
/**
* Unify used pathsep character.
* Accepts array of paths also.
- * This might not work on Windows95 or FAT volumes. (not tested)
*
- * @param string $path
- * @return array|string
+ * @param string|array $path
+ * @return string|array
*/
public function slashifyPath($path)
{
- return $this->forcePathSlashes($path, $this->_pathsep);
+ return $this->forcePathSlashes($path);
}
/**
* Force using '/' as path separator.
*
- * @param string $path
- * @param string $sep
- * @return array|string
+ * @param string|array $path
+ * @return string|array
*/
- public function forcePathSlashes($path, $sep = '/')
+ public function forcePathSlashes($path)
{
if (is_array($path)) {
$result = array();
foreach ($path as $dir) {
- $result[] = $this->forcePathSlashes($dir, $sep);
+ $result[] = $this->forcePathSlashes($dir);
}
return $result;
} else {
- if (isWindows() or $this->_isOtherPathsep()) {
- if (isWindows()) $from = "\\";
- else $from = "\\";
+ if (isWindows()) {
+ $from = "\\";
// PHP is stupid enough to use \\ instead of \
- if (isWindows()) {
- if (substr($path, 0, 2) != '\\\\')
- $path = str_replace('\\\\', '\\', $path);
- else // UNC paths
- $path = '\\\\' . str_replace('\\\\', '\\', substr($path, 2));
- }
+ if (substr($path, 0, 2) != '\\\\')
+ $path = str_replace('\\\\', '\\', $path);
+ else // UNC paths
+ $path = '\\\\' . str_replace('\\\\', '\\', substr($path, 2));
return strtr($path, $from, $sep);
} else
return $path;
@@ -113,54 +107,10 @@
}
}
- private function _isOtherPathsep()
- {
- return $this->_pathsep != '/';
- }
-
/**
- * The system-dependent path-separator character.
- * UNIX,WindowsNT,MacOSX: /
- * Windows95: \
- * Mac: :
- *
- * @return string path_separator.
- */
- public function _get_syspath_separator()
- {
- if (!empty($this->_pathsep)) return $this->_pathsep;
- elseif (isWindowsNT()) return "/"; // we can safely use '/'
- elseif (isWindows()) return "\\"; // FAT might use '\'
- // VMS or LispM is really weird, we ignore it.
- else return '/';
- }
-
- /**
- * The path-separator character of the given path.
- * Windows accepts "/" also, but gets confused with mixed path_separators,
- * e.g "C:\Apache\phpwiki/locale/button"
- * > dir "C:\Apache\phpwiki/locale/button" =>
- * Parameterformat nicht korrekt - "locale"
- * So if there's any '\' in the path, either fix them to '/' (not in Win95 or FAT?)
- * or use '\' for ours.
- *
- * @param string $path
- * @return string path_separator.
- */
- public function _use_path_separator($path)
- {
- if (isWindows95()) {
- if (empty($path)) return "\\";
- else return (strchr($path, "\\")) ? "\\" : '/';
- } else {
- return $this->_get_syspath_separator();
- }
- }
-
- /**
* Determine if path is absolute.
*
- * @param $path string Path.
+ * @param string $path Path.
* @return bool True if path is absolute.
*/
public function _is_abs($path)
@@ -192,7 +142,7 @@
/**
* Report a "file not found" error.
*
- * @param $file string Name of missing file.
+ * @param string $file Name of missing file.
* @return bool false.
*/
private function _not_found($file)
@@ -204,20 +154,13 @@
/**
* Search our path for a file.
*
- * @param $file string File to find.
- * @return string Directory which contains $file, or false.
- * [5x,44ms]
+ * @param string $file string File to find.
+ * @return string|bool Directory which contains $file, or false.
*/
private function _search_path($file)
{
foreach ($this->_path as $dir) {
- // ensure we use the same pathsep
- if ($this->_isOtherPathsep()) {
- $dir = $this->slashifyPath($dir);
- $file = $this->slashifyPath($file);
- if (file_exists($dir . $this->_pathsep . $file))
- return $dir;
- } elseif (@file_exists($dir . $this->_pathsep . $file))
+ if (@file_exists($dir . '/' . $file))
return $dir;
}
return false;
@@ -258,7 +201,7 @@
* The directory is appended only if it is not already listed in
* the include_path.
*
- * @param $dir string Directory to add.
+ * @param string $dir Directory to add.
*/
public function _append_to_include_path($dir)
{
@@ -286,7 +229,7 @@
*
* The directory is prepended, and removed from the tail if already existing.
*
- * @param $dir string Directory to add.
+ * @param string $dir Directory to add.
*/
public function _prepend_to_include_path($dir)
{
@@ -300,10 +243,14 @@
@ini_set('include_path', $GLOBALS['INCLUDE_PATH']);
}
- // Return all the possible shortened locale specifiers for the given locale.
- // Most specific first.
- // de_DE.iso8859-1@euro => de_DE.iso8859-1, de_DE, de
- // This code might needed somewhere else also.
+ /**
+ * Return all the possible shortened locale specifiers for the given locale.
+ * Most specific first.
+ * de_DE.iso8859-1@euro => de_DE.iso8859-1, de_DE, de
+ * This code might needed somewhere else also.
+ *
+ * @param string $lang Locale string
+ */
function locale_versions($lang)
{
// Try less specific versions of the locale
@@ -357,7 +304,6 @@
{
function __construct()
{
- $this->_pathsep = $this->_get_syspath_separator();
$include_path = $this->_get_include_path();
$path = array();
@@ -393,7 +339,6 @@
function __construct()
{
global $WikiTheme;
- $this->_pathsep = $this->_get_syspath_separator();
$include_path = $this->_get_include_path();
$path = array();
@@ -476,9 +421,8 @@
if (defined("PHPWIKI_DIR")) $wikidir = PHPWIKI_DIR;
else $wikidir = preg_replace('/.lib$/', '', dirname(__FILE__));
$wikidir = $finder->_strip_last_pathchar($wikidir);
- $pathsep = $finder->_use_path_separator($wikidir);
+ $pathsep = '/';
return $finder->slashifyPath($wikidir . $pathsep . $file);
- // return PHPWIKI_DIR . "/" . $file;
}
}
@@ -509,24 +453,3 @@
if (isset($win)) return $win;
return (substr(PHP_OS, 0, 3) == 'WIN');
}
-
-function isWindows95()
-{
- static $win95;
- if (isset($win95)) return $win95;
- $win95 = isWindows() and !isWindowsNT();
- return $win95;
-}
-
-function isWindowsNT()
-{
- static $winnt;
- if (isset($winnt)) return $winnt;
- // FIXME: Do this using PHP_OS instead of php_uname().
- // $winnt = (PHP_OS == "WINNT"); // example from https://www.php.net/manual/en/ref.readline.php
- if (function_usable('php_uname'))
- $winnt = preg_match('/^Windows NT/', php_uname());
- else
- $winnt = false; // FIXME: punt.
- return $winnt;
-}
Modified: trunk/lib/IniConfig.php
===================================================================
--- trunk/lib/IniConfig.php 2021-09-17 13:25:45 UTC (rev 10564)
+++ trunk/lib/IniConfig.php 2021-09-17 13:29:39 UTC (rev 10565)
@@ -120,7 +120,6 @@
// Optionally check config/config.php dump for faster startup
$dump = substr($file, 0, -3) . "php";
- if (isWindows()) $dump = str_replace("/", "\\", $dump);
if (file_exists($dump) and is_readable($dump) and filesize($dump) > 0 and sort_file_mtime($dump, $file) < 0) {
@include($dump) or die("Error including " . $dump);
if (function_exists('wiki_configrestore') and (wiki_configrestore() === 'noerr')) {
@@ -862,8 +861,6 @@
// then bindtextdomain() fails, but after chdir to the correct path it will work okay.
// 2. But the weird error "Undefined variable: bindtextdomain" is generated then.
$bindtextdomain_path = findFile("locale", false, true);
- if (isWindows())
- $bindtextdomain_path = str_replace("/", "\\", $bindtextdomain_path);
$bindtextdomain_real = @bindtextdomain("phpwiki", $bindtextdomain_path);
if (realpath($bindtextdomain_real) != realpath($bindtextdomain_path)) {
// this will happen with virtual_paths. chdir and try again.
@@ -876,7 +873,7 @@
if ($LANG != 'en')
textdomain("phpwiki");
if ($chback) { // change back
- chdir($bindtextdomain_real . (isWindows() ? "\\.." : "/.."));
+ chdir($bindtextdomain_real . "/..");
}
}
@@ -1011,8 +1008,6 @@
$SCRIPT_FILENAME = @$_ENV['SCRIPT_FILENAME'];
if (!isset($SCRIPT_FILENAME))
$SCRIPT_FILENAME = dirname(__FILE__ . '/../') . '/index.php';
- if (isWindows())
- $SCRIPT_FILENAME = str_replace('\\\\', '\\', strtr($SCRIPT_FILENAME, '/', '\\'));
define('SCRIPT_FILENAME', $SCRIPT_FILENAME);
// Get remote host name, if Apache hasn't done it for us
Modified: trunk/lib/loadsave.php
===================================================================
--- trunk/lib/loadsave.php 2021-09-17 13:25:45 UTC (rev 10564)
+++ trunk/lib/loadsave.php 2021-09-17 13:29:39 UTC (rev 10565)
@@ -601,8 +601,6 @@
$request_args = $request->args;
$timeout = (!$request->getArg('start_debug')) ? 60 : 240;
if ($directory) {
- if (isWindows())
- $directory = str_replace("\\", "/", $directory); // no Win95 support.
if (!is_dir("$directory/images"))
mkdir("$directory/images");
}
@@ -661,7 +659,7 @@
if ($directory)
mkdir_p($directory . "/" . $dirname);
// Fails with "XX / YY", "XX" is created, "XX / YY" cannot be written
- // if (isWindows()) // interesting Windows bug: cannot mkdir "bla "
+ // interesting Windows bug: cannot mkdir "bla "
// Since dumps needs to be copied, we have to disallow this for all platforms.
$filename = preg_replace("/ \//", "/", $filename);
$relative_base = "../";
@@ -1565,10 +1563,10 @@
$epage = urlencode($page);
if (!$dbi->isWikiPage($page)) {
// translated version provided?
- if ($lf = findLocalizedFile($pgsrc . $finder->_pathsep . $epage, 1)) {
+ if ($lf = findLocalizedFile($pgsrc . '/' . $epage, 1)) {
LoadAny($request, $lf);
} else { // load english version of required action page
- LoadAny($request, findFile(DEFAULT_WIKI_PGSRC . $finder->_pathsep . urlencode($f)));
+ LoadAny($request, findFile(DEFAULT_WIKI_PGSRC . '/' . urlencode($f)));
$page = $f;
}
}
Modified: trunk/lib/stdlib.php
===================================================================
--- trunk/lib/stdlib.php 2021-09-17 13:25:45 UTC (rev 10564)
+++ trunk/lib/stdlib.php 2021-09-17 13:29:39 UTC (rev 10565)
@@ -1385,7 +1385,6 @@
$this->_pcre_pattern = glob_to_pcre($this->_pattern);
}
$this->_case = !isWindows();
- $this->_pathsep = '/';
if (empty($directory) or !file_exists($directory) or !is_dir($directory)) {
return; // early return
@@ -1397,7 +1396,7 @@
}
while ($filename = readdir($dir_handle)) {
- if ($filename[0] == '.' || filetype($dir . $this->_pathsep . $filename) != 'file')
+ if ($filename[0] == '.' || filetype($dir . '/' . $filename) != 'file')
continue;
if ($this->_filenameSelector($filename)) {
array_push($this->_fileList, "$filename");
Modified: trunk/lib/upgrade.php
===================================================================
--- trunk/lib/upgrade.php 2021-09-17 13:25:45 UTC (rev 10564)
+++ trunk/lib/upgrade.php 2021-09-17 13:29:39 UTC (rev 10565)
@@ -237,14 +237,11 @@
if (is_writable($filename)) {
$in = fopen($filename, "rb");
$out = fopen($tmp = tempnam(getUploadFilePath(), "cfg"), "wb");
- if (isWindows())
- $tmp = str_replace("/", "\\", $tmp);
// Detect the existing linesep at first line. fgets strips it even if 'rb'.
// Before we simply assumed \r\n on Windows local files.
$s = fread($in, 1024);
rewind($in);
$linesep = (substr_count($s, "\r\n") > substr_count($s, "\n")) ? "\r\n" : "\n";
- //$linesep = isWindows() ? "\r\n" : "\n";
while ($s = fgets($in)) {
// =>php-5.0.1 can fill count
//$new = preg_replace($match, $replace, $s, -1, $count);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|