public class Wiki extends Object implements Serializable
Extended documentation is available here. All wikilinks are relative to the English Wikipedia and all timestamps are in your wiki's time zone.
Please file bug reports here (fast) or at the Google code bug tracker (slow).Modifier and Type | Class and Description |
---|---|
static class |
Wiki.Gender
The list of options the user can specify for his/her gender.
|
class |
Wiki.LogEntry
A wrapper class for an entry in a wiki log, which represents an action
performed on the wiki.
|
class |
Wiki.Revision
Represents a contribution and/or a revision to a page.
|
class |
Wiki.User
Subclass for wiki users.
|
Modifier and Type | Field and Description |
---|---|
static String |
ALL_LOGS
Denotes all logs.
|
static int |
ALL_NAMESPACES
Denotes all namespaces.
|
protected String |
apiUrl |
static int |
ASSERT_BOT
Assert that we have a bot flag (i.e.
|
static int |
ASSERT_NO_MESSAGES
Assert that we have no new messages.
|
static int |
ASSERT_NONE
Use no assertions (i.e.
|
protected String |
base |
static String |
BLOCK_LOG
Denotes the block log.
|
static int |
CATEGORY_NAMESPACE
Denotes the namespace for category description pages.
|
static int |
CATEGORY_TALK_NAMESPACE
Denotes the namespace for talk pages regarding categories.
|
static long |
CURRENT_REVISION
In Revision.diff(), denotes the current revision.
|
static String |
DELETION_LOG
Denotes the deletion log.
|
static int |
FILE_NAMESPACE
Denotes the namespace for image/file description pages.
|
static int |
FILE_TALK_NAMESPACE
Denotes talk pages for image description pages.
|
static String |
FULL_PROTECTION
Denotes full protection (i.e.
|
static int |
HELP_NAMESPACE
Denotes the namespace for help pages, given the prefix "Help:".
|
static int |
HELP_TALK_NAMESPACE
Denotes the namespace for talk pages regarding help pages, given the
prefix "Help talk:".
|
static int |
HIDE_ANON
In queries against the recent changes table, this would mean we don't
fetch anonymous edits.
|
static int |
HIDE_BOT
In queries against the recent changes table, this would mean we don't
fetch edits made by bots.
|
static int |
HIDE_MINOR
In queries against the recent changes table, this would mean we don't
fetch minor edits.
|
static int |
HIDE_PATROLLED
In queries against the recent changes table, this would mean we don't
fetch patrolled edits.
|
static int |
HIDE_SELF
In queries against the recent changes table, this would mean we don't
fetch by the logged in user.
|
static int |
IMAGE_NAMESPACE
Deprecated.
use FILE_NAMESPACE
|
static int |
IMAGE_TALK_NAMESPACE
Deprecated.
use FILE_TALK_NAMESPACE
|
static String |
IMPORT_LOG
Denotes the page importation log.
|
protected static Logger |
logger |
static int |
MAIN_NAMESPACE
Denotes the main namespace, with no prefix.
|
static int |
MEDIA_NAMESPACE
Denotes the namespace of images and media, such that there is no
description page.
|
static int |
MEDIAWIKI_NAMESPACE
Denotes the namespace for (wiki) system messages, given the prefix
"MediaWiki:".
|
static int |
MEDIAWIKI_TALK_NAMESPACE
Denotes the namespace for talk pages relating to system messages, given
the prefix "MediaWiki talk:".
|
static String |
MOVE_LOG
Denotes the move log.
|
static long |
NEXT_REVISION
In Revision.diff(), denotes the next revision.
|
static String |
NO_PROTECTION
Denotes a non-protected page.
|
static String |
PATROL_LOG
Denotes the edit patrol log.
|
static long |
PREVIOUS_REVISION
In Revision.diff(), denotes the previous revision.
|
static int |
PROJECT_NAMESPACE
Denotes the namespace for pages relating to the project, with prefix
"Project:".
|
static int |
PROJECT_TALK_NAMESPACE
Denotes the namespace for talk pages relating to project pages, with
prefix "Project talk:".
|
static String |
PROTECTION_LOG
Denotes the protection log.
|
protected String |
query |
protected String |
scriptPath |
static String |
SEMI_PROTECTION
Denotes semi-protection (i.e.
|
static int |
SPECIAL_NAMESPACE
Denotes the namespace of pages with the "Special:" prefix.
|
static int |
TALK_NAMESPACE
Denotes the namespace for talk pages relating to the main namespace,
denoted by the prefix "Talk:".
|
static int |
TEMPLATE_NAMESPACE
Denotes the namespace for templates, given the prefix "Template:".
|
static int |
TEMPLATE_TALK_NAMESPACE
Denotes the namespace for talk pages regarding templates, given the
prefix "Template talk:".
|
static String |
UPLOAD_LOG
Denotes the upload log.
|
static String |
USER_CREATION_LOG
Denotes the user creation log.
|
static int |
USER_NAMESPACE
Denotes the namespace for user pages, given the prefix "User:".
|
static String |
USER_RENAME_LOG
Denotes the user renaming log.
|
static String |
USER_RIGHTS_LOG
Denotes the user rights log.
|
static int |
USER_TALK_NAMESPACE
Denotes the namespace for user talk pages, given the prefix "User talk:".
|
Constructor and Description |
---|
Wiki()
Creates a new connection to the English Wikipedia.
|
Wiki(String domain)
Creates a new connection to a wiki.
|
Wiki(String domain,
String scriptPath)
Creates a new connection to a wiki with $wgScriptpath set to
scriptPath.
|
Modifier and Type | Method and Description |
---|---|
String[] |
allUsers(String start,
int number)
Gets the specified number of users (as a String) starting at the given
string, in alphabetical order.
|
String[] |
allUsers(String start,
int number,
String prefix)
Gets the specified number of users (as a String) starting at the given
string, in alphabetical order.
|
String[] |
allUsersWithPrefix(String prefix)
Returns all usernames with the given prefix.
|
protected String |
calendarToTimestamp(Calendar c)
Turns a calendar into a timestamp of the format yyyymmddhhmmss.
|
protected void |
checkErrors(String line,
String caller)
Checks for errors from standard read/write requests.
|
protected boolean |
checkRights(HashMap<String,Object> pageinfo,
String action)
Checks whether the currently logged on user has sufficient rights to
edit/move a protected page.
|
protected void |
constructNamespaceString(StringBuilder sb,
String id,
int... namespaces)
Convenience method for converting a namespace list into String form.
|
Wiki.Revision[] |
contribs(String user,
int... ns)
Gets the contributions of a user in a particular namespace.
|
Wiki.Revision[] |
contribs(String user,
String prefix,
Calendar end,
Calendar start,
int... ns)
Gets the contributions for a user, an IP address or a range of IP
addresses.
|
protected String |
convertTimestamp(String timestamp)
Converts a timestamp of the form used by the API (yyyy-mm-ddThh:mm:ssZ)
to the form yyyymmddhhmmss, which can be fed into
timestampToCalendar().
|
protected String |
decode(String in)
Strips entity references like " from the supplied string.
|
void |
delete(String title,
String reason)
Deletes a page.
|
void |
edit(String title,
String text,
String summary)
Edits a page by setting its text to the supplied value.
|
void |
edit(String title,
String text,
String summary,
boolean minor,
boolean bot,
int section,
Calendar basetime)
Edits a page by setting its text to the supplied value.
|
void |
edit(String title,
String text,
String summary,
Calendar basetime)
Edits a page by setting its text to the supplied value.
|
void |
edit(String title,
String text,
String summary,
int section)
Edits a page by setting its text to the supplied value.
|
void |
edit(String title,
String text,
String summary,
int section,
Calendar basetime)
Edits a page by setting its text to the supplied value.
|
void |
emailUser(Wiki.User user,
String message,
String subject,
boolean emailme)
Sends an email message to a user in a similar manner to
[[Special:Emailuser]].
|
boolean |
equals(Object obj)
Determines whether this wiki is equal to another object.
|
boolean[] |
exists(String... titles)
Determines whether a series of pages exist.
|
String |
export(String title)
Exports the current revision of this page.
|
protected String |
fetch(String url,
String caller)
A generic URL content fetcher.
|
int |
getAssertionMode()
Gets the assertion mode.
|
String[] |
getCategories(String title)
Gets the list of categories a particular page is in.
|
String[] |
getCategoryMembers(String name,
boolean subcat,
int... ns)
Gets the members of a category.
|
String[] |
getCategoryMembers(String name,
int... ns)
Gets the members of a category.
|
int |
getCurrentDatabaseLag()
Determines the current database replication lag.
|
Wiki.User |
getCurrentUser()
Gets the user we are currently logged in as.
|
String |
getDomain()
Gets the domain of the wiki, as supplied on construction.
|
String[] |
getDuplicates(String file)
Gets duplicates of this file.
|
HashMap<String,Object> |
getFileMetadata(String file)
Gets the file metadata for a file.
|
Wiki.Revision |
getFirstRevision(String title)
Gets the first revision of a page, or null if the page does not exist.
|
byte[] |
getImage(String title)
Fetches an image file and returns the image data in a byte[].
|
byte[] |
getImage(String title,
int width,
int height)
Fetches a thumbnail of an image file and returns the image data in a
byte[].
|
Wiki.LogEntry[] |
getImageHistory(String title)
Returns the upload history of an image.
|
String[] |
getImagesOnPage(String title)
Gets the list of images used on a particular page.
|
String[][] |
getInterWikiBacklinks(String prefix)
Fetches all pages that use interwiki links to the specified wiki and the
page on that wiki that is linked to.
|
String[][] |
getInterWikiBacklinks(String prefix,
String title)
Fetches all pages that use interwiki links with a certain prefix
and title.
|
HashMap<String,String> |
getInterWikiLinks(String title)
Gets the list of interwiki links a particular page has.
|
Wiki.LogEntry[] |
getIPBlockList(Calendar start,
Calendar end)
Lists currently operating blocks that were made in the specified
interval.
|
Wiki.LogEntry[] |
getIPBlockList(String user)
Looks up a particular user in the IP block list, i.e.
|
protected Wiki.LogEntry[] |
getIPBlockList(String user,
Calendar start,
Calendar end)
Fetches part of the list of currently operational blocks.
|
String[] |
getLinksOnPage(String title)
Gets the list of links used on a particular page.
|
Wiki.LogEntry[] |
getLogEntries(Calendar start,
Calendar end)
Gets all log entries that occurred between the specified dates.
|
Wiki.LogEntry[] |
getLogEntries(Calendar start,
Calendar end,
int amount,
String log,
String action,
Wiki.User user,
String target,
int namespace)
Gets the specified amount of log entries between the given times by the
given user on the given target.
|
Wiki.LogEntry[] |
getLogEntries(int amount)
Gets the most recent set of log entries up to the given amount.
|
Wiki.LogEntry[] |
getLogEntries(int amount,
String type,
String action)
Gets the last how ever many log entries in the specified log.
|
Wiki.LogEntry[] |
getLogEntries(String target)
Gets the log entries representing actions that were performed on a
specific target.
|
Wiki.LogEntry[] |
getLogEntries(Wiki.User user)
Gets log entries for a specific user.
|
int |
getMaxLag()
Gets the maxlag parameter.
|
HashMap<String,Integer> |
getNamespaces()
Gets the namespaces used by this wiki.
|
byte[] |
getOldImage(Wiki.LogEntry entry)
Gets an old image revision and returns the image data in a
byte[].
|
Wiki.Revision[] |
getPageHistory(String title)
Gets the entire revision history of a page.
|
Wiki.Revision[] |
getPageHistory(String title,
Calendar start,
Calendar end)
Gets the revision history of a page between two dates.
|
HashMap |
getPageInfo(String page)
Gets miscellaneous page info.
|
HashMap[] |
getPageInfo(String[] pages)
Gets miscellaneous page info.
|
String |
getPageText(String title)
Gets the raw wikicode for a page.
|
String[] |
getRawWatchlist()
Fetches the list of titles on the currently logged in user's watchlist.
|
String[] |
getRawWatchlist(boolean cache)
Fetches the list of titles on the currently logged in user's watchlist.
|
String |
getRenderedText(String title)
Gets the contents of a page, rendered in HTML (as opposed to wikitext).
|
Wiki.Revision |
getRevision(long oldid)
Gets a revision based on a given oldid.
|
String |
getScriptPath()
Detects the $wgScriptpath wiki variable and sets the bot framework up to
use it.
|
LinkedHashMap<String,String> |
getSectionMap(String page)
Gets the list of sections on a particular page.
|
String |
getSectionText(String title,
int number)
Gets the text of a specific section.
|
HashMap<String,Integer> |
getSiteStatistics()
Fetches some site statistics, namely the number of articles, pages,
files, edits, users and admins.
|
int |
getStatusCheckInterval()
Gets the number of actions (edit, move, block, delete, etc) between
status checks.
|
String |
getTalkPage(String title)
Returns the corresponding talk page to this page.
|
String[] |
getTemplates(String title,
int... ns)
Gets the list of templates used on a particular page that are in a
particular namespace(s).
|
int |
getThrottle()
Gets the editing throttle.
|
Wiki.Revision |
getTopRevision(String title)
Gets the most recent revision of a page, or null if the page does not
exist.
|
Wiki.LogEntry[] |
getUploads(Wiki.User user)
Gets the uploads of a user.
|
Wiki.LogEntry[] |
getUploads(Wiki.User user,
Calendar start,
Calendar end)
Gets the uploads of a user between the specified times.
|
Wiki.User |
getUser(String username)
Gets the user with the given username.
|
String |
getUserAgent()
Gets the user agent HTTP header to be used for requests.
|
int |
hashCode()
Returns a hash code of this object.
|
boolean |
hasNewMessages()
Determines whether the current user has new messages.
|
String[] |
imageUsage(String image,
int... ns)
Returns a list of pages in the specified namespaces which use the
specified image.
|
protected void |
initVars()
Override/edit this if you need to change the API and human interface url
configuration of the wiki.
|
static String[] |
intersection(String[] a,
String[] b)
Determines the intersection of two lists of pages a and b.
|
boolean |
isMarkBot()
Are edits are marked as bot by default?
|
boolean |
isMarkMinor()
Are edits are marked as minor by default?
|
boolean |
isResolvingRedirects()
Checks whether API action=query dependencies automatically resolve
redirects (default = false).
|
boolean |
isUsingCompressedRequests()
Checks whether we are using GZip compression for GET requests.
|
boolean |
isWatched(String title)
Determines whether a page is watched.
|
ArrayList[] |
linksearch(String pattern)
Searches the wiki for external links.
|
ArrayList[] |
linksearch(String pattern,
String protocol,
int... ns)
Searches the wiki for external links.
|
String[] |
listPages(String prefix,
HashMap<String,Object> protectionstate,
int namespace)
Lists pages with titles containing a certain prefix with a certain
protection state and in a certain namespace.
|
String[] |
listPages(String prefix,
HashMap<String,Object> protectionstate,
int namespace,
int minimum,
int maximum)
Lists pages with titles containing a certain prefix with a certain
protection state and in a certain namespace.
|
protected void |
log(Level level,
String text,
String method)
Logs a successful result.
|
void |
login(String username,
char[] password)
Logs in to the wiki.
|
void |
login(String username,
String password) |
void |
logout()
Logs out of the wiki.
|
void |
logoutServerSide()
Logs out of the wiki and destroys the session on the server.
|
protected void |
logurl(String url,
String method)
Logs a url fetch.
|
String[] |
longPages(int cutoff)
List pages above a certain size in the main namespace.
|
String[] |
longPages(int cutoff,
int namespace)
List pages above a certain size in any namespace.
|
Calendar |
makeCalendar()
Creates a Calendar object with the current time.
|
void |
move(String title,
String newTitle,
String reason)
Moves a page.
|
void |
move(String title,
String newTitle,
String reason,
boolean noredirect,
boolean movetalk,
boolean movesubpages)
Moves a page.
|
protected String |
multipartPost(String url,
Map<String,?> params,
String caller)
Performs a multi-part HTTP POST.
|
int |
namespace(String title)
Returns the namespace a set of pages is in.
|
int[] |
namespace(String[] titles)
Returns the namespace a set of pages is in.
|
String |
namespaceIdentifier(int namespace)
For a given namespace denoted as an integer, fetch the corresponding
identification string e.g.
|
Wiki.Revision[] |
newPages(int amount)
Fetches the amount most recently created pages in the main
namespace.
|
Wiki.Revision[] |
newPages(int amount,
int rcoptions)
Fetches the amount most recently created pages in the main
namespace subject to the specified constraints.
|
Wiki.Revision[] |
newPages(int amount,
int rcoptions,
int... ns)
Fetches the amount most recently created pages in the specified
namespace, subject to the specified constraints.
|
void |
newSection(String title,
String subject,
String text,
boolean minor,
boolean bot)
Creates a new section on the specified page.
|
String |
normalize(String s)
Convenience method for normalizing MediaWiki titles.
|
String |
parse(String markup)
Renders the specified wiki markup by passing it to the MediaWiki parser
through the API.
|
protected String |
parseAndCleanup(String in)
Same as parse(), but also strips out unwanted crap.
|
protected Wiki.LogEntry |
parseLogEntry(String xml)
Parses xml generated by getLogEntries(),
getImageHistory() and getIPBlockList() into LogEntry
objects.
|
protected Wiki.Revision |
parseRevision(String xml,
String title)
Parses stuff of the form title="L.
|
protected void |
populateNamespaceCache()
Populates the namespace cache.
|
protected String |
post(String url,
String text,
String caller)
Does a text-only HTTP POST.
|
String[] |
prefixIndex(String prefix)
Lists pages that start with a given prefix.
|
void |
prepend(String title,
String stuff,
String summary,
boolean minor,
boolean bot)
Prepends something to the given page.
|
void |
protect(String page,
HashMap<String,Object> protectionstate)
Protects a page.
|
void |
purge(boolean links,
String... titles)
Purges the server-side cache for various pages.
|
String[] |
queryPage(String page)
Fetches data from one of a set of miscellaneous special pages.
|
String |
random()
Fetches a random page in the main namespace.
|
String |
random(int... ns)
Fetches a random page in the specified namespace.
|
Wiki.Revision[] |
rangeContribs(String range)
Deprecated.
doesn't support IPv6, and I am way too lazy to make it do so
|
Wiki.Revision[] |
recentChanges(int amount)
Fetches the amount most recent changes in the main namespace.
|
Wiki.Revision[] |
recentChanges(int amount,
int... ns)
Fetches the amount most recent changes in the specified
namespace.
|
protected Wiki.Revision[] |
recentChanges(int amount,
int rcoptions,
boolean newpages,
int... ns)
Fetches the amount most recent changes in the specified
namespace subject to the specified constraints.
|
Wiki.Revision[] |
recentChanges(int amount,
int rcoptions,
int... ns)
Fetches the amount most recent changes in the specified
namespace subject to the specified constraints.
|
static String[] |
relativeComplement(String[] a,
String[] b)
Determines the list of articles that are in a but not b, i.e.
|
void |
rollback(Wiki.Revision revision)
Reverts a series of edits on the same page by the same user quickly
provided that they are the most recent revisions on that page.
|
void |
rollback(Wiki.Revision revision,
boolean bot,
String reason)
Reverts a series of edits on the same page by the same user quickly
provided that they are the most recent revisions on that page.
|
String[][] |
search(String search,
int... namespaces)
Performs a full text search of the wiki.
|
void |
setAssertionMode(int mode)
Sets the assertion mode.
|
protected void |
setCookies(URLConnection u)
Sets cookies to an unconnected URLConnection and enables gzip compression
of returned text.
|
void |
setLogLevel(Level level)
Deprecated.
logger is now protected, can call setLevel there
|
void |
setMarkBot(boolean markbot)
Sets whether edits are marked as bot by default (may be overridden
specifically by edit()).
|
void |
setMarkMinor(boolean minor)
Sets whether edits are marked as minor by default (may be overridden
specifically by edit()).
|
void |
setMaxLag(int lag)
Sets the maxlag parameter.
|
void |
setResolveRedirects(boolean b)
Sets whether API action=query dependencies automatically resolve
redirects (default = false).
|
void |
setStatusCheckInterval(int interval)
Sets the number of actions (edit, move, block, delete, etc) between
status checks.
|
void |
setThrottle(int throttle)
Sets the editing throttle.
|
void |
setUserAgent(String useragent)
Sets the user agent HTTP header to be used for requests.
|
void |
setUsingCompressedRequests(boolean zipped)
Enables/disables GZip compression for GET requests.
|
String[] |
shortPages(int cutoff)
List pages below a certain size in the main namespace.
|
String[] |
shortPages(int cutoff,
int namespace)
List pages below a certain size in any namespace.
|
protected void |
statusCheck()
Performs a status check, including assertions.
|
protected Calendar |
timestampToCalendar(String timestamp)
Turns a timestamp of the format yyyymmddhhmmss into a Calendar object.
|
String |
toString()
Returns a string representation of this Wiki.
|
void |
undo(Wiki.Revision rev,
Wiki.Revision to,
String reason,
boolean minor,
boolean bot)
Undoes revisions, equivalent to the "undo" button in the GUI page
history.
|
void |
unprotect(String page)
Completely unprotects a page.
|
void |
unwatch(String... titles)
Removes pages from the watchlist.
|
void |
upload(File file,
String filename,
String contents,
String reason)
Uploads an image.
|
boolean |
userExists(String username)
Determines whether a specific user exists.
|
String |
version()
Gets the version of MediaWiki this wiki runs e.g.
|
void |
watch(String... titles)
Adds a page to the watchlist.
|
protected void |
watchInternal(boolean unwatch,
String... titles)
Internal method for interfacing with the watchlist, since the API URLs
for (un)watching are very similar.
|
Wiki.Revision[] |
watchlist()
Fetches the most recent changes to pages on your watchlist.
|
Wiki.Revision[] |
watchlist(boolean allrev,
int... ns)
Fetches recent changes to pages on your watchlist.
|
String[] |
whatLinksHere(String title,
boolean redirects,
int... ns)
Returns a list of all pages linking to this page within the specified
namespaces.
|
String[] |
whatLinksHere(String title,
int... ns)
Returns a list of all pages linking to this page.
|
String[] |
whatTranscludesHere(String title,
int... ns)
Returns a list of all pages transcluding to a page within the specified
namespaces.
|
public static final int MEDIA_NAMESPACE
FILE_NAMESPACE
,
Constant Field Valuespublic static final int SPECIAL_NAMESPACE
public static final int MAIN_NAMESPACE
public static final int TALK_NAMESPACE
public static final int USER_NAMESPACE
public static final int USER_TALK_NAMESPACE
public static final int PROJECT_NAMESPACE
public static final int PROJECT_TALK_NAMESPACE
public static final int FILE_NAMESPACE
MEDIA_NAMESPACE
,
Constant Field Valuespublic static final int FILE_TALK_NAMESPACE
@Deprecated public static final int IMAGE_NAMESPACE
MEDIA_NAMESPACE
,
Constant Field Values@Deprecated public static final int IMAGE_TALK_NAMESPACE
public static final int MEDIAWIKI_NAMESPACE
public static final int MEDIAWIKI_TALK_NAMESPACE
public static final int TEMPLATE_NAMESPACE
public static final int TEMPLATE_TALK_NAMESPACE
public static final int HELP_NAMESPACE
public static final int HELP_TALK_NAMESPACE
public static final int CATEGORY_NAMESPACE
public static final int CATEGORY_TALK_NAMESPACE
public static final int ALL_NAMESPACES
public static final String ALL_LOGS
public static final String USER_CREATION_LOG
public static final String UPLOAD_LOG
public static final String DELETION_LOG
public static final String MOVE_LOG
public static final String BLOCK_LOG
public static final String PROTECTION_LOG
public static final String USER_RIGHTS_LOG
public static final String USER_RENAME_LOG
public static final String IMPORT_LOG
public static final String PATROL_LOG
public static final String NO_PROTECTION
public static final String SEMI_PROTECTION
public static final String FULL_PROTECTION
public static final int ASSERT_NONE
setAssertionMode(int)
,
Constant Field Valuespublic static final int ASSERT_BOT
setAssertionMode(int)
,
Constant Field Valuespublic static final int ASSERT_NO_MESSAGES
setAssertionMode(int)
,
Constant Field Valuespublic static final int HIDE_ANON
public static final int HIDE_BOT
public static final int HIDE_SELF
public static final int HIDE_MINOR
public static final int HIDE_PATROLLED
public static final long NEXT_REVISION
Wiki.Revision.diff(org.wikipedia.Wiki.Revision)
,
Constant Field Valuespublic static final long CURRENT_REVISION
Wiki.Revision.diff(org.wikipedia.Wiki.Revision)
,
Constant Field Valuespublic static final long PREVIOUS_REVISION
Wiki.Revision.diff(org.wikipedia.Wiki.Revision)
,
Constant Field Valuesprotected String query
protected String base
protected String apiUrl
protected String scriptPath
protected static final Logger logger
public Wiki()
public Wiki(String domain)
domain
- the wiki domain name e.g. en.wikipedia.org (defaults to
en.wikipedia.org)protected void initVars()
public String getDomain()
public int getThrottle()
setThrottle(int)
public void setThrottle(int throttle)
throttle
- the new throttle value in millisecondsgetThrottle()
public String getScriptPath() throws IOException
IOException
- if a network error occurspublic void setUserAgent(String useragent)
useragent
- the new user agentpublic String getUserAgent()
public void setUsingCompressedRequests(boolean zipped)
zipped
- whether we use GZip compressionpublic boolean isUsingCompressedRequests()
public boolean isResolvingRedirects()
public void setResolveRedirects(boolean b)
b
- (see above)public void setMarkBot(boolean markbot)
markbot
- (see above)public boolean isMarkBot()
public void setMarkMinor(boolean minor)
minor
- (see above)public boolean isMarkMinor()
public boolean equals(Object obj)
public int hashCode()
public String toString()
public int getMaxLag()
setMaxLag(int)
,
getCurrentDatabaseLag()
public void setMaxLag(int lag)
lag
- the desired maxlag in secondsgetMaxLag()
,
getCurrentDatabaseLag()
public int getAssertionMode()
setAssertionMode(int)
public void setAssertionMode(int mode)
mode
- an assertion modegetAssertionMode()
public int getStatusCheckInterval()
setStatusCheckInterval(int)
public void setStatusCheckInterval(int interval)
interval
- the number of edits between status checksgetStatusCheckInterval()
public void login(String username, char[] password) throws IOException, FailedLoginException
username
- a usernamepassword
- a password (as a char[] due to JPasswordField)FailedLoginException
- if the login failed due to incorrect username and/or passwordIOException
- if a network error occurslogout()
public void login(String username, String password) throws IOException, FailedLoginException
IOException
FailedLoginException
public void logout()
public void logoutServerSide() throws IOException
IOException
- if a network error occurslogin(java.lang.String, char[])
,
logout()
public boolean hasNewMessages() throws IOException
IOException
- if a network error occurspublic int getCurrentDatabaseLag() throws IOException
IOException
- if a network error occurssetMaxLag(int)
,
getMaxLag()
public HashMap<String,Integer> getSiteStatistics() throws IOException
IOException
- if a network error occurspublic String version() throws IOException
IOException
- if a network error occurspublic String parse(String markup) throws IOException
markup
- the markup to parseIOException
- if a network error occursprotected String parseAndCleanup(String in) throws IOException
in
- the string to parseIOException
- if a network error occurspublic String random() throws IOException
IOException
- if a network error occurspublic String random(int... ns) throws IOException
ns
- namespace(s)IOException
- if a network error occurspublic static String[] intersection(String[] a, String[] b)
// find all orphaned and unwikified articles String[] articles = Wiki.intersection(wikipedia.getCategoryMembers( "All orphaned articles", Wiki.MAIN_NAMESPACE), wikipedia .getCategoryMembers("All pages needing to be wikified", Wiki.MAIN_NAMESPACE)); // find all (notable) living people who are related to Barack Obama String[] people = Wiki.intersection( wikipedia.getCategoryMembers("Living people", Wiki.MAIN_NAMESPACE), wikipedia.whatLinksHere("Barack Obama", Wiki.MAIN_NAMESPACE));
a
- a list of pagesb
- another list of pagespublic static String[] relativeComplement(String[] a, String[] b)
// find all Martian crater articles that do not have an infobox String[] articles = Wiki.relativeComplement(wikipedia .getCategoryMembers("Craters on Mars"), wikipedia.whatTranscludesHere( "Template:MarsGeo-Crater", Wiki.MAIN_NAMESPACE)); // find all images without a description that haven't been tagged "no license" String[] images = Wiki.relativeComplement(wikipedia .getCategoryMembers("Images lacking a description"), wikipedia .getCategoryMembers("All images with unknown copyright status"));
a
- a list of pagesb
- another list of pagespublic String getTalkPage(String title) throws IOException
title
- the page titleIllegalArgumentException
- if given title is in a talk namespace or we try to retrieve
the talk page of a Special: or Media: page.IOException
- if a network error occurspublic HashMap getPageInfo(String page) throws IOException
page
- the page to get info forgetPageInfo(String[])
IOException
- if a network error occurspublic HashMap[] getPageInfo(String[] pages) throws IOException
{
"displaytitle" => "iPod" , // the title of the page that is actually displayed (String)
"protection" => NO_PROTECTION , // the // protection state
of the page (HashMap)
"token" => "\+" , // an edit token for the page, must be logged
// in to be non-trivial (String)
"exists" => true , // whether the page exists (Boolean)
"lastpurged" => 20110101000000 , // when the page was last purged (Calendar), null if the
// page does not exist
"lastrevid" => 123456789L , // the revid of the top revision (Long), -1L if the page
// does not exist
"size" => 5000 , // the size of the page (Integer), -1 if the page does
// not exist
"timestamp" => makeCalendar() , // when this method was called (Calendar)
"watchtoken" => "\+" , // watchlist token (String)
"watchers" => 34 // number of watchers (Integer), may be restricted
}
pages
- the pages to get info forIOException
- if a network error occurspublic int namespace(String title) throws IOException
namespace(String[])
.title
- a pageIOException
- if a network error occurspublic int[] namespace(String[] titles) throws IOException
titles
- at least one pageIOException
- if a network error occurs while populating the namespace
cachenamespaceIdentifier(int)
public String namespaceIdentifier(int namespace) throws IOException
namespace
- an integer corresponding to a namespace. If it does not
correspond to a namespace, we assume you mean the main
namespace (i.e. return "").IOException
- if the namespace cache has not been populated, and a network
error occurs when populating itnamespace(java.lang.String)
public HashMap<String,Integer> getNamespaces() throws IOException
IOException
- if a network error occursprotected void populateNamespaceCache() throws IOException
IOException
- if a network error occurs.public boolean[] exists(String... titles) throws IOException
titles
- the titles to checkIOException
- if a network error occurspublic String getPageText(String title) throws IOException
title
- the title of the page.UnsupportedOperationException
- if you try to retrieve the text of a Special: or Media: pageFileNotFoundException
- if the page does not existIOException
- if a network error occursedit(java.lang.String, java.lang.String, java.lang.String)
public String getSectionText(String title, int number) throws IOException
title
- the title of the relevant pagenumber
- the section number of the section to retrieve text forIOException
- if a network error occursIllegalArgumentException
- if the page has less than number sectionspublic String getRenderedText(String title) throws IOException
title
- the title of the pageIOException
- if a network error occurspublic void edit(String title, String text, String summary) throws IOException, LoginException
text
- the text of the pagetitle
- the title of the pagesummary
- the edit summary. See [[Help:Edit summary]]. Summaries longer
than 200 characters are truncated server-side.IOException
- if a network error occursAccountLockedException
- if user is blockedCredentialException
- if page is protected and we can't edit itUnsupportedOperationException
- if you try to edit a Special: or a Media: pageLoginException
getPageText(java.lang.String)
public void edit(String title, String text, String summary, Calendar basetime) throws IOException, LoginException
text
- the text of the pagetitle
- the title of the pagesummary
- the edit summary. See [[Help:Edit summary]]. Summaries longer
than 200 characters are truncated server-side.basetime
- the timestamp of the revision on which text is based,
used to check for edit conflicts. null disables this.IOException
- if a network error occursAccountLockedException
- if user is blockedCredentialException
- if page is protected and we can't edit itUnsupportedOperationException
- if you try to edit a Special: or a Media: pageLoginException
getPageText(java.lang.String)
public void edit(String title, String text, String summary, int section) throws IOException, LoginException
text
- the text of the pagetitle
- the title of the pagesummary
- the edit summary. See [[Help:Edit summary]]. Summaries longer
than 200 characters are truncated server-side.section
- the section to edit. Use -1 to specify a new section and -2 to
disable section editing.IOException
- if a network error occursAccountLockedException
- if user is blockedCredentialException
- if page is protected and we can't edit itUnsupportedOperationException
- if you try to edit a Special: or a Media: pageLoginException
getPageText(java.lang.String)
public void edit(String title, String text, String summary, int section, Calendar basetime) throws IOException, LoginException
text
- the text of the pagetitle
- the title of the pagesummary
- the edit summary. See [[Help:Edit summary]]. Summaries longer
than 200 characters are truncated server-side.section
- the section to edit. Use -1 to specify a new section and -2 to
disable section editing.basetime
- the timestamp of the revision on which text is based,
used to check for edit conflicts. null disables this.IOException
- if a network error occursAccountLockedException
- if user is blockedCredentialException
- if page is protected and we can't edit itUnsupportedOperationException
- if you try to edit a Special: or a Media: pageLoginException
getPageText(java.lang.String)
public void edit(String title, String text, String summary, boolean minor, boolean bot, int section, Calendar basetime) throws IOException, LoginException
text
- the text of the pagetitle
- the title of the pagesummary
- the edit summary. See [[Help:Edit summary]]. Summaries longer
than 200 characters are truncated server-side.minor
- whether the edit should be marked as minor, See [[Help:Minor
edit]].bot
- whether to mark the edit as a bot edit (ignored if one does
not have the necessary permissions)section
- the section to edit. Use -1 to specify a new section and -2 to
disable section editing.basetime
- the timestamp of the revision on which text is based,
used to check for edit conflicts. null disables this.IOException
- if a network error occursAccountLockedException
- if user is blockedCredentialExpiredException
- if cookies have expiredCredentialException
- if page is protected and we can't edit itUnsupportedOperationException
- if you try to edit a Special: or Media: pageLoginException
getPageText(java.lang.String)
public void newSection(String title, String subject, String text, boolean minor, boolean bot) throws IOException, LoginException
title
- the title of the page to editsubject
- the subject of the new sectiontext
- the text of the new sectionminor
- whether the edit should be marked as minor (see [[Help:Minor
edit]])IOException
- if a network error occursAccountLockedException
- if user is blockedCredentialException
- if page is protected and we can't edit itCredentialExpiredException
- if cookies have expiredUnsupportedOperationException
- if you try to edit a Special: or Media: pageLoginException
public void prepend(String title, String stuff, String summary, boolean minor, boolean bot) throws IOException, LoginException
title
- the title of the pagestuff
- what to prepend to the pagesummary
- the edit summary. See [[Help:Edit summary]]. Summaries longer
than 200 characters are truncated server-side.minor
- whether the edit is minorAccountLockedException
- if user is blockedCredentialException
- if page is protected and we can't edit itCredentialExpiredException
- if cookies have expiredUnsupportedOperationException
- if you try to retrieve the text of a Special: page or a
Media: pageIOException
- if a network error occursLoginException
public void delete(String title, String reason) throws IOException, LoginException
title
- the page to deletereason
- the reason for deletionIOException
- if a network error occursCredentialNotFoundException
- if the user lacks the permission to deleteCredentialExpiredException
- if cookies have expiredAccountLockedException
- if user is blockedLoginException
public void purge(boolean links, String... titles) throws IOException
titles
- the titles of the page to purgelinks
- update the links tablesIOException
- if a network error occurspublic String[] getImagesOnPage(String title) throws IOException
title
- a pageIOException
- if a network error occurspublic String[] getCategories(String title) throws IOException
title
- a pageIOException
- if a network error occurspublic String[] getTemplates(String title, int... ns) throws IOException
title
- a pagens
- a list of namespaces to filter by, empty = all namespaces.IOException
- if a network error occurspublic HashMap<String,String> getInterWikiLinks(String title) throws IOException
title
- a pageIOException
- if a network error occurspublic String[] getLinksOnPage(String title) throws IOException
title
- a pageIOException
- if a network error occurspublic LinkedHashMap<String,String> getSectionMap(String page) throws IOException
page
- the page to get sections forIOException
- if a network error occurspublic Wiki.Revision getTopRevision(String title) throws IOException
title
- a pageIOException
- if a network error occurspublic Wiki.Revision getFirstRevision(String title) throws IOException
title
- a pageIOException
- if a network error occurspublic Wiki.Revision[] getPageHistory(String title) throws IOException
title
- a pageIOException
- if a network error occurspublic Wiki.Revision[] getPageHistory(String title, Calendar start, Calendar end) throws IOException
title
- a pagestart
- the date to start enumeration (the latest of the two dates)end
- the date to stop enumeration (the earliest of the two dates)IOException
- if a network error occurspublic void move(String title, String newTitle, String reason) throws IOException, LoginException
title
- the title of the page to movenewTitle
- the new title of the pagereason
- a reason for the moveUnsupportedOperationException
- if the original page is in the Category or Image namespace.
MediaWiki does not support moving of these pages.IOException
- if a network error occursCredentialNotFoundException
- if not logged inCredentialExpiredException
- if cookies have expiredCredentialException
- if page is protected and we can't move itLoginException
public void move(String title, String newTitle, String reason, boolean noredirect, boolean movetalk, boolean movesubpages) throws IOException, LoginException
title
- the title of the page to movenewTitle
- the new title of the pagereason
- a reason for the movenoredirect
- don't leave a redirect behind. You need to be a admin to do
this, otherwise this option is ignored.movesubpages
- move the subpages of this page as well. You need to be an
admin to do this, otherwise this will be ignored.movetalk
- move the talk page as well (if applicable)UnsupportedOperationException
- if the original page is in the Category or Image namespace.
MediaWiki does not support moving of these pages.IOException
- if a network error occursCredentialNotFoundException
- if not logged inCredentialExpiredException
- if cookies have expiredCredentialException
- if page is protected and we can't move itLoginException
public void protect(String page, HashMap<String,Object> protectionstate) throws IOException, CredentialException
{ edit => one of { NO_PROTECTION, SEMI_PROTECTION, FULL_PROTECTION }, // restricts editing editexpiry => Calendar, // expiry time for edit protection, null = indefinite move, moveexpiry, // as above, prevents page moving create, createexpiry, // as above, prevents page creation (no effect on existing pages) upload, uploadexpiry, // as above, prevents uploading of files (FILE_NAMESPACE only) cascade => Boolean // Enables cascading protection (requires edit=FULL_PROTECTION). Default: false. cascadesource => String // souce of cascading protection (here ignored) };
page
- the pageprotectionstate
- (see above). null unprotects.IOException
- if a network error occursCredentialException
- if we cannot protectpublic void unprotect(String page) throws IOException, CredentialException
page
- the page to unprotectIOException
- if a network error occursCredentialException
- if we cannot protectpublic String export(String title) throws IOException
title
- the title of the page to exportIOException
- if a network error occurspublic Wiki.Revision getRevision(long oldid) throws IOException
oldid
- a particular oldidIOException
- if a network error occurspublic void rollback(Wiki.Revision revision) throws IOException, LoginException
revision
- the revision to revert. revision.isTop() must be true
for the rollback to succeedIOException
- if a network error occursCredentialNotFoundException
- if the user is not an adminCredentialExpiredException
- if cookies have expiredAccountLockedException
- if the user is blockedLoginException
public void rollback(Wiki.Revision revision, boolean bot, String reason) throws IOException, LoginException
revision
- the revision to revert. revision.isTop() must be true
for the rollback to succeedbot
- whether to mark this edit and the reverted revisions as bot
edits (ignored if we cannot do this)reason
- (optional) a reason for the rollback. Use "" for the default
([[MediaWiki:Revertpage]]).IOException
- if a network error occursCredentialExpiredException
- if cookies have expiredCredentialNotFoundException
- if the user is not an adminAccountLockedException
- if the user is blockedLoginException
public void undo(Wiki.Revision rev, Wiki.Revision to, String reason, boolean minor, boolean bot) throws IOException, LoginException
wiki.undo(wiki.getRevision(314L), null, reason, false); // undo revision 314 // only wiki.undo(wiki.getRevision(236L), wiki.getRevision(325L), reason, false); // undo // revisions // 236-325This will only work if revision 541 or any subsequent edits do not clash with the change resulting from the undo.
rev
- a revision to undoto
- the most recent in a range of revisions to undo. Set to null
to undo only one revision.reason
- an edit summary (optional). Use "" to get the default
[[MediaWiki:Undo-summary]].minor
- whether this is a minor editbot
- whether this is a bot editIOException
- if a network error occursAccountLockedException
- if user is blockedCredentialExpiredException
- if cookies have expiredCredentialException
- if page is protected and we can't edit itIllegalArgumentException
- if the revisions are not on the same page.LoginException
protected Wiki.Revision parseRevision(String xml, String title)
xml
- the XML to parsetitle
- an optional title parameter if we already know what it is (use
"" if we don't)public byte[] getImage(String title) throws IOException
title
- the title of the image (may contain "File")IOException
- if a network error occurspublic byte[] getImage(String title, int width, int height) throws IOException
title
- the title of the image (may contain "File")width
- the width of the thumbnail (use -1 for actual width)height
- the height of the thumbnail (use -1 for actual height)IOException
- if a network error occurspublic HashMap<String,Object> getFileMetadata(String file) throws IOException
file
- the image to get metadata for (may contain "File")IOException
- if a network error occurspublic String[] getDuplicates(String file) throws IOException
file
- the file for checking duplicates (may contain "File")IOException
- if a network error occurspublic Wiki.LogEntry[] getImageHistory(String title) throws IOException
title
- the title of the image (may contain File)IOException
- if a network error occurspublic byte[] getOldImage(Wiki.LogEntry entry) throws IOException
entry
- the upload log entry that corresponds to the image being
uploadedIOException
- if a network error occursIllegalArgumentException
- if the entry is not in the upload logpublic Wiki.LogEntry[] getUploads(Wiki.User user) throws IOException
user
- the user to get uploads forIOException
- if a network error occurspublic Wiki.LogEntry[] getUploads(Wiki.User user, Calendar start, Calendar end) throws IOException
user
- the user to get uploads forstart
- the date to start enumeration (use null to not specify one)end
- the date to end enumeration (use null to not specify one)IOException
- if a network error occurspublic void upload(File file, String filename, String contents, String reason) throws IOException, LoginException
file
- the image filefilename
- the target file name (may contain File)contents
- the contents of the image description page, set to "" if
overwriting an existing filereason
- an upload summary (defaults to contents, use "" to
not specify one)CredentialNotFoundException
- if not logged inCredentialException
- if (page is protected OR file is on a central repository) and
we can't uploadCredentialExpiredException
- if cookies have expiredIOException
- if a network/local filesystem error occursAccountLockedException
- if user is blockedLoginException
public boolean userExists(String username) throws IOException
username
- a usernameIOException
- if a network error occurspublic String[] allUsers(String start, int number) throws IOException
start
- the string to start enumerationnumber
- the number of users to returnIOException
- if a network error occurspublic String[] allUsersWithPrefix(String prefix) throws IOException
prefix
- a username prefix (without User:)IOException
- if a network error occurspublic String[] allUsers(String start, int number, String prefix) throws IOException
start
- the string to start enumerationnumber
- the number of users to returnprefix
- list all users with this prefix (overrides start and amount),
use "" to not specify oneIOException
- if a network error occurspublic Wiki.User getUser(String username) throws IOException
username
- a usernameIOException
- if a network error occurspublic Wiki.User getCurrentUser()
public Wiki.Revision[] contribs(String user, int... ns) throws IOException
user
- the user or IP to get contributions forns
- a list of namespaces to filter by, empty = all namespaces.IOException
- if a network error occurs@Deprecated public Wiki.Revision[] rangeContribs(String range) throws IOException
range
- the CIDR range of IP addresses to get contributions forIOException
- if a network error occursNumberFormatException
- if we aren't able to parse the rangepublic Wiki.Revision[] contribs(String user, String prefix, Calendar end, Calendar start, int... ns) throws IOException
user
- the user to get contributions for.start
- fetch edits no newer than this dateend
- fetch edits no older than this datens
- a list of namespaces to filter by, empty = all namespaces.prefix
- a prefix of usernames. Overrides user. Use "" to not
specify one.IOException
- if a network error occurspublic void emailUser(Wiki.User user, String message, String subject, boolean emailme) throws IOException, LoginException
user
- a Wikipedia user with email enabledsubject
- the subject of the messagemessage
- the plain text messageemailme
- whether to send a copy of the message to your email addressIOException
- if a network error occursCredentialExpiredException
- if cookies have expiredAccountLockedException
- if you have been blocked from sending emailUnsupportedOperationException
- if email is disabled or if you do not have a verified email
addressLoginException
public void watch(String... titles) throws IOException, CredentialNotFoundException
titles
- the pages to add to the watchlistIOException
- if a network error occursCredentialNotFoundException
- if not logged inunwatch(java.lang.String...)
public void unwatch(String... titles) throws IOException, CredentialNotFoundException
titles
- the pages to remove from the watchlist.IOException
- if a network error occursCredentialNotFoundException
- if not logged inwatch(java.lang.String...)
protected void watchInternal(boolean unwatch, String... titles) throws IOException, CredentialNotFoundException
titles
- the titles to (un)watchunwatch
- whether we should unwatch these pagesIOException
- if a network error occursCredentialNotFoundException
- if not logged inwatch(java.lang.String...)
,
unwatch(java.lang.String...)
public String[] getRawWatchlist() throws IOException, CredentialNotFoundException
IOException
- if a network error occursCredentialNotFoundException
- if not logged inpublic String[] getRawWatchlist(boolean cache) throws IOException, CredentialNotFoundException
cache
- whether we should use the watchlist cache (no online activity,
if the cache exists)IOException
- if a network error occursCredentialNotFoundException
- if not logged inpublic boolean isWatched(String title) throws IOException, CredentialNotFoundException
title
- the title to be checkedIOException
- if a network error occursCredentialNotFoundException
- if not logged inpublic Wiki.Revision[] watchlist() throws IOException, CredentialNotFoundException
IOException
- if a network error occursCredentialNotFoundException
- if not logged inpublic Wiki.Revision[] watchlist(boolean allrev, int... ns) throws IOException, CredentialNotFoundException
allrev
- show all revisions to the pages, instead of the top most
changens
- a list of namespaces to filter by, empty = all namespaces.IOException
- if a network error occursCredentialNotFoundException
- if not logged inpublic String[][] search(String search, int... namespaces) throws IOException
results[0] == page name results[1] == parsed section name (may be "") results[2] == snippet of page text
search
- a search stringnamespaces
- the namespaces to search. If no parameters are passed then the
default is MAIN_NAMESPACE only.IOException
- if a network error occurspublic String[] imageUsage(String image, int... ns) throws IOException
image
- the image (may contain File:)ns
- a list of namespaces to filter by, empty = all namespaces.IOException
- if a network error occurspublic String[] whatLinksHere(String title, int... ns) throws IOException
title
- the title of the pagens
- a list of namespaces to filter by, empty = all namespaces.IOException
- if a network error occurspublic String[] whatLinksHere(String title, boolean redirects, int... ns) throws IOException
title
- the title of the pagens
- a list of namespaces to filter by, empty = all namespaces.redirects
- whether we should limit to redirects onlyIOException
- if a network error occurspublic String[] whatTranscludesHere(String title, int... ns) throws IOException
title
- the title of the page, e.g. "Template:Stub"ns
- a list of namespaces to filter by, empty = all namespaces.IOException
- if a netwrok error occurspublic String[] getCategoryMembers(String name, int... ns) throws IOException
name
- the name of the category (with or without namespace attached)ns
- a list of namespaces to filter by, empty = all namespaces.IOException
- if a network error occurspublic String[] getCategoryMembers(String name, boolean subcat, int... ns) throws IOException
name
- the name of the categorysubcat
- do you want to return members of sub-categories also?
(default: false)ns
- a list of namespaces to filter by, empty = all namespaces.IOException
- if a network error occurspublic ArrayList[] linksearch(String pattern) throws IOException
pattern
- the pattern (String) to search for (e.g. example.com,
*.example.com)IOException
- if a network error occurspublic ArrayList[] linksearch(String pattern, String protocol, int... ns) throws IOException
pattern
- the pattern (String) to search for (e.g. example.com,
*.example.com)ns
- a list of namespaces to filter by, empty = all namespaces.protocol
- one of { http, https, ftp, irc, gopher, telnet, nntp,
worldwind, mailto, news, svn, git, mms } or "" (equivalent to
http)IOException
- if a network error occurspublic Wiki.LogEntry[] getIPBlockList(String user) throws IOException
user
- a username or IP (e.g. "127.0.0.1")IOException
- if a network error occurspublic Wiki.LogEntry[] getIPBlockList(Calendar start, Calendar end) throws IOException
start
- the start dateend
- the end dateIOException
- if a network error occursprotected Wiki.LogEntry[] getIPBlockList(String user, Calendar start, Calendar end) throws IOException
user
- a particular user that might have been blocked. Use "" to not
specify one. May be an IP (e.g. "127.0.0.1") or a CIDR range
(e.g. "127.0.0.0/16") but not an autoblock (e.g. "#123456").start
- what timestamp to start. Use null to not specify one.end
- what timestamp to end. Use null to not specify one.IOException
- if a network error occursIllegalArgumentException
- if start date is before end datepublic Wiki.LogEntry[] getLogEntries(int amount) throws IOException
amount
- the amount of log entries to getIOException
- if a network error occursIllegalArgumentException
- if amount < 1public Wiki.LogEntry[] getLogEntries(Wiki.User user) throws IOException
user
- the user to get log entries forIOException
- if a network error occurspublic Wiki.LogEntry[] getLogEntries(String target) throws IOException
target
- the target of the action(s).IOException
- if a network error occurspublic Wiki.LogEntry[] getLogEntries(Calendar start, Calendar end) throws IOException
start
- what timestamp to start. Use null to not specify one.end
- what timestamp to end. Use null to not specify one.IOException
- if something goes wrongIllegalArgumentException
- if start < endpublic Wiki.LogEntry[] getLogEntries(int amount, String type, String action) throws IOException
amount
- the number of entries to gettype
- what log to get (e.g. DELETION_LOG)action
- what action to get (e.g. delete, undelete, etc.), use "" to
not specify oneIOException
- if a network error occursIllegalArgumentException
- if the log type doesn't existpublic Wiki.LogEntry[] getLogEntries(Calendar start, Calendar end, int amount, String log, String action, Wiki.User user, String target, int namespace) throws IOException
start
- what timestamp to start. Use null to not specify one.end
- what timestamp to end. Use null to not specify one.amount
- the amount of log entries to get. If both start and end are
defined, this is ignored. Use Integer.MAX_VALUE to not specify
one.log
- what log to get (e.g. DELETION_LOG)action
- what action to get (e.g. delete, undelete, etc.), use "" to
not specify oneuser
- the user performing the action. Use null not to specify one.target
- the target of the action. Use "" not to specify one.namespace
- filters by namespace. Returns empty if namespace doesn't
exist.IOException
- if a network error occursIllegalArgumentException
- if start < end or amount < 1protected Wiki.LogEntry parseLogEntry(String xml)
xml
- the xml to parsepublic String[] prefixIndex(String prefix) throws IOException
prefix
- the prefixIOException
- if a network error occurspublic String[] shortPages(int cutoff) throws IOException
cutoff
- the maximum size in bytes these short pages can beIOException
- if a network error occurspublic String[] shortPages(int cutoff, int namespace) throws IOException
cutoff
- the maximum size in bytes these short pages can benamespace
- a namespaceIOException
- if a network error occurspublic String[] longPages(int cutoff) throws IOException
cutoff
- the minimum size in bytes these long pages can beIOException
- if a network error occurspublic String[] longPages(int cutoff, int namespace) throws IOException
cutoff
- the minimum size in nbytes these long pages can benamespace
- a namespaceIOException
- if a network error occurspublic String[] listPages(String prefix, HashMap<String,Object> protectionstate, int namespace) throws IOException
prefix
- the prefix of the title. Use "" to not specify one.protectionstate
- a protection state
, use null to not specify
onenamespace
- a namespace. ALL_NAMESPACES is not suppported, an
UnsupportedOperationException will be thrown.IOException
- if a network error occurspublic String[] listPages(String prefix, HashMap<String,Object> protectionstate, int namespace, int minimum, int maximum) throws IOException
prefix
- the prefix of the title. Use "" to not specify one.protectionstate
- a protection state
, use null to not specify
onenamespace
- a namespace. ALL_NAMESPACES is not suppported, an
UnsupportedOperationException will be thrown.minimum
- the minimum size in bytes these pages can be. Use -1 to not
specify one.maximum
- the maximum size in bytes these pages can be. Use -1 to not
specify one.IOException
- if a network error occurspublic String[] queryPage(String page) throws IOException, CredentialNotFoundException
page
- one of { Ancientpages, BrokenRedirects, Deadendpages,
Disambiguations, DoubleRedirects, Listredirects, Lonelypages,
Longpages, Mostcategories, Mostimages, Mostinterwikis,
Mostlinkedcategories, Mostlinkedtemplates, Mostlinked,
Mostrevisions, Fewestrevisions, Shortpages,
Uncategorizedcategories, Uncategorizedpages,
Uncategorizedimages, Uncategorizedtemplates, Unusedcategories,
Unusedimages, Wantedcategories, Wantedfiles, Wantedpages,
Wantedtemplates, Unwatchedpages, Unusedtemplates,
Withoutinterwiki }. This parameter is *case sensitive*.IOException
- if a network error occursCredentialNotFoundException
- if page=Unwatchedpages and we cannot read itpublic Wiki.Revision[] newPages(int amount) throws IOException
amount
- the number of pages to fetchIOException
- if a network error occurspublic Wiki.Revision[] newPages(int amount, int rcoptions) throws IOException
rcoptions
- a bitmask of HIDE_ANON etc that dictate which pages we return
(e.g. exclude patrolled pages => rcoptions = HIDE_PATROLLED).amount
- the amount of new pages to getIOException
- if a network error occurspublic Wiki.Revision[] newPages(int amount, int rcoptions, int... ns) throws IOException
rcoptions
- a bitmask of HIDE_ANON etc that dictate which pages we return
(e.g. exclude patrolled pages => rcoptions = HIDE_PATROLLED).amount
- the amount of new pages to getns
- a list of namespaces to filter by, empty = all namespaces.IOException
- if a network error occurspublic Wiki.Revision[] recentChanges(int amount) throws IOException
Note: Log entries in recent changes have a revid of 0!
amount
- the number of entries to returnIOException
- if a network error occurspublic Wiki.Revision[] recentChanges(int amount, int... ns) throws IOException
Note: Log entries in recent changes have a revid of 0!
amount
- the number of entries to returnns
- a list of namespaces to filter by, empty = all namespaces.IOException
- if a network error occurspublic Wiki.Revision[] recentChanges(int amount, int rcoptions, int... ns) throws IOException
Note: Log entries in recent changes have a revid of 0!
amount
- the number of entries to returnns
- a list of namespaces to filter by, empty = all namespaces.rcoptions
- a bitmask of HIDE_ANON etc that dictate which pages we return.IOException
- if a network error occursprotected Wiki.Revision[] recentChanges(int amount, int rcoptions, boolean newpages, int... ns) throws IOException
Note: Log entries in recent changes have a revid of 0!
amount
- the number of entries to returnns
- a list of namespaces to filter by, empty = all namespaces.rcoptions
- a bitmask of HIDE_ANON etc that dictate which pages we return.newpages
- show new pages onlyIOException
- if a network error occurspublic String[][] getInterWikiBacklinks(String prefix) throws IOException
{ { "Spam", "testwiki:Blah" }, { "Test", "testwiki:Main_Page" } }
Here the page [[Spam]] contains the interwiki link [[testwiki:Blah]] and the page [[Test]] contains the interwiki link [[testwiki:Main_Page]]. This does not resolve nested interwiki prefixes, e.g. [[wikt:fr:Test]].
For WMF wikis, see the interwiki mapfor where some prefixes link to.
prefix
- the interwiki prefix that denotes a wikiIOException
- if a network error occurspublic String[][] getInterWikiBacklinks(String prefix, String title) throws IOException
Example: If [[Test]] and [[Spam]] both contain the interwiki link [[testwiki:Blah]] then getInterWikiBacklinks("testwiki", "Blah"); will return (sorted by title)
{ { "Spam", "testwiki:Blah" }, { "Test", "testwiki:Blah" } }
For WMF wikis, see the interwiki mapfor where some prefixes link to.
prefix
- the interwiki prefix to searchtitle
- the title of the page on the other wiki to search for
(optional, use "|" to not specify one). Warning: "" is a valid
interwiki target!IOException
- if a network error occursIllegalArgumentException
- if a title is specified without a prefix (the MediaWiki API
doesn't like this)protected String fetch(String url, String caller) throws IOException
url
- the url to fetchcaller
- the caller of this methodIOException
- if a network error occursprotected String post(String url, String text, String caller) throws IOException
url
- the url to post totext
- the text to postcaller
- the caller of this methodIOException
- if a network error occursmultipartPost(java.lang.String, java.util.Map, java.lang.String)
protected String multipartPost(String url, Map<String,?> params, String caller) throws IOException
url
- the url to post toparams
- the POST parameters. Supported types: UTF-8 text, byte[]. Text
and parameter names must NOT be URL encoded.caller
- the caller of this methodIOException
post(java.lang.String, java.lang.String, java.lang.String)
,
Multipart/form-dataprotected void checkErrors(String line, String caller) throws IOException, LoginException
line
- the response from the server to analyzecaller
- what we tried to doAccountLockedException
- if the user is blockedHttpRetryException
- if the database is locked or action was throttled and a retry
failedUnknownError
- in the case of a MediaWiki bugIOException
LoginException
protected String decode(String in)
in
- the string to remove URL encoding fromprotected void constructNamespaceString(StringBuilder sb, String id, int... namespaces)
sb
- the url StringBuilder to append toid
- the request type prefix (e.g. "pl" for prop=links)namespaces
- the list of namespaces to appendpublic String normalize(String s)
s
- the string to normalizeIllegalArgumentException
- if the title is invalidprotected boolean checkRights(HashMap<String,Object> pageinfo, String action) throws IOException, CredentialException
pageinfo
- the output from getPageInfo()action
- what we are doingIOException
- if a network error occursCredentialExpiredException
- if cookies have expiredCredentialException
protected void statusCheck() throws IOException
AssertionError
- if any assertions are falseIOException
- if a network error occurssetAssertionMode(int)
protected void setCookies(URLConnection u)
u
- an unconnected URLConnectionprotected void log(Level level, String text, String method)
text
- string the string to logmethod
- what we are currently doinglevel
- the level to log at@Deprecated public void setLogLevel(Level level)
level
- the new logging levelprotected void logurl(String url, String method)
url
- the url we are fetchingmethod
- what we are currently doingpublic Calendar makeCalendar()
protected String calendarToTimestamp(Calendar c)
c
- the calendar to converttimestampToCalendar(java.lang.String)
protected final Calendar timestampToCalendar(String timestamp)
timestamp
- the timestamp to convertcalendarToTimestamp(java.util.Calendar)
protected String convertTimestamp(String timestamp)
timestamp
- the timestamp to converttimestampToCalendar(java.lang.String)
Copyright © 2013. All rights reserved.