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:
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
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.pfuncs.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
public class Pfunc_defaultsort extends Pf_func_base {
|
||||
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bb) {}
|
||||
@Override public int Id() {return Xol_kwd_grp_.Id_page_defaultsort;}
|
||||
@Override public Pf_func New(int id, byte[] name) {return new Pfunc_defaultsort().Name_(name);}
|
||||
public static final Pfunc_defaultsort _ = new Pfunc_defaultsort(); Pfunc_defaultsort() {}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
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.pfuncs.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
import gplx.xowa.html.*; import gplx.xowa.langs.cases.*;
|
||||
public class Pfunc_displaytitle extends Pf_func_base {
|
||||
@Override public int Id() {return Xol_kwd_grp_.Id_page_displaytitle;}
|
||||
@Override public Pf_func New(int id, byte[] name) {return new Pfunc_displaytitle().Name_(name);}
|
||||
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) {
|
||||
byte[] val_dat_ary = Eval_argx(ctx, src, caller, self);
|
||||
Xowe_wiki wiki = ctx.Wiki(); Xop_parser parser = wiki.Parser();
|
||||
Xop_ctx display_ttl_ctx = Xop_ctx.new_sub_(wiki);
|
||||
Xop_root_tkn display_ttl_root = parser.Parse_text_to_wdom(display_ttl_ctx, val_dat_ary, false);
|
||||
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
boolean restrict = wiki.Cfg_parser().Display_title_restrict();
|
||||
Xoh_wtr_ctx hctx = restrict ? Xoh_wtr_ctx.Display_title : Xoh_wtr_ctx.Basic; // restrict removes certain HTML (display:none)
|
||||
wiki.Html_mgr().Html_wtr().Write_tkn(tmp_bfr, display_ttl_ctx, hctx, display_ttl_root.Data_mid(), display_ttl_root, 0, display_ttl_root);
|
||||
byte[] val_html = tmp_bfr.Xto_bry_and_clear();
|
||||
if (restrict) { // restrict only allows displayTitles which have text similar to the pageTitle; PAGE:de.b:Kochbuch/_Druckversion; DATE:2014-08-18
|
||||
Xoae_page page = ctx.Cur_page();
|
||||
wiki.Html_mgr().Html_wtr().Write_tkn(tmp_bfr, display_ttl_ctx, Xoh_wtr_ctx.Alt, display_ttl_root.Data_mid(), display_ttl_root, 0, display_ttl_root);
|
||||
byte[] val_html_lc = tmp_bfr.Xto_bry_and_clear();
|
||||
Xol_case_mgr case_mgr = wiki.Lang().Case_mgr();
|
||||
val_html_lc = Standardize_displaytitle_text(case_mgr, val_html_lc);
|
||||
byte[] page_ttl_lc = Standardize_displaytitle_text(case_mgr, page.Ttl().Page_db());
|
||||
if (!Bry_.Eq(val_html_lc, page_ttl_lc))
|
||||
val_html = null;
|
||||
}
|
||||
ctx.Cur_page().Html_data().Display_ttl_(val_html);
|
||||
tmp_bfr.Mkr_rls();
|
||||
}
|
||||
private static byte[] Standardize_displaytitle_text(Xol_case_mgr case_mgr, byte[] val) {
|
||||
byte[] rv = case_mgr.Case_build_lower(val); // lower-case
|
||||
return Bry_.Replace(rv, Byte_ascii.Space, Byte_ascii.Underline); // force underline; PAGE:de.w:Mod_qos DATE:2014-11-06
|
||||
}
|
||||
public static final Pfunc_displaytitle _ = new Pfunc_displaytitle(); Pfunc_displaytitle() {}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
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.pfuncs.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
import org.junit.*;
|
||||
public class Pfunc_displaytitle_tst {
|
||||
@Before public void init() {fxt.Reset();} private Pfunc_displaytitle_fxt fxt = new Pfunc_displaytitle_fxt();
|
||||
@Test public void Basic() {fxt.Init_restrict(Bool_.N).Test("{{DISPLAYTITLE:B A}}" , "B A");}
|
||||
@Test public void Apos_italic() {fxt.Init_restrict(Bool_.N).Test("{{DISPLAYTITLE:''B A''}}" , "<i>B A</i>");}
|
||||
@Test public void Restrict_skip() {fxt.Init_restrict(Bool_.Y).Test("{{DISPLAYTITLE:B A}}" , null);} // PURPOSE: skip if text does not match title; PAGE:de.b:Kochbuch/_Druckversion; DATE:2014-08-18
|
||||
@Test public void Restrict_keep_ci() {fxt.Init_restrict(Bool_.Y).Test("{{DISPLAYTITLE:a B}}" , "a B");} // PURPOSE: keep b/c case-insensitive match; DATE:2014-08-18
|
||||
@Test public void Restrict_keep_underscore() {fxt.Init_restrict(Bool_.Y).Test("{{DISPLAYTITLE:a_b}}" , "a_b");} // PURPOSE: keep b/c underscores should match spaces; PAGE:de.w:Mod_qos DATE:2014-11-06
|
||||
@Test public void Restrict_keep_tags() {fxt.Init_restrict(Bool_.Y).Test("{{DISPLAYTITLE:<b>a</b> <i>B</i>}}" , "<b>a</b> <i>B</i>");}// PURPOSE: keep b/c text match (tags ignored); DATE:2014-08-18
|
||||
@Test public void Strip_display() {
|
||||
String expd_fail = "<span style='/* attempt to bypass $wgRestrictDisplayTitle */'>A b</span>";
|
||||
fxt.Init_restrict(Bool_.Y);
|
||||
fxt.Test("{{DISPLAYTITLE:<span style='display:none;'>A b</span>}}" , expd_fail);
|
||||
fxt.Test("{{DISPLAYTITLE:<span style='user-select:n;'>A b</span>}}" , expd_fail);
|
||||
fxt.Test("{{DISPLAYTITLE:<span style='visibility:n;'>A b</span>}}" , expd_fail);
|
||||
fxt.Test("{{DISPLAYTITLE:<span style=''>display:none</span>}}" , null);
|
||||
}
|
||||
}
|
||||
class Pfunc_displaytitle_fxt {
|
||||
private Xop_fxt fxt = new Xop_fxt();
|
||||
public void Reset() {
|
||||
fxt.Reset();
|
||||
fxt.Page_ttl_("A b");
|
||||
}
|
||||
public Pfunc_displaytitle_fxt Init_restrict(boolean v) {fxt.Wiki().Cfg_parser().Display_title_restrict_(v); return this;}
|
||||
public void Test(String raw, String expd) {
|
||||
fxt.Page().Html_data().Display_ttl_(null); // TEST: always reset; needed for Strip_display which calls multiple times
|
||||
fxt.Test_parse_tmpl_str_test(raw, "{{test}}", "");
|
||||
Tfds.Eq(expd, String_.new_u8(fxt.Page().Html_data().Display_ttl()));
|
||||
}
|
||||
}
|
||||
24
400_xowa/src/gplx/xowa/xtns/pfuncs/pages/Pfunc_misc_tst.java
Normal file
24
400_xowa/src/gplx/xowa/xtns/pfuncs/pages/Pfunc_misc_tst.java
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
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.pfuncs.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
import org.junit.*;
|
||||
public class Pfunc_misc_tst {
|
||||
private Xop_fxt fxt = new Xop_fxt();
|
||||
@Before public void init() {fxt.Reset();}
|
||||
@Test public void CascadingSources() {fxt.Test_parse_page_all_str("{{CASCADINGSOURCES}}", "");} // PURPOSE: noop; DATE:2014-04-09
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
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.pfuncs.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
public class Pfunc_noeditsection extends Pf_func_base {
|
||||
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bb) {}
|
||||
@Override public int Id() {return Xol_kwd_grp_.Id_noeditsection;}
|
||||
@Override public Pf_func New(int id, byte[] name) {return new Pfunc_noeditsection().Name_(name);}
|
||||
public static final Pfunc_noeditsection _ = new Pfunc_noeditsection(); Pfunc_noeditsection() {}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
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.pfuncs.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
import gplx.xowa.pages.*;
|
||||
public class Pfunc_rev_props extends Pf_func_base {
|
||||
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) {
|
||||
byte[] argx = Eval_argx(ctx, src, caller, self);
|
||||
Xopg_revision_data rev_data = ctx.Cur_page().Revision_data();
|
||||
switch (id) {
|
||||
case Xol_kwd_grp_.Id_page_id:
|
||||
case Xol_kwd_grp_.Id_rev_id: bfr.Add_int_variable(ctx.Cur_page().Revision_data().Id()); break; // NOTE: making rev_id and page_id interchangeable; XOWA does not store rev_id
|
||||
case Xol_kwd_grp_.Id_rev_user: bfr.Add(rev_data.User()); break;
|
||||
case Xol_kwd_grp_.Id_rev_pagesize:
|
||||
if (argx.length > 0) {
|
||||
Xoa_ttl argx_ttl = Xoa_ttl.parse_(ctx.Wiki(), argx);
|
||||
if (argx_ttl == null) { // invalid ttl; EX: {{PAGESIZE:{{{bad}}}}}
|
||||
bfr.Add_byte(Byte_ascii.Num_0);
|
||||
return;
|
||||
}
|
||||
Xoae_page argx_page = ctx.Wiki().Data_mgr().Get_page(argx_ttl, false);
|
||||
if (!argx_page.Missing()) {
|
||||
bfr.Add_int_variable(argx_page.Data_raw().length);
|
||||
return;
|
||||
}
|
||||
}
|
||||
bfr.Add_byte(Byte_ascii.Num_0);
|
||||
break;
|
||||
case Xol_kwd_grp_.Id_rev_protectionlevel: bfr.Add(rev_data.Protection_level()); break;
|
||||
default: throw Exc_.new_unhandled(id);
|
||||
}
|
||||
}
|
||||
public Pfunc_rev_props(int id) {this.id = id;}
|
||||
@Override public int Id() {return id;} private int id;
|
||||
@Override public Pf_func New(int id, byte[] name) {return new Pfunc_rev_props(id).Name_(name);}
|
||||
public static final Pfunc_rev_props _ = new Pfunc_rev_props(-1);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
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.pfuncs.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
import org.junit.*;
|
||||
public class Pfunc_rev_props_tst {
|
||||
private Xop_fxt fxt = new Xop_fxt();
|
||||
@Before public void setup() {fxt.Reset(); fxt.Page().Revision_data().User_(Bry_.new_a7("user")).Protection_level_(Bry_.new_a7("normal"));}
|
||||
@After public void teardown() {}
|
||||
@Test public void RevisionID() {fxt.Page().Revision_data().Id_(1); fxt.Test_parse_tmpl_str_test("{{REVISIONID}}" , "{{test}}", "1");}
|
||||
@Test public void PageID() {fxt.Page().Revision_data().Id_(1); fxt.Test_parse_tmpl_str_test("{{PAGEID}}" , "{{test}}", "1");}
|
||||
@Test public void RevisionUser() {fxt.Test_parse_tmpl_str_test("{{REVISIONUSER}}" , "{{test}}", "user");}
|
||||
@Test public void PageSize() {fxt.Test_parse_tmpl_str_test("{{PAGESIZE:Test page}}" , "{{test}}", "0");}
|
||||
@Test public void ProtectionLevel() {fxt.Test_parse_tmpl_str_test("{{PROTECTIONLEVEL}}" , "{{test}}", "normal");}
|
||||
@Test public void PageSize_invalid_ttl() {
|
||||
fxt.Init_log_(Xop_ttl_log.Invalid_char);
|
||||
fxt.Test_parse_tmpl_str_test("{{PAGESIZE:{{{100}}}|R}}" , "{{test}}", "0");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user