git-push-to-gitlab: Don't create or push `synced/master`
[sunny256-utils.git] / purgewiki
blob3e1c4d567c133ef46a41e4e06ecaf8b261d15ab9
1 #!/usr/bin/env bash
2 # mwpurgecache - invalidate mediawiki cache
4 set -e
6 PROG=$(basename $0)
7 VER=0.1
9 function version() {
10 echo "$PROG $VER - invalidate mediawiki cache
11 Copyright (c) 2005 Claudio Jolowicz <claudio@jolowicz.com>
13 Copying and distribution of this file, with or without modification,
14 are permitted in any medium without royalty provided the copyright
15 notice and this notice are preserved. This programs comes with
16 ABSOLUTELY NO WARRANTEE.
20 function usage() {
21 version
22 echo "Syntax: $PROG [options] [--] [pages]
24 Options:
26 -H, --host host name (default: localhost)
27 -w, --wiki WIKI server path to wiki (default: /wiki/)
28 -u, --user USER username for HTTP authentication
29 -p, --passwd PASS password for HTTP authentication
30 -d, --dryrun show commands without executing them
31 -q, --quiet quiet (no output)
32 -v, --verbose be verbose (print server response)
33 -h, --help display this message
34 -V, --version display version information
36 Options and arguments must be separated by whitespace. WIKI must
37 match wgArticlePath, such that \$wgArticlePath = \"WIKI/\$1\". WIKI
38 must not contain regex special characters.
40 This script requests all wiki pages listed on the command line by
41 HTTP, prefixed by the wiki path, appending \`?action=purge' to the
42 URL. If no pages are specified, it retrieves the list of all pages
43 from Special:Allpages.
45 Examples:
47 \$ $PROG Main_page Help:Contents
48 \$ $PROG -H wiki.my.org -w /mediawiki -u joe -p banana
49 \$ $PROG -H wiki.my.org --dryrun | wc -l
53 ## The '-e#' is a noop option to avoid `Unsupported scheme' errors.
54 user='-e#'
55 passwd='-e#'
56 run=
57 verbose=-nv
58 quiet='-e#'
60 opt_host=http://localhost
61 opt_wiki=/wiki/
62 opt_user=
63 opt_passwd=
64 opt_dryrun=false
65 opt_quiet=false
66 opt_verbose=false
67 while [ "$1" ]
69 case "$1" in
70 -H|--host) opt_host="$2"; shift;;
71 -w|--wiki) opt_wiki="$2"; shift;;
72 -u|--user) opt_user="$2"; shift;;
73 -p|--passwd) opt_passwd="$2"; shift;;
74 -d|--dryrun) opt_dryrun=true;;
75 -q|--quiet) opt_quiet=true;;
76 -v|--verbose) opt_verbose=true;;
77 -h|--help) usage; exit 0;;
78 -V|--version) version; exit 0;;
79 --) shift; break;;
80 -*) usage 2>&1; exit 1;;
81 *) break;;
82 esac
83 shift
84 done
85 opt_host=${opt_host%/}
86 opt_wiki=/${opt_wiki#/}
87 opt_wiki=${opt_wiki%/}/
88 [ x"$opt_user" = x"" ] || user="--http-user=${opt_user}"
89 [ x"$opt_passwd" = x"" ] || passwd="--http-passwd=${opt_passwd}"
90 $opt_dryrun && run=echo
91 $opt_verbose && verbose="--server-response"
92 $opt_quiet && quiet="-q"
94 if [ $# -eq 0 ]; then
95 wget -qO- "$user" "$passwd" "${opt_host}${opt_wiki}Special:Allpages" |
96 sed -re '/start content/,/end content/p' -e 's/href="([^"]+)"/\nGREPME:\1\n/g' |
97 sed -nre 's/^GREPME:(.*)$/\1/p' |
98 grep "^${opt_wiki}"
99 else
100 for page; do echo "${opt_wiki}${page}"; done
103 while read page
105 $run wget -O/dev/null "$user" "$passwd" "$quiet" "$verbose" "${opt_host}${page}?action=purge"
106 done
108 exit 0