diff --git a/tools/README.md b/tools/README.md index 05ee262..73d5e3e 100644 --- a/tools/README.md +++ b/tools/README.md @@ -1,41 +1,43 @@ # boz-mw command line tools This is a directory for command line tools that uses the boz-mw framework. Actually there are not too much tools. ## Configuration Copy the `config-example.php` to `config.php` and fill it with your bot credentials. ## replace.php This is a script to sobstitute text in the wikitext from an API query. e.g. to transform in *farfallese* the whole Italian Wikipedia: ```bash ./replace.php --wiki=itwiki --generator=allpages \ a afa \ e efe \ i ifi \ o ofo \ u ufu ``` e.g. to replace a simple template parameter in top of the page, e.g. from `{{Sito web|commerciale = Sì}}` to `{{Sito web|lucro = Sì}}`: ```bash ./replace.php \ --wiki=itwiki \ --generator=transcludedin \ --titles=Template:Sito_web \ --rvsection=0 \ --regex \ '/\|commerciale(.*=.*)(Sì|No|sì|no)(.*)/' \ '|lucro$1$2$3' ``` Other options: ```bash ./replace.php --help ``` + +You can see some [examples](./examples). diff --git a/tools/examples/fix-htm4.sh b/tools/examples/fix-htm4.sh new file mode 100755 index 0000000..76fd1b5 --- /dev/null +++ b/tools/examples/fix-htm4.sh @@ -0,0 +1,40 @@ +# Script to partially upgrade the wikitext to HTML4 + +# Regex to be called n times where n is the number of attributes to be fixed + 1 (bgcolor, color, valign, align + 1 = 5) +PATTERN_MERGE_STYLES='/style="([a-zA-Z0-9-; #:%]+?);?"((?: +[a-zA-Z]+ *= *("?)[a-zA-Z0-9-; #:%]+\3)*) style="([a-zA-Z0-9-; #:%]+?);?"/' +REPLACE_MERGE_STYLES='style="$1; $4"$2' + +# ___ ____________________________________________________________________________ +../replace.php \ +--wiki=itwiki \ +--generator=search \ +--gsrsearch='insource:bgcolor' \ +--regex \ +--summary="Bot: migrazione attributi deprecati da [[HTML 4.0]]" \ + \ +'/(.{0,10})[bB]gcolor *= *["”]?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})+["”]?(.{0,10})/' \ +'$1style="background:#$2"$3' \ + \ +'/(.{0,10})color *= *["”]?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})+["”]?(.{0,10})/' \ +'$1style="color:#$2"$3' \ + \ +'/(.{0,10})[bB]gcolor *= *["”]?(#[a-z0-9A-Z]{6}|#[a-zA-Z0-9]{3}|[a-zA-Z]{3,})+["”]?(.{0,10})/' \ +'$1style="background:$2"$3' \ + \ +'/(.{0,10})[cC]olor *= *["”]?(#[a-z0-9A-Z]{6}|#[a-zA-Z0-9]{3}|[a-zA-Z]{3,})+["”]?(.{0,10})/' \ +'$1style="color:$2"$3' \ + \ +'/#([a-fA-F0-9])\1([a-fA-F0-9])\2([a-fA-F0-9])\3(;?)"/' \ +'#$1$2$3$4"' \ + \ +'/(.{0,10})valign *= *["”]?([a-zA-Z0-9-])["”]?(.{0,10})/' \ +'$1style="vertical-align:$2"$3' \ + \ +'/(.{0,10})align *= *["”]?([a-zA-Z0-9-]+)["”]?(.{0,10})/' \ +'$1style="text-align:$2"$3' \ + \ +$PATTERN_MERGE_STYLES $REPLACE_MERGE_STYLES \ +$PATTERN_MERGE_STYLES $REPLACE_MERGE_STYLES \ +$PATTERN_MERGE_STYLES $REPLACE_MERGE_STYLES \ +$PATTERN_MERGE_STYLES $REPLACE_MERGE_STYLES \ +$PATTERN_MERGE_STYLES $REPLACE_MERGE_STYLES \