@ThreadSafe public final class MediaWiki extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
MediaWiki.APIError
Thrown when a MediaWiki API call returns an explicit error response.
|
static class |
MediaWiki.MalformedRequest
Thrown when an improperly formed API call is detected.
|
static class |
MediaWiki.MalformedResponse
Thrown when the response to an API call is improperly formed.
|
static class |
MediaWiki.NoSuchItem
Thrown when a request cannot be met because an item does not exist.
|
static class |
MediaWiki.NoSuchPage
Thrown when a request cannot be met because a page does not exist.
|
static class |
MediaWiki.NoSuchRev
Thrown when a request cannot be met because a page revision does not exist.
|
| Modifier and Type | Field and Description |
|---|---|
static String |
API_POST_CHARSET
The character set for posting to the MediaWiki API.
|
static Pattern |
MAYBE_UGLY_URL_PATTERN
A pattern that detects whether a wiki URL might be based on the standard access
URL ending in "index.php" for example, or is definitely based on a pretty alias
per
$wgUsePathInfo. |
| Modifier and Type | Method and Description |
|---|---|
static StringBuilder |
appendPageSpecifier(StringBuilder b,
boolean maybeUgly,
String encodedPageName)
Appends an already encoded page name to a wiki base URL.
|
static String |
demiDecodedPageName(String demiEncodedPageName)
Completes the URL-decoding of a page name by substituting spaces for underscores.
|
static String |
demiEncodedPageName(String unEncodedPageName,
boolean maybeUgly)
Partially encodes a page name prior to full URL-encoding, either by substituting
underscores for spaces, or by doing the opposite if the wiki URL is ugly.
|
static javax.ws.rs.core.UriBuilder |
encodePageSpecifier(javax.ws.rs.core.UriBuilder ub,
boolean maybeUgly,
String pageName)
Encodes a page name and appends it to a wiki base URL.
|
static File |
fetchPageAsFile(URI s,
String idType,
int id,
String prefix)
Downloads the wikitext source of the specified page into a temporary file.
|
static String |
login(URI api,
CookieHandler cookieHandler,
String username,
String password)
Logs into a wiki.
|
static XMLStreamReader |
newXMLStreamReader(InputStream in,
Spool spool)
Constructs a new stream reader suitable for reading a MediaWiki API response, and
reads just to the 'api' element.
|
static String |
normalUsername(String name)
Translates the username to normal form by shifting the first letter to uppercase
and substituting spaces for underscores.
|
static MatchResult |
parsePageName(String pageName)
Parses a page name (example "Ns:Root/sub/path") into two groups: (1) namespace
"Ns", and (2) local name "Root/sub/path".
|
static MatchResult |
parsePageNameS(String pageName)
Parses a page name (example "Ns:Root/sub/path") into three groups: (1) namespace
"Ns", (2) local root name "Root" and (3) subpage path "sub/path".
|
static com.google.gson.stream.JsonReader |
requestJSON(URLConnection _http,
Spool spool)
Establishes an HTTP connection and returns a JSON reader for the response.
|
static XMLStreamReader |
requestXML(URLConnection _http,
Spool spool)
Establishes an HTTP connection and returns an XML reader pre-situated on the 'api'
element of the response body.
|
static String |
revLoc(String scriptLoc,
int rev)
Constructs the URL for a page revision.
|
static String |
revLoc(URI scriptURI,
int _rev)
Constructs the URL to a page revision.
|
static void |
test_badrevids(XMLStreamReader r)
Tests the current element of an API response and throws NoSuchRev if the element
is named 'badrevids'.
|
static void |
test_error(XMLStreamReader r)
Tests the current element of an API response and throws an APIError if the element
is named 'error'.
|
static void |
testPage_missing(XMLStreamReader r)
Tests the 'page' element of an API 'info' query response and throws NoSuchPage if
it encodes a 'missing' attribute.
|
public static final String API_POST_CHARSET
public static final Pattern MAYBE_UGLY_URL_PATTERN
$wgUsePathInfo.public static StringBuilder appendPageSpecifier(StringBuilder b, boolean maybeUgly, String encodedPageName)
/Main_page) if that
is safe, otherwise as a title query (?title=Main_page).b - a String builder containing only the wiki base URL, without a
trailing slash (/).maybeUgly - whether the base URL might be the standard access URL ending
in "index.php" for example, or is definitely a pretty alias per
$wgUsePathInfo.encodePageSpecifier(UriBuilder,boolean,String),
MAYBE_UGLY_URL_PATTERNpublic static String demiDecodedPageName(String demiEncodedPageName)
public static String demiEncodedPageName(String unEncodedPageName, boolean maybeUgly)
maybeUgly - whether the base URL might be the standard access
URL ending in "index.php" for example, or is definitely a pretty alias per
$wgUsePathInfo.public static javax.ws.rs.core.UriBuilder encodePageSpecifier(javax.ws.rs.core.UriBuilder ub, boolean maybeUgly, String pageName)
/Main_page) if that
is safe, otherwise as a title query (?title=Main+page).ub - a URI builder containing only the wiki base URL.maybeUgly - whether the base URL might be the standard access
URL ending in "index.php" for example, or is definitely a pretty alias per
$wgUsePathInfo.appendPageSpecifier(StringBuilder,boolean,String),
MAYBE_UGLY_URL_PATTERNpublic static File fetchPageAsFile(URI s, String idType, int id, String prefix) throws IOException
idType - one of "curid" or "oldid".id - the page identifier (curid) or revision identifier (oldid).s - the base URL for script execution in the wiki, without a trailing
slash (/).prefix - the prefix
for the temporary file.IOExceptionpublic static String login(URI api, CookieHandler cookieHandler, String username, String password) throws IOException
api - the URL of the wiki's api.php script.IOException@ThreadSafe public static XMLStreamReader newXMLStreamReader(InputStream in, Spool spool) throws IOException, XMLStreamException
spool - an optional spool for the release of associated holds. When
unwound it releases the holds of the reader and thereby disables it.IOExceptionXMLStreamExceptionrequestXML(URLConnection,Spool)public static String normalUsername(String name)
public static MatchResult parsePageName(String pageName)
public static MatchResult parsePageNameS(String pageName)
public static com.google.gson.stream.JsonReader requestJSON(URLConnection _http, Spool spool) throws IOException
_http - the connector, which must be of type HttpURLConnection. The base
class is accepted only as a convenience to save clients having to cast the
result of URL.openConnection().spool - a spool for the release of associated holds. When unwound it
releases the holds of the reader and thereby disables it.IOExceptionpublic static XMLStreamReader requestXML(URLConnection _http, Spool spool) throws IOException, XMLStreamException
_http - the connector, which must be of type HttpURLConnection. The base
class is accepted only as a convenience to save clients having to cast the
result of URL.openConnection().spool - a spool for the release of associated holds. When unwound it
releases the holds of the reader and thereby disables it.IOExceptionXMLStreamExceptionpublic static String revLoc(String scriptLoc, int rev)
scriptLoc - the base location for script execution in the wiki, without a
trailing slash (/).public static String revLoc(URI scriptURI, int _rev)
scriptURI - the base location for script execution in the wiki, without a
trailing slash (/).public static void test_badrevids(XMLStreamReader r) throws MediaWiki.NoSuchRev, XMLStreamException
r - a reader positioned at an element start tag.MediaWiki.NoSuchRevXMLStreamExceptionpublic static void test_error(XMLStreamReader r) throws MediaWiki.APIError
r - a reader positioned at an element start tag.MediaWiki.APIErrorpublic static void testPage_missing(XMLStreamReader r) throws MediaWiki.NoSuchPage
r - a reader positioned at a 'page' element start tag.MediaWiki.NoSuchPage - if the response indicates a missing page.MediaWiki.MalformedRequest - if the response indicates an invalid page name.