diff --git a/.gitattributes b/.gitattributes
index f15146fea27baee172023b26bbfea9379f5897a8..1ae4290d61d48a0997f4a9e4cd1f94a8f049acc6 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -479,6 +479,7 @@ ecrire/exec/statistiques_visites.php -text
 ecrire/exec/synchro.php -text
 ecrire/exec/tourner.php -text
 ecrire/exec/upgrade.php -text
+ecrire/exec/valider_xml.php -text
 ecrire/exec/virtualiser.php -text
 ecrire/inc/actions.php -text
 ecrire/inc/agenda.php -text
diff --git a/ecrire/exec/valider_xml.php b/ecrire/exec/valider_xml.php
new file mode 100644
index 0000000000000000000000000000000000000000..60371b0b8a584272a0dca230344dfcb8ec573a8d
--- /dev/null
+++ b/ecrire/exec/valider_xml.php
@@ -0,0 +1,71 @@
+<?php
+
+/***************************************************************************\
+ *  SPIP, Systeme de publication pour l'internet                           *
+ *                                                                         *
+ *  Copyright (c) 2001-2007                                                *
+ *  Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James  *
+ *                                                                         *
+ *  Ce programme est un logiciel libre distribue sous licence GNU/GPL.     *
+ *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
+\***************************************************************************/
+
+if (!defined("_ECRIRE_INC_VERSION")) return;
+include_spip('inc/presentation');
+
+// http://doc.spip.org/@exec_recherche_dist
+function exec_valider_xml_dist()
+{
+	if ($GLOBALS['connect_statut'] != '0minirezo') {
+		echo minipres();
+		exit;
+	}
+
+	$url = urldecode(_request('var_url'));
+
+	if (!$url) {
+	  $url_aff = 'http://';
+	  $onfocus = "this.value='';";
+	  $texte = $err = '';
+
+	} else {
+
+	  list($server, $script) = preg_split('/[?]/', $url);
+	  if ((!$server) OR ($server == './') 
+	      OR strpos($server, url_de_base()) === 0) {
+	    	    include_spip('inc/headers');
+	    	    redirige_par_entete(parametre_url($url,'transformer_xml','valider_xml', '&'));
+	  }
+
+	  include_spip('public/debug');
+	  include_spip('inc/distant');
+	  $url_aff = entites_html($url);
+	  $onfocus = "this.value='" . addslashes($url) . "';";
+
+	  $transformer_xml = charger_fonction('valider_xml', 'inc');
+
+	  if (preg_match(',^[a-z][0-9a-z_]*$,i', $url))
+		$texte = $transformer_xml(charger_fonction($url, 'exec'), true);
+	  else 	$texte = $transformer_xml(recuperer_page($url));
+
+	  if (isset($GLOBALS['xhtml_error'])) 
+	  	list($texte, $err) = emboite_texte($texte);
+	  else {
+	    $err = '<h3>' . _T('spip_conforme_dtd') . '</h3>';
+	    list($texte, ) = emboite_texte($texte);
+	  }
+	}
+	$titre = _T('analyse_xml');
+	$commencer_page = charger_fonction('commencer_page', 'inc');
+	echo $commencer_page($titre);
+
+	echo "<div style='margin: 10px; text-align: center'>", "<h1>", $titre, '</h1>';
+	echo "<form style='margin: 0px;' action='", generer_url_ecrire('valider_xml') . "'>";
+	echo "<div><input type='hidden' name='exec' value='valider_xml' />";
+	echo '<input type="text" size="70" value="',$url_aff,'" name="var_url" onfocus="'.$onfocus . '" />';
+	echo "</div></form>";
+
+	echo  $err, "</div>";
+	echo "<div style='margin: 10px; text-align: left'>",$texte, '</div>', fin_page();
+}
+?>
diff --git a/ecrire/index.php b/ecrire/index.php
index b39da2d028cb82f1c637c117adc3f1b7d41246b3..6347f818301cfd38d22c7a86ac579eae15e39acc 100644
--- a/ecrire/index.php
+++ b/ecrire/index.php
@@ -192,12 +192,19 @@ AND $l = @unserialize($l)) {
 	}
 }
 
