public class Mediawiki extends MediaWikiApiImpl implements MediawikiApi
| Modifier and Type | Class and Description |
|---|---|
static class |
Mediawiki.Method |
| Modifier and Type | Field and Description |
|---|---|
protected String |
apiPath |
protected boolean |
debug
set to true for debugging
|
static String |
DEFAULT_SCRIPTPATH
default script path
|
protected String |
format |
protected String |
scriptPath |
protected String |
siteurl |
static boolean |
testMode
if true main can be called without calling system.exit() when finished
|
protected static String |
USER_AGENT
|
protected String |
userid |
protected static String |
VERSION
current Version
|
LOGGER, protectionMarker, throwExceptionOnError| Constructor and Description |
|---|
Mediawiki()
construct me with no siteurl set
|
Mediawiki(String siteurl)
construct a Mediawiki for the given url using the default Script path
|
Mediawiki(String siteurl,
String pScriptPath)
construct a Mediawiki for the given url and scriptpath
|
| Modifier and Type | Method and Description |
|---|---|
Api |
createAccount(String name,
String eMail,
String realname,
boolean mailpassword,
String reason,
String language)
create the given user account
|
String |
dateToMWTimeStamp(Date date)
convert a data to a MediaWiki API timestamp
|
Delete |
delete(String pageTitle,
String reason)
https://www.mediawiki.org/wiki/API:Delete/de
|
Edit |
edit(String pageTitle,
String text,
String summary)
https://www.mediawiki.org/wiki/API:Edit
|
Edit |
edit(String pageTitle,
String text,
String summary,
boolean minor,
boolean bot,
int sectionNumber,
String sectionTitle,
Calendar basetime)
edit
|
Api |
getActionResult(String action,
String params)
get the result for the given action and query
|
Api |
getActionResult(String action,
String params,
com.bitplan.mediawiki.japi.Mediawiki.TokenResult token,
Object pFormData)
get the action result for the default format
|
Api |
getActionResult(String action,
String params,
com.bitplan.mediawiki.japi.Mediawiki.TokenResult token,
Object pFormData,
String format)
get the result for the given action and params
|
String |
getActionResultText(String action,
String params,
com.bitplan.mediawiki.japi.Mediawiki.TokenResult token,
Object pFormData,
String format)
get the action result for the given parameters
|
List<Img> |
getAllImagesByTimeStamp(String aistart,
String aiend,
int ailimit)
get all Images by the given time stamps
|
List<P> |
getAllPages(String apfrom,
int aplimit)
getAllPages
|
List<Bl> |
getBacklinks(String pageTitle,
String params,
int bllimit)
get the backlinks for the given pagetitle
|
com.bitplan.mediawiki.japi.Mediawiki.TokenResult |
getEditToken(String pageTitle,
String type)
get an edit token for the given page Title see
API:Tokens
|
String |
getFormat() |
Ii |
getImageInfo(String pageTitle)
get the Image Info for the given pageTitle
|
List<Ii> |
getImageInfosForPage(String pageTitle,
int imLimit)
get the imageInfos for all images on the given page Title
|
List<Im> |
getImagesOnPage(String pageTitle,
int imLimit)
get the Images on the given page
|
List<Iu> |
getImageUsage(String imageTitle,
String params,
int limit)
get the imageusage for the given imageTitle
|
String |
getIsoTimeStamp()
get a current IsoTimeStamp
|
List<Rc> |
getMostRecentChanges(int days,
int rcLimit)
get the most recent changes
|
String |
getPageContent(String pageTitle)
get the page Content for the given page Title
|
String |
getPageContent(String pageTitle,
String queryParams,
boolean checkNotNull)
get the page Content for the given page Title
|
String |
getPageHtml(String pageTitle)
get the html rendered version of a page
|
List<Page> |
getPages(List<String> titleList)
get a list of pages for the given titles see
API:Query
|
List<Page> |
getPages(List<String> titleList,
String rvprop)
get a list of pages for the given titles see
API:Query
|
Map<String,String> |
getParamMap(String params)
get a Map of parameter from a & delimited parameter list
|
Parse |
getParse(String params)
get the parse Result for the given params
|
com.sun.jersey.api.client.ClientResponse |
getPostResponse(String queryUrl,
String params,
com.bitplan.mediawiki.japi.Mediawiki.TokenResult token,
Object pFormDataObject)
get a Post response
|
Api |
getQueryResult(String query)
get the Result for the given query
|
List<Rc> |
getRecentChanges(String rcstart,
String rcend,
Integer rclimit)
get the recent changes see https://www.mediawiki.org/wiki/API:RecentChanges
|
com.sun.jersey.api.client.WebResource.Builder |
getResource(String queryUrl)
get the given Builder for the given queryUrl this is a wrapper to be able
to debug all QueryUrl
|
com.sun.jersey.api.client.ClientResponse |
getResponse(String url,
Mediawiki.Method method)
get a response for the given url and method
|
String |
getResponseString(com.sun.jersey.api.client.ClientResponse response)
get the Response string
|
String |
getScriptPath()
get the script Path
|
List<S> |
getSections(String pageTitle)
get the sections for the given pageTitle
|
String |
getSectionText(String pageTitle,
int sectionNumber)
get the text for the given section
|
SiteInfo |
getSiteInfo()
get the siteinfo
|
String |
getSiteurl() |
static String |
getStringFromUrl(String urlString)
get a String from a given URL
|
String |
getTitles(List<String> titleList)
get a normalized | delimited (encoded as %7C) string of titles
|
void |
handle(Throwable t)
handle the given Throwable (in commandline mode)
|
void |
init(String siteurl,
String scriptpath)
overrideable e.g for SSL configuration
|
boolean |
isDebug()
get the state of the debug mode
|
boolean |
isLoggedIn()
check whether there is a User logged In
|
boolean |
isVersion128()
check whether this is MediaWiki 1.28 or higher but make sure getVersion
calls with readapidenied are ignored see
https://github.com/WolfgangFahl/Mediawiki-Japi/issues/32
|
Login |
login(com.bitplan.mediawiki.japi.Mediawiki.TokenResult token,
String username,
String password)
second step of login process
|
Login |
login(com.bitplan.mediawiki.japi.Mediawiki.TokenResult token,
String username,
String password,
String domain)
second step of login process
|
Login |
login(String username,
String password)
login with the given username and password
|
Login |
login(String username,
String password,
String domain)
login with the given username, password and domain
|
void |
logout()
end the session
|
static void |
main(String[] args)
entry point e.g. for java -jar called provides a command line interface
|
protected int |
maininstance(String[] args)
main instance - this is the non-static version of main - it will run as a
static main would but return it's exitCode to the static main the static
main will then decide whether to do a System.exit(exitCode) or not.
|
com.bitplan.mediawiki.japi.Mediawiki.TokenResult |
prepareLogin(String username)
prepare the login by getting the login token
|
void |
setDebug(boolean debug)
enable debugging
|
void |
setFormat(String format) |
void |
setScriptPath(String scriptPath)
set the scriptPath of this Wiki
|
void |
setSiteurl(String siteurl)
set the siteurl
|
void |
setUpSiteInfo(Query query)
setup siteinfo for a query (e.g. for testing)
|
void |
showHelp()
show Help
|
static void |
showVersion()
show the Version
|
List<Rc> |
sortByTitleAndFilterDoubles(List<Rc> rcList)
sort the given List by title and filter double titles
|
void |
upload(File fileToUpload,
String filename,
String contents,
String comment)
https://www.mediawiki.org/wiki/API:Upload
|
void |
upload(Ii ii,
String fileName,
String pageContent)
upload the image described in the given imageinfo
|
void |
upload(InputStream fileToUpload,
String filename,
String contents,
String comment)
upload from the given inputstream
|
void |
usage(String msg)
show a usage
|
copyToWiki, decode, encode, fromXML, getProtectionMarker, getVersion, handleError, handleError, handleError, isThrowExceptionOnError, normalizeTitle, setProtectionMarker, setThrowExceptionOnError, setVersionclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcopyToWiki, getVersion, isThrowExceptionOnError, normalizeTitle, setProtectionMarker, setThrowExceptionOnErrorprotected static final String VERSION
public static boolean testMode
protected static final String USER_AGENT
public static final String DEFAULT_SCRIPTPATH
protected String siteurl
protected String scriptPath
protected String format
protected String apiPath
protected String userid
protected boolean debug
public Mediawiki(String siteurl) throws Exception
siteurl - - the url to useExceptionpublic void setDebug(boolean debug)
setDebug in interface MediawikiApidebug - public boolean isDebug()
MediawikiApiisDebug in interface MediawikiApipublic String getSiteurl()
getSiteurl in interface MediawikiApipublic void setSiteurl(String siteurl)
MediawikiApisetSiteurl in interface MediawikiApisiteurl - the siteurl to setpublic String getScriptPath()
MediawikiApigetScriptPath in interface MediawikiApipublic void setScriptPath(String scriptPath)
MediawikiApisetScriptPath in interface MediawikiApiscriptPath - the scriptPath to setpublic String getFormat()
public void setFormat(String format)
public void init(String siteurl, String scriptpath) throws Exception
init in interface MediawikiApisiteurl - - the url to usescriptpath - - the script path to useExceptionpublic String getIsoTimeStamp()
getIsoTimeStamp in interface MediawikiApipublic static String getStringFromUrl(String urlString)
urlString - public com.sun.jersey.api.client.WebResource.Builder getResource(String queryUrl) throws Exception
queryUrl - - either a relative or absolute pathExceptionpublic com.sun.jersey.api.client.ClientResponse getPostResponse(String queryUrl, String params, com.bitplan.mediawiki.japi.Mediawiki.TokenResult token, Object pFormDataObject) throws Exception
queryUrl - params - - direct query parameterstoken - - a token if anypFormData - - the form data - either as multipart of urlencodedExceptionpublic com.sun.jersey.api.client.ClientResponse getResponse(String url, Mediawiki.Method method) throws Exception
url - method - Exceptionpublic String getResponseString(com.sun.jersey.api.client.ClientResponse response) throws Exception
response - Exceptionpublic Map<String,String> getParamMap(String params)
params - - the list of parameterspublic String getActionResultText(String action, String params, com.bitplan.mediawiki.japi.Mediawiki.TokenResult token, Object pFormData, String format) throws Exception
action - params - token - pFormData - format - - json or xmlExceptionpublic Api getActionResult(String action, String params, com.bitplan.mediawiki.japi.Mediawiki.TokenResult token, Object pFormData, String format) throws Exception
action - params - token - (may be null)formData - (may be null)Exceptionpublic Api getActionResult(String action, String params, com.bitplan.mediawiki.japi.Mediawiki.TokenResult token, Object pFormData) throws Exception
action - params - token - pFormData - Exceptionpublic Api getActionResult(String action, String params) throws Exception
action - params - Exceptionpublic Api getQueryResult(String query) throws Exception
query - Exceptionpublic String getTitles(List<String> titleList) throws Exception
examplePages - - the list of pages to get the titles forExceptionpublic SiteInfo getSiteInfo() throws Exception
getSiteInfo in interface MediawikiApigetSiteInfo in class MediaWikiApiImplExceptionpublic void setUpSiteInfo(Query query)
query - public boolean isVersion128()
public com.bitplan.mediawiki.japi.Mediawiki.TokenResult prepareLogin(String username) throws Exception
username - Exceptionpublic Login login(com.bitplan.mediawiki.japi.Mediawiki.TokenResult token, String username, String password) throws Exception
token - username - password - Exceptionpublic Login login(com.bitplan.mediawiki.japi.Mediawiki.TokenResult token, String username, String password, String domain) throws Exception
token - username - password - domain - Exceptionpublic Login login(String username, String password, String domain) throws Exception
username - password - domain - Exceptionpublic Login login(String username, String password) throws Exception
login in interface MediawikiApiusername - password - Exceptionpublic boolean isLoggedIn()
MediawikiApiisLoggedIn in interface MediawikiApipublic void logout()
throws Exception
logout in interface MediawikiApiExceptionpublic String getPageContent(String pageTitle, String queryParams, boolean checkNotNull) throws Exception
pageTitle - queryParams - - extra query params e.g. for sectionscheckNotNull - - check if the content should not be nullExceptionpublic String getPageContent(String pageTitle) throws Exception
getPageContent in interface MediawikiApipageTitle - Exceptionpublic String getSectionText(String pageTitle, int sectionNumber) throws Exception
getSectionText in interface MediawikiApipageTitle - sectionNumber - Exceptionpublic List<S> getSections(String pageTitle) throws Exception
MediawikiApigetSections in interface MediawikiApiExceptionpublic String getPageHtml(String pageTitle) throws Exception
MediawikiApigetPageHtml in interface MediawikiApiExceptionpublic Parse getParse(String params) throws Exception
params - Exceptionpublic List<Page> getPages(List<String> titleList, String rvprop) throws Exception
titleList - rvprop - - the revision propertiesException - FIXME should be part of the Java Interfacepublic List<Page> getPages(List<String> titleList) throws Exception
titleList - Exceptionpublic com.bitplan.mediawiki.japi.Mediawiki.TokenResult getEditToken(String pageTitle, String type) throws Exception
pageTitle - type - e.g. edit or deleteExceptionpublic Edit edit(String pageTitle, String text, String summary) throws Exception
edit in interface MediawikiApipageTitle - the title of the pagetext - the text of the pagesummary - the edit summary. Summaries longer than 200 characters are
truncated server-side.Exception - - if the edit failsMediawikiApi.getPageContent(java.lang.String)public Delete delete(String pageTitle, String reason) throws Exception
delete in interface MediawikiApiExceptionpublic Edit edit(String pageTitle, String text, String summary, boolean minor, boolean bot, int sectionNumber, String sectionTitle, Calendar basetime) throws Exception
MediawikiApiedit in interface MediawikiApiminor - - true if this is a minor editbot - whether to mark the edit as a bot edit (ignored if one does not
have the necessary permissions)sectionNumber - the section to edit. Use -1 to specify a new section and -2 to
disable section editing.sectionTitle - the title of a new sectionbasetime - the timestamp of the revision on which text is based,
used to check for edit conflicts. null disables this.ExceptionMediawikiApi.getPageContent(java.lang.String)public void upload(File fileToUpload, String filename, String contents, String comment) throws Exception
upload in interface MediawikiApifileToUpload - the image filefilename - the target file name (may contain File)contents - the contents of the image description page, set to "" if
overwriting an existing filecomment - an upload summary (defaults to contents, use "" to not
specify one)Exception - - if the upload failspublic void upload(InputStream fileToUpload, String filename, String contents, String comment) throws Exception
fileToUpload - filename - contents - comment - Exceptionpublic void upload(Ii ii, String fileName, String pageContent) throws Exception
MediawikiApiupload in interface MediawikiApipageContent - the contents of the image description page, set to "" if
overwriting an existing fileExceptionpublic List<P> getAllPages(String apfrom, int aplimit) throws Exception
getAllPages in interface MediawikiApiapfrom - - may be null or emptyaplimit - Exceptionpublic List<Img> getAllImagesByTimeStamp(String aistart, String aiend, int ailimit) throws Exception
MediawikiApigetAllImagesByTimeStamp in interface MediawikiApiaistart - - start time stampaiend - - end time stampailimit - - how many images to getExceptionpublic List<Bl> getBacklinks(String pageTitle, String params, int bllimit) throws Exception
MediawikiApigetBacklinks in interface MediawikiApiparams - - extra paramsExceptionpublic List<Iu> getImageUsage(String imageTitle, String params, int limit) throws Exception
MediawikiApigetImageUsage in interface MediawikiApiparams - - extra paramsExceptionpublic void handle(Throwable t)
t - public static void showVersion()
public void usage(String msg)
public void showHelp()
protected int maininstance(String[] args)
args - - command line argumentspublic static void main(String[] args)
args - public Api createAccount(String name, String eMail, String realname, boolean mailpassword, String reason, String language) throws Exception
name - eMail - realname - mailpassword - reason - language - Exceptionpublic Ii getImageInfo(String pageTitle) throws Exception
MediawikiApigetImageInfo in interface MediawikiApipageTitle - - the pageTitle to get the ImageInfo forExceptionpublic List<Im> getImagesOnPage(String pageTitle, int imLimit) throws Exception
MediawikiApigetImagesOnPage in interface MediawikiApiExceptionpublic List<Ii> getImageInfosForPage(String pageTitle, int imLimit) throws Exception
MediawikiApigetImageInfosForPage in interface MediawikiApiExceptionpublic List<Rc> getRecentChanges(String rcstart, String rcend, Integer rclimit) throws Exception
rcstart - The timestamp to start listing from (May not be more than
$wgRCMaxAge into the past, which on Wikimedia wikis is 30 days[1])rcend - rclimit - Exceptionpublic List<Rc> sortByTitleAndFilterDoubles(List<Rc> rcList)
rcList - public String dateToMWTimeStamp(Date date)
date - Copyright © 2018 BITPlan GmbH. All rights reserved.