diff --git a/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/XomwEnv.java b/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/XomwEnv.java index 9f262c507..c5d65fd48 100644 --- a/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/XomwEnv.java +++ b/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/XomwEnv.java @@ -15,7 +15,9 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt */ package gplx.xowa.mediawiki; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.includes.*; +import gplx.xowa.mediawiki.includes.interwiki.*; import gplx.xowa.mediawiki.includes.filerepo.file.*; import gplx.xowa.mediawiki.includes.media.*; +import gplx.xowa.mediawiki.includes.site.*; import gplx.xowa.mediawiki.languages.*; import gplx.xowa.langs.*; public class XomwEnv { @@ -28,7 +30,9 @@ public class XomwEnv { public XomwEnv(Xol_lang_itm xoLang) { XomwLanguage language = new XomwLanguage(xoLang); - this.mediaWikiServices = new XomwMediaWikiServices(language); + XomwFileBasedSiteLookup siteLookup = new XomwFileBasedSiteLookup(); + XomwInterwikiLookup interwikiLookup = new XomwInterwikiLookupAdapter(siteLookup); + this.mediaWikiServices = new XomwMediaWikiServices(interwikiLookup, language); } public XomwMagicWordMgr Magic_word_mgr() {return magic_word_mgr;} private final XomwMagicWordMgr magic_word_mgr = new XomwMagicWordMgr(); diff --git a/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/XomwMediaWikiServices.java b/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/XomwMediaWikiServices.java index c221e9c61..1eef32922 100644 --- a/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/XomwMediaWikiServices.java +++ b/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/XomwMediaWikiServices.java @@ -15,6 +15,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt */ package gplx.xowa.mediawiki.includes; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.languages.*; +import gplx.xowa.mediawiki.includes.interwiki.*; import gplx.xowa.mediawiki.includes.title.*; /** * MediaWikiServices is the service locator for the application scope of MediaWiki. @@ -32,9 +33,11 @@ import gplx.xowa.mediawiki.includes.title.*; public class XomwMediaWikiServices { // XO.MW.SKIP:remove global getInstance(). See XomwEnv private final XomwMediaWikiTitleCodec titleParser; + private final XomwInterwikiLookup interwikiLookup; - public XomwMediaWikiServices(XomwLanguage language) { - this.titleParser = new XomwMediaWikiTitleCodec(language); + public XomwMediaWikiServices(XomwInterwikiLookup interwikiLookup, XomwLanguage language) { + this.interwikiLookup = interwikiLookup; + this.titleParser = new XomwMediaWikiTitleCodec(this, language); } // /** @@ -132,7 +135,7 @@ public class XomwMediaWikiServices { // * @param MediaWikiServices $other // */ // private function salvage( self $other ) { -// foreach ( $this->getServiceNames() as $name ) { +// foreach ( this.getServiceNames() as $name ) { // // The service could be new in the new instance and not registered in the // // other instance (e.g. an extension that was loaded after the instantiation of // // the other instance. Skip this service in this case. See T143974 @@ -144,7 +147,7 @@ public class XomwMediaWikiServices { // // if ( $oldService instanceof SalvageableService ) { // /** @var SalvageableService $newService */ -// $newService = $this->getService( $name ); +// $newService = this.getService( $name ); // $newService->salvage( $oldService ); // } // } @@ -257,7 +260,7 @@ public class XomwMediaWikiServices { // throw new MWException( 'resetServiceForTesting() must not be used outside unit tests.' ); // } // -// $this->resetService( $name, $destroy ); +// this.resetService( $name, $destroy ); // } // // /** @@ -307,7 +310,7 @@ public class XomwMediaWikiServices { // parent::__construct(); // // // Register the given Config Object as the bootstrap config service. -// $this->defineService( 'BootstrapConfig', function() use ( $config ) { +// this.defineService( 'BootstrapConfig', function() use ( $config ) { // return $config; // } ); // } @@ -328,7 +331,7 @@ public class XomwMediaWikiServices { // * @return Config // */ // public function getBootstrapConfig() { -// return $this->getService( 'BootstrapConfig' ); +// return this.getService( 'BootstrapConfig' ); // } // // /** @@ -336,7 +339,7 @@ public class XomwMediaWikiServices { // * @return ConfigFactory // */ // public function getConfigFactory() { -// return $this->getService( 'ConfigFactory' ); +// return this.getService( 'ConfigFactory' ); // } // // /** @@ -347,7 +350,7 @@ public class XomwMediaWikiServices { // * @return Config // */ // public function getMainConfig() { -// return $this->getService( 'MainConfig' ); +// return this.getService( 'MainConfig' ); // } // // /** @@ -355,7 +358,7 @@ public class XomwMediaWikiServices { // * @return SiteLookup // */ // public function getSiteLookup() { -// return $this->getService( 'SiteLookup' ); +// return this.getService( 'SiteLookup' ); // } // // /** @@ -363,23 +366,23 @@ public class XomwMediaWikiServices { // * @return SiteStore // */ // public function getSiteStore() { -// return $this->getService( 'SiteStore' ); +// return this.getService( 'SiteStore' ); // } -// -// /** -// * @since 1.28 -// * @return InterwikiLookup -// */ -// public function getInterwikiLookup() { -// return $this->getService( 'InterwikiLookup' ); -// } -// + + /** + * @since 1.28 + * @return InterwikiLookup + */ + public XomwInterwikiLookup getInterwikiLookup() { + return interwikiLookup; + } + // /** // * @since 1.27 // * @return StatsdDataFactory // */ // public function getStatsdDataFactory() { -// return $this->getService( 'StatsdDataFactory' ); +// return this.getService( 'StatsdDataFactory' ); // } // // /** @@ -387,7 +390,7 @@ public class XomwMediaWikiServices { // * @return EventRelayerGroup // */ // public function getEventRelayerGroup() { -// return $this->getService( 'EventRelayerGroup' ); +// return this.getService( 'EventRelayerGroup' ); // } // // /** @@ -396,7 +399,7 @@ public class XomwMediaWikiServices { // */ // public function newSearchEngine() { // // New engine Object every time, since they keep state -// return $this->getService( 'SearchEngineFactory' )->create(); +// return this.getService( 'SearchEngineFactory' )->create(); // } // // /** @@ -404,7 +407,7 @@ public class XomwMediaWikiServices { // * @return SearchEngineFactory // */ // public function getSearchEngineFactory() { -// return $this->getService( 'SearchEngineFactory' ); +// return this.getService( 'SearchEngineFactory' ); // } // // /** @@ -412,7 +415,7 @@ public class XomwMediaWikiServices { // * @return SearchEngineConfig // */ // public function getSearchEngineConfig() { -// return $this->getService( 'SearchEngineConfig' ); +// return this.getService( 'SearchEngineConfig' ); // } // // /** @@ -420,7 +423,7 @@ public class XomwMediaWikiServices { // * @return SkinFactory // */ // public function getSkinFactory() { -// return $this->getService( 'SkinFactory' ); +// return this.getService( 'SkinFactory' ); // } // // /** @@ -428,7 +431,7 @@ public class XomwMediaWikiServices { // * @return LBFactory // */ // public function getDBLoadBalancerFactory() { -// return $this->getService( 'DBLoadBalancerFactory' ); +// return this.getService( 'DBLoadBalancerFactory' ); // } // // /** @@ -436,7 +439,7 @@ public class XomwMediaWikiServices { // * @return LoadBalancer The main DB load balancer for the local wiki. // */ // public function getDBLoadBalancer() { -// return $this->getService( 'DBLoadBalancer' ); +// return this.getService( 'DBLoadBalancer' ); // } // // /** @@ -444,7 +447,7 @@ public class XomwMediaWikiServices { // * @return WatchedItemStore // */ // public function getWatchedItemStore() { -// return $this->getService( 'WatchedItemStore' ); +// return this.getService( 'WatchedItemStore' ); // } // // /** @@ -452,7 +455,7 @@ public class XomwMediaWikiServices { // * @return WatchedItemQueryService // */ // public function getWatchedItemQueryService() { -// return $this->getService( 'WatchedItemQueryService' ); +// return this.getService( 'WatchedItemQueryService' ); // } // // /** @@ -460,7 +463,7 @@ public class XomwMediaWikiServices { // * @return CryptRand // */ // public function getCryptRand() { -// return $this->getService( 'CryptRand' ); +// return this.getService( 'CryptRand' ); // } // // /** @@ -468,7 +471,7 @@ public class XomwMediaWikiServices { // * @return CryptHKDF // */ // public function getCryptHKDF() { -// return $this->getService( 'CryptHKDF' ); +// return this.getService( 'CryptHKDF' ); // } // // /** @@ -476,7 +479,7 @@ public class XomwMediaWikiServices { // * @return MediaHandlerFactory // */ // public function getMediaHandlerFactory() { -// return $this->getService( 'MediaHandlerFactory' ); +// return this.getService( 'MediaHandlerFactory' ); // } // // /** @@ -484,7 +487,7 @@ public class XomwMediaWikiServices { // * @return MimeAnalyzer // */ // public function getMimeAnalyzer() { -// return $this->getService( 'MimeAnalyzer' ); +// return this.getService( 'MimeAnalyzer' ); // } // // /** @@ -492,7 +495,7 @@ public class XomwMediaWikiServices { // * @return ProxyLookup // */ // public function getProxyLookup() { -// return $this->getService( 'ProxyLookup' ); +// return this.getService( 'ProxyLookup' ); // } // // /** @@ -500,7 +503,7 @@ public class XomwMediaWikiServices { // * @return Parser // */ // public function getParser() { -// return $this->getService( 'Parser' ); +// return this.getService( 'Parser' ); // } // // /** @@ -508,7 +511,7 @@ public class XomwMediaWikiServices { // * @return GenderCache // */ // public function getGenderCache() { -// return $this->getService( 'GenderCache' ); +// return this.getService( 'GenderCache' ); // } // // /** @@ -516,7 +519,7 @@ public class XomwMediaWikiServices { // * @return LinkCache // */ // public function getLinkCache() { -// return $this->getService( 'LinkCache' ); +// return this.getService( 'LinkCache' ); // } // // /** @@ -524,7 +527,7 @@ public class XomwMediaWikiServices { // * @return LinkRendererFactory // */ // public function getLinkRendererFactory() { -// return $this->getService( 'LinkRendererFactory' ); +// return this.getService( 'LinkRendererFactory' ); // } // // /** @@ -535,7 +538,7 @@ public class XomwMediaWikiServices { // * @return LinkRenderer // */ // public function getLinkRenderer() { -// return $this->getService( 'LinkRenderer' ); +// return this.getService( 'LinkRenderer' ); // } /** @@ -543,7 +546,7 @@ public class XomwMediaWikiServices { * @return TitleFormatter */ public XomwMediaWikiTitleCodec getTitleFormatter() { - // return $this->getService( 'TitleFormatter' ); + // return this.getService( 'TitleFormatter' ); return titleParser; } @@ -552,7 +555,7 @@ public class XomwMediaWikiServices { * @return TitleParser */ public XomwMediaWikiTitleCodec getTitleParser() { - // return $this->getService( 'TitleParser' ); + // return this.getService( 'TitleParser' ); return titleParser; } @@ -561,7 +564,7 @@ public class XomwMediaWikiServices { // * @return \BagOStuff // */ // public function getMainObjectStash() { -// return $this->getService( 'MainObjectStash' ); +// return this.getService( 'MainObjectStash' ); // } // // /** @@ -569,7 +572,7 @@ public class XomwMediaWikiServices { // * @return \WANObjectCache // */ // public function getMainWANObjectCache() { -// return $this->getService( 'MainWANObjectCache' ); +// return this.getService( 'MainWANObjectCache' ); // } // // /** @@ -577,7 +580,7 @@ public class XomwMediaWikiServices { // * @return \BagOStuff // */ // public function getLocalServerObjectCache() { -// return $this->getService( 'LocalServerObjectCache' ); +// return this.getService( 'LocalServerObjectCache' ); // } // // /** @@ -585,7 +588,7 @@ public class XomwMediaWikiServices { // * @return VirtualRESTServiceClient // */ // public function getVirtualRESTServiceClient() { -// return $this->getService( 'VirtualRESTServiceClient' ); +// return this.getService( 'VirtualRESTServiceClient' ); // } // // /////////////////////////////////////////////////////////////////////////// diff --git a/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/interwiki/XomwInterwiki.java b/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/interwiki/XomwInterwiki.java index 3420cb74e..636e81031 100644 --- a/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/interwiki/XomwInterwiki.java +++ b/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/interwiki/XomwInterwiki.java @@ -48,18 +48,19 @@ public class XomwInterwiki { this.mTrans = trans; } -// /** -// * Check whether an interwiki prefix exists -// * -// * @deprecated since 1.28, use InterwikiLookup instead -// * -// * @param String prefix Interwiki prefix to use -// * @return boolean Whether it exists -// */ -// public static function isValidInterwiki(prefix) { + /** + * Check whether an interwiki prefix exists + * + * [@]deprecated since 1.28, use InterwikiLookup instead + * + * @param String prefix Interwiki prefix to use + * @return boolean Whether it exists + */ + public static boolean isValidInterwiki(XomwMediaWikiServices mws, byte[] prefix) { + return mws.getInterwikiLookup().isValidInterwiki(prefix); // return MediaWikiServices::getInstance().getInterwikiLookup().isValidInterwiki(prefix); -// } -// + } + // /** // * Fetch an Interwiki Object // * diff --git a/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/interwiki/XomwInterwikiLookup.java b/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/interwiki/XomwInterwikiLookup.java index 9fefff40e..21566f0f6 100644 --- a/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/interwiki/XomwInterwikiLookup.java +++ b/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/interwiki/XomwInterwikiLookup.java @@ -28,25 +28,25 @@ public interface XomwInterwikiLookup { */ boolean isValidInterwiki(byte[] prefix); - /** - * Fetch an Interwiki Object - * - * @param String $prefix Interwiki prefix to use - * @return Interwiki|null|boolean - */ - XomwInterwiki fetch(byte[] prefix); - - /** - * Returns all interwiki prefixes - * - * @param String|null $local If set, limits output to local/non-local interwikis - * @return String[] List of prefixes - */ - byte[][] getAllPrefixes(byte[] local); - - /** - * Purge the in-process and persistent Object cache for an interwiki prefix - * @param String $prefix - */ - void invalidateCache(byte[] prefix); +// /** +// * Fetch an Interwiki Object +// * +// * @param String $prefix Interwiki prefix to use +// * @return Interwiki|null|boolean +// */ +// XomwInterwiki fetch(byte[] prefix); +// +// /** +// * Returns all interwiki prefixes +// * +// * @param String|null $local If set, limits output to local/non-local interwikis +// * @return String[] List of prefixes +// */ +// byte[][] getAllPrefixes(byte[] local); +// +// /** +// * Purge the in-process and persistent Object cache for an interwiki prefix +// * @param String $prefix +// */ +// void invalidateCache(byte[] prefix); } diff --git a/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/interwiki/XomwInterwikiLookupAdapter.java b/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/interwiki/XomwInterwikiLookupAdapter.java index 5ba24229c..bb48ec255 100644 --- a/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/interwiki/XomwInterwikiLookupAdapter.java +++ b/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/interwiki/XomwInterwikiLookupAdapter.java @@ -14,37 +14,38 @@ 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.interwiki; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*; -class XomwInterwikiLookupAdapter { -// /** -// * @var SiteLookup -// */ -// private $siteLookup; -// +import gplx.xowa.mediawiki.includes.site.*; +public class XomwInterwikiLookupAdapter implements XomwInterwikiLookup { + /** + * @var SiteLookup + */ +// private final XomwSiteLookup siteLookup; + // /** // * @var Interwiki[]|null associative array mapping interwiki prefixes to Interwiki objects // */ // private $interwikiMap; -// -// function __construct( -// SiteLookup $siteLookup, + + public XomwInterwikiLookupAdapter( + XomwSiteLookup siteLookup //, // array $interwikiMap = null -// ) { -// $this->siteLookup = $siteLookup; -// $this->interwikiMap = $interwikiMap; -// } -// -// /** -// * See InterwikiLookup::isValidInterwiki -// * It loads the whole interwiki map. -// * -// * @param String $prefix Interwiki prefix to use -// * @return boolean Whether it exists -// */ -// public function isValidInterwiki( $prefix ) { -// -// return array_key_exists( $prefix, $this->getInterwikiMap() ); -// } -// + ) { +// this.siteLookup = siteLookup; +// this.interwikiMap = $interwikiMap; + } + + /** + * See InterwikiLookup::isValidInterwiki + * It loads the whole interwiki map. + * + * @param String $prefix Interwiki prefix to use + * @return boolean Whether it exists + */ + public boolean isValidInterwiki(byte[] prefix) { + return false; +// return array_key_exists($prefix, this.getInterwikiMap()); + } + // /** // * See InterwikiLookup::fetch // * It loads the whole interwiki map. @@ -52,16 +53,16 @@ class XomwInterwikiLookupAdapter { // * @param String $prefix Interwiki prefix to use // * @return Interwiki|null|boolean // */ -// public function fetch( $prefix ) { -// if ( $prefix == '' ) { +// public function fetch($prefix) { +// if ($prefix == '') { // return null; // } // -// if ( !$this->isValidInterwiki( $prefix ) ) { +// if (!this.isValidInterwiki($prefix)) { // return false; // } // -// return $this->interwikiMap[$prefix]; +// return this.interwikiMap[$prefix]; // } // // /** @@ -70,13 +71,13 @@ class XomwInterwikiLookupAdapter { // * @param String|null $local If set, limits output to local/non-local interwikis // * @return String[] List of prefixes // */ -// public function getAllPrefixes( $local = null ) { -// if ( $local === null ) { -// return array_keys( $this->getInterwikiMap() ); +// public function getAllPrefixes($local = null) { +// if ($local === null) { +// return array_keys(this.getInterwikiMap()); // } // $res = []; -// foreach ( $this->getInterwikiMap() as $interwikiId => $interwiki ) { -// if ( $interwiki->isLocal() === $local ) { +// foreach (this.getInterwikiMap() as $interwikiId => $interwiki) { +// if ($interwiki->isLocal() === $local) { // $res[] = $interwikiId; // } // } @@ -88,56 +89,60 @@ class XomwInterwikiLookupAdapter { // * // * @param String $prefix // */ -// public function invalidateCache( $prefix ) { -// if ( !isset( $this->interwikiMap[$prefix] ) ) { +// public function invalidateCache($prefix) { +// if (!isset(this.interwikiMap[$prefix])) { // return; // } -// $globalId = $this->interwikiMap[$prefix]->getWikiID(); -// unset( $this->interwikiMap[$prefix] ); +// $globalId = this.interwikiMap[$prefix]->getWikiID(); +// unset(this.interwikiMap[$prefix]); // // // Reload the interwiki -// $site = $this->siteLookup->getSites()->getSite( $globalId ); -// $interwikis = $this->getSiteInterwikis( $site ); -// $this->interwikiMap = array_merge( $this->interwikiMap, [ $interwikis[$prefix] ] ); +// $site = this.siteLookup->getSites()->getSite($globalId); +// $interwikis = this.getSiteInterwikis($site); +// this.interwikiMap = array_merge(this.interwikiMap, [ $interwikis[$prefix] ]); // } -// -// /** -// * Load interwiki map to use as cache -// */ -// private function loadInterwikiMap() { -// $interwikiMap = []; -// $siteList = $this->siteLookup->getSites(); -// foreach ( $siteList as $site ) { -// $interwikis = $this->getSiteInterwikis( $site ); -// $interwikiMap = array_merge( $interwikiMap, $interwikis ); + + /** + * Load interwiki map to use as cache + */ +// private Object loadInterwikiMap() { +//// $interwikiMap = []; +// XomwSiteList siteList = this.siteLookup.getSites(); +// int len = siteList.Len(); +// for (int i = 0; i < len; i++) { +// XomwSite site = siteList.GetAt(i); +//// $interwikis = this.getSiteInterwikis($site); +//// $interwikiMap = array_merge($interwikiMap, $interwikis); // } -// $this->interwikiMap = $interwikiMap; +//// this.interwikiMap = $interwikiMap; +// return null; // } -// -// /** -// * Get interwikiMap attribute, load if needed. -// * -// * @return Interwiki[] -// */ -// private function getInterwikiMap() { -// if ( $this->interwikiMap === null ) { -// $this->loadInterwikiMap(); + + /** + * Get interwikiMap attribute, load if needed. + * + * @return Interwiki[] + */ +// private Object getInterwikiMap() { +// if (this.interwikiMap === null) { +// this.loadInterwikiMap(); // } -// return $this->interwikiMap; +// return this.interwikiMap; +// return null; // } -// + // /** // * Load interwikis for the given site // * // * @param Site $site // * @return Interwiki[] // */ -// private function getSiteInterwikis( Site $site ) { +// private function getSiteInterwikis(Site $site) { // $interwikis = []; -// foreach ( $site->getInterwikiIds() as $interwiki ) { +// foreach ($site->getInterwikiIds() as $interwiki) { // $url = $site->getPageUrl(); -// if ( $site instanceof MediaWikiSite ) { -// $path = $site->getFileUrl( 'api.php' ); +// if ($site instanceof MediaWikiSite) { +// $path = $site->getFileUrl('api.php'); // } else { // $path = ''; // } diff --git a/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/site/XomwFileBasedSiteLookup.java b/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/site/XomwFileBasedSiteLookup.java new file mode 100644 index 000000000..a88fdeaa8 --- /dev/null +++ b/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/site/XomwFileBasedSiteLookup.java @@ -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; +// } +} diff --git a/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/site/XomwSite.java b/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/site/XomwSite.java new file mode 100644 index 000000000..11814cbd7 --- /dev/null +++ b/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/site/XomwSite.java @@ -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'] ); +// } +} diff --git a/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/site/XomwSiteList.java b/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/site/XomwSiteList.java new file mode 100644 index 000000000..502a72677 --- /dev/null +++ b/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/site/XomwSiteList.java @@ -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; +// } +} diff --git a/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/site/XomwSiteLookup.java b/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/site/XomwSiteLookup.java new file mode 100644 index 000000000..8999dd302 --- /dev/null +++ b/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/site/XomwSiteLookup.java @@ -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(); + +} diff --git a/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/title/XomwMediaWikiTitleCodec.java b/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/title/XomwMediaWikiTitleCodec.java index 6f9c48988..da6aea372 100644 --- a/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/title/XomwMediaWikiTitleCodec.java +++ b/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/title/XomwMediaWikiTitleCodec.java @@ -15,7 +15,9 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt */ package gplx.xowa.mediawiki.includes.title; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*; import gplx.xowa.mediawiki.languages.*; +import gplx.xowa.mediawiki.includes.interwiki.*; public class XomwMediaWikiTitleCodec implements XomwTitleFormatter { + private XomwMediaWikiServices mws; /** * @var Language */ @@ -43,7 +45,8 @@ public class XomwMediaWikiTitleCodec implements XomwTitleFormatter { // $this->genderCache = $genderCache; // $this->localInterwikis = (array)$localInterwikis; // } - public XomwMediaWikiTitleCodec(XomwLanguage language) { + public XomwMediaWikiTitleCodec(XomwMediaWikiServices mws, XomwLanguage language) { + this.mws = mws; this.language = language; } @@ -291,11 +294,11 @@ public class XomwMediaWikiTitleCodec implements XomwTitleFormatter { // Disallow Talk:File:x type titles... throw new XomwMalformedTitleException("title-invalid-talk-namespace", text); } -// else if (Interwiki::isValidInterwiki($x[1])) { -// // TODO: get rid of global state! -// // Disallow Talk:Interwiki:x type titles... -// throw new XomwMalformedTitleException('title-invalid-talk-namespace', text); -// } + else if (XomwInterwiki.isValidInterwiki(mws, m[0])) { + // TODO: get rid of global state! + // Disallow Talk:Interwiki:x type titles... + throw new XomwMalformedTitleException("title-invalid-talk-namespace", text); + } } } // else if (Interwiki::isValidInterwiki($p)) { diff --git a/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/title/XomwMediaWikiTitleCodecTest.java b/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/title/XomwMediaWikiTitleCodecTest.java index 070b7d643..ab77f35df 100644 --- a/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/title/XomwMediaWikiTitleCodecTest.java +++ b/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/title/XomwMediaWikiTitleCodecTest.java @@ -45,7 +45,8 @@ class XomwMediaWikiTitleCodecFxt { return new XomwMediaWikiTitleCodecParts(Bry_.new_u8(dbkey), ns); } public XomwMediaWikiTitleCodec Make_codec(XomwLanguage lang) { - return new XomwMediaWikiTitleCodec(lang); + XomwEnv env = new XomwEnv(lang.XoLang()); + return env.MediaWikiServices().getTitleFormatter(); } public XomwLanguage Make_lang() { Xoae_app app = Xoa_app_fxt.Make__app__edit(); diff --git a/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/languages/XomwLanguage.java b/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/languages/XomwLanguage.java index e0f7d3bb0..08a637fe6 100644 --- a/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/languages/XomwLanguage.java +++ b/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/languages/XomwLanguage.java @@ -17,6 +17,8 @@ package gplx.xowa.mediawiki.languages; import gplx.*; import gplx.xowa.*; import import gplx.xowa.mediawiki.includes.*; import gplx.xowa.langs.*; public class XomwLanguage { + public Xol_lang_itm XoLang() {return xoLang;} private Xol_lang_itm xoLang = null; + private final Bry_bfr tmpBfr = Bry_bfr_.New(); // /** // * @var LanguageConverter // */ @@ -193,8 +195,6 @@ public class XomwLanguage { // -\x{1edff}\x{1ef00}-\x{1efff}\x{608}\x{60b}\x{60d}\x{61b}-\x{64a}\x{66d}-\x{66f}\x{671}-\x{6d5}\x{6e5}\x{6e6}\x{6ee}\x{6ef}\x{6fa}-\x{710}\x{712}-\x{72f}\x{74b}-\x{7a5}\x{7b1}-\x{7bf}\x{8a0}-\x{8e2}\x{fb50}-\x{fd3d}\x{fd40}-\x{fdcf}\x{fdf0}-\x{fdfc}\x{fdfe}\x{fdff}\x{fe70}-\x{fefe}\x{1ee00}-\x{1eeef}\x{1eef2}-\x{1eeff}]))/u'; // // @codeCoverageIgnoreEnd // // @codingStandardsIgnoreEnd - private Xol_lang_itm xoLang = null; - private final Bry_bfr tmpBfr = Bry_bfr_.New(); // /** // * Get a cached or new language Object for a given language code