1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2015-09-20 23:43:51 -04:00
parent 5fe27b5b3b
commit fa70c05354
1056 changed files with 8375 additions and 7095 deletions

View File

@@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.metas; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
public class Bfmtr_eval_wiki implements Bry_fmtr_eval_mgr {
public Bfmtr_eval_wiki(Xowe_wiki wiki) {this.wiki = wiki;} private Xowe_wiki wiki;
public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled = true;
public byte[] Eval(byte[] cmd) {
Object rslt = GfsCore._.Exec_bry(cmd, wiki);
return Bry_.new_u8(Object_.Xto_str_strict_or_null_mark(rslt));
}
public void Eval_mgr_(Bry_fmtr... fmtrs) {
int fmtrs_len = fmtrs.length;
for (int i = 0; i < fmtrs_len; i++)
fmtrs[i].Eval_mgr_(this);
}
}

View File

@@ -0,0 +1,36 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.metas; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
public class Xow_html_util implements GfoInvkAble {
public Xow_html_util(Xowe_wiki wiki) {this.wiki = wiki;} private Xowe_wiki wiki;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_if_bool)) return If_bool(m.ReadStr("expr"), m.ReadStr("true_val"), m.ReadStr("false_val"));
else if (ctx.Match(k, Invk_if_yn)) return If_yn(m.ReadStr("expr"), m.ReadStr("true_val"), m.ReadStr("false_val"));
else return GfoInvkAble_.Rv_unhandled;
} private static final String Invk_if_bool = "if_bool", Invk_if_yn = "if_yn";
String If_bool(String expr, String true_val, String false_val) {
Object o = wiki.Appe().Gfs_mgr().Run_str(expr);
try {return Bool_.cast(o) ? true_val : false_val;}
catch (Exception e) {Err_.Noop(e); return "expr failed: " + expr;}
}
String If_yn(String expr, String true_val, String false_val) {
String o = String_.as_(wiki.Appe().Gfs_mgr().Run_str(expr));
try {return Yn.parse(o) ? true_val : false_val;}
catch (Exception e) {Err_.Noop(e); return "expr failed: " + expr;}
}
}

View File

@@ -0,0 +1,58 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.metas; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.xowa.wikis.domains.*;
public class Xow_script_mgr implements GfoInvkAble {
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_set)) Set(m.ReadBry("key"), m.ReadBry("wiki_type"), m.ReadBry("script"));
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_set = "set";
public void Exec(Xowe_wiki wiki) {
int len = hash.Count();
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_k004();
for (int i = 0; i < len; i++) {
Xow_script_itm itm = (Xow_script_itm)hash.Get_at(i);
int wiki_tid = wiki.Domain_tid();
if (Int_.In(wiki_tid, itm.Wiki_tids())) // wiki_tid matches itm
itm.Fmtr().Bld_bfr_many(bfr, wiki.Domain_bry(), Xow_domain_type_.Get_type_as_bry(wiki_tid), wiki.Lang().Key_bry());
}
String gfs_script = String_.Replace(bfr.Xto_str_and_clear(), Op_sys.Wnt.Nl_str(), Op_sys.Lnx.Nl_str());
wiki.Appe().Gfs_mgr().Run_str(gfs_script);
bfr.Mkr_rls();
}
public void Set(byte[] key, byte[] wiki_types_raw, byte[] script) {
byte[][] wiki_tid_names = Bry_split_.Split(wiki_types_raw, Byte_ascii.Tilde);
int len = wiki_tid_names.length;
int[] wiki_tids = new int[len];
for (int i = 0; i < len; i++)
wiki_tids[i] = Xow_domain_type_.Get_type_as_tid(wiki_tid_names[i]);
Xow_script_itm itm = new Xow_script_itm(key, wiki_tids, script);
hash.Add_if_dupe_use_nth(itm.Key(), itm);
}
public Ordered_hash hash = Ordered_hash_.new_bry_();
}
class Xow_script_itm {
public Xow_script_itm(byte[] key, int[] wiki_tids, byte[] script) {
this.key = key; this.wiki_tids = wiki_tids; this.fmtr = Bry_fmtr.new_bry_(script, "wiki_key", "wiki_type_name", "wiki_lang");
}
public byte[] Key() {return key;} private byte[] key;
public int[] Wiki_tids() {return wiki_tids;} private int[] wiki_tids;
public Bry_fmtr Fmtr() {return fmtr;} Bry_fmtr fmtr;
}

View File

