1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

'v3.6.3.1'

This commit is contained in:
gnosygnu
2016-06-20 13:34:48 -04:00
parent d4e8590345
commit d43e0d2341
28 changed files with 162 additions and 344 deletions

View File

@@ -19,7 +19,7 @@ package gplx.xowa.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.
import gplx.xowa.files.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.wkrs.lnkis.htmls.*; import gplx.xowa.xtns.pfuncs.ttls.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.parsers.tmpls.*;
public class Xop_lnki_tkn extends Xop_tkn_itm_base {
public class Xop_lnki_tkn extends Xop_tkn_itm_base implements gplx.xowa.wikis.pages.lnkis.Xopg_lnki_itm {
@Override public byte Tkn_tid() {return tkn_tid;} private byte tkn_tid = Xop_tkn_itm_.Tid_lnki;
public void Tkn_tid_to_txt() {tkn_tid = Xop_tkn_itm_.Tid_txt;}
public int Ns_id() {return ns_id;} public Xop_lnki_tkn Ns_id_(int v) {ns_id = v; return this;} private int ns_id;
@@ -46,7 +46,7 @@ public class Xop_lnki_tkn extends Xop_tkn_itm_base {
public boolean Alt_exists() {return alt_tkn != Arg_nde_tkn.Null;}
public int Subpage_tid() {return subpage_tid;} public Xop_lnki_tkn Subpage_tid_(int v) {subpage_tid = v; return this;} private int subpage_tid = Pfunc_rel2abs.Id_null;
public boolean Subpage_slash_at_end() {return subpage_slash_at_end;} public Xop_lnki_tkn Subpage_slash_at_end_(boolean v) {subpage_slash_at_end = v; return this;} private boolean subpage_slash_at_end;
public int Html_uid() {return html_uid;} public Xop_lnki_tkn Html_uid_(int v) {html_uid = v; return this;} private int html_uid;
public int Html_uid() {return html_uid;} public void Html_uid_(int v) {html_uid = v;} private int html_uid;
public int Pipe_count() {return pipe_count;} private int pipe_count;
public boolean Pipe_count_is_zero() {return pipe_count++ == 0;}
public boolean Xtn_sites_link() {return xtn_sites_link;} public void Xtn_sites_link_(boolean v) {xtn_sites_link = v;} private boolean xtn_sites_link;

View File

@@ -20,7 +20,7 @@ import gplx.core.primitives.*; import gplx.core.btries.*;
import gplx.xowa.langs.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.wikis.*; import gplx.xowa.xtns.pfuncs.ttls.*; import gplx.xowa.xtns.relatedSites.*;
import gplx.xowa.parsers.tmpls.*; import gplx.xowa.parsers.lnkis.redlinks.*;
import gplx.xowa.parsers.tmpls.*; import gplx.xowa.wikis.pages.lnkis.*;
public class Xop_lnki_wkr_ {
private static final Int_obj_ref rel2abs_tid = Int_obj_ref.New_zero();
public static final int Invalidate_lnki_len = 128;

View File

@@ -1,117 +0,0 @@
/*
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.core.primitives.*;
import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.langs.vnts.*; import gplx.xowa.guis.views.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.htmls.core.makes.imgs.*;
import gplx.xowa.parsers.tmpls.*;
public class Xog_redlink_mgr implements Gfo_invk {
private Gfo_usr_dlg usr_dlg; 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 int thread_id;
public Xog_redlink_mgr(Xoae_page page) {
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.usr_dlg = Gfo_usr_dlg_.Instance;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_run)) Redlink();
else return Gfo_invk_.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();
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 (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 (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 (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(usr_dlg, page_hash, Bool_.Y, i, end);
}
int redlink_count = 0;
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_.To_str(lnki.Html_uid());
if (variants_enabled) {
Xowd_page_itm vnt_page = vnt_mgr.Convert_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__lnki_style(), ""))
html_itm.Html_atr_set(lnki_id, "style", vnt_mgr.Html__lnki_style());
continue;
}
}
if (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_.To_str(uid));
redlink_mgr.Add(uid);
++redlink_count;
}
}
usr_dlg.Log_many("", "", "redlink.redlink_end: redlinks_run=~{0}", redlink_count);
}
}
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_.To_str(uid));
}
}

View File

@@ -1,33 +0,0 @@
/*
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.core.primitives.*;
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

@@ -1,51 +0,0 @@
/*
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.nss.*;
import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.users.*;
public class Xopg_redlink_lnki_list {
private int lnki_idx = gplx.xowa.htmls.core.wkrs.lnkis.htmls.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 = gplx.xowa.htmls.core.wkrs.lnkis.htmls.Xoh_lnki_wtr.Lnki_id_min; // 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_is_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_is_ctg() && !ttl.ForceLiteralLink()) // ignore ctgs which have their own html builder, unless it is literal; EX: [[:Category:A]]; DATE:2014-02-24
|| ns.Id_is_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 = "xolnki_";
public static final int Lnki_id_prefix_len = String_.Len(Lnki_id_prefix);
}