Package org.openrefine.wikibase.editing
Class MediaFileUtils
- java.lang.Object
-
- org.openrefine.wikibase.editing.MediaFileUtils
-
public class MediaFileUtils extends Object
Collection of wrappers around MediaWiki actions which are not supported by WDTK.- Author:
- Antonin Delpeuch
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMediaFileUtils.MediaUploadResponse
-
Field Summary
Fields Modifier and Type Field Description protected org.wikidata.wdtk.wikibaseapi.ApiConnectionapiConnectionprotected StringcsrfTokenprotected StringfilePrefixprotected intmaxLagWaitTime
-
Constructor Summary
Constructors Constructor Description MediaFileUtils(org.wikidata.wdtk.wikibaseapi.ApiConnection wdtkConnection)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Set<String>checkIfPageNamesExist(List<String> pageNames)Checks which of the provided page names already exist on the wiki.voideditPage(long pageId, String wikitext, String summary, List<String> tags)Edits the text contents of a wiki pageprotected StringfetchCsrfToken()org.wikidata.wdtk.wikibaseapi.ApiConnectiongetApiConnection()protected StringgetCsrfToken()voidpurgePage(long pageid)Purge the cache associated with a given MediaWiki page.voidsetMaxLagWaitTime(int milliseconds)Sets how long we should wait before retrying in case of a maxlag error.protected MediaFileUtils.MediaUploadResponseuploadFile(Map<String,String> parameters, Map<String,org.apache.commons.lang3.tuple.ImmutablePair<String,File>> files)Internal method, common to both local and remote file upload.MediaFileUtils.MediaUploadResponseuploadLocalFile(File path, String fileName, String wikitext, String summary, List<String> tags)Upload a local file to the MediaWiki instance.MediaFileUtils.MediaUploadResponseuploadRemoteFile(URL url, String fileName, String wikitext, String summary, List<String> tags)Upload a file that the MediaWiki server fetches directly from the supplied URL.
-
-
-
Method Detail
-
getApiConnection
public org.wikidata.wdtk.wikibaseapi.ApiConnection getApiConnection()
-
setMaxLagWaitTime
public void setMaxLagWaitTime(int milliseconds)
Sets how long we should wait before retrying in case of a maxlag error.- Parameters:
milliseconds-
-
purgePage
public void purgePage(long pageid) throws IOException, org.wikidata.wdtk.wikibaseapi.apierrors.MediaWikiApiErrorExceptionPurge the cache associated with a given MediaWiki page.- Throws:
org.wikidata.wdtk.wikibaseapi.apierrors.MediaWikiApiErrorExceptionIOException
-
uploadLocalFile
public MediaFileUtils.MediaUploadResponse uploadLocalFile(File path, String fileName, String wikitext, String summary, List<String> tags) throws IOException, org.wikidata.wdtk.wikibaseapi.apierrors.MediaWikiApiErrorException
Upload a local file to the MediaWiki instance.- Parameters:
path- the path to the local filefileName- its filename once stored on the wikiwikitext- the accompanying wikitext for the filesummary- the edit summary associated with the uploadtags- tags to apply to the edit- Returns:
- Throws:
IOExceptionorg.wikidata.wdtk.wikibaseapi.apierrors.MediaWikiApiErrorException
-
uploadRemoteFile
public MediaFileUtils.MediaUploadResponse uploadRemoteFile(URL url, String fileName, String wikitext, String summary, List<String> tags) throws IOException, org.wikidata.wdtk.wikibaseapi.apierrors.MediaWikiApiErrorException
Upload a file that the MediaWiki server fetches directly from the supplied URL. The URL domain must likely be whitelisted before.- Parameters:
url- the URL of the file to uploadfileName- its filename once stored on the wikiwikitext- the accompanying wikitext for the filesummary- the edit summary associated with the uploadtags- tags to apply to the edit- Returns:
- Throws:
IOExceptionorg.wikidata.wdtk.wikibaseapi.apierrors.MediaWikiApiErrorException
-
editPage
public void editPage(long pageId, String wikitext, String summary, List<String> tags) throws IOException, org.wikidata.wdtk.wikibaseapi.apierrors.MediaWikiApiErrorExceptionEdits the text contents of a wiki page- Parameters:
pageId- the pageId of the page to editwikitext- the new contents which should override the existing onesummary- the edit summarytags- any tags that should be applied to the edit- Throws:
IOException- if a network error happenedorg.wikidata.wdtk.wikibaseapi.apierrors.MediaWikiApiErrorException- if the editing failed for some reason, after a few retries
-
checkIfPageNamesExist
public Set<String> checkIfPageNamesExist(List<String> pageNames) throws IOException, org.wikidata.wdtk.wikibaseapi.apierrors.MediaWikiApiErrorException
Checks which of the provided page names already exist on the wiki.- Parameters:
pageNames- the page names (including namespace prefix)- Returns:
- Throws:
IOExceptionorg.wikidata.wdtk.wikibaseapi.apierrors.MediaWikiApiErrorException
-
uploadFile
protected MediaFileUtils.MediaUploadResponse uploadFile(Map<String,String> parameters, Map<String,org.apache.commons.lang3.tuple.ImmutablePair<String,File>> files) throws IOException, org.wikidata.wdtk.wikibaseapi.apierrors.MediaWikiApiErrorException
Internal method, common to both local and remote file upload.- Parameters:
parameters-files-- Returns:
- Throws:
IOExceptionorg.wikidata.wdtk.wikibaseapi.apierrors.MediaWikiApiErrorException
-
getCsrfToken
protected String getCsrfToken() throws IOException, org.wikidata.wdtk.wikibaseapi.apierrors.MediaWikiApiErrorException
- Throws:
IOExceptionorg.wikidata.wdtk.wikibaseapi.apierrors.MediaWikiApiErrorException
-
fetchCsrfToken
protected String fetchCsrfToken() throws IOException, org.wikidata.wdtk.wikibaseapi.apierrors.MediaWikiApiErrorException
- Throws:
IOExceptionorg.wikidata.wdtk.wikibaseapi.apierrors.MediaWikiApiErrorException
-
-