mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Scribunto.Site: Use fully-qualified url for url property, not domain
This commit is contained in:
parent
8cda46bef9
commit
3674dcf8de
@ -39,7 +39,10 @@ class Xoa_site_cfg_itm__interwikimap extends Xoa_site_cfg_itm__base {
|
||||
byte[][] flds = Bry_split_.Split(line, Byte_ascii.Pipe);
|
||||
byte[] url_fmt = flds[1];
|
||||
byte[] domain_bry = Xow_xwiki_mgr.Get_domain_from_url(url_parser, url_fmt);
|
||||
wiki.Xwiki_mgr().Add_by_atrs(flds[0], domain_bry, url_fmt);
|
||||
wiki.Xwiki_mgr().Add_by_site_interwikimap
|
||||
( flds[0], domain_bry, url_fmt
|
||||
, Bry_.Replace(url_fmt, Arg0_xo, Arg0_wm) // NOTE: interwiki items are stored in wiki.core.xowa_cfg as https://en.wikipedia.org/wiki/~{0}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -112,5 +115,9 @@ class Xoa_site_cfg_itm__interwikimap extends Xoa_site_cfg_itm__base {
|
||||
))
|
||||
, Csv__enwiki = Bry_.new_a7("2|w|wikipedia")
|
||||
;
|
||||
private static final byte[]
|
||||
Arg0_xo = Bry_.new_a7("~{0}")
|
||||
, Arg0_wm = Bry_.new_a7("$1")
|
||||
;
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@ package gplx.xowa.wikis.xwikis; import gplx.*; import gplx.xowa.*; import gplx.x
|
||||
import gplx.core.net.*; import gplx.xowa.htmls.hrefs.*;
|
||||
import gplx.xowa.langs.*;
|
||||
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.xwikis.parsers.*; import gplx.xowa.wikis.xwikis.sitelinks.*;
|
||||
import gplx.xowa.wikis.xwikis.interwikis.*;
|
||||
public class Xow_xwiki_mgr {
|
||||
private final Ordered_hash list = Ordered_hash_.New_bry(); private final Hash_adp_bry hash = Hash_adp_bry.ci_a7();
|
||||
private final Xow_wiki wiki;
|
||||
@ -24,6 +25,7 @@ public class Xow_xwiki_mgr {
|
||||
this.wiki = wiki;
|
||||
this.xwiki_domain_tid = Xwiki_tid(wiki.Domain_tid());
|
||||
}
|
||||
public Xow_interwiki_map Interwiki_map() {return interwiki_map;} private final Xow_interwiki_map interwiki_map = new Xow_interwiki_map(); // separate map for Scrib; DATE:2017-04-01
|
||||
public int Xwiki_domain_tid() {return xwiki_domain_tid;} private int xwiki_domain_tid;
|
||||
public int Len() {return list.Count();}
|
||||
public void Clear() {hash.Clear(); list.Clear();}
|
||||
@ -36,6 +38,11 @@ public class Xow_xwiki_mgr {
|
||||
return Add_by_atrs(Bry_.new_a7(key), Bry_.new_a7(domain), null)
|
||||
.Offline_(true);// NOTE: need to mark offline in order to show in left sidebar
|
||||
}
|
||||
public Xow_xwiki_itm Add_by_site_interwikimap(byte[] key, byte[] domain_bry, byte[] url_xo, byte[] url_wm) {
|
||||
interwiki_map.Add(key, domain_bry, url_wm);
|
||||
return this.Add_by_atrs(key, domain_bry, url_xo);
|
||||
}
|
||||
|
||||
public Xow_xwiki_itm Add_by_atrs(String key, String domain) {return Add_by_atrs(Bry_.new_a7(key), Bry_.new_a7(domain), null);}
|
||||
public Xow_xwiki_itm Add_by_atrs(byte[] key, byte[] domain) {return Add_by_atrs(key, domain, null);}
|
||||
public Xow_xwiki_itm Add_by_atrs(byte[] key, byte[] domain_bry, byte[] url_fmt) {
|
||||
|
@ -0,0 +1,26 @@
|
||||
/*
|
||||
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.wikis.xwikis.interwikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.xwikis.*;
|
||||
public class Xow_interwiki_itm {
|
||||
public Xow_interwiki_itm(byte[] key, byte[] domain, byte[] url) {
|
||||
this.key = key;
|
||||
this.domain = domain;
|
||||
this.url = url;
|
||||
}
|
||||
public byte[] Key() {return key;} private final byte[] key;
|
||||
public byte[] Domain() {return domain;} private final byte[] domain;
|
||||
public byte[] Url() {return url;} private final byte[] url;
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
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.wikis.xwikis.interwikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.xwikis.*;
|
||||
public class Xow_interwiki_map {
|
||||
private final Ordered_hash hash = Ordered_hash_.New_bry();
|
||||
public int Len() {return hash.Len();}
|
||||
public Xow_interwiki_itm Get_at(int i) {return (Xow_interwiki_itm)hash.Get_at(i);}
|
||||
public void Add(byte[] key, byte[] domain, byte[] url) {
|
||||
Xow_interwiki_itm itm = new Xow_interwiki_itm(key, domain, url);
|
||||
hash.Add_if_dupe_use_nth(key, itm);
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@ import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
|
||||
import gplx.xowa.wikis.nss.*; import gplx.xowa.addons.wikis.ctgs.*;
|
||||
import gplx.xowa.wikis.metas.*; import gplx.xowa.wikis.data.site_stats.*; import gplx.xowa.wikis.xwikis.*;
|
||||
import gplx.xowa.xtns.scribunto.procs.*;
|
||||
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.xwikis.interwikis.*;
|
||||
public class Scrib_lib_site implements Scrib_lib {
|
||||
public Scrib_lib_site(Scrib_core core) {this.core = core;} private final Scrib_core core;
|
||||
public Scrib_lua_mod Mod() {return mod;} private Scrib_lua_mod mod;
|
||||
@ -101,28 +102,29 @@ public class Scrib_lib_site implements Scrib_lib {
|
||||
String cache_key = "scribunto.interwikimap." + core.Wiki().Domain_str() + "." + filter;
|
||||
Keyval[] rv = (Keyval[])misc_cache.Get_by(cache_key);
|
||||
if (rv == null) {
|
||||
Xow_xwiki_mgr xwiki_mgr = core.Wiki().Xwiki_mgr();
|
||||
int xwiki_len = xwiki_mgr.Len();
|
||||
Xow_interwiki_map interwiki_map = core.Wiki().Xwiki_mgr().Interwiki_map();
|
||||
int interwiki_map_len = interwiki_map.Len();
|
||||
List_adp list = List_adp_.New();
|
||||
for (int i = 0; i < xwiki_len; ++i) {
|
||||
Xow_xwiki_itm itm = xwiki_mgr.Get_at(i);
|
||||
boolean itm_is_local = itm.Offline();
|
||||
for (int i = 0; i < interwiki_map_len; i++) {
|
||||
Xow_interwiki_itm itm = interwiki_map.Get_at(i);
|
||||
Xow_domain_itm domain = Xow_domain_itm_.parse(itm.Domain());
|
||||
boolean itm_is_local = domain.Domain_type_id() != Xow_domain_tid_.Itm__other.Tid(); // NOTE: define local as anything with an "other" domain; EX: "en.wikipedia.org" -> Wikipedia; "toollabs.org" -> Other; was itm.Offline(); DATE:2017-04-01
|
||||
if (local == 1 && !itm_is_local) continue;
|
||||
if (local == 0 && itm_is_local) continue;
|
||||
String prefix = itm.Key_str();
|
||||
list.Add(Keyval_.new_(prefix, InterwikiMap_itm(itm, prefix, itm_is_local)));
|
||||
String prefix = String_.new_u8(itm.Key());
|
||||
list.Add(Keyval_.new_(prefix, InterwikiMap_itm(prefix, itm_is_local, String_.new_u8(itm.Url()))));
|
||||
}
|
||||
rv = (Keyval[])list.To_ary_and_clear(Keyval.class);
|
||||
misc_cache.Add(cache_key, rv);
|
||||
}
|
||||
return rslt.Init_obj(rv);
|
||||
}
|
||||
private Keyval[] InterwikiMap_itm(Xow_xwiki_itm itm, String prefix, boolean itm_is_local) {
|
||||
public static Keyval[] InterwikiMap_itm(String prefix, boolean itm_is_local, String url) {
|
||||
// NOTE: wiki.core_db.xowa_cfg should be upgraded to store isProtocolRelative, isLocal and other properties from WMF_API. DATE:2017-04-01
|
||||
boolean is_extralanguage_link = false;
|
||||
int rv_len = 7;
|
||||
if (is_extralanguage_link) rv_len += 2;
|
||||
String url = String_.new_u8(itm.Domain_bry());
|
||||
boolean url_is_relative = String_.Has_at_bgn(url, "//");
|
||||
boolean url_is_relative = String_.Has_at_bgn(url, "//"); // effectively false since url is built up programatically
|
||||
Keyval[] rv = new Keyval[rv_len];
|
||||
rv[ 0] = Keyval_.new_("prefix" , prefix);
|
||||
rv[ 1] = Keyval_.new_("url" , url); // wfExpandUrl( $row['iw_url'], PROTO_RELATIVE ),
|
||||
|
@ -51,11 +51,16 @@ public class Scrib_lib_site_tst {
|
||||
fxt.Test__proc__ints(lib, Scrib_lib_site.Invk_pagesInNs, Object_.Ary("12"), 0);
|
||||
}
|
||||
@Test public void InterwikiMap() {
|
||||
String key = "scribunto.interwikimap.en.wikipedia.org.!local";
|
||||
fxt.Core().Wiki().Cache_mgr().Misc_cache().Add(key, new Keyval[]
|
||||
{ Keyval_.new_("en"
|
||||
, Scrib_lib_site.InterwikiMap_itm("en.wikipedia.org", false, "https://en.wikipedia.org/wiki/$1"))
|
||||
});
|
||||
fxt.Test__proc__objs__nest(lib, Scrib_lib_site.Invk_interwikiMap, Object_.Ary("!local"), String_.Concat_lines_nl_skip_last
|
||||
( "1="
|
||||
, " en.wikipedia.org="
|
||||
, " en="
|
||||
, " prefix=en.wikipedia.org"
|
||||
, " url=en.wikipedia.org"
|
||||
, " url=https://en.wikipedia.org/wiki/$1"
|
||||
, " isProtocolRelative=false"
|
||||
, " isLocal=false"
|
||||
, " isTranscludable=false"
|
||||
|
Loading…
Reference in New Issue
Block a user