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, setVersion
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
copyToWiki, getVersion, isThrowExceptionOnError, normalizeTitle, setProtectionMarker, setThrowExceptionOnError
protected 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 useException
public void setDebug(boolean debug)
setDebug
in interface MediawikiApi
debug
- public boolean isDebug()
MediawikiApi
isDebug
in interface MediawikiApi
public String getSiteurl()
getSiteurl
in interface MediawikiApi
public void setSiteurl(String siteurl)
MediawikiApi
setSiteurl
in interface MediawikiApi
siteurl
- the siteurl to setpublic String getScriptPath()
MediawikiApi
getScriptPath
in interface MediawikiApi
public void setScriptPath(String scriptPath)
MediawikiApi
setScriptPath
in interface MediawikiApi
scriptPath
- the scriptPath to setpublic String getFormat()
public void setFormat(String format)
public void init(String siteurl, String scriptpath) throws Exception
init
in interface MediawikiApi
siteurl
- - the url to usescriptpath
- - the script path to useException
public String getIsoTimeStamp()
getIsoTimeStamp
in interface MediawikiApi
public 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 pathException
public 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 urlencodedException
public com.sun.jersey.api.client.ClientResponse getResponse(String url, Mediawiki.Method method) throws Exception
url
- method
- Exception
public String getResponseString(com.sun.jersey.api.client.ClientResponse response) throws Exception
response
- Exception
public 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 xmlException
public 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)Exception
public Api getActionResult(String action, String params, com.bitplan.mediawiki.japi.Mediawiki.TokenResult token, Object pFormData) throws Exception
action
- params
- token
- pFormData
- Exception
public Api getActionResult(String action, String params) throws Exception
action
- params
- Exception
public Api getQueryResult(String query) throws Exception
query
- Exception
public String getTitles(List<String> titleList) throws Exception
examplePages
- - the list of pages to get the titles forException
public SiteInfo getSiteInfo() throws Exception
getSiteInfo
in interface MediawikiApi
getSiteInfo
in class MediaWikiApiImpl
Exception
public void setUpSiteInfo(Query query)
query
- public boolean isVersion128()
public com.bitplan.mediawiki.japi.Mediawiki.TokenResult prepareLogin(String username) throws Exception
username
- Exception
public Login login(com.bitplan.mediawiki.japi.Mediawiki.TokenResult token, String username, String password) throws Exception
token
- username
- password
- Exception
public Login login(com.bitplan.mediawiki.japi.Mediawiki.TokenResult token, String username, String password, String domain) throws Exception
token
- username
- password
- domain
- Exception
public Login login(String username, String password, String domain) throws Exception
username
- password
- domain
- Exception
public Login login(String username, String password) throws Exception
login
in interface MediawikiApi
username
- password
- Exception
public boolean isLoggedIn()
MediawikiApi
isLoggedIn
in interface MediawikiApi
public void logout() throws Exception
logout
in interface MediawikiApi
Exception
public 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 nullException
public String getPageContent(String pageTitle) throws Exception
getPageContent
in interface MediawikiApi
pageTitle
- Exception
public String getSectionText(String pageTitle, int sectionNumber) throws Exception
getSectionText
in interface MediawikiApi
pageTitle
- sectionNumber
- Exception
public List<S> getSections(String pageTitle) throws Exception
MediawikiApi
getSections
in interface MediawikiApi
Exception
public String getPageHtml(String pageTitle) throws Exception
MediawikiApi
getPageHtml
in interface MediawikiApi
Exception
public Parse getParse(String params) throws Exception
params
- Exception
public 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
- Exception
public com.bitplan.mediawiki.japi.Mediawiki.TokenResult getEditToken(String pageTitle, String type) throws Exception
pageTitle
- type
- e.g. edit or deleteException
public Edit edit(String pageTitle, String text, String summary) throws Exception
edit
in interface MediawikiApi
pageTitle
- 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 MediawikiApi
Exception
public Edit edit(String pageTitle, String text, String summary, boolean minor, boolean bot, int sectionNumber, String sectionTitle, Calendar basetime) throws Exception
MediawikiApi
edit
in interface MediawikiApi
minor
- - 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.Exception
MediawikiApi.getPageContent(java.lang.String)
public void upload(File fileToUpload, String filename, String contents, String comment) throws Exception
upload
in interface MediawikiApi
fileToUpload
- 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
- Exception
public void upload(Ii ii, String fileName, String pageContent) throws Exception
MediawikiApi
upload
in interface MediawikiApi
pageContent
- the contents of the image description page, set to "" if
overwriting an existing fileException
public List<P> getAllPages(String apfrom, int aplimit) throws Exception
getAllPages
in interface MediawikiApi
apfrom
- - may be null or emptyaplimit
- Exception
public List<Img> getAllImagesByTimeStamp(String aistart, String aiend, int ailimit) throws Exception
MediawikiApi
getAllImagesByTimeStamp
in interface MediawikiApi
aistart
- - start time stampaiend
- - end time stampailimit
- - how many images to getException
public List<Bl> getBacklinks(String pageTitle, String params, int bllimit) throws Exception
MediawikiApi
getBacklinks
in interface MediawikiApi
params
- - extra paramsException
public List<Iu> getImageUsage(String imageTitle, String params, int limit) throws Exception
MediawikiApi
getImageUsage
in interface MediawikiApi
params
- - extra paramsException
public 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
- Exception
public Ii getImageInfo(String pageTitle) throws Exception
MediawikiApi
getImageInfo
in interface MediawikiApi
pageTitle
- - the pageTitle to get the ImageInfo forException
public List<Im> getImagesOnPage(String pageTitle, int imLimit) throws Exception
MediawikiApi
getImagesOnPage
in interface MediawikiApi
Exception
public List<Ii> getImageInfosForPage(String pageTitle, int imLimit) throws Exception
MediawikiApi
getImageInfosForPage
in interface MediawikiApi
Exception
public 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
- Exception
public List<Rc> sortByTitleAndFilterDoubles(List<Rc> rcList)
rcList
- public String dateToMWTimeStamp(Date date)
date
- Copyright © 2018 BITPlan GmbH. All rights reserved.