1 USING: help.markup help.syntax mediawiki.api ;
4 ARTICLE: "mediawiki.api" "MediaWiki API"
5 { $url "https://www.mediawiki.org/wiki/API:Main_page" }
6 { $heading "Configuration" }
7 "Set " { $snippet "endpoint" } " to the API entry point. An"
8 "example for Wikimedia wikis:"
10 "USING: formatting mediawiki.api namespaces ;"
11 ": wikimedia-url ( lang family -- str )"
12 " \"https://%s.%s.org/w/api.php\" sprintf ;"
13 "\"en\" \"wikipedia\" wikimedia-url endpoint set-global" }
15 "For Wikimedia wikis, also provide contact information in " {
16 $snippet "contact" } " so that wiki operators can contact you in"
17 "case of malfunction, including username or email, and possibly"
20 "USING: mediawiki.api namespaces ;"
21 "\"BotName/Task1 (email@address.tld)\" contact set-global" }
23 "OAuth login with an owner-only consumer:"
25 "USING: mediawiki.api namespaces ;"
30 "<oauth-login> oauth-login set-global" }
32 "Login with username and password:"
34 "USING: mediawiki.api namespaces ;"
37 "<password-login> password-login set-global" }
39 "If both login methods are given, OAuth is preferred. If none"
40 "are given, you're not logged in."
42 "If you use several wikis simultaneously, you might want to save"
43 "your " { $snippet "cookies" } " (if you use the password login"
44 "method) and your " { $snippet "csrf-token" } ". You also should"
45 "invalidate your csrf-token before using an action that requires"
46 "a csrf token in a wiki for the first time:"
48 "USING: mediawiki.api namespaces ;"
49 "f csrf-token set-global" }
53 { $subsections api-call }
55 { $subsections query page-content }
56 "Actions that require a csrf token:"
57 { $subsections token-call edit-page move-page email }
58 "Sometimes you need to loop over a non-query API call:"
59 { $subsection call-continue } ;
63 { "params" "an assoc of API parameters" }
64 { "assoc" "a parsed JSON result" } }
66 "Makes a call to a MediaWiki API. Retries on certain error"
67 "conditions. Uses a maxlag value of 5 and, in the case of"
68 "replication lag, pauses for the amount of time specified by the"
69 "API. Pauses 10 minutes on non-200 status codes and 5 minutes"
70 "when the database is set to readonly. Prints debug information"
71 "on non-200 status codes and JSON parse failure. Prints API"
72 "warnings and errors." }
75 "USING: locals mediawiki.api ;"
77 " { \"meta\" \"tokens\" }"
78 " { \"type\" \"watch\" }"
79 "} query \"watchtoken\" of"
81 " { \"action\" \"watch\" }"
83 " \"Volkswagen Beetle\""
84 " \"Factor (programming language)\""
86 " { \"token\" token }"
87 "} api-call ] call drop" } } ;
91 { "params" "an assoc of query parameters" }
92 { "seq" "a stripped parsed JSON result" } }
94 "Makes an API query and extracts the query result from the"
97 "The following two code snippets are equivalent:"
100 " { \"action\" \"query\" }"
101 " { \"meta\" \"userinfo\" }"
103 "\"query\" \"userinfo\" \"name\" [ of ] tri@" }
104 { $code " { { \"meta\" \"userinfo\" } } query \"name\" of" }
106 "The following two code snippets are also equivalent:"
109 " { \"action\" \"query\" }"
110 " { \"list\" \"watchlistraw\" }"
112 "\"watchlistraw\" of" }
113 { $code " { { \"list\" \"watchlistraw\" } } query" } } ;
117 { "title" "a page title" }
118 { "content" "a page content" } }
120 "Gets the page content of the most current revision." } ;
124 { "params" "an assoc of API call parameters" }
125 { "assoc" "a parsed JSON result" } }
127 "Constructs API call with csrf token, fetches token if necessary." }
128 { $notes "This word is used in the implementation of "
129 { $links edit-page move-page } " and " { $link email } "." } ;
133 { "title" "a page title" }
134 { "text" "a page content" }
135 { "summary" "an edit summary" }
136 { "params" "an assoc of additional parameters (section,
138 { "assoc" "a parsed JSON result" } }
140 "Changes the content of a page. In conjunction with "
141 { $link page-content } ", it uses the revision timstamp and the"
142 "timestamp of when you begin editing for edit-conflict"
145 "You can disable the bot flag by setting " { $snippet "botflag" }
146 " to " { $link f } ":"
147 { $code "f botflag set-global" } } ;
151 { "from" "a page source" }
152 { "to" "a page destination" }
153 { "reason" "a summary" }
154 { "params" "an assoc of additional parameters" }
155 { "assoc" "a parsed JSON result" } }
157 "Moves " { $snippet "from" } " to " { $snippet "to" } ". Also moves"
162 { "target" "a username" }
163 { "subject" "a subject line" }
164 { "text" "a message body" }
165 { "assoc" "a parsed JSON result" } }
166 { $description "Sends an email to " { $snippet "target" } "." } ;
170 { "params" "an assoc of API call parameters" }
171 { "quot1" { $quotation ( params -- obj assoc ) } }
172 { "quot2" { $quotation ( ... -- ... ) } }
173 { "seq" { "a sequence" } } }
174 { $description "Calls the API until all input is consumed." }
175 { $notes "This word is used in the implementation of "
176 { $link query } "." }
179 "USING: mediawiki.api assocs kernel ;"
181 " { \"meta\" \"tokens\" }"
182 " { \"type\" \"watch\" }"
183 "} query \"watchtoken\" of "
184 "\"Category:Concatenative programming languages\""
185 "\"Category:Stack-oriented programming languages\""
187 " { \"action\" \"watch\" }"
188 " { \"generator\" \"categorymembers\" }"
189 " { \"gcmtitle\" cat }"
190 " { \"gcmnamespace\" 0 }"
191 " { \"gcmtype\" \"page\" }"
192 " { \"gcmlimit\" 50 }"
193 " { \"token\" token }"
194 "} [ api-call dup ] [ ] call-continue drop ] bi-curry@ bi" } } ;
196 ABOUT: "mediawiki.api"