Projet:Bot/Codes/AWB
Informations générales sur AWB. |
Discussion sur AWB et questions sur son fonctionnement. |
Demande pour être autorisé à utiliser AWB. |
Corrections d'orthographe et de typographie gérées par AWB. |
Requête à faire exécuter par AWB ou un autre robot. |
Pages d'aide à l'utilisation d'AWB. |
| |||||
Pour ajouter un nouveau code, utilisez {{subst:Projet:Bot/Codes/E|auteur=|titre=|date=|langage=}}, puis complétez les informations manquantes.
Correction de liens internes
| auteur : Chico (d · c · b) | Création : 21 avril 2007 | Dernière modification : |
Descriptif
Code
<Regex Remplacer="\[\[([Ll])yen(s?)\]\]" Par="[[$1ien$2]]" />
<Regex Remplacer="\[\[([Ll])yen(s?)\|([^\]]+)\]\]" Par="[[$1ien$2|$3]]" />
Discussion
Pose de bandeau de portail
| auteur : Chico (d · c · b) | Création : avril 2007 | Dernière modification : |
Descriptif
Code
<Si Contient="{{Multi bandeau" Alors/>
<Regex Remplacer="({{Multi bandeau ?(\| ?Portail [^\}]*)+\}\}" Par="$1|Portail à ajouter}}" />
<Sinon>
<Si Contient="{{Portail" Alors/>
<Regex Remplacer="{{(Portail [^\}]*)}}" Par="{{Multi bandeau|$1|Portail à ajouter}}" />
<Sinon>
<Si Contient="DEFAULTSORT" Alors/>
<Regex Remplacer="(\{\{DEFAULTSORT:.*)" Par="{{Portail à ajouter}}\r\n$1" Mode singleline activé />
<Sinon>
<Regex Remplacer="(\[\[Catégorie:.*)" Par="{{Portail à ajouter}}\r\n$1" Mode singleline activé />
Discussion
Remplacement de mot
| auteur : TiChou (d · c · b) | Création : 19 mai 2007 | Dernière modification : |
Descriptif
Code
s/(?<!<nowiki>(?s:.(?<!</nowiki>))*)(?<!<pre>(?s:.(?<!</pre>))*)(?<!<math>(?s:.(?<!</math>))*)(?<!<!--(?s:.(?<!-->))*)(?<!<timeline>(?s:.(?<!</timeline>))*)(?<!\[\[(?:.(?<!\]\]|\|))*)(?<!\[\[(?:Catégorie|Category)\s*:(?:.(?<!\]\]))*)(?<!\{\{(?:.(?<!\}\}|\|))*)(?<!\{\{DEFAULTSORT\s*:(?:.(?<!\}\}))*)(?<!\[(?:http|https|ftp|mailto):(?:.(?<!\]\]|\s))*)\bmot\b/autre mot/gi
Discussion
Ajout DEFAULTSORT
| auteur : Chico (d · c · b) | Création : juin 2007 | Dernière modification : |
Descriptif
Code
<Set_Options Apply General Fixes />
<More Ajouter-Categorie="Test|%%key%%" />
<Regex Remplacer="(\[\[Catégorie:.*)\[\[Catégorie:Test\|([^\]]*)\]\]" Par="\r\n{{DEFAULTSORT|$2}}\r\n$1" Mode singleline activé />
<Regex Remplacer="(\[\[Catégorie:[^\|]*)((\|\*)?[^\]]*)?\]\]" Par="$1$3]]" />
Discussion
Ajout automatique de {{DEFAULTSORT}}
| auteur : TiChou (d · c · b) | Création : 06/06/2007 | Dernière modification : |
Descriptif
Code
public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip)
{
Skip = false;
Summary = "";
ArticleText = Regex.Replace(ArticleText,
@"(?<=\[\[)[ _]*" +
@"(?:" + Variables.LangCode.ToString().ToLower() + @"[ _]*:[ _]*)?" +
@"(?:Category|" + Variables.Namespaces[14].Replace(":", "") + @")[ _]*:[ _]*" +
@"(?=[^\]]+\]\])",
Variables.Namespaces[14], RegexOptions.IgnoreCase);
ArticleText = Regex.Replace(ArticleText,
@"(?<=\[\[" +
Variables.Namespaces[14] +
@")\p{Ll}",
new MatchEvaluator(UpFirstChar));
Match match;
string key;
if (!Regex.IsMatch(ArticleText, @"\{\{DEFAULTSORT:[^\}]*\}\}"))
{
match = Regex.Match(ArticleText, @"\[\[Catégorie:[^\|\]]+\|((?:[^,\]]+(?=,)|[^\]]{2,})(?:, *[^\]]+)?)\]\]");
if (!match.Success)
{
key = CleanKey(Tools.MakeHumanCatKey(ArticleTitle));
}
else
{
key = CleanKey(match.Groups[1].Value);
}
ArticleText = Regex.Replace(ArticleText,
@"(\[\[Catégorie:[^\]]+\]\].*)",
"{{DEFAULTSORT:" + key + "}}\n$1",
RegexOptions.Singleline);
ArticleText = Regex.Replace(ArticleText,
@"(?<=\[\[Catégorie:[^\|\]]+)\|[^\]]{2,}(?=\]\])",
"");
}
else
{
ArticleText = Regex.Replace(ArticleText,
@"(?<=\{\{)[ _]*DEFAULTSORT[ _]*:[ _]*([^\}]*?)[ _]*(?=\}\})",
new MatchEvaluator(Key),
RegexOptions.IgnoreCase);
ArticleText = Regex.Replace(ArticleText,
@"(?<=\{\{DEFAULTSORT:[^\}]*\}\})\s*(?=\[\[" +
Variables.Namespaces[14] +
@")",
"\r\n",
RegexOptions.Singleline);
}
return ArticleText;
}
private string UpFirstChar(Match m)
{
return m.Value.ToUpper();
}
private string CleanKey(string key)
{
key = Regex.Replace(key.Replace("_"," "), @" +", " ");
string[] tr1 = new string[48] { "0⅛¼⅜⅝⅞½¾٠۰", "1١۱", "2٢۲", "3٣۳", "4٤۴", "5٥۵", "6٦۶", "7٧۷", "8٨۸", "9٩۹", "aáàâãäåăąā", "AÁÀÂÃÄÅĂĄĀ", "cçćĉčċ", "CÇĆĈČĊ", "dðďđ", "DÐĎĐ", "eéèêëěėęē", "EÉÈÊËĚĖĘĒ", "gğĝġģ", "GĞĜĠĢ", "hĥħ", "HĤĦ", "iíìîïıĩįī", "IÍÌÎÏİĨĮĪ", "jĵ", "JĴ", "kĸķ", "KĶ", "lĺľłļŀ", "LĹĽŁĻĿ", "nñʼnńňņ", "NÑŃŇŅ", "oóòôõöøőō", "OÓÒÔÕÖØŐŌ", "rŕřŗ", "RŔŘŖ", "sśŝšş", "SŚŜŠŞ", "tťŧţ", "TŤŦŢ", "uúùûüŭůűũųū", "UÚÙÛÜŬŮŰŨŲŪ", "wŵ", "WŴ", "yýÿŷ", "YÝŶŸ", "zźžż", "ZŹŽŻ" };
string[] tr2 = new string[8] { "aeæ", "AEÆ", "oeœ", "OEŒ", "ssß", "ijij", "ngŋ", "NGŊ" };
foreach (string t in tr1)
{
key = Regex.Replace(key, @"[" + t.Substring(1) + @"]", t.Substring(0, 1));
}
foreach (string t in tr2)
{
key = Regex.Replace(key, @"[" + t.Substring(2) + @"]", t.Substring(0, 2));
}
return key;
}
private string Key(Match m)
{
return "DEFAULTSORT:" + CleanKey(m.Groups[1].Value);
}
Discussion
Pose d'un bandeau
| auteur : TiChou (d · c · b) | Création : 23 mai 2007 | Dernière modification : |
Descriptif
Code
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using WikiFunctions;
namespace AutoWikiBrowser
{
class Module1 : WikiFunctions.Plugin.IModule
{
string portail = "<bandeau portail à ajouter>";
string SummaryTemp;
string[] BandeauxUniques;
int nbBU;
public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip)
{
Skip = false;
Summary = "";
string ArticleTextOld = ArticleText;
SummaryTemp = "";
BandeauxUniques = new string[100];
nbBU = 0;
// Remplacement des divers modèles de multi bandeaux par le modèle {{Multi bandeau}}
ArticleText = Regex.Replace(ArticleText,
@"\{\{ *(?:(?::? *fr *: *)?(?:Modèle|Template) *: *)?(?:Multi[ _]+bandeaux?|Multi-?bandeau|Multib) *(\|[^\}]*)?\}\}",
"{{Multi bandeau$1}}",
RegexOptions.IgnoreCase);
if (ArticleText != ArticleTextOld)
{
Summary += ", rempl. modèle";
ArticleTextOld = ArticleText;
}
// Suppression des modèles multi bandeaux ou des paramètres vides se trouvant à l'intérieur d'un modèle {{Multi bandeau}}
ArticleText = Regex.Replace(ArticleText,
@"(?<=\{\{Multi bandeau(?:\|[^\|\}]*)*?)\| *(?:(?::? *fr *: *)?(?:Modèle|Template) *: *)?(?:Multi[ _]+bandeaux?|Multi-?bandeau|Multib|) *(?=(?:\|[^\|\}]*)*\}\})",
"",
RegexOptions.IgnoreCase);
if (ArticleText != ArticleTextOld)
{
Summary += ", suppr. modèle à l'intérieur";
ArticleTextOld = ArticleText;
}
// Nettoyage des (multi-)bandeaux et suppression des doublons
ArticleText = Regex.Replace(ArticleText,
@"(\{\{(?:Multi bandeau\|)?)((?<=\{\{Multi bandeau\|)[^\}]+|(?<=\{\{) *(?:(?::? *fr *: *)?(?:Modèle|Template) *: *)?(?:Ébauche(?:s?|[ _]+[^\|\}]+)|Portail[ _]+[^\|\}]+))(\}\}(?s:\s*))",
new MatchEvaluator(NettoyageBandeau),
RegexOptions.IgnoreCase);
if (ArticleText != ArticleTextOld)
{
Summary += ", net. modèle";
Summary += SummaryTemp;
SummaryTemp = "";
ArticleTextOld = ArticleText;
}
// Groupement des bandeaux ébauches dans un unique modèle {{Multi bandeau}}
ArticleText = Regex.Replace(ArticleText,
@"(?:\{\{(?:Multi bandeau\|)?((?<=\{\{Multi bandeau\|)(?:[^\}]+\|)?Ébauche[s ][^\}]+|Ébauche(?:s?| [^\|\}]+))\}\}(\s*)){2,}",
new MatchEvaluator(MultiBandeau),
RegexOptions.Singleline);
// Groupement des bandeaux portail dans un unique modèle {{Multi bandeau}}
ArticleText = Regex.Replace(ArticleText,
@"(?:\{\{(?:Multi bandeau\|)?((?<=\{\{Multi bandeau\|)(?:[^\}]+\|)?Portail [^\}]+|Portail [^\|\}]+)\}\}(\s*)){2,}",
new MatchEvaluator(MultiBandeau),
RegexOptions.Singleline);
if (ArticleText != ArticleTextOld)
{
Summary += ", group. bandeaux";
ArticleTextOld = ArticleText;
}
// Ajout portail
portail = portail.Trim();
if (portail != String.Empty)
{
portail = Regex.Replace(portail, "_", " ");
portail = Regex.Replace(portail, " +", " ");
portail = Regex.Replace(portail, @"^(?:(?::? *fr *: *)?(?:Modèle|Template) *: *)?", "");
portail = Tools.TurnFirstToUpper(portail);
if (Array.IndexOf(BandeauxUniques, portail) == -1)
{
if (Regex.IsMatch(ArticleText, @"\{\{(?:Multi bandeau\|(?:[^\}]+\|)?Portail [^\}]+|Portail [^\|\}]+)\}\}"))
{
ArticleText = Regex.Replace(ArticleText,
@"(.*\{\{)(?:Multi bandeau\|((?:[^\}]+\|)?Portail [^\}]+)|(Portail [^\|\}]+))(?=\}\})",
"$1Multi bandeau|$2$3|" + portail,
RegexOptions.Singleline | RegexOptions.Multiline);
}
else if (Regex.IsMatch(ArticleText, @"(?:\{\{ *DEFAULTSORT *:[^\}]+\}\}\s*)?\[\[ *Catégorie *:[^\]]+\]\]", RegexOptions.IgnoreCase))
{
ArticleText = Regex.Replace(ArticleText,
@"((?:\{\{ *DEFAULTSORT *:[^\}]+\}\}\s*)?\[\[ *Catégorie *:[^\]]+\]\].*)",
"{{" + portail + "}}\n\n$1",
RegexOptions.Singleline | RegexOptions.IgnoreCase);
}
else
{
Skip = true;
return ArticleText;
}
}
else
{
Skip = true;
return ArticleText;
}
}
if (ArticleText != ArticleTextOld)
{
Summary += ", ajout bandeau " + portail;
ArticleTextOld = ArticleText;
}
// Suppression des modèles {{Multi bandeau}} vide ou avec un seul bandeau
ArticleText = Regex.Replace(ArticleText,
@"\{\{Multi bandeau\|?\}\}\s*|(?<=\{\{)Multi bandeau\|(?=[^\|\}]+\}\})",
"");
if (ArticleText != ArticleTextOld)
{
Summary += ", suppr. modèle inutile";
ArticleTextOld = ArticleText;
}
// Correction des retours à la ligne entre bandeaux et catégories
ArticleText = Regex.Replace(ArticleText,
@"(?<=\{\{(?:Multi bandeau\|[^\}]+|Portail [^\|\}]+)\}\})\s*(?=(?:\{\{ *DEFAULTSORT *:[^\}]+\}\}\s*)?\[\[ *Catégorie *:[^\]]+\]\].*)",
"\r\n\r\n",
RegexOptions.Singleline);
if (ArticleText != ArticleTextOld)
{
Summary += ", corr. \\r\\n";
ArticleTextOld = ArticleText;
}
ArticleText = Regex.Replace(ArticleText, @"\[\[ *Cat(?:égorie|egory) *: *(?=[^\]]+\]\])", "[[Catégorie:", RegexOptions.IgnoreCase);
ArticleText = Regex.Replace(ArticleText, @"\[\[Catégorie:(\p{Ll})", new MatchEvaluator(UpFirstChar));
ArticleText = Regex.Replace(ArticleText, @"(?<=\{\{)(?::? *fr *: *)?(?:Modèle|Template) *: *(?=[^\}]+\}\})", "", RegexOptions.IgnoreCase);
return ArticleText;
}
private string UpFirstChar(Match m)
{
return "[[Catégorie:" + m.Groups[1].ToString().ToUpper();
}
private string NettoyageBandeau(Match m)
{
string bandeau;
string bandeaux = "";
foreach (string b in m.Groups[2].Value.Split(new Char[] { '|' }))
{
bandeau = b.Trim();
bandeau = Regex.Replace(bandeau, "_", " ");
bandeau = Regex.Replace(bandeau, " +", " ");
bandeau = Regex.Replace(bandeau, @"^(?:(?::? *fr *: *)?(?:Modèle|Template) *: *)?", "");
bandeau = Tools.TurnFirstToUpper(bandeau);
if (Regex.IsMatch(bandeau, @"^(?:Ébauche(?:s?| .+)|Portail .+)$", RegexOptions.IgnoreCase))
{
if (Array.IndexOf(BandeauxUniques, bandeau) == -1)
{
BandeauxUniques[nbBU] = bandeau;
nbBU++;
bandeaux += bandeau + "|";
}
else
{
SummaryTemp += ", suppr. doublon " + bandeau;
}
}
else
{
bandeaux += bandeau + "|";
}
}
if (bandeaux == String.Empty)
{
return String.Empty;
} else {
return m.Groups[1].Value + bandeaux.Trim(new Char[] { '|' }) + m.Groups[3].Value;
}
}
private string MultiBandeau(Match m)
{
string bandeaux = "";
foreach (Capture c in m.Groups[1].Captures)
{
bandeaux += "|" + c.Value;
}
return "{{Multi bandeau" + bandeaux + "}}" + m.Groups[2].Captures[m.Groups[2].Captures.Count-1];
}
}
}
Discussion
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.