mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.7.2.1
This commit is contained in:
120
400_xowa/src/gplx/xowa/xtns/proofreadPage/Pp_index_parser.java
Normal file
120
400_xowa/src/gplx/xowa/xtns/proofreadPage/Pp_index_parser.java
Normal file
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
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.xtns.proofreadPage; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.primitives.*; import gplx.xowa.parsers.logs.*;
|
||||
class Pp_index_parser {
|
||||
public static Pp_index_page Parse(Xowe_wiki wiki, Xop_ctx ctx, Xoa_ttl index_ttl, int ns_page_id) {
|
||||
byte[] src = wiki.Cache_mgr().Page_cache().Get_or_load_as_src(index_ttl);
|
||||
if (src == null) return Pp_index_page.Null;
|
||||
Xop_parser sub_parser = new Xop_parser(wiki, wiki.Parser().Tmpl_lxr_mgr(), wiki.Parser().Wtxt_lxr_mgr());
|
||||
Xop_ctx sub_ctx = Xop_ctx.new_sub_(wiki);
|
||||
Xop_tkn_mkr tkn_mkr = sub_ctx.Tkn_mkr();
|
||||
Xop_root_tkn index_root = tkn_mkr.Root(src);
|
||||
byte[] mid_text = sub_parser.Parse_text_to_wtxt(index_root, sub_ctx, tkn_mkr, src);
|
||||
Pp_index_page rv = new Pp_index_page();
|
||||
Inspect_tmpl(rv, src, index_root, index_root.Subs_len(), ns_page_id, 1);
|
||||
sub_parser.Parse_wtxt_to_wdom(index_root, sub_ctx, tkn_mkr, mid_text, Xop_parser_.Doc_bgn_bos);
|
||||
rv.Src_(mid_text);
|
||||
Inspect_wiki(rv, mid_text, index_root, index_root.Subs_len(), ns_page_id, 1); // changed from src to mid_text; DATE:2014-07-14
|
||||
return rv;
|
||||
}
|
||||
private static void Inspect_tmpl(Pp_index_page rv, byte[] src, Xop_tkn_itm_base owner, int owner_len, int ns_page_id, int depth) {
|
||||
for (int i = 0; i < owner_len; i++) {
|
||||
Xop_tkn_itm sub = owner.Subs_get(i);
|
||||
int sub_tid = sub.Tkn_tid();
|
||||
switch (sub_tid) {
|
||||
case Xop_tkn_itm_.Tid_tmpl_invk: {
|
||||
if (depth == 1) { // NOTE: only look at tmpls directly beneath root; note that this should be fine b/c [[Index:]] pages have a constrained form-fields GUI; ProofreadPage takes the form fields, and builds a template from it; DATE:2014-01-25
|
||||
Xot_invk_tkn invk = (Xot_invk_tkn)sub;
|
||||
int args_len = invk.Args_len();
|
||||
for (int j = 0; j < args_len; j++) {
|
||||
Arg_nde_tkn nde_tkn = invk.Args_get_by_idx(j);
|
||||
byte[] key = Get_bry(src, nde_tkn.Key_tkn());
|
||||
byte[] val = Get_bry(src, nde_tkn.Val_tkn());
|
||||
rv.Invk_args().Add(new Pp_index_arg(key, val));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
int sub_subs_len = sub.Subs_len();
|
||||
if (sub_subs_len > 0)
|
||||
Inspect_tmpl(rv, src, (Xop_tkn_itm_base)sub, sub_subs_len, ns_page_id, depth + 1);
|
||||
}
|
||||
}
|
||||
private static void Inspect_wiki(Pp_index_page rv, byte[] src, Xop_tkn_itm_base owner, int owner_len, int ns_page_id, int depth) {
|
||||
for (int i = 0; i < owner_len; i++) {
|
||||
Xop_tkn_itm sub = owner.Subs_get(i);
|
||||
int sub_tid = sub.Tkn_tid();
|
||||
switch (sub_tid) {
|
||||
case Xop_tkn_itm_.Tid_lnki: {
|
||||
Xop_lnki_tkn lnki = (Xop_lnki_tkn)sub;
|
||||
int sub_ns_id = lnki.Ns_id();
|
||||
if (sub_ns_id == ns_page_id) rv.Page_ttls().Add(lnki.Ttl());
|
||||
else if (sub_ns_id == Xow_ns_.Id_main) rv.Main_lnkis().Add(lnki);
|
||||
break;
|
||||
}
|
||||
case Xop_tkn_itm_.Tid_xnde: {
|
||||
Xop_xnde_tkn xnde = (Xop_xnde_tkn)sub;
|
||||
if (xnde.Tag().Id() == Xop_xnde_tag_.Tid_pagelist)
|
||||
rv.Pagelist_xndes().Add(xnde);
|
||||
break;
|
||||
}
|
||||
}
|
||||
int sub_subs_len = sub.Subs_len();
|
||||
if (sub_subs_len > 0)
|
||||
Inspect_wiki(rv, src, (Xop_tkn_itm_base)sub, sub_subs_len, ns_page_id, depth + 1);
|
||||
}
|
||||
}
|
||||
private static byte[] Get_bry(byte[] src, Arg_itm_tkn itm) {
|
||||
return Bry_.Mid(src, itm.Dat_bgn(), itm.Dat_end());
|
||||
}
|
||||
}
|
||||
class Pp_index_page {
|
||||
public Pp_index_page() {}
|
||||
public byte[] Src() {return src;} public Pp_index_page Src_(byte[] v) {src = v; return this;} private byte[] src;
|
||||
public List_adp Pagelist_xndes() {return pagelist_xndes;} private List_adp pagelist_xndes = List_adp_.new_();
|
||||
public List_adp Page_ttls() {return page_ttls;} private List_adp page_ttls = List_adp_.new_();
|
||||
public List_adp Main_lnkis() {return main_lnkis;} private List_adp main_lnkis = List_adp_.new_();
|
||||
public List_adp Invk_args() {return invk_args;} private List_adp invk_args = List_adp_.new_();
|
||||
public Xoa_ttl[] Get_ttls_rng(Xowe_wiki wiki, int ns_page_id, byte[] bgn_page_bry, byte[] end_page_bry, Int_obj_ref bgn_page_ref, Int_obj_ref end_page_ref) {
|
||||
int list_len = page_ttls.Count(); if (list_len == 0) return Pp_pages_nde.Ttls_null;
|
||||
List_adp rv = List_adp_.new_();
|
||||
Xoa_ttl bgn_page_ttl = new_ttl_(wiki, ns_page_id, bgn_page_bry), end_page_ttl = new_ttl_(wiki, ns_page_id, end_page_bry);
|
||||
boolean add = bgn_page_ttl == Xoa_ttl.Null; // if from is missing, default to bgn; EX: <pages index=A to="A/5"/>
|
||||
for (int i = 0; i < list_len; i++) { // REF.MW:ProofreadPageRenderer|renderPages
|
||||
Xoa_ttl ttl = (Xoa_ttl)page_ttls.Get_at(i);
|
||||
if ( ttl.Eq_page_db(bgn_page_ttl)) {add = Bool_.Y; bgn_page_ref.Val_(i);}
|
||||
if (add) rv.Add(ttl);
|
||||
if ( end_page_ttl != Xoa_ttl.Null // if to is missing default to end;
|
||||
&& ttl.Eq_page_db(end_page_ttl)
|
||||
) {add = Bool_.N; end_page_ref.Val_(i);}
|
||||
}
|
||||
if (bgn_page_ref.Val() == -1) bgn_page_ref.Val_(0); // NOTE: set "from" which will be passed to {{MediaWiki:Proofreadpage_header_template}}; DATE:2014-05-21
|
||||
if (end_page_ref.Val() == -1) end_page_ref.Val_(list_len - 1); // NOTE: set "to" which will be passed to {{MediaWiki:Proofreadpage_header_template}}; DATE:2014-05-21
|
||||
if (rv.Count() == 0) return Pp_pages_nde.Ttls_null;
|
||||
return (Xoa_ttl[])rv.To_ary(Xoa_ttl.class);
|
||||
}
|
||||
private static Xoa_ttl new_ttl_(Xowe_wiki wiki, int ns_page_id, byte[] bry) {return bry == null ? Xoa_ttl.Null : Xoa_ttl.parse_(wiki, ns_page_id, bry);}
|
||||
public static final Pp_index_page Null = new Pp_index_page();
|
||||
}
|
||||
class Pp_index_arg {
|
||||
public Pp_index_arg(byte[] key, byte[] val) {this.key = key; this.val = val;}
|
||||
public byte[] Key() {return key;} private byte[] key;
|
||||
public byte[] Val() {return val;} private byte[] val;
|
||||
}
|
||||
@@ -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.xtns.proofreadPage; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.xowa.html.*;
|
||||
import gplx.xowa.parsers.logs.*;
|
||||
public class Pp_pagelist_nde implements Xox_xnde, Xop_xnde_atr_parser { // TODO:
|
||||
public void Xatr_parse(Xowe_wiki wiki, byte[] src, Xop_xatr_itm xatr, Object xatr_key_obj) {}
|
||||
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
|
||||
boolean log_wkr_enabled = Log_wkr != Xop_log_basic_wkr.Null; if (log_wkr_enabled) Log_wkr.Log_end_xnde(ctx.Cur_page(), Xop_log_basic_wkr.Tid_hiero, src, xnde);
|
||||
} public static Xop_log_basic_wkr Log_wkr = Xop_log_basic_wkr.Null;
|
||||
public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
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.xtns.proofreadPage; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import org.junit.*;
|
||||
public class Pp_pagelist_nde_tst {
|
||||
private Xop_fxt fxt = new Xop_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test_parse_page_wiki_str("a<pagelist>b</pagelist>c", "ac");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
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.xtns.proofreadPage; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.xowa.html.*;
|
||||
public class Pp_pagequality_nde implements Xox_xnde {
|
||||
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {} // FUTURE: noop for now so it doesn't show (since it's useless)
|
||||
public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
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.xtns.proofreadPage; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import org.junit.*;
|
||||
public class Pp_pagequality_nde_tst {
|
||||
private Xop_fxt fxt = new Xop_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test_parse_page_wiki_str("a<pagequality>b</pagequality>c", "ac");
|
||||
}
|
||||
}
|
||||
442
400_xowa/src/gplx/xowa/xtns/proofreadPage/Pp_pages_nde.java
Normal file
442
400_xowa/src/gplx/xowa/xtns/proofreadPage/Pp_pages_nde.java
Normal file
@@ -0,0 +1,442 @@
|
||||
/*
|
||||
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.xtns.proofreadPage; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.xowa.html.*; import gplx.xowa.parsers.amps.*;
|
||||
import gplx.xowa.xtns.lst.*; import gplx.xowa.pages.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Pp_pages_nde implements Xox_xnde, Xop_xnde_atr_parser {
|
||||
private boolean xtn_literal = false;
|
||||
private Xop_root_tkn xtn_root;
|
||||
private byte[] index_ttl_bry, bgn_page_bry, end_page_bry, bgn_sect_bry, end_sect_bry;
|
||||
private int step_int;
|
||||
private byte[] include, exclude, step_bry, header, onlysection;
|
||||
private byte[] toc_cur, toc_nxt, toc_prv;
|
||||
private int ns_index_id = Int_.MinValue, ns_page_id = Int_.MinValue;
|
||||
private int bgn_page_int = -1, end_page_int = -1;
|
||||
private Xow_ns ns_page;
|
||||
private Xoa_ttl index_ttl;
|
||||
private Xoae_app app; private Xowe_wiki wiki; private Xop_ctx ctx; private Gfo_usr_dlg usr_dlg;
|
||||
private byte[] src; private Xop_xnde_tkn xnde_tkn;
|
||||
private Xoa_ttl cur_page_ttl;
|
||||
public void Xatr_parse(Xowe_wiki wiki, byte[] src, Xop_xatr_itm xatr, Object xatr_key_obj) {
|
||||
if (xatr_key_obj == null) return;
|
||||
Byte_obj_val xatr_key = (Byte_obj_val)xatr_key_obj;
|
||||
switch (xatr_key.Val()) {
|
||||
case Xatr_index_ttl: index_ttl_bry = xatr.Val_as_bry(src); break;
|
||||
case Xatr_bgn_page: bgn_page_bry = xatr.Val_as_bry(src); break;
|
||||
case Xatr_end_page: end_page_bry = xatr.Val_as_bry(src); break;
|
||||
case Xatr_bgn_sect: bgn_sect_bry = xatr.Val_as_bry(src); break;
|
||||
case Xatr_end_sect: end_sect_bry = xatr.Val_as_bry(src); break;
|
||||
case Xatr_include: include = xatr.Val_as_bry(src); break;
|
||||
case Xatr_exclude: exclude = xatr.Val_as_bry(src); break;
|
||||
case Xatr_step: step_bry = xatr.Val_as_bry(src); break;
|
||||
case Xatr_onlysection: onlysection = xatr.Val_as_bry(src); break;
|
||||
case Xatr_header: header = xatr.Val_as_bry(src); break;
|
||||
case Xatr_toc_cur: toc_cur = xatr.Val_as_bry(src); break;
|
||||
case Xatr_toc_prv: toc_prv = xatr.Val_as_bry(src); break;
|
||||
case Xatr_toc_nxt: toc_nxt = xatr.Val_as_bry(src); break;
|
||||
}
|
||||
}
|
||||
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
|
||||
// if (!wiki.Xtn_mgr().Xtn_proofread().Enabled()) return;
|
||||
if (!Init_vars(wiki, ctx, src, xnde)) return;
|
||||
Xoae_page page = ctx.Cur_page();
|
||||
if (page.Pages_recursed()) return; // moved from Pp_index_parser; DATE:2014-05-21s
|
||||
page.Pages_recursed_(true);
|
||||
Bry_bfr full_bfr = app.Utl__bfr_mkr().Get_m001();
|
||||
Hash_adp_bry lst_page_regy = ctx.Lst_page_regy(); if (lst_page_regy == null) lst_page_regy = Hash_adp_bry.cs_(); // SEE:NOTE:page_regy; DATE:2014-01-01
|
||||
page.Html_data().Indicators().Enabled_(Bool_.N); // disable <indicator> b/c <page> should not add to current page; PAGE:en.s:The_Parochial_System_(Wilberforce,_1838); DATE:2015-04-29
|
||||
byte[] page_bry = Bld_wikitext(full_bfr, lst_page_regy);
|
||||
if (page_bry != null)
|
||||
xtn_root = Bld_root_nde(full_bfr, lst_page_regy, page_bry); // NOTE: this effectively reparses page twice; needed b/c of "if {| : ; # *, auto add new_line" which can build different tokens
|
||||
page.Pages_recursed_(false);
|
||||
full_bfr.Mkr_rls();
|
||||
page.Html_data().Indicators().Enabled_(Bool_.Y);
|
||||
}
|
||||
public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {
|
||||
if (xtn_literal)
|
||||
Xox_mgr_base.Xtn_write_escape(app, bfr, src, xnde);
|
||||
else {
|
||||
if (xtn_root == null) return; // xtn_root is null when Xtn_parse exits early; occurs for recursion; DATE:2014-05-21
|
||||
html_wtr.Write_tkn(bfr, ctx, hctx, xtn_root.Root_src(), xnde, Xoh_html_wtr.Sub_idx_null, xtn_root);
|
||||
}
|
||||
}
|
||||
private boolean Init_vars(Xowe_wiki wiki, Xop_ctx ctx, byte[] src, Xop_xnde_tkn xnde) {
|
||||
this.wiki = wiki; this.ctx = ctx; app = wiki.Appe(); usr_dlg = app.Usr_dlg();
|
||||
this.src = src; this.xnde_tkn = xnde; cur_page_ttl = ctx.Cur_page().Ttl();
|
||||
Xop_xatr_itm.Xatr_parse(app, this, xtn_atrs, wiki, src, xnde);
|
||||
Xop_amp_mgr amp_mgr = wiki.Appe().Parser_amp_mgr();
|
||||
index_ttl_bry = amp_mgr.Decode_as_bry(index_ttl_bry);
|
||||
bgn_page_bry = amp_mgr.Decode_as_bry(bgn_page_bry);
|
||||
end_page_bry = amp_mgr.Decode_as_bry(end_page_bry);
|
||||
Xowc_xtn_pages cfg_pages = wiki.Cfg_parser().Xtns().Itm_pages();
|
||||
if (cfg_pages.Init_needed()) cfg_pages.Init(wiki.Ns_mgr());
|
||||
ns_index_id = cfg_pages.Ns_index_id(); if (ns_index_id == Int_.MinValue) return Fail_msg("wiki does not have an Index ns");
|
||||
ns_page_id = cfg_pages.Ns_page_id(); if (ns_page_id == Int_.MinValue) return Fail_msg("wiki does not have a Page ns"); // occurs when <pages> used in a wiki without a "Page:" ns; EX: de.w:Help:Buchfunktion/Feedback
|
||||
index_ttl = Xoa_ttl.parse_(wiki, ns_index_id, index_ttl_bry); if (index_ttl == null) return Fail_args("index title is not valid: index={0}", String_.new_u8(index_ttl_bry));
|
||||
ns_page = wiki.Ns_mgr().Ids_get_or_null(ns_page_id);
|
||||
if (onlysection != null)
|
||||
bgn_sect_bry = end_sect_bry = null;
|
||||
return true;
|
||||
}
|
||||
private byte[] Bld_wikitext(Bry_bfr full_bfr, Hash_adp_bry lst_page_regy) {
|
||||
Pp_index_page index_page = Pp_index_parser.Parse(wiki, ctx, index_ttl, ns_page_id);
|
||||
int index_page_ttls_len = index_page.Page_ttls().Count();
|
||||
byte[] rv = Bry_.Empty;
|
||||
if (bgn_page_bry != null || end_page_bry != null || include != null) { // from, to, or include specified
|
||||
Xoa_ttl[] ttls = null;
|
||||
if ( index_page.Pagelist_xndes().Count() > 0 // pagelist exists; don't get from args
|
||||
|| index_page_ttls_len == 0 // no [[Page:]] in [[Index:]]
|
||||
) // NOTE: this simulates MW's if (empty($links)); REF.MW:ProofreadPageRenderer.php|renderPages
|
||||
ttls = Get_ttls_from_xnde_args();
|
||||
else {
|
||||
Int_obj_ref bgn_page_ref = Int_obj_ref.neg1_(), end_page_ref = Int_obj_ref.neg1_();
|
||||
ttls = index_page.Get_ttls_rng(wiki, ns_page_id, bgn_page_bry, end_page_bry, bgn_page_ref, end_page_ref);
|
||||
bgn_page_int = bgn_page_ref.Val();
|
||||
end_page_int = end_page_ref.Val();
|
||||
}
|
||||
if (ttls == Ttls_null) {Fail_msg("no index ttls found"); return null;}
|
||||
rv = Bld_wikitext_from_ttls(full_bfr, lst_page_regy, ttls);
|
||||
}
|
||||
else {
|
||||
header = Toc_bry;
|
||||
}
|
||||
if (header != null)
|
||||
rv = Bld_wikitext_for_header(full_bfr, index_page, rv);
|
||||
return rv;
|
||||
} private static final byte[] Toc_bry = Bry_.new_a7("toc");
|
||||
private byte[] Make_lnki(Bry_bfr full_bfr, byte[] index_page_src, Xop_lnki_tkn lnki) {
|
||||
byte[] caption = Get_caption(full_bfr, index_page_src, lnki);
|
||||
full_bfr.Add(Xop_tkn_.Lnki_bgn);
|
||||
Xoa_ttl lnki_ttl = lnki.Ttl();
|
||||
if (lnki_ttl.Wik_bgn() == -1) // no xwiki; just add ns + page
|
||||
full_bfr.Add(lnki_ttl.Full_db());
|
||||
else // xwiki; add entire ttl which also includes xwiki; PAGE:sv.s:Valda_dikter_(Bj<42>rck); EX:[[:Commons:File:Valda dikter (tredje upplagan).djvu|Commons]]; DATE:2014-07-14
|
||||
full_bfr.Add(lnki_ttl.Raw());
|
||||
full_bfr.Add_byte_pipe()
|
||||
.Add(caption)
|
||||
.Add(Xop_tkn_.Lnki_end);
|
||||
return full_bfr.Xto_bry_and_clear();
|
||||
}
|
||||
private byte[] Get_caption(Bry_bfr full_bfr, byte[] index_page_src, Xop_lnki_tkn lnki) {
|
||||
byte[] rv = Bry_.Empty;
|
||||
try {
|
||||
wiki.Html_mgr().Html_wtr().Write_tkn(full_bfr, ctx, Xoh_wtr_ctx.Basic, index_page_src, null, -1, lnki.Caption_tkn());
|
||||
rv = full_bfr.Xto_bry_and_clear();
|
||||
}
|
||||
catch (Exception e) {
|
||||
wiki.Appe().Usr_dlg().Warn_many("", "", "failed to write caption: page=~{0} lnki=~{1} err=~{2}", String_.new_u8(ctx.Cur_page().Ttl().Full_db()), String_.new_u8(index_page_src, lnki.Src_bgn(), lnki.Src_end()), Err_.Message_gplx_brief(e));
|
||||
rv = lnki.Ttl().Page_txt();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
private static final byte[]
|
||||
Bry_tmpl = Bry_.new_a7("{{:MediaWiki:Proofreadpage_header_template")
|
||||
, Bry_value = Bry_.new_a7("|value=")
|
||||
, Bry_toc_cur = Bry_.new_a7("|current=")
|
||||
, Bry_toc_prv = Bry_.new_a7("|prev=")
|
||||
, Bry_toc_nxt = Bry_.new_a7("|next=")
|
||||
, Bry_page_bgn = Bry_.new_a7("|from=")
|
||||
, Bry_page_end = Bry_.new_a7("|to=")
|
||||
;
|
||||
private byte[] Bld_wikitext_for_header(Bry_bfr full_bfr, Pp_index_page index_page, byte[] rv) {
|
||||
List_adp main_lnkis = index_page.Main_lnkis();
|
||||
int main_lnkis_len = main_lnkis.Count();
|
||||
byte[] index_page_src = index_page.Src();
|
||||
if (main_lnkis_len > 0) {
|
||||
Xoa_ttl page_ttl = ctx.Cur_page().Ttl();
|
||||
for (int i = 0; i < main_lnkis_len; i++) {
|
||||
Xop_lnki_tkn main_lnki = (Xop_lnki_tkn)main_lnkis.Get_at(i);
|
||||
if (page_ttl.Eq_full_db(main_lnki.Ttl())) {
|
||||
Xoae_page old_page = ctx.Cur_page();
|
||||
wiki.Html_mgr().Html_wtr().Init_by_page(ctx, Xoh_wtr_ctx.Basic, index_page_src, ctx.Cur_page()); // HACK: should not reuse html_wtr, but should be safe to use during parse (not html_gen)
|
||||
if (toc_cur == null) // do not set if "current" is specified, even if "blank" specified; EX: current=''
|
||||
toc_cur = Make_lnki(full_bfr, index_page_src, main_lnki);
|
||||
if (toc_prv == null // do not set if "prev" is specified
|
||||
&& i > 0)
|
||||
toc_prv = Make_lnki(full_bfr, index_page_src, (Xop_lnki_tkn)main_lnkis.Get_at(i - 1));
|
||||
if (toc_nxt == null // do not set if "next" is specified
|
||||
&& i + 1 < main_lnkis_len)
|
||||
toc_nxt = Make_lnki(full_bfr, index_page_src, (Xop_lnki_tkn)main_lnkis.Get_at(i + 1));
|
||||
wiki.Html_mgr().Html_wtr().Init_by_page(ctx, Xoh_wtr_ctx.Basic, index_page_src, old_page);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
full_bfr.Add(Bry_tmpl); // {{:MediaWiki:Proofreadpage_header_template
|
||||
full_bfr.Add(Bry_value).Add(header); // |value=toc"
|
||||
if (toc_cur != null)
|
||||
full_bfr.Add(Bry_toc_cur).Add(toc_cur); // |current=Page/2"
|
||||
if (toc_prv != null)
|
||||
full_bfr.Add(Bry_toc_prv).Add(toc_prv); // |prev=Page/1"
|
||||
if (toc_nxt != null)
|
||||
full_bfr.Add(Bry_toc_nxt).Add(toc_nxt); // |next=Page/3"
|
||||
if (bgn_page_int != -1)
|
||||
full_bfr.Add(Bry_page_bgn).Add_int_variable(bgn_page_int); // |from=1"
|
||||
if (end_page_int != -1)
|
||||
full_bfr.Add(Bry_page_end).Add_int_variable(end_page_int); // |to=3"
|
||||
List_adp invk_args = index_page.Invk_args();
|
||||
int invk_args_len = invk_args.Count();
|
||||
for (int i = 0; i < invk_args_len; i++) {
|
||||
Pp_index_arg arg = (Pp_index_arg)invk_args.Get_at(i);
|
||||
full_bfr
|
||||
.Add_byte_pipe() // |
|
||||
.Add(wiki.Lang().Case_mgr().Case_build_lower(arg.Key())) // per MW, always lowercase key
|
||||
.Add_byte_eq() // =
|
||||
.Add(arg.Val())
|
||||
;
|
||||
}
|
||||
full_bfr.Add(Xoa_consts.Invk_end);
|
||||
full_bfr.Add(rv);
|
||||
return full_bfr.Xto_bry_and_clear();
|
||||
}
|
||||
private Xoa_ttl[] Get_ttls_from_xnde_args() {
|
||||
if (!Chk_step()) return Ttls_null;
|
||||
List_adp list = List_adp_.new_();
|
||||
list = Get_ttls_from_xnde_args__include(list); if (list == null) return Ttls_null;
|
||||
list = Get_ttls_from_xnde_args__rng(list); if (list == null) return Ttls_null;
|
||||
list = Get_ttls_from_xnde_args__exclude(list); if (list == null) return Ttls_null;
|
||||
if (include != null || exclude != null) // sort if include / exclude specified; will skip sort if only range specified
|
||||
list.Sort();
|
||||
return Get_ttls_from_xnde_args__ttls(list);
|
||||
}
|
||||
private List_adp Get_ttls_from_xnde_args__include(List_adp list) {
|
||||
if (Bry_.Len_eq_0(include)) return list; // include is blank; exit early;
|
||||
int[] include_pages = Int_ary_.Parse_list_or(include, null);
|
||||
if (include_pages == null) return list; // ignore invalid include; DATE:2014-02-22
|
||||
int include_pages_len = include_pages.length;
|
||||
for (int i = 0; i < include_pages_len; i++)
|
||||
list.Add(Int_obj_val.new_(include_pages[i]));
|
||||
return list;
|
||||
}
|
||||
private List_adp Get_ttls_from_xnde_args__rng(List_adp list) {
|
||||
if (Bry_.Len_eq_0(bgn_page_bry) && Bry_.Len_eq_0(end_page_bry)) return list; // from and to are blank; exit early
|
||||
bgn_page_int = 0; // NOTE: default to 0 (1st page)
|
||||
if (Bry_.Len_gt_0(bgn_page_bry)) {
|
||||
num_parser.Parse(bgn_page_bry);
|
||||
if (num_parser.Has_err()) {
|
||||
Fail_args("pages node does not have a valid 'from': from={0}", String_.new_u8(bgn_page_bry));
|
||||
return null;
|
||||
}
|
||||
else
|
||||
bgn_page_int = num_parser.Rv_as_int();
|
||||
}
|
||||
end_page_int = 0;
|
||||
if (Bry_.Len_eq_0(end_page_bry))
|
||||
end_page_int = Get_max_page_idx(wiki, index_ttl);
|
||||
else {
|
||||
num_parser.Parse(end_page_bry);
|
||||
if (num_parser.Has_err()) {
|
||||
Fail_args("pages node does not have a valid 'to': to={0}", String_.new_u8(bgn_page_bry));
|
||||
return null;
|
||||
}
|
||||
else
|
||||
end_page_int = num_parser.Rv_as_int();
|
||||
}
|
||||
if (bgn_page_int > end_page_int) {
|
||||
Fail_args("from must be less than to: from={0} to={0}", bgn_page_int, end_page_int);
|
||||
return null;
|
||||
}
|
||||
for (int i = bgn_page_int; i <= end_page_int; i++)
|
||||
list.Add(Int_obj_val.new_(i));
|
||||
return list;
|
||||
}
|
||||
private int Get_max_page_idx(Xowe_wiki wiki, Xoa_ttl index_ttl) {
|
||||
List_adp rslt = List_adp_.new_();
|
||||
Int_obj_ref rslt_count = Int_obj_ref.zero_();
|
||||
wiki.Db_mgr().Load_mgr().Load_ttls_for_all_pages(Cancelable_.Never, rslt, tmp_page, tmp_page, rslt_count, ns_page, index_ttl.Page_db(), Int_.MaxValue, 0, Int_.MaxValue, false, false);
|
||||
int len = rslt_count.Val();
|
||||
int page_leaf_max = 0;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xowd_page_itm page = (Xowd_page_itm)rslt.Get_at(i);
|
||||
Xoa_ttl page_ttl = Xoa_ttl.parse_(wiki, ns_page_id, page.Ttl_page_db()); if (page_ttl == null) continue; // page_ttl is not valid; should never happen;
|
||||
byte[] page_ttl_leaf = page_ttl.Leaf_txt(); if (page_ttl_leaf == null) continue; // page is not leaf; should not happen
|
||||
int page_leaf_val = Bry_.Xto_int_or(page_ttl_leaf, Int_.MinValue); if (page_leaf_val == Int_.MinValue) continue; // leaf is not int; ignore
|
||||
if (page_leaf_val > page_leaf_max) page_leaf_max = page_leaf_val;
|
||||
}
|
||||
return page_leaf_max;
|
||||
} private static Xowd_page_itm tmp_page = new Xowd_page_itm(); // tmp_page passed to Load_ttls_for_all_pages; values are never looked at, so use static instance
|
||||
private List_adp Get_ttls_from_xnde_args__exclude(List_adp list) {
|
||||
if (Bry_.Len_eq_0(exclude)) return list; // exclude is blank; exit early;
|
||||
int[] exclude_pages = Int_ary_.Parse_list_or(exclude, null);
|
||||
if (exclude_pages == null) return list; // ignore invalid exclude; DATE:2014-02-22
|
||||
Hash_adp exclude_pages_hash = Hash_adp_.new_();
|
||||
int exclude_pages_len = exclude_pages.length;
|
||||
for (int i = 0; i < exclude_pages_len; i++) {
|
||||
Int_obj_val exclude_page = Int_obj_val.new_(exclude_pages[i]);
|
||||
if (!exclude_pages_hash.Has(exclude_page))
|
||||
exclude_pages_hash.Add(exclude_page, exclude_page);
|
||||
}
|
||||
List_adp new_list = List_adp_.new_();
|
||||
int list_len = list.Count();
|
||||
for (int i = 0; i < list_len; i++) {
|
||||
Int_obj_val page = (Int_obj_val)list.Get_at(i);
|
||||
if (exclude_pages_hash.Has(page)) continue;
|
||||
new_list.Add(page);
|
||||
}
|
||||
return new_list;
|
||||
}
|
||||
private Xoa_ttl[] Get_ttls_from_xnde_args__ttls(List_adp list) {
|
||||
int list_len = list.Count(); if (list_len == 0) return Ttls_null;
|
||||
Xoa_ttl[] rv = new Xoa_ttl[(list_len / step_int) + ((list_len % step_int == 0) ? 0 : 1)];
|
||||
int rv_idx = 0;
|
||||
Bry_bfr ttl_bfr = app.Utl__bfr_mkr().Get_b512();
|
||||
for (int i = 0; i < list_len; i += step_int) {
|
||||
Int_obj_val page = (Int_obj_val)list.Get_at(i);
|
||||
ttl_bfr.Add(ns_page.Name_db_w_colon()) // EX: 'Page:'
|
||||
.Add(index_ttl_bry) // EX: 'File.djvu'
|
||||
.Add_byte(Byte_ascii.Slash) // EX: '/'
|
||||
.Add_int_variable(page.Val()); // EX: '123'
|
||||
rv[rv_idx++] = Xoa_ttl.parse_(wiki, ttl_bfr.Xto_bry_and_clear());
|
||||
}
|
||||
ttl_bfr.Mkr_rls();
|
||||
return rv;
|
||||
}
|
||||
private boolean Chk_step() {
|
||||
if (step_bry == null) {
|
||||
step_int = 1;
|
||||
return true;
|
||||
}
|
||||
step_int = Bry_.Xto_int_or(step_bry, Int_.MinValue);
|
||||
if (step_int < 1 || step_int > 1000) {
|
||||
Fail_args("pages node does not have a valid 'step': step={0}", String_.new_u8(step_bry));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private byte[] Bld_wikitext_from_ttls(Bry_bfr full_bfr, Hash_adp_bry lst_page_regy, Xoa_ttl[] ary) {
|
||||
int ary_len = ary.length;
|
||||
Xoa_ttl bgn_page_ttl = bgn_page_bry == null ? null : ary[0];
|
||||
Xoa_ttl end_page_ttl = end_page_bry == null ? null : ary[ary_len - 1];
|
||||
|
||||
Bry_bfr page_bfr = app.Utl__bfr_mkr().Get_m001();
|
||||
ctx.Tmpl_output_(page_bfr);
|
||||
Lst_pfunc_wkr lst_pfunc_wkr = new Lst_pfunc_wkr();
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
Xoa_ttl ttl = ary[i];
|
||||
byte[] ttl_page_db = ttl.Page_db();
|
||||
if (lst_page_regy.Get_by_bry(ttl_page_db) == null) // check if page was already added; avoids recursive <page> calls which will overflow stack; DATE:2014-01-01
|
||||
lst_page_regy.Add(ttl_page_db, ttl_page_db);
|
||||
else
|
||||
continue;
|
||||
byte[] cur_sect_bgn = Lst_pfunc_wkr.Null_arg, cur_sect_end = Lst_pfunc_wkr.Null_arg;
|
||||
if (ttl.Eq_page_db(bgn_page_ttl)) {
|
||||
if (bgn_sect_bry != null)
|
||||
cur_sect_bgn = bgn_sect_bry;
|
||||
else if (onlysection != null) {
|
||||
cur_sect_bgn = onlysection;
|
||||
cur_sect_end = onlysection;
|
||||
}
|
||||
}
|
||||
else if (ttl.Eq_page_db(end_page_ttl)) {
|
||||
if (end_sect_bry != null)
|
||||
cur_sect_end = end_sect_bry;
|
||||
}
|
||||
Xopg_tmpl_prepend_mgr prepend_mgr = ctx.Cur_page().Tmpl_prepend_mgr().Bgn(full_bfr);
|
||||
lst_pfunc_wkr.Init_include(ttl.Full_db(), cur_sect_bgn, cur_sect_end).Exec(page_bfr, ctx);
|
||||
prepend_mgr.End(ctx, full_bfr, page_bfr.Bfr(), page_bfr.Len(), Bool_.Y);
|
||||
full_bfr.Add_bfr_and_clear(page_bfr);
|
||||
full_bfr.Add(gplx.html.Html_entity_.Space_bry); // $out.= " "; REF.MW:ProofreadPageRenderer.pn
|
||||
}
|
||||
page_bfr.Mkr_rls();
|
||||
ctx.Tmpl_output_(null);
|
||||
return full_bfr.Xto_bry_and_clear();
|
||||
}
|
||||
private Xop_root_tkn Bld_root_nde(Bry_bfr page_bfr, Hash_adp_bry lst_page_regy, byte[] wikitext) {
|
||||
Xop_ctx tmp_ctx = Xop_ctx.new_sub_page_(wiki, ctx, lst_page_regy);
|
||||
tmp_ctx.Cur_page().Ttl_(ctx.Cur_page().Ttl()); // NOTE: must set tmp_ctx.Ttl to ctx.Ttl; EX: Flatland and First World; DATE:2013-04-29
|
||||
tmp_ctx.Lnki().File_wkr_(null); // NOTE: set file_wkr to null, else items will be double-counted
|
||||
tmp_ctx.Parse_tid_(Xop_parser_.Parse_tid_tmpl);
|
||||
Xop_parser tmp_parser = new Xop_parser(wiki, wiki.Parser().Tmpl_lxr_mgr(), wiki.Parser().Wtxt_lxr_mgr());
|
||||
Xop_root_tkn rv = tmp_ctx.Tkn_mkr().Root(wikitext);
|
||||
tmp_parser.Parse_text_to_wdom(rv, tmp_ctx, tmp_ctx.Tkn_mkr(), wikitext, Xop_parser_.Doc_bgn_bos);
|
||||
return rv;
|
||||
}
|
||||
private static Hash_adp_bry xtn_atrs = Hash_adp_bry.ci_ascii_() // NOTE: these do not seem to be i18n'd; no ProofreadPage.magic.php; ProofreadPage.i18n.php only has messages; ProofreadPage.body.php refers to names literally
|
||||
.Add_str_obj("index" , Byte_obj_val.new_(Pp_pages_nde.Xatr_index_ttl))
|
||||
.Add_str_obj("from" , Byte_obj_val.new_(Pp_pages_nde.Xatr_bgn_page))
|
||||
.Add_str_obj("to" , Byte_obj_val.new_(Pp_pages_nde.Xatr_end_page))
|
||||
.Add_str_obj("fromsection" , Byte_obj_val.new_(Pp_pages_nde.Xatr_bgn_sect))
|
||||
.Add_str_obj("tosection" , Byte_obj_val.new_(Pp_pages_nde.Xatr_end_sect))
|
||||
.Add_str_obj("include" , Byte_obj_val.new_(Pp_pages_nde.Xatr_include))
|
||||
.Add_str_obj("exclude" , Byte_obj_val.new_(Pp_pages_nde.Xatr_exclude))
|
||||
.Add_str_obj("onlysection" , Byte_obj_val.new_(Pp_pages_nde.Xatr_onlysection))
|
||||
.Add_str_obj("step" , Byte_obj_val.new_(Pp_pages_nde.Xatr_step))
|
||||
.Add_str_obj("header" , Byte_obj_val.new_(Pp_pages_nde.Xatr_header))
|
||||
.Add_str_obj("current" , Byte_obj_val.new_(Pp_pages_nde.Xatr_toc_cur))
|
||||
.Add_str_obj("prev" , Byte_obj_val.new_(Pp_pages_nde.Xatr_toc_prv))
|
||||
.Add_str_obj("next" , Byte_obj_val.new_(Pp_pages_nde.Xatr_toc_nxt))
|
||||
;
|
||||
public static final byte
|
||||
Xatr_index_ttl = 0
|
||||
, Xatr_bgn_page = 1
|
||||
, Xatr_end_page = 2
|
||||
, Xatr_bgn_sect = 3
|
||||
, Xatr_end_sect = 4
|
||||
, Xatr_include = 5
|
||||
, Xatr_exclude = 6
|
||||
, Xatr_onlysection = 7
|
||||
, Xatr_step = 8
|
||||
, Xatr_header = 9
|
||||
, Xatr_toc_cur = 10
|
||||
, Xatr_toc_prv = 11
|
||||
, Xatr_toc_nxt = 12
|
||||
;
|
||||
public static final Xoa_ttl[] Ttls_null = null;
|
||||
private static final Number_parser num_parser = new Number_parser().Ignore_space_at_end_y_(); // ignore space at end; PAGE:en.s:1911_Encyclop<6F>dia_Britannica/Boissier,_Marie_Louis_Antoine_Gaston DATE:2015-04-29
|
||||
private String Fail_msg_suffix() {
|
||||
String excerpt = Bry_fmtr.Escape_tilde(String_.new_u8(Bry_.Mid_by_len_safe(src, xnde_tkn.Src_bgn(), 32)));
|
||||
return String_.Format(" ttl={0} src={1}", String_.new_u8(cur_page_ttl.Full_db()), excerpt);
|
||||
}
|
||||
private String Fail_msg_basic(String msg) {return msg + ";" + Fail_msg_suffix();}
|
||||
private String Fail_msg_custom(String fmt, Object... args) {return String_.Format(fmt, args) + Fail_msg_suffix();}
|
||||
private boolean Fail_msg(String msg) {
|
||||
xtn_literal = true;
|
||||
usr_dlg.Warn_many("", "", String_.Replace(Fail_msg_basic(msg), "\n", ""));
|
||||
return false;
|
||||
}
|
||||
private boolean Fail_args(String fmt, Object... args) {
|
||||
xtn_literal = true;
|
||||
usr_dlg.Warn_many("", "", String_.Replace(Fail_msg_custom(fmt, args), "\n", ""));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/*
|
||||
NOTE:page_regy
|
||||
. original implmentation was following
|
||||
in Xop_ctx
|
||||
public Hash_adp_bry Lst_page_regy() {if (lst_page_regy == null) lst_page_regy = Hash_adp_bry.cs_(); return lst_page_regy;}
|
||||
in Pp_pages_nde
|
||||
Hash_adp_bry lst_page_regy = ctx.Lst_page_regy();
|
||||
. current implementation is following
|
||||
in Xop_ctx
|
||||
public Hash_adp_bry Lst_page_regy() {return lst_page_regy;}
|
||||
in Pp_pages_nde
|
||||
Hash_adp_bry lst_page_regy = ctx.Lst_page_regy();
|
||||
if (lst_page_regy == null) lst_page_regy = Hash_adp_bry.cs_();
|
||||
. note that this only skips transcluded <pages> within a given <pages> call, not across the entire page
|
||||
EX: Page:A/1 has the following text
|
||||
<pages index="A" from=1 to=3 />
|
||||
<pages index="B" from=1 to=1 />
|
||||
text
|
||||
<pages index="B" from=1 to=1 />
|
||||
. original implementation would correctly include <pages index="A" from=1 to=3 /> only once, but would also include <pages index="B" from=1 to=1 /> once
|
||||
. current implmentation would include <pages index="B" from=1 to=1 /> twice
|
||||
. also, side-effect of only having Lst_page_regy only be non-null on sub_ctx, which means nothing needs to be cleared on main_ctx
|
||||
*/
|
||||
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
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.xtns.proofreadPage; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import org.junit.*;
|
||||
public class Pp_pages_nde_basic_tst {
|
||||
private Xop_fxt fxt = new Xop_fxt();
|
||||
@Before public void Init() {
|
||||
Io_mgr.I.InitEngine_mem();
|
||||
fxt.Wiki().Xtn_mgr().Xtn_proofread().Enabled_y_();
|
||||
fxt.Wiki().Db_mgr().Load_mgr().Clear(); // must clear; otherwise fails b/c files get deleted, but wiki.data_mgr caches the Xowd_regy_mgr (the .reg file) in memory;
|
||||
fxt.Wiki().Ns_mgr().Add_new(Xowc_xtn_pages.Ns_page_id_default, "Page").Add_new(Xowc_xtn_pages.Ns_index_id_default, "Index").Init();
|
||||
}
|
||||
@After public void term() {
|
||||
fxt.Wiki().Cache_mgr().Free_mem_all();
|
||||
}
|
||||
@Test public void Basic() {
|
||||
fxt.Init_page_create("Page:A/1", "abc");
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\"A\" from=1 to=1 />", String_.Concat_lines_nl
|
||||
( "<p>abc "
|
||||
, "</p>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Multiple() {
|
||||
fxt.Init_page_create("Page:A/1", "a");
|
||||
fxt.Init_page_create("Page:A/2", "b");
|
||||
fxt.Init_page_create("Page:A/3", "c");
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\"A\" from=1 to=3 />", String_.Concat_lines_nl
|
||||
( "<p>a b c "
|
||||
, "</p>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Section() {
|
||||
fxt.Init_page_create("Page:A/1", "a<section begin=\"sect_0\"/>b");
|
||||
fxt.Init_page_create("Page:A/2", "cd");
|
||||
fxt.Init_page_create("Page:A/3", "e<section end=\"sect_2\"/>f");
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\"A\" from=1 to=3 fromsection='sect_0' tosection='sect_2' />", String_.Concat_lines_nl
|
||||
( "<p>b cd e "
|
||||
, "</p>"
|
||||
));
|
||||
}
|
||||
@Test public void Section__onlyinclude() {
|
||||
fxt.Init_page_create("Page:A/1", "a<section begin='sect_0'/>b<section end='sect_0'/>c");
|
||||
fxt.Test_parse_page_wiki_str("<pages index='A' from=1 to=1 onlysection='sect_0' />", String_.Concat_lines_nl
|
||||
( "<p>b "
|
||||
, "</p>"
|
||||
));
|
||||
}
|
||||
@Test public void Section__onlyinclude_ignores_from_to() {
|
||||
fxt.Init_page_create("Page:A/1", "<section begin='sect_a'/>a<section end='sect_a'/><section begin='sect_b'/>b<section end='sect_b'/><section begin='sect_c'/>c<section end='sect_c'/>");
|
||||
fxt.Test_parse_page_wiki_str("<pages from=1 index='A' onlysection='sect_b' fromsection='sect_a' tosection='sect_c' />", String_.Concat_lines_nl
|
||||
( "<p>b "
|
||||
, "</p>"
|
||||
));
|
||||
}
|
||||
@Test public void Noinclude() {
|
||||
fxt.Init_page_create("Page:A/1", "<noinclude>a</noinclude>{|\n|b\n|}");
|
||||
fxt.Init_page_create("Page:A/2", "<noinclude>c</noinclude>''d''");
|
||||
fxt.Init_page_create("Page:A/3", "<noinclude>e</noinclude>f");
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\"A\" from=1 to=3 />", String_.Concat_lines_nl_skip_last
|
||||
( "<table>"
|
||||
, " <tr>"
|
||||
, " <td>b"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
, " <i>d</i> f "
|
||||
));
|
||||
}
|
||||
@Test public void Err_page_ns_doesnt_exist() {
|
||||
fxt.Wiki().Ns_mgr().Init().Clear(); // call .Clear() to remove ns for Page / Index
|
||||
fxt.Wiki().Cfg_parser().Xtns().Itm_pages().Reset(); // must reset to clear cached valid ns_page from previous tests
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\"A\" from=1 to=3 />", "<pages index="A" from=1 to=3 />");
|
||||
fxt.Wiki().Cfg_parser().Xtns().Itm_pages().Reset(); // must reset to clear cached invalid ns_page for next tests
|
||||
}
|
||||
@Test public void Subpage() { // PURPOSE: [[/Page]] should be relative to current page; EX: Flatland and [[/First World]]; DATE:2013-04-29
|
||||
fxt.Init_page_create("Page:A/1", "[[/Sub1|Sub 1]]");
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\"A\" from=1 to=1 />", String_.Concat_lines_nl
|
||||
( "<p><a href=\"/wiki/Test_page/Sub1\">Sub 1</a> " // NOTE: / is relative to Page_name (in this case Test_page)
|
||||
, "</p>"
|
||||
));
|
||||
}
|
||||
@Test public void Disable() { // PURPOSE: simulate disabled wiki; PAGE:en.w:Wikipedia:Requests_for_adminship/Phantomsteve DATE:2014-09-08
|
||||
fxt.Wiki().Xtn_mgr().Xtn_proofread().Enabled_n_();
|
||||
fxt.Init_page_create("Page:A/1", "A");
|
||||
fxt.Test_parse_page_wiki_str
|
||||
( "<pages index=\"A\" from=1 to=1>a</pages>"
|
||||
, "<pages index="A" from=1 to=1>a"
|
||||
);
|
||||
}
|
||||
@Test public void Page_has_nl() { // PURPOSE: parse "to" page, even if it has \n at end; PAGE:en.s:1911_Encyclop<6F>dia_Britannica/Boissier,_Marie_Louis_Antoine_Gaston DATE:2015-04-29
|
||||
fxt.Init_page_create("Page:A/1", "abc");
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\"A\" from=1 to='1\n' />", String_.Concat_lines_nl
|
||||
( "<p>abc "
|
||||
, "</p>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Indicator() { // PURPOSE: handle indicators; PAGE:en.s:The_Parochial_System_(Wilberforce,_1838); DATE:2015-04-29
|
||||
fxt.Init_page_create("Page:A/1", "<indicator name='b'>b</indicator>page_1");
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "<indicator name='a'>a</indicator>"
|
||||
, "<pages index=\"A\" from=1 to='1\' />"
|
||||
), String_.Concat_lines_nl
|
||||
( "<p>page_1 " // make sure Page:A/1 is transcribed
|
||||
, "</p>"
|
||||
, ""
|
||||
));
|
||||
Tfds.Eq(1, fxt.Page().Html_data().Indicators().Count()); // only 1 indicator, not 2
|
||||
Tfds.Eq(true, fxt.Page().Html_data().Indicators().Has("a")); // indicator should be from wikitext, not <page>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
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.xtns.proofreadPage; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import org.junit.*;
|
||||
public class Pp_pages_nde_hdr_tst {
|
||||
private Xop_fxt fxt = new Xop_fxt();
|
||||
@Before public void Init() {
|
||||
Io_mgr.I.InitEngine_mem();
|
||||
fxt.Wiki().Xtn_mgr().Xtn_proofread().Enabled_y_();
|
||||
fxt.Wiki().Cache_mgr().Page_cache().Free_mem_all();
|
||||
fxt.Wiki().Db_mgr().Load_mgr().Clear(); // must clear; otherwise fails b/c files get deleted, but wiki.data_mgr caches the Xowd_regy_mgr (the .reg file) in memory;
|
||||
fxt.Wiki().Ns_mgr().Add_new(Xowc_xtn_pages.Ns_page_id_default, "Page").Add_new(Xowc_xtn_pages.Ns_index_id_default, "Index").Init();
|
||||
fxt.Init_page_create("MediaWiki:Proofreadpage_header_template", String_.Concat
|
||||
( "{{#if:{{{value|}}}|value={{{value}}};|value=nil;}}"
|
||||
, "{{#if:{{{current|}}}|current={{{current}}};|}}"
|
||||
, "{{#if:{{{prev|}}}|prev={{{prev}}};|}}"
|
||||
, "{{#if:{{{next|}}}|next={{{next}}};|}}"
|
||||
, "{{#if:{{{from|}}}|from={{{from}}};|}}"
|
||||
, "{{#if:{{{to|}}}|to={{{to}}};|}}"
|
||||
, "{{#if:{{{custom|}}}|custom={{{custom}}};|}}"
|
||||
, "\n\n"
|
||||
));
|
||||
}
|
||||
@Test public void Default_to_toc() { // PURPOSE: default header to "toc" if no "from", "to", "include"; DATE:2014-01-27
|
||||
fxt.Init_page_create("Index:A", "");
|
||||
// only index supplied; add header='toc'
|
||||
fxt.Test_parse_page_wiki_str("<pages index='A'/>", String_.Concat_lines_nl
|
||||
( "<p>value=toc;"
|
||||
, "</p>"
|
||||
, ""
|
||||
, "<p><br/>"
|
||||
, "</p>"
|
||||
));
|
||||
|
||||
fxt.Init_page_create("Page:A/1", "A/1");
|
||||
// from specified; don't add toc
|
||||
fxt.Test_parse_page_wiki_str("<pages index='A' from='1'/>", String_.Concat_lines_nl
|
||||
( "<p>A/1 "
|
||||
, "</p>"
|
||||
));
|
||||
}
|
||||
@Test public void From_set() { // PURPOSE: "from" should (a) appear in toc; and (b) select pages; DATE:2014-01-27
|
||||
fxt.Init_page_create("Index:A" , "idx");
|
||||
fxt.Init_page_create("Page:A/1", "a1");
|
||||
fxt.Init_page_create("Page:A/2", "a2");
|
||||
fxt.Init_page_create("Page:A/3", "a3");
|
||||
fxt.Test_parse_page_wiki_str("<pages index='A' from=2 to=2 header='toc'/>", String_.Concat_lines_nl
|
||||
( "<p>value=toc;from=2;to=2;"
|
||||
, "</p>"
|
||||
, ""
|
||||
, "<p>a2 "
|
||||
, "</p>"
|
||||
));
|
||||
}
|
||||
@Test public void Mainspace_toc() { // PURPOSE: Mainspace links should be sent to toc; DATE:2014-01-27
|
||||
fxt.Init_page_create("Index:A" , String_.Concat_lines_nl_skip_last
|
||||
( "[[Page/1]]"
|
||||
, "[[Page/2]]"
|
||||
, "[[Page/3]]"
|
||||
));
|
||||
// next only
|
||||
fxt.Page_ttl_("Page/1");
|
||||
fxt.Test_parse_page_wiki_str("<pages index='A' />", String_.Concat_lines_nl
|
||||
( "<p>value=toc;current=<b>Page/1</b>;next=<a href=\"/wiki/Page/2\">Page/2</a>;"
|
||||
, "</p>"
|
||||
, ""
|
||||
, "<p><br/>"
|
||||
, "</p>"
|
||||
));
|
||||
|
||||
// next and prev
|
||||
fxt.Page_ttl_("Page/2");
|
||||
fxt.Test_parse_page_wiki_str("<pages index='A' />", String_.Concat_lines_nl
|
||||
( "<p>value=toc;current=<b>Page/2</b>;prev=<a href=\"/wiki/Page/1\">Page/1</a>;next=<a href=\"/wiki/Page/3\">Page/3</a>;"
|
||||
, "</p>"
|
||||
, ""
|
||||
, "<p><br/>"
|
||||
, "</p>"
|
||||
));
|
||||
|
||||
// prev only
|
||||
fxt.Page_ttl_("Page/3");
|
||||
fxt.Test_parse_page_wiki_str("<pages index='A' />", String_.Concat_lines_nl
|
||||
( "<p>value=toc;current=<b>Page/3</b>;prev=<a href=\"/wiki/Page/2\">Page/2</a>;"
|
||||
, "</p>"
|
||||
, ""
|
||||
, "<p><br/>"
|
||||
, "</p>"
|
||||
));
|
||||
|
||||
// override current only;
|
||||
fxt.Page_ttl_("Page/2");
|
||||
fxt.Test_parse_page_wiki_str("<pages index='A' current='custom_cur'/>", String_.Concat_lines_nl
|
||||
( "<p>value=toc;current=custom_cur;prev=<a href=\"/wiki/Page/1\">Page/1</a>;next=<a href=\"/wiki/Page/3\">Page/3</a>;"
|
||||
, "</p>"
|
||||
, ""
|
||||
, "<p><br/>"
|
||||
, "</p>"
|
||||
));
|
||||
|
||||
// override current, prev, next
|
||||
fxt.Test_parse_page_wiki_str("<pages index='A' current='custom_cur' prev='custom_prv' next='custom_nxt'/>", String_.Concat_lines_nl
|
||||
( "<p>value=toc;current=custom_cur;prev=custom_prv;next=custom_nxt;"
|
||||
, "</p>"
|
||||
, ""
|
||||
, "<p><br/>"
|
||||
, "</p>"
|
||||
));
|
||||
}
|
||||
@Test public void Mainspace_caption() { // PURPOSE: extract caption; DATE:2014-01-27
|
||||
fxt.Init_page_create("Index:A" , String_.Concat_lines_nl_skip_last
|
||||
( "[[Page/1|Caption_1]]"
|
||||
, "[[Page/2]]"
|
||||
, "[[Page/3]]"
|
||||
));
|
||||
|
||||
fxt.Page_ttl_("Page/2");
|
||||
fxt.Test_parse_page_wiki_str("<pages index='A' />", String_.Concat_lines_nl
|
||||
( "<p>value=toc;current=<b>Page/2</b>;prev=<a href=\"/wiki/Page/1\">Caption_1</a>;next=<a href=\"/wiki/Page/3\">Page/3</a>;"
|
||||
, "</p>"
|
||||
, ""
|
||||
, "<p><br/>"
|
||||
, "</p>"
|
||||
));
|
||||
}
|
||||
@Test public void Xwiki() { // PURPOSE: Mainspace links should be sent to toc; DATE:2014-01-27
|
||||
fxt.Init_xwiki_add_wiki_and_user_("commons", "commons.wikimedia.org");
|
||||
fxt.Init_page_create("Index:A" , String_.Concat_lines_nl_skip_last
|
||||
( "[[Page/1]]"
|
||||
, "[[:commons:File:A.png]]"
|
||||
));
|
||||
// next only
|
||||
fxt.Page_ttl_("Page/1");
|
||||
fxt.Test_parse_page_wiki_str("<pages index='A' />", String_.Concat_lines_nl
|
||||
( "<p>value=toc;current=<b>Page/1</b>;next=<a href=\"/site/commons.wikimedia.org/wiki/File:A.png\">File:A.png</a>;"
|
||||
, "</p>"
|
||||
, ""
|
||||
, "<p><br/>"
|
||||
, "</p>"
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,236 @@
|
||||
/*
|
||||
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.xtns.proofreadPage; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import org.junit.*;
|
||||
public class Pp_pages_nde_index_tst {
|
||||
private Xop_fxt fxt = new Xop_fxt();
|
||||
@Before public void Init() {
|
||||
Io_mgr.I.InitEngine_mem();
|
||||
fxt.Wiki().Xtn_mgr().Xtn_proofread().Enabled_y_();
|
||||
fxt.Wiki().Db_mgr().Load_mgr().Clear(); // must clear; otherwise fails b/c files get deleted, but wiki.data_mgr caches the Xowd_regy_mgr (the .reg file) in memory;
|
||||
fxt.Wiki().Ns_mgr().Add_new(Xowc_xtn_pages.Ns_page_id_default, "Page").Add_new(Xowc_xtn_pages.Ns_index_id_default, "Index").Init();
|
||||
}
|
||||
@After public void term() {
|
||||
fxt.Wiki().Cache_mgr().Free_mem_all();
|
||||
}
|
||||
@Test public void Repeated() { // PURPOSE: repeated pages should still show (and not be excluded by recursive logic); DATE:2014-01-01
|
||||
fxt.Init_page_create("Page:A/1", "<pages index=\"A\" from=1 to=1 />abc"); // NOTE: recursive call to self
|
||||
fxt.Init_page_create("Page:D/1", "d");
|
||||
String main_txt = String_.Concat_lines_nl
|
||||
( "<pages index=\"A\" from=1 to=1 />"
|
||||
, "text_0"
|
||||
, "<pages index=\"D\" from=1 to=1/>"
|
||||
, "text_1"
|
||||
, "<pages index=\"D\" from=1 to=1/>"
|
||||
);
|
||||
fxt.Test_parse_page_wiki_str(main_txt, String_.Concat_lines_nl
|
||||
( "<p>abc "
|
||||
, "</p>"
|
||||
, "text_0"
|
||||
, "<p>d "
|
||||
, "</p>"
|
||||
, "text_1"
|
||||
, "<p>d "
|
||||
, "</p>"
|
||||
));
|
||||
}
|
||||
@Test public void Index() {
|
||||
fxt.Init_page_create("Index:A", String_.Concat_lines_nl
|
||||
( "[[ignore]]"
|
||||
, "[[Page:A b/1]]"
|
||||
, "[[Page:A b/2]]"
|
||||
, "[[Page:A b/3]]"
|
||||
, "[[Page:A b/4]]"
|
||||
, "[[Page:A b/5]]"
|
||||
));
|
||||
fxt.Init_page_create("Page:A_b/1", "A_b/1\n");
|
||||
fxt.Init_page_create("Page:A_b/2", "A_b/2\n");
|
||||
fxt.Init_page_create("Page:A_b/3", "A_b/3\n");
|
||||
fxt.Init_page_create("Page:A_b/4", "A_b/4\n");
|
||||
fxt.Init_page_create("Page:A_b/5", "A_b/5\n");
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\"A\" from='A b/2' to='A_b/4' />", String_.Concat_lines_nl
|
||||
( "<p>A_b/2"
|
||||
, " A_b/3"
|
||||
, " A_b/4"
|
||||
, " "
|
||||
, "</p>"
|
||||
));
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\"A\" from='A b/2' />", String_.Concat_lines_nl // to missing
|
||||
( "<p>A_b/2"
|
||||
, " A_b/3"
|
||||
, " A_b/4"
|
||||
, " A_b/5"
|
||||
, " "
|
||||
, "</p>"
|
||||
));
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\"A\" to='A b/4' />", String_.Concat_lines_nl // from missing
|
||||
( "<p>A_b/1"
|
||||
, " A_b/2"
|
||||
, " A_b/3"
|
||||
, " A_b/4"
|
||||
, " "
|
||||
, "</p>"
|
||||
));
|
||||
}
|
||||
@Test public void Index_amp_encoded() { // handle ampersand encoded strings; EX: en.s:Team_Work_Wins!; DATE:2014-01-19
|
||||
fxt.Init_page_create("Index:\"A\"", "[[Page:\"A\"]]");
|
||||
fxt.Init_page_create("Page:\"A\"", "a");
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\""A"\" from='"A"' />", "<p>a \n</p>");
|
||||
}
|
||||
@Test public void Index_amp_encoded_num() {// handle num-encoded vals; EX: pl.s:Zarządzenie_Nr_11_Ministra_Finansów_z_dnia_21_lipca_2008_r._w_sprawie_ustanowienia_„Dnia_Skarbowości”; DATE:2014-05-07
|
||||
fxt.Init_page_create("Index:\"A\"", "[[Page:\"A\"]]");
|
||||
fxt.Init_page_create("Page:\"A\"", "a");
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\""A"\" from='"A"' />", "<p>a \n</p>");
|
||||
}
|
||||
// @Test public void Index_all() { // PURPOSE: if from / to not specified, add all titles
|
||||
// fxt.Init_page_create("Index:A", String_.Concat_lines_nl
|
||||
// ( "[[Page:A b/1]]"
|
||||
// , "[[Page:A b/2]]"
|
||||
// ));
|
||||
// fxt.Init_page_create("Page:A_b/1", "A_b/1\n");
|
||||
// fxt.Init_page_create("Page:A_b/2", "A_b/2\n");
|
||||
// String main_txt = String_.Concat_lines_nl
|
||||
// ( "<pages index=\"A\" />"
|
||||
// );
|
||||
// fxt.Test_parse_page_wiki_str(main_txt, String_.Concat_lines_nl
|
||||
// ( "<p>A_b/1"
|
||||
// , "A_b/2"
|
||||
// , "</p>"
|
||||
// ));
|
||||
// }
|
||||
@Test public void Section_failed_when_xnde() { // PURPOSE: section failed to be retrieved if preceding xnde; DATE:2014-01-15
|
||||
fxt.Init_page_create("Page:A/1", "<b>a</b><section begin=\"sect_0\"/>b<section end=\"sect_0\"/>");
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\"A\" from=1 to=1 fromsection='sect_0' tosection='sect_0' />", String_.Concat_lines_nl
|
||||
( "<p>b "
|
||||
, "</p>"
|
||||
));
|
||||
}
|
||||
@Test public void Index_to_missing() { // PURPOSE: if no to, get rest of pages
|
||||
fxt.Init_page_create("Index:A", String_.Concat_lines_nl
|
||||
( "[[Page:A b/1]]"
|
||||
, "[[Page:A b/2]]"
|
||||
));
|
||||
fxt.Init_page_create("Page:A_b/1", "A_b/1\n");
|
||||
fxt.Init_page_create("Page:A_b/2", "A_b/2\n");
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\"A\" from='A b/1' />", String_.Concat_lines_nl
|
||||
( "<p>A_b/1"
|
||||
, " A_b/2"
|
||||
, " "
|
||||
, "</p>"
|
||||
));
|
||||
}
|
||||
@Test public void Set_from_to_if_missing() { // PURPOSE: if no from / to, set from / to variables; note that earlier version of XO was correctly transcluding content, but just not updating from / to variable; fr.s:Constitution_de_la_France_de_1958_(version_initiale); DATE:2014-05-21
|
||||
fxt.Init_page_create("MediaWiki:Proofreadpage_header_template", "{{{from}}}-{{{to}}}\n");
|
||||
fxt.Init_page_create("Index:A", String_.Concat_lines_nl
|
||||
( "[[Page:A/1]]"
|
||||
, "[[Page:A/2]]"
|
||||
));
|
||||
fxt.Init_page_create("Page:A/1", "A/1\n");
|
||||
fxt.Init_page_create("Page:A/2", "A/2\n");
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\"A\" from='A/1' header='y' />", String_.Concat_lines_nl
|
||||
( "<p>0-1"
|
||||
, "A/1"
|
||||
, " A/2"
|
||||
, " "
|
||||
, "</p>"
|
||||
));
|
||||
}
|
||||
@Test public void Various() {
|
||||
fxt.Init_page_create("Page:A/1", "a");
|
||||
fxt.Init_page_create("Page:A/2", "b");
|
||||
fxt.Init_page_create("Page:A/3", "c");
|
||||
fxt.Init_page_create("Page:A/4", "d");
|
||||
fxt.Init_page_create("Page:A/5", "e");
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\"A\" include='1-2,4' />", "<p>a b d \n</p>\n"); // include
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\"A\" from=1 to=5 exclude='3' />", "<p>a b d e \n</p>\n"); // exclude
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\"A\" include=5 from=2 to=4 />", "<p>b c d e \n</p>\n"); // include should be sorted
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\"A\" from=1 to=5 step=2 />", "<p>a c e \n</p>\n"); // step
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\"A\" from=1 to=5 step=4 />", "<p>a e \n</p>\n"); // step
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\"A\" from=1 to=5 step=10 />", "<p>a \n</p>\n"); // step
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\"A\" from=3 to=3 />", "<p>c \n</p>\n"); // from = to
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\"A\" to=3/>", "<p> a b c \n</p>\n"); // from omitted
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\"A\" from=3/>", "<p>c d e \n</p>\n"); // to omitted
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\"A\" from='' to=3 />", "<p> a b c \n</p>\n"); // from is blank
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\"A\" from=3 to=''/>", "<p>c d e \n</p>\n"); // to is blank
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\"A\" from=3 to='4.' />", "<p>c d \n</p>\n"); // allow decimal-like number; PAGE:en.w:Haworth's/Chapter_XIX; DATE:2014-01-19
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\"A\" from=1 to=5 exclude=''3' />", "<p>a b c d e \n</p>\n");// exclude is invalid; EX:fr.s:Sanguis_martyrum/Première_partie/I DATE:2014-01-18
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\"A\" exclude from=1 to=5 />", "<p>a b c d e \n</p>\n"); // exclude empty; ru.s:ПБЭ/Гуттен,_Ульрих_фон DATE:2014-02-22
|
||||
}
|
||||
@Test public void Ref() { // PURPOSE: ref on page should show; DATE:2014-01-18
|
||||
fxt.Init_page_create("Page:A/1", "a<ref>b</ref>c");
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\"A\" from=1 to=1 /><references/>", String_.Concat_lines_nl
|
||||
( "<p>a<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>c "
|
||||
, "</p>"
|
||||
, "<ol class=\"references\">"
|
||||
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">b</span></li>"
|
||||
, "</ol>"
|
||||
));
|
||||
}
|
||||
@Test public void Tblw() { // PURPOSE: if page begins with *, {|, etc, , automatically prepend \n (just like templates); DATE:2014-01-23
|
||||
fxt.Init_page_create("Page:A/1", "a");
|
||||
fxt.Init_page_create("Page:A/2", "* b");
|
||||
fxt.Init_page_create("Page:A/3", "c");
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\"A\" from=1 to=3 />", String_.Concat_lines_nl
|
||||
( "<p>a "
|
||||
, "</p>"
|
||||
, ""
|
||||
, "<ul>"
|
||||
, " <li> b c "
|
||||
, " </li>"
|
||||
, "</ul>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Index_various() {// varying logic depending on whether [[Index:]] has [[Page]] or <pagelist> DATE:2014-01-27
|
||||
fxt.Init_page_create("Page:A/0", "A/0");
|
||||
fxt.Init_page_create("Page:A/1", "A/1");
|
||||
fxt.Init_page_create("Page:A/2", "A/2");
|
||||
fxt.Init_page_create("Index:A", "");
|
||||
|
||||
// [[Index:]] has no [[Page:]] links; interpret to=1 as [[Page:A/1]]
|
||||
fxt.Wiki().Cache_mgr().Free_mem_all();
|
||||
fxt.Init_page_update("Index:A" , String_.Concat_lines_nl
|
||||
( "no links"
|
||||
));
|
||||
fxt.Test_parse_page_wiki_str("<pages index='A' to=1 />", String_.Concat_lines_nl
|
||||
( "<p>A/0 A/1 "
|
||||
, "</p>"
|
||||
));
|
||||
|
||||
// [[Index:]] has [[Page:]] links; interpret to=1 as 1st [[Page:]] in [[Index:]]'s [[Page:]] links
|
||||
fxt.Wiki().Cache_mgr().Free_mem_all();
|
||||
fxt.Init_page_update("Index:A" , String_.Concat_lines_nl
|
||||
( "[[Page:A/0]]"
|
||||
));
|
||||
fxt.Test_parse_page_wiki_str("<pages index='A' to=1 />", String_.Concat_lines_nl
|
||||
( "<p>A/0 "
|
||||
, "</p>"
|
||||
));
|
||||
|
||||
// [[Index:]] has [[Page:]] links but also <pagelist>; interpret to=1 as [[Page:A/1]]
|
||||
fxt.Wiki().Cache_mgr().Free_mem_all();
|
||||
fxt.Init_page_update("Index:A" , String_.Concat_lines_nl
|
||||
( "[[Page:A/0]]"
|
||||
, "<pagelist/>"
|
||||
));
|
||||
fxt.Test_parse_page_wiki_str("<pages index='A' to=1 />", String_.Concat_lines_nl
|
||||
( "<p>A/0 A/1 "
|
||||
, "</p>"
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
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.xtns.proofreadPage; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import org.junit.*;
|
||||
public class Pp_pages_nde_recursion_tst {
|
||||
private Xop_fxt fxt = new Xop_fxt();
|
||||
@Before public void Init() {fxt.Init_xtn_pages();}
|
||||
@After public void term() {
|
||||
fxt.Wiki().Cache_mgr().Free_mem_all();
|
||||
}
|
||||
@Test public void Page() { // PURPOSE: handle recursive calls on page; EX: fr.s:Page:NRF_19.djvu/19; DATE:2014-01-01
|
||||
fxt.Init_page_create("Page:A/1", "<pages index=\"A\" from=1 to=1 />abc"); // NOTE: recursive call to self
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\"A\" from=1 to=1 />", String_.Concat_lines_nl
|
||||
( "<p>abc "
|
||||
, "</p>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Index() { // PURPOSE: handle recursive calls on index; EX: en.s:Poems_of_Italy:_selections_from_the_Odes_of_Giosue_Carducci/Before_the_Old_Castle_of_Verona; DATE:2014-01-19
|
||||
fxt.Init_page_create("Index:A", "<pages index=A/>");
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\"A\" from=1 to=1 />", "<p> \n</p>");
|
||||
}
|
||||
@Test public void MediaWiki_Proofreadpage_header_template() { // PURPOSE: handle recursive calls through Proofreadpage_header_template; EX: fr.s:L<>Enfer_(Barbusse); DATE:2014-05-21
|
||||
fxt.Init_page_create("MediaWiki:Proofreadpage_header_template", "<pages index=\"A\" />"); // NOTE: this is just a simulation of fr.s, which calls Module:Header_template which in turn calls preprocess to results in recursion
|
||||
fxt.Test_parse_page_wiki_str("<pages index=\"A\" />", "<p>\n</p>");
|
||||
}
|
||||
}
|
||||
28
400_xowa/src/gplx/xowa/xtns/proofreadPage/Pp_xtn_mgr.java
Normal file
28
400_xowa/src/gplx/xowa/xtns/proofreadPage/Pp_xtn_mgr.java
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
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.xtns.proofreadPage; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.html.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.xwikis.*;
|
||||
public class Pp_xtn_mgr extends Xox_mgr_base {
|
||||
@Override public boolean Enabled_default() {return false;}
|
||||
@Override public byte[] Xtn_key() {return XTN_KEY;} public static final byte[] XTN_KEY = Bry_.new_a7("ProofreadPages");
|
||||
@Override public Xox_mgr Clone_new() {return new Pp_xtn_mgr();}
|
||||
@Override public void Xtn_init_by_wiki(Xowe_wiki wiki) {
|
||||
if (!this.Enabled_manually())
|
||||
this.Enabled_(wiki.Domain_tid() == Xow_domain_type_.Tid_wikisource); // only enable for wikisource
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user