From aeb02e7b8ae530624153bbe8c4a6c70df6d7f152 Mon Sep 17 00:00:00 2001 From: "Committo,Ergo:sum" <esj@rezo.net> Date: Fri, 19 Jan 2007 10:54:46 +0000 Subject: [PATCH] =?UTF-8?q?Pas=20mal=20de=20scories=20dans=20l'=C3=A9ditio?= =?UTF-8?q?n=20de=20mot:=20mauvais=20retour=20en=20cas=20de=20cr=C3=A9atio?= =?UTF-8?q?n=20hormis=20=C3=A0=20partir=20d'un=20article;=20page=20blanche?= =?UTF-8?q?=20sur=20id=5Fmot=20inaccessible;=20tache=20#605=20inachev?= =?UTF-8?q?=C3=A9e=20(pathologique=20il=20est=20vrai);=20renforcement=20de?= =?UTF-8?q?=20s=C3=A9curit=C3=A9=20(en=20cas=20d'admin=20g=C3=A9n=C3=A9ral?= =?UTF-8?q?=20suicidaire,=20mais=20si=20les=20droits=20changent=20un=20jou?= =?UTF-8?q?r=20on=20aura=20oubli=C3=A9=20=C3=A7a).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ecrire/action/instituer_groupe_mots.php | 16 ++++- ecrire/action/instituer_mot.php | 18 ++--- ecrire/exec/mots_edit.php | 93 +++++++++++++------------ 3 files changed, 72 insertions(+), 55 deletions(-) diff --git a/ecrire/action/instituer_groupe_mots.php b/ecrire/action/instituer_groupe_mots.php index 1f225388d3..206d4116cf 100644 --- a/ecrire/action/instituer_groupe_mots.php +++ b/ecrire/action/instituer_groupe_mots.php @@ -21,7 +21,9 @@ function action_instituer_groupe_mots_dist() $securiser_action = charger_fonction('securiser_action', 'inc'); $arg = $securiser_action(); - if (!preg_match(",^(-?\d+)$,", $arg, $r)) { + if (preg_match(",^(\w+)$,", $arg, $r)) + action_instituer_groupe_mots_get($arg); + elseif (!preg_match(",^(-?\d+)$,", $arg, $r)) { spip_log("action_instituer_groupe_mots_dist $arg pas compris"); } else action_instituer_groupe_mots_post($r); } @@ -51,4 +53,16 @@ function action_instituer_groupe_mots_post($r) } } } + + +function action_instituer_groupe_mots_get($table) +{ + $titre = _T('info_mot_sans_groupe'); + + $id_groupe = spip_abstract_insert("spip_groupes_mots", "(titre, unseul, obligatoire, articles, breves, rubriques, syndic, minirezo, comite, forum)", "(" . _q($titre) . ", 'non', 'non', '" . (($table=='articles') ? 'oui' : 'non') ."', '" . (($table=='breves') ? 'oui' : 'non') ."','" . (($table=='rubriques') ? 'oui' : 'non') ."','" . (($table=='syndic') ? 'oui' : 'non') ."', 'oui', 'non', 'non'" . ")"); + + redirige_par_entete(parametre_url(urldecode(_request('redirect')), + 'id_groupe', $id_groupe, '&')); +} + ?> diff --git a/ecrire/action/instituer_mot.php b/ecrire/action/instituer_mot.php index 3631826b9d..a74d39c2da 100644 --- a/ecrire/action/instituer_mot.php +++ b/ecrire/action/instituer_mot.php @@ -21,8 +21,8 @@ function action_instituer_mot_dist() { $securiser_action = charger_fonction('securiser_action', 'inc'); $arg = $securiser_action(); - if (!preg_match(",^(\d+)$,", $arg, $r)) { - spip_log("action_instituer_mot_dist $arg pas compris"); + if (!preg_match(",^(\d+)(\W(\d+)\W(\w+)\W(\w+))?$,", $arg, $r)) { + spip_log("action_instituer_mot_dist '$arg' pas compris"); } else action_instituer_mot_post($r); } @@ -30,24 +30,24 @@ function action_instituer_mot_dist() function action_instituer_mot_post($r) { $id_mot = $r[1]; - global $new, $table, $table_id, $ajouter_id_article; - $id_groupe = intval(_request('id_groupe')); - if ($new == 'oui') { + if (!$id_mot AND $id_groupe) { $id_mot = spip_abstract_insert("spip_mots", '(id_groupe)', "($id_groupe)"); - if ($ajouter_id_article = intval($ajouter_id_article)) - // heureusement que c'est pour les admin complet, - // sinon bonjour le XSS + if ($r[2]) { + list(,,,$ajouter_id_article, $table, $table_id) = $r; ajouter_nouveau_mot($id_groupe, $table, $table_id, $id_mot, $ajouter_id_article); - + } } // modifier le contenu via l'API include_spip('inc/modifier'); revision_mot($id_mot); + if ($redirect = _request('redirect')) + redirige_par_entete(parametre_url(urldecode($redirect), + 'id_mot', $id_mot, '&')); } diff --git a/ecrire/exec/mots_edit.php b/ecrire/exec/mots_edit.php index 8760b58a30..ce91d02c48 100644 --- a/ecrire/exec/mots_edit.php +++ b/ecrire/exec/mots_edit.php @@ -38,12 +38,14 @@ global $id_groupe = intval($id_groupe); $id_mot = intval($id_mot); - + // Secu un peu superfetatoire car seuls les admin generaux les verront; + // mais si un jour on relache les droits, vaut mieux blinder. + $table = preg_replace('/\W/','',$table); + $table_id = preg_replace('/\W/','',$table_id); + $ajouter_id_article = intval($ajouter_id_article); // // Recupere les donnees // - $out = ""; - $row = spip_fetch_array(spip_query("SELECT * FROM spip_mots WHERE id_mot=$id_mot")); if ($row) { $id_mot = $row['id_mot']; @@ -52,14 +54,38 @@ global $texte = $row['texte']; $extra = $row['extra']; $id_groupe = $row['id_groupe']; - } else $id_mot = 0; - + $onfocus =''; + } else { + if (!$new OR !acces_mots()) { + echo minipres(_T('info_mot_sans_groupe')); + exit; + } + $id_mot = 0; + + if (!$titre_mot = $titre) { + $titre_mot = filtrer_entites(_T('texte_nouveau_mot')); + $onfocus = " onfocus=\"if(!antifocus){this.value='';antifocus=true;}\""; + } + $res = spip_num_rows(spip_query("SELECT id_groupe FROM spip_groupes_mots ". ($table ? "WHERE $table='oui'" : '') . " LIMIT 1")); + + if (!$res) { + // cas pathologique: + // creation d'un mot sans groupe de mots cree auparavant + // (ne devrait arriver qu'en cas d'appel explicite ou + // destruction concomittante des groupes de mots idoines) + if ($redirect) + $redirect = '&redirect=' . $redirect; + if ($titre) + $titre = "&titre=".rawurlencode($titre); + include_spip('inc/headers'); + redirige_par_entete(redirige_action_auteur('instituer_groupe_mots', $table, 'mots_edit', "new=$new&table=$table&table_id=$table_id&ajouter_id_article=$ajouter_id_article$titre$redirect", true)); + } + } + pipeline('exec_init',array('args'=>array('exec'=>'mots_edit','id_mot'=>$id_mot),'data'=>'')); $commencer_page = charger_fonction('commencer_page', 'inc'); - $out .= $commencer_page("« $titre_mot »", "naviguer", "mots"); - - $out .= debut_gauche('',true); + $out = $commencer_page("« $titre_mot »", "naviguer", "mots") . debut_gauche('',true); ////////////////////////////////////////////////////// @@ -67,37 +93,24 @@ global // if ($id_mot) { - $res = "\n<div style='font-weight: bold; text-align: center' class='verdana1 spip_xx-small'>" + + $out .= debut_boite_info(true); + $out .= "\n<div style='font-weight: bold; text-align: center' class='verdana1 spip_xx-small'>" . _T('titre_gauche_mots_edit') . "<br /><span class='spip_xx-large'>" . $id_mot . '</span></div>'; - - $out .= debut_boite_info(true); - $out .= $res; $out .= voir_en_ligne ('mot', $id_mot, false, 'racine-24.gif', false); $out .= fin_boite_info(true); - $onfocus =''; - } elseif (!$new OR !acces_mots()) { - $out .= _T('info_mot_sans_groupe'); - exit; - } else { - if (!$titre_mot = $titre) { - $titre_mot = filtrer_entites(_T('texte_nouveau_mot')); - $onfocus = " onfocus=\"if(!antifocus){this.value='';antifocus=true;}\""; + // Logos du mot-clef + + if (acces_mots() AND ($spip_display != 4)) { + $iconifier = charger_fonction('iconifier', 'inc'); + $out .= $iconifier('id_mot', $id_mot, 'mots_edit'); } } -////////////////////////////////////////////////////// -// Logos du mot-clef -// - - if ($id_mot > 0 AND acces_mots() AND ($spip_display != 4)) { - $iconifier = charger_fonction('iconifier', 'inc'); - $out .= $iconifier('id_mot', $id_mot, 'mots_edit'); - } - // // Afficher les boutons de creation // @@ -129,7 +142,6 @@ global $out .= "<td style='width: 100%' valign='top'>"; $out .= gros_titre($titre_mot,'',false); - if ($descriptif) { $out .= "<div style='border: 1px dashed #aaaaaa; ' class='verdana1 spip_small'>"; $out .= "<b>" . _T('info_descriptif') . "</b> "; @@ -182,12 +194,6 @@ global $res = "<div class='serif'>"; - if ($new=='oui') - $res .= "<input type='hidden' name='new' value='oui' />\n"; - $res .= "<input type='hidden' name='table' value='$table' />\n"; - $res .= "<input type='hidden' name='table_id' value='$table_id' />\n"; - $res .= "<input type='hidden' name='ajouter_id_article' value=\"$ajouter_id_article\" />\n"; - $titre_mot = entites_html($titre_mot); $descriptif = entites_html($descriptif); $texte = entites_html($texte); @@ -232,7 +238,9 @@ global $redirect = generer_url_ecrire('mots_edit','id_mot='.$id_mot, '&',true); else $redirect = rawurldecode($redirect); - $out .= generer_action_auteur("instituer_mot", $id_mot, _DIR_RESTREINT_ABS . $redirect, $res); + $arg = "$id_mot,$ajouter_id_article,$table,$table_id"; + + $out .= generer_action_auteur("instituer_mot", $arg, _DIR_RESTREINT_ABS . $redirect, $res); $out .= fin_cadre_formulaire(true); } @@ -256,15 +264,10 @@ function determine_groupe_mots($table, $id_groupe) { } $res .= "</select>"; } else { + // pas de menu si un seul groupe + // (et on est sur qu'il y en a un grace au redirect preventif) $row = spip_fetch_array($q); - if (!$row) { - // il faut creer un groupe de mots - // (cas d'un mot cree depuis le script articles) - - $titre = _T('info_mot_sans_groupe'); - $row['id_groupe'] = spip_abstract_insert("spip_groupes_mots", "(titre, unseul, obligatoire, articles, breves, rubriques, syndic, minirezo, comite, forum)", "(" . _q($titre) . ", 'non', 'non', '" . (($table=='articles') ? 'oui' : 'non') ."', '" . (($table=='breves') ? 'oui' : 'non') ."','" . (($table=='rubriques') ? 'oui' : 'non') ."','" . (($table=='syndic') ? 'oui' : 'non') ."', 'oui', 'non', 'non'" . ")"); - } else $titre = $row['titre']; - $res = $titre + $res = $row['titre'] . "<br /><input type='hidden' name='id_groupe' value='".$row['id_groupe']."' />"; } -- GitLab