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-07-12 21:10:02 -04:00
commit 794b5a232f
3099 changed files with 238212 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
/*
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.parsers.lnkis.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; import gplx.xowa.parsers.lnkis.*;
public class Xoc_lnki_cfg implements GfoInvkAble {
public Xoc_lnki_cfg(Xowe_wiki wiki) {xwiki_repo_mgr = new Xoc_xwiki_repo_mgr(wiki);}
public Xoc_xwiki_repo_mgr Xwiki_repo_mgr() {return xwiki_repo_mgr;} private Xoc_xwiki_repo_mgr xwiki_repo_mgr;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_xwiki_repos)) return xwiki_repo_mgr;
else return GfoInvkAble_.Rv_unhandled;
}
private static final String Invk_xwiki_repos = "xwiki_repos";
}

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.parsers.lnkis.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; import gplx.xowa.parsers.lnkis.*;
public class Xoc_xwiki_repo_mgr implements GfoInvkAble {
private Ordered_hash hash = Ordered_hash_.new_bry_();
private Xowe_wiki wiki;
public Xoc_xwiki_repo_mgr(Xowe_wiki wiki) {this.wiki = wiki;}
public boolean Has(byte[] abrv) {
Xoc_xwiki_repo_itm itm = (Xoc_xwiki_repo_itm)hash.Get_by(abrv);
return itm != null;
}
public void Add_or_mod(byte[] abrv) {
Xoc_xwiki_repo_itm itm = (Xoc_xwiki_repo_itm)hash.Get_by(abrv);
if (itm == null) {
itm = new Xoc_xwiki_repo_itm(abrv);
hash.Add(abrv, itm);
wiki.Cfg_parser_lnki_xwiki_repos_enabled_(true);
}
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_add)) Add_or_mod(m.ReadBry("xwiki"));
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String Invk_add = "add";
}
class Xoc_xwiki_repo_itm {
public Xoc_xwiki_repo_itm(byte[] abrv) {this.abrv = abrv;}
public byte[] Abrv() {return abrv;} private byte[] abrv;
}

View File

@@ -0,0 +1,121 @@
/*
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.parsers.lnkis.redlinks; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; import gplx.xowa.parsers.lnkis.*;
import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.langs.vnts.*; import gplx.xowa.gui.views.*; import gplx.xowa.pages.*; import gplx.xowa.html.hdumps.core.*;
public class Xog_redlink_mgr implements GfoInvkAble {
private Xog_win_itm win; private Xog_html_itm html_itm; private Xowe_wiki wiki; private Xoae_page page;
private Xopg_redlink_lnki_list redlink_lnki_list; private List_adp lnki_list; private boolean log_enabled; private Gfo_usr_dlg usr_dlg; private int thread_id;
public Xog_redlink_mgr(Xog_win_itm win, Xoae_page page, boolean log_enabled) {
this.win = win; this.page = page; this.wiki = page.Wikie();
this.html_itm = page.Tab_data().Tab().Html_itm(); // NOTE: caching locally b/c page.Tab() is sometimes null
this.redlink_lnki_list = page.Redlink_lnki_list();
this.lnki_list = redlink_lnki_list.Lnki_list();
this.thread_id = redlink_lnki_list.Thread_id();
this.log_enabled = log_enabled; this.usr_dlg = log_enabled ? Gfo_usr_dlg_.I : Gfo_usr_dlg_.Noop;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_run)) Redlink();
else return GfoInvkAble_.Rv_unhandled;
return this;
} public static final String Invk_run = "run";
public void Redlink() {
synchronized (this) { // NOTE: attempt to eliminate random IndexBounds errors; DATE:2014-09-02
if (redlink_lnki_list.Disabled()) return;
List_adp work_list = List_adp_.new_();
Ordered_hash page_hash = Ordered_hash_.new_bry_();
page_hash.Clear(); // NOTE: do not clear in Page_bgn, else will fail b/c of threading; EX: Open Page -> Preview -> Save; DATE:2013-11-17
work_list.Clear();
int len = lnki_list.Count();
if (log_enabled) usr_dlg.Log_many("", "", "redlink.redlink_bgn: page=~{0} total_links=~{1}", String_.new_u8(page.Ttl().Raw()), len);
for (int i = 0; i < len; i++) { // make a copy of list else thread issues
if (win.Usr_dlg().Canceled()) return;
if (redlink_lnki_list.Thread_id() != thread_id) return;
work_list.Add(lnki_list.Get_at(i));
}
for (int i = 0; i < len; i++) {
if (win.Usr_dlg().Canceled()) return;
if (redlink_lnki_list.Thread_id() != thread_id) return;
Xop_lnki_tkn lnki = (Xop_lnki_tkn)work_list.Get_at(i);
Xoa_ttl ttl = lnki.Ttl();
Xowd_page_itm db_page = new Xowd_page_itm().Ttl_(ttl);
byte[] full_txt = ttl.Full_db();
if (!page_hash.Has(full_txt))
page_hash.Add(full_txt, db_page);
}
int page_len = page_hash.Count();
for (int i = 0; i < page_len; i += Batch_size) {
if (win.Usr_dlg().Canceled()) return;
if (redlink_lnki_list.Thread_id() != thread_id) return;
int end = i + Batch_size;
if (end > page_len) end = page_len;
wiki.Db_mgr().Load_mgr().Load_by_ttls(win.Usr_dlg(), page_hash, Bool_.Y, i, end);
}
int redlink_count = 0;
Bry_bfr bfr = null;
boolean variants_enabled = wiki.Lang().Vnt_mgr().Enabled();
Xol_vnt_mgr vnt_mgr = wiki.Lang().Vnt_mgr();
Xopg_redlink_idx_list redlink_mgr = page.Hdump_data().Redlink_mgr();
for (int j = 0; j < len; j++) {
Xop_lnki_tkn lnki = (Xop_lnki_tkn)work_list.Get_at(j);
byte[] full_db = lnki.Ttl().Full_db();
Xowd_page_itm db_page = (Xowd_page_itm)page_hash.Get_by(full_db);
if (db_page == null) continue; // pages shouldn't be null, but just in case
if (!db_page.Exists()) {
String lnki_id = Xopg_redlink_lnki_list.Lnki_id_prefix + Int_.Xto_str(lnki.Html_uid());
if (variants_enabled) {
Xowd_page_itm vnt_page = vnt_mgr.Convert_ttl(wiki, lnki.Ttl());
if (vnt_page != null) {
Xoa_ttl vnt_ttl = Xoa_ttl.parse_(wiki, lnki.Ttl().Ns().Id(), vnt_page.Ttl_page_db());
html_itm.Html_atr_set(lnki_id, "href", "/wiki/" + String_.new_u8(vnt_ttl.Full_url()));
if (!String_.Eq(vnt_mgr.Html_style(), ""))
html_itm.Html_atr_set(lnki_id, "style", vnt_mgr.Html_style());
continue;
}
}
if (log_enabled) {
if (bfr == null) bfr = Bry_bfr.new_();
bfr.Add_int_variable(lnki.Html_uid()).Add_byte_pipe().Add(Xop_tkn_.Lnki_bgn).Add(full_db).Add(Xop_tkn_.Lnki_end).Add_byte(Byte_ascii.Semic).Add_byte_space();
}
if (win.Usr_dlg().Canceled()) return;
if (redlink_lnki_list.Thread_id() != thread_id) return;
int uid = lnki.Html_uid();
gplx.xowa.files.gui.Js_img_mgr.Update_link_missing(html_itm, Xopg_redlink_lnki_list.Lnki_id_prefix + Int_.Xto_str(uid));
redlink_mgr.Add(uid);
++redlink_count;
}
}
if (log_enabled)
usr_dlg.Log_many("", "", "redlink.redlink_end: redlinks_run=~{0} links=~{1}", redlink_count, bfr == null ? String_.Empty : bfr.Xto_str_and_clear());
}
}
public static final Xog_redlink_mgr Null = new Xog_redlink_mgr(); Xog_redlink_mgr() {}
private static final int Batch_size = 32;
}
class Xog_redlink_wkr {
public static void Redlink(Xog_html_itm html_itm, Int_list list) {
int len = list.Len();
for (int i = 0; i < len; ++i) {
int uid = list.Get_at(i);
Redlink(html_itm, uid);
}
}
public static void Redlink(Xog_html_itm html_itm, int uid) {
gplx.xowa.files.gui.Js_img_mgr.Update_link_missing(html_itm, Xopg_redlink_lnki_list.Lnki_id_prefix + Int_.Xto_str(uid));
}
}

View File

@@ -0,0 +1,32 @@
/*
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.parsers.lnkis.redlinks; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; import gplx.xowa.parsers.lnkis.*;
public class Xopg_redlink_idx_list {
private final Int_list list = new Int_list();
public int Len() {return list.Len();}
public int Max() {return max;} private int max;
public int Get_at(int i) {return list.Get_at(i);}
public void Clear() {
list.Clear();
max = 0;
}
public void Add(int i) {
list.Add(i);
if (i > max) max = i;
}
}

View File

@@ -0,0 +1,50 @@
/*
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.parsers.lnkis.redlinks; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; import gplx.xowa.parsers.lnkis.*;
import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.users.*;
public class Xopg_redlink_lnki_list {
private int lnki_idx = gplx.xowa.html.lnkis.Xoh_lnki_wtr.Lnki_id_min; // NOTE: default to 1, not 0, b/c 0 is ignored by wtr; DATE:2014-10-09
public Xopg_redlink_lnki_list(boolean ttl_is_module) { // never redlink in Module ns; particularly since Lua has multi-line comments for [[ ]]
this.disabled = ttl_is_module;
}
public boolean Disabled() {return disabled;} private final boolean disabled;
public List_adp Lnki_list() {return lnki_list;} private final List_adp lnki_list = List_adp_.new_();
public int Thread_id() {return thread_id;} private int thread_id = 1;
public void Clear() {
if (disabled) return;
lnki_idx = 0; // NOTE: must start at 0, so that ++lnki_idx is > 0; html_wtr checks for > 0
lnki_list.Clear();
thread_id++;
}
public void Lnki_add(Xop_lnki_tkn lnki) {
if (disabled) return;
Xoa_ttl ttl = lnki.Ttl(); if (ttl == null) return; // occurs for invalid links
Xow_ns ns = ttl.Ns();
lnki.Html_uid_(++lnki_idx); // NOTE: set html_id in order html to print out "id='xowa_lnki_1'; want to print out id for consistency's sake, even if these links won't be check for redlinks; DATE:2015-05-07
if ( ns.Id_file_or_media() // ignore files which will usually not be in local wiki (most are in commons), and whose html is built up separately
|| (ns.Id_ctg() && !ttl.ForceLiteralLink()) // ignore ctgs which have their own html builder, unless it is literal; EX: [[:Category:A]]; DATE:2014-02-24
|| ns.Id_special() // ignore special, especially Search; EX: Special:Search/Earth
|| ttl.Anch_bgn() == Xoa_ttl.Anch_bgn_anchor_only // anchor only link; EX: [[#anchor]]
|| ttl.Wik_itm() != null // xwiki lnki; EX: simplewiki links in homewiki; [[simplewiki:Earth]]
)
return;
lnki_list.Add(lnki);
}
public static final String Lnki_id_prefix = "xowa_lnki_";
public static final int Lnki_id_prefix_len = String_.Len(Lnki_id_prefix);
}

View File

@@ -0,0 +1,21 @@
/*
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.parsers.lnkis.redlinks; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; import gplx.xowa.parsers.lnkis.*;
public interface Xopg_redlink_logger {
void Wkr_exec(Xop_ctx ctx, byte[] src, Xop_lnki_tkn lnki, byte lnki_src_tid);
}