mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Xomw: Add initial Interwiki classes
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.mediawiki.includes.site; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
/**
|
||||
* Provides a file-based cache of a SiteStore. The sites are stored in
|
||||
* a json file. (see docs/sitescache.txt regarding format)
|
||||
*
|
||||
* The cache can be built with the rebuildSitesCache.php maintenance script,
|
||||
* and a MediaWiki instance can be setup to use this by setting the
|
||||
* 'wgSitesCacheFile' configuration to the cache file location.
|
||||
*
|
||||
* @since 1.25
|
||||
*/
|
||||
public class XomwFileBasedSiteLookup implements XomwSiteLookup {
|
||||
/**
|
||||
* @var SiteList
|
||||
*/
|
||||
private XomwSiteList sites = null;
|
||||
|
||||
// /**
|
||||
// * @var String
|
||||
// */
|
||||
// private $cacheFile;
|
||||
//
|
||||
// /**
|
||||
// * @param String $cacheFile
|
||||
// */
|
||||
// public function __construct($cacheFile) {
|
||||
// this.cacheFile = $cacheFile;
|
||||
// }
|
||||
|
||||
/**
|
||||
* @since 1.25
|
||||
*
|
||||
* @return SiteList
|
||||
*/
|
||||
public XomwSiteList getSites() {
|
||||
// if (this.sites === null) {
|
||||
// this.sites = this.loadSitesFromCache();
|
||||
// }
|
||||
|
||||
return this.sites;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param String $globalId
|
||||
*
|
||||
* @since 1.25
|
||||
*
|
||||
* @return Site|null
|
||||
*/
|
||||
public XomwSite getSite(byte[] globalId) {
|
||||
// $sites = this.getSites();
|
||||
//
|
||||
// return $sites->hasSite($globalId) ? $sites->getSite($globalId) : null;
|
||||
return null;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return SiteList
|
||||
// */
|
||||
// private function loadSitesFromCache() {
|
||||
// $data = this.loadJsonFile();
|
||||
//
|
||||
// $sites = new SiteList();
|
||||
//
|
||||
// // @todo lazy initialize the site objects in the site list (e.g. only when needed to access)
|
||||
// foreach ($data['sites'] as $siteArray) {
|
||||
// $sites[] = this.newSiteFromArray($siteArray);
|
||||
// }
|
||||
//
|
||||
// return $sites;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @throws MWException
|
||||
// * @return array see docs/sitescache.txt for format of the array.
|
||||
// */
|
||||
// private function loadJsonFile() {
|
||||
// if (!is_readable(this.cacheFile)) {
|
||||
// throw new MWException('SiteList cache file not found.');
|
||||
// }
|
||||
//
|
||||
// $contents = file_get_contents(this.cacheFile);
|
||||
// $data = json_decode($contents, true);
|
||||
//
|
||||
// if (!is_array($data) || !is_array($data['sites'])
|
||||
// || !array_key_exists('sites', $data)
|
||||
// ) {
|
||||
// throw new MWException('SiteStore json cache data is invalid.');
|
||||
// }
|
||||
//
|
||||
// return $data;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @param array $data
|
||||
// *
|
||||
// * @return Site
|
||||
// */
|
||||
// private function newSiteFromArray(array $data) {
|
||||
// $siteType = array_key_exists('type', $data) ? $data['type'] : Site::TYPE_UNKNOWN;
|
||||
// $site = Site::newForType($siteType);
|
||||
//
|
||||
// $site->setGlobalId($data['globalid']);
|
||||
// $site->setForward($data['forward']);
|
||||
// $site->setGroup($data['group']);
|
||||
// $site->setLanguageCode($data['language']);
|
||||
// $site->setSource($data['source']);
|
||||
// $site->setExtraData($data['data']);
|
||||
// $site->setExtraConfig($data['config']);
|
||||
//
|
||||
// foreach ($data['identifiers'] as $identifier) {
|
||||
// $site->addLocalId($identifier['type'], $identifier['key']);
|
||||
// }
|
||||
//
|
||||
// return $site;
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,691 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.mediawiki.includes.site; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
/**
|
||||
* Represents a single site.
|
||||
*/
|
||||
public class XomwSite {
|
||||
// static final TYPE_UNKNOWN = 'unknown';
|
||||
// static final TYPE_MEDIAWIKI = 'mediawiki';
|
||||
//
|
||||
// static final GROUP_NONE = 'none';
|
||||
//
|
||||
// static final ID_INTERWIKI = 'interwiki';
|
||||
// static final ID_EQUIVALENT = 'equivalent';
|
||||
//
|
||||
// static final SOURCE_LOCAL = 'local';
|
||||
//
|
||||
// static final PATH_LINK = 'link';
|
||||
//
|
||||
// /**
|
||||
// * A version ID that identifies the serialization structure used by getSerializationData()
|
||||
// * and unserialize(). This is useful for constructing cache keys in cases where the cache relies
|
||||
// * on serialization for storing the SiteList.
|
||||
// *
|
||||
// * @var String A String uniquely identifying the version of the serialization structure.
|
||||
// */
|
||||
// static final SERIAL_VERSION_ID = '2013-01-23';
|
||||
//
|
||||
// /**
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @var String|null
|
||||
// */
|
||||
// protected $globalId = null;
|
||||
//
|
||||
// /**
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @var String
|
||||
// */
|
||||
// protected $type = self::TYPE_UNKNOWN;
|
||||
//
|
||||
// /**
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @var String
|
||||
// */
|
||||
// protected $group = self::GROUP_NONE;
|
||||
//
|
||||
// /**
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @var String
|
||||
// */
|
||||
// protected $source = self::SOURCE_LOCAL;
|
||||
//
|
||||
// /**
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @var String|null
|
||||
// */
|
||||
// protected $languageCode = null;
|
||||
//
|
||||
// /**
|
||||
// * Holds the local ids for this site.
|
||||
// * local id type => [ ids for this type (strings) ]
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @var array[]
|
||||
// */
|
||||
// protected $localIds = [];
|
||||
//
|
||||
// /**
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @var array
|
||||
// */
|
||||
// protected $extraData = [];
|
||||
//
|
||||
// /**
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @var array
|
||||
// */
|
||||
// protected $extraConfig = [];
|
||||
//
|
||||
// /**
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @var boolean
|
||||
// */
|
||||
// protected $forward = false;
|
||||
//
|
||||
// /**
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @var int|null
|
||||
// */
|
||||
// protected $internalId = null;
|
||||
//
|
||||
// /**
|
||||
// * Constructor.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param String $type
|
||||
// */
|
||||
// public function __construct( $type = self::TYPE_UNKNOWN ) {
|
||||
// $this->type = $type;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns the global site identifier (ie enwiktionary).
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @return String|null
|
||||
// */
|
||||
// public function getGlobalId() {
|
||||
// return $this->globalId;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Sets the global site identifier (ie enwiktionary).
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param String|null $globalId
|
||||
// *
|
||||
// * @throws MWException
|
||||
// */
|
||||
// public function setGlobalId( $globalId ) {
|
||||
// if ( $globalId !== null && !is_string( $globalId ) ) {
|
||||
// throw new MWException( '$globalId needs to be String or null' );
|
||||
// }
|
||||
//
|
||||
// $this->globalId = $globalId;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns the type of the site (ie mediawiki).
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @return String
|
||||
// */
|
||||
// public function getType() {
|
||||
// return $this->type;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Gets the group of the site (ie wikipedia).
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @return String
|
||||
// */
|
||||
// public function getGroup() {
|
||||
// return $this->group;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Sets the group of the site (ie wikipedia).
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param String $group
|
||||
// *
|
||||
// * @throws MWException
|
||||
// */
|
||||
// public function setGroup( $group ) {
|
||||
// if ( !is_string( $group ) ) {
|
||||
// throw new MWException( '$group needs to be a String' );
|
||||
// }
|
||||
//
|
||||
// $this->group = $group;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns the source of the site data (ie 'local', 'wikidata', 'my-magical-repo').
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @return String
|
||||
// */
|
||||
// public function getSource() {
|
||||
// return $this->source;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Sets the source of the site data (ie 'local', 'wikidata', 'my-magical-repo').
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param String $source
|
||||
// *
|
||||
// * @throws MWException
|
||||
// */
|
||||
// public function setSource( $source ) {
|
||||
// if ( !is_string( $source ) ) {
|
||||
// throw new MWException( '$source needs to be a String' );
|
||||
// }
|
||||
//
|
||||
// $this->source = $source;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Gets if site.tld/path/key:pageTitle should forward users to the page on
|
||||
// * the actual site, where "key" is the local identifier.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @return boolean
|
||||
// */
|
||||
// public function shouldForward() {
|
||||
// return $this->forward;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Sets if site.tld/path/key:pageTitle should forward users to the page on
|
||||
// * the actual site, where "key" is the local identifier.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param boolean $shouldForward
|
||||
// *
|
||||
// * @throws MWException
|
||||
// */
|
||||
// public function setForward( $shouldForward ) {
|
||||
// if ( !is_bool( $shouldForward ) ) {
|
||||
// throw new MWException( '$shouldForward needs to be a boolean' );
|
||||
// }
|
||||
//
|
||||
// $this->forward = $shouldForward;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns the domain of the site, ie en.wikipedia.org
|
||||
// * Or false if it's not known.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @return String|null
|
||||
// */
|
||||
// public function getDomain() {
|
||||
// $path = $this->getLinkPath();
|
||||
//
|
||||
// if ( $path === null ) {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// return parse_url( $path, PHP_URL_HOST );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns the protocol of the site.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @throws MWException
|
||||
// * @return String
|
||||
// */
|
||||
// public function getProtocol() {
|
||||
// $path = $this->getLinkPath();
|
||||
//
|
||||
// if ( $path === null ) {
|
||||
// return '';
|
||||
// }
|
||||
//
|
||||
// $protocol = parse_url( $path, PHP_URL_SCHEME );
|
||||
//
|
||||
// // Malformed URL
|
||||
// if ( $protocol === false ) {
|
||||
// throw new MWException( "failed to parse URL '$path'" );
|
||||
// }
|
||||
//
|
||||
// // No schema
|
||||
// if ( $protocol === null ) {
|
||||
// // Used for protocol relative URLs
|
||||
// $protocol = '';
|
||||
// }
|
||||
//
|
||||
// return $protocol;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Sets the path used to construct links with.
|
||||
// * Shall be equivalent to setPath( getLinkPathType(), $fullUrl ).
|
||||
// *
|
||||
// * @param String $fullUrl
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @throws MWException
|
||||
// */
|
||||
// public function setLinkPath( $fullUrl ) {
|
||||
// $type = $this->getLinkPathType();
|
||||
//
|
||||
// if ( $type === null ) {
|
||||
// throw new MWException( "This Site does not support link paths." );
|
||||
// }
|
||||
//
|
||||
// $this->setPath( $type, $fullUrl );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns the path used to construct links with or false if there is no such path.
|
||||
// *
|
||||
// * Shall be equivalent to getPath( getLinkPathType() ).
|
||||
// *
|
||||
// * @return String|null
|
||||
// */
|
||||
// public function getLinkPath() {
|
||||
// $type = $this->getLinkPathType();
|
||||
// return $type === null ? null: $this->getPath( $type );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns the main path type, that is the type of the path that should
|
||||
// * generally be used to construct links to the target site.
|
||||
// *
|
||||
// * This default implementation returns Site::PATH_LINK as the default path
|
||||
// * type. Subclasses can override this to define a different default path
|
||||
// * type, or return false to disable site links.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @return String|null
|
||||
// */
|
||||
// public function getLinkPathType() {
|
||||
// return self::PATH_LINK;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns the full URL for the given page on the site.
|
||||
// * Or false if the needed information is not known.
|
||||
// *
|
||||
// * This generated URL is usually based upon the path returned by getLinkPath(),
|
||||
// * but this is not a requirement.
|
||||
// *
|
||||
// * This implementation returns a URL constructed using the path returned by getLinkPath().
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param boolean|String $pageName
|
||||
// *
|
||||
// * @return String|boolean
|
||||
// */
|
||||
// public function getPageUrl( $pageName = false ) {
|
||||
// $url = $this->getLinkPath();
|
||||
//
|
||||
// if ( $url === false ) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// if ( $pageName !== false ) {
|
||||
// $url = str_replace( '$1', rawurlencode( $pageName ), $url );
|
||||
// }
|
||||
//
|
||||
// return $url;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns $pageName without changes.
|
||||
// * Subclasses may override this to apply some kind of normalization.
|
||||
// *
|
||||
// * @see Site::normalizePageName
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param String $pageName
|
||||
// *
|
||||
// * @return String
|
||||
// */
|
||||
// public function normalizePageName( $pageName ) {
|
||||
// return $pageName;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns the type specific fields.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @return array
|
||||
// */
|
||||
// public function getExtraData() {
|
||||
// return $this->extraData;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Sets the type specific fields.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param array $extraData
|
||||
// */
|
||||
// public function setExtraData( array $extraData ) {
|
||||
// $this->extraData = $extraData;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns the type specific config.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @return array
|
||||
// */
|
||||
// public function getExtraConfig() {
|
||||
// return $this->extraConfig;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Sets the type specific config.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param array $extraConfig
|
||||
// */
|
||||
// public function setExtraConfig( array $extraConfig ) {
|
||||
// $this->extraConfig = $extraConfig;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns language code of the sites primary language.
|
||||
// * Or null if it's not known.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @return String|null
|
||||
// */
|
||||
// public function getLanguageCode() {
|
||||
// return $this->languageCode;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Sets language code of the sites primary language.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param String $languageCode
|
||||
// */
|
||||
// public function setLanguageCode( $languageCode ) {
|
||||
// $this->languageCode = $languageCode;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns the set @gplx.Internal protected identifier for the site.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @return String|null
|
||||
// */
|
||||
// public function getInternalId() {
|
||||
// return $this->internalId;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Sets the @gplx.Internal protected identifier for the site.
|
||||
// * This typically is a primary key in a db table.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param int|null $internalId
|
||||
// */
|
||||
// public function setInternalId( $internalId = null ) {
|
||||
// $this->internalId = $internalId;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Adds a local identifier.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param String $type
|
||||
// * @param String $identifier
|
||||
// */
|
||||
// public function addLocalId( $type, $identifier ) {
|
||||
// if ( $this->localIds === false ) {
|
||||
// $this->localIds = [];
|
||||
// }
|
||||
//
|
||||
// if ( !array_key_exists( $type, $this->localIds ) ) {
|
||||
// $this->localIds[$type] = [];
|
||||
// }
|
||||
//
|
||||
// if ( !in_array( $identifier, $this->localIds[$type] ) ) {
|
||||
// $this->localIds[$type][] = $identifier;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Adds an interwiki id to the site.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param String $identifier
|
||||
// */
|
||||
// public function addInterwikiId( $identifier ) {
|
||||
// $this->addLocalId( self::ID_INTERWIKI, $identifier );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Adds a navigation id to the site.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param String $identifier
|
||||
// */
|
||||
// public function addNavigationId( $identifier ) {
|
||||
// $this->addLocalId( self::ID_EQUIVALENT, $identifier );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns the interwiki link identifiers that can be used for this site.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @return String[]
|
||||
// */
|
||||
// public function getInterwikiIds() {
|
||||
// return array_key_exists( self::ID_INTERWIKI, $this->localIds )
|
||||
// ? $this->localIds[self::ID_INTERWIKI]
|
||||
// : [];
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns the equivalent link identifiers that can be used to make
|
||||
// * the site show up in interfaces such as the "language links" section.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @return String[]
|
||||
// */
|
||||
// public function getNavigationIds() {
|
||||
// return array_key_exists( self::ID_EQUIVALENT, $this->localIds )
|
||||
// ? $this->localIds[self::ID_EQUIVALENT] :
|
||||
// [];
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns all local ids
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @return array[]
|
||||
// */
|
||||
// public function getLocalIds() {
|
||||
// return $this->localIds;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Sets the path used to construct links with.
|
||||
// * Shall be equivalent to setPath( getLinkPathType(), $fullUrl ).
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param String $pathType
|
||||
// * @param String $fullUrl
|
||||
// *
|
||||
// * @throws MWException
|
||||
// */
|
||||
// public function setPath( $pathType, $fullUrl ) {
|
||||
// if ( !is_string( $fullUrl ) ) {
|
||||
// throw new MWException( '$fullUrl needs to be a String' );
|
||||
// }
|
||||
//
|
||||
// if ( !array_key_exists( 'paths', $this->extraData ) ) {
|
||||
// $this->extraData['paths'] = [];
|
||||
// }
|
||||
//
|
||||
// $this->extraData['paths'][$pathType] = $fullUrl;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns the path of the provided type or false if there is no such path.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param String $pathType
|
||||
// *
|
||||
// * @return String|null
|
||||
// */
|
||||
// public function getPath( $pathType ) {
|
||||
// $paths = $this->getAllPaths();
|
||||
// return array_key_exists( $pathType, $paths ) ? $paths[$pathType] : null;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns the paths as associative array.
|
||||
// * The keys are path types, the values are the path urls.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @return String[]
|
||||
// */
|
||||
// public function getAllPaths() {
|
||||
// return array_key_exists( 'paths', $this->extraData ) ? $this->extraData['paths'] : [];
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Removes the path of the provided type if it's set.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param String $pathType
|
||||
// */
|
||||
// public function removePath( $pathType ) {
|
||||
// if ( array_key_exists( 'paths', $this->extraData ) ) {
|
||||
// unset( $this->extraData['paths'][$pathType] );
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param String $siteType
|
||||
// *
|
||||
// * @return Site
|
||||
// */
|
||||
// public static function newForType( $siteType ) {
|
||||
// global $wgSiteTypes;
|
||||
//
|
||||
// if ( array_key_exists( $siteType, $wgSiteTypes ) ) {
|
||||
// return new $wgSiteTypes[$siteType]();
|
||||
// }
|
||||
//
|
||||
// return new Site();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @see Serializable::serialize
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @return String
|
||||
// */
|
||||
// public function serialize() {
|
||||
// $fields = [
|
||||
// 'globalid' => $this->globalId,
|
||||
// 'type' => $this->type,
|
||||
// 'group' => $this->group,
|
||||
// 'source' => $this->source,
|
||||
// 'language' => $this->languageCode,
|
||||
// 'localids' => $this->localIds,
|
||||
// 'config' => $this->extraConfig,
|
||||
// 'data' => $this->extraData,
|
||||
// 'forward' => $this->forward,
|
||||
// 'internalid' => $this->internalId,
|
||||
//
|
||||
// ];
|
||||
//
|
||||
// return serialize( $fields );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @see Serializable::unserialize
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param String $serialized
|
||||
// */
|
||||
// public function unserialize( $serialized ) {
|
||||
// $fields = unserialize( $serialized );
|
||||
//
|
||||
// $this->__construct( $fields['type'] );
|
||||
//
|
||||
// $this->setGlobalId( $fields['globalid'] );
|
||||
// $this->setGroup( $fields['group'] );
|
||||
// $this->setSource( $fields['source'] );
|
||||
// $this->setLanguageCode( $fields['language'] );
|
||||
// $this->localIds = $fields['localids'];
|
||||
// $this->setExtraConfig( $fields['config'] );
|
||||
// $this->setExtraData( $fields['data'] );
|
||||
// $this->setForward( $fields['forward'] );
|
||||
// $this->setInternalId( $fields['internalid'] );
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,345 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.mediawiki.includes.site; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
/**
|
||||
* Collection of Site objects.
|
||||
*/
|
||||
public class XomwSiteList {
|
||||
public int Len() {return 0;}
|
||||
public XomwSite GetAt(int idx) {return null;}
|
||||
// /**
|
||||
// * Internal site identifiers pointing to their sites offset value.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @var array Array of integer
|
||||
// */
|
||||
// protected $byInternalId = [];
|
||||
//
|
||||
// /**
|
||||
// * Global site identifiers pointing to their sites offset value.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @var array Array of String
|
||||
// */
|
||||
// protected $byGlobalId = [];
|
||||
//
|
||||
// /**
|
||||
// * Navigational site identifiers alias inter-language prefixes
|
||||
// * pointing to their sites offset value.
|
||||
// *
|
||||
// * @since 1.23
|
||||
// *
|
||||
// * @var array Array of String
|
||||
// */
|
||||
// protected $byNavigationId = [];
|
||||
//
|
||||
// /**
|
||||
// * @see GenericArrayObject::getObjectType
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @return String
|
||||
// */
|
||||
// public function getObjectType() {
|
||||
// return 'Site';
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @see GenericArrayObject::preSetElement
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param int|String $index
|
||||
// * @param Site $site
|
||||
// *
|
||||
// * @return boolean
|
||||
// */
|
||||
// protected function preSetElement( $index, $site ) {
|
||||
// if ( $this->hasSite( $site->getGlobalId() ) ) {
|
||||
// $this->removeSite( $site->getGlobalId() );
|
||||
// }
|
||||
//
|
||||
// $this->byGlobalId[$site->getGlobalId()] = $index;
|
||||
// $this->byInternalId[$site->getInternalId()] = $index;
|
||||
//
|
||||
// $ids = $site->getNavigationIds();
|
||||
// foreach ( $ids as $navId ) {
|
||||
// $this->byNavigationId[$navId] = $index;
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @see ArrayObject::offsetUnset()
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param mixed $index
|
||||
// */
|
||||
// public function offsetUnset( $index ) {
|
||||
// if ( $this->offsetExists( $index ) ) {
|
||||
// /**
|
||||
// * @var Site $site
|
||||
// */
|
||||
// $site = $this->offsetGet( $index );
|
||||
//
|
||||
// unset( $this->byGlobalId[$site->getGlobalId()] );
|
||||
// unset( $this->byInternalId[$site->getInternalId()] );
|
||||
//
|
||||
// $ids = $site->getNavigationIds();
|
||||
// foreach ( $ids as $navId ) {
|
||||
// unset( $this->byNavigationId[$navId] );
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// parent::offsetUnset( $index );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns all the global site identifiers.
|
||||
// * Optionally only those belonging to the specified group.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @return array
|
||||
// */
|
||||
// public function getGlobalIdentifiers() {
|
||||
// return array_keys( $this->byGlobalId );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns if the list contains the site with the provided global site identifier.
|
||||
// *
|
||||
// * @param String $globalSiteId
|
||||
// *
|
||||
// * @return boolean
|
||||
// */
|
||||
// public function hasSite( $globalSiteId ) {
|
||||
// return array_key_exists( $globalSiteId, $this->byGlobalId );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns the Site with the provided global site identifier.
|
||||
// * The site needs to exist, so if not sure, call hasGlobalId first.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param String $globalSiteId
|
||||
// *
|
||||
// * @return Site
|
||||
// */
|
||||
// public function getSite( $globalSiteId ) {
|
||||
// return $this->offsetGet( $this->byGlobalId[$globalSiteId] );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Removes the site with the specified global site identifier.
|
||||
// * The site needs to exist, so if not sure, call hasGlobalId first.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param String $globalSiteId
|
||||
// */
|
||||
// public function removeSite( $globalSiteId ) {
|
||||
// $this->offsetUnset( $this->byGlobalId[$globalSiteId] );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns if the list contains no sites.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @return boolean
|
||||
// */
|
||||
// public function isEmpty() {
|
||||
// return $this->byGlobalId === [];
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns if the list contains the site with the provided site id.
|
||||
// *
|
||||
// * @param int $id
|
||||
// *
|
||||
// * @return boolean
|
||||
// */
|
||||
// public function hasInternalId( $id ) {
|
||||
// return array_key_exists( $id, $this->byInternalId );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns the Site with the provided site id.
|
||||
// * The site needs to exist, so if not sure, call has first.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param int $id
|
||||
// *
|
||||
// * @return Site
|
||||
// */
|
||||
// public function getSiteByInternalId( $id ) {
|
||||
// return $this->offsetGet( $this->byInternalId[$id] );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Removes the site with the specified site id.
|
||||
// * The site needs to exist, so if not sure, call has first.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param int $id
|
||||
// */
|
||||
// public function removeSiteByInternalId( $id ) {
|
||||
// $this->offsetUnset( $this->byInternalId[$id] );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns if the list contains the site with the provided navigational site id.
|
||||
// *
|
||||
// * @param String $id
|
||||
// *
|
||||
// * @return boolean
|
||||
// */
|
||||
// public function hasNavigationId( $id ) {
|
||||
// return array_key_exists( $id, $this->byNavigationId );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns the Site with the provided navigational site id.
|
||||
// * The site needs to exist, so if not sure, call has first.
|
||||
// *
|
||||
// * @since 1.23
|
||||
// *
|
||||
// * @param String $id
|
||||
// *
|
||||
// * @return Site
|
||||
// */
|
||||
// public function getSiteByNavigationId( $id ) {
|
||||
// return $this->offsetGet( $this->byNavigationId[$id] );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Removes the site with the specified navigational site id.
|
||||
// * The site needs to exist, so if not sure, call has first.
|
||||
// *
|
||||
// * @since 1.23
|
||||
// *
|
||||
// * @param String $id
|
||||
// */
|
||||
// public function removeSiteByNavigationId( $id ) {
|
||||
// $this->offsetUnset( $this->byNavigationId[$id] );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Sets a site in the list. If the site was not there,
|
||||
// * it will be added. If it was, it will be updated.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param Site $site
|
||||
// */
|
||||
// public function setSite( Site $site ) {
|
||||
// $this[] = $site;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns the sites that are in the provided group.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param String $groupName
|
||||
// *
|
||||
// * @return SiteList
|
||||
// */
|
||||
// public function getGroup( $groupName ) {
|
||||
// $group = new self();
|
||||
//
|
||||
// /**
|
||||
// * @var Site $site
|
||||
// */
|
||||
// foreach ( $this as $site ) {
|
||||
// if ( $site->getGroup() === $groupName ) {
|
||||
// $group[] = $site;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return $group;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * A version ID that identifies the serialization structure used by getSerializationData()
|
||||
// * and unserialize(). This is useful for constructing cache keys in cases where the cache relies
|
||||
// * on serialization for storing the SiteList.
|
||||
// *
|
||||
// * @var String A String uniquely identifying the version of the serialization structure,
|
||||
// * not including any sub-structures.
|
||||
// */
|
||||
// static final SERIAL_VERSION_ID = '2014-03-17';
|
||||
//
|
||||
// /**
|
||||
// * Returns the version ID that identifies the serialization structure used by
|
||||
// * getSerializationData() and unserialize(), including the structure of any nested structures.
|
||||
// * This is useful for constructing cache keys in cases where the cache relies
|
||||
// * on serialization for storing the SiteList.
|
||||
// *
|
||||
// * @return String A String uniquely identifying the version of the serialization structure,
|
||||
// * including any sub-structures.
|
||||
// */
|
||||
// public static function getSerialVersionId() {
|
||||
// return self::SERIAL_VERSION_ID . '+Site:' . Site::SERIAL_VERSION_ID;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @see GenericArrayObject::getSerializationData
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @return array
|
||||
// */
|
||||
// protected function getSerializationData() {
|
||||
// // NOTE: When changing the structure, either implement unserialize() to handle the
|
||||
// // old structure too, or update SERIAL_VERSION_ID to kill any caches.
|
||||
// return array_merge(
|
||||
// parent::getSerializationData(),
|
||||
// [
|
||||
// 'internalIds' => $this->byInternalId,
|
||||
// 'globalIds' => $this->byGlobalId,
|
||||
// 'navigationIds' => $this->byNavigationId
|
||||
// ]
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @see GenericArrayObject::unserialize
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param String $serialization
|
||||
// *
|
||||
// * @return array
|
||||
// */
|
||||
// public function unserialize( $serialization ) {
|
||||
// $serializationData = parent::unserialize( $serialization );
|
||||
//
|
||||
// $this->byInternalId = $serializationData['internalIds'];
|
||||
// $this->byGlobalId = $serializationData['globalIds'];
|
||||
// $this->byNavigationId = $serializationData['navigationIds'];
|
||||
//
|
||||
// return $serializationData;
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.mediawiki.includes.site; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
/**
|
||||
* Interface for service objects providing a lookup of Site objects.
|
||||
*/
|
||||
public interface XomwSiteLookup {
|
||||
|
||||
/**
|
||||
* Returns the site with provided global id, or null if there is no such site.
|
||||
*
|
||||
* @since 1.25
|
||||
*
|
||||
* @param String $globalId
|
||||
*
|
||||
* @return Site|null
|
||||
*/
|
||||
XomwSite getSite(byte[] globalId);
|
||||
|
||||
/**
|
||||
* Returns a list of all sites.
|
||||
*
|
||||
* @since 1.25
|
||||
*
|
||||
* @return SiteList
|
||||
*/
|
||||
XomwSiteList getSites();
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user