From 76a077da0f4edd706da6eb0ac1d1296d453e975c Mon Sep 17 00:00:00 2001
From: "Committo,Ergo:sum" <esj@rezo.net>
Date: Sat, 25 Nov 2006 06:39:06 +0000
Subject: [PATCH] Neutraliser les demandes Ajax pendant une restauration. Et 2
 scories XML.

---
 ecrire/inc/actions.php      | 10 +++++-----
 ecrire/inc/gadgets.php      |  8 ++++++--
 ecrire/inc/presentation.php |  2 +-
 ecrire/inc/selectionner.php |  2 +-
 ecrire/index.php            |  8 ++++++--
 5 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/ecrire/inc/actions.php b/ecrire/inc/actions.php
index 2f789e1eb3..f989584d04 100644
--- a/ecrire/inc/actions.php
+++ b/ecrire/inc/actions.php
@@ -135,25 +135,25 @@ function ajax_retour($corps)
 	header('Content-Type: text/html; charset='. $c);
 	$c = '<' . "?xml version='1.0' encoding='" . $c . "'?" . ">\n";
 	if (isset($GLOBALS['ajax_debug']))
-	  ajax_debug_retour($corps, $c);
+		ajax_debug_retour($corps, $c);
 	echo $c, $corps;
 	exit;
 }
 
 // http://doc.spip.org/@ajax_debug_retour
-function ajax_debug_retour($c, $corps)
+function ajax_debug_retour($corps, $c)
 {
 	$sax = charger_fonction('sax', 'inc');
 	$corps = $sax($corps);
 	if ($GLOBALS['xhtml_error']) {
-	  spip_log("ajax_retour " .  $GLOBALS['xhtml_error']);
+	  spip_log("ajax_retour " .  $GLOBALS['REQUEST_URI'] . $GLOBALS['xhtml_error']);
 	  $debut = "<script type='text/javascript'>console.log('";
 	  $fin = "')</script>\n";
-	  $corps = $GLOBALS['xhtml_error']
+	  echo $GLOBALS['xhtml_error']
 	  . $debut
 	  . join("$fin$debut", split("\n", addslashes($corps)))
 	  . $fin;
-	  $c ='';
+	  exit;
 	}
 }
 
diff --git a/ecrire/inc/gadgets.php b/ecrire/inc/gadgets.php
index 43309006af..7d0b6caaeb 100644
--- a/ecrire/inc/gadgets.php
+++ b/ecrire/inc/gadgets.php
@@ -482,12 +482,16 @@ function repercuter_gadgets($id_rubrique) {
 
 	if (!_SPIP_AJAX) return '';
 
-	$rub = $id_rubrique ? "\\x26id_rubrique=$id_rubrique" : '';
+	// ne sert ici qu'a caracteriser l'asyncrhonisme de ces scripts,
+	// afin de les neutraliser lors d'une restauration
+	$ajax = "\\x26var_ajaxcharset=utf8" ;
+
+	$rub = $ajax . ($id_rubrique ? "\\x26id_rubrique=$id_rubrique" : '');
 
 	return
 	 "
 	$('#gadget-rubriques')
-	.load('./?exec=gadgets\\x26gadget=rubriques');" #pas de $rub
+	.load('./?exec=gadgets\\x26gadget=rubriques$ajax');" #pas de $rub
 	."
 	$('#gadget-navigation')
 	.load('./?exec=gadgets\\x26gadget=navigation$rub');"
diff --git a/ecrire/inc/presentation.php b/ecrire/inc/presentation.php
index f48f20e1ff..c03191635f 100644
--- a/ecrire/inc/presentation.php
+++ b/ecrire/inc/presentation.php
@@ -1324,7 +1324,7 @@ function debut_javascript($admin, $stat)
 	// on installe egalement un <noscript></noscript> qui charge une image qui
 	// pose un cookie valant -1
 
-	$testeur = generer_url_ecrire('test_ajax', 'js=1');
+	$testeur = generer_url_ecrire('test_ajax', 'var_ajaxcharset=utf-8&js=1');
 
 	if (_SPIP_AJAX) {
 	  // pour le pied de page
diff --git a/ecrire/inc/selectionner.php b/ecrire/inc/selectionner.php
index 72c64a271e..e79647ef0d 100644
--- a/ecrire/inc/selectionner.php
+++ b/ecrire/inc/selectionner.php
@@ -71,7 +71,7 @@ function construire_selectionner_hierarchie($idom, $liste, $racine, $url, $name,
 
 	return "<div id='$idom'>"
 	. "<a id='$idom6' style='visibility: hidden;'"
-	. ($url_init ?  "href='$url_init'" : '')
+	. ($url_init ?  " href='$url_init'" : '')
 	. "></a>"
 	. "<table width='100%' cellpadding='0' cellspacing='0'><tr>"
 	. "<td style='vertical-align: bottom;'>\n"
diff --git a/ecrire/index.php b/ecrire/index.php
index 38194f4dd0..eb0314d5af 100644
--- a/ecrire/index.php
+++ b/ecrire/index.php
@@ -173,10 +173,14 @@ AND (!isset($var_ajaxcharset))
 AND ($GLOBALS['spip_version'] <> ((double) str_replace(',','.',$GLOBALS['meta']['version_installee']))))
 	$exec = 'demande_mise_a_jour';
 
-// Controle d'interruption d'une longue restauration
+// Si interruption d'une longue restauration
+// detourner le script demande pour qu'il reprenne le boulot
+// mais virer les Ajax pour eviter plusieurs restaurations en parallele
 elseif ($_COOKIE['spip_admin']
-AND isset($GLOBALS['meta']["debut_restauration"]))
+AND isset($GLOBALS['meta']["debut_restauration"])) {
+	if (isset($var_ajaxcharset)) exit;
 	$exec = 'import_all';
+}
 
 // Verification des plugins
 // (ne pas interrompre une restauration ou un upgrade)
-- 
GitLab