User talk:MER-C/Wiki.java
From Wikipedia, the free encyclopedia
Contents |
[edit] Changelog
Version | Diff | Comment |
---|---|---|
0.01 | diff | Initial. |
0.02 | diff | Add default constructor, getCategoryMembers(String name). |
0.03 | diff | Added namespace support. |
0.04 | diff | Moved to use the mediawiki api. Added category intersection. License -> GPL 3. |
0.05 | diff | Added logging, sketchy user support. Worked around silly api limitation of 500/5000 elements returned per query. |
0.06 | diff | Fields for the various mediawiki logs. Added spamsearch, getDomain() (should have done this earlier). |
0.07 | diff | Optimized for bandwidth, add userRights() caching. Debug. |
0.08 | diff | Log support. Added a few utility methods. |
0.09 | diff | Add listPages(), editing throttle, better cookies. Now uses GZIP compression. Various other fixes. |
0.10 | diff | Add persistence, getImage(), whatLinksHere(), imageUsage(), getCurrentDatabaseLag(), getRenderedText(), getTalkPage(), getProtectionLevel(), pageExists(). We now check whether a page is protected before editing it. Various fixes, including ones below. |
0.11 | diff | Add upload(), parseList(), hasNewMessages(), assertions, maxlag. Rewrite login(), intersection(). |
0.12 | diff | Add ip block list, transclusions. Exception overhaul. Various optimizations. |
0.13 | diff | Add random page, thumbnails, ability to parse arbitrary wikitext. |
0.14 | diff | Added arbitrary scriptpath support, search, statistics, some other stuff. |
0.15 | diff | Short/long pages, bug fixes. |
[edit] Special page equivalents
See Special:Specialpages for a list of special pages. The text on special pages may be edited by editing the appropriate system message.
Special page | Equivalent code |
---|---|
Special:Allmessages | listPages("MediaWiki:", Wiki.FULL_PROTECTION, Wiki.ALL_NAMESPACES) |
Special:Allpages | listPages() |
Special:Ipblocklist | getIPBlockList() |
Special:Linksearch | spamsearch() |
Special:Listusers | allUsers() |
Special:Log | getLogEntries() |
Special:Longpages | longPages() |
Special:Mypage | String title = "User:" + wiki.getCurrentUser().getUsername(); |
Special:Mytalk | String title = "User talk:" + wiki.getCurrentUser().getUsername(); |
Special:Prefixindex | listPages() |
Special:Protectedpages | listPages() |
Special:Random | random() |
Special:Search | search() |
Special:Shortpages | shortPages() |
Special:Statistics | getSiteStatistics() |
Special:Upload | upload() |
Special:Userlogin | login() |
Special:Userlogout | logoutServerSide() |
Special:Whatlinkshere | whatLinksHere() |
[edit] Two Errors
Hello, There are two little Errors in your Code:
First:
In the method "getPageText(String title)" the row
text.append(line);
should be
text.append(line + "\n");
second:
the method "login" doesn't work at the german Wikipedia, the Bot log in correctly, but the Function returns false, because in the German Login-page the text "Login successful" doesn't exist.
--88.72.43.131 11:05, 14 November 2007 (UTC) I hope you can understand me. I know, my english isn't very good ;)
- Fixed both, but it would be some time before they are live - the todo list for 0.10 is quite long. (The fix for the second one is to replace "Login successful" with "wgUserName = \"" + username + "\"", if you can't wait). MER-C 05:50, 16 November 2007 (UTC)
[edit] getPageText() can use API
public String getPageText(String title) throws IOException { // pitfall check if (namespace(title) < 0) throw new UnsupportedOperationException("Cannot retrieve Special: or Media: pages!"); // go for it String URL = query + "prop=revisions&rvprop=content&titles="+URLEncoder.encode(title, "UTF-8"); logurl(URL, "getPageText"); checkLag("getPageText"); URLConnection connection = new URL(URL).openConnection(); setCookies(connection, cookies); connection.connect(); BufferedReader in = new BufferedReader(new InputStreamReader(new GZIPInputStream(connection.getInputStream()), "UTF-8")); String result = ""; String content = ""; // get the text String line = ""; while ((line = in.readLine()) != null) result += line+"\n"; if (result.indexOf("missing=\"\"") != -1) content = "(not yet written)"; else if (result.indexOf("invalid=\"\"") != -1) content = "(Bad title)"; else if (result.indexOf("<rev />") != -1) content = "(empty)"; else content = result.substring(result.indexOf("<rev>")+5,result.indexOf("</rev>")); in.close(); log(Level.INFO, "Successfully retrieved text of " + title, "getPageText"); return decode(content); }
[edit] using rights and not groups for "apihighlimits"
Use rights to chance highlimit, not group ('BOT' or 'ADMIN' are groups see 'query("meta=userinfo&uiprop=rights|groups")', but you call it right ('User.userRights()')
int limit = 500; String result = query("meta=userinfo&uiprop=rights") if (result.indexOf("apihighlimits") != -1) limit = 5000; //500 per default