java.lang.Object
org.wikidata.wdtk.datamodel.implementation.SitesImpl
All Implemented Interfaces:
Sites

public class SitesImpl extends Object implements Sites
Implementation of the Sites interface that allows sites to be registered. Objects of this type are not immutable, since they are not data objects, but the Sites interface only supports read access.

This object supports protocol-relative URLs by adding the default protocol DEFAULT_PROTOCOL_PREFIX for these cases.

Author:
Markus Kroetzsch
  • Field Details

    • DEFAULT_PROTOCOL_PREFIX

      public static String DEFAULT_PROTOCOL_PREFIX
      MediaWiki supports relative URLs in site configurations, which do not start with "http://" or "https://", but with "//". The intended usage is that generated links to this site will use either http or https depending on the access method used to call the page. In Java, we do not have any context, and we therefore define a default protocol to be used in such cases.
  • Constructor Details

    • SitesImpl

      public SitesImpl()
  • Method Details

    • setSiteInformation

      public void setSiteInformation(String siteKey, String group, String languageCode, String siteType, String filePath, String pagePath)
      Description copied from interface: Sites
      Sets the stored information for the site of the given key to the given values.

      Note that the path URLs given here should be absolute. In MediaWiki, it is common to use protocol-relative paths (starting with "//" rather than with "http://" or "https://"). The code in this class is not prepared to handle this yet (URL-returning methods would need to allow for a preferred protocol to be specified).

      Specified by:
      setSiteInformation in interface Sites
      Parameters:
      siteKey - the global site key, e.g., "enwiki" or "fawikivoyage"
      group - the site group, e.g., "wikipedia" or "wikivoyage"
      languageCode - the site MediaWiki language code, e.g., "en" or "fa"
      siteType - the site type, typically "mediawiki"
      filePath - the file path with $1 as a placeholder for the file name, e.g., "http://en.wikipedia.org/w/$1" or "http://fa.wikivoyage.org/w/$1"
      pagePath - the page path with $1 as a placeholder for the page title, e.g., "http://en.wikipedia.org/wiki/$1" or "http://fa.wikivoyage.org/wiki/$1"
    • getLanguageCode

      public String getLanguageCode(String siteKey)
      Description copied from interface: Sites
      Returns the MediaWiki language code for the given site, or null if there is no such data for this site key.

      The language code follows the MediaWiki conventions for language codes, which do not follow any standard. Most codes agree with those in BCP 47 , but there are a number of exceptions.

      Specified by:
      getLanguageCode in interface Sites
      Parameters:
      siteKey - the global site key
      Returns:
      the corresponding MediaWiki language code, or null if not known
    • getGroup

      public String getGroup(String siteKey)
      Description copied from interface: Sites
      Returns the group for the given site, or null if there is no such data for this site key. The group is a string identifier used for configuration purposes. Typical groups on Wikimedia sites include "wikipedia", "wikisource", "wikivoyage", and "wikiquote", used for most sites of these projects, but also singleton groups like "commons" and "wikimania2013".
      Specified by:
      getGroup in interface Sites
      Parameters:
      siteKey - the global site key
      Returns:
      the corresponding group, or null if not known
    • getPageUrl

      public String getPageUrl(String siteKey, String pageTitle)
      Description copied from interface: Sites
      Returns the URL for the page of the given name, or null if the site is not known. All characters in the page title will be escaped for use in URLs.
      Specified by:
      getPageUrl in interface Sites
      Parameters:
      siteKey - the global site key
      pageTitle - the title of the page, including namespace prefixes if any
      Returns:
      the URL to link to this page on the given site, or null if not known
    • getSiteLinkUrl

      public String getSiteLinkUrl(SiteLink siteLink)
      Description copied from interface: Sites
      Returns the URL for the given site link, or null if its site key is not known.
      Specified by:
      getSiteLinkUrl in interface Sites
      Parameters:
      siteLink - the SiteLink object
      Returns:
      the page URL for this site link, or null if not known
    • getFileUrl

      public String getFileUrl(String siteKey, String fileName)
      Description copied from interface: Sites
      Returns the URL for the file of the given name, or null if the site is not known. The file name is not escaped for use in URLs, so that one can use this method to construct URLs with parameters, e.g., when calling the API of the site. Also note that this method does not construct URLs for files uploaded to a MediaWiki site using the given file name; such files are usually placed in some subdirectory.
      Specified by:
      getFileUrl in interface Sites
      Parameters:
      siteKey - the global site key
      fileName - the name of the file
      Returns:
      the URL to link to this page on the given site, or null if not known
    • getSiteType

      public String getSiteType(String siteKey)
      Description copied from interface: Sites
      Returns the type for the given site, or null if there is no such data for this site key. For MediaWiki sites, this is "mediawiki".
      Specified by:
      getSiteType in interface Sites
      Parameters:
      siteKey - the global site key
      Returns:
      the corresponding type, or null if not known