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:
@@ -17,10 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.htmls.core.makes.imgs.*; import gplx.xowa.files.*;
|
||||
import gplx.xowa.parsers.lnkis.redlinks.*;
|
||||
import gplx.xowa.wikis.pages.lnkis.*;
|
||||
public class Xopg_hdump_data {
|
||||
public byte[] Body() {return body;} public void Body_(byte[] v) {body = v;} private byte[] body;
|
||||
public Xopg_redlink_idx_list Redlink_mgr() {return redlink_mgr;} private final Xopg_redlink_idx_list redlink_mgr = new Xopg_redlink_idx_list();
|
||||
public List_adp Imgs() {return imgs;} private final List_adp imgs = List_adp_.New();
|
||||
public void Imgs_add(Xohd_img_itm itm) {imgs.Add(itm);}
|
||||
public void Imgs_add_img(Xohd_img_itm__base img, Xof_file_itm xfer, int tid) {
|
||||
@@ -34,6 +33,5 @@ public class Xopg_hdump_data {
|
||||
public void Clear() {
|
||||
body = null;
|
||||
imgs.Clear();
|
||||
redlink_mgr.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
22
400_xowa/src/gplx/xowa/wikis/pages/lnkis/Xopg_lnki_itm.java
Normal file
22
400_xowa/src/gplx/xowa/wikis/pages/lnkis/Xopg_lnki_itm.java
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
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.*;
|
||||
public interface Xopg_lnki_itm {
|
||||
Xoa_ttl Ttl();
|
||||
int Html_uid(); void Html_uid_(int v);
|
||||
}
|
||||
50
400_xowa/src/gplx/xowa/wikis/pages/lnkis/Xopg_lnki_list.java
Normal file
50
400_xowa/src/gplx/xowa/wikis/pages/lnkis/Xopg_lnki_list.java
Normal 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.wikis.pages.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.pages.*;
|
||||
import gplx.xowa.wikis.nss.*; import gplx.xowa.parsers.lnkis.*;
|
||||
public class Xopg_lnki_list {
|
||||
private final List_adp list = List_adp_.New();
|
||||
private int lnki_idx;
|
||||
public Xopg_lnki_list(boolean ttl_is_module) { // never redlink in Module ns; particularly since Lua has multi-line comments for [[ ]]
|
||||
this.disabled = ttl_is_module;
|
||||
this.Clear();
|
||||
}
|
||||
public boolean Disabled() {return disabled;} private final boolean disabled;
|
||||
public int Len() {return list.Len();}
|
||||
public Xopg_lnki_itm Get_at(int i) {return (Xop_lnki_tkn)list.Get_at(i);}
|
||||
public void Add(Xopg_lnki_itm lnki) {
|
||||
if (disabled) return;
|
||||
Xoa_ttl ttl = lnki.Ttl(); if (ttl == null) return; // ttl is null 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;
|
||||
list.Add(lnki);
|
||||
}
|
||||
public void Clear() {
|
||||
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; DATE:2014-10-09
|
||||
list.Clear();
|
||||
}
|
||||
|
||||
public static final String Lnki_id_prefix = "xolnki_";
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user