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 or at the Github issue tracker.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. 2).
|
static int |
ASSERT_NO_MESSAGES
Assert that we have no new messages.
|
static int |
ASSERT_NONE
Use no assertions (i.e. 0).
|
static int |
ASSERT_SYSOP
Assert that we have a sysop flag (i.e. 8).
|
static int |
ASSERT_USER
Assert that we are logged in (i.e. 1).
|
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 file description pages.
|
static int |
FILE_TALK_NAMESPACE
Denotes talk pages for file description pages.
|
static String |
FULL_PROTECTION
Denotes full protection (i.e. only admins can perfom a particular action).
|
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 String |
IMPORT_LOG
Denotes the page importation log.
|
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. only autoconfirmed users can perform a
particular action).
|
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 via HTTPS.
|
Wiki(String domain)
Creates a new connection to a wiki via HTTPS.
|
Wiki(String domain,
String scriptPath)
Creates a new connection to a wiki with $wgScriptpath set to
scriptPath via HTTPS.
|
Wiki(String domain,
String scriptPath,
String protocol)
Creates a new connection to a wiki with $wgScriptpath set to
scriptPath via the specified protocol.
|
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 |
checkErrorsAndUpdateStatus(String line,
String caller)
Checks for errors from standard read/write requests and performs
occasional status checks.
|
protected boolean |
checkRights(Map<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.
|
protected String[] |
constructTitleString(String[] titles)
Cuts up a list of titles into batches for prop=X&titles=Y type queries.
|
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.
|
protected String |
decode(String in)
Strips entity references like " from the supplied string.
|
void |
delete(String title,
String reason)
Deletes a page.
|
Wiki.Revision[] |
deletedContribs(String u)
Gets the deleted contributions of a user.
|
Wiki.Revision[] |
deletedContribs(String u,
Calendar end,
Calendar start,
boolean reverse,
int... namespace)
Gets the deleted contributions of a user in the given namespace.
|
String[] |
deletedPrefixIndex(String prefix,
int namespace)
Returns all deleted pages that begin with the given prefix.
|
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[] |
getCategories(String title,
boolean sortkey,
boolean ignoreHidden)
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.
|
String[] |
getCategoryMembers(String name,
int maxdepth,
int... ns)
Gets the members of a category with maxdepth recursion.
|
protected String[] |
getCategoryMembers(String name,
int maxdepth,
List<String> visitedcategories,
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.
|
Wiki.Revision[] |
getDeletedHistory(String title)
Gets the deleted history of a page.
|
Wiki.Revision[] |
getDeletedHistory(String title,
Calendar start,
Calendar end,
boolean reverse)
Gets the deleted history of a page.
|
String |
getDeletedText(String page)
Gets the text of a deleted page (it's like getPageText, but for deleted
pages).
|
String |
getDomain()
Gets the domain of the wiki, as supplied on construction.
|
String[] |
getDuplicates(String file)
Gets duplicates of this file.
|
String[] |
getExternalLinksOnPage(String title)
Gets the list of external links used on a particular page.
|
Map<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)
Deprecated.
expects a file as additional parameter
|
boolean |
getImage(String title,
File file)
Fetches an image and saves it in the given file.
|
byte[] |
getImage(String title,
int width,
int height)
Deprecated.
expects a file as additional parameter
|
boolean |
getImage(String title,
int width,
int height,
File file)
Fetches a thumbnail of an image file and saves the image data
into the given file.
|
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.
|
Map<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. whether a user
is currently blocked.
|
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 wikilinks 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.
|
LinkedHashMap<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,
boolean reverse)
Gets the revision history of a page between two dates.
|
Map |
getPageInfo(String page)
Gets miscellaneous page info.
|
Map[] |
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.
|
Wiki.Revision[] |
getRevisions(long[] oldids)
Gets revisions based on given oldids.
|
String |
getScriptPath()
Deprecated.
use getSiteInfo
|
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.
|
Map<String,Object> |
getSiteInfo()
Gets various properties of the wiki and sets the bot framework up to use
them.
|
Map<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()
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 |
isUsingCapitalLinks()
Deprecated.
use getSiteInfo
|
boolean |
isUsingCompressedRequests()
Checks whether we are using GZip compression for GET requests.
|
boolean |
isWatched(String title)
Determines whether a page is watched.
|
List[] |
linksearch(String pattern)
Searches the wiki for external links.
|
List[] |
linksearch(String pattern,
String protocol,
int... ns)
Searches the wiki for external links.
|
String[] |
listPages(String prefix,
Map<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,
Map<String,Object> protectionstate,
int namespace,
int minimum,
int maximum,
Boolean redirects)
Lists pages with titles containing a certain prefix with a certain
protection state and in a certain namespace.
|
protected void |
log(Level level,
String method,
String text)
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.
|
protected URLConnection |
makeConnection(String url)
Creates a new URL connection.
|
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 page 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 String |
parseAttribute(String xml,
String attribute,
int index)
Parses the next XML attribute with the given name.
|
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,
Map<String,Object> protectionstate,
String reason)
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. a \ b.
|
String |
resolveRedirect(String title)
Gets the newest page name or the name of a page where the asked page
redirects.
|
String[] |
resolveRedirects(String[] titles)
Gets the newest page name or the name of a page where the asked pages
redirect.
|
void |
revisionDelete(Boolean hidecontent,
Boolean hideuser,
Boolean hidereason,
String reason,
Boolean suppress,
Wiki.Revision[] revisions)
Deletes and undeletes revisions.
|
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 loglevel)
Set the logging level used by the internal logger.
|
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 Calendar |
timestampToCalendar(String timestamp,
boolean api)
Turns a timestamp into a Calendar object.
|
String |
toString()
Returns a string representation of this Wiki.
|
void |
unblock(String blockeduser,
String reason)
Unblocks a user.
|
void |
undelete(String title,
String reason,
Wiki.Revision... revisions)
Undeletes a page.
|
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,
String reason)
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()
Deprecated.
use getSiteInfo
|
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
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_USER
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 ASSERT_SYSOP
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
public Wiki()
public Wiki(String domain)
domain
- the wiki domain name e.g. en.wikipedia.org (defaults to
en.wikipedia.org)public Wiki(String domain, String scriptPath)
domain
- the wiki domain namescriptPath
- the script pathpublic Wiki(String domain, String scriptPath, String protocol)
domain
- the wiki domain namescriptPath
- the script pathprotocol
- a protocol e.g. "http://", "https://" or "file:///"protected void initVars()
Contributed by Tedder
public String getDomain()
public int getThrottle()
setThrottle(int)
public void setThrottle(int throttle)
throttle
- the new throttle value in millisecondsgetThrottle()
@Deprecated public String getScriptPath() throws IOException
IOException
- if a network error occurs@Deprecated public boolean isUsingCapitalLinks() throws IOException
IOException
- if a network error occurspublic Map<String,Object> getSiteInfo() 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 setLogLevel(Level loglevel)
loglevel
- one of the levels specified in java.util.logging.LEVELpublic 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 Map<String,Integer> getSiteStatistics() throws IOException
IOException
- if a network error occurs@Deprecated public 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 Map getPageInfo(String page) throws IOException
page
- the page to get info forgetPageInfo(String[])
IOException
- if a network error occurspublic Map[] getPageInfo(String[] pages) throws IOException
protection state
of the page. Does
not cover implied protection levels (e.g. MediaWiki namespace).
pages
- the pages to get info for.IOException
- if a network error occurspublic int namespace(String title) throws IOException
title
- any valid page nameIOException
- 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 LinkedHashMap<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 check.IOException
- 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 occursUnknownError
- 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 or the title of the new section. 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]])bot
- whether to mark the edit as a bot edit (ignored if one does
not have the necessary permissions)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 minorbot
- whether to mark the edit as a bot edit (ignored if one does
not have the necessary permissions)AccountLockedException
- 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 undelete(String title, String reason, Wiki.Revision... revisions) throws IOException, LoginException
title
- a page to undeletereason
- the reason for undeletionrevisions
- a list of revisions for selective undeletionIOException
- if a network error occursCredentialNotFoundException
- if we cannot undeleteCredentialExpiredException
- 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[] getCategories(String title, boolean sortkey, boolean ignoreHidden) throws IOException
title
- a pagesortkey
- return a sortkey as well (default = false)ignoreHidden
- skip hidden categories (default = false)IOException
- 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 Map<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 String[] getExternalLinksOnPage(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 String resolveRedirect(String title) throws IOException
title
- a titleIOException
- if a network error occurspublic String[] resolveRedirects(String[] titles) throws IOException
titles
- a list of titles.IOException
- 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, boolean reverse) throws IOException
title
- a pagestart
- the EARLIEST of the two datesend
- the LATEST of the two datesreverse
- whether to put the oldest first (default = false, newest
first is how history pages work)IOException
- if a network error occurspublic Wiki.Revision[] getDeletedHistory(String title) throws IOException, CredentialNotFoundException
title
- a pageIOException
- if a network error occursCredentialNotFoundException
- if we cannot obtain deleted revisionspublic Wiki.Revision[] getDeletedHistory(String title, Calendar start, Calendar end, boolean reverse) throws IOException, CredentialNotFoundException
title
- a pagestart
- the EARLIEST of the two datesend
- the LATEST of the two datesreverse
- whether to put the oldest first (default = false, newest
first is how history pages work)IOException
- if a network error occursCredentialNotFoundException
- if we cannot obtain deleted revisionspublic Wiki.Revision[] deletedContribs(String u) throws IOException, CredentialNotFoundException
u
- a userIOException
- if a network error occursCredentialNotFoundException
- if we cannot obtain deleted revisionspublic Wiki.Revision[] deletedContribs(String u, Calendar end, Calendar start, boolean reverse, int... namespace) throws IOException, CredentialNotFoundException
u
- a userstart
- the EARLIEST of the two datesend
- the LATEST of the two datesreverse
- whether to put the oldest first (default = false, newest
first is how history pages work)namespace
- a list of namespacesIOException
- if a network error occursCredentialNotFoundException
- if we cannot obtain deleted revisionspublic String[] deletedPrefixIndex(String prefix, int namespace) throws IOException, CredentialNotFoundException
prefix
- a prefix without a namespace specifier, empty string
lists all deleted pages in the namespace.namespace
- one (and only one) namespaceIOException
- if a network error occursCredentialNotFoundException
- if we cannot view deleted pagespublic String getDeletedText(String page) throws IOException, CredentialNotFoundException
page
- a pageIOException
- if a network error occursCredentialNotFoundException
- if we cannot obtain deleted revisionspublic 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 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, Map<String,Object> protectionstate, String reason) throws IOException, LoginException
{ 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)reason
- the reason for (un)protectionIOException
- if a network error occursAccountLockedException
- if user is blockedCredentialExpiredException
- if cookies have expiredCredentialNotFoundException
- if we cannot protectLoginException
public void unprotect(String page, String reason) throws IOException, LoginException
page
- the page to unprotectreason
- the reason for unprotectionIOException
- if a network error occursAccountLockedException
- if user is blockedCredentialExpiredException
- if cookies have expiredCredentialNotFoundException
- if we cannot protectLoginException
public 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
- an oldidIOException
- if a network error occurspublic Wiki.Revision[] getRevisions(long[] oldids) throws IOException
oldids
- a list of oldidsIOException
- 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 cannot rollbackAccountLockedException
- if the user is blockedLoginException
public void revisionDelete(Boolean hidecontent, Boolean hideuser, Boolean hidereason, String reason, Boolean suppress, Wiki.Revision[] revisions) throws IOException, LoginException
hidecontent
- hide the content of the revision (true/false
= hide/unhide, null = status quo)hidereason
- hide the edit summary or the reason for an actionhideuser
- hide who made the revision/actionreason
- the reason why the (un)deletion was performedsuppress
- [[Wikipedia:Oversight]] the information in question
(ignored if we cannot suppressrevision, null = status quo).revisions
- the list of revisions to (un)deleteIOException
- if a network error occursCredentialNotFoundException
AccountLockedException
- 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)@Deprecated public byte[] getImage(String title) throws IOException
title
- the title of the image (may contain "File")IOException
- if a network error occurspublic boolean getImage(String title, File file) throws FileNotFoundException, IOException
title
- the title of the image (may contain "File")file
- the file to save the image to.FileNotFoundException
- if the file is a directory, cannot be created or openedIOException
- if a network error occurs@Deprecated public 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 boolean getImage(String title, int width, int height, File file) throws FileNotFoundException, 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)file
- a write-able file to save the data to.FileNotFoundException
- if the file is a directory, cannot be created or openedIOException
- if a network error occurspublic Map<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 unblock(String blockeduser, String reason) throws IOException, LoginException
blockeduser
- the user to unblockreason
- the reason for unblockingCredentialNotFoundException
- if not an adminIOException
- if a network error occursCredentialExpiredException
- if cookies have expiredAccountLockedException
- if you have been blockedLoginException
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)
Recursion is limited to a depth of one.ns
- a list of namespaces to filter by, empty = all namespaces.IOException
- if a network error occurspublic String[] getCategoryMembers(String name, int maxdepth, int... ns) throws IOException
name
- the name of the categorymaxdepth
- depth of recursion for subcategoriesns
- a list of namespaces to filter by, empty = all namespaces.IOException
- if a network error occursprotected String[] getCategoryMembers(String name, int maxdepth, List<String> visitedcategories, int... ns) throws IOException
name
- the name of the categorymaxdepth
- depth of recursion for subcategoriesvisitedcategories
- list of already visited categoriesns
- a list of namespaces to filter by, empty = all namespaces.IOException
- if a network error occurspublic List[] linksearch(String pattern) throws IOException
pattern
- the pattern (String) to search for (e.g. example.com,
*.example.com)IOException
- if a network error occurspublic List[] 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. Use ALL_NAMESPACES to not specify one.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, Map<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, Map<String,Object> protectionstate, int namespace, int minimum, int maximum, Boolean redirects) 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.redirects
- Boolean.TRUE = list redirects only, Boolean.FALSE = list
non-redirects only, null = list bothIOException
- 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 occursAssertionError
- if assert=user|bot failsprotected 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
- if a network error occurspost(java.lang.String, java.lang.String, java.lang.String)
,
Multipart/form-dataprotected URLConnection makeConnection(String url) throws IOException
url
- a URL stringIOException
- if a network error occursprotected void checkErrorsAndUpdateStatus(String line, String caller) throws IOException, LoginException
line
- the response from the server to analyzecaller
- what we tried to doCredentialNotFoundException
- if permission deniedAccountLockedException
- if the user is blockedHttpRetryException
- if the database is locked or action was
throttled and a retry failedAssertionError
- if assertions failUnknownError
- in the case of a MediaWiki bugIOException
LoginException
protected String decode(String in)
in
- the string to remove URL encoding fromprotected String parseAttribute(String xml, String attribute, int index)
xml
- the xml to searchattribute
- the attribute to searchindex
- where to start lookingprotected 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 appendprotected String[] constructTitleString(String[] titles) throws IOException
titles
- a list of titles.IOException
- if a network error occurspublic String normalize(String s) throws IOException
s
- the string to normalizeIllegalArgumentException
- if the title is invalidIOException
- if a network error occurs (rare)protected boolean checkRights(Map<String,Object> pageinfo, String action) throws IOException
pageinfo
- the output from getPageInfo()action
- what we are doingIOException
- if a network error occursprotected void setCookies(URLConnection u)
u
- an unconnected URLConnectionprotected void log(Level level, String method, String text)
text
- string the string to logmethod
- what we are currently doinglevel
- the level to log atprotected 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, boolean)
protected final Calendar timestampToCalendar(String timestamp, boolean api)
timestamp
- the timestamp to convertapi
- whether the timestamp is of the format yyyy-mm-ddThh:mm:ssZ
as opposed to yyyymmddhhmmss (which is the default)calendarToTimestamp(java.util.Calendar)
protected String convertTimestamp(String timestamp)
timestamp
- the timestamp to converttimestampToCalendar(java.lang.String, boolean)
Copyright © 2018 BITPlan GmbH. All rights reserved.