mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v1.6.5.1
This commit is contained in:
26
400_xowa/src_300_html/gplx/xowa/Xoa_app_eval.java
Normal file
26
400_xowa/src_300_html/gplx/xowa/Xoa_app_eval.java
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
public class Xoa_app_eval implements Bry_fmtr_eval_mgr {
|
||||
public Xoa_app_eval(Xoa_app app) {}
|
||||
public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled = true;
|
||||
public byte[] Eval(byte[] cmd) {
|
||||
Object rslt = GfsCore._.Exec_bry(cmd);
|
||||
return Bry_.new_utf8_(Object_.XtoStr_OrNullStr(rslt));
|
||||
}
|
||||
}
|
||||
41
400_xowa/src_300_html/gplx/xowa/Xoa_app_eval_tst.java
Normal file
41
400_xowa/src_300_html/gplx/xowa/Xoa_app_eval_tst.java
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.apps.*;
|
||||
public class Xoa_app_eval_tst {
|
||||
Xoa_app_eval_fxt fxt = new Xoa_app_eval_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Basic() {
|
||||
fxt.Eval_test("[~{<>app.sys_cfg.version;<>}]", "[" + Xoa_app_.Version + "]");
|
||||
}
|
||||
}
|
||||
class Xoa_app_eval_fxt {
|
||||
public void Clear() {
|
||||
if (app == null) {
|
||||
app = Xoa_app_fxt.app_();
|
||||
fmtr = Bry_fmtr.new_();
|
||||
eval = new Xoa_app_eval(app);
|
||||
fmtr.Eval_mgr_(eval);
|
||||
Xoa_gfs_mgr.Msg_parser_init();
|
||||
}
|
||||
} private Xoa_app app; Bry_fmtr fmtr; Xoa_app_eval eval;
|
||||
public void Eval_test(String raw, String expd) {
|
||||
Tfds.Eq(fmtr.Fmt_(raw).Bld_str_many(), expd);
|
||||
}
|
||||
}
|
||||
63
400_xowa/src_300_html/gplx/xowa/Xoa_html_data.java
Normal file
63
400_xowa/src_300_html/gplx/xowa/Xoa_html_data.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
import gplx.xowa.html.modules.*;
|
||||
public class Xoa_html_data {
|
||||
private OrderedHash ctg_hash;
|
||||
public Xoh_module_mgr Module_mgr() {return module_mgr;} private Xoh_module_mgr module_mgr = new Xoh_module_mgr();
|
||||
public byte[] Content_sub() {return html_content_sub;} public void Content_sub_(byte[] v) {html_content_sub = v;} private byte[] html_content_sub;
|
||||
public Bry_bfr Portal_div_xtn() {return portal_div_xtn;} private Bry_bfr portal_div_xtn = Bry_bfr.reset_(255);
|
||||
public int Lnke_autonumber_next() {return lnke_autonumber++;} private int lnke_autonumber = 1;
|
||||
public String Bmk_pos() {return html_bmk_pos;} public void Bmk_pos_(String v) {html_bmk_pos = v;} private String html_bmk_pos;
|
||||
public boolean Restricted() {return html_restricted;} public void Restricted_n_() {html_restricted = false;} private boolean html_restricted = true;
|
||||
public void Restricted_y_() {html_restricted = true;}
|
||||
public byte[] Edit_preview() {return edit_preview;} public void Edit_preview_(byte[] v) {edit_preview = v;} private byte[] edit_preview = Bry_.Empty;
|
||||
public byte[] Search_text() {return search_text;} public void Search_text_(byte[] v) {search_text = v;} private byte[] search_text = Bry_.Empty;
|
||||
public byte[] Custom_html() {return custom_html;} public Xoa_html_data Custom_html_(byte[] v) {custom_html = v; return this;} private byte[] custom_html;
|
||||
public byte[] Custom_name() {return custom_name;} public Xoa_html_data Custom_name_(byte[] v) {custom_name = v; return this;} private byte[] custom_name;
|
||||
public byte[] Custom_head_end() {return custom_head_end;}
|
||||
public void Custom_head_end_concat(byte[] v) {
|
||||
if (v == null)
|
||||
custom_head_end = v;
|
||||
else
|
||||
custom_head_end = Bry_.Add(custom_head_end, v);
|
||||
} private byte[] custom_head_end;
|
||||
public byte[] Custom_html_end() {return custom_html_end;}
|
||||
public void Custom_html_end_concat(byte[] v) {
|
||||
if (v == null)
|
||||
custom_html_end = v;
|
||||
else
|
||||
custom_html_end = Bry_.Add(custom_html_end, v);
|
||||
} private byte[] custom_html_end;
|
||||
public void Clear() {
|
||||
if (ctg_hash != null) ctg_hash.Clear();
|
||||
module_mgr.Clear();
|
||||
lnke_autonumber = 1;
|
||||
html_restricted = true;
|
||||
html_content_sub = Bry_.Empty;
|
||||
search_text = Bry_.Empty;
|
||||
custom_html_end = custom_head_end = custom_html = custom_name = null;
|
||||
}
|
||||
public byte[][] Ctgs_to_ary() {return ctg_hash == null ? Bry_.Ary_empty : (byte[][])ctg_hash.XtoAry(byte[].class);}
|
||||
public void Ctgs_add(Xoa_ttl ttl) {
|
||||
if (ctg_hash == null) ctg_hash = OrderedHash_.new_bry_();
|
||||
byte[] ttl_bry = ttl.Page_txt();
|
||||
if (ctg_hash.Has(ttl_bry)) return;
|
||||
ctg_hash.Add(ttl_bry, ttl_bry);
|
||||
}
|
||||
}
|
||||
105
400_xowa/src_300_html/gplx/xowa/Xoa_page.java
Normal file
105
400_xowa/src_300_html/gplx/xowa/Xoa_page.java
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
import gplx.xowa.gui.*; import gplx.xowa.gui.views.*; import gplx.xowa.html.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.xtns.refs.*; import gplx.xowa.xtns.wdatas.*; import gplx.xowa.parsers.lnkis.redlinks.*; import gplx.xowa.html.tocs.*;
|
||||
public class Xoa_page {
|
||||
Xoa_page(Xow_wiki wiki, Xoa_ttl ttl) {
|
||||
this.wiki = wiki; this.ttl = ttl;
|
||||
this.app = wiki.App(); this.lang = wiki.Lang(); // default to wiki.lang; can be override later by wikitext
|
||||
hdr_mgr = new Xow_hdr_mgr(wiki, this);
|
||||
lnki_redlinks_mgr = new Xop_lnki_logger_redlinks_mgr(this);
|
||||
Ttl_(ttl);
|
||||
} Xoa_page() {} // called by Null
|
||||
public Xoa_app App() {return app;} private Xoa_app app;
|
||||
public Xow_wiki Wiki() {return wiki;} private Xow_wiki wiki;
|
||||
public Xol_lang Lang() {return lang;} public Xoa_page Lang_(Xol_lang v) {lang = v; return this;} private Xol_lang lang;
|
||||
public Xoa_revision_data Revision_data() {return revision_data;} private Xoa_revision_data revision_data = new Xoa_revision_data();
|
||||
public Xoa_html_data Html_data() {return html_data;} private Xoa_html_data html_data = new Xoa_html_data();
|
||||
public Xoa_ttl Ttl() {return ttl;} public Xoa_page Ttl_(Xoa_ttl v) {ttl = v; url.Wiki_bry_(wiki.Domain_bry()).Page_bry_(v.Full_url()); return this;} private Xoa_ttl ttl;
|
||||
public Xoa_url Url() {return url;} public Xoa_page Url_(Xoa_url v) {url = v; return this;} private Xoa_url url = new Xoa_url();
|
||||
public Xog_tab_itm Tab() {return tab;} public void Tab_(Xog_tab_itm v) {tab = v;} private Xog_tab_itm tab;
|
||||
|
||||
public boolean Missing() {return missing;} public Xoa_page Missing_() {return Missing_(true);} public Xoa_page Missing_(boolean v) {missing = v; return this;} private boolean missing;
|
||||
public boolean Redirected() {return redirected;} public Xoa_page Redirected_(boolean v) {redirected = v; return this;} private boolean redirected;
|
||||
public ListAdp Redirect_list() {return redirect_list;} private ListAdp redirect_list = ListAdp_.new_();
|
||||
public byte Edit_mode() {return edit_mode;} private byte edit_mode; public void Edit_mode_update_() {edit_mode = Xoa_page_.Edit_mode_update;}
|
||||
public byte[] Display_ttl() {return display_ttl;} public Xoa_page Display_ttl_(byte[] v) {display_ttl = v; return this;} private byte[] display_ttl;
|
||||
public Xop_root_tkn Root() {return root;} public Xoa_page Root_(Xop_root_tkn v) {root = v; return this;} private Xop_root_tkn root;
|
||||
public byte[] Data_raw() {return data_raw;} public Xoa_page Data_raw_(byte[] v) {data_raw = v; return this;} private byte[] data_raw = Bry_.Empty;
|
||||
public Xow_hdr_mgr Hdr_mgr() {return hdr_mgr;} private Xow_hdr_mgr hdr_mgr;
|
||||
public Xoh_cmd_mgr Html_cmd_mgr() {return html_cmd_mgr;} private Xoh_cmd_mgr html_cmd_mgr = new Xoh_cmd_mgr();
|
||||
public byte[][] Category_list() {return category_list;} public Xoa_page Category_list_(byte[][] v) {category_list = v; return this;} private byte[][] category_list = new byte[0][];
|
||||
public ListAdp Lnki_list() {return lnki_list;} public void Lnki_list_(ListAdp v) {this.lnki_list = v;} private ListAdp lnki_list = ListAdp_.new_();
|
||||
public Xof_xfer_queue File_queue() {return file_queue;} private Xof_xfer_queue file_queue = new Xof_xfer_queue();
|
||||
public ListAdp File_math() {return file_math;} private ListAdp file_math = ListAdp_.new_();
|
||||
public Xof_lnki_file_mgr Lnki_file_mgr() {return lnki_file_mgr;} private Xof_lnki_file_mgr lnki_file_mgr = new Xof_lnki_file_mgr();
|
||||
public Xop_lnki_logger_redlinks_mgr Lnki_redlinks_mgr() {return lnki_redlinks_mgr;} private Xop_lnki_logger_redlinks_mgr lnki_redlinks_mgr;
|
||||
public Ref_itm_mgr Ref_mgr() {return ref_mgr;} private Ref_itm_mgr ref_mgr = new Ref_itm_mgr();
|
||||
public HashAdp Popup_itms() {return popup_itms;} private HashAdp popup_itms = HashAdp_.new_();
|
||||
public Xoh_xtn_mgr Xtn_mgr() {return xtn_mgr;} private Xoh_xtn_mgr xtn_mgr = new Xoh_xtn_mgr();
|
||||
public ListAdp Xwiki_langs() {return xwiki_langs;} private ListAdp xwiki_langs = ListAdp_.new_();
|
||||
public boolean Lang_convert_content() {return lang_convert_content;} public Xoa_page Lang_convert_content_(boolean v) {lang_convert_content = v; return this;} private boolean lang_convert_content = true;
|
||||
public boolean Lang_convert_title() {return lang_convert_title;} public Xoa_page Lang_convert_title_(boolean v) {lang_convert_title = v; return this;} private boolean lang_convert_title = true;
|
||||
public Wdata_external_lang_links_data Wdata_external_lang_links() {return wdata_external_lang_links;} private Wdata_external_lang_links_data wdata_external_lang_links = new Wdata_external_lang_links_data();
|
||||
public boolean Pages_recursed() {return pages_recursed;} public void Pages_recursed_(boolean v) {pages_recursed = v; } private boolean pages_recursed;
|
||||
public void Tmpl_stack_del() {--tmpl_stack_ary_len;}
|
||||
public boolean Tmpl_stack_add(byte[] key) {
|
||||
for (int i = 0; i < tmpl_stack_ary_len; i++) {
|
||||
if (Bry_.Match(key, tmpl_stack_ary[i])) return false;
|
||||
}
|
||||
int new_len = tmpl_stack_ary_len + 1;
|
||||
if (new_len > tmpl_stack_ary_max) {
|
||||
tmpl_stack_ary_max = new_len * 2;
|
||||
tmpl_stack_ary = (byte[][])Array_.Resize(tmpl_stack_ary, tmpl_stack_ary_max);
|
||||
}
|
||||
tmpl_stack_ary[tmpl_stack_ary_len] = key;
|
||||
tmpl_stack_ary_len = new_len;
|
||||
return true;
|
||||
} private byte[][] tmpl_stack_ary = Bry_.Ary_empty; private int tmpl_stack_ary_len = 0, tmpl_stack_ary_max = 0;
|
||||
public void Clear() { // NOTE: this is called post-fetch but pre-parse; do not clear items set by post-fetch, such as id, ttl, redirect_list, data_raw
|
||||
hdr_mgr.Clear();
|
||||
lnki_list.Clear();
|
||||
file_math.Clear();
|
||||
file_queue.Clear();
|
||||
ref_mgr.Grps_clear();
|
||||
html_cmd_mgr.Clear();
|
||||
wdata_external_lang_links.Reset();
|
||||
gplx.xowa.xtns.scribunto.Scrib_core.Core_page_changed(this);
|
||||
lang_convert_content = lang_convert_title = true;
|
||||
xtn_mgr.Clear();
|
||||
xwiki_langs.Clear();
|
||||
html_data.Clear();
|
||||
lnki_file_mgr.Clear();
|
||||
pages_recursed = false;
|
||||
tmpl_stack_ary = Bry_.Ary_empty;
|
||||
tmpl_stack_ary_len = tmpl_stack_ary_max = 0;
|
||||
popup_itms.Clear();
|
||||
}
|
||||
public static final Xoa_page Empty = new Xoa_page().Missing_();
|
||||
public static final Xoa_page Null = null;
|
||||
public static Xoa_page new_(Xow_wiki wiki, Xoa_ttl ttl) {
|
||||
return new Xoa_page(wiki, ttl);
|
||||
}
|
||||
public static Xoa_page test_(Xow_wiki wiki, Xoa_ttl ttl) {return new Xoa_page(wiki, ttl);}
|
||||
public static Xoa_page create_(Xow_wiki wiki, Xoa_ttl ttl) {
|
||||
Xoa_page rv = new Xoa_page(wiki, ttl);
|
||||
rv.edit_mode = Xoa_page_.Edit_mode_create;
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
24
400_xowa/src_300_html/gplx/xowa/Xoa_page_.java
Normal file
24
400_xowa/src_300_html/gplx/xowa/Xoa_page_.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; import gplx.*;
|
||||
public class Xoa_page_ {
|
||||
public static final byte Edit_mode_create = 1, Edit_mode_update = 2;
|
||||
public static final byte[] Main_page_bry = Bry_.new_ascii_("Main_Page"); // OBSOLETE; may not work for non-english wikis
|
||||
public static final byte[] Main_page_bry_empty = Bry_.Empty;
|
||||
public static final int Page_len_max = 2048 * Io_mgr.Len_kb; // REF.MW: DefaultSettings.php; $wgMaxArticleSize = 2048;
|
||||
}
|
||||
24
400_xowa/src_300_html/gplx/xowa/Xoa_revision_data.java
Normal file
24
400_xowa/src_300_html/gplx/xowa/Xoa_revision_data.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; import gplx.*;
|
||||
public class Xoa_revision_data {
|
||||
public int Id() {return id;} public Xoa_revision_data Id_(int v) {id = v; return this;} private int id;
|
||||
public DateAdp Modified_on() {return modified_on;} public Xoa_revision_data Modified_on_(DateAdp v) {modified_on = v; return this;} DateAdp modified_on = DateAdp_.Now();
|
||||
public byte[] User() {return user;} public Xoa_revision_data User_(byte[] v) {user = v; return this;} private byte[] user = Bry_.Empty;
|
||||
public byte[] Protection_level() {return protection_level;} public Xoa_revision_data Protection_level_(byte[] v) {protection_level = v; return this;} private byte[] protection_level = Bry_.Empty;
|
||||
}
|
||||
26
400_xowa/src_300_html/gplx/xowa/Xoh_cfg_gallery.java
Normal file
26
400_xowa/src_300_html/gplx/xowa/Xoh_cfg_gallery.java
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
public class Xoh_cfg_gallery implements GfoInvkAble {
|
||||
public int Imgs_per_row() {return imgs_per_row;} public Xoh_cfg_gallery Imgs_per_row_(int v) {imgs_per_row = v; return this;} private int imgs_per_row = 8; // changed from 4 to 8; DATE:2014-02-04
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_imgs_per_row_)) imgs_per_row = m.ReadInt("v");
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_imgs_per_row_ = "imgs_per_row_";
|
||||
}
|
||||
77
400_xowa/src_300_html/gplx/xowa/Xoh_dom_.java
Normal file
77
400_xowa/src_300_html/gplx/xowa/Xoh_dom_.java
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
import gplx.xowa.html.*;
|
||||
public class Xoh_dom_ {
|
||||
private static final byte[] Lt_bry = Bry_.new_ascii_("<"), Space_bry = Bry_.new_ascii_(" ");
|
||||
public static byte[] Query_val_by_where(Xoh_find rv, byte[] src, byte[] where_nde, byte[] where_key, byte[] where_val, byte[] query_key, int bgn) {
|
||||
int src_len = src.length;
|
||||
where_nde = Bry_.Add(Lt_bry, where_nde, Space_bry);
|
||||
while (true) {
|
||||
boolean where_val_found = Select_tag(rv, src, where_nde, where_key, bgn, src_len);
|
||||
if (where_val_found) {
|
||||
int tag_bgn = rv.Tag_bgn();
|
||||
int tag_end = rv.Tag_end();
|
||||
boolean where_val_match = Bry_.Match(src, rv.Val_bgn(), rv.Val_end(), where_val);
|
||||
if (where_val_match) {
|
||||
boolean query_val_found = Find_atr_val_in_tag(rv, src, query_key, tag_bgn, tag_end);
|
||||
if (query_val_found) {
|
||||
return Bry_.Mid(src, rv.Val_bgn(), rv.Val_end());
|
||||
}
|
||||
else
|
||||
return null;
|
||||
}
|
||||
else
|
||||
bgn = tag_end + 1;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static boolean Select_tag(Xoh_find rv, byte[] src, byte[] nde, byte[] key, int rng_bgn, int rng_end) {
|
||||
int tag_bgn = Bry_finder.Find_fwd(src, nde, rng_bgn, rng_end); if (tag_bgn == Bry_.NotFound) return false;
|
||||
int tag_end = Bry_finder.Find_fwd(src, Byte_ascii.Gt, tag_bgn, rng_end); if (tag_end == Bry_.NotFound) return false;
|
||||
int key_bgn = Bry_finder.Find_fwd(src, key, tag_bgn, tag_end); if (key_bgn == Bry_.NotFound) return false;
|
||||
int key_end = key_bgn + key.length;
|
||||
int val_bgn = Bry_finder.Find_fwd(src, Byte_ascii.Quote, key_end, tag_end); if (val_bgn == Bry_.NotFound) return false;
|
||||
++val_bgn;
|
||||
int val_end = Bry_finder.Find_fwd(src, Byte_ascii.Quote, val_bgn, tag_end); if (val_end == Bry_.NotFound) return false;
|
||||
rv.Set_all(tag_bgn, tag_end, key_bgn, key_end, val_bgn, val_end);
|
||||
return true;
|
||||
}
|
||||
public static boolean Find_atr_val_in_tag(Xoh_find rv, byte[] src, byte[] key, int tag_bgn, int tag_end) {
|
||||
int key_bgn = Bry_finder.Find_fwd(src, key, tag_bgn, tag_end); if (key_bgn == Bry_.NotFound) return false;
|
||||
int key_end = key_bgn + key.length;
|
||||
int val_bgn = Bry_finder.Find_fwd(src, Byte_ascii.Quote, key_end, tag_end); if (val_bgn == Bry_.NotFound) return false;
|
||||
++val_bgn;
|
||||
int val_end = Bry_finder.Find_fwd(src, Byte_ascii.Quote, val_bgn, tag_end); if (val_end == Bry_.NotFound) return false;
|
||||
rv.Set_all(tag_bgn, tag_end, key_bgn, key_end, val_bgn, val_end);
|
||||
return true;
|
||||
}
|
||||
public static String Title_by_href(Url_encoder encoder, Bry_bfr bfr, byte[] href_dec, byte[] html_src) {
|
||||
int slash_pos = Bry_finder.Find_bwd(href_dec, Byte_ascii.Slash);
|
||||
encoder.Encode(bfr, href_dec, slash_pos + 1, href_dec.length);
|
||||
byte[] name_enc = bfr.XtoAryAndClear();
|
||||
bfr.Add_mid(href_dec, 0, slash_pos + Int_.Const_dlm_len); // include trailing slash
|
||||
bfr.Add(name_enc);
|
||||
byte[] href_enc = bfr.XtoAryAndClear();
|
||||
byte[] xowa_title = Xoh_dom_.Query_val_by_where(dom_find, html_src, Xoh_html_tag.Nde_a_bry, Xoh_html_tag.Nde_href_bry, href_enc, Xoh_html_tag.Nde_xowa_title_bry, 0);
|
||||
return String_.new_utf8_(xowa_title);
|
||||
} static final Xoh_find dom_find = new Xoh_find();
|
||||
}
|
||||
45
400_xowa/src_300_html/gplx/xowa/Xoh_dom_tst.java
Normal file
45
400_xowa/src_300_html/gplx/xowa/Xoh_dom_tst.java
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
import org.junit.*;
|
||||
public class Xoh_dom_tst {
|
||||
@Test public void Find_atr() {
|
||||
String src = "a <nde0 atr0=\"val0\" atr1=\"val1\"/> b <nde1 atr0=\"val3\" atr1=\"val4\"/> c";
|
||||
tst_Find(src, "nde0", "atr0", "val0", "atr1", "val1"); // match nde0
|
||||
tst_Find(src, "nde1", "atr0", "val3", "atr1", "val4"); // match nde1
|
||||
tst_Find(src, "nde0", "atr0", "val5", "atr1", null); // wrong val
|
||||
tst_Find(src, "nde0", "atr2", "val0", "atr1", null); // wrong key
|
||||
tst_Find(src, "nde2", "atr0", "val0", "atr1", null); // wrong nde
|
||||
}
|
||||
@Test public void Title_by_href() {// PURPOSE: handle content-editable=n and finding file directly for download
|
||||
Title_by_href_tst("/wiki/File:Bazille,_Frédéric_~_Le_Petit_Jardinier_(The_Little_Gardener),_c1866-67_oil_on_canvas_Museum_of_Fine_Arts,_Houston.jpg"
|
||||
, "<a href=\"lure\" xowa_title=\"wrong\"></a><a href=\"/wiki/File:Bazille,_Fr%C3%A9d%C3%A9ric_%7E_Le_Petit_Jardinier_%28The_Little_Gardener%29,_c1866-67_oil_on_canvas_Museum_of_Fine_Arts,_Houston.jpg\" xowa_title=\"find_me\"></a>"
|
||||
, "find_me"
|
||||
);
|
||||
}
|
||||
private void tst_Find(String src, String where_nde, String where_key, String where_val, String select_key, String expd) {
|
||||
Xoh_find rv = new Xoh_find();
|
||||
byte[] actl = Xoh_dom_.Query_val_by_where(rv, Bry_.new_utf8_(src), Bry_.new_utf8_(where_nde), Bry_.new_utf8_(where_key), Bry_.new_utf8_(where_val), Bry_.new_utf8_(select_key), 0);
|
||||
Tfds.Eq(expd, String_.new_utf8_(actl));
|
||||
}
|
||||
private void Title_by_href_tst(String href, String html_src, String expd) {
|
||||
Bry_bfr bfr = Bry_bfr.reset_(255);
|
||||
String actl = Xoh_dom_.Title_by_href(encoder, bfr, Bry_.new_utf8_(href), Bry_.new_utf8_(html_src));
|
||||
Tfds.Eq(expd, actl);
|
||||
} static final Url_encoder encoder = Url_encoder.url_comma();
|
||||
}
|
||||
36
400_xowa/src_300_html/gplx/xowa/Xoh_file_main.java
Normal file
36
400_xowa/src_300_html/gplx/xowa/Xoh_file_main.java
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
import gplx.xowa.files.*;
|
||||
class Xoh_file_main_alts implements Bry_fmtr_arg {
|
||||
public Xoh_file_main_alts Ini_(Xoh_file_page opt) {
|
||||
this.opt = opt;
|
||||
return this;
|
||||
} private Xoh_file_page opt; Xof_xfer_itm xfer_itm = new Xof_xfer_itm();
|
||||
public void XferAry(Bry_bfr bfr, int idx) {
|
||||
Int_2_ref[] size_alts = opt.Size_alts();
|
||||
int len = size_alts.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Int_2_ref size = size_alts[i];
|
||||
if (xfer_itm.Html_w() < size.Val_0()) continue;
|
||||
xfer_itm.Atrs_by_lnki(Xop_lnki_type.Id_none, size.Val_0(), size.Val_1(), Xop_lnki_tkn.Upright_null, Xof_doc_thumb.Null, Xof_doc_page.Null);
|
||||
xfer_itm.Atrs_calc_for_html();
|
||||
opt.Html_alts().Bld_bfr_many(bfr, xfer_itm.Html_w(), xfer_itm.Html_h(), xfer_itm.Html_view_src(), i == len - 1 ? opt.Html_alt_dlm_last() : opt.Html_alt_dlm_default());
|
||||
}
|
||||
}
|
||||
}
|
||||
138
400_xowa/src_300_html/gplx/xowa/Xoh_file_main_tst.java
Normal file
138
400_xowa/src_300_html/gplx/xowa/Xoh_file_main_tst.java
Normal file
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
import org.junit.*; import gplx.xowa.files.*;
|
||||
public class Xoh_file_main_tst {
|
||||
Xoh_fil_main_fxt fxt = new Xoh_fil_main_fxt();
|
||||
@Before public void init() {fxt.Reset();}
|
||||
@Test public void Image() {
|
||||
fxt.Ttl_str_("Test.png").Html_src_("mem/file/cur.png").Html_orig_src_("mem/file/orig.png").Html_w_(300).Html_h_(200).Html_file_size_(100)
|
||||
.tst(String_.Concat_lines_nl_skip_last
|
||||
( Xoh_fil_main_fxt.Hdr
|
||||
, "<div class=\"fullImageLink\" id=\"file\">"
|
||||
, " <a href=\"mem/file/orig.png\" xowa_title=\"Test.png\">"
|
||||
, " <img id=\"xowa_file_img_0\" alt=\"Test.png\" src=\"mem/file/cur.png\" width=\"300\" height=\"200\" />"
|
||||
, " </a>"
|
||||
, " <div class=\"mw-filepage-resolutioninfo\">Size of this preview: "
|
||||
, " <a href=\"mem/file/cur.png\" class=\"mw-thumbnail-link\">"
|
||||
, " 300 × 200 pixels"
|
||||
, " </a>"
|
||||
, " ."
|
||||
, " <span class=\"mw-filepage-other-resolutions\">"
|
||||
, " Other resolutions:"
|
||||
, ""
|
||||
, " </span>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
, "<div class=\"fullMedia\">"
|
||||
, " <a href=\"mem/file/orig.png\" class=\"internal\" title=\"Test.png\" xowa_title=\"Test.png\">"
|
||||
, " Full resolution"
|
||||
, " </a>"
|
||||
, " ‎"
|
||||
, " <span class=\"fileInfo\">"
|
||||
, " (0 × 0 pixels, file size: 100, MIME type: image/png)"
|
||||
, " </span>"
|
||||
, "</div>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Audio() {
|
||||
fxt.Ttl_str_("Test.oga").Html_src_("mem/file/cur.oga").Html_orig_src_("mem/file/orig.oga").Html_w_(300).Html_h_(200).Html_file_size_(100)
|
||||
.tst(String_.Concat_lines_nl_skip_last
|
||||
( Xoh_fil_main_fxt.Hdr
|
||||
, "<div class=\"fullImageLink\" id=\"file\">"
|
||||
, " <div>"
|
||||
, " <a href=\"mem/file/orig.oga\" xowa_title=\"Test.oga\" class=\"xowa_anchor_button\" style=\"width:300px;max-width:300px;\">"
|
||||
, " <img src=\"file:///mem/xowa/user/test_user/app/img/file/play.png\" width=\"22\" height=\"22\" alt=\"Play sound\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Video() {
|
||||
fxt.Ttl_str_("Test.ogv").Html_src_("mem/file/thumb.png").Html_orig_src_("mem/file/orig.ogv").Html_w_(300).Html_h_(200).Html_file_size_(100)
|
||||
.tst(String_.Concat_lines_nl_skip_last
|
||||
( Xoh_fil_main_fxt.Hdr
|
||||
, "<div class=\"fullImageLink\" id=\"file\">"
|
||||
, " <div>"
|
||||
, " <a href=\"mem/file/thumb.png\" class=\"image\" title=\"Test.ogv\">"
|
||||
, " <img id=\"xowa_file_img_0\" src=\"mem/file/thumb.png\" width=\"300\" height=\"200\" alt=\"\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
, " <div>"
|
||||
, " <a href=\"mem/file/orig.ogv\" xowa_title=\"Test.ogv\" class=\"xowa_anchor_button\" style=\"width:300px;max-width:300px;\">"
|
||||
, " <img src=\"file:///mem/xowa/user/test_user/app/img/file/play.png\" width=\"22\" height=\"22\" alt=\"Play sound\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
}
|
||||
class Xoh_fil_main_fxt {
|
||||
Xoh_file_main_wkr wkr = new Xoh_file_main_wkr();
|
||||
Xoa_app app; Xow_wiki wiki; Xoh_file_page opt;
|
||||
Xof_xfer_itm file = new Xof_xfer_itm();
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
public Xoh_fil_main_fxt Ttl_str_(String v) {this.ttl_str = v; return this;} private String ttl_str;
|
||||
public Xoh_fil_main_fxt Html_src_(String v) {this.html_src = v; return this;} private String html_src;
|
||||
public Xoh_fil_main_fxt Html_orig_src_(String v) {this.html_orig_src = v; return this;} private String html_orig_src;
|
||||
public Xoh_fil_main_fxt Html_w_(int v) {this.html_w = v; return this;} private int html_w;
|
||||
public Xoh_fil_main_fxt Html_h_(int v) {this.html_h = v; return this;} private int html_h;
|
||||
public Xoh_fil_main_fxt Html_file_size_(int v) {this.html_file_size = v; return this;} private int html_file_size;
|
||||
public void Reset() {
|
||||
if (app != null) return;
|
||||
app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
opt = new Xoh_file_page();
|
||||
}
|
||||
public void tst(String expd) {
|
||||
byte[] ttl_bry = Bry_.new_utf8_(ttl_str);
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, ttl_bry);
|
||||
file.Atrs_by_html_for_tests(html_w, html_h, Bry_.new_utf8_(html_src), Bry_.new_utf8_(html_orig_src));
|
||||
file.Atrs_by_ttl(ttl_bry, Bry_.Empty);
|
||||
wkr.Bld_html(wiki, bfr, file, ttl, opt, Bry_.XtoStrBytesByInt(html_file_size, 0), play_btn_icon, 0); // TEST: must pass in elem_val b/c test only uses 2nd Bld_html while app uses 1st
|
||||
Tfds.Eq_str_lines(expd, bfr.XtoStrAndClear());
|
||||
} static final byte[] play_btn_icon = Bry_.new_ascii_("file:///mem/xowa/user/test_user/app/img/file/play.png");
|
||||
public static final String Hdr = String_.Concat_lines_nl_skip_last
|
||||
( "<ul id=\"filetoc\">"
|
||||
, " <li>"
|
||||
, " <a href=\"#file\">"
|
||||
, " File"
|
||||
, " </a>"
|
||||
, " </li>"
|
||||
, " <li>"
|
||||
, " <a href=\"#filehistory\">"
|
||||
, " File history"
|
||||
, " </a>"
|
||||
, " </li>"
|
||||
, " <li>"
|
||||
, " <a href=\"#filelinks\">"
|
||||
, " File usage on Commons"
|
||||
, " </a>"
|
||||
, " </li>"
|
||||
, " <li>"
|
||||
, " <a href=\"#globalusage\">"
|
||||
, " File usage on other wikis"
|
||||
, " </a>"
|
||||
, " </li>"
|
||||
, "</ul>"
|
||||
);
|
||||
}
|
||||
|
||||
67
400_xowa/src_300_html/gplx/xowa/Xoh_file_main_wkr.java
Normal file
67
400_xowa/src_300_html/gplx/xowa/Xoh_file_main_wkr.java
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
import gplx.xowa.html.*;
|
||||
import gplx.xowa.files.*;
|
||||
public class Xoh_file_main_wkr implements Bry_fmtr_arg {
|
||||
Xoh_file_page opt; Xoh_file_main_alts alts = new Xoh_file_main_alts();
|
||||
byte[] file_size_bry; Xoa_ttl ttl; Xow_wiki wiki;
|
||||
public void Bld_html(Xow_wiki wiki, Xop_ctx ctx, Bry_bfr bfr, Xoa_ttl ttl, Xoh_file_page opt, Xof_xfer_queue queue) {
|
||||
this.opt = opt; this.ttl = ttl; this.wiki = wiki;
|
||||
Int_2_ref size_main = opt.Size_main();
|
||||
int main_w = size_main.Val_0();
|
||||
int main_h = size_main.Val_1();
|
||||
this.xfer_itm = wiki.Html_mgr().Html_wtr().Lnki_wtr().File_wtr().Lnki_eval(ctx, queue, ttl.Page_txt(), Xop_lnki_type.Id_thumb, main_w, main_h, Xop_lnki_tkn.Upright_null, Xof_doc_thumb.Null, Xof_doc_page.Null, false, queue_add_ref);
|
||||
Xof_meta_itm meta_itm = wiki.File_mgr().Meta_mgr().Get_itm_or_new(ttl.Page_db(), Xof_xfer_itm_.Md5_(ttl.Page_db())); // NOTE: can't use Md5 of xfer_itm, b/c xfer_itm.Ttl() b/c may be redirected; EX:w:[[Image:Alcott-L.jpg]]
|
||||
Xof_repo_itm trg_repo = null;
|
||||
trg_repo = meta_itm.Repo_itm(wiki);
|
||||
if (trg_repo == null) trg_repo = wiki.File_mgr().Repo_mgr().Repos_get_at(0).Trg();
|
||||
xfer_itm.Atrs_by_meta(meta_itm, trg_repo, Xof_repo_itm.Thumb_default_null);
|
||||
xfer_itm.Atrs_by_orig(meta_itm.Orig_w(), meta_itm.Orig_h(), Xof_img_size.Size_null);
|
||||
|
||||
xfer_itm.Trg_repo_idx_(meta_itm.Vrtl_repo());
|
||||
|
||||
play_btn_icon = wiki.Html_mgr().Img_media_play_btn();
|
||||
|
||||
file_size_bry = Bry_.Empty;
|
||||
if (xfer_itm.Atrs_calc_for_html(true)) {
|
||||
long file_size = Io_mgr._.QueryFil(xfer_itm.Trg_file(Xof_repo_itm.Mode_orig, Xof_img_size.Size_null_deprecated)).Size();
|
||||
file_size_bry = Bry_.new_ascii_(gplx.ios.Io_size_.Xto_str(file_size));
|
||||
}
|
||||
else { // NOTE: commons.wikimedia.org/wiki/File:Solar_Life_Cycle.svg would not load on subsequent views; note that "xfer_itm.Atrs_calc_for_html(true)" resizes image b/c it is .svg; DATE:2013-03-01
|
||||
xfer_itm = Xoh_lnki_file_wtr.Queue_add_manual(queue, xfer_itm);
|
||||
}
|
||||
opt.Html_main().Bld_bfr_many(bfr, this);
|
||||
} byte[] play_btn_icon; Bool_obj_ref queue_add_ref = Bool_obj_ref.n_();
|
||||
public void Bld_html(Xow_wiki wiki, Bry_bfr bfr, Xof_xfer_itm xfer_itm, Xoa_ttl ttl, Xoh_file_page opt, byte[] file_size_bry, byte[] play_btn_icon, int elem_id_val) {
|
||||
this.xfer_itm = xfer_itm;
|
||||
this.wiki = wiki; this.ttl = ttl; this.opt = opt; this.file_size_bry = file_size_bry; this.play_btn_icon = play_btn_icon; this.elem_id_val = elem_id_val;
|
||||
opt.Html_main().Bld_bfr_many(bfr, this);
|
||||
} int elem_id_val;
|
||||
Xof_xfer_itm xfer_itm;
|
||||
public void XferAry(Bry_bfr bfr, int idx) {
|
||||
alts.Ini_(opt);
|
||||
Xof_ext ext = xfer_itm.Lnki_ext();
|
||||
if (ext.Id_is_thumbable_img())
|
||||
opt.Html_main_img().Bld_bfr_many(bfr, xfer_itm.Orig_w(), xfer_itm.Orig_h(), xfer_itm.Html_orig_src(), file_size_bry, ext.Mime_type(), elem_id_val, xfer_itm.Html_w(), xfer_itm.Html_h(), xfer_itm.Html_view_src(), ttl.Full_txt(), wiki.App().Url_converter_url().Encode(ttl.Page_url()), alts);
|
||||
else if (ext.Id_is_video()) // NOTE: video must precede audio else File:***.ogg will not show thumbs
|
||||
opt.Html_main_vid().Bld_bfr_many(bfr, elem_id_val, xfer_itm.Html_view_src(), Xoh_lnki_file_wtr.Bry_class_internal, ttl.Page_db(), xfer_itm.Html_view_src(), xfer_itm.Html_w(), xfer_itm.Html_h(), Bry_.Empty, xfer_itm.Html_orig_src(), xfer_itm.Html_w(), xfer_itm.Html_w(), play_btn_icon);
|
||||
else if (ext.Id_is_audio())
|
||||
opt.Html_main_aud().Bld_bfr_many(bfr, xfer_itm.Html_orig_src(), ttl.Page_db(), xfer_itm.Html_w(), xfer_itm.Html_w(), play_btn_icon);
|
||||
}
|
||||
}
|
||||
134
400_xowa/src_300_html/gplx/xowa/Xoh_file_page.java
Normal file
134
400_xowa/src_300_html/gplx/xowa/Xoh_file_page.java
Normal file
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
public class Xoh_file_page implements GfoInvkAble {
|
||||
public Int_2_ref Size_main() {return size_main;} Int_2_ref size_main;
|
||||
public Int_2_ref[] Size_alts() {return size_alts;} Int_2_ref[] size_alts;
|
||||
public byte[] Html_alt_dlm_default() {return html_alt_dlm_dflt;} private byte[] html_alt_dlm_dflt;
|
||||
public byte[] Html_alt_dlm_last() {return html_alt_dlm_last;} private byte[] html_alt_dlm_last;
|
||||
public Bry_fmtr Html_main() {return html_main;} Bry_fmtr html_main = Bry_fmtr.new_("", "media");
|
||||
public Bry_fmtr Html_main_img() {return html_main_img;} Bry_fmtr html_main_img = Bry_fmtr.new_("", "orig_width", "orig_height", "orig_href", "orig_file_size", "orig_mime_type", "elem_id", "thumb_width", "thumb_height", "thumb_href", "thumb_ttl", "thumb_name", "section_alts");
|
||||
public Bry_fmtr Html_main_aud() {return html_main_aud;} Bry_fmtr html_main_aud = Bry_fmtr.new_("", "lnki_url", "lnki_title", "play_width", "play_max_width", "play_icon");
|
||||
public Bry_fmtr Html_main_vid() {return html_main_vid;} Bry_fmtr html_main_vid = Bry_fmtr.new_("", "elem_id", "lnki_href", "lnki_class", "lnki_title", "lnki_src", "lnki_width", "lnki_height", "lnki_alt", "lnki_url", "play_width", "play_max_width", "play_icon");
|
||||
public Bry_fmtr Html_alts() {return html_alts;} Bry_fmtr html_alts = Bry_fmtr.new_("", "thumb_width", "thumb_height", "thumb_href", "thumb_dlm");
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_html_main_)) html_main.Fmt_(m.ReadStr("v"));
|
||||
else if (ctx.Match(k, Invk_html_main_img_)) html_main_img.Fmt_(m.ReadStr("v"));
|
||||
else if (ctx.Match(k, Invk_html_main_aud_)) html_main_aud.Fmt_(m.ReadStr("v"));
|
||||
else if (ctx.Match(k, Invk_html_main_vid_)) html_main_vid.Fmt_(m.ReadStr("v"));
|
||||
else if (ctx.Match(k, Invk_html_alts_)) html_alts.Fmt_(m.ReadStr("v"));
|
||||
else if (ctx.Match(k, Invk_html_alt_dlm_dflt_)) html_alt_dlm_dflt = m.ReadBry("v");
|
||||
else if (ctx.Match(k, Invk_html_alt_dlm_last_)) html_alt_dlm_last = m.ReadBry("v");
|
||||
else if (ctx.Match(k, Invk_size_main_)) size_main = Int_2_ref.parse_(m.ReadStr("v"));
|
||||
else if (ctx.Match(k, Invk_size_alts_)) size_alts = Int_2_ref.parse_ary_(m.ReadStr("v"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_html_main_ = "html_main_", Invk_html_main_img_ = "html_main_img_", Invk_html_main_aud_ = "html_main_aud_", Invk_html_main_vid_ = "html_main_vid_", Invk_html_alts_ = "html_alts_"
|
||||
, Invk_size_main_ = "size_main_" , Invk_size_alts_ = "size_alts_", Invk_html_alt_dlm_dflt_ = "html_alt_dlm_dflt_", Invk_html_alt_dlm_last_ = "html_alt_dlm_last_";
|
||||
public Xoh_file_page() {
|
||||
size_main = new Int_2_ref(800, 600);
|
||||
size_alts = new Int_2_ref[] {new Int_2_ref(320, 240), new Int_2_ref(640, 480), new Int_2_ref(800, 600), new Int_2_ref(1024, 768), new Int_2_ref(1280, 1024)};
|
||||
html_alt_dlm_dflt = Bry_.new_ascii_("|");
|
||||
html_alt_dlm_last = Bry_.new_ascii_(".");
|
||||
html_main.Fmt_(String_.Concat_lines_nl_skip_last
|
||||
( "<ul id=\"filetoc\">"
|
||||
, " <li>"
|
||||
, " <a href=\"#file\">"
|
||||
, " File"
|
||||
, " </a>"
|
||||
, " </li>"
|
||||
, " <li>"
|
||||
, " <a href=\"#filehistory\">"
|
||||
, " File history"
|
||||
, " </a>"
|
||||
, " </li>"
|
||||
, " <li>"
|
||||
, " <a href=\"#filelinks\">"
|
||||
, " File usage on Commons"
|
||||
, " </a>"
|
||||
, " </li>"
|
||||
, " <li>"
|
||||
, " <a href=\"#globalusage\">"
|
||||
, " File usage on other wikis"
|
||||
, " </a>"
|
||||
, " </li>"
|
||||
, "</ul>"
|
||||
, "~{media}"
|
||||
));
|
||||
html_main_img.Fmt_(String_.Concat_lines_nl_skip_last
|
||||
( "<div class=\"fullImageLink\" id=\"file\">"
|
||||
, " <a href=\"~{orig_href}\" xowa_title=\"~{thumb_name}\">"
|
||||
, " <img id=\"xowa_file_img_~{elem_id}\" alt=\"~{thumb_ttl}\" src=\"~{thumb_href}\" width=\"~{thumb_width}\" height=\"~{thumb_height}\" />"
|
||||
, " </a>"
|
||||
, " <div class=\"mw-filepage-resolutioninfo\">Size of this preview: "
|
||||
, " <a href=\"~{thumb_href}\" class=\"mw-thumbnail-link\">"
|
||||
, " ~{thumb_width} × ~{thumb_height} pixels"
|
||||
, " </a>"
|
||||
, " ."
|
||||
, " <span class=\"mw-filepage-other-resolutions\">"
|
||||
, " Other resolutions:"
|
||||
, "~{section_alts}"
|
||||
, " </span>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
, "<div class=\"fullMedia\">"
|
||||
, " <a href=\"~{orig_href}\" class=\"internal\" title=\"~{thumb_name}\" xowa_title=\"~{thumb_name}\">"
|
||||
, " Full resolution"
|
||||
, " </a>"
|
||||
, " ‎"
|
||||
, " <span class=\"fileInfo\">"
|
||||
, " (~{orig_width} × ~{orig_height} pixels, file size: ~{orig_file_size}, MIME type: ~{orig_mime_type})"
|
||||
, " </span>"
|
||||
, "</div>"
|
||||
, ""
|
||||
));
|
||||
html_main_aud.Fmt_(String_.Concat_lines_nl_skip_last
|
||||
( "<div class=\"fullImageLink\" id=\"file\">"
|
||||
, " <div>"
|
||||
, " <a href=\"~{lnki_url}\" xowa_title=\"~{lnki_title}\" class=\"xowa_anchor_button\" style=\"width:~{play_width}px;max-width:~{play_max_width}px;\">"
|
||||
, " <img src=\"~{play_icon}\" width=\"22\" height=\"22\" alt=\"Play sound\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
, ""
|
||||
));
|
||||
html_main_vid.Fmt_(String_.Concat_lines_nl_skip_last
|
||||
( "<div class=\"fullImageLink\" id=\"file\">"
|
||||
, " <div>"
|
||||
, " <a href=\"~{lnki_href}\" class=\"~{lnki_class}\" title=\"~{lnki_title}\">"
|
||||
, " <img id=\"xowa_file_img_~{elem_id}\" src=\"~{lnki_src}\" width=\"~{lnki_width}\" height=\"~{lnki_height}\" alt=\"~{lnki_alt}\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
, " <div>"
|
||||
, " <a href=\"~{lnki_url}\" xowa_title=\"~{lnki_title}\" class=\"xowa_anchor_button\" style=\"width:~{play_width}px;max-width:~{play_max_width}px;\">"
|
||||
, " <img src=\"~{play_icon}\" width=\"22\" height=\"22\" alt=\"Play sound\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
, ""
|
||||
));
|
||||
html_alts.Fmt_(String_.Concat_lines_nl_skip_last
|
||||
( " <a href=\"~{thumb_href}\" class=\"mw-thumbnail-link\">"
|
||||
, " ~{thumb_width} × ~{thumb_height}"
|
||||
, " </a>"
|
||||
, " ~{thumb_dlm} "
|
||||
, ""
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
29
400_xowa/src_300_html/gplx/xowa/Xoh_find.java
Normal file
29
400_xowa/src_300_html/gplx/xowa/Xoh_find.java
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
public class Xoh_find {
|
||||
public int Tag_bgn() {return tag_bgn;} public Xoh_find Tag_bgn_(int v) {tag_bgn = v; return this;} private int tag_bgn;
|
||||
public int Tag_end() {return tag_end;} public Xoh_find Tag_end_(int v) {tag_end = v; return this;} private int tag_end;
|
||||
public int Key_bgn() {return key_bgn;} public Xoh_find Key_bgn_(int v) {key_bgn = v; return this;} private int key_bgn;
|
||||
public int Key_end() {return key_end;} public Xoh_find Key_end_(int v) {key_end = v; return this;} private int key_end;
|
||||
public int Val_bgn() {return val_bgn;} public Xoh_find Val_bgn_(int v) {val_bgn = v; return this;} private int val_bgn;
|
||||
public int Val_end() {return val_end;} public Xoh_find Val_end_(int v) {val_end = v; return this;} private int val_end;
|
||||
public void Set_all(int tag_bgn, int tag_end, int key_bgn, int key_end, int val_bgn, int val_end) {
|
||||
this.tag_bgn = tag_bgn; this.tag_end = tag_end; this.key_bgn = key_bgn; this.key_end = key_end; this.val_bgn = val_bgn; this.val_end = val_end;
|
||||
}
|
||||
}
|
||||
89
400_xowa/src_300_html/gplx/xowa/Xop_link_parser.java
Normal file
89
400_xowa/src_300_html/gplx/xowa/Xop_link_parser.java
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
import gplx.xowa.html.*; import gplx.xowa.net.*;
|
||||
public class Xop_link_parser {
|
||||
public byte[] Html_xowa_ttl() {return html_xowa_ttl;} private byte[] html_xowa_ttl;
|
||||
public byte[] Html_anchor_cls() {return html_anchor_cls;} private byte[] html_anchor_cls;
|
||||
public byte[] Html_anchor_rel() {return html_anchor_rel;} private byte[] html_anchor_rel;
|
||||
public byte[] Parse(Bry_bfr tmp_bfr, Xoa_url tmp_url, Xow_wiki wiki, byte[] raw, byte[] or) {
|
||||
html_xowa_ttl = null; html_anchor_cls = Xow_html_mgr.Bry_anchor_class_image; html_anchor_rel = Xow_html_mgr.Bry_anchor_rel_blank; // default member variables for html
|
||||
Xoa_app app = wiki.App(); int raw_len = raw.length;
|
||||
app.Url_parser().Parse(tmp_url, raw);
|
||||
switch (tmp_url.Protocol_tid()) {
|
||||
case Xoo_protocol_itm.Tid_http: case Xoo_protocol_itm.Tid_https: // "http:" or "https:"; check if to offline wiki and redirect
|
||||
byte[] wiki_bry = tmp_url.Wiki_bry(), page_bry = tmp_url.Page_bry();
|
||||
if (Bry_.Eq(wiki_bry, wiki.Domain_bry()) // link is to this wiki; check if alias
|
||||
|| app.Xwiki_exists(wiki_bry)) { // link is to an xwiki
|
||||
page_bry = tmp_url.Page_for_lnki();
|
||||
Parse__ttl(tmp_bfr, wiki, wiki_bry, page_bry);
|
||||
}
|
||||
else { // http is to an unknown site
|
||||
if (tmp_url.Protocol_is_relative()) // relative protocol; EX:"//www.a.org";
|
||||
tmp_bfr.Add(tmp_url.Protocol_bry()).Add(raw); // prepend protocol b/c mozilla cannot launch "//www.a.org", but can launch "http://www.a.org"
|
||||
else // regular url
|
||||
tmp_bfr.Add(raw); // dump everything
|
||||
}
|
||||
raw = tmp_bfr.XtoAryAndClear();
|
||||
html_anchor_cls = Xow_html_mgr.Bry_anchor_class_blank;
|
||||
html_anchor_rel = Xow_html_mgr.Bry_anchor_rel_nofollow;
|
||||
break;
|
||||
case Xoo_protocol_itm.Tid_file: // "file:///" or "File:A.png"
|
||||
int proto_len = tmp_url.Protocol_bry().length;
|
||||
if (proto_len + 1 < raw_len && raw[proto_len + 1] == Byte_ascii.Slash) { // next char is slash, assume xfer_itm refers to protocol; EX: file:///C/A.png
|
||||
int slash_pos = Bry_finder.Find_bwd(raw, Byte_ascii.Slash);
|
||||
if (slash_pos != Bry_.NotFound) // set xowa_title to file_name; TODO: call Xoa_url.build; note that this will fail sometimes when (a) xfer_itm is very long (File:ReallyLongName will be shortened to 128 chars) or (b) xfer_itm has invalid windows characters (EX:File:a"b"c.jpg)
|
||||
html_xowa_ttl = Bry_.Mid(raw, slash_pos + Int_.Const_dlm_len, raw.length);
|
||||
}
|
||||
else // next char is not slash; assume xfer_itm refers to ns; EX:File:A.png
|
||||
raw = tmp_bfr.Add(Xoh_href_parser.Href_wiki_bry).Add(raw).XtoAryAndClear();
|
||||
break;
|
||||
default: // is page only; EX: Abc
|
||||
if (Bry_.Len_eq_0(raw)) // NOTE: handle blank link; EX: [[File:Loudspeaker.svg|11px|link=|alt=play]]
|
||||
raw = or;
|
||||
else {
|
||||
if (raw[0] == Byte_ascii.Colon) raw = Bry_.Mid(raw, 1, raw.length); // ignore initial colon; EX: [[:commons:A.png]]
|
||||
if (!Parse__ttl(tmp_bfr, wiki, wiki.Domain_bry(), raw)) {
|
||||
tmp_bfr.Clear();
|
||||
return null;
|
||||
}
|
||||
raw = tmp_bfr.XtoAryAndClear();
|
||||
}
|
||||
break;
|
||||
}
|
||||
return raw;
|
||||
}
|
||||
private static boolean Parse__ttl(Bry_bfr tmp_bfr, Xow_wiki wiki, byte[] wiki_bry, byte[] page_bry) {
|
||||
Xoa_ttl page_ttl = Xoa_ttl.parse_(wiki, page_bry);
|
||||
boolean page_ttl_is_valid = page_ttl != null;
|
||||
if (page_ttl_is_valid) {
|
||||
Xow_xwiki_itm xwiki_itm = page_ttl.Wik_itm();
|
||||
if (xwiki_itm != null) { // is alias; set wiki, page
|
||||
wiki_bry = xwiki_itm.Domain();
|
||||
page_bry = Bry_.Mid(page_bry, xwiki_itm.Key().length + 1, page_bry.length); // +1 for ":"
|
||||
}
|
||||
else // is regular page; use ttl.Full_db() to normalize; EX: -> _
|
||||
page_bry = page_ttl.Full_db();
|
||||
}
|
||||
if (Bry_.Eq(wiki_bry, wiki.Domain_bry())) // NOTE: check against wiki.Key_bry() again; EX: in en_wiki, and http://commons.wikimedia.org/wiki/w:A
|
||||
tmp_bfr.Add(Xoh_href_parser.Href_wiki_bry).Add(page_bry);
|
||||
else
|
||||
tmp_bfr.Add(Xoh_href_parser.Href_site_bry).Add(wiki_bry).Add(Xoh_href_parser.Href_wiki_bry).Add(page_bry);
|
||||
return page_ttl_is_valid;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user