@@ -0,0 +1,29 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.metas; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
public class Xow_sys_cfg implements GfoInvkAble {
public Xow_sys_cfg(Xowe_wiki wiki) {}
public boolean Xowa_cmd_enabled() {return xowa_cmd_enabled;} public Xow_sys_cfg Xowa_cmd_enabled_(boolean v) {xowa_cmd_enabled = v; return this;} private boolean xowa_cmd_enabled;
public boolean Xowa_proto_enabled() {return xowa_proto_enabled;} public Xow_sys_cfg Xowa_proto_enabled_(boolean v) {xowa_proto_enabled = v; return this;} private boolean xowa_proto_enabled;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_xowa_cmd_enabled_)) xowa_cmd_enabled = m.ReadYn("v");
else if (ctx.Match(k, Invk_xowa_cmd_enabled_)) xowa_proto_enabled = m.ReadYn("v");
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_xowa_cmd_enabled_ = "xowa_cmd_enabled_";
}

View File

@@ -0,0 +1,26 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.metas; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
public class Xow_user implements GfoInvkAble {
public byte[] Name() {return name;} private byte[] name = Bry_.new_a7("anonymous");
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_name_)) name = m.ReadBry("v");
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_name_ = "name_";
}

View File

@@ -0,0 +1,77 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.metas; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.xowa.langs.msgs.*;
import gplx.xowa.wikis.*; import gplx.xowa.wikis.domains.*;
import gplx.xowa.html.hrefs.*;
public class Xow_wiki_props implements GfoInvkAble {
public byte[] Main_page() {return main_page;} private byte[] main_page = Xoa_page_.Main_page_bry; // HACK: default to Main_Page b/c some code tries to do Xoa_ttl.parse() which will not work with ""; DATE:2014-02-16
public Xow_wiki_props Main_page_(byte[] v) {main_page = v; return this;}
public void Main_page_update(Xowe_wiki wiki) {
siteinfo_mainpage = main_page; // note that main_page came from <siteinfo>; store old value for record's sake
main_page = Xow_mainpage_finder.Find_or(wiki, siteinfo_mainpage); // get new main_page from mainpage_finder
}
public byte Protocol_tid() {return protocol_tid;} private final byte protocol_tid = gplx.core.net.Gfo_protocol_itm.Tid_https; // NOTE: default protocol to https; handles external links like [//a.org]; may need to be changed for wikia or other non-WMF wikis; DATE:2015-07-27
public byte[] Site_name() {return site_name;} private byte[] site_name = Bry_.Empty;
public byte[] ServerName() {return serverName;} public Xow_wiki_props ServerName_(byte[] v) {serverName = v; server = Bry_.Add(bry_http, v); return this;} private byte[] serverName = Bry_.new_a7("localhost");
public byte[] Server() {return server;} private byte[] server = Bry_.new_a7("http://localhost"); static final byte[] bry_http = Bry_.new_a7("http://");
public byte[] ArticlePath() {return articlePath;} public Xow_wiki_props ArticlePath_(byte[] v) {articlePath = v; return this;} private byte[] articlePath = Xoh_href_.Bry__wiki;
public byte[] ScriptPath() {return scriptPath;} public Xow_wiki_props ScriptPath_(byte[] v) {scriptPath = v; return this;} private byte[] scriptPath = Bry_.new_a7("/wiki");
public byte[] StylePath() {return stylePath;} public Xow_wiki_props StylePath_(byte[] v) {stylePath = v; return this;} private byte[] stylePath = Bry_.new_a7("/wiki/skins");
public byte[] ContentLanguage() {return contentLanguage;} public Xow_wiki_props ContentLanguage_(byte[] v) {contentLanguage = v; return this;} private byte[] contentLanguage = Bry_.Empty;
public byte[] DirectionMark() {return directionMark;} public Xow_wiki_props DirectionMark_(byte[] v) {directionMark = v; return this;} private byte[] directionMark = Bry_.Empty;
public byte[] Current_version() {return Current_version_const;}
public byte[] Bldr_version() {return bldr_version;} public Xow_wiki_props Bldr_version_(byte[] v) {bldr_version = v; return this;} private byte[] bldr_version = Bry_.Empty;
public int Css_version() {return css_version;} public Xow_wiki_props Css_version_(int v) {css_version = v; return this;} private int css_version = 1;
public byte[] Siteinfo_misc() {return siteinfo_misc;}
public byte[] Siteinfo_mainpage() {return siteinfo_mainpage;} private byte[] siteinfo_mainpage = Bry_.Empty;
public DateAdp Modified_latest() {return modified_latest;} private DateAdp modified_latest;
public Xow_wiki_props SiteName_(int v) {site_name = Bry_.new_a7(String_.UpperFirst(String_.new_a7(Xow_domain_type_.Get_type_as_bry(v)))); return this;}
public Xow_wiki_props Siteinfo_misc_(byte[] v) {
siteinfo_misc = v;
int pipe_0 = Bry_find_.Find_fwd(v, Byte_ascii.Pipe);
if (pipe_0 != Bry_.NotFound)
site_name = Bry_.Mid(siteinfo_misc, 0, pipe_0);
return this;
} private byte[] siteinfo_misc = Bry_.Empty;
public void Init_by_load(Xoa_app app, gplx.dbs.cfgs.Db_cfg_tbl cfg_tbl) {
if (app.Bldr__running()) return; // never load main_page during bldr; note that Init_by_load is called by bldr cmds like css; DATE:2015-07-24
this.main_page = cfg_tbl.Select_bry_or(Xow_cfg_consts.Grp__wiki_init, Xow_cfg_consts.Key__init__main_page, null);
if (main_page == null) { // main_page not found
Xoa_app_.Usr_dlg().Warn_many("", "", "mw_props.load; main_page not found; conn=~{0}", cfg_tbl.Conn().Conn_info().Xto_api());
this.main_page = Xoa_page_.Main_page_bry;
}
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_main_page_)) main_page = m.ReadBry("v");
else if (ctx.Match(k, Invk_bldr_version_)) bldr_version = m.ReadBry("v");
else if (ctx.Match(k, Invk_siteinfo_misc_)) Siteinfo_misc_(m.ReadBry("v"));
else if (ctx.Match(k, Invk_siteinfo_mainpage_)) siteinfo_mainpage = m.ReadBry("v");
else if (ctx.Match(k, Invk_css_version_)) css_version = m.ReadInt("v");
else if (ctx.Match(k, Invk_modified_latest_)) modified_latest = m.ReadDate("v");
else return GfoInvkAble_.Rv_unhandled;
return this;
}
public static final String Invk_main_page_ = "main_page_"
, Invk_bldr_version = "bldr_version", Invk_bldr_version_ = "bldr_version_", Invk_siteinfo_misc_ = "siteinfo_misc_", Invk_siteinfo_mainpage_ = "siteinfo_mainpage_"
, Invk_css_version_ = "css_version_"
, Invk_modified_latest_ = "modified_latest_"
;
private static final byte[] Current_version_const = Bry_.new_a7("1.21wmf11"); // approximate level of compatibility
}

