Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitda1654e

Browse files
zaycodesbrendajerop
authored andcommitted
Added Sample codes for API:Setnotificationtimestamp
1 parentd73312e commitda1654e

File tree

8 files changed

+301
-0
lines changed

8 files changed

+301
-0
lines changed

‎javascript/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ Code snippets in Javascript demonstrating how to use various modules of the [Med
107107
*[get_file_usage.js](get_file_usage.js): Get a list of pages using a given file.
108108
*[API:Feedrecentchanges](https://www.mediawiki.org/wiki/API:Feedrecentchanges)
109109
*[get_feed_recent_changes.js](get_feed_recent_changes.js): Show recent changes as an RSS feed.
110+
*[API:Setnotificationtimestamp](https://www.mediawiki.org/wiki/API:Setnotificationtimestamp)
111+
*[set_notification_timestamp.js](set_notification_timestamp.js): Reset the notification status for the entire watchlist.
110112

111113
###Search
112114
*[API:Search](https://www.mediawiki.org/wiki/API:Search)
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
set_notification_timestamp.js
3+
4+
MediaWiki API Demos
5+
Demo of `Setnotificationtimestamp` module: Reset the notification status for the entire watchlist.
6+
7+
MIT license
8+
*/
9+
varrequest=require("request").defaults({jar:true}),
10+
url="https://test.wikipedia.org/w/api.php";
11+
12+
// Step 1: GET Request to fetch login token
13+
functiongetLoginToken(){
14+
varparams_0={
15+
action:"query",
16+
meta:"tokens",
17+
type:"login",
18+
format:"json"
19+
};
20+
request.get({url:url,qs:params_0},function(error,res,body){
21+
if(error){
22+
return;
23+
}
24+
vardata=JSON.parse(body);
25+
loginRequest(data.query.tokens.logintoken);
26+
});
27+
}
28+
29+
// Step 2: POST request to log in.
30+
// Use of main account for login is not
31+
// supported. Obtain credentials via Special:BotPasswords
32+
// (https://www.mediawiki.org/wiki/Special:BotPasswords) for lgname & lgpassword
33+
functionloginRequest(login_token){
34+
varparams_1={
35+
action:"login",
36+
lgname:"bot_username",
37+
lgpassword:"bot_password",
38+
lgtoken:login_token,
39+
format:"json"
40+
};
41+
42+
request.post({url:url,form:params_1},function(error,res,body){
43+
if(error){
44+
return;
45+
}
46+
getCsrfToken();
47+
});
48+
}
49+
50+
// Step 3: GET request to fetch CSRF token
51+
functiongetCsrfToken(){
52+
varparams_2={
53+
action:"query",
54+
meta:"tokens",
55+
format:"json"
56+
};
57+
request.get({url:url,qs:params_2},function(error,res,body){
58+
if(error){
59+
return;
60+
}
61+
vardata=JSON.parse(body);
62+
setNotificationTimestamp(data.query.tokens.csrftoken);
63+
});
64+
}
65+
66+
// Step 4: Send a POST request to reset the notification status for the entire watchlist.
67+
functionsetNotificationTimestamp(csrf_token){
68+
varparams_3={
69+
action:"setnotificationtimestamp",
70+
entirewatchlist:"",
71+
format:"json",
72+
token:csrf_token
73+
};
74+
request.post({url:url,form:params_3},function(error,res,body){
75+
if(error){
76+
return;
77+
}
78+
console.log(body);
79+
});
80+
}
81+
82+
// Start From Step 1
83+
getLoginToken();
84+
85+

‎mediawikijs/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ These code snippets are usefull to create Userscripts and Gadgets.
171171
*[get_file_usage.js](get_file_usage.js): Get a list of pages using a given file.
172172
*[API:Feedrecentchanges](https://www.mediawiki.org/wiki/API:Feedrecentchanges)
173173
*[get_feed_recent_changes.js](get_feed_recent_changes.js): Show recent changes as an RSS feed.
174+
*[API:Setnotificationtimestamp](https://www.mediawiki.org/wiki/API:Setnotificationtimestamp)
175+
*[set_notification_timestamp.js](set_notification_timestamp.js): Reset the notification status for the entire watchlist.
174176

175177
###Search
176178
*[API:Search](https://www.mediawiki.org/wiki/API:Search)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
set_notification_timestamp.js
3+
4+
MediaWiki API Demos
5+
Demo of `Setnotificationtimestamp` module: Reset the notification status for the entire watchlist.
6+
7+
MIT license
8+
*/
9+
10+
varparams={
11+
action:'setnotificationtimestamp',
12+
entirewatchlist:'',
13+
format:'json'
14+
},
15+
api=newmw.Api();
16+
17+
api.postWithToken('csrf',params).done(function(data){
18+
console.log(data);
19+
});

‎php/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ Code snippets in PHP demonstrating how to use various modules of the [MediaWiki
175175
*[get_file_usage.php](get_file_usage.php): Get a list of pages using a given file.
176176
*[API:Feedrecentchanges](https://www.mediawiki.org/wiki/API:Feedrecentchanges)
177177
*[get_feed_recent_changes.php](get_feed_recent_changes.php): Show recent changes as an RSS feed.
178+
*[API:Setnotificationtimestamp](https://www.mediawiki.org/wiki/API:Setnotificationtimestamp)
179+
*[set_notification_timestamp.php](set_notification_timestamp.php): Reset the notification status for the entire watchlist.
178180

179181
###Search
180182
*[API:Search](https://www.mediawiki.org/wiki/API:Search)

‎php/set_notification_timestamp.php‎

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<?php
2+
3+
/*
4+
set_notification_timestamp.php
5+
6+
MediaWiki API Demos
7+
Demo of `Setnotificationtimestamp` module: Reset the notification status for the entire watchlist.
8+
9+
MIT license
10+
*/
11+
$endPoint ="https://test.wikipedia.org/w/api.php";
12+
13+
$login_Token =getLoginToken();// Step 1
14+
loginRequest($login_Token );// Step 2
15+
$csrf_Token =getCSRFToken();// Step 3
16+
setNotificationTimestamp($csrf_Token );// Step 4
17+
18+
// Step 1: GET request to fetch login token
19+
functiongetLoginToken() {
20+
global$endPoint;
21+
22+
$params1 = [
23+
"action" =>"query",
24+
"meta" =>"tokens",
25+
"type" =>"login",
26+
"format" =>"json"
27+
];
28+
29+
$url =$endPoint ."?" .http_build_query($params1 );
30+
31+
$ch =curl_init($url );
32+
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true );
33+
curl_setopt($ch,CURLOPT_COOKIEJAR,"cookie.txt" );
34+
curl_setopt($ch,CURLOPT_COOKIEFILE,"cookie.txt" );
35+
36+
$output =curl_exec($ch );
37+
curl_close($ch );
38+
39+
$result =json_decode($output,true );
40+
return$result["query"]["tokens"]["logintoken"];
41+
}
42+
43+
// Step 2: POST request to log in. Use of main account for login is not
44+
// supported. Obtain credentials via Special:BotPasswords
45+
// (https://www.mediawiki.org/wiki/Special:BotPasswords) for lgname & lgpassword
46+
functionloginRequest($logintoken ) {
47+
global$endPoint;
48+
49+
$params2 = [
50+
"action" =>"login",
51+
"lgname" =>"bot_user_name",
52+
"lgpassword" =>"bot_password",
53+
"lgtoken" =>$logintoken,
54+
"format" =>"json"
55+
];
56+
57+
$ch =curl_init();
58+
59+
curl_setopt($ch,CURLOPT_URL,$endPoint );
60+
curl_setopt($ch,CURLOPT_POST,true );
61+
curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query($params2 ) );
62+
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true );
63+
curl_setopt($ch,CURLOPT_COOKIEJAR,"cookie.txt" );
64+
curl_setopt($ch,CURLOPT_COOKIEFILE,"cookie.txt" );
65+
66+
$output =curl_exec($ch );
67+
curl_close($ch );
68+
}
69+
70+
// Step 3: GET request to fetch CSRF token
71+
functiongetCSRFToken() {
72+
global$endPoint;
73+
74+
$params3 = [
75+
"action" =>"query",
76+
"meta" =>"tokens",
77+
"format" =>"json"
78+
];
79+
80+
$url =$endPoint ."?" .http_build_query($params3 );
81+
82+
$ch =curl_init($url );
83+
84+
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true );
85+
curl_setopt($ch,CURLOPT_COOKIEJAR,"cookie.txt" );
86+
curl_setopt($ch,CURLOPT_COOKIEFILE,"cookie.txt" );
87+
88+
$output =curl_exec($ch );
89+
curl_close($ch );
90+
91+
$result =json_decode($output,true );
92+
return$result["query"]["tokens"]["csrftoken"];
93+
}
94+
95+
# Step 4: Send a POST request to reset the notification status for the entire watchlist.
96+
functionsetNotificationTimestamp($csrftoken ) {
97+
global$endPoint;
98+
99+
$params4 = [
100+
"action" =>"setnotificationtimestamp",
101+
"entirewatchlist" =>"",
102+
"format" =>"json",
103+
"token" =>$csrftoken
104+
];
105+
106+
$ch =curl_init();
107+
108+
curl_setopt($ch,CURLOPT_URL,$endPoint );
109+
curl_setopt($ch,CURLOPT_POST,true );
110+
curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query($params4 ) );
111+
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true );
112+
curl_setopt($ch,CURLOPT_COOKIEJAR,"cookie.txt" );
113+
curl_setopt($ch,CURLOPT_COOKIEFILE,"cookie.txt" );
114+
115+
$response =curl_exec($ch);
116+
curl_close($ch);
117+
118+
echo ($response);
119+
}

‎python/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ Code snippets in Python demonstrating how to use various modules of the [MediaWi
181181
*[get_file_usage.py](get_file_usage.py): Get a list of pages using a given file.
182182
*[API:Feedrecentchanges](https://www.mediawiki.org/wiki/API:Feedrecentchanges)
183183
*[get_feed_recent_changes.py](get_feed_recent_changes.py): Show recent changes as an RSS feed.
184+
*[API:Setnotificationtimestamp](https://www.mediawiki.org/wiki/API:Setnotificationtimestamp)
185+
*[set_notification_timestamp.py](set_notification_timestamp.py): Reset the notification status for the entire watchlist.
184186

185187
###Search
186188
*[API:Search](https://www.mediawiki.org/wiki/API:Search)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/python3
2+
3+
"""
4+
set_notification_timestamp.py
5+
6+
MediaWiki API Demos
7+
Demo of `Setnotificationtimestamp` module:
8+
Reset the notification status for the entire watchlist.
9+
10+
MIT license
11+
"""
12+
importrequests
13+
14+
S=requests.Session()
15+
16+
URL="https://test.wikipedia.org/w/api.php"
17+
18+
# Step 1: Retrieve a login token
19+
PARAMS_1= {
20+
"action":"query",
21+
"meta":"tokens",
22+
"type":"login",
23+
"format":"json"
24+
}
25+
26+
R=S.get(url=URL,params=PARAMS_1)
27+
DATA=R.json()
28+
29+
LOGIN_TOKEN=DATA['query']['tokens']['logintoken']
30+
31+
# Step 2: Send a POST request to log in. For this login
32+
# method, obtain credentials by first visiting
33+
# https://www.test.wikipedia.org/wiki/Manual:Bot_passwords
34+
# See https://www.mediawiki.org/wiki/API:Login for more
35+
# information on log in methods.
36+
PARAMS_2= {
37+
"action":"login",
38+
"lgname":"user_name",
39+
"lgpassword":"password",
40+
"format":"json",
41+
"lgtoken":LOGIN_TOKEN
42+
}
43+
44+
R=S.post(URL,data=PARAMS_2)
45+
DATA=R.json()
46+
47+
# Step 3: While logged in, retrieve a CSRF token
48+
PARAMS_3= {
49+
"action":"query",
50+
"meta":"tokens",
51+
"format":"json"
52+
}
53+
54+
R=S.get(url=URL,params=PARAMS_3)
55+
DATA=R.json()
56+
57+
CSRF_TOKEN=DATA["query"]["tokens"]["csrftoken"]
58+
59+
# Step 4: Send a POST request to reset the notification status for the entire watchlist.
60+
PARAMS_4= {
61+
"action":"setnotificationtimestamp",
62+
"entirewatchlist":"",
63+
"format":"json",
64+
"token" :CSRF_TOKEN
65+
}
66+
67+
R=S.post(URL,data=PARAMS_4)
68+
DATA=R.text
69+
70+
print(DATA)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp