mirror of https://github.com/gnosygnu/xowa
parent
d4e8590345
commit
d43e0d2341
@ -1,86 +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/>.
|
||||
*/
|
||||
//namespace gplx.xowa.htmls.core.to_delete {
|
||||
// using gplx.core.primitives; using gplx.core.btries; using gplx.dbs; using gplx.core.ios;
|
||||
// using gplx.xowa.wikis.dbs; using gplx.xowa.wikis.pages; using gplx.xowa.htmls.core.makes.imgs; using gplx.xowa.wikis.pages.skins;
|
||||
// using gplx.xowa.wikis.data; using gplx.xowa.wikis.data.tbls; using gplx.xowa.guis;
|
||||
// public class Xohd_page_html_mgr__load {
|
||||
// private final Bry_rdr_old rdr = new Bry_rdr_old(); private final List_adp rows = List_adp_.New(), imgs = List_adp_.New();
|
||||
// public void Load_page(Xow_wiki wiki, Xoh_page hpg, Xowd_html_tbl tbl, int page_id, Xoa_ttl page_ttl) {
|
||||
// Xoa_app_.Usr_dlg().Plog_many("", "", "hdump.load.text: ttl=~{0}", page_ttl.Full_db_as_str());
|
||||
// tbl.Select_by_page(rows, page_id);
|
||||
// Parse_rows(wiki, hpg, page_id, Xoa_url.blank(), page_ttl, rows);
|
||||
// }
|
||||
// public void Parse_rows(Xow_wiki wiki, Xoh_page hpg, int page_id, Xoa_url page_url, Xoa_ttl page_ttl, List_adp rows) { // TEST:
|
||||
// hpg.Init(wiki, page_id, page_url, page_ttl);
|
||||
// imgs.Clear();
|
||||
// int len = rows.Count();
|
||||
// for (int i = 0; i < len; ++i) {
|
||||
// Xowd_html_row row = (Xowd_html_row)rows.Get_at(i);
|
||||
// switch (row.Tid()) {
|
||||
// case Xowd_html_row.Tid__img:
|
||||
// case Xowd_html_row.Tid__redlink:
|
||||
// Parse_data(hpg, row); break;
|
||||
// }
|
||||
// }
|
||||
// rows.Clear();
|
||||
// }
|
||||
// private void Parse_data(Xoh_page hpg, Xowd_html_row row) {
|
||||
// rdr.Init(row.Data());
|
||||
// while (!rdr.Pos_is_eos()) {
|
||||
// int tid = rdr.Read_int_to_pipe();
|
||||
// switch (tid) {
|
||||
// case Xohd_img_tid.Tid_img : Load_data_img(); break; // 1|0|A.png|0|220|110|...
|
||||
// case Xohd_img_tid.Tid_gallery : Load_data_gallery(hpg); break; // 3|0|800
|
||||
// case Xohd_img_tid.Tid_redlink : Load_data_redlink(hpg); break; // 2|2|0|1
|
||||
// }
|
||||
// }
|
||||
// if (imgs.Count() > 0) hpg.Img_itms_((Xohd_img_itm__base[])imgs.To_ary_and_clear(typeof(Xohd_img_itm__base)));
|
||||
// }
|
||||
// public static Xohd_img_itm__base Load_img(Bry_rdr_old rdr) {
|
||||
// int tid = rdr.Read_int_to_pipe();
|
||||
// Xohd_img_itm__base img_itm = null;
|
||||
// switch (tid) {
|
||||
// case Xohd_img_itm__base.Tid_basic : img_itm = new Xohd_img_itm__img(); break;
|
||||
// case Xohd_img_itm__base.Tid_gallery : img_itm = new Xohd_img_itm__gallery_itm(); break;
|
||||
// default : throw Err_.new_unhandled(tid);
|
||||
// }
|
||||
// img_itm.Data_parse(rdr);
|
||||
// // Xoa_app_.Usr_dlg().Log_many("", "", "itm: ~{0}", img_itm.Data_print());
|
||||
// rdr.Pos_add_one();
|
||||
// return img_itm;
|
||||
// }
|
||||
// private void Load_data_img() {
|
||||
// Xohd_img_itm__base img = Load_img(rdr);
|
||||
// if (img == null) return;
|
||||
// imgs.Add(img);
|
||||
// }
|
||||
// private void Load_data_redlink(Xoh_page hpg) {
|
||||
// Ordered_hash redlink_hash = hpg.Redlink_uids();
|
||||
// while (!rdr.Pos_is_eos()) {
|
||||
// Int_obj_ref redlink_uid = Int_obj_ref.New(rdr.Read_int_to_pipe());
|
||||
// redlink_hash.Add(redlink_uid, redlink_uid);
|
||||
// }
|
||||
// }
|
||||
// private void Load_data_gallery(Xoh_page hpg) {
|
||||
// int uid = rdr.Read_int_to_pipe();
|
||||
// int box_max = rdr.Read_int_to_pipe();
|
||||
// hpg.Gallery_itms().Add_if_dupe_use_nth(uid, new Xohd_img_itm__gallery_mgr(uid, box_max)); // TODO_OLD: temporarily added b/c last build did not add gallery uid correctly
|
||||
// }
|
||||
// }
|
||||
//}
|
@ -1,50 +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/>.
|
||||
*/
|
||||
//namespace gplx.xowa.htmls.core.to_delete {
|
||||
// using gplx.xowa.wikis.data; using gplx.xowa.wikis.data.tbls; using gplx.xowa.htmls.core.makes.imgs;
|
||||
// using gplx.xowa.guis; using gplx.xowa.wikis.pages; using gplx.xowa.parsers.lnkis.redlinks;
|
||||
// public class Xohd_page_html_mgr__save {
|
||||
// public void Update(Bry_bfr tmp_bfr, Xowd_html_tbl tbl, Xoae_page page) {
|
||||
// Xoh_page hpg = new Xoh_page().Ctor_by_page(tmp_bfr, page);
|
||||
// tbl.Delete(page.Revision_data().Id());
|
||||
// this.Insert(tmp_bfr, tbl, hpg, page.Hdump_data());
|
||||
// }
|
||||
// public int Insert(Bry_bfr tmp_bfr, Xowd_html_tbl tbl, Xoh_page hpg, Xopg_hdump_data hdump_data) {
|
||||
// int rv = 0;
|
||||
// int page_id = hpg.Page_id();
|
||||
// rv += Insert_row(tbl, page_id, Xowd_html_row.Tid__img , Write_imgs(tmp_bfr, hdump_data.Imgs()));
|
||||
// rv += Insert_row(tbl, page_id, Xowd_html_row.Tid__redlink , Write_redlinks(tmp_bfr, hdump_data.Redlink_mgr()));
|
||||
// return rv;
|
||||
// }
|
||||
// private int Insert_row(Xowd_html_tbl tbl, int page_id, int row_tid, byte[] bry) {return bry == null ? 0 : tbl.Insert(page_id, row_tid, bry);}
|
||||
// public static byte[] Write_redlinks(Bry_bfr bfr, Xopg_redlink_idx_list redlink_mgr) {
|
||||
// int len = redlink_mgr.Len(); if (len == 0) return null;
|
||||
// for (int i = 0; i < len; ++i)
|
||||
// bfr.Add_int_variable(redlink_mgr.Get_at(i)).Add_byte_pipe();
|
||||
// return bfr.To_bry_and_clear();
|
||||
// }
|
||||
// public static byte[] Write_imgs(Bry_bfr bfr, List_adp imgs) {
|
||||
// int len = imgs.Count(); if (len == 0) return null; // no images; exit early, else will write blank String
|
||||
// for (int i = 0; i < len; ++i) {
|
||||
// Xohd_img_itm itm = (Xohd_img_itm)imgs.Get_at(i);
|
||||
// itm.Data_write(bfr);
|
||||
// }
|
||||
// return bfr.To_bry_and_clear();
|
||||
// }
|
||||
// }
|
||||
//}
|
@ -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));
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
/*
|
||||
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.pages.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.pages.*;
|
||||
import gplx.xowa.files.gui.*;
|
||||
import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.langs.vnts.*;
|
||||
public class Xopg_redlink_mgr implements Gfo_invk {
|
||||
private final Xoa_page page; private final Xog_js_wkr js_wkr;
|
||||
public Xopg_redlink_mgr(Xoa_page page, Xog_js_wkr js_wkr) {this.page = page; this.js_wkr = js_wkr; }
|
||||
private void Redlink() {
|
||||
Xopg_lnki_list lnki_list = page.Redlink_list(); if (lnki_list.Disabled()) return;
|
||||
Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_.Instance;
|
||||
Xow_wiki wiki = page.Wiki();
|
||||
Ordered_hash lnki_hash = Ordered_hash_.New_bry();
|
||||
|
||||
// create unique list of page_rows
|
||||
int len = lnki_list.Len();
|
||||
usr_dlg.Log_many("", "", "redlink.redlink_bgn: page=~{0} total_links=~{1}", page.Ttl().Raw(), len);
|
||||
for (int i = 0; i < len; ++i) {
|
||||
if (usr_dlg.Canceled()) return;
|
||||
Xoa_ttl ttl = lnki_list.Get_at(i).Ttl();
|
||||
Xowd_page_itm page_row = new Xowd_page_itm().Ttl_(ttl);
|
||||
byte[] full_db = ttl.Full_db();
|
||||
if (!lnki_hash.Has(full_db)) // only search page_table once for multiple identical redlinks; EX: "[[Missing]] [[Missing]]"
|
||||
lnki_hash.Add(full_db, page_row);
|
||||
}
|
||||
|
||||
// load page_rows from page_tbl
|
||||
int page_len = lnki_hash.Len();
|
||||
for (int i = 0; i < page_len; i += Batch_size) {
|
||||
if (usr_dlg.Canceled()) return;
|
||||
int end = i + Batch_size; if (end > page_len) end = page_len;
|
||||
wiki.Data__core_mgr().Tbl__page().Select_in__ns_ttl(usr_dlg, lnki_hash, wiki.Ns_mgr(), Bool_.Y, i, end);
|
||||
// wiki.Db_mgr().Load_mgr().Load_by_ttls(usr_dlg, lnki_hash, Bool_.Y, i, end);
|
||||
}
|
||||
|
||||
// cross-check page_rows against lnki_list; redlink if missing;
|
||||
boolean vnt_enabled = wiki.Lang().Vnt_mgr().Enabled();
|
||||
Xol_vnt_mgr vnt_mgr = wiki.Lang().Vnt_mgr();
|
||||
int redlink_count = 0;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xopg_lnki_itm lnki = lnki_list.Get_at(i);
|
||||
byte[] full_db = lnki.Ttl().Full_db();
|
||||
Xowd_page_itm page_row = (Xowd_page_itm)lnki_hash.Get_by(full_db);
|
||||
if (page_row.Exists()) continue; // page exists; nothing to do;
|
||||
|
||||
// for vnt languages, convert missing ttl to vnt and check again; EX: [[zh_cn]] will check for page_ttl for [[zh_tw]]
|
||||
String html_uid = Xopg_lnki_list.Lnki_id_prefix + Int_.To_str(lnki.Html_uid());
|
||||
if (vnt_enabled) {
|
||||
Xowd_page_itm vnt_page = vnt_mgr.Convert_mgr().Convert_ttl(wiki, lnki.Ttl()); // check db
|
||||
if (vnt_page != null) { // vnt found; update href to point to vnt
|
||||
Xoa_ttl vnt_ttl = wiki.Ttl_parse(lnki.Ttl().Ns().Id(), vnt_page.Ttl_page_db());
|
||||
js_wkr.Html_atr_set(html_uid, "href", "/wiki/" + String_.new_u8(vnt_ttl.Full_url()));
|
||||
if (!String_.Eq(vnt_mgr.Html__lnki_style(), "")) js_wkr.Html_atr_set(html_uid, "style", vnt_mgr.Html__lnki_style()); // colorize for debugging
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// lnki is missing; redlink it
|
||||
if (usr_dlg.Canceled()) return;
|
||||
Js_img_mgr.Update_link_missing(js_wkr, html_uid);
|
||||
++redlink_count;
|
||||
}
|
||||
usr_dlg.Log_many("", "", "redlink.redlink_end: redlinks_run=~{0}", redlink_count);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_run)) {synchronized (this) {Redlink();}} // NOTE: attempt to eliminate random IndexBounds errors; DATE:2014-09-02
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
} public static final String Invk_run = "run";
|
||||
private static final int Batch_size = 32;
|
||||
}
|
Loading…
Reference in new issue