View File

@@ -0,0 +1,45 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.metas; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.xowa.nss.*;
public class Xow_wiki_stats implements GfoInvkAble {
public Xow_wiki_stats(Xowe_wiki wiki) {this.wiki = wiki;} private Xowe_wiki wiki;
public int NumPages() {return num_pages;} public Xow_wiki_stats NumPages_(int v) {num_pages = v; return this;} private int num_pages; // in entire wiki: 28,433,596
public int NumArticles() {return num_articles;} public Xow_wiki_stats NumArticles_(int v) {num_articles = v; return this;} private int num_articles; // in main ns: 4,074,996
public int NumFiles() {return num_files;} public Xow_wiki_stats NumFiles_(int v) {num_files = v; return this;} private int num_files;
public int NumEdits() {return num_edits;} public Xow_wiki_stats NumEdits_(int v) {num_edits = v; return this;} private int num_edits;
public int NumViews() {return num_views;} public Xow_wiki_stats NumViews_(int v) {num_views = v; return this;} private int num_views;
public int NumUsers() {return num_users;} public Xow_wiki_stats NumUsers_(int v) {num_users = v; return this;} private int num_users;
public int NumUsersActive() {return num_users_active;} public Xow_wiki_stats NumUsersActive_(int v) {num_users_active = v; return this;} private int num_users_active;
public int NumAdmins() {return num_admins;} public Xow_wiki_stats NumAdmins_(int v) {num_admins = v; return this;} private int num_admins;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_number_of_pages_)) num_pages = m.ReadInt("v");
else if (ctx.Match(k, Invk_number_of_articles_)) num_articles = m.ReadInt("v");
else if (ctx.Match(k, Invk_number_of_files_)) num_files = m.ReadInt("v");
else if (ctx.Match(k, Invk_number_of_articles_in_ns_)) return Number_of_articles_in_ns_(m);
else return GfoInvkAble_.Rv_unhandled;
return this;
} public static final String Invk_number_of_pages_ = "number_of_pages_", Invk_number_of_articles_ = "number_of_articles_", Invk_number_of_files_ = "number_of_files_", Invk_number_of_articles_in_ns_ = "number_of_articles_in_ns_";
Object Number_of_articles_in_ns_(GfoMsg m) {
int ns_id = m.ReadInt("ns_id");
int count = m.ReadInt("count");
Xow_ns ns = wiki.Ns_mgr().Ids_get_or_null(ns_id);
if (ns != null) ns.Count_(count);
return this;
}
}