-
Notifications
You must be signed in to change notification settings - Fork 0
/
batch_edit.php
127 lines (109 loc) · 3.47 KB
/
batch_edit.php
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
/////////////////////////////////////////////////////////
//用户信息
$UserID = "";
$UserName = "";
$SSOToken = "";
$SSO_session = "";
/////////////////////////////////////////////////////////
$Cookie = "moegirlSSOUserID=".$UserID."; moegirlSSOUserName=".$UserName."; moegirlSSOToken=".$SSOToken."; moegirlSSO_session=".$SSO_session.";";
function processContent($content){
//return $content."xxtestEdit";
return str_replace(
//将这里的内容
array("{| class=\"wikitable\" style=\"margin: 1em auto 1em auto;width: 400px;\""),
//替换成
array("{| class=\"wikitable\" style=\"margin: 1em auto 1em auto;max-width: 400px;\""),
////////////////////////
$content
);
}
//这里填上需要修改的页面
$editpages = array(
"神乐丽",
"秋月凉",
"卯月卷绪"
);
//请详细填写好修改的理由
$reason = "偶像大师SideM 表格宽度适配";
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
function getToken($title){
$url = 'https://zh.moegirl.org/api.php';
$post = array(
"action" => "query",
"meta" => "tokens",
"titles" => $title,
"format" => "json"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Moegirl iOS Login Proxy');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_COOKIE, $Cookie);
$content = curl_exec($ch);
$http_status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($http_status_code == 200) {
$data = json_decode($content);
//print_r($data);
return $data->query->tokens->csrftoken;
}else{
return;
}
}
function submitChanges($title,$tokens,$content,$summary){
$url = 'https://zh.moegirl.org/api.php';
$post = array(
"action" => "edit",
"text" => $content,
"title" => $title,
"summary" => $summary,
"token" => $tokens,
"format" => "json"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded; charset=UTF-8'));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Moegirl iOS Login Proxy');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_COOKIE, $Cookie);
$content = curl_exec($ch);
$http_status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$data = json_decode($content);
//print_r($data);
echo "\t\t".$http_status_code."\t\t".$data->edit->result;
}
foreach ($editpages as $key => $value) {
echo $key."\t".$value;
//获取内容
$title = $value;
$url = 'https://zh.moegirl.org/index.php?title='.urlencode($title)."&action=raw";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Moegirl iOS Login Proxy');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_COOKIE, $Cookie);
$content = curl_exec($ch);
$http_status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($http_status_code == 200) {
$token = getToken($title);
echo "\t\t".$token;
if (!empty($token)) {
submitChanges($title,$token,processContent($content),$reason);
}
}else{
echo $http_status_code;
}
//结束
echo "\n";
}