From 90c7e1146feb1e21280bce0ac307d72c6eccf9b6 Mon Sep 17 00:00:00 2001
From: Garvin Hicking <mail@garv.in>
Date: Tue, 9 Dec 2008 10:41:48 +0000
Subject: [PATCH] Make checksum code skippable

---
 .../serendipity_generateFTPChecksums.php      |  8 ++++++-
 checksums.inc.php                             |  0
 include/admin/upgrader.inc.php                |  2 +-
 include/functions_config.inc.php              |  3 +++
 include/functions_installer.inc.php           | 22 +++++++++++++++----
 include/lang.inc.php                          |  5 +++++
 6 files changed, 34 insertions(+), 6 deletions(-)
 create mode 100644 checksums.inc.php

diff --git a/bundled-libs/serendipity_generateFTPChecksums.php b/bundled-libs/serendipity_generateFTPChecksums.php
index 57cdfe13..ea3f94ff 100644
--- a/bundled-libs/serendipity_generateFTPChecksums.php
+++ b/bundled-libs/serendipity_generateFTPChecksums.php
@@ -9,10 +9,15 @@ if (IN_serendipity !== true) {
     die ("Don't hack!\n");
 }
 
+echo "Creating checksums.\n";
+
 $basedir = realpath(dirname(__FILE__) . '/../') . '/';
 require_once $basedir . 'include/functions_installer.inc.php';
 require_once $basedir . 'include/functions_images.inc.php';
 
+$conf = file_get_contents($basedir . 'serendipity_config.inc.php');
+preg_match('@\$serendipity\[\'version\'\]\s*=\s*\'(.+)\'@imsU', $conf, $vmatch);
+
 // Find all the files in the serendipity directory and calculate their md5 sums
 $sums = array();
 $excludes = array(
@@ -21,6 +26,7 @@ $excludes = array(
     );
 $files = serendipity_traversePath($basedir, '', false);
 foreach ($files as $fdata) {
+    echo $fdata['relpath'] . "\n";
     // Don't take checksums of directories
     if ($fdata['directory']) {
         continue;
@@ -48,7 +54,7 @@ if (!empty($sums)) {
     if (!$file) {
         die('Unable to open output file!');
     }
-    fwrite($file, '<?php' . "\n" . 'global $serendipity;' . "\n" . '$serendipity[\'checksums\'] = array (' . "\n");
+    fwrite($file, '<?php' . "\n" . 'global $serendipity;' . "\n" . '$serendipity[\'checksums_' . $vmatch[1] . '\'] = array (' . "\n");
         foreach ($sums as $fname => $sum) {
             fwrite($file, "'$fname' => '$sum',\n");
         }
diff --git a/checksums.inc.php b/checksums.inc.php
new file mode 100644
index 00000000..e69de29b
diff --git a/include/admin/upgrader.inc.php b/include/admin/upgrader.inc.php
index 30933287..d2e97df5 100644
--- a/include/admin/upgrader.inc.php
+++ b/include/admin/upgrader.inc.php
@@ -276,7 +276,7 @@ if (($showAbort && $serendipity['GET']['action'] == 'ignore') || $serendipity['G
                 echo serendipity_upgraderResultDiagnose(S9Y_U_SUCCESS, CHECKSUMS_PASS);
             } else {
                 foreach ($badsums as $rfile => $sum) {
-                    echo serendipity_upgraderResultDiagnose(S9Y_U_ERROR, sprintf(CHECKSUM_FAILED, $rfile));
+                    echo serendipity_upgraderResultDiagnose(S9Y_U_WARNING, sprintf(CHECKSUM_FAILED, $rfile)) . "<br />\n";
                 }
             }
      ?></td>
diff --git a/include/functions_config.inc.php b/include/functions_config.inc.php
index c8ec467b..410a9abe 100644
--- a/include/functions_config.inc.php
+++ b/include/functions_config.inc.php
@@ -887,6 +887,9 @@ function serendipity_getSessionLanguage() {
         return $serendipity['lang'];
     }
 */
+    if (isset($serendipity['lang']) && !isset($serendipity['languages'][$serendipity['lang']])) {
+        $serendipity['lang'] = $serendipity['autolang'];
+    }
 
     if (isset($_REQUEST['user_language']) && (!empty($serendipity['languages'][$_REQUEST['user_language']])) && !headers_sent()) {
         serendipity_setCookie('serendipityLanguage', $_REQUEST['user_language'], false);
diff --git a/include/functions_installer.inc.php b/include/functions_installer.inc.php
index bb3987f4..3b7cb14e 100644
--- a/include/functions_installer.inc.php
+++ b/include/functions_installer.inc.php
@@ -1273,12 +1273,26 @@ function serendipity_FTPChecksum($filename, $type = null) {
  *    relative path of the file, and values are the bad checksum
  */
 function serendipity_verifyFTPChecksums() {
-    // Load the checksums
-    require_once S9Y_INCLUDE_PATH . 'checksums.inc.php';
-    // Verify that every file in the checksum list was uploaded correctly
+    global $serendipity;
+
     $badsums = array();
+
+    // Load the checksums
+    $f = S9Y_INCLUDE_PATH . 'checksums.inc.php';
+    
+    if (!file_exists($f) || filesize($f) < 1) {
+        return $badsums;
+    }
+
+    require_once $f;
+    // Verify that every file in the checksum list was uploaded correctly
     $basedir = realpath(dirname(__FILE__) . '/../');
-    foreach ($serendipity['checksums'] as $prel => $sum) {
+
+    if (!is_array($serendipity['checksums_' . $serendipity['version']])) {
+        return $badsums;
+    }
+
+    foreach ($serendipity['checksums_' . $serendipity['version']] as $prel => $sum) {
         $path = $basedir . '/' . $prel;
         // Don't take checksums of directories
         if (is_dir($path)) {
diff --git a/include/lang.inc.php b/include/lang.inc.php
index 6f13822e..14ab6b44 100644
--- a/include/lang.inc.php
+++ b/include/lang.inc.php
@@ -6,6 +6,10 @@ if (IN_serendipity !== true) {
     die ("Don't hack!");
 }
 
+if (isset($serendipity['lang']) && !isset($serendipity['languages'][$serendipity['lang']])) {
+    $serendipity['lang'] = $serendipity['autolang'];
+}
+
 if (!defined('serendipity_LANG_LOADED') || serendipity_LANG_LOADED !== true) {
     $charset = serendipity_getCharset();
 
@@ -21,6 +25,7 @@ if (!defined('serendipity_LANG_LOADED') || serendipity_LANG_LOADED !== true) {
     }
 
     // Try and include preferred language from the configurated setting
+
     if (@include(S9Y_INCLUDE_PATH . 'lang/' . $charset . 'serendipity_lang_'. $serendipity['lang'] .'.inc.php') ) {
         // Only here can we truely say the language is loaded
         define('serendipity_LANG_LOADED', true);