1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2015-05-24 22:43:55 -04:00
parent 6eec99a713
commit 51e6188c1e
1577 changed files with 11555 additions and 10080 deletions

View File

@@ -20,6 +20,6 @@ public class Xoa_app_eval implements Bry_fmtr_eval_mgr {
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_.Xto_str_strict_or_null_mark(rslt));
return Bry_.new_u8(Object_.Xto_str_strict_or_null_mark(rslt));
}
}

View File

@@ -19,7 +19,9 @@ package gplx.xowa; import gplx.*;
public interface Xoa_page {
Xow_wiki Wiki();
Xoa_url Url();
byte[] Url_bry_safe();
Xoa_ttl Ttl();
void Xtn_gallery_packed_exists_y_();
boolean Exists();
Xoa_page__commons_mgr Commons_mgr();
}

View File

@@ -18,7 +18,7 @@ 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 = Bry_.new_a7("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;
}

View File

@@ -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; import gplx.*;
public class Xoa_page__commons_mgr {
public boolean Xowa_mockup() {return xowa_mockup;} public void Xowa_mockup_(boolean v) {xowa_mockup = v;} private boolean xowa_mockup;
public Xow_wiki Source_wiki() {return source_wiki;} public void Source_wiki_(Xow_wiki v) {source_wiki = v;} private Xow_wiki source_wiki;
public Xow_wiki Source_wiki_or(Xow_wiki or) {return source_wiki == null ? or : source_wiki;}
public void Clear() {
this.xowa_mockup = false;
this.source_wiki = null;
}
}

View File

@@ -17,7 +17,7 @@ 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.pages.*;
import gplx.xowa.files.*; import gplx.xowa.xtns.cite.*; import gplx.xowa.xtns.wdatas.*; import gplx.xowa.parsers.lnkis.redlinks.*; import gplx.xowa.html.tocs.*;
import gplx.xowa.files.*; import gplx.xowa.files.xfers.*; import gplx.xowa.xtns.cite.*; import gplx.xowa.xtns.wdatas.*; import gplx.xowa.parsers.lnkis.redlinks.*; import gplx.xowa.html.tocs.*;
import gplx.xowa.html.modules.popups.*; import gplx.xowa.html.hdumps.pages.*; import gplx.xowa.xtns.wdatas.pfuncs.*;
public class Xoae_page implements Xoa_page {
Xoae_page(Xowe_wiki wiki, Xoa_ttl ttl) {
@@ -30,9 +30,11 @@ public class Xoae_page implements Xoa_page {
public Xow_wiki Wiki() {return wiki;}
public Xoa_ttl Ttl() {return ttl;} public Xoae_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 Xoae_page Url_(Xoa_url v) {url = v; return this;} private Xoa_url url = Xoa_url.blank_();
public byte[] Url_bry_safe() {return url == null ? Bry_.Empty : url.Raw();}
public void Xtn_gallery_packed_exists_y_() {html_data.Xtn_gallery_packed_exists_y_();}
public boolean Exists() {return !Missing();}
public Xoa_page__commons_mgr Commons_mgr() {return commons_mgr;} private final Xoa_page__commons_mgr commons_mgr = new Xoa_page__commons_mgr();
public Xopg_revision_data Revision_data() {return revision_data;} private Xopg_revision_data revision_data = new Xopg_revision_data();
public Xowe_wiki Wikie() {return wiki;} private Xowe_wiki wiki;
public Xopg_redlink_lnki_list Redlink_lnki_list() {return redlink_lnki_list;} private Xopg_redlink_lnki_list redlink_lnki_list;
@@ -42,8 +44,8 @@ public class Xoae_page implements Xoa_page {
public Xopg_hdump_data Hdump_data() {return hdump_data;} private final Xopg_hdump_data hdump_data = new Xopg_hdump_data();
public boolean Missing() {return missing;} public Xoae_page Missing_() {return Missing_(true);} public Xoae_page Missing_(boolean v) {missing = v; return this;} private boolean missing;
public boolean Redirected() {return redirected;} public Xoae_page Redirected_(boolean v) {redirected = v; return this;} private boolean redirected;
public ListAdp Redirected_ttls() {return redirected_ttls;} private ListAdp redirected_ttls = ListAdp_.new_();
public byte[] Redirected_ttls__itm_0() {return (byte[])redirected_ttls.FetchAt(0);}
public List_adp Redirected_ttls() {return redirected_ttls;} private List_adp redirected_ttls = List_adp_.new_();
public byte[] Redirected_ttls__itm_0() {return (byte[])redirected_ttls.Get_at(0);}
public byte[] Redirected_src() {return redirected_src;} public void Redirected_src_(byte[] v) {this.redirected_src = v;} private byte[] redirected_src;
public byte Edit_mode() {return edit_mode;} private byte edit_mode; public void Edit_mode_update_() {edit_mode = Xoa_page_.Edit_mode_update;}
public Xop_root_tkn Root() {return root;} public Xoae_page Root_(Xop_root_tkn v) {root = v; return this;} private Xop_root_tkn root;
@@ -51,13 +53,12 @@ public class Xoae_page implements Xoa_page {
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 Xoae_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 List_adp Lnki_list() {return lnki_list;} public void Lnki_list_(List_adp v) {this.lnki_list = v;} private List_adp lnki_list = List_adp_.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 List_adp File_math() {return file_math;} private List_adp file_math = List_adp_.new_();
public Ref_itm_mgr Ref_mgr() {return ref_mgr;} private Ref_itm_mgr ref_mgr = new Ref_itm_mgr();
public Xopg_popup_mgr Popup_mgr() {return popup_mgr;} private Xopg_popup_mgr popup_mgr = new Xopg_popup_mgr();
public ListAdp Slink_list() {return slink_list;} private ListAdp slink_list = ListAdp_.new_();
public List_adp Slink_list() {return slink_list;} private List_adp slink_list = List_adp_.new_();
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 int Bldr__ns_ord() {return bldr__ns_ord;} public void Bldr__ns_ord_(int v) {bldr__ns_ord = v;} private int bldr__ns_ord;
@@ -88,7 +89,6 @@ public class Xoae_page implements Xoa_page {
gplx.xowa.xtns.scribunto.Scrib_core.Core_page_changed(this);
slink_list.Clear();
html_data.Clear();
lnki_file_mgr.Clear();
tab_data.Clear();
pages_recursed = false;
tmpl_stack_ary = Bry_.Ary_empty;
@@ -96,12 +96,13 @@ public class Xoae_page implements Xoa_page {
popup_mgr.Clear();
revision_data.Clear();
tmpl_prepend_mgr.Clear();
commons_mgr.Clear();
}
public static final Xoae_page Null = null;
public static final Xoae_page Empty = new Xoae_page().Missing_();
public static Xoae_page test_(Xowe_wiki wiki, Xoa_ttl ttl) {return new Xoae_page(wiki, ttl);}
public static Xoae_page new_(Xowe_wiki wiki, Xoa_ttl ttl) {return new Xoae_page(wiki, ttl);}
public static Xoae_page create_(Xowe_wiki wiki, Xoa_ttl ttl) {
public static Xoae_page create_(Xowe_wiki wiki, Xoa_ttl ttl) {
Xoae_page rv = new Xoae_page(wiki, ttl);
rv.edit_mode = Xoa_page_.Edit_mode_create;
return rv;

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa; import gplx.*;
import gplx.html.*;
public class Xoh_dom_ {
private static final byte[] Lt_bry = Bry_.new_ascii_("<"), Space_bry = Bry_.new_ascii_(" ");
private static final byte[] Lt_bry = Bry_.new_a7("<"), Space_bry = Bry_.new_a7(" ");
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);
@@ -64,14 +64,8 @@ public class Xoh_dom_ {
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.Xto_bry_and_clear();
bfr.Add_mid(href_dec, 0, slash_pos + Int_.Const_dlm_len); // include trailing slash
bfr.Add(name_enc);
byte[] href_enc = bfr.Xto_bry_and_clear();
byte[] xowa_title = Xoh_dom_.Query_val_by_where(dom_find, html_src, Html_tag_.A_name_bry, Html_atr_.Href_bry, href_enc, gplx.xowa.html.Xoh_consts.Atr_xowa_title_bry, 0);
return String_.new_utf8_(xowa_title);
} static final Xoh_find dom_find = new Xoh_find();
public static String Title_by_href(byte[] href, byte[] html_src) {
byte[] xowa_title = Xoh_dom_.Query_val_by_where(dom_find, html_src, Html_tag_.A_name_bry, Html_atr_.Href_bry, href, gplx.xowa.html.Xoh_consts.Atr_xowa_title_bry, 0);
return String_.new_u8(xowa_title);
} private static final Xoh_find dom_find = new Xoh_find();
}

View File

@@ -27,19 +27,19 @@ public class Xoh_dom_tst {
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"
);
Title_by_href_tst
( "/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"
, "<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));
byte[] actl = Xoh_dom_.Query_val_by_where(rv, Bry_.new_u8(src), Bry_.new_u8(where_nde), Bry_.new_u8(where_key), Bry_.new_u8(where_val), Bry_.new_u8(select_key), 0);
Tfds.Eq(expd, String_.new_u8(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));
String actl = Xoh_dom_.Title_by_href(Bry_.new_u8(href), Bry_.new_u8(html_src));
Tfds.Eq(expd, actl);
} static final Url_encoder encoder = Url_encoder.url_comma();
}
}

View File

@@ -1,36 +0,0 @@
/*
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 {
private Xof_xfer_itm orig_itm; private Xoh_file_page opt; private Xof_xfer_itm xfer_itm = new Xof_xfer_itm();
public Xoh_file_main_alts Ctor(Xof_xfer_itm orig_itm, Xoh_file_page opt) {
this.orig_itm = orig_itm; this.opt = opt; return this;
}
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.Init_by_lnki(orig_itm.Lnki_ttl(), orig_itm.Orig_redirect(), Xop_lnki_type.Id_none, size.Val_0(), size.Val_1(), Xop_lnki_tkn.Upright_null, Xof_lnki_time.Null, Xof_lnki_page.Null);
xfer_itm.Calc_by_meta();
opt.Html_alts().Bld_bfr_many(bfr, xfer_itm.Html_w(), xfer_itm.Html_h(), xfer_itm.Html_view_url(), i == len - 1 ? opt.Html_alt_dlm_last() : opt.Html_alt_dlm_dflt());
}
}
}

View File

@@ -1,138 +0,0 @@
/*
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>"
, " &#8206;"
, " <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();
Xoae_app app; Xowe_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.Init_for_test__img(html_w, html_h, Bry_.new_utf8_(html_src), Bry_.new_utf8_(html_orig_src));
file.Set__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.Xto_str_and_clear());
} 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>"
);
}

View File

@@ -1,69 +0,0 @@
/*
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.core.primitives.*;
import gplx.xowa.html.*; import gplx.xowa.html.lnkis.*;
import gplx.xowa.files.*; import gplx.xowa.files.repos.*;
public class Xoh_file_main_wkr implements Bry_fmtr_arg {
private byte[] file_size_bry; private Xoa_ttl ttl;
private Xof_xfer_itm xfer_itm; private Xoh_file_main_alts alts = new Xoh_file_main_alts(); private Xoh_file_page page_wtr_cfg;
private byte[] play_btn_icon; private Bool_obj_ref queue_add_ref = Bool_obj_ref.n_();
private int elem_id_val;
public void Bld_html(Xowe_wiki wiki, Xop_ctx ctx, Bry_bfr bfr, Xoa_ttl ttl, Xoh_file_page page_wtr_cfg, Xof_xfer_queue queue) {
this.page_wtr_cfg = page_wtr_cfg; this.ttl = ttl;
Int_2_ref main_size = page_wtr_cfg.Size_main();
int main_w = main_size.Val_0();
int main_h = main_size.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_lnki_time.Null, Xof_lnki_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 = meta_itm.Repo_itm(wiki);
if (trg_repo == null) trg_repo = wiki.File_mgr().Repo_mgr().Repos_get_at(0).Trg();
xfer_itm.Set__meta(meta_itm, trg_repo, Xof_repo_itm.Thumb_default_null);
xfer_itm.Init_by_orig_old(meta_itm.Orig_w(), meta_itm.Orig_h(), Xof_img_size.Size_null);
xfer_itm.Trg_repo_idx_(meta_itm.Vrtl_repo());
this.play_btn_icon = wiki.Html_mgr().Img_media_play_btn();
this.file_size_bry = Bry_.Empty;
if (xfer_itm.Calc_by_meta(true)) { // file exists
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: PAGE:c: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 = xfer_itm.Clone();
queue.Add(xfer_itm);
}
page_wtr_cfg.Html_main().Bld_bfr_many(bfr, this);
}
public void Bld_html(Xowe_wiki wiki, Bry_bfr bfr, Xof_xfer_itm xfer_itm, Xoa_ttl ttl, Xoh_file_page page_wtr_cfg, byte[] file_size_bry, byte[] play_btn_icon, int elem_id_val) {
this.xfer_itm = xfer_itm;
this.ttl = ttl; this.page_wtr_cfg = page_wtr_cfg; this.file_size_bry = file_size_bry; this.play_btn_icon = play_btn_icon; this.elem_id_val = elem_id_val;
page_wtr_cfg.Html_main().Bld_bfr_many(bfr, this);
}
public void XferAry(Bry_bfr bfr, int idx) {
alts.Ctor(xfer_itm, page_wtr_cfg);
Xof_ext ext = xfer_itm.Lnki_ext();
if (ext.Id_is_thumbable_img())
page_wtr_cfg.Html_main_img().Bld_bfr_many(bfr, xfer_itm.Orig_w(), xfer_itm.Orig_h(), xfer_itm.Html_orig_url(), file_size_bry, ext.Mime_type(), elem_id_val, xfer_itm.Html_w(), xfer_itm.Html_h(), xfer_itm.Html_view_url(), ttl.Full_txt(), Xoa_app_.Utl__encoder_mgr().Url().Encode(ttl.Page_url()), alts);
else if (ext.Id_is_video()) // NOTE: video must precede audio else File:***.ogg will not show thumbs
page_wtr_cfg.Html_main_vid().Bld_bfr_many(bfr, elem_id_val, xfer_itm.Html_view_url(), Atr_class_image, ttl.Page_db(), xfer_itm.Html_view_url(), xfer_itm.Html_w(), xfer_itm.Html_h(), Bry_.Empty, xfer_itm.Html_orig_url(), xfer_itm.Html_w(), xfer_itm.Html_w(), play_btn_icon);
else if (ext.Id_is_audio())
page_wtr_cfg.Html_main_aud().Bld_bfr_many(bfr, xfer_itm.Html_orig_url(), ttl.Page_db(), xfer_itm.Html_w(), xfer_itm.Html_w(), play_btn_icon);
}
private static final byte[] Atr_class_image = Bry_.new_ascii_("image");
}

View File

@@ -1,131 +0,0 @@
/*
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 Xoh_file_page() {
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>"
, " &#8206;"
, " <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} "
, ""
));
}
public Int_2_ref Size_main() {return size_main;} private Int_2_ref size_main = new Int_2_ref(800, 600);
public Int_2_ref[] Size_alts() {return size_alts;} private Int_2_ref[] 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)};
public byte[] Html_alt_dlm_dflt() {return html_alt_dlm_dflt;} private byte[] html_alt_dlm_dflt = Bry_.new_ascii_("|");
public byte[] Html_alt_dlm_last() {return html_alt_dlm_last;} private byte[] html_alt_dlm_last = Bry_.new_ascii_(".");
public Bry_fmtr Html_main() {return html_main;} private final Bry_fmtr html_main = Bry_fmtr.new_("", "media");
public Bry_fmtr Html_main_img() {return html_main_img;} private final 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;} private final 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;} private final 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;} private final 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_";
}