1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-10-27 20:34:16 +00:00

Section_edit: Fail when clicking on transcluded headers

This commit is contained in:
gnosygnu 2016-12-08 19:53:59 -05:00
parent fd79415b53
commit 998937ca26
8 changed files with 161 additions and 40 deletions

View File

@ -32,7 +32,7 @@ public class Xoa_app_ {
}
}
public static final String Name = "xowa";
public static final String Version = "3.12.1.1";
public static final String Version = "3.12.1.2";
public static String Build_date = "2012-12-30 00:00:00";
public static String Op_sys_str;
public static String User_agent = "";

View File

@ -69,7 +69,7 @@ public class Xoedit_itm implements Xoedit_nde, Mustache_doc_itm {
Gfobj_nde rv = Gfobj_nde.New();
rv.Add_int("id", id);
rv.Add_str("key", key);
rv.Add_str("dflt", lang);
rv.Add_str("dflt", dflt);
rv.Add_str("lang", lang);
rv.Add_str("name", name);
rv.Add_str("help", help);
@ -88,7 +88,7 @@ public class Xoedit_itm implements Xoedit_nde, Mustache_doc_itm {
if (String_.Eq(k, "id")) bfr.Add_int(id);
else if (String_.Eq(k, "key")) bfr.Add_str_u8(key);
else if (String_.Eq(k, "dflt")) bfr.Add_str_u8(dflt);
else if (String_.Eq(k, "lang")) bfr.Add_str_u8(name);
else if (String_.Eq(k, "lang")) bfr.Add_str_u8(lang);
else if (String_.Eq(k, "name")) bfr.Add_str_u8(name);
else if (String_.Eq(k, "help")) bfr.Add_str_u8(help);
else if (String_.Eq(k, "ctx")) bfr.Add_str_u8(ctx);

View File

@ -226,7 +226,7 @@ public class Xoh_page_wtr_wkr {
data_raw = Gfs_php_converter.Xto_php(tmp_bfr, Bool_.N, data_raw);
int data_raw_len = data_raw.length;
if (mgr.Html_capable()) {
data_raw = wiki.Parser_mgr().Hdr__section_editable__mgr().Extract_section(page.Url(), page.Ttl(), data_raw);
data_raw = wiki.Parser_mgr().Hdr__section_editable__mgr().Extract_section(app, page.Url(), page.Ttl(), data_raw);
data_raw_len = data_raw.length;
Xoh_html_wtr_escaper.Escape(page.Wikie().Appe().Parser_amp_mgr(), bfr, data_raw, 0, data_raw_len, false, false); // NOTE: must escape; assume that browser will automatically escape (<) (which Mozilla does)
}

View File

@ -18,5 +18,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.htmls.core.wkrs.hdrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*; import gplx.xowa.parsers.hdrs.*;
public class Xoh_section_editable_ {
public static final String Cfg__section_editing__enabled = "section_editing.enabled";
public static final String Cfg__section_editing__enabled = "xowa.edit.section_edit.enabled";
}

View File

@ -24,6 +24,7 @@ class Xop_section_list implements Xomw_hdr_cbk {
public Xop_section_list Parse(byte[] src) {
this.src = src;
hash.Clear();
Xomw_parser_ctx pctx = new Xomw_parser_ctx();
hdr_wkr.Parse(pctx, src, 0, src.length, this);
return this;

View File

@ -0,0 +1,144 @@
/*
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.hdrs.sections; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; import gplx.xowa.parsers.hdrs.*;
import org.junit.*; import gplx.core.tests.*;
public class Xop_section_list__merge__tst {
private final Xop_section_list__fxt fxt = new Xop_section_list__fxt();
@Test public void Basic() {
fxt.Exec__parse
( "== Hdr 1 =="
, "Para 1"
, ""
, "== Hdr 2 =="
, "Para 2"
, ""
, "== Hdr 3 =="
, "Para 3"
);
fxt.Test__merge_bry_or_null("Hdr 2", String_.Concat_lines_nl_skip_last
( "== Hdr 2 =="
, "Para 2a"
), String_.Concat_lines_nl_skip_last
( "== Hdr 1 =="
, "Para 1"
, ""
, "== Hdr 2 =="
, "Para 2a"
, ""
, "== Hdr 3 =="
, "Para 3"
)
);
}
@Test public void Nl_many() {
fxt.Exec__parse
( "== Hdr 1 =="
, "Para 1"
, ""
, ""
, ""
, "== Hdr 2 =="
, "Para 2"
, ""
, ""
, ""
, "== Hdr 3 =="
, "Para 3"
);
fxt.Test__merge_bry_or_null("Hdr 2", String_.Concat_lines_nl_skip_last
( "== Hdr 2 =="
, "Para 2a"
), String_.Concat_lines_nl_skip_last
( "== Hdr 1 =="
, "Para 1"
, ""
, ""
, ""
, "== Hdr 2 =="
, "Para 2a"
, ""
, ""
, ""
, "== Hdr 3 =="
, "Para 3"
)
);
}
@Test public void Bos() {
fxt.Exec__parse
( "== Hdr 1 =="
, "Para 1"
, ""
, "== Hdr 2 =="
, "Para 2"
);
fxt.Test__merge_bry_or_null("Hdr 1", String_.Concat_lines_nl_skip_last
( "== Hdr 1 =="
, "Para 1a"
), String_.Concat_lines_nl_skip_last
( "== Hdr 1 =="
, "Para 1a"
, ""
, "== Hdr 2 =="
, "Para 2"
)
);
}
@Test public void Bos__ws() {
fxt.Exec__parse
( ""
, "== Hdr 1 =="
, "Para 1"
, ""
, "== Hdr 2 =="
, "Para 2"
);
fxt.Test__merge_bry_or_null("Hdr 1", String_.Concat_lines_nl_skip_last
( "== Hdr 1 =="
, "Para 1a"
), String_.Concat_lines_nl_skip_last
( ""
, "== Hdr 1 =="
, "Para 1a"
, ""
, "== Hdr 2 =="
, "Para 2"
)
);
}
@Test public void Eos() {
fxt.Exec__parse
( "== Hdr 1 =="
, "Para 1"
, ""
, "== Hdr 2 =="
, "Para 2"
);
fxt.Test__merge_bry_or_null("Hdr 2", String_.Concat_lines_nl_skip_last
( "== Hdr 2 =="
, "Para 2a"
), String_.Concat_lines_nl_skip_last
( "== Hdr 1 =="
, "Para 1"
, ""
, "== Hdr 2 =="
, "Para 2a"
)
);
}
}

View File

@ -17,9 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.parsers.hdrs.sections; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; import gplx.xowa.parsers.hdrs.*;
import org.junit.*; import gplx.core.tests.*;
public class Xop_section_list__tst {
public class Xop_section_list__slice__tst {
private final Xop_section_list__fxt fxt = new Xop_section_list__fxt();
@Test public void Extract__basic() {
@Test public void Basic() {
fxt.Exec__parse
( "== Hdr 1 =="
, "Para 1"
@ -30,52 +30,26 @@ public class Xop_section_list__tst {
, "== Hdr 3 =="
, "Para 3"
);
fxt.Test__extract_bry_or_null("Hdr 1"
fxt.Test__slice_bry_or_null("Hdr 1"
, "== Hdr 1 =="
, "Para 1"
);
fxt.Test__extract_bry_or_null("Hdr 2"
fxt.Test__slice_bry_or_null("Hdr 2"
, "== Hdr 2 =="
, "Para 2"
);
fxt.Test__extract_bry_or_null("Hdr 3"
fxt.Test__slice_bry_or_null("Hdr 3"
, "== Hdr 3 =="
, "Para 3"
);
}
@Test public void Merge__basic() {
fxt.Exec__parse
( "== Hdr 1 =="
, "Para 1"
, ""
, "== Hdr 2 =="
, "Para 2"
, ""
, "== Hdr 3 =="
, "Para 3"
);
fxt.Test__merge_bry_or_null("Hdr 2", String_.Concat_lines_nl_skip_last
( "== Hdr 2 =="
, "abcd"
), String_.Concat_lines_nl_skip_last
( "== Hdr 1 =="
, "Para 1"
, ""
, "== Hdr 2 =="
, "abcd"
, ""
, "== Hdr 3 =="
, "Para 3"
)
);
}
}
class Xop_section_list__fxt {
private final Xop_section_list list = new Xop_section_list();
public void Exec__parse(String... lines) {
list.Parse(Bry_.new_u8(String_.Concat_lines_nl_skip_last(lines)));
}
public void Test__extract_bry_or_null(String key, String... lines) {
public void Test__slice_bry_or_null(String key, String... lines) {
String expd = String_.Concat_lines_nl_skip_last(lines);
byte[] actl = list.Extract_bry_or_null(Bry_.new_u8(key));
Gftest.Eq__ary__lines(expd, actl, key);

View File

@ -28,7 +28,7 @@ public class Xop_section_mgr implements Gfo_invk {
public void Init_by_wiki(Xowe_wiki wiki) {
enabled = wiki.App().Cfg().Bind_bool(wiki, gplx.xowa.htmls.core.wkrs.hdrs.Xoh_section_editable_.Cfg__section_editing__enabled, this); // SECTION_EDIT
}
public byte[] Extract_section(Xoa_url url, Xoa_ttl ttl, byte[] src) {
public byte[] Extract_section(Xoae_app app, Xoa_url url, Xoa_ttl ttl, byte[] src) {
// return orig if section_editing not enabled
if (!enabled) return src;
@ -39,8 +39,10 @@ public class Xop_section_mgr implements Gfo_invk {
// parse wikitext into list of headers
Xop_section_list section_list = new Xop_section_list().Parse(src);
byte[] rv = section_list.Extract_bry_or_null(section_key);
if (rv == null)
throw Err_.new_wo_type("section_key not found", "page", ttl.Full_db(), "section_key", section_key);
if (rv == null) {
app.Gui_mgr().Kit().Ask_ok("", "", String_.Format("Section extraction failed!\nPlease do not edit this page else data will be lost!!\n\nwiki={0}\npage={1}\nsection={2}", url.Wiki_bry(), ttl.Full_db(), section_key));
throw Err_.new_wo_type("section_key not found", "wiki", url.Wiki_bry(), "page", ttl.Full_db(), "section_key", section_key);
}
return rv;
}
public byte[] Merge_section(Xoa_url url, byte[] edit, byte[] orig) {