forked from sigbertklinke/R
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpurgeAll.php
More file actions
executable file
·65 lines (58 loc) · 2.08 KB
/
Copy pathpurgeAll.php
File metadata and controls
executable file
·65 lines (58 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/*
(C) 2006- Sigbert Klinke ([email protected]),
This file is part of R/Octave Extension for Mediawiki.
The R/Octave Extension is free software: you can
redistribute it and/or modify it under the terms of
the GNU General Public License as published by the
Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
The R/Octave Extension is distributed in the hope that
It will be useful, but WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
You should have received a copy of the GNU General
Public License along with the R/Octave Extension.
If not, see http://www.gnu.org/licenses/.
*/
if (count($argv)!=4) {
print "\nUsage: php purgeAll.php http://mywiki/ Loginname Password\n\n";
die(1);
}
$wwwpre = $argv[1];
$allpages = array();
$apfrom = '';
do {
$www = $wwwpre . 'api.php?action=query&list=allpages&apfrom=' . urlencode($apfrom) . '&aplimit=500&format=php';
print "Get : $www\n";
$pages = unserialize(file_get_contents($www));
$pages = $pages['query']['allpages'];
foreach ($pages as $page) { $allpages[] = $page['title']; }
$allpages = array_unique($allpages);
sort($allpages, SORT_STRING);
$apfrom = end($allpages);
} while (count($pages)>1);
sort($allpages, SORT_STRING);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// login
$postfields = 'action=login&lgname=' . $argv[2] . '&lgpassword=' . $argv[3];
curl_setopt($ch, CURLOPT_URL, $wwwpre . 'api.php');
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_exec($ch);
// purge all pages
foreach($allpages as $page) {
print "Purge: $page\n";
$postfields = 'action=purge&titles=' . urlencode($page);
curl_setopt($ch, CURLOPT_URL, $wwwpre . 'api.php');
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$pages = curl_exec($ch);
}
// logout
$postfields = 'action=logout';
curl_setopt($ch, CURLOPT_URL, $wwwpre . 'api.php');
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_exec($ch);
curl_close($ch);
?>