Jump to content
MediaWiki

API:ClearHasMsg/Sample code 1

From mediawiki.org

Python

[edit ]
#!/usr/bin/python3
"""
 clear_has_msg.py
 MediaWiki API Demos
 Demo of `ClearHasMsg` module: Clear the hasmsg flag for the current user.
 MIT License
"""
importrequests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
 "action": "clearhasmsg",
 "format": "json"
}
R = S.post(url=URL, data=PARAMS)
DATA = R.json()
print(DATA)

PHP

[edit ]
<?php
/*
 clear_has_msg.php
 MediaWiki API Demos
 Demo of `ClearHasMsg` module: Clear the hasmsg flag for the current user.
 MIT License
*/
$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
 "action" => "clearhasmsg",
 "format" => "json"
];
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $endPoint );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $params ) );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_COOKIEJAR, "cookie.txt" );
curl_setopt( $ch, CURLOPT_COOKIEFILE, "cookie.txt" );
$response = curl_exec($ch);
curl_close($ch);
echo ($response);

JavaScript

[edit ]
/*
	clear_has_msg.js
 MediaWiki API Demos
 Demo of `ClearHasMsg` module: Clear the hasmsg flag for the current user.
 MIT License
*/
varurl="https://en.wikipedia.org/w/api.php";
varparams={
action:"clearhasmsg",
format:"json"
};
request.post({url:url,form:params},function(error,res,body){
if(error){
return;
}
console.log(body);
});

MediaWiki JS

[edit ]
/*
	clear_has_msg.js
 MediaWiki API Demos
 Demo of `ClearHasMsg` module: Clear the hasmsg flag for the current user.
 MIT License
*/
varparams={
action:"clearhasmsg",
format:"json"
},
api=newmw.Api();
api.post(params).done(function(data){
console.log(data);
});

AltStyle によって変換されたページ (->オリジナル) /