From c84cdf13b37bc48757d5cb9d6c03fb4b131e82b6 Mon Sep 17 00:00:00 2001 From: gnosygnu Date: Sun, 19 Mar 2017 10:03:00 -0400 Subject: [PATCH] Xomw: Add XomwXowaSiteLookup --- .../caches/Xofulltext_cache_mgr.java | 2 +- .../src/gplx/xowa/mediawiki/XomwEnv.java | 2 +- .../site/XomwFileBasedSiteLookup.java | 132 ------------------ .../includes/site/XomwXowaSiteLookup.java | 47 +++++++ 4 files changed, 49 insertions(+), 134 deletions(-) delete mode 100644 gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/site/XomwFileBasedSiteLookup.java create mode 100644 gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/site/XomwXowaSiteLookup.java diff --git a/400_xowa/src/gplx/xowa/addons/wikis/fulltexts/searchers/caches/Xofulltext_cache_mgr.java b/400_xowa/src/gplx/xowa/addons/wikis/fulltexts/searchers/caches/Xofulltext_cache_mgr.java index a70b49ef3..51c36898c 100644 --- a/400_xowa/src/gplx/xowa/addons/wikis/fulltexts/searchers/caches/Xofulltext_cache_mgr.java +++ b/400_xowa/src/gplx/xowa/addons/wikis/fulltexts/searchers/caches/Xofulltext_cache_mgr.java @@ -52,7 +52,7 @@ public class Xofulltext_cache_mgr { Xofulltext_cache_line line = new Xofulltext_cache_line(line_seq, line_html); page.Lines().Add(line); } - public Object Get_pages_rng(int qry_id, byte[] wiki, int page_seq_bgn, int page_seq_end) { + public Object Get_pages_rng(int qry_id, int page_seq_bgn, int page_seq_end) { return null; } public Xofulltext_cache_line[] Get_lines_rest(int qry_id, byte[] wiki_bry, int page_id) { diff --git a/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/XomwEnv.java b/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/XomwEnv.java index c5d65fd48..ffdce4ace 100644 --- a/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/XomwEnv.java +++ b/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/XomwEnv.java @@ -30,7 +30,7 @@ public class XomwEnv { public XomwEnv(Xol_lang_itm xoLang) { XomwLanguage language = new XomwLanguage(xoLang); - XomwFileBasedSiteLookup siteLookup = new XomwFileBasedSiteLookup(); + XomwSiteLookup siteLookup = new XomwXowaSiteLookup(); XomwInterwikiLookup interwikiLookup = new XomwInterwikiLookupAdapter(siteLookup); this.mediaWikiServices = new XomwMediaWikiServices(interwikiLookup, language); } 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 deleted file mode 100644 index a88fdeaa8..000000000 --- a/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/site/XomwFileBasedSiteLookup.java +++ /dev/null @@ -1,132 +0,0 @@ -/* -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/XomwXowaSiteLookup.java b/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/site/XomwXowaSiteLookup.java new file mode 100644 index 000000000..db98803b5 --- /dev/null +++ b/gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/site/XomwXowaSiteLookup.java @@ -0,0 +1,47 @@ +/* +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.*; +import gplx.dbs.*; +public class XomwXowaSiteLookup implements XomwSiteLookup { + private final XomwSiteList sites = new XomwSiteList(); + public XomwSite getSite(byte[] globalId) { + return (XomwSite)sites.getSite(String_.new_u8(globalId)); + } + public XomwSiteList getSites() { + throw Err_.new_unimplemented(); + } + public XomwSite addSite(String type, String global_key, int id, boolean forward, String group, byte[] language, String source) { + // REF:DBSiteStore + XomwSite site = new XomwSite(type); + site.setGlobalId(global_key); + site.setInternalId(id); + site.setForward(forward); + site.setGroup(group); + site.setLanguageCode(language); + site.setSource(source); + +// while (rdr.Move_next()) { +// int si_site = rdr.Read_int("si_site"); +// if (this.sites.hasInternalId(si_site)) { +// XomwSite site = this.sites.getSiteByInternalId(si_site); +// site.addLocalId(rdr.Read_str("si_type"), rdr.Read_str("si_key")); +// this.sites.setSite(site); +// } +// } + + return site; + } +}