1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2025-05-30 22:14:38 +00:00

Xomw: Add XomwXowaSiteLookup

This commit is contained in:
gnosygnu 2017-03-19 10:03:00 -04:00
parent 96d1299273
commit c84cdf13b3
4 changed files with 49 additions and 134 deletions

View File

@ -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) {

View File

@ -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);
}

View File

@ -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;
// }
}

View File

@ -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;
}
}