Class MediaFileUtils


  • public class MediaFileUtils
    extends Object
    Collection of wrappers around MediaWiki actions which are not supported by WDTK.
    Author:
    Antonin Delpeuch
    • Field Detail

      • apiConnection

        protected org.wikidata.wdtk.wikibaseapi.ApiConnection apiConnection
      • csrfToken

        protected String csrfToken
      • maxLagWaitTime

        protected int maxLagWaitTime
      • filePrefix

        protected String filePrefix
    • Constructor Detail

      • MediaFileUtils

        public MediaFileUtils​(org.wikidata.wdtk.wikibaseapi.ApiConnection wdtkConnection)
    • 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.MediaWikiApiErrorException
        Purge the cache associated with a given MediaWiki page.
        Throws:
        org.wikidata.wdtk.wikibaseapi.apierrors.MediaWikiApiErrorException
        IOException
      • 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 file
        fileName - its filename once stored on the wiki
        wikitext - the accompanying wikitext for the file
        summary - the edit summary associated with the upload
        tags - tags to apply to the edit
        Returns:
        Throws:
        IOException
        org.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 upload
        fileName - its filename once stored on the wiki
        wikitext - the accompanying wikitext for the file
        summary - the edit summary associated with the upload
        tags - tags to apply to the edit
        Returns:
        Throws:
        IOException
        org.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.MediaWikiApiErrorException
        Edits the text contents of a wiki page
        Parameters:
        pageId - the pageId of the page to edit
        wikitext - the new contents which should override the existing one
        summary - the edit summary
        tags - any tags that should be applied to the edit
        Throws:
        IOException - if a network error happened
        org.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:
        IOException
        org.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:
        IOException
        org.wikidata.wdtk.wikibaseapi.apierrors.MediaWikiApiErrorException
      • getCsrfToken

        protected String getCsrfToken()
                               throws IOException,
                                      org.wikidata.wdtk.wikibaseapi.apierrors.MediaWikiApiErrorException
        Throws:
        IOException
        org.wikidata.wdtk.wikibaseapi.apierrors.MediaWikiApiErrorException
      • fetchCsrfToken

        protected String fetchCsrfToken()
                                 throws IOException,
                                        org.wikidata.wdtk.wikibaseapi.apierrors.MediaWikiApiErrorException
        Throws:
        IOException
        org.wikidata.wdtk.wikibaseapi.apierrors.MediaWikiApiErrorException