-// Trouver la fonction eventuellement surchagee et l'appeler.
-$var_f = charger_fonction($exec);
-if (!isset($GLOBALS['transformer_xml'])
-OR $GLOBALS['auteur_session']['statut']!='0minirezo')
-	$var_f();
- else { include('public/debug.php');
-   debug_script($var_f, true);
+// Passer la main aux outils XML a la demande.
+if (isset($GLOBALS['transformer_xml'])
+AND $GLOBALS['auteur_session']['statut']=='0minirezo') {
+	set_request('var_url', $exec);
+	$exec = $GLOBALS['transformer_xml'];
  }
+
+// Trouver la fonction eventuellement surchagee
+
+$var_f = charger_fonction($exec);
+
+// Feu !
+
+$var_f();
+
 ?>
diff --git a/ecrire/public/debug.php b/ecrire/public/debug.php
index 4a816a540207541473a5da7feb14e16e99d5a74a..6c155fa55d20f1b39791bdd9e9a48077ba114b17 100644
--- a/ecrire/public/debug.php
+++ b/ecrire/public/debug.php
@@ -42,10 +42,12 @@ function afficher_debug_contexte($env) {
 
 // Si le code php produit des erreurs, on les affiche en surimpression
 // sauf pour un visiteur non admin (lui ne voit rien de special)
+// et en mode validation (fausse erreur "double occurrence insert_head")
 // ajouter &var_mode=debug pour voir les erreurs et en parler sur spip@rezo.net
 // http://doc.spip.org/@affiche_erreurs_page
 function affiche_erreurs_page($tableau_des_erreurs) {
 
+	if ($GLOBALS['exec']=='valider_xml') return '';
 	$GLOBALS['bouton_admin_debug'] = true;
 	$res = '';
 	foreach ($tableau_des_erreurs as $err) {
@@ -308,6 +310,7 @@ function ancre_texte($texte, $fautifs=array())
 	global $var_mode_ligne;
 	if ($var_mode_ligne) $fautifs[]= array($var_mode_ligne);
 	$res ='';
+
 	$s = highlight_string(str_replace('</script>','</@@@@@>',$texte),true);
 
 	$s = str_replace('/@@@@@','/script', // bug de highlight_string
@@ -318,6 +321,7 @@ function ancre_texte($texte, $fautifs=array())
 	$s = preg_replace(',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,',
 			  '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>',
 			  $s);
+
 	$tableau = explode("<br />", $s);
 
 	$ancre = md5($texte);
@@ -377,7 +381,7 @@ function debug_dumpfile ($texte, $fonc, $type) {
 	$self = str_replace("\\'", '&#39;', self());
 	$self = parametre_url($self,'var_mode', 'debug');
 
-	debug_debut($fonc);
+	echo debug_debut($fonc);
 	if ($var_mode_affiche !== 'validation') {
 		$self = parametre_url($self,'var_mode', 'debug');
 	  foreach ($debug_objets['sourcefile'] as $nom_skel => $sourcefile) {
@@ -480,39 +484,6 @@ function debug_dumpfile ($texte, $fonc, $type) {
 	exit;
 }
 
-// Fonction pour l'espace de redaction, appeler par ecrire/index.php
-
-// http://doc.spip.org/@debug_script
-function debug_script ($f, $apply=false) {
-
-	$transformer_xml=charger_fonction($GLOBALS['transformer_xml'], 'inc');
-	$t = $transformer_xml($f, $apply);
-
-	debug_debut($GLOBALS['exec']);
-	if (!isset($GLOBALS['xhtml_error'])) {
-		list (,$top, $avail, $grammaire, $rotlvl) = analyser_doctype($t);
-		$err = '<h3>' . _T('spip_conforme_dtd')
-		. "<br /><a href='" 
-		. $grammaire
-		. "'>"
-		. $rotlvl
-		. '</a></h3>';
-		list($t, ) = emboite_texte($t);
-	} else {
-		list($t, $err) = emboite_texte($t);
-	}
-
-	echo "<div style='text-align: center'><h1>", _T('analyse_xml') . '</h1>',
-	  $err,
-	   "<br /><a href='"
-	    . parametre_url(self(),'transformer_xml', '')
-	    . "'>"
-	    .  _T("access_interface_graphique")
-	    . "</a></div>";
-	echo $t;
-	echo "\n</div></div></body></html>";
-}
-
 // http://doc.spip.org/@debug_debut
 function debug_debut($titre)
 {
@@ -521,19 +492,19 @@ function debug_debut($titre)
 	include_spip('inc/filtres');
 	http_no_cache();
 	lang_select($auteur_session['lang']);
-	echo _DOCTYPE_ECRIRE,
-	  html_lang_attributes(),
-	  "<head>\n<title>",
+	return _DOCTYPE_ECRIRE .
+	  html_lang_attributes() .
+	  "<head>\n<title>" .
 	  ('Spip ' . $GLOBALS['spip_version_affichee'] . ' ' .
 	   _T('admin_debug') . ' ' . $titre . ' (' .
-	   supprimer_tags(extraire_multi($GLOBALS['meta']['nom_site']))), 
-	  ")</title>\n",
-	  "<meta http-equiv='Content-Type' content='text/html",
-	  (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : ''),
-	  "' />\n",
+	   supprimer_tags(extraire_multi($GLOBALS['meta']['nom_site']))) . 
+	  ")</title>\n" .
+	  "<meta http-equiv='Content-Type' content='text/html" .
+	  (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') .
+	  "' />\n" .
 	  "<link rel='stylesheet' href='".url_absolue(find_in_path('spip_admin.css'))
-	  . "' type='text/css' />",
-	  "</head>\n<body style='margin:0 10px;'>",
+	  . "' type='text/css' />" .
+	  "</head>\n<body style='margin:0 10px;'>" .
 	  "\n<div id='spip-debug' style='position: absolute; top: 22px; z-index: 1000;height:97%;left:10px;right:10px;'><div id='spip-boucles'>\n"; 
 }
 
@@ -559,6 +530,7 @@ function emboite_texte($texte, $fonc='',$self='')
 	elseif (!ereg("^[[:space:]]*([^<][^0-9]*)([0-9]*)(.*[^0-9])([0-9]*)$",
                      $GLOBALS['xhtml_error'],
                      $eregs))
+
 		return array(ancre_texte($texte, array('', '')), true);
 	if (!isset($GLOBALS['debug_objets'])) {
 		preg_match_all(",(.*?)(\d+)(\D+(\d+)<br />),",
@@ -588,6 +560,7 @@ function emboite_texte($texte, $fonc='',$self='')
 		}			
 		$encore2 = array();
 		$colors = array('#e0e0f0', '#f8f8ff');
+
 		foreach($regs as $r) {
 			$i++;
 			list(,$msg, $ligne, $fin, $col) = $r;