Skip to content

Commit c1a7d55

Browse files
committed
GCI Code Samples for 10 modules
1 parent 3833e04 commit c1a7d55

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1414
-5
lines changed

javascript/README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Code snippets in Javascript demonstrating how to use various modules of the [Med
2121
* [reset_password.js](reset_password.js): Reset password for all users with an email address.
2222
* [API:Feedcontributions](https://www.mediawiki.org/wiki/API:Feedcontributions)
2323
* [get_user_contributions_feed.js](get_user_contributions_feed.js): Show contributions of a user as an RSS feed.
24+
* [API:Userinfo](https://www.mediawiki.org/wiki/API:Userinfo)
25+
* [userinfo.js](userinfo.js): get general user info and user rights
2426

2527
### Page Operations
2628
* [API:Parse](https://www.mediawiki.org/wiki/API:Parse)
@@ -39,7 +41,7 @@ Code snippets in Javascript demonstrating how to use various modules of the [Med
3941
* [API:Deletedrevs](https://www.mediawiki.org/wiki/API:Deletedrevs)
4042
* [get_deleted_revisions.js](get_deleted_revisions.js): list deleted revisions from a user
4143
* [API:Deletedrevisions](https://www.mediawiki.org/wiki/API:Deletedrevisions)
42-
| * [get_deleted_revs.js](get_deleted_revs.js): list deleted revisions for a page
44+
* [get_deleted_revs.js](get_deleted_revs.js): list deleted revisions for a page
4345
* [API:Revisions](https://www.mediawiki.org/wiki/API:Revisions)
4446
* [get_pages_revisions.js](get_pages_revisions.js): get revision data of multiple pages
4547
* [get_filtered_page_revisions.js](get_filtered_page_revisions.js): get revision data of a page filtered by date and user
@@ -113,6 +115,24 @@ Code snippets in Javascript demonstrating how to use various modules of the [Med
113115
* [get_feed_recent_changes.js](get_feed_recent_changes.js): Show recent changes as an RSS feed.
114116
* [API:Setnotificationtimestamp](https://www.mediawiki.org/wiki/API:Setnotificationtimestamp)
115117
* [set_notification_timestamp.js](set_notification_timestamp.js): Reset the notification status for the entire watchlist.
118+
* [API:Langbacklinks](https://www.mediawiki.org/wiki/Langbacklinks)
119+
* [langbacklinks.js](langbacklinks.js): get pages linking to a given language link
120+
* [API:Templates](https://www.mediawiki.org/wiki/Templates)
121+
* [templates.js](templates.js): get a list of templates used on a page
122+
* [API:Pageprops](https://www.mediawiki.org/wiki/Pageprops)
123+
* [pageprops.js](pageprops.js): get various properties defined in the page content
124+
* [API:Extlinks](https://www.mediawiki.org/wiki/Extlinks)
125+
* [get_extlinks.js](get_extlinks.js): get a list of external links on a page
126+
* [API:Linkshere](https://www.mediawiki.org/wiki/Linkshere)
127+
* [linkshere.js](linkshere.js): get a list of pages linking to a given page
128+
* [API:Allmessages](https://www.mediawiki.org/wiki/Allmessages)
129+
* [all_messages.js](all_messages.js): get the Dutch translations of some messages
130+
* [API:Transcludedin](https://www.mediawiki.org/wiki/Transcludedin)
131+
* [get_transcluded_in.js](get_transcluded_in.js): get a list of pages which transclude a given page
132+
* [API:Langlinks](https://www.mediawiki.org/wiki/Langlinks)
133+
* [langlinks.js](langlinks.js): get a list of language links that a given page has
134+
* [API:Stashimageinfo](https://www.mediawiki.org/wiki/Stashimageinfo)
135+
* [stash_image_info.js](stash_image_info.js): return information for a stashed file
116136

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

javascript/all_messages.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//This file is autogenerated. See modules.json and autogenerator.py for details
2+
3+
/*
4+
all_messages.js
5+
6+
MediaWiki API Demos
7+
Demo of `Allmessages` module: Get the Dutch translations of some messages
8+
9+
MIT License
10+
*/
11+
12+
var url = "https://en.wikipedia.org/w/api.php";
13+
14+
var params = {
15+
action: "query",
16+
meta: "allmessages",
17+
ammessages: "august|mainpage|edit|rollback-success",
18+
amlang: "nl",
19+
format: "json"
20+
};
21+
22+
url = url + "?origin=*";
23+
Object.keys(params).forEach(function(key){url += "&" + key + "=" + params[key];});
24+
25+
fetch(url)
26+
.then(function(response){return response.json();})
27+
.then(function(response) {console.log(response);})
28+
.catch(function(error){console.log(error);});

javascript/get_extlinks.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//This file is autogenerated. See modules.json and autogenerator.py for details
2+
3+
/*
4+
get_extlinks.js
5+
6+
MediaWiki API Demos
7+
Demo of `Extlinks` module: Get a list of external links on a page
8+
9+
MIT License
10+
*/
11+
12+
var url = "https://en.wikipedia.org/w/api.php";
13+
14+
var params = {
15+
action: "query",
16+
titles: "Albert Einstein",
17+
prop: "extlinks",
18+
format: "json"
19+
};
20+
21+
url = url + "?origin=*";
22+
Object.keys(params).forEach(function(key){url += "&" + key + "=" + params[key];});
23+
24+
fetch(url)
25+
.then(function(response){return response.json();})
26+
.then(function(response) {console.log(response);})
27+
.catch(function(error){console.log(error);});

javascript/get_transcluded_in.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//This file is autogenerated. See modules.json and autogenerator.py for details
2+
3+
/*
4+
get_transcluded_in.js
5+
6+
MediaWiki API Demos
7+
Demo of `Transcludedin` module: Get a list of pages which transclude a given page
8+
9+
MIT License
10+
*/
11+
12+
var url = "https://en.wikipedia.org/w/api.php";
13+
14+
var params = {
15+
action: "query",
16+
titles: "Main Page",
17+
prop: "transcludedin",
18+
format: "json"
19+
};
20+
21+
url = url + "?origin=*";
22+
Object.keys(params).forEach(function(key){url += "&" + key + "=" + params[key];});
23+
24+
fetch(url)
25+
.then(function(response){return response.json();})
26+
.then(function(response) {console.log(response);})
27+
.catch(function(error){console.log(error);});

javascript/langbacklinks.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//This file is autogenerated. See modules.json and autogenerator.py for details
2+
3+
/*
4+
langbacklinks.js
5+
6+
MediaWiki API Demos
7+
Demo of `Langbacklinks` module: Get pages linking to a given language link
8+
9+
MIT License
10+
*/
11+
12+
var url = "https://en.wikipedia.org/w/api.php";
13+
14+
var params = {
15+
action: "query",
16+
list: "langbacklinks",
17+
lbltitle: "Test",
18+
lbllang: "fr",
19+
format: "json"
20+
};
21+
22+
url = url + "?origin=*";
23+
Object.keys(params).forEach(function(key){url += "&" + key + "=" + params[key];});
24+
25+
fetch(url)
26+
.then(function(response){return response.json();})
27+
.then(function(response) {console.log(response);})
28+
.catch(function(error){console.log(error);});

javascript/langlinks.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//This file is autogenerated. See modules.json and autogenerator.py for details
2+
3+
/*
4+
langlinks.js
5+
6+
MediaWiki API Demos
7+
Demo of `Langlinks` module: Get a list of language links that a given page has
8+
9+
MIT License
10+
*/
11+
12+
var url = "https://en.wikipedia.org/w/api.php";
13+
14+
var params = {
15+
action: "query",
16+
titles: "Albert Einstein",
17+
prop: "langlinks",
18+
format: "json"
19+
};
20+
21+
url = url + "?origin=*";
22+
Object.keys(params).forEach(function(key){url += "&" + key + "=" + params[key];});
23+
24+
fetch(url)
25+
.then(function(response){return response.json();})
26+
.then(function(response) {console.log(response);})
27+
.catch(function(error){console.log(error);});

javascript/linkshere.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//This file is autogenerated. See modules.json and autogenerator.py for details
2+
3+
/*
4+
linkshere.js
5+
6+
MediaWiki API Demos
7+
Demo of `Linkshere` module: Get a list of pages linking to a given page
8+
9+
MIT License
10+
*/
11+
12+
var url = "https://en.wikipedia.org/w/api.php";
13+
14+
var params = {
15+
action: "query",
16+
titles: "Main Page",
17+
prop: "linkshere",
18+
format: "json"
19+
};
20+
21+
url = url + "?origin=*";
22+
Object.keys(params).forEach(function(key){url += "&" + key + "=" + params[key];});
23+
24+
fetch(url)
25+
.then(function(response){return response.json();})
26+
.then(function(response) {console.log(response);})
27+
.catch(function(error){console.log(error);});

javascript/pageprops.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//This file is autogenerated. See modules.json and autogenerator.py for details
2+
3+
/*
4+
pageprops.js
5+
6+
MediaWiki API Demos
7+
Demo of `Pageprops` module: Get various properties defined in the page content
8+
9+
MIT License
10+
*/
11+
12+
var url = "https://en.wikipedia.org/w/api.php";
13+
14+
var params = {
15+
action: "query",
16+
titles: "Albert Einstein",
17+
prop: "pageprops",
18+
format: "json"
19+
};
20+
21+
url = url + "?origin=*";
22+
Object.keys(params).forEach(function(key){url += "&" + key + "=" + params[key];});
23+
24+
fetch(url)
25+
.then(function(response){return response.json();})
26+
.then(function(response) {console.log(response);})
27+
.catch(function(error){console.log(error);});

javascript/stash_image_info.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
stash_image_info.js
3+
4+
MediaWiki API Demos
5+
Demo of `Stashimageinfo` module: Return information for a stashed file.
6+
7+
MIT license
8+
*/
9+
10+
var request = require('request').defaults({jar: true}),
11+
url = "https://test.wikipedia.org/w/api.php";
12+
13+
// Step 1: GET Request to fetch login token
14+
function getLoginToken() {
15+
var params_0 = {
16+
action: "query",
17+
meta: "tokens",
18+
type: "login",
19+
format: "json"
20+
};
21+
22+
request.get({ url: url, qs: params_0 }, function (error, res, body) {
23+
if (error) {
24+
return;
25+
}
26+
var data = JSON.parse(body);
27+
loginRequest(data.query.tokens.logintoken);
28+
});
29+
}
30+
31+
// Step 2: POST Request to log in.
32+
// Use of main account for login is not
33+
// supported. Obtain credentials via Special:BotPasswords
34+
// (https://www.mediawiki.org/wiki/Special:BotPasswords) for lgname & lgpassword
35+
function loginRequest(login_token) {
36+
var params_1 = {
37+
action: "login",
38+
lgname: "bot_username",
39+
lgpassword: "bot_password",
40+
lgtoken: login_token,
41+
format: "json"
42+
};
43+
44+
request.post({ url: url, form: params_1 }, function (error, res, body) {
45+
if (error) {
46+
return;
47+
}
48+
stashimageinfo();
49+
});
50+
}
51+
52+
// Step 3: Return information for a stashed file.
53+
function stashimageinfo() {
54+
var params_3 = {
55+
action: "query",
56+
format: "json",
57+
prop: "stashimageinfo",
58+
siifilekey: "124sd34rsdf567"
59+
};
60+
61+
request.post({ url: url, form: params_3 }, function (error, res, body) {
62+
if (error) {
63+
return;
64+
}
65+
console.log(body);
66+
});
67+
}
68+
69+
// Start From Step 1
70+
getLoginToken();

javascript/templates.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//This file is autogenerated. See modules.json and autogenerator.py for details
2+
3+
/*
4+
templates.js
5+
6+
MediaWiki API Demos
7+
Demo of `Templates` module: Get a list of templates used on a page
8+
9+
MIT License
10+
*/
11+
12+
var url = "https://en.wikipedia.org/w/api.php";
13+
14+
var params = {
15+
action: "query",
16+
titles: "Albert Einstein",
17+
prop: "templates",
18+
format: "json"
19+
};
20+
21+
url = url + "?origin=*";
22+
Object.keys(params).forEach(function(key){url += "&" + key + "=" + params[key];});
23+
24+
fetch(url)
25+
.then(function(response){return response.json();})
26+
.then(function(response) {console.log(response);})
27+
.catch(function(error){console.log(error);});

0 commit comments

Comments
 (0)