1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-10-27 20:34:16 +00:00
This commit is contained in:
gnosygnu 2014-08-24 23:14:26 -04:00
parent 7ee4326485
commit b0a01882de
109 changed files with 1470 additions and 1106 deletions

View File

@ -47,6 +47,7 @@ public class Bry_bfr {
}
public Bry_bfr Clear() {bfr_len = 0; return this;}
public Bry_bfr ClearAndReset() {bfr_len = 0; if (reset > 0) Reset_if_gt(reset); return this;}
public byte Get_at_last_or_nil_if_empty() {return bfr_len == 0 ? Byte_ascii.Nil : bfr[bfr_len - 1];}
public Bry_bfr Add_safe(byte[] val) {return val == null ? this : Add(val);}
public Bry_bfr Add(byte[] val) {
int val_len = val.length;

View File

@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
public class Bry_bfr_ {
public static Bry_bfr[] Ary_empty = new Bry_bfr[0];
public static void Assert_at_end(Bry_bfr bfr, byte assert_byte) {
int len = bfr.Len(); if (len == 0) return;
int assert_count = 0;

View File

@ -21,7 +21,7 @@ public class Db_provider implements RlsAble {
this.engine = engine;
txn_mgr = new Db_txn_mgr_base(engine);
}
@gplx.Internal protected Db_engine Engine() {return engine;} Db_engine engine;
@gplx.Internal protected Db_engine Engine() {return engine;} private Db_engine engine;
public Db_connect ConnectInfo() {return engine.ConnectInfo();}
public Db_stmt Prepare(Db_qry qry) {return engine.New_db_stmt(this, qry);}
public int Exec_qry(Db_qry qry) {txn_mgr.Txn_count_(txn_mgr.Txn_count() + 1); return Int_.cast_(engine.Execute(qry));}

View File

@ -26,7 +26,7 @@ public interface Db_txn_mgr {
int Txn_count(); void Txn_count_(int v);
}
class Db_txn_mgr_base implements Db_txn_mgr {
public Db_txn_mgr_base(Db_engine engine) {this.engine = engine;} Db_engine engine;
public Db_txn_mgr_base(Db_engine engine) {this.engine = engine;} private Db_engine engine;
public int Txn_depth() {return txn_depth;} int txn_depth; // NOTE: only support 1 level for now;
public void Txn_bgn_if_none() {if (txn_depth == 0) this.Txn_bgn();}
public void Txn_bgn() {

View File

@ -15,11 +15,12 @@ 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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
package gplx.core.brys; import gplx.*; import gplx.core.*;
public class Bry_rdr {
private byte[] src; private int src_len;
public Bry_rdr Src_(byte[] src, int src_len) {this.src = src; this.src_len = src_len; pos = 0; return this;} public Bry_rdr Src_(byte[] src) {return Src_(src, src.length);}
public int Pos() {return pos;} public Bry_rdr Pos_(int v) {this.pos = v; return this;} private int pos;
public boolean Pos_is_eos() {return pos == src_len;}
public int Or_int() {return or_int;} public void Or_int_(int v) {or_int = v;} private int or_int = Int_.MinValue;
public byte[] Or_bry() {return or_bry;} public void Or_bry_(byte[] v) {or_bry = v;} private byte[] or_bry;
public int Read_int_to_pipe() {return Read_int_to(Byte_ascii.Pipe);}
@ -39,6 +40,7 @@ public class Bry_rdr {
}
return bgn == pos ? or_int : rv;
}
public byte[] Read_bry_to_nl() {return Read_bry_to(Byte_ascii.NewLine);}
public byte[] Read_bry_to_pipe() {return Read_bry_to(Byte_ascii.Pipe);}
public byte[] Read_bry_to(byte to_char) {
int bgn = pos;

View File

@ -15,7 +15,7 @@ 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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
package gplx.core.brys; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Bry_rdr_tst {
@Before public void init() {fxt.Clear();} private Bry_rdr_fxt fxt = new Bry_rdr_fxt();

View File

@ -19,7 +19,7 @@ package gplx.fsdb; import gplx.*;
import gplx.dbs.*; import gplx.cache.*;
public class Fsdb_db_atr_fil implements RlsAble {
private Gfo_cache_mgr_bry dir_cache = new Gfo_cache_mgr_bry();
private Fsdb_dir_tbl tbl_dir; private Fsdb_fil_tbl tbl_fil; private Fsdb_xtn_thm_tbl tbl_thm; private Fsdb_xtn_img_tbl tbl_img; private Bool_obj_ref img_needs_create = Bool_obj_ref.n_();
private Fsdb_dir_tbl tbl_dir; private Fsdb_fil_tbl tbl_fil; private Fsdb_xtn_thm_tbl tbl_thm;
public Fsdb_db_atr_fil(Fsdb_db_abc_mgr abc_mgr, Io_url url, boolean create) {
this.abc_mgr = abc_mgr;
Db_connect connect = create ? Db_connect_sqlite.make_(url) : Db_connect_sqlite.load_(url);
@ -28,7 +28,6 @@ public class Fsdb_db_atr_fil implements RlsAble {
tbl_dir = new Fsdb_dir_tbl(provider, create);
tbl_fil = new Fsdb_fil_tbl(provider, create);
tbl_thm = new Fsdb_xtn_thm_tbl(this, provider, create);
tbl_img = new Fsdb_xtn_img_tbl(provider, create);
}
public Fsdb_db_abc_mgr Abc_mgr() {return abc_mgr;} private Fsdb_db_abc_mgr abc_mgr;
public Db_provider Provider() {return provider;} private Db_provider provider;
@ -39,7 +38,6 @@ public class Fsdb_db_atr_fil implements RlsAble {
public void Rls() {
tbl_dir.Rls();
tbl_fil.Rls();
tbl_img.Rls();
tbl_thm.Rls();
provider.Txn_mgr().Txn_end_all();
provider.Rls();
@ -74,10 +72,7 @@ public class Fsdb_db_atr_fil implements RlsAble {
}
public int Img_insert(Fsdb_xtn_img_itm rv, String dir, String fil, int ext_id, int img_w, int img_h, DateAdp modified, String hash, int bin_db_id, long bin_len, gplx.ios.Io_stream_rdr bin_rdr) {
int dir_id = Dir_id__get_or_insert(dir);
img_needs_create.Val_(false);
int fil_id = Fil_id__get_or_insert(Fsdb_xtn_tid_.Tid_img, dir_id, fil, ext_id, modified, hash, bin_db_id, bin_len);
if (img_needs_create.Val()) // NOTE: fsdb_fil row can already exist; EX: thm gets inserted -> fsdb_fil row gets created with -1 bin_db_id; orig gets inserted -> fsdb_fil row already exists
tbl_img.Insert(fil_id, img_w, img_h);
rv.Id_(fil_id);
return fil_id;
}
@ -134,15 +129,12 @@ public class Fsdb_db_atr_fil implements RlsAble {
if (fil_id == Fsdb_fil_itm.Null_id) { // new item
fil_id = abc_mgr.Next_id();
tbl_fil.Insert(fil_id, dir_id, fil, xtn_tid, ext_id, bin_len, modified, hash, bin_db_id);
img_needs_create.Val_(true);
}
else { // existing item
if ( fil_itm.Db_bin_id() == Fsdb_bin_tbl.Null_db_bin_id // prv row was previously inserted by thumb
&& xtn_tid != Fsdb_xtn_tid_.Tid_thm // cur row is not thumb
) {
tbl_fil.Update(fil_id, dir_id, fil, xtn_tid, ext_id, bin_len, modified, hash, bin_db_id); // update props; note that thumb inserts null props, whereas file will insert real props (EX: bin_db_id)
if (xtn_tid == Fsdb_xtn_tid_.Tid_img)
img_needs_create.Val_(true);
}
}
return fil_id;

View File

@ -1,68 +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.fsdb; import gplx.*;
import gplx.dbs.*;
public class Fsdb_xtn_img_tbl {
private Db_provider provider;
private Db_stmt stmt_insert, stmt_select_by_id;
public Fsdb_xtn_img_tbl(Db_provider provider, boolean created) {
this.provider = provider;
if (created) Create_table();
}
public void Rls() {
if (stmt_insert != null) {stmt_insert.Rls(); stmt_insert = null;}
if (stmt_select_by_id != null) {stmt_select_by_id.Rls(); stmt_select_by_id = null;}
}
public void Create_table() {
Sqlite_engine_.Tbl_create(provider, Tbl_name, Tbl_sql);
}
public Db_stmt Insert_stmt() {return Db_stmt_.new_insert_(provider, Tbl_name, Fld_img_id, Fld_img_w, Fld_img_h);}
public void Insert(int id, int w, int h) {
if (stmt_insert == null) stmt_insert = Insert_stmt();
try {
stmt_insert.Clear()
.Val_int_(id)
.Val_int_(w)
.Val_int_(h)
.Exec_insert();
} catch (Exception exc) {stmt_insert = null; throw Err_.err_(exc, "stmt failed");} // must reset stmt, else next call will fail
}
public Db_stmt Select_itm_by_id_stmt() {return Db_stmt_.new_select_(provider, Tbl_name, String_.Ary(Fld_img_id), Fld_img_w, Fld_img_h); }
public Fsdb_xtn_img_itm Select_itm_by_id(int id) {
if (stmt_select_by_id == null) stmt_select_by_id = this.Select_itm_by_id_stmt();
DataRdr rdr = DataRdr_.Null;
try {
rdr = stmt_select_by_id.Clear()
.Val_int_(id)
.Exec_select();
if (rdr.MoveNextPeer())
return new Fsdb_xtn_img_itm().Init_by_load(id, rdr.ReadInt(Fld_img_w), rdr.ReadInt(Fld_img_h));
else
return Fsdb_xtn_img_itm.Null;
}
finally {rdr.Rls();}
}
public static final String Tbl_name = "fsdb_xtn_img", Fld_img_id = "img_id", Fld_img_w = "img_w", Fld_img_h = "img_h";
private static final String Tbl_sql = String_.Concat_lines_nl
( "CREATE TABLE IF NOT EXISTS fsdb_xtn_img"
, "( img_id integer NOT NULL PRIMARY KEY"
, ", img_w integer NOT NULL"
, ", img_h integer NOT NULL"
, ");"
);
}

View File

@ -23,7 +23,7 @@ public class Xoa_app_ {
boot_mgr.Run(args);
}
public static final String Name = "xowa";
public static final String Version = "1.8.3.1";
public static final String Version = "1.8.4.1";
public static String Build_date = "2012-12-30 00:00:00";
public static String Op_sys;
public static String User_agent = "";

View File

@ -43,7 +43,7 @@ public class Db_mgr_fxt {
for (int i = 0; i < len; i++) {
String ttl = ttls[i];
int page_id = page_id_next.Val();
tbl_page.Insert(stmt, page_id, ns_id, Bry_.new_utf8_(ttl), false, modified_on, 0, page_id, 0);
tbl_page.Insert(stmt, page_id, ns_id, Bry_.new_utf8_(ttl), false, modified_on, 0, page_id, 0, 0);
page_id_next.Val_add(1);
}
} finally {stmt.Rls();}

View File

@ -65,6 +65,7 @@ public class Xob_fsdb_make extends Xob_itm_basic_base implements Xob_cmd {
}
usr_dlg.Note_many("", "", "done: ~{0} ~{1}", exec_count, DecimalAdp_.divide_safe_(exec_count, Env_.TickCount_elapsed_in_sec(time_bgn)).XtoStr("#,###.000"));
this.Txn_save();
tbl_cfg.Delete(Cfg_fsdb_make, Cfg_page_id_bmk); tbl_cfg.Delete(Cfg_fsdb_make, Cfg_lnki_id_bmk); // delete bmks if future reruns are needed; DATE:2014-08-20
trg_fsdb_mgr.Txn_save();
trg_fsdb_mgr.Rls(); // save changes and rls all connections
db_select_stmt.Rls();
@ -237,7 +238,8 @@ public class Xob_fsdb_make extends Xob_itm_basic_base implements Xob_cmd {
trg_fsdb_mgr.Thm_insert(tmp_thm_itm, itm.Orig_wiki(), itm.Lnki_ttl(), itm.Lnki_ext_id(), itm.Html_w(), itm.Html_h(), itm.Lnki_thumbtime(), itm.Lnki_page(), Sqlite_engine_.Date_null, Fsdb_xtn_thm_tbl.Hash_null, rdr.Len(), rdr);
db_uid = tmp_thm_itm.Id();
}
app.Usr_dlg().Log_direct(String_.Format("download done; size=~{0} id=~{1}\n", rdr.Len(), db_uid));
if (app.Mode() == Xoa_app_.Mode_gui)
app.Usr_dlg().Log_direct(String_.Format("download done; size={0} id={1}", rdr.Len(), db_uid));
}
private void Txn_renew() {
this.Txn_save();

View File

@ -136,7 +136,8 @@ class Xob_orig_regy_tbl {
, "FROM orig_regy o"
, " JOIN image_db.image i ON o.lnki_ttl = i.img_name"
, " JOIN page_db.page_regy m ON m.repo_id = {0} AND m.itm_tid = 0 AND o.lnki_ttl = m.src_ttl"
, "WHERE i.img_timestamp > o.orig_timestamp" // NOTE: this handles an image in local and remote by taking later version; DATE:2014-07-22
, "WHERE o.orig_file_ttl IS NULL" // NOTE: only insert if file doesn't exist; changed from timestamp b/c old images may exist in both wikis; EX:ar.n:File:Facebook.png; DATE:2014-08-20
// , "WHERE i.img_timestamp > o.orig_timestamp" // NOTE: this handles an image in local and remote by taking later version; DATE:2014-07-22
, "ORDER BY 1" // must order by lnki_id since it is PRIMARY KEY, else sqlite will spend hours shuffling rows in table
, ";"
)
@ -165,7 +166,8 @@ class Xob_orig_regy_tbl {
, "FROM orig_regy o"
, " JOIN page_db.page_regy m ON m.repo_id = {0} AND m.itm_tid = 1 AND o.lnki_ttl = m.src_ttl"
, " JOIN image_db.image i ON m.trg_ttl = i.img_name"
, "WHERE i.img_timestamp > o.orig_timestamp" // NOTE: this handles an image in local and remote by taking later version; DATE:2014-07-22
, "WHERE o.orig_file_ttl IS NULL" // NOTE: only insert if file doesn't exist; changed from timestamp b/c old images may exist in both wikis; EX:ar.n:File:Facebook.png; DATE:2014-08-20
// , "WHERE i.img_timestamp > o.orig_timestamp" // NOTE: this handles an image in local and remote by taking later version; DATE:2014-07-22
, "ORDER BY 1" // must order by lnki_id since it is PRIMARY KEY, else sqlite will spend hours shuffling rows in table
, ";"
)

View File

@ -77,6 +77,7 @@ class Xob_xfer_temp_itm {
, Chk_tid_orig_page_id_is_null = 1
, Chk_tid_orig_media_type_is_audio = 2
, Chk_tid_ns_is_media = 3
, Chk_tid_orig_w_is_0 = 4
;
public byte Chk_tid() {return chk_tid;} private byte chk_tid;
public boolean Chk(Xof_img_size img_size) {
@ -103,6 +104,10 @@ class Xob_xfer_temp_itm {
chk_tid = Chk_tid_orig_media_type_is_audio;
return false;
}
if (orig_w <= 0) { // ignore files that have an orig_w of 0; note that ogg files that are sometimes flagged as VIDEO; EX:2009_10_08_Marc_Randazza_interview.ogg; DATE:2014-08-20
chk_tid = Chk_tid_orig_w_is_0;
return false;
}
if (lnki_ext == Xof_ext_.Id_mid) { // NOTE: .mid does not have orig_media_type of "AUDIO"
chk_tid = Chk_tid_orig_media_type_is_audio;
return false;

View File

@ -88,6 +88,15 @@ public class Xob_xfer_temp_itm_tst {
);
fxt.Test_itm_chk_fail_id(Xob_xfer_temp_itm.Chk_tid_ns_is_media);
}
@Test public void Orig_width_is_0() {// PURPOSE: ignore files with an orig width of 0; note that ogg files that are sometimes flagged as VIDEO; EX:2009_10_08_Marc_Randazza_interview.ogg; DATE:2014-08-20
fxt.Test_bgn
( KeyVal_.new_(Xob_orig_regy_tbl.Fld_lnki_ttl , "A.ogg")
, KeyVal_.new_(Xob_orig_regy_tbl.Fld_orig_media_type , Xof_media_type.Name_video) // VIDEO
, KeyVal_.new_(Xob_orig_regy_tbl.Fld_orig_w , 0) // no width defined in image table
, KeyVal_.new_(Xob_orig_regy_tbl.Fld_orig_h , 0)
);
fxt.Test_itm_chk_fail_id(Xob_xfer_temp_itm.Chk_tid_orig_w_is_0);
}
}
class Xob_xfer_temp_itm_fxt {
private Xob_xfer_temp_itm itm = new Xob_xfer_temp_itm();

View File

@ -0,0 +1,46 @@
/*
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.bldrs.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
import gplx.gfui.*;
public class Xob_import_marker {
public static void Import_bgn(Xow_wiki wiki) {Io_mgr._.SaveFilStr(url_(wiki), "XOWA has created this file to indicate that an import is in progress. This file will be deleted once the import is completed.");}
public static void Import_end(Xow_wiki wiki) {Io_mgr._.DeleteFil_args(url_(wiki)).MissingFails_off().Exec();}
public static boolean Check(Xow_wiki wiki) {
Io_url url = url_(wiki);
if (!Io_mgr._.ExistsFil(url)) return true;
Xoa_app app = wiki.App();
app.Usr_dlg().Log_many("", "", "import.marker: marker found: url=~{0}", url.Raw());
int rslt = app.Gui_mgr().Kit().Ask_yes_no_cancel("", "", String_.Concat_lines_nl
( "~{0} was not completely imported."
, "Please choose one of the following:"
, ""
, "* Yes\t: Delete the wiki. You will need to reimport again."
, "* No\t: Delete the warning. XOWA will continue, but may run into unexpected issues."
, "* Cancel\t: Do nothing and continue. This message will show whenever you restart the app and reopen this wiki."
), wiki.Domain_str());
switch (rslt) {
case Gfui_dlg_msg_.Btn_yes: Xobc_core_cleanup.Delete_wiki_sql(wiki); Import_end(wiki); return false; // delete wiki
case Gfui_dlg_msg_.Btn_no: Import_end(wiki); return true; // delete marker
case Gfui_dlg_msg_.Btn_cancel: return true; // noop
default: throw Err_.unhandled(rslt);
}
}
private static Io_url url_(Xow_wiki wiki) {
return wiki.Fsys_mgr().Root_dir().GenSubFil(wiki.Domain_str() + "-import.lock");
}
}

View File

@ -23,6 +23,7 @@ public abstract class Xob_init_base implements Xob_cmd, GfoInvkAble {
public abstract void Cmd_ini_wdata(Xob_bldr bldr, Xow_wiki wiki);
public abstract void Cmd_run_end(Xow_wiki wiki);
public void Cmd_ini(Xob_bldr bldr) { // add other cmds; EX: wikidata
Xob_import_marker.Import_bgn(wiki);
if (wdata_enabled == Bool_.__byte) wdata_enabled = wiki.Domain_tid() == Xow_wiki_domain_.Tid_wikidata ? Bool_.Y_byte : Bool_.N_byte; // if wdata_enabled not explicitly set, set it to y if wiki is "www.wikidata.org"
if (wdata_enabled == Bool_.Y_byte) // if wdata_enabled, auto-add wdata_wkrs bldr
this.Cmd_ini_wdata(bldr, wiki);

View File

@ -28,9 +28,10 @@ public abstract class Xob_term_base implements Xob_cmd, GfoInvkAble {
Xoa_app app = wiki.App();
app.Gui_mgr().Html_mgr().Portal_mgr().Wikis().Itms_reset(); // NOTE: dirty wiki list so that next refresh will load itm
app.Free_mem(false); // clear cache, else import will load new page with old items from cache; DATE:2013-11-21
wiki.Props().Main_page_update(wiki);
Xob_import_marker.Import_end(wiki);
wiki.Init_needed_(true);// flag init_needed prior to show; dir_info will show page_txt instead of page_gz;
wiki.Init_assert(); // force load; needed to pick up MediaWiki ns for MediaWiki:mainpage
wiki.Props().Main_page_update(wiki);
Cmd_end_hook();
}
public abstract void Cmd_end_hook();

View File

@ -27,7 +27,7 @@ public class Xobc_core_cleanup extends Xob_itm_basic_base implements Xob_cmd {
public Xobc_core_cleanup Delete_sqlite3_(boolean v){delete_sqlite3 = v; return this;} private boolean delete_sqlite3;
public Xobc_core_cleanup Delete_xml_(boolean v) {delete_xml = v; return this;} private boolean delete_xml;
public Xobc_core_cleanup Delete_wiki_(boolean v) {delete_wiki = v; return this;} private boolean delete_wiki;
public void Bz2_fil_(Io_url v) {bz2_fil = v;} Io_url bz2_fil;
public void Bz2_fil_(Io_url v) {bz2_fil = v;} private Io_url bz2_fil;
public void Cmd_run() {
Io_url wiki_root_dir = wiki.Fsys_mgr().Root_dir();
if (bz2_fil != null) {
@ -39,20 +39,10 @@ public class Xobc_core_cleanup extends Xob_itm_basic_base implements Xob_cmd {
if (delete_xml) Io_mgr._.DeleteFil(Xobd_rdr.Find_fil_by(wiki_root_dir, "*.xml"));
if (delete_wiki) {
usr_dlg.Note_many("", "delete_wiki", "deleting wiki");
Io_url[] dirs = Io_mgr._.QueryDir_args(wiki_root_dir).DirOnly_().DirInclude_().ExecAsUrlAry();
int dirs_len = dirs.length;
for (int i = 0; i < dirs_len; i++)
Io_mgr._.DeleteDirDeep(dirs[i]);
}
if (delete_sqlite3) {
if (wiki.Db_mgr().Tid() == gplx.xowa.dbs.Xodb_mgr_sql.Tid_sql) // NOTE: must check; if empty dir (or text db) than db_mgr will be txt
wiki.Db_mgr_as_sql().Fsys_mgr().Rls(); // NOTE: if sqlite files, must rls;
Io_url[] sqlite3_files = Io_mgr._.QueryDir_args(wiki_root_dir).FilPath_("*.sqlite3").ExecAsUrlAry();
int sqlite3_files_len = sqlite3_files.length;
usr_dlg.Note_many("", "delete_wiki", "deleting sqlite3 files: ~{0} ~{1}", sqlite3_files_len, wiki_root_dir.Raw());
for (int i = 0; i < sqlite3_files_len; i++)
Io_mgr._.DeleteFil(sqlite3_files[i]);
Delete_wiki_txt(wiki_root_dir);
}
if (delete_sqlite3)
Delete_wiki_sql(wiki);
if (delete_all)
Io_mgr._.DeleteDirDeep(wiki_root_dir);
if (delete_by_match_ary != null)
@ -107,4 +97,20 @@ public class Xobc_core_cleanup extends Xob_itm_basic_base implements Xob_cmd {
}
}
}
private static void Delete_wiki_txt(Io_url wiki_root_dir) {
Io_url[] dirs = Io_mgr._.QueryDir_args(wiki_root_dir).DirOnly_().DirInclude_().ExecAsUrlAry();
int dirs_len = dirs.length;
for (int i = 0; i < dirs_len; i++)
Io_mgr._.DeleteDirDeep(dirs[i]);
}
public static void Delete_wiki_sql(Xow_wiki wiki) {
Gfo_usr_dlg usr_dlg = wiki.App().Usr_dlg(); Io_url wiki_root_dir = wiki.Fsys_mgr().Root_dir();
if (wiki.Db_mgr().Tid() == gplx.xowa.dbs.Xodb_mgr_sql.Tid_sql) // NOTE: must check; if empty dir (or text db) than db_mgr will be txt
wiki.Db_mgr_as_sql().Fsys_mgr().Rls(); // NOTE: if sqlite files, must rls;
Io_url[] sqlite3_files = Io_mgr._.QueryDir_args(wiki_root_dir).FilPath_("*.sqlite3").ExecAsUrlAry();
int sqlite3_files_len = sqlite3_files.length;
usr_dlg.Note_many("", "delete_wiki", "deleting sqlite3 files: ~{0} ~{1}", sqlite3_files_len, wiki_root_dir.Raw());
for (int i = 0; i < sqlite3_files_len; i++)
Io_mgr._.DeleteFil(sqlite3_files[i]);
}
}

View File

@ -0,0 +1,21 @@
/*
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.dbs; import gplx.*; import gplx.xowa.*;
public class Xodb_ctx {
public boolean Html_db_enabled() {return html_db_enabled;} public void Html_db_enabled_(boolean v) {html_db_enabled = v;} private boolean html_db_enabled;
}

View File

@ -128,7 +128,7 @@ public class Xodb_load_mgr_sql implements Xodb_load_mgr {
if (search_version == gplx.xowa.specials.search.Xosrh_core.Version_1)
db_mgr.Tbl_page().Select_by_search(cancelable, rv, search, results_max);
else {
Xodb_search_title_word_tbl.Select_by_word(cancelable, rv, search, results_max, db_mgr.Fsys_mgr().Get_tid_root(Xodb_file_tid.Tid_search).Provider());
Xodb_search_title_word_tbl.Select_by_word(cancelable, rv, db_mgr.Wiki(), search, results_max, db_mgr.Fsys_mgr().Get_tid_root(Xodb_file_tid.Tid_search).Provider());
db_mgr.Tbl_page().Select_by_id_list(cancelable, true, rv);
}
}
@ -166,7 +166,7 @@ public class Xodb_load_mgr_sql implements Xodb_load_mgr {
hash2.Add(page.Id_val(), page);
}
len = hash2.Count(); // must update len (!hash2.Has() may have skipped titles)
db_mgr.Tbl_category().Select_by_cat_id_in(Cancelable_.Never, hash2, fsys_mgr.Provider_ctg(), 0, len);
db_mgr.Tbl_category().Select_by_cat_id_in(Cancelable_.Never, hash2, fsys_mgr.Provider_ctg(), db_mgr.Wiki(), 0, len);
return (Xodb_page[])hash.XtoAry(Xodb_page.class);
}
}

View File

@ -66,7 +66,7 @@ class Xodb_load_mgr_sql_fxt {
DateAdp modified = DateAdp_.Now();
for (int i = 0; i < len; i++) {
Xodb_page page = ary[i];
db_mgr.Tbl_page().Insert(page_stmt, page.Id(), page.Ns_id(), page.Ttl_wo_ns(), false, modified, 10, page.Id(), 0);
db_mgr.Tbl_page().Insert(page_stmt, page.Id(), page.Ns_id(), page.Ttl_wo_ns(), false, modified, 10, page.Id(), 0, 0);
Xodb_category_itm ctg_itm = (Xodb_category_itm)page.Xtn();
db_mgr.Tbl_category().Insert(category_stmt, ctg_itm.Id(), ctg_itm.Count_pages(), ctg_itm.Count_subcs(), ctg_itm.Count_files(), Bool_.Xto_byte(ctg_itm.Hidden()), 0);
}

View File

@ -16,15 +16,16 @@ 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.dbs; import gplx.*; import gplx.xowa.*;
import gplx.dbs.*; import gplx.xowa.dbs.hdumps.*;
import gplx.dbs.*; import gplx.xowa.hdumps.*;
public interface Xodb_mgr extends GfoInvkAble, RlsAble {
byte Tid();
String Tid_name();
byte Data_storage_format(); void Data_storage_format_(byte v);
byte Category_version();
byte Search_version(); void Search_version_refresh();
Xodb_ctx Db_ctx();
DateAdp Dump_date_query();
Xodb_load_mgr Load_mgr();
Xodb_save_mgr Save_mgr();
Xodb_html_mgr Html_mgr();
Xodb_hdump_mgr Hdump_mgr();
}

View File

@ -17,14 +17,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.dbs; import gplx.*; import gplx.xowa.*;
import gplx.dbs.*;
import gplx.xowa.apps.*; import gplx.xowa.dbs.tbls.*; import gplx.xowa.ctgs.*; import gplx.xowa.dbs.hdumps.*;
import gplx.xowa.apps.*; import gplx.xowa.dbs.tbls.*; import gplx.xowa.ctgs.*; import gplx.xowa.hdumps.*;
public class Xodb_mgr_sql implements Xodb_mgr, GfoInvkAble {
private boolean html_db_enabled;
public Xodb_mgr_sql(Xow_wiki wiki) {
this.wiki = wiki;
fsys_mgr = new Xodb_fsys_mgr(wiki.App().Fsys_mgr().Bin_db_dir(), wiki.Fsys_mgr().Root_dir(), wiki.Domain_str());
load_mgr = new Xodb_load_mgr_sql(this, fsys_mgr);
save_mgr = new Xodb_save_mgr_sql(this);
tbl_text = new Xodb_text_tbl(this);
tbl_page = new Xodb_page_tbl(wiki);
hdump_mgr = new Xodb_hdump_mgr(wiki);
}
public byte Tid() {return Tid_sql;} public static final byte Tid_sql = 1;
public String Tid_name() {return "sqlite3";}
@ -33,14 +36,21 @@ public class Xodb_mgr_sql implements Xodb_mgr, GfoInvkAble {
public byte Category_version() {return category_version;} private byte category_version = Xoa_ctg_mgr.Version_null;
public byte Search_version() {return load_mgr.Search_version();}
public void Search_version_refresh() {load_mgr.Search_version_refresh();}
public void Html_db_enabled_(boolean v) {
html_db_enabled = v; db_ctx.Html_db_enabled_(v);
hdump_mgr.Enabled_(v);
tbl_page.Html_db_enabled_(v);
if (v) Xodb_hdump_mgr_setup.Hdump_db_file_init(hdump_mgr);
}
public Xodb_ctx Db_ctx() {return db_ctx;} private Xodb_ctx db_ctx = new Xodb_ctx();
public Xodb_fsys_mgr Fsys_mgr() {return fsys_mgr;} private Xodb_fsys_mgr fsys_mgr;
public Xodb_load_mgr Load_mgr() {return load_mgr;} private Xodb_load_mgr_sql load_mgr;
public Xodb_save_mgr Save_mgr() {return save_mgr;} private Xodb_save_mgr_sql save_mgr;
public Xodb_html_mgr Html_mgr() {return html_mgr;} private Xodb_html_mgr html_mgr = new Xodb_html_mgr();
public Xodb_hdump_mgr Hdump_mgr() {return hdump_mgr;} private Xodb_hdump_mgr hdump_mgr;
public Xodb_xowa_cfg_tbl Tbl_xowa_cfg() {return tbl_cfg;} private Xodb_xowa_cfg_tbl tbl_cfg = new Xodb_xowa_cfg_tbl();
public Xodb_xowa_ns_tbl Tbl_xowa_ns() {return tbl_ns;} private Xodb_xowa_ns_tbl tbl_ns = new Xodb_xowa_ns_tbl();
public Xodb_xowa_db_tbl Tbl_xowa_db() {return tbl_db;} private Xodb_xowa_db_tbl tbl_db = new Xodb_xowa_db_tbl();
public Xodb_page_tbl Tbl_page() {return tbl_page;} private Xodb_page_tbl tbl_page = new Xodb_page_tbl();
public Xodb_page_tbl Tbl_page() {return tbl_page;} private Xodb_page_tbl tbl_page;
public Xodb_text_tbl Tbl_text() {return tbl_text;} private Xodb_text_tbl tbl_text;
public Xodb_site_stats_tbl Tbl_site_stats() {return tbl_site_stats;} private Xodb_site_stats_tbl tbl_site_stats = new Xodb_site_stats_tbl();
public Xodb_wdata_qids_tbl Tbl_wdata_qids() {return tbl_wdata_qids;} private Xodb_wdata_qids_tbl tbl_wdata_qids = new Xodb_wdata_qids_tbl();
@ -78,7 +88,9 @@ public class Xodb_mgr_sql implements Xodb_mgr, GfoInvkAble {
tbl_site_stats.Provider_(provider);
}
public void Page_create(Db_stmt page_stmt, Db_stmt text_stmt, int page_id, int ns_id, byte[] ttl_wo_ns, boolean redirect, DateAdp modified_on, byte[] text, int random_int, int file_idx) {
tbl_page.Insert(page_stmt, page_id, ns_id, ttl_wo_ns, redirect, modified_on, text.length, random_int, file_idx);
int text_len = text.length;
int html_db_id = (html_db_enabled) ? -1 : hdump_mgr.Html_db_id_default(text_len);
tbl_page.Insert(page_stmt, page_id, ns_id, ttl_wo_ns, redirect, modified_on, text_len, random_int, file_idx, html_db_id);
tbl_text.Insert(text_stmt, page_id, text, data_storage_format);
}
public boolean Ctg_select_v1(Xoctg_view_ctg view_ctg, Db_provider ctg_provider, Xodb_category_itm ctg) {
@ -130,14 +142,14 @@ public class Xodb_mgr_sql implements Xodb_mgr, GfoInvkAble {
else if (ctx.Match(k, Invk_category_version_)) category_version = m.ReadByte("v");
else if (ctx.Match(k, Invk_search_version)) return this.Search_version();
else if (ctx.Match(k, Invk_tid_name)) return this.Tid_name();
else if (ctx.Match(k, Invk_html_mgr)) return html_mgr;
else if (ctx.Match(k, Invk_html_mgr)) return hdump_mgr;
return this;
}
public static final String
Invk_data_storage_format = "data_storage_format", Invk_data_storage_format_ = "data_storage_format_"
, Invk_category_version = "category_version", Invk_category_version_ = "category_version_"
, Invk_search_version = "search_version"
, Invk_tid_name = "tid_name", Invk_html_mgr = "html_mgr"
, Invk_tid_name = "tid_name", Invk_html_mgr = "hdump_mgr"
;
public void Category_version_update(boolean version_is_1) {
String grp = Xodb_mgr_sql.Grp_wiki_init;

View File

@ -16,19 +16,21 @@ 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.dbs; import gplx.*; import gplx.xowa.*;
import gplx.dbs.*; import gplx.xowa.ctgs.*; import gplx.xowa.dbs.hdumps.*;
import gplx.dbs.*; import gplx.xowa.ctgs.*; import gplx.xowa.hdumps.*;
public class Xodb_mgr_txt implements Xodb_mgr {
public Xodb_mgr_txt(Xow_wiki wiki, Xow_data_mgr data_mgr) {
this.wiki = wiki;
load_mgr = new Xodb_load_mgr_txt(wiki);
save_mgr = new Xodb_save_mgr_txt(wiki, load_mgr);
hdump_mgr = new Xodb_hdump_mgr(wiki);
} private Xow_wiki wiki;
public byte Tid() {return Tid_txt;} public static final byte Tid_txt = 0;
public String Tid_name() {return "xdat";}
public byte Data_storage_format() {return data_storage_format;} public void Data_storage_format_(byte v) {data_storage_format = v;} private byte data_storage_format = gplx.ios.Io_stream_.Tid_file;
public Xodb_load_mgr Load_mgr() {return load_mgr;} private Xodb_load_mgr_txt load_mgr;
public Xodb_save_mgr Save_mgr() {return save_mgr;} private Xodb_save_mgr_txt save_mgr;
public Xodb_html_mgr Html_mgr() {return html_mgr;} private Xodb_html_mgr html_mgr = new Xodb_html_mgr();
public Xodb_hdump_mgr Hdump_mgr() {return hdump_mgr;} private Xodb_hdump_mgr hdump_mgr;
public Xodb_ctx Db_ctx() {return db_ctx;} private Xodb_ctx db_ctx = new Xodb_ctx();
public DateAdp Dump_date_query() {
Io_url url = wiki.Fsys_mgr().Url_ns_fil(Xow_dir_info_.Tid_page, Xow_ns_.Id_main, 0);
return Io_mgr._.QueryFil(url).ModifiedTime();

View File

@ -1,85 +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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
import org.junit.*; import gplx.dbs.*; import gplx.xowa.files.*;
public class Hdump_mgr__save_tst {
@Before public void init() {fxt.Clear();} private Hdump_mgr__save_fxt fxt = new Hdump_mgr__save_fxt();
@Test public void Body() {
fxt.Test_save("abc", fxt.Make_itm_body("abc"));
}
@Test public void Img() {
fxt.Test_save("a[[File:A.png|test_caption]]b"
, fxt.Make_itm_body("a<a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"test_caption\"~<img|0> /></a>b")
, fxt.Make_itm_img(0, 0, 0, "A.png", "orig/7/0/A.png")
);
}
@Test public void Display_title() {
fxt.Test_save("{{DISPLAYTITLE:A}}bcd", fxt.Make_itm_body("bcd"), fxt.Make_itm_display_title("A"));
}
@Test public void Content_sub() {
fxt.Test_save("{{#isin:A}}bcd", fxt.Make_itm_body("bcd"), fxt.Make_itm_content_sub("<a href=\"/wiki/A\">A</a>"));
}
@Test public void Sidebar_div() {
fxt.Test_save("{{#related:A}}bcd", fxt.Make_itm_body("bcd"), fxt.Make_itm_sidebar_div(String_.Concat_lines_nl_skip_last
( "<div class=\"portal\" role=\"navigation\" id=\"p-relatedarticles\">"
, " <h3></h3>"
, " <div class=\"body\">"
, " <ul>"
, " <li class=\"interwiki-relart\"><a href=\"/wiki/A\">A</a></li>"
, " </ul>"
, " </div>"
, "</div>"
)));
}
}
class Hdump_mgr__save_fxt extends Hdump_mgr__base_fxt {
private int page_id = 0;
private ListAdp text_itms = ListAdp_.new_();
@Override public void Clear_end() {
db_mgr.Mode_mem_();
db_mgr.Text_tbl().Provider_(Hdump_text_tbl_mem.Null_provider);
}
public Hdump_text_row Make_itm_body(String v) {return new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_body, 0, 0, Bry_.new_utf8_(v));}
public Hdump_text_row Make_itm_img(int uid, int img_w, int img_h, String lnki_ttl, String img_src_rel) {return new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_img, 0, 0, Hdump_text_row.data_img_(bfr, uid, img_w, img_h, Bry_.new_utf8_(lnki_ttl), Bry_.new_utf8_(img_src_rel)));}
public Hdump_text_row Make_itm_display_title(String v) {return new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_display_ttl, 0, 0, Bry_.new_utf8_(v));}
public Hdump_text_row Make_itm_content_sub(String v) {return new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_content_sub, 0, 0, Bry_.new_utf8_(v));}
public Hdump_text_row Make_itm_sidebar_div(String v) {return new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_sidebar_div, 0, 0, Bry_.new_utf8_(v));}
public void Test_save(String raw, Hdump_text_row... expd) {
this.Exec_write(raw);
hdump_mgr.Save_mgr().Update(page);
db_mgr.Text_tbl().Select_by_page(text_itms, 0);
Hdump_text_row[] actl = (Hdump_text_row[])text_itms.XtoAryAndClear(Hdump_text_row.class);
Tfds.Eq_ary_str(Xto_str_ary(expd), Xto_str_ary(actl));
}
private static String[] Xto_str_ary(Hdump_text_row[] ary) {
int len = ary.length;
String[] rv = new String[len];
Bry_bfr bfr = Bry_bfr.new_();
for (int i = 0; i < len; ++i) {
Hdump_text_row itm = ary[i];
bfr .Add_int_variable(itm.Page_id())
.Add_byte_pipe().Add_int_variable(itm.Tid())
.Add_byte_pipe().Add_int_variable(itm.Idx())
.Add_byte_pipe().Add_int_variable(itm.Version_id())
.Add_byte_pipe().Add(itm.Data())
;
rv[i] = bfr.XtoStrAndClear();
}
return rv;
}
}

View File

@ -1,60 +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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
import gplx.dbs.*;
import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.saves.*; import gplx.xowa.pages.*;
import gplx.xowa.html.*; import gplx.xowa.gui.*;
public class Xodb_html_mgr implements GfoInvkAble {
private Xodb_file hdump_db_file;
public Xodb_html_mgr() {
save_mgr = db_mgr.Save_mgr();
}
public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled;
public Hdump_db_mgr Db_mgr() {return db_mgr;} private Hdump_db_mgr db_mgr = new Hdump_db_mgr();
@gplx.Internal protected Hdump_save_mgr Save_mgr() {return save_mgr;} private Hdump_save_mgr save_mgr;
public void Write(Bry_bfr bfr, Xow_wiki wiki, Xoa_page page) {
page.File_queue().Clear(); // need to reset uid to 0;
Xoh_page_wtr_wkr wkr = wiki.Html_mgr().Page_wtr_mgr().Wkr(Xopg_view_mode.Tid_read);
wkr.Write_body(bfr, Xoh_wtr_ctx.Hdump, page);
page.Hdump_data().Body_(bfr.XtoAryAndClear());
}
public void Save(Xoa_page page) {
if (!enabled) return;
if (hdump_db_file == null) hdump_db_file = Hdump_db_file_init(this, page);
Xow_wiki wiki = page.Wiki();
Bry_bfr tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_m001();
this.Write(tmp_bfr, wiki, page);
save_mgr.Update(page);
tmp_bfr.Mkr_rls();
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_enabled)) return Yn.Xto_str(enabled);
else if (ctx.Match(k, Invk_enabled_)) enabled = m.ReadYn("v");
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static Xodb_file Hdump_db_file_init(Xodb_html_mgr html_mgr, Xoa_page page) {
Xow_wiki wiki = page.Wiki();
Xodb_mgr_sql db_mgr_as_sql = wiki.Db_mgr_as_sql();
Xodb_file rv = db_mgr_as_sql.Fsys_mgr().Get_tid_root(Xodb_file_tid.Tid_html);
if (rv == null) rv = Hdump_db_mgr_setup.Setup(db_mgr_as_sql);
html_mgr.Db_mgr().Text_tbl().Provider_(rv.Provider());
return rv;
}
private static final String Invk_enabled = "enabled", Invk_enabled_ = "enabled_";
}

View File

@ -1,94 +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.dbs.hdumps.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
import gplx.core.btries.*; import gplx.xowa.html.*; import gplx.xowa.html.lnkis.*;
public class Hdump_html_fmtr__body implements Bry_fmtr_arg {
private Bry_rdr bry_rdr = new Bry_rdr();
private Xow_wiki wiki; private Hdump_page_itm page;
private Gfo_usr_dlg usr_dlg; private byte[] file_dir;
public void Init_by_app(Gfo_usr_dlg usr_dlg, byte [] file_dir) {this.usr_dlg = usr_dlg; this.file_dir = file_dir;}
public void Init_by_page(Xow_wiki wiki, Hdump_page_itm page) {this.wiki = wiki; this.page = page;}
public void XferAry(Bry_bfr bfr, int idx) {
byte[] src = page.Page_body(); int len = src.length;
Hdump_img_itm[] imgs = page.Img_itms(); int imgs_len = page.Img_itms().length;
bry_rdr.Src_(src);
int pos = 0; int rng_bgn = -1;
Xow_html_mgr html_mgr = wiki.Html_mgr();
Xoh_file_html_fmtr__base html_fmtr = html_mgr.Html_wtr().Lnki_wtr().File_wtr().File_wtr().Html_fmtr();
while (pos < len) {
byte b = src[pos];
Object o = trie.Match_bgn_w_byte(b, src, pos, len);
if (o == null) {
if (rng_bgn == -1) rng_bgn = pos;
++pos;
}
else {
if (rng_bgn != -1) {
bfr.Add_mid(src, rng_bgn, pos);
rng_bgn = -1;
}
byte tid = ((Byte_obj_val)o).Val();
pos = trie.Match_pos(); // position after match; EX: "~{xo.img." positions after "."
pos = Write_img(bfr, html_mgr, html_fmtr, page, src, imgs, imgs_len, pos, tid); // note no +1; Write_img return pos after }
}
}
if (rng_bgn != -1) bfr.Add_mid(src, rng_bgn, len);
}
private int Write_img(Bry_bfr bfr, Xow_html_mgr html_mgr, Xoh_file_html_fmtr__base fmtr, Hdump_page_itm page, byte[] src, Hdump_img_itm[] imgs, int imgs_len, int uid_bgn, byte tid) {
bry_rdr.Pos_(uid_bgn);
int uid = bry_rdr.Read_int_to(Byte_ascii.Gt);
int uid_end = bry_rdr.Pos(); // note that uid_end is set to pos after }
if (uid == bry_rdr.Or_int()) {usr_dlg.Warn_many("", "", "index is not a valid int; page=~{0} text=~{1}", page.Page_url(), Bry_.Mid_safe(src, uid_bgn, uid_end)); return uid_end;}
if (!Int_.Between(uid, 0, imgs_len)) {usr_dlg.Warn_many("", "", "index is out of range; page=~{0} idx=~{1} len=~{2}", page.Page_url(), uid, imgs_len); return uid_end;}
Hdump_img_itm img = imgs[uid];
int img_view_w = img.View_w();
if (tid == Tid_img_w) {
bfr.Add_int_variable(img_view_w);
return uid_end;
}
byte[] a_title = img.Lnki_ttl();
byte[] a_href = Bry_.Add(A_href_bgn, a_title);
switch (tid) {
case Tid_mda_info: fmtr.Html_thumb_part_info (bfr, uid, a_href, html_mgr.Img_media_info_btn()); return uid_end;
case Tid_mda_mgnf: fmtr.Html_thumb_part_magnify (bfr, uid, a_href, a_title, html_mgr.Img_thumb_magnify()); return uid_end;
case Tid_mda_play: fmtr.Html_thumb_part_play (bfr, uid, img_view_w, Xoh_file_wtr__basic.Play_btn_max_width, a_href, a_title, html_mgr.Img_media_play_btn()); return uid_end;
}
byte[] img_src = Bry_.Add(file_dir, img.View_src());
if (tid == Tid_img) {
fmtr_img.Bld_bfr_many(bfr, img_src, img_view_w, img.View_h());
}
return uid_end;
}
private static final Bry_fmtr fmtr_img = Bry_fmtr.new_(" src='~{src}' width='~{w}' height='~{h}'", "src", "w", "h");
private static final byte[] A_href_bgn = Bry_.new_ascii_("/wiki/File:");
public static final byte[]
Key_img = Bry_.new_ascii_("~<img|")
, Key_img_w = Bry_.new_ascii_("~<img.w|")
, Key_mda_play = Bry_.new_ascii_("~<mda.play|")
, Key_mda_info = Bry_.new_ascii_("~<mda.info|")
, Key_mda_mgnf = Bry_.new_ascii_("~<mda.mgnf|")
;
private static final byte Tid_img = 1, Tid_img_w = 2, Tid_mda_play = 3, Tid_mda_info = 4, Tid_mda_mgnf = 5;
private Btrie_slim_mgr trie = Btrie_slim_mgr.cs_()
.Add_bry_bval(Key_img , Tid_img)
.Add_bry_bval(Key_img_w , Tid_img_w)
.Add_bry_bval(Key_mda_play , Tid_mda_play)
.Add_bry_bval(Key_mda_info , Tid_mda_info)
.Add_bry_bval(Key_mda_mgnf , Tid_mda_mgnf)
;
}

View File

@ -57,10 +57,10 @@ public class Xodb_category_tbl {
} finally {stmt.Rls(); rdr.Rls();}
return Xodb_category_itm.Null;
}
public void Select_by_cat_id_in(Cancelable cancelable, OrderedHash rv, Db_provider p, int bgn, int end) {
public void Select_by_cat_id_in(Cancelable cancelable, OrderedHash rv, Db_provider p, Xow_wiki wiki, int bgn, int end) {
Xodb_in_wkr_category_id wkr = new Xodb_in_wkr_category_id();
wkr.Init(rv);
wkr.Select_in(p, cancelable, bgn, end);
wkr.Select_in(p, cancelable, wiki, bgn, end);
}
public static Xodb_category_itm Read_ctg(DataRdr rdr) {
return Xodb_category_itm.load_

View File

@ -20,20 +20,21 @@ import gplx.dbs.*;
public abstract class Xodb_in_wkr_base {
public abstract int Interval();
public abstract void Fill_stmt(Db_stmt stmt, int bgn, int end);
public abstract Db_qry Build_qry(int bgn, int end);
public abstract void Eval_rslts(Cancelable cancelable, DataRdr rdr);
public void Select_in(Db_provider provider, Cancelable cancelable, int full_bgn, int full_end) {
public abstract Db_qry Build_qry(Xodb_ctx tbl_ctx, int bgn, int end);
public abstract void Eval_rslts(Cancelable cancelable, Xow_wiki wiki, DataRdr rdr);
public void Select_in(Db_provider provider, Cancelable cancelable, Xow_wiki wiki, int full_bgn, int full_end) {
DataRdr rdr = DataRdr_.Null;
Db_stmt stmt = Db_stmt_.Null;
int interval = Interval();
Xodb_ctx db_ctx = wiki.Db_mgr().Db_ctx();
for (int i = full_bgn; i < full_end; i += interval) {
int part_end = i + interval;
if (part_end > full_end) part_end = full_end;
try {
stmt = provider.Prepare(Build_qry(i, part_end));
stmt = provider.Prepare(Build_qry(db_ctx, i, part_end));
Fill_stmt(stmt, i, part_end);
rdr = stmt.Exec_select();
Eval_rslts(cancelable, rdr);
Eval_rslts(cancelable, wiki, rdr);
}
finally {rdr.Rls(); stmt.Rls();}
}

View File

@ -0,0 +1,145 @@
/*
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.dbs.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
import gplx.dbs.*; import gplx.criterias.*;
class Xodb_in_wkr_page_id extends Xodb_in_wkr_page_base {
private ListAdp list; // list is original list of ids which may have dupes; needed to fill statement (which takes range of bgn - end); DATE:2013-12-08
private OrderedHash hash; // hash is unique list of ids; needed for fetch from rdr (which indexes by id)
public void Init(ListAdp list, OrderedHash hash) {this.list = list; this.hash = hash; this.Fill_idx_fields_only_(true);}
@Override public int Interval() {return 990;}
@Override public String In_fld_name() {return Xodb_page_tbl.Fld_page_id;}
@Override public Criteria In_filter(Object[] part_ary) {
return Db_crt_.in_(this.In_fld_name(), part_ary);
}
@Override public void Fill_stmt(Db_stmt stmt, int bgn, int end) {
for (int i = bgn; i < end; i++) {
Xodb_page page = (Xodb_page)list.FetchAt(i);
stmt.Val_int_(page.Id());
}
}
@Override public Xodb_page Eval_rslts_key(Xodb_page rdr_page) {return (Xodb_page)hash.Fetch(rdr_page.Id_val());}
}
class Xodb_in_wkr_page_title extends Xodb_in_wkr_page_base {
private OrderedHash hash;
private int in_ns;
@Override public int Interval() {return 64;} // NOTE: 96+ overflows; EX: w:Space_Liability_Convention; DATE:2013-10-24
public void Init(OrderedHash hash, int in_ns) {this.hash = hash; this.in_ns = in_ns;}
@Override public String In_fld_name() {return Xodb_page_tbl.Fld_page_title;}
@Override public Criteria In_filter(Object[] part_ary) {
int len = part_ary.length;
Criteria[] crt_ary = new Criteria[len];
for (int i = 0; i < len; i++)
crt_ary[i] = Criteria_.And(Db_crt_.eq_(Xodb_page_tbl.Fld_page_ns, in_ns), Db_crt_.eq_(Xodb_page_tbl.Fld_page_title, Bry_.Empty));
return Criteria_.Or_many(crt_ary);
}
@Override public void Fill_stmt(Db_stmt stmt, int bgn, int end) {
for (int i = bgn; i < end; i++) {
Xodb_page page = (Xodb_page)hash.FetchAt(i);
stmt.Val_int_(in_ns);
stmt.Val_str_by_bry_(page.Ttl_wo_ns());
}
}
@Override public Xodb_page Eval_rslts_key(Xodb_page rdr_page) {return (Xodb_page)hash.Fetch(rdr_page.Ttl_wo_ns());}
}
class Xodb_in_wkr_page_title_ns extends Xodb_in_wkr_page_base {
private Xow_wiki wiki;
private OrderedHash hash;
@Override public int Interval() {return 64;} // NOTE: 96+ overflows; EX: w:Space_Liability_Convention; DATE:2013-10-24
public void Init(Xow_wiki wiki, OrderedHash hash) {this.wiki = wiki; this.hash = hash;}
@Override public String In_fld_name() {return Xodb_page_tbl.Fld_page_title;}
@Override public Criteria In_filter(Object[] part_ary) {
int len = part_ary.length;
Criteria[] crt_ary = new Criteria[len];
for (int i = 0; i < len; i++)
crt_ary[i] = Criteria_.And(Db_crt_.eq_(Xodb_page_tbl.Fld_page_ns, 0), Db_crt_.eq_(Xodb_page_tbl.Fld_page_title, Bry_.Empty));
return Criteria_.Or_many(crt_ary);
}
@Override public void Fill_stmt(Db_stmt stmt, int bgn, int end) {
for (int i = bgn; i < end; i++) {
Xodb_page page = (Xodb_page)hash.FetchAt(i);
stmt.Val_int_(page.Ns_id());
stmt.Val_str_by_bry_(page.Ttl_wo_ns());
}
}
@Override public Xodb_page Eval_rslts_key(Xodb_page rdr_page) {
Xow_ns ns = wiki.Ns_mgr().Ids_get_or_null(rdr_page.Ns_id());
if (ns == null) return null; // NOTE: ns seems to "randomly" be null when threading during redlinks; guard against null; DATE:2014-01-03
byte[] ttl_wo_ns = rdr_page.Ttl_wo_ns();
rdr_page.Ttl_(ns, ttl_wo_ns);
return (Xodb_page)hash.Fetch(rdr_page.Ttl_w_ns());
}
}
abstract class Xodb_in_wkr_page_base extends Xodb_in_wkr_base {
public String Tbl_name() {return Xodb_page_tbl.Tbl_name;}
public abstract String In_fld_name();
public abstract Criteria In_filter(Object[] part_ary);
public abstract Xodb_page Eval_rslts_key(Xodb_page rdr_page);
public boolean Fill_idx_fields_only() {return fill_idx_fields_only;} public Xodb_in_wkr_page_base Fill_idx_fields_only_(boolean v) {fill_idx_fields_only = v; return this;} private boolean fill_idx_fields_only;
@Override public Db_qry Build_qry(Xodb_ctx db_ctx, int bgn, int end) {
Object[] part_ary = Xodb_in_wkr_base.In_ary(end - bgn);
return Db_qry_.select_cols_
( this.Tbl_name()
, In_filter(part_ary)
, fill_idx_fields_only ? Xodb_page_tbl.Flds_select_idx : db_ctx.Html_db_enabled() ? Xodb_page_tbl.Flds_select_all__html_y : Xodb_page_tbl.Flds_select_all__html_n
)
;
}
@Override public void Eval_rslts(Cancelable cancelable, Xow_wiki wiki, DataRdr rdr) {
Xodb_page temp = new Xodb_page();
boolean html_db_enabled = wiki.Db_mgr().Hdump_mgr().Enabled();
while (rdr.MoveNextPeer()) {
if (cancelable.Canceled()) return;
if (fill_idx_fields_only)
Xodb_page_tbl.Read_page__idx(temp, rdr);
else
Xodb_page_tbl.Read_page__all(temp, rdr, html_db_enabled);
Xodb_page page = Eval_rslts_key(temp);
if (page == null) continue; // page not found
temp.Exists_(true);
page.Copy(temp);
}
}
}
class Xodb_in_wkr_category_id extends Xodb_in_wkr_base {
private OrderedHash hash;
@Override public int Interval() {return 990;}
public void Init(OrderedHash hash) {this.hash = hash;}
@Override public Db_qry Build_qry(Xodb_ctx db_ctx, int bgn, int end) {
Object[] part_ary = Xodb_in_wkr_base.In_ary(end - bgn);
String in_fld_name = Xodb_category_tbl.Fld_cat_id;
return Db_qry_.select_cols_
( Xodb_category_tbl.Tbl_name
, Db_crt_.in_(in_fld_name, part_ary)
)
;
}
@Override public void Fill_stmt(Db_stmt stmt, int bgn, int end) {
for (int i = bgn; i < end; i++) {
Xodb_page page = (Xodb_page)hash.FetchAt(i);
stmt.Val_int_(page.Id());
}
}
@Override public void Eval_rslts(Cancelable cancelable, Xow_wiki wiki, DataRdr rdr) {
while (rdr.MoveNextPeer()) {
if (cancelable.Canceled()) return;
Xodb_category_itm ctg_data = Xodb_category_tbl.Read_ctg(rdr);
Xodb_page page = (Xodb_page)hash.Fetch(ctg_data.Id_val());
page.Xtn_(ctg_data);
}
}
}

View File

@ -18,10 +18,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.dbs.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
import gplx.dbs.*; import gplx.criterias.*;
public class Xodb_page_tbl {
private Xow_wiki wiki;
public Xodb_page_tbl(Xow_wiki wiki) {this.wiki = wiki;}
public void Html_db_enabled_(boolean v) {html_db_enabled = v;} private boolean html_db_enabled;
public Db_provider Provider() {return provider;} public void Provider_(Db_provider provider) {this.provider = provider;} private Db_provider provider;
public void Delete_all() {provider.Exec_qry(Db_qry_.delete_tbl_(Tbl_name));}
public Db_stmt Insert_stmt(Db_provider p) {return Db_stmt_.new_insert_(p, Tbl_name, Fld_page_id, Fld_page_ns, Fld_page_title, Fld_page_is_redirect, Fld_page_touched, Fld_page_len, Fld_page_random_int, Fld_page_file_idx);}
public void Insert(Db_stmt stmt, int page_id, int ns_id, byte[] ttl_wo_ns, boolean redirect, DateAdp modified_on, int page_len, int random_int, int file_idx) {
public Db_stmt Insert_stmt(Db_provider p) {
return Db_stmt_.new_insert_(p, Tbl_name, html_db_enabled ? Flds_insert__html_y : Flds_insert__html_n);
}
public void Insert(Db_stmt stmt, int page_id, int ns_id, byte[] ttl_wo_ns, boolean redirect, DateAdp modified_on, int page_len, int random_int, int file_idx, int html_db_id) {
stmt.Clear()
.Val_int_(page_id)
.Val_int_(ns_id)
@ -30,8 +35,10 @@ public class Xodb_page_tbl {
.Val_str_(Xto_touched_str(modified_on))
.Val_int_(page_len)
.Val_int_(random_int)
.Val_int_(file_idx)
.Exec_insert();
.Val_int_(file_idx);
if (html_db_enabled)
stmt.Val_int_(html_db_id);
stmt.Exec_insert();
}
public int Select_id(int ns_id, byte[] ttl) {
DataRdr rdr = DataRdr_.Null;
@ -61,33 +68,18 @@ public class Xodb_page_tbl {
.Val_int_(page_id)
.Exec_select();
while (rdr.MoveNextPeer()) {
Read_page(rv, rdr);
Read_page__all(rv, rdr, html_db_enabled);
return true;
}
} finally {rdr.Rls(); stmt.Rls();}
return false;
}
public static void Read_page(Xodb_page page, DataRdr rdr) {
page.Id_ (rdr.ReadInt(Fld_page_id));
page.Ns_id_ (rdr.ReadInt(Fld_page_ns));
page.Ttl_wo_ns_ (rdr.ReadBryByStr(Fld_page_title));
page.Modified_on_ (DateAdp_.parse_fmt(rdr.ReadStr(Fld_page_touched), Page_touched_fmt));
page.Type_redirect_ (rdr.ReadByte(Fld_page_is_redirect) == 1);
page.Text_len_ (rdr.ReadInt(Fld_page_len));
page.Db_file_idx_ (rdr.ReadInt(Fld_page_file_idx));
}
public static void Read_page_for_search_suggest(Xodb_page page, DataRdr rdr) {
page.Id_ (rdr.ReadInt(Fld_page_id));
page.Ns_id_ (rdr.ReadInt(Fld_page_ns));
page.Ttl_wo_ns_ (rdr.ReadBryByStr(Fld_page_title));
page.Text_len_ (rdr.ReadInt(Fld_page_len));
}
private DataRdr Load_ttls_starting_with_rdr(int ns_id, byte[] ttl_frag, boolean include_redirects, int max_results, int min_page_len, int browse_len, boolean fwd, boolean search_suggest) {
Criteria crt_ttl = fwd ? Db_crt_.mte_(Fld_page_title, String_.new_utf8_(ttl_frag)) : Db_crt_.lt_(Fld_page_title, String_.new_utf8_(ttl_frag));
Criteria crt = Criteria_.And_many(Db_crt_.eq_(Fld_page_ns, ns_id), crt_ttl, Db_crt_.mte_(Fld_page_len, min_page_len));
if (!include_redirects)
crt = Criteria_.And(crt, Db_crt_.eq_(Fld_page_is_redirect, Byte_.Zero));
String[] cols = search_suggest ? Flds_ary_search_suggest : Flds_ary_all;
String[] cols = search_suggest ? Flds_select_idx : html_db_enabled ? Flds_select_all__html_y : Flds_select_all__html_n;
int limit = fwd ? max_results + 1 : max_results; // + 1 to get next item
Db_qry_select select = Db_qry_.select_cols_(Tbl_name, crt, cols).Limit_(limit).OrderBy_(Fld_page_title, fwd);
return select.Exec_qry_as_rdr(provider);
@ -102,7 +94,7 @@ public class Xodb_page_tbl {
while (rdr.MoveNextPeer()) {
if (cancelable.Canceled()) return;
Xodb_page page = new Xodb_page();
Read_page_for_search_suggest(page, rdr);
Read_page__idx(page, rdr);
if (max_val_check && !Bry_.HasAtBgn(page.Ttl_wo_ns(), key)) break;
nxt_itm = page;
if (rslt_idx == max_results) {} // last item which is not meant for rslts, but only for nxt itm
@ -119,7 +111,7 @@ public class Xodb_page_tbl {
Xodb_page prv_itm = new Xodb_page();
boolean found = false;
while (rdr.MoveNextPeer()) {
Read_page(prv_itm, rdr);
Read_page__all(prv_itm, rdr, html_db_enabled);
found = true;
}
if (found)
@ -143,7 +135,7 @@ public class Xodb_page_tbl {
while (rdr.MoveNextPeer()) {
if (cancelable.Canceled()) return;
Xodb_page page = new Xodb_page();
Read_page_for_search_suggest(page, rdr);
Read_page__idx(page, rdr);
rslt_list.Add(page);
}
rslt_list.SortBy(Xodb_page_sorter.TitleAsc);
@ -164,7 +156,7 @@ public class Xodb_page_tbl {
}
Xodb_in_wkr_page_id wkr = new Xodb_in_wkr_page_id();
wkr.Init(rv, hash);
wkr.Select_in(provider, cancelable, bgn, end);
wkr.Select_in(provider, cancelable, wiki, bgn, end);
return true;
}
public boolean Select_by_ttl(Xodb_page rv, Xow_ns ns, byte[] ttl) {
@ -177,7 +169,7 @@ public class Xodb_page_tbl {
.Val_str_(String_.new_utf8_(ttl))
.Exec_select();
if (rdr.MoveNextPeer()) {
Read_page(rv, rdr);
Read_page__all(rv, rdr, html_db_enabled);
return true;
}
} finally {rdr.Rls(); stmt.Rls();}
@ -231,7 +223,7 @@ public class Xodb_page_tbl {
Criteria crt = gplx.criterias.Criteria_.And_many(Db_crt_.eq_(Fld_page_ns, -1), Db_crt_.mt_(Fld_page_title, ""));
if (redirect != Bool_.__byte)
crt = gplx.criterias.Criteria_.And(crt, Db_crt_.eq_(Fld_page_is_redirect, redirect));
Db_qry_select qry = Db_qry_.select_().From_(Tbl_name).Cols_(Flds_all)
Db_qry_select qry = Db_qry_.select_().From_(Tbl_name).Cols_(html_db_enabled ? Flds_select_all__html_y : Flds_select_all__html_n)
.Where_(crt)
.Limit_(limit);
return p.Prepare(qry);
@ -246,7 +238,7 @@ public class Xodb_page_tbl {
while (rdr.MoveNextPeer()) {
if (cancelable.Canceled()) return;
Xodb_page page = new Xodb_page();
Read_page(page, rdr);
Read_page__all(page, rdr, html_db_enabled);
rv.Add(page.Id_val(), page);
}
} finally {rdr.Rls();}
@ -255,159 +247,46 @@ public class Xodb_page_tbl {
Xodb_in_wkr_page_title_ns wkr = new Xodb_in_wkr_page_title_ns();
wkr.Fill_idx_fields_only_(fill_idx_fields_only);
wkr.Init(wiki, rv);
wkr.Select_in(provider, cancelable, bgn, end);
wkr.Select_in(provider, cancelable, wiki, bgn, end);
}
public void Select_by_ttl_in(Cancelable cancelable, OrderedHash rv, int ns_id, int bgn, int end) {
Xodb_in_wkr_page_title wkr = new Xodb_in_wkr_page_title();
wkr.Init(rv, ns_id);
wkr.Select_in(provider, cancelable, bgn, end);
wkr.Select_in(provider, cancelable, wiki, bgn, end);
}
public void Update_html_db_id(int page_id, int html_db_id) {
if (!html_db_enabled) throw Err_.new_("html_db not enabled");
Db_stmt stmt = Db_stmt_.new_update_(provider, Tbl_name, String_.Ary(Fld_page_id), Fld_page_html_db_id);
stmt.Val_int_(html_db_id).Val_int_(page_id).Exec_update();
}
private static final String Page_touched_fmt = "yyyyMMddHHmmss";
private static String Xto_touched_str(DateAdp v) {return v.XtoStr_fmt(Page_touched_fmt);}
public static final String Tbl_name = "page", Fld_page_id = "page_id", Fld_page_ns = "page_namespace", Fld_page_title = "page_title", Fld_page_is_redirect = "page_is_redirect", Fld_page_touched = "page_touched", Fld_page_len = "page_len", Fld_page_random_int = "page_random_int", Fld_page_file_idx = "page_file_idx";
private static final String[] Flds_all = new String[] {Fld_page_id, Fld_page_ns, Fld_page_title, Fld_page_touched, Fld_page_is_redirect, Fld_page_len, Fld_page_file_idx};
public static String[] Flds_ary_all = String_.Ary(Flds_all), Flds_ary_search_suggest = String_.Ary(Fld_page_id, Fld_page_ns, Fld_page_title, Fld_page_len);
public static final String Tbl_name = "page"
, Fld_page_id = "page_id", Fld_page_ns = "page_namespace", Fld_page_title = "page_title", Fld_page_is_redirect = "page_is_redirect", Fld_page_touched = "page_touched", Fld_page_len = "page_len"
, Fld_page_random_int = "page_random_int", Fld_page_file_idx = "page_file_idx", Fld_page_html_db_id = "page_html_db_id";
public static final String[]
Flds_insert__html_n = String_.Ary(Fld_page_id, Fld_page_ns, Fld_page_title, Fld_page_is_redirect, Fld_page_touched, Fld_page_len, Fld_page_random_int, Fld_page_file_idx)
, Flds_insert__html_y = String_.Ary(Fld_page_id, Fld_page_ns, Fld_page_title, Fld_page_is_redirect, Fld_page_touched, Fld_page_len, Fld_page_random_int, Fld_page_file_idx, Fld_page_html_db_id)
, Flds_select_all__html_n = String_.Ary(Fld_page_id, Fld_page_ns, Fld_page_title, Fld_page_touched, Fld_page_is_redirect, Fld_page_len, Fld_page_file_idx)
, Flds_select_all__html_y = String_.Ary(Fld_page_id, Fld_page_ns, Fld_page_title, Fld_page_touched, Fld_page_is_redirect, Fld_page_len, Fld_page_file_idx, Fld_page_html_db_id)
, Flds_select_idx = String_.Ary(Fld_page_id, Fld_page_ns, Fld_page_title, Fld_page_len)
;
public static final boolean Load_idx_flds_only_y = true;
public static void Read_page__all(Xodb_page page, DataRdr rdr, boolean html_db_enabled) {
page.Id_ (rdr.ReadInt(Fld_page_id));
page.Ns_id_ (rdr.ReadInt(Fld_page_ns));
page.Ttl_wo_ns_ (rdr.ReadBryByStr(Fld_page_title));
page.Modified_on_ (DateAdp_.parse_fmt(rdr.ReadStr(Fld_page_touched), Page_touched_fmt));
page.Type_redirect_ (rdr.ReadByte(Fld_page_is_redirect) == 1);
page.Text_len_ (rdr.ReadInt(Fld_page_len));
page.Db_file_idx_ (rdr.ReadInt(Fld_page_file_idx));
if (html_db_enabled)
page.Html_db_id_(rdr.ReadInt(Fld_page_html_db_id));
}
class Xodb_in_wkr_page_id extends Xodb_in_wkr_page_base {
private ListAdp list; // list is original list of ids which may have dupes; needed to fill statement (which takes range of bgn - end); DATE:2013-12-08
private OrderedHash hash; // hash is unique list of ids; needed for fetch from rdr (which indexes by id)
public void Init(ListAdp list, OrderedHash hash) {this.list = list; this.hash = hash; this.Fill_idx_fields_only_(true);}
@Override public int Interval() {return 990;}
@Override public String In_fld_name() {return Xodb_page_tbl.Fld_page_id;}
@Override public Criteria In_filter(Object[] part_ary) {
return Db_crt_.in_(this.In_fld_name(), part_ary);
}
@Override public void Fill_stmt(Db_stmt stmt, int bgn, int end) {
for (int i = bgn; i < end; i++) {
Xodb_page page = (Xodb_page)list.FetchAt(i);
stmt.Val_int_(page.Id());
}
}
@Override public Xodb_page Eval_rslts_key(Xodb_page rdr_page) {return (Xodb_page)hash.Fetch(rdr_page.Id_val());}
}
class Xodb_in_wkr_page_title extends Xodb_in_wkr_page_base {
private OrderedHash hash;
private int in_ns;
@Override public int Interval() {return 64;} // NOTE: 96+ overflows; EX: w:Space_Liability_Convention; DATE:2013-10-24
public void Init(OrderedHash hash, int in_ns) {this.hash = hash; this.in_ns = in_ns;}
@Override public String In_fld_name() {return Xodb_page_tbl.Fld_page_title;}
@Override public Criteria In_filter(Object[] part_ary) {
int len = part_ary.length;
Criteria[] crt_ary = new Criteria[len];
for (int i = 0; i < len; i++)
crt_ary[i] = Criteria_.And(Db_crt_.eq_(Xodb_page_tbl.Fld_page_ns, in_ns), Db_crt_.eq_(Xodb_page_tbl.Fld_page_title, Bry_.Empty));
return Criteria_.Or_many(crt_ary);
}
@Override public void Fill_stmt(Db_stmt stmt, int bgn, int end) {
for (int i = bgn; i < end; i++) {
Xodb_page page = (Xodb_page)hash.FetchAt(i);
stmt.Val_int_(in_ns);
stmt.Val_str_by_bry_(page.Ttl_wo_ns());
}
}
@Override public Xodb_page Eval_rslts_key(Xodb_page rdr_page) {return (Xodb_page)hash.Fetch(rdr_page.Ttl_wo_ns());}
}
class Xodb_in_wkr_page_title_ns extends Xodb_in_wkr_page_base {
private Xow_wiki wiki;
private OrderedHash hash;
@Override public int Interval() {return 64;} // NOTE: 96+ overflows; EX: w:Space_Liability_Convention; DATE:2013-10-24
public void Init(Xow_wiki wiki, OrderedHash hash) {this.wiki = wiki; this.hash = hash;}
@Override public String In_fld_name() {return Xodb_page_tbl.Fld_page_title;}
@Override public Criteria In_filter(Object[] part_ary) {
int len = part_ary.length;
Criteria[] crt_ary = new Criteria[len];
for (int i = 0; i < len; i++)
crt_ary[i] = Criteria_.And(Db_crt_.eq_(Xodb_page_tbl.Fld_page_ns, 0), Db_crt_.eq_(Xodb_page_tbl.Fld_page_title, Bry_.Empty));
return Criteria_.Or_many(crt_ary);
}
@Override public void Fill_stmt(Db_stmt stmt, int bgn, int end) {
for (int i = bgn; i < end; i++) {
Xodb_page page = (Xodb_page)hash.FetchAt(i);
stmt.Val_int_(page.Ns_id());
stmt.Val_str_by_bry_(page.Ttl_wo_ns());
}
}
// public override Criteria In_filter(Object[] part_ary) {
// int len = part_ary.length;
// Object[] vals = new Object[len];
// for (int i = 0; i < len; i++)
// vals[i] = Bry_.Empty;
// Db_obj_ary_crt crt_x = Db_obj_ary_crt.new_(new Db_fld(Xodb_page_tbl.Fld_page_title, ClassAdp_.Tid_str));
// crt_x.Vals_(new Object[][] {vals});
// return Criteria_.And(Db_crt_.eq_(Xodb_page_tbl.Fld_page_ns, 0), crt_x);
//// return Criteria_.And(Db_crt_.eq_(Xodb_page_tbl.Fld_page_ns, 0), Criteria_.Or_many(crt_ary));
// }
// public override void Fill_stmt(Db_stmt stmt, int bgn, int end) {
// stmt.Val_int_(0);
// for (int i = bgn; i < end; i++) {
// Xodb_page page = (Xodb_page)hash.FetchAt(i);
// stmt.Val_str_by_bry_(page.Ttl_wo_ns());
// }
// }
@Override public Xodb_page Eval_rslts_key(Xodb_page rdr_page) {
Xow_ns ns = wiki.Ns_mgr().Ids_get_or_null(rdr_page.Ns_id());
if (ns == null) return null; // NOTE: ns seems to "randomly" be null when threading during redlinks; guard against null; DATE:2014-01-03
byte[] ttl_wo_ns = rdr_page.Ttl_wo_ns();
rdr_page.Ttl_(ns, ttl_wo_ns);
return (Xodb_page)hash.Fetch(rdr_page.Ttl_w_ns());
}
}
abstract class Xodb_in_wkr_page_base extends Xodb_in_wkr_base {
public String Tbl_name() {return Xodb_page_tbl.Tbl_name;}
public abstract String In_fld_name();
public abstract Criteria In_filter(Object[] part_ary);
public abstract Xodb_page Eval_rslts_key(Xodb_page rdr_page);
public boolean Fill_idx_fields_only() {return fill_idx_fields_only;} public Xodb_in_wkr_page_base Fill_idx_fields_only_(boolean v) {fill_idx_fields_only = v; return this;} private boolean fill_idx_fields_only;
@Override public Db_qry Build_qry(int bgn, int end) {
Object[] part_ary = Xodb_in_wkr_base.In_ary(end - bgn);
return Db_qry_.select_cols_
( this.Tbl_name()
, In_filter(part_ary)
, fill_idx_fields_only ? Xodb_page_tbl.Flds_ary_search_suggest : Xodb_page_tbl.Flds_ary_all
)
;
}
@Override public void Eval_rslts(Cancelable cancelable, DataRdr rdr) {
Xodb_page temp = new Xodb_page();
while (rdr.MoveNextPeer()) {
if (cancelable.Canceled()) return;
if (fill_idx_fields_only)
Xodb_page_tbl.Read_page_for_search_suggest(temp, rdr);
else
Xodb_page_tbl.Read_page(temp, rdr);
Xodb_page page = Eval_rslts_key(temp);
if (page == null) continue; // page not found
temp.Exists_(true);
page.Copy(temp);
}
}
}
class Xodb_in_wkr_category_id extends Xodb_in_wkr_base {
private OrderedHash hash;
@Override public int Interval() {return 990;}
public void Init(OrderedHash hash) {this.hash = hash;}
@Override public Db_qry Build_qry(int bgn, int end) {
Object[] part_ary = Xodb_in_wkr_base.In_ary(end - bgn);
String in_fld_name = Xodb_category_tbl.Fld_cat_id;
return Db_qry_.select_cols_
( Xodb_category_tbl.Tbl_name
, Db_crt_.in_(in_fld_name, part_ary)
)
;
}
@Override public void Fill_stmt(Db_stmt stmt, int bgn, int end) {
for (int i = bgn; i < end; i++) {
Xodb_page page = (Xodb_page)hash.FetchAt(i);
stmt.Val_int_(page.Id());
}
}
@Override public void Eval_rslts(Cancelable cancelable, DataRdr rdr) {
while (rdr.MoveNextPeer()) {
if (cancelable.Canceled()) return;
Xodb_category_itm ctg_data = Xodb_category_tbl.Read_ctg(rdr);
Xodb_page page = (Xodb_page)hash.Fetch(ctg_data.Id_val());
page.Xtn_(ctg_data);
}
public static void Read_page__idx(Xodb_page page, DataRdr rdr) {
page.Id_ (rdr.ReadInt(Fld_page_id));
page.Ns_id_ (rdr.ReadInt(Fld_page_ns));
page.Ttl_wo_ns_ (rdr.ReadBryByStr(Fld_page_title));
page.Text_len_ (rdr.ReadInt(Fld_page_len));
}
}

View File

@ -27,7 +27,7 @@ public class Xodb_search_title_word_tbl {
.Val_str_by_bry_(word)
.Exec_insert();
}
public static void Select_by_word(Cancelable cancelable, ListAdp rv, byte[] search, int results_max, Db_provider p) {
public static void Select_by_word(Cancelable cancelable, ListAdp rv, Xow_wiki wiki, byte[] search, int results_max, Db_provider p) {
Db_qry_select qry = Db_qry_.select_()
.Cols_(Xodb_search_title_word_tbl.Fld_stw_word_id)
.From_(Xodb_search_title_word_tbl.Tbl_name, "w")
@ -54,7 +54,7 @@ public class Xodb_search_title_word_tbl {
Xodb_in_wkr_search_title_id wkr = new Xodb_in_wkr_search_title_id();
wkr.Init(words, rv);
wkr.Select_in(p, cancelable, 0, words.Count());
wkr.Select_in(p, cancelable, wiki, 0, words.Count());
}
public static final String Tbl_name = "search_title_word", Fld_stw_word_id = "stw_word_id", Fld_stw_word = "stw_word";
private static final String Tbl_sql = String_.Concat_lines_nl
@ -70,7 +70,7 @@ class Xodb_in_wkr_search_title_id extends Xodb_in_wkr_base {
private ListAdp words, pages;
@Override public int Interval() {return 990;}
public void Init(ListAdp words, ListAdp pages) {this.words = words; this.pages = pages;}
@Override public Db_qry Build_qry(int bgn, int end) {
@Override public Db_qry Build_qry(Xodb_ctx db_ctx, int bgn, int end) {
Object[] part_ary = Xodb_in_wkr_base.In_ary(end - bgn);
String in_fld_name = Xodb_search_title_page_tbl.Fld_stp_word_id;
return Db_qry_.select_cols_
@ -85,7 +85,7 @@ class Xodb_in_wkr_search_title_id extends Xodb_in_wkr_base {
stmt.Val_int_(word_id.Val());
}
}
@Override public void Eval_rslts(Cancelable cancelable, DataRdr rdr) {
@Override public void Eval_rslts(Cancelable cancelable, Xow_wiki wiki, DataRdr rdr) {
while (rdr.MoveNextPeer()) {
if (cancelable.Canceled()) return;
int page_id = rdr.ReadInt(Xodb_search_title_page_tbl.Fld_stp_page_id);

View File

@ -104,7 +104,7 @@ public class Xof_xfer_itm implements Xof_file_itm {
this.html_pass = true;
this.file_found = true;
}
public void Init_for_test__hdump(int uid, int img_w, int img_h, byte[] html_view_src_rel) {this.html_uid = uid; this.html_w = img_w; this.html_h = img_h; this.html_view_src_rel = html_view_src_rel;}
public Xof_xfer_itm Init_for_test__hdump(int uid, int img_w, int img_h, byte[] lnki_ttl, byte[] html_view_src_rel) {this.html_uid = uid; this.html_w = img_w; this.html_h = img_h; this.lnki_ttl = lnki_ttl; this.html_view_src_rel = html_view_src_rel; return this;}
public void Init_for_test__img(int html_w, int html_h, byte[] html_view_src, byte[] html_orig_src) {this.html_w = html_w; this.html_h = html_h; this.html_view_src = html_view_src; this.html_orig_src = html_orig_src;}
public Xof_xfer_itm Set__ttl(byte[] ttl, byte[] redirect) {
this.lnki_redirect = redirect;

View File

@ -87,7 +87,7 @@ public class Xof_fsdb_mgr_sql implements Xof_fsdb_mgr, GfoInvkAble {
} private boolean init = false;
public boolean Reg_select_itm_exists(byte[] ttl) {return Xof_wiki_orig_tbl.Select_itm_exists(img_regy_provider, ttl);}
public void Reg_select_only(Xoa_page page, byte exec_tid, ListAdp itms, OrderedHash hash) {
Xof_wiki_orig_tbl.Select_list(wiki.App().Usr_dlg(), img_regy_provider, exec_tid, itms, hash, url_bldr, bin_mgr.Repo_mgr());
Xof_wiki_orig_tbl.Select_list(wiki.App().Usr_dlg(), img_regy_provider, wiki, exec_tid, itms, hash, url_bldr, bin_mgr.Repo_mgr());
}
public void Reg_select(Xoa_page page, byte exec_tid, ListAdp itms) {
OrderedHash hash = OrderedHash_.new_bry_();

View File

@ -22,10 +22,10 @@ public class Xof_wiki_orig_tbl {
Sqlite_engine_.Tbl_create(p, Tbl_name, Tbl_sql);
Sqlite_engine_.Idx_create(p, Idx_key);
}
public static void Select_list(Cancelable cancelable, Db_provider p, byte exec_tid, ListAdp itms, OrderedHash hash, Xof_url_bldr url_bldr, Xow_repo_mgr repo_mgr) {
public static void Select_list(Cancelable cancelable, Db_provider p, Xow_wiki wiki, byte exec_tid, ListAdp itms, OrderedHash hash, Xof_url_bldr url_bldr, Xow_repo_mgr repo_mgr) {
Xof_wiki_orig_tbl_in_wkr in_wkr = new Xof_wiki_orig_tbl_in_wkr();
in_wkr.Init(itms, hash);
in_wkr.Select_in(p, cancelable, 0, itms.Count());
in_wkr.Select_in(p, cancelable, wiki, 0, itms.Count());
Xof_wiki_orig_tbl_evaluator.Rdr_done(exec_tid, itms, hash, url_bldr, repo_mgr);
}
public static Xof_wiki_orig_itm Select_itm(Db_provider p, byte[] ttl) {

View File

@ -16,13 +16,13 @@ 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.files.wiki_orig; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import gplx.dbs.*; import gplx.xowa.files.fsdb.*;
import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.xowa.files.fsdb.*;
class Xof_wiki_orig_tbl_in_wkr extends gplx.xowa.dbs.tbls.Xodb_in_wkr_base {
private ListAdp itms_all;
@Override public int Interval() {return Sqlite_engine_.Stmt_arg_max;}
private OrderedHash itms_by_ttl;
public Xof_wiki_orig_tbl_in_wkr Init(ListAdp v, OrderedHash itms_by_ttl) {this.itms_all = v; this.itms_by_ttl = itms_by_ttl; return this;}
@Override public Db_qry Build_qry(int bgn, int end) {
@Override public Db_qry Build_qry(Xodb_ctx db_ctx, int bgn, int end) {
Object[] part_ary = gplx.xowa.dbs.tbls.Xodb_in_wkr_base.In_ary(end - bgn);
String in_fld_name = Xof_wiki_orig_tbl.Fld_orig_ttl;
return Db_qry_.select_cols_
@ -37,7 +37,7 @@ class Xof_wiki_orig_tbl_in_wkr extends gplx.xowa.dbs.tbls.Xodb_in_wkr_base {
stmt.Val_str_by_bry_(itm.Lnki_ttl());
}
}
@Override public void Eval_rslts(Cancelable cancelable, DataRdr rdr) {
@Override public void Eval_rslts(Cancelable cancelable, Xow_wiki wiki, DataRdr rdr) {
while (rdr.MoveNextPeer()) {
if (cancelable.Canceled()) return;
Xof_wiki_orig_itm itm = Xof_wiki_orig_itm.load_(rdr);

View File

@ -214,6 +214,9 @@ public class Xog_tab_itm implements GfoInvkAble {
} catch (Exception e) {usr_dlg.Warn_many("", "", "page.thread.redlinks: page=~{0} err=~{1}", page_ttl_str, Err_.Message_gplx_brief(e));}
try {app.File_mgr().Cache_mgr().Compress_check();}
catch (Exception e) {usr_dlg.Warn_many("", "", "page.thread.cache: page=~{0} err=~{1}", page_ttl_str, Err_.Message_gplx_brief(e));}
if (wiki.Db_mgr().Hdump_mgr().Enabled()) {
wiki.Db_mgr().Hdump_mgr().Save_if_missing(page);
}
app.Log_wtr().Queue_enabled_(false);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
@ -241,7 +244,11 @@ class Load_page_wkr implements Gfo_thread_wkr {
app.Free_mem(false); // clear caches (which will clear bry_bfr_mk)
else // not low in memory
app.Utl_bry_bfr_mkr().Clear(); // clear bry_bfr_mk only; NOTE: call before page parse, not when page is first added, else threading errors; DATE:2014-05-30
Xoa_page page = wiki.GetPageByTtl(url, ttl, tab);
Xoa_page page = wiki.GetPageByTtl(url, ttl, wiki.Lang(), tab, false);
if (wiki.Db_mgr().Hdump_mgr().Enabled() && page.Revision_data().Html_db_id() != -1)
wiki.Db_mgr().Hdump_mgr().Load(wiki, page);
else
wiki.ParsePage(page, false);
GfoInvkAble_.InvkCmd_val(tab.Cmd_sync(), Xog_tab_itm.Invk_show_url_loaded_swt, page);
}
catch (Exception e) {

View File

@ -40,7 +40,7 @@ public class Xog_tab_itm_edit_mgr {
win_itm.Page__mode_(Xopg_view_mode.Tid_read);
win_itm.Page__async__bgn(tab);
}
wiki.Db_mgr().Html_mgr().Save(page);
wiki.Db_mgr().Hdump_mgr().Save(page);
}
public static void Preview(Xog_tab_itm tab) {
if (tab.View_mode() != Xopg_view_mode.Tid_edit) return; // exit if not edit; handles preview somehow being called?

View File

@ -0,0 +1,78 @@
/*
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.hdumps; import gplx.*; import gplx.xowa.*;
import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.xowa.html.*; import gplx.xowa.gui.*;
import gplx.xowa.hdumps.core.*; import gplx.xowa.hdumps.saves.*; import gplx.xowa.pages.*; import gplx.xowa.hdumps.loads.*; import gplx.xowa.hdumps.htmls.*; import gplx.xowa.hdumps.dbs.*;
public class Xodb_hdump_mgr {
private Xodb_file hdump_db_file; private Hdump_html_mgr html_mgr = new Hdump_html_mgr();
public Xodb_hdump_mgr(Xow_wiki wiki) {
this.wiki = wiki;
load_mgr = new Hdump_load_mgr(this);
Tbl_(new Hdump_text_tbl());
Xoa_app app = wiki.App();
html_mgr.Init_by_app(app.Usr_dlg(), app.Fsys_mgr().File_dir().To_http_file_bry());
}
public Xow_wiki Wiki() {return wiki;} private final Xow_wiki wiki;
@gplx.Internal protected Hdump_load_mgr Load_mgr() {return load_mgr;} private Hdump_load_mgr load_mgr;
@gplx.Internal protected Hdump_save_mgr Save_mgr() {return save_mgr;} private Hdump_save_mgr save_mgr = new Hdump_save_mgr();
public Hdump_text_tbl Text_tbl() {return text_tbl;} private Hdump_text_tbl text_tbl;
public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled;
@gplx.Internal protected void Tbl_mem_() {Tbl_(new Hdump_text_tbl_mem());}
public int Html_db_id_default(int page_len) {
return -1;
}
public Db_provider Db_provider_by_page(int page_id) {
return text_tbl.Provider();
}
public void Save_if_missing(Xoa_page page) {
if (page.Revision_data().Html_db_id() == -1) Save(page);
}
public void Save(Xoa_page page) {
if (!Enabled_chk()) return;
Bry_bfr tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_m001();
this.Write(tmp_bfr, page);
save_mgr.Update(page);
wiki.Db_mgr_as_sql().Tbl_page().Update_html_db_id(page.Revision_data().Id(), hdump_db_file.Id());
tmp_bfr.Mkr_rls();
}
@gplx.Internal protected void Write(Bry_bfr bfr, Xoa_page page) {
page.File_queue().Clear(); // need to reset uid to 0, else xowa_file_# will resume from last
Xoh_page_wtr_wkr wkr = wiki.Html_mgr().Page_wtr_mgr().Wkr(Xopg_view_mode.Tid_read);
wkr.Write_body(bfr, Xoh_wtr_ctx.Hdump, page);
page.Hdump_data().Body_(bfr.XtoAryAndClear());
}
public void Load(Xow_wiki wiki, Xoa_page page) {
if (!Enabled_chk()) return;
page.Root_(new Xop_root_tkn());
Hdump_page_itm hdump_page = new Hdump_page_itm();
load_mgr.Load(hdump_page, page.Revision_data().Id(), page.Url());
Bry_bfr tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_m001();
html_mgr.Write(tmp_bfr, wiki, hdump_page);
page.Hdump_data().Body_(tmp_bfr.XtoAryAndClear());
tmp_bfr.Mkr_rls();
}
private void Tbl_(Hdump_text_tbl v) {
text_tbl = v;
save_mgr.Tbl_(text_tbl);
load_mgr.Tbl_(text_tbl);
}
private boolean Enabled_chk() {
if (enabled && hdump_db_file == null) hdump_db_file = Xodb_hdump_mgr_setup.Hdump_db_file_init(this);
return enabled;
}
}

View File

@ -0,0 +1,101 @@
/*
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.hdumps; import gplx.*; import gplx.xowa.*;
import org.junit.*; import gplx.dbs.*; import gplx.xowa.files.*; import gplx.xowa.hdumps.dbs.*; import gplx.xowa.hdumps.saves.*;
public class Xodb_hdump_mgr__save_tst {
@Before public void init() {fxt.Clear();} private Xodb_hdump_mgr__save_fxt fxt = new Xodb_hdump_mgr__save_fxt();
@Test public void Body() {
fxt.Test_save("abc", fxt.Make_row_body("abc"));
}
@Test public void Img() {
fxt.Test_save("a[[File:A.png|test_caption]]b[[File:B.png|test_caption]]"
, fxt.Make_row_body("a<a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"test_caption\" xowa_img='0' /></a>b<a href=\"/wiki/File:B.png\" class=\"image\" xowa_title=\"B.png\"><img id=\"xowa_file_img_1\" alt=\"test_caption\" xowa_img='1' /></a>")
, fxt.Make_row_img
( fxt.Make_img(0, 0, 0, "A.png", "trg/orig/7/0/A.png")
, fxt.Make_img(1, 0, 0, "B.png", "trg/orig/5/7/B.png")
)
);
}
@Test public void Display_title() {
fxt.Test_save("{{DISPLAYTITLE:A}}bcd", fxt.Make_row_body("bcd"), fxt.Make_row_display_title("A"));
}
@Test public void Content_sub() {
fxt.Test_save("{{#isin:A}}bcd", fxt.Make_row_body("bcd"), fxt.Make_row_content_sub("<a href=\"/wiki/A\">A</a>"));
}
@Test public void Sidebar_div() {
fxt.Test_save("{{#related:A}}bcd", fxt.Make_row_body("bcd"), fxt.Make_row_sidebar_div(String_.Concat_lines_nl_skip_last
( "<div class=\"portal\" role=\"navigation\" id=\"p-relatedarticles\">"
, " <h3></h3>"
, " <div class=\"body\">"
, " <ul>"
, " <li class=\"interwiki-relart\"><a href=\"/wiki/A\">A</a></li>"
, " </ul>"
, " </div>"
, "</div>"
)));
}
}
class Xodb_hdump_mgr__save_fxt extends Xodb_hdump_mgr__base_fxt {
private int page_id = 0;
private Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
private ListAdp expd_rows = ListAdp_.new_();
@Override public void Clear_end() {
hdump_mgr.Tbl_mem_();
hdump_mgr.Text_tbl().Provider_(Hdump_text_tbl_mem.Null_provider);
}
public Hdump_text_row Make_row_body(String v) {return new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_body, Bry_.new_utf8_(v));}
public Xof_xfer_itm Make_img(int uid, int img_w, int img_h, String lnki_ttl, String img_src_rel) {return new Xof_xfer_itm().Init_for_test__hdump(uid, img_w, img_h, Bry_.new_utf8_(lnki_ttl), Bry_.new_utf8_(img_src_rel));}
public Hdump_text_row Make_row_img(Xof_xfer_itm... itms) {
ListAdp tmp_list = ListAdp_.new_();
tmp_list.AddMany((Object[])itms);
byte[] imgs_bry = Hdump_save_mgr.Write_imgs(tmp_bfr, tmp_list);
return new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_img, imgs_bry);
}
public Hdump_text_row Make_row_display_title(String v) {return new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_display_ttl, Bry_.new_utf8_(v));}
public Hdump_text_row Make_row_content_sub(String v) {return new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_content_sub, Bry_.new_utf8_(v));}
public Hdump_text_row Make_row_sidebar_div(String v) {return new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_sidebar_div, Bry_.new_utf8_(v));}
public void Test_save(String raw, Hdump_text_row... expd) {
this.Exec_write(raw);
hdump_mgr.Save_mgr().Update(page);
hdump_mgr.Text_tbl().Select_by_page(expd_rows, 0);
Hdump_text_row[] actl = (Hdump_text_row[])expd_rows.XtoAryAndClear(Hdump_text_row.class);
Tfds.Eq_ary_str(Xto_str_ary(tmp_bfr, expd), Xto_str_ary(tmp_bfr, actl));
}
private static String[] Xto_str_ary(Bry_bfr bfr, Hdump_text_row[] ary) {
int len = ary.length;
String[] rv = new String[len];
for (int i = 0; i < len; ++i) {
Hdump_text_row itm = ary[i];
bfr .Add_int_variable(itm.Page_id())
.Add_byte_pipe().Add_int_variable(itm.Tid())
.Add_byte_pipe().Add(itm.Data())
;
rv[i] = bfr.XtoStrAndClear();
}
return rv;
}
}
class Hdump_text_row_img {
public Hdump_text_row_img(int uid, int img_w, int img_h, byte[] lnki_ttl, byte[] img_src_rel) {this.uid = uid; this.img_w = img_w; this.img_h = img_h; this.lnki_ttl = lnki_ttl; this.img_src_rel = img_src_rel;}
public int Uid() {return uid;} private int uid;
public int Img_w() {return img_w;} private int img_w;
public int Img_h() {return img_h;} private int img_h;
public byte[] Lnki_ttl() {return lnki_ttl;} private byte[] lnki_ttl;
public byte[] Img_src_rel() {return img_src_rel;} private byte[] img_src_rel;
// return new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_img, 0, Hdump_save_mgr.Write_img(bfr, uid, img_w, img_h, Bry_.new_utf8_(lnki_ttl), Bry_.new_utf8_(img_src_rel)))
}

View File

@ -15,24 +15,24 @@ 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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
import org.junit.*; import gplx.xowa.files.*;
public class Hdump_mgr__write_tst {
@Before public void init() {fxt.Clear();} private Hdump_mgr__write_fxt fxt = new Hdump_mgr__write_fxt();
package gplx.xowa.hdumps; import gplx.*; import gplx.xowa.*;
import org.junit.*; import gplx.xowa.files.*; import gplx.xowa.hdumps.dbs.*;
public class Xodb_hdump_mgr__write_tst {
@Before public void init() {fxt.Clear();} private Xodb_hdump_mgr__write_fxt fxt = new Xodb_hdump_mgr__write_fxt();
@Test public void Image_full() {
fxt.Expd_itms_xfers(fxt.Make_xfer(0, 0, 0, "orig/7/0/A.png"));
fxt.Expd_itms_xfers(fxt.Make_xfer(0, 0, 0, "A.png", "trg/orig/7/0/A.png"));
fxt.Test_write
( "[[File:A.png|test_caption]]"
, "<a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"test_caption\"~<img|0> /></a>");
, "<a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"test_caption\" xowa_img='0' /></a>");
}
@Test public void Image_thumb() {
fxt.Expd_itms_xfers(fxt.Make_xfer(0, 0, 0, "thumb/7/0/A.png/220px.png"));
fxt.Expd_itms_xfers(fxt.Make_xfer(0, 0, 0, "A.png", "trg/thumb/7/0/A.png/220px.png"));
fxt.Test_write
( "[[File:A.png|thumb|test_caption]]", String_.Concat_lines_nl_skip_last
( "<div class=\"thumb tright\">"
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" style=\"width:~<img.w|0>px;\">"
, " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"\"~<img|0> /></a>"
, " <div class=\"thumbcaption\">~<mda.mgnf|0>"
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" xowa_img_style='0'>"
, " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"\" xowa_img='0' /></a>"
, " <div class=\"thumbcaption\"><xowa_mgnf id='0'/>"
, " test_caption"
, " </div>"
, " </div>"
@ -40,14 +40,14 @@ public class Hdump_mgr__write_tst {
));
}
@Test public void Audio_thumb() {
fxt.Expd_itms_xfers(fxt.Make_xfer(0, 220, -1, ""));
fxt.Expd_itms_xfers(fxt.Make_xfer(0, 220, -1, "A.oga", ""));
fxt.Test_write
( "[[File:A.oga|thumb|test_caption]]", String_.Concat_lines_nl_skip_last
( "<div class=\"thumb tright\">"
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" style=\"width:~<img.w|0>px;\">"
, " <div id=\"xowa_media_div\">~<mda.play|0>~<mda.info|0>"
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" xowa_img_style='0'>"
, " <div id=\"xowa_media_div\"><xowa_play id='0'/><xowa_info id='0'/>"
, " </div>"
, " <div class=\"thumbcaption\">~<mda.mgnf|0>"
, " <div class=\"thumbcaption\"><xowa_mgnf id='0'/>"
, " test_caption"
, " </div>"
, " </div>"
@ -55,19 +55,19 @@ public class Hdump_mgr__write_tst {
));
}
@Test public void Video_thumb() {
fxt.Expd_itms_xfers(fxt.Make_xfer(0, 0, 0, ""));
fxt.Expd_itms_xfers(fxt.Make_xfer(0, 0, 0, "A.ogv", ""));
fxt.Test_write
( "[[File:A.ogv|thumb|test_caption]]", String_.Concat_lines_nl_skip_last
( "<div class=\"thumb tright\">"
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" style=\"width:~<img.w|0>px;\">"
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" xowa_img_style='0'>"
, " <div id=\"xowa_media_div\">"
, " <div>"
, " <a href=\"/wiki/File:A.ogv\" class=\"image\" title=\"A.ogv\">"
, " <img id=\"xowa_file_img_0\"~<img|0> alt=\"\" />"
, " <img id=\"xowa_file_img_0\" xowa_img='0' alt=\"\" />"
, " </a>"
, " </div>~<mda.play|0>"
, " </div><xowa_play id='0'/>"
, " </div>"
, " <div class=\"thumbcaption\">~<mda.mgnf|0>"
, " <div class=\"thumbcaption\"><xowa_mgnf id='0'/>"
, " test_caption"
, " </div>"
, " </div>"
@ -75,9 +75,8 @@ public class Hdump_mgr__write_tst {
));
}
}
class Hdump_mgr__base_fxt {
protected Hdump_db_mgr db_mgr;
protected Xodb_html_mgr hdump_mgr = new Xodb_html_mgr();
class Xodb_hdump_mgr__base_fxt {
protected Xodb_hdump_mgr hdump_mgr;
protected Bry_bfr bfr = Bry_bfr.reset_(255);
protected Xow_wiki wiki; protected Xoa_page page;
public Xop_fxt Fxt() {return fxt;} protected Xop_fxt fxt;
@ -86,24 +85,25 @@ class Hdump_mgr__base_fxt {
fxt = new Xop_fxt();
wiki = fxt.Wiki();
page = wiki.Ctx().Cur_page();
db_mgr = hdump_mgr.Db_mgr();
hdump_mgr = new Xodb_hdump_mgr(wiki);
}
fxt.Reset();
page.Revision_data().Id_(0);
this.Clear_end();
}
@gplx.Virtual public void Clear_end() {}
public void Exec_write(String raw) {
Xop_root_tkn root = fxt.Exec_parse_page_all_as_root(Bry_.new_utf8_(raw));
page.Root_(root);
hdump_mgr.Write(bfr, wiki, page);
hdump_mgr.Write(bfr, page);
}
}
class Hdump_mgr__write_fxt extends Hdump_mgr__base_fxt {
class Xodb_hdump_mgr__write_fxt extends Xodb_hdump_mgr__base_fxt {
private ListAdp expd_itms_xfers = ListAdp_.new_();
@Override public void Clear_end() {expd_itms_xfers.Clear();}
public Xof_xfer_itm Make_xfer(int uid, int img_w, int img_h, String img_src) {
public Xof_xfer_itm Make_xfer(int uid, int img_w, int img_h, String lnki_ttl, String img_src) {
Xof_xfer_itm rv = new Xof_xfer_itm();
rv.Init_for_test__hdump(uid, img_w, img_h, Bry_.new_utf8_(img_src));
rv.Init_for_test__hdump(uid, img_w, img_h, Bry_.new_utf8_(lnki_ttl), Bry_.new_utf8_(img_src));
return rv;
}
public void Expd_itms_xfers(Xof_xfer_itm... itms) {expd_itms_xfers.AddMany((Object[])itms);}

View File

@ -15,44 +15,38 @@ 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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
import gplx.dbs.*; import gplx.xowa.dbs.tbls.*; import gplx.xowa.dbs.hdumps.saves.*;
public class Hdump_db_mgr {
public Hdump_db_mgr() {
save_mgr.Tbl_(text_tbl);
package gplx.xowa.hdumps; import gplx.*; import gplx.xowa.*;
import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.tbls.*; import gplx.xowa.hdumps.dbs.*;
public class Xodb_hdump_mgr_setup {
public static Xodb_file Hdump_db_file_init(Xodb_hdump_mgr hdump_mgr) {
Xow_wiki wiki = hdump_mgr.Wiki();
Xodb_mgr_sql db_mgr_as_sql = wiki.Db_mgr_as_sql();
Xodb_file rv = db_mgr_as_sql.Fsys_mgr().Get_tid_root(Xodb_file_tid.Tid_html);
if (rv == null) rv = Setup(db_mgr_as_sql);
hdump_mgr.Text_tbl().Provider_(rv.Provider());
return rv;
}
public Hdump_save_mgr Save_mgr() {return save_mgr;} private Hdump_save_mgr save_mgr = new Hdump_save_mgr();
public Hdump_text_tbl Text_tbl() {return text_tbl;} private Hdump_text_tbl text_tbl = new Hdump_text_tbl();
@gplx.Internal protected void Mode_mem_() {
text_tbl = new Hdump_text_tbl_mem();
save_mgr.Tbl_(text_tbl);
}
public Db_provider Db_provider_by_page(int page_id) {
return null;
}
}
class Hdump_db_mgr_setup {
public static Xodb_file Setup(Xodb_mgr_sql db_mgr) {
private static Xodb_file Setup(Xodb_mgr_sql db_mgr) {
Xodb_fsys_mgr fsys_mgr = db_mgr.Fsys_mgr();
Update_core(fsys_mgr);
Xodb_file html_db_file = Create_db(db_mgr, fsys_mgr);
Create_idx(html_db_file);
return html_db_file;
}
public static void Update_core(Xodb_fsys_mgr fsys_mgr) {
private static void Update_core(Xodb_fsys_mgr fsys_mgr) {
Db_provider core_provider = fsys_mgr.Provider_core();
try {
Xodb_xowa_cfg_tbl.Insert_str(core_provider, "db.meta", "html_db.exists", "y");
core_provider.Exec_sql("ALTER TABLE page ADD COLUMN html_db_idx integer NOT NULL DEFAULT '-1'");
core_provider.Exec_sql("ALTER TABLE page ADD COLUMN page_html_db_id integer NOT NULL DEFAULT '-1'");
} catch (Exception e) {Gfo_usr_dlg_._.Warn_many("", "", "failed to update core: db=~{0} err=~{1}", core_provider.ConnectInfo().Raw_of_db_connect(), Err_.Message_gplx(e));}
}
public static Xodb_file Create_db(Xodb_mgr_sql db_mgr, Xodb_fsys_mgr fsys_mgr) {
private static Xodb_file Create_db(Xodb_mgr_sql db_mgr, Xodb_fsys_mgr fsys_mgr) {
Xodb_file html_db_file = fsys_mgr.Make(Xodb_file_tid.Tid_html);
html_db_file.Provider().Exec_sql(Hdump_text_tbl.Tbl_sql);
db_mgr.Tbl_xowa_db().Commit_all(fsys_mgr.Provider_core(), db_mgr.Fsys_mgr().Files_ary());
return html_db_file;
}
public static void Create_idx(Xodb_file html_db_file) {
private static void Create_idx(Xodb_file html_db_file) {
Sqlite_engine_.Idx_create(html_db_file.Provider(), Hdump_text_tbl.Idx_core);
}
}

View File

@ -15,9 +15,8 @@ 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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
package gplx.xowa.hdumps.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
class Hdump_file_itm {
// lnki_ttl|lnki_ext|lnki_type|lnki_w|lnki_h|lnki_align_x|lnki_align_y|lnki_border|lnki_upright|lnki_time|lnki_page|lnki_media_icon|lnki_alt|lnki_caption
public byte[] Lnki_ttl() {return lnki_ttl;} private byte[] lnki_ttl;
public byte Lnki_tid() {return lnki_tid;} private byte lnki_tid;
public int Lnki_w() {return lnki_w;} private int lnki_w;

View File

@ -15,7 +15,7 @@ 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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
package gplx.xowa.hdumps.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
public class Hdump_img_itm {
public Hdump_img_itm(int idx, int view_w, int view_h, byte[] lnki_ttl, byte[] view_src) {
this.idx = idx;

View File

@ -15,17 +15,17 @@ 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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
package gplx.xowa.hdumps.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
public class Hdump_page_itm {
public int Page_id() {return page_id;} private int page_id;
public byte[] Page_url() {return page_url;} private byte[] page_url;
public Xoa_url Page_url() {return page_url;} private Xoa_url page_url;
public int Version_id() {return version_id;} public void Version_id_(int v) {version_id = v;} private int version_id;
public byte[] Page_body() {return page_body;} public void Page_body_(byte[] v) {this.page_body = v;} private byte[] page_body = Bry_.Empty;
public byte[] Display_ttl() {return display_ttl;} private byte[] display_ttl = Bry_.Empty;
public byte[] Content_sub() {return content_sub;} private byte[] content_sub = Bry_.Empty;
public byte[][] Sidebar_divs() {return sidebar_divs;} private byte[][] sidebar_divs = Bry_.Ary_empty;
public Hdump_img_itm[] Img_itms() {return img_itms;} public void Img_itms_(Hdump_img_itm[] v) {this.img_itms = v;} private Hdump_img_itm[] img_itms = Hdump_img_itm.Ary_empty;
public void Init(int page_id, byte[] page_url, int version_id, byte[] display_ttl, byte[] content_sub, byte[] page_body, byte[][] sidebar_divs, Hdump_img_itm[] img_itms) {
public void Init(int page_id, Xoa_url page_url, int version_id, byte[] display_ttl, byte[] content_sub, byte[] page_body, byte[][] sidebar_divs, Hdump_img_itm[] img_itms) {
this.page_id = page_id;
this.page_url = page_url;
this.version_id = version_id;

View File

@ -15,23 +15,10 @@ 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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
package gplx.xowa.hdumps.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
public class Hdump_text_row {
public Hdump_text_row(int page_id, int tid, int idx, int version_id, byte[] data) {
this.page_id = page_id; this.tid = tid; this.idx = idx; this.version_id = version_id; this.data = data;
}
public Hdump_text_row(int page_id, int tid, byte[] data) {this.page_id = page_id; this.tid = tid; this.data = data;}
public int Page_id() {return page_id;} private int page_id;
public int Tid() {return tid;} private int tid;
public int Idx() {return idx;} private int idx;
public int Version_id() {return version_id;} private int version_id;
public byte[] Data() {return data;} private byte[] data;
public static byte[] data_img_(Bry_bfr bfr, int uid, int img_w, int img_h, byte[] lnki_ttl, byte[] img_src_rel) {
bfr .Add_int_variable(uid)
.Add_byte_pipe().Add_int_variable(img_w)
.Add_byte_pipe().Add_int_variable(img_h)
.Add_byte_pipe().Add(lnki_ttl)
.Add_byte_pipe().Add(img_src_rel)
;
return bfr.XtoAryAndClear();
}
}

View File

@ -15,7 +15,7 @@ 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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
package gplx.xowa.hdumps.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
public class Hdump_text_row_tid { // NOTE: SERIALIZED
public static final int Tid_body = 0, Tid_img = 1, Tid_gallery = 2, Tid_imap = 3, Tid_display_ttl = 4, Tid_content_sub = 5, Tid_sidebar_div = 6;
}

View File

@ -15,22 +15,20 @@ 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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
package gplx.xowa.hdumps.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
import gplx.dbs.*;
public class Hdump_text_tbl {
private Db_stmt stmt_select, stmt_insert, stmt_delete;
public Db_provider Provider() {return provider;} public void Provider_(Db_provider v) {this.Rls_all(); provider = v;} private Db_provider provider;
@gplx.Virtual public void Delete_by_page(int page_id) {
if (stmt_delete == null) stmt_delete = Db_stmt_.new_delete_(provider, Tbl_name, Fld_page_id);
try {
stmt_delete.Clear().Val_int_(page_id).Exec_delete();
} catch (Exception exc) {stmt_insert = null; throw Err_.err_(exc, "stmt failed");} // must reset stmt, else next call will fail
try {stmt_delete.Clear().Val_int_(page_id).Exec_delete();}
catch (Exception exc) {stmt_delete = null; throw Err_.err_(exc, "stmt failed");} // must reset stmt, else next call will fail
}
@gplx.Virtual public void Insert(int page_id, int tid, int idx, int version, byte[] data) {
@gplx.Virtual public void Insert(int page_id, int tid, byte[] data) {
if (stmt_insert == null) stmt_insert = Db_stmt_.new_insert_(provider, Tbl_name, Flds_all);
try {
stmt_insert.Clear().Val_int_(page_id).Val_int_(tid).Val_int_(idx).Val_int_(version).Val_str_by_bry_(data).Exec_insert();
} catch (Exception exc) {stmt_insert = null; throw Err_.err_(exc, "stmt failed");} // must reset stmt, else next call will fail
try {stmt_insert.Clear().Val_int_(page_id).Val_int_(tid).Val_str_by_bry_(data).Exec_insert();}
catch (Exception exc) {stmt_insert = null; throw Err_.err_(exc, "stmt failed");} // must reset stmt, else next call will fail
}
@gplx.Virtual public void Select_by_page(ListAdp rv, int page_id) {
if (stmt_select == null) stmt_select = Db_stmt_.new_select_(provider, Tbl_name, String_.Ary(Fld_page_id), Flds_all);
@ -40,14 +38,14 @@ public class Hdump_text_tbl {
Hdump_text_row row = new Hdump_text_row
( rdr.ReadInt(Fld_page_id)
, rdr.ReadInt(Fld_text_tid)
, rdr.ReadInt(Fld_text_idx)
, rdr.ReadInt(Fld_text_version)
, rdr.ReadBryByStr(Fld_text_data)
);
rv.Add(row);
}
rdr.Rls();
} finally {stmt_select.Rls();}
}
catch (Exception exc) {stmt_select = null; throw Err_.err_(exc, "stmt failed");} // must reset stmt, else next call will fail
finally {stmt_select.Rls();}
}
public void Rls_all() {
if (stmt_select != null) {stmt_select.Rls(); stmt_select = null;}
@ -56,44 +54,16 @@ public class Hdump_text_tbl {
provider = null;
}
public static final String Tbl_name = "html_text"
, Fld_page_id = "page_id", Fld_text_tid = "text_tid", Fld_text_idx = "text_idx"
, Fld_text_version = "text_version", Fld_text_data = "text_data";
private static final String[] Flds_all = new String[] {Fld_page_id, Fld_text_tid, Fld_text_idx, Fld_text_version, Fld_text_data};
, Fld_page_id = "page_id", Fld_text_tid = "text_tid", Fld_text_data = "text_data";
private static final String[] Flds_all = new String[] {Fld_page_id, Fld_text_tid, Fld_text_data};
public static final String Tbl_sql = String_.Concat_lines_nl
( "CREATE TABLE IF NOT EXISTS html_text"
, "( page_id integer NOT NULL"
, ", text_tid integer NOT NULL"
, ", text_idx integer NOT NULL"
, ", text_version integer NOT NULL"
, ", text_data mediumblob NOT NULL"
, ");"
);
public static final Db_idx_itm
Idx_core = Db_idx_itm.sql_("CREATE UNIQUE INDEX IF NOT EXISTS html_text__core ON html_text (page_id, text_tid, text_idx);")
Idx_core = Db_idx_itm.sql_("CREATE UNIQUE INDEX IF NOT EXISTS html_text__core ON html_text (page_id, text_tid);")
;
}
class Hdump_text_tbl_mem extends Hdump_text_tbl { private HashAdp pages = HashAdp_.new_();
@Override public void Insert(int page_id, int tid, int idx, int version, byte[] data) {
Hdump_text_row row = new Hdump_text_row(page_id, tid, idx, version, data);
ListAdp rows = Get_or_new(pages, page_id);
rows.Add(row);
}
@Override public void Select_by_page(ListAdp rv, int page_id) {
ListAdp rows = Get_or_new(pages, page_id);
int len = rows.Count();
for (int i = 0; i < len; ++i) {
Hdump_text_row row = (Hdump_text_row)rows.FetchAt(i);
rv.Add(row);
}
}
@Override public void Delete_by_page(int page_id) {pages.Del(page_id);}
private static ListAdp Get_or_new(HashAdp pages, int page_id) {
ListAdp rv = (ListAdp)pages.Fetch(page_id);
if (rv == null) {
rv = ListAdp_.new_();
pages.Add(page_id, rv);
}
return rv;
}
public static final Db_provider Null_provider = null;
}

View File

@ -0,0 +1,44 @@
/*
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.hdumps.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
import gplx.dbs.*;
public class Hdump_text_tbl_mem extends Hdump_text_tbl { private HashAdp pages = HashAdp_.new_();
@Override public void Insert(int page_id, int tid, byte[] data) {
Hdump_text_row row = new Hdump_text_row(page_id, tid, data);
ListAdp rows = Get_or_new(pages, page_id);
rows.Add(row);
}
@Override public void Select_by_page(ListAdp rv, int page_id) {
ListAdp rows = Get_or_new(pages, page_id);
int len = rows.Count();
for (int i = 0; i < len; ++i) {
Hdump_text_row row = (Hdump_text_row)rows.FetchAt(i);
rv.Add(row);
}
}
@Override public void Delete_by_page(int page_id) {pages.Del(page_id);}
private static ListAdp Get_or_new(HashAdp pages, int page_id) {
ListAdp rv = (ListAdp)pages.Fetch(page_id);
if (rv == null) {
rv = ListAdp_.new_();
pages.Add(page_id, rv);
}
return rv;
}
public static final Db_provider Null_provider = null;
}

View File

@ -0,0 +1,114 @@
/*
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.hdumps.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
import gplx.core.brys.*; import gplx.core.btries.*; import gplx.xowa.html.*; import gplx.xowa.html.lnkis.*; import gplx.xowa.hdumps.core.*;
public class Hdump_html_fmtr__body implements Bry_fmtr_arg {
private Bry_rdr bry_rdr = new Bry_rdr();
private Xow_wiki wiki; private Hdump_page_itm page;
private Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_._; private byte[] file_dir;
public void Init_by_app(Gfo_usr_dlg usr_dlg, byte [] file_dir) {this.usr_dlg = usr_dlg; this.file_dir = file_dir;}
public void Init_by_page(Xow_wiki wiki, Hdump_page_itm page) {this.wiki = wiki; this.page = page;}
public void XferAry(Bry_bfr bfr, int idx) {
byte[] src = page.Page_body(); int len = src.length;
Hdump_img_itm[] imgs = page.Img_itms(); int imgs_len = page.Img_itms().length;
bry_rdr.Src_(src);
int pos = 0; int rng_bgn = -1;
Xow_html_mgr html_mgr = wiki.Html_mgr();
Xoh_file_html_fmtr__base html_fmtr = html_mgr.Html_wtr().Lnki_wtr().File_wtr().File_wtr().Html_fmtr();
while (pos < len) {
byte b = src[pos];
Object o = trie.Match_bgn_w_byte(b, src, pos, len);
if (o == null) {
if (rng_bgn == -1) rng_bgn = pos;
++pos;
}
else {
if (rng_bgn != -1) {
bfr.Add_mid(src, rng_bgn, pos);
rng_bgn = -1;
}
pos = trie.Match_pos(); // position after match; EX: "xowa_img='" positions after "'"
Hdump_html_fmtr_itm itm = (Hdump_html_fmtr_itm)o;
pos = Write_img(bfr, html_mgr, html_fmtr, page, src, imgs, imgs_len, pos, itm); // note no +1; Write_img return pos after }
}
}
if (rng_bgn != -1) bfr.Add_mid(src, rng_bgn, len);
}
private int Write_img(Bry_bfr bfr, Xow_html_mgr html_mgr, Xoh_file_html_fmtr__base fmtr, Hdump_page_itm page, byte[] src, Hdump_img_itm[] imgs, int imgs_len, int uid_bgn, Hdump_html_fmtr_itm itm) {
bry_rdr.Pos_(uid_bgn);
int uid = bry_rdr.Read_int_to(Byte_ascii.Apos);
int uid_end = bry_rdr.Pos(); // set uid_end after "'"
int rv = uid_end;
if (itm.Elem_is_xnde()) rv += 2; // if xnde, skip "/>"
if (uid == bry_rdr.Or_int()) {usr_dlg.Warn_many("", "", "index is not a valid int; page=~{0} text=~{1}", page.Page_url().Xto_full_str_safe(), Bry_.Mid_safe(src, uid_bgn, uid_end)); return uid_end;}
if (!Int_.Between(uid, 0, imgs_len)) {usr_dlg.Warn_many("", "", "index is out of range; page=~{0} idx=~{1} len=~{2}", page.Page_url().Xto_full_str_safe(), uid, imgs_len); return uid_end;}
Hdump_img_itm img = imgs[uid];
int img_view_w = img.View_w();
byte tid = itm.Tid();
if (tid == Tid_img_style) {
bfr.Add(Bry_img_style_bgn);
bfr.Add_int_variable(img_view_w);
bfr.Add(Bry_img_style_end);
return rv;
}
byte[] a_title = img.Lnki_ttl();
byte[] a_href = Bry_.Add(A_href_bgn, a_title);
switch (tid) {
case Tid_file_info: fmtr.Html_thumb_part_info (bfr, uid, a_href, html_mgr.Img_media_info_btn()); return rv;
case Tid_file_mgnf: fmtr.Html_thumb_part_magnify(bfr, uid, a_href, a_title, html_mgr.Img_thumb_magnify()); return rv;
case Tid_file_play: fmtr.Html_thumb_part_play (bfr, uid, img_view_w, Xoh_file_wtr__basic.Play_btn_max_width, a_href, a_title, html_mgr.Img_media_play_btn()); return rv;
}
byte[] img_src = Bry_.Add(file_dir, img.View_src());
if (tid == Tid_img) {
fmtr_img.Bld_bfr_many(bfr, img_src, img_view_w, img.View_h());
}
return rv;
}
private static final Bry_fmtr fmtr_img = Bry_fmtr.new_("src='~{src}' width='~{w}' height='~{h}'", "src", "w", "h");
private static final byte[] A_href_bgn = Bry_.new_ascii_("/wiki/File:"), Bry_img_style_bgn = Bry_.new_ascii_("style='width:"), Bry_img_style_end = Bry_.new_ascii_("px;'");
public static final byte[]
Key_img = Bry_.new_ascii_("xowa_img='")
, Key_img_style = Bry_.new_ascii_("xowa_img_style='")
, Key_file_play = Bry_.new_ascii_("<xowa_play id='")
, Key_file_info = Bry_.new_ascii_("<xowa_info id='")
, Key_file_mgnf = Bry_.new_ascii_("<xowa_mgnf id='")
;
private static final byte Tid_img = 1, Tid_img_style = 2, Tid_file_play = 3, Tid_file_info = 4, Tid_file_mgnf = 5;
private static final Btrie_slim_mgr trie = trie_();
private static Btrie_slim_mgr trie_() {
Btrie_slim_mgr rv = Btrie_slim_mgr.cs_();
trie_itm(rv, Tid_img , "xowa_img='");
trie_itm(rv, Tid_img_style , "xowa_img_style='");
trie_itm(rv, Tid_file_play , "<xowa_play id='");
trie_itm(rv, Tid_file_info , "<xowa_info id='");
trie_itm(rv, Tid_file_mgnf , "<xowa_mgnf id='");
return rv;
}
private static void trie_itm(Btrie_slim_mgr trie, byte tid, String key_str) {
byte[] key_bry = Bry_.new_utf8_(key_str);
boolean elem_is_xnde = key_bry[0] == Byte_ascii.Lt;
Hdump_html_fmtr_itm itm = new Hdump_html_fmtr_itm(tid, key_bry, elem_is_xnde);
trie.Add_obj(key_bry, itm);
}
}
class Hdump_html_fmtr_itm {
public Hdump_html_fmtr_itm(byte tid, byte[] key, boolean elem_is_xnde) {this.tid = tid; this.key = key; this.elem_is_xnde = elem_is_xnde;}
public byte Tid() {return tid;} private byte tid;
public byte[] Key() {return key;} private byte[] key;
public boolean Elem_is_xnde() {return elem_is_xnde;} private boolean elem_is_xnde;
}

View File

@ -15,7 +15,8 @@ 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.dbs.hdumps.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
package gplx.xowa.hdumps.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
import gplx.xowa.hdumps.core.*;
class Hdump_html_fmtr__sidebars implements Bry_fmtr_arg {
private Hdump_page_itm page;
public void Init_by_page(Hdump_page_itm page) {this.page = page;}

View File

@ -15,12 +15,14 @@ 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.dbs.hdumps.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
class Hdump_html_mgr {
package gplx.xowa.hdumps.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
import gplx.xowa.hdumps.core.*;
public class Hdump_html_mgr {
private Hdump_html_fmtr__sidebars sidebars_fmtr = new Hdump_html_fmtr__sidebars();
private Hdump_html_fmtr__body body_fmtr = new Hdump_html_fmtr__body();
public void Init_by_app(Gfo_usr_dlg usr_dlg, byte[] file_dir) {body_fmtr.Init_by_app(usr_dlg, file_dir);}
public void Write(Bry_bfr bfr, Xow_wiki wiki, Bry_fmtr skin_fmtr, Hdump_page_itm page) {
public Hdump_html_mgr Init_by_app(Gfo_usr_dlg usr_dlg, byte[] file_dir) {body_fmtr.Init_by_app(usr_dlg, file_dir); return this;}
public Bry_fmtr Skin_fmtr() {return skin_fmtr;} private Bry_fmtr skin_fmtr = Bry_fmtr.new_("~{display_ttl}~{content_sub}~{sidebar_divs}~{body_html}", "display_ttl", "content_sub", "sidebar_divs", "body_html");
public void Write(Bry_bfr bfr, Xow_wiki wiki, Hdump_page_itm page) {
body_fmtr.Init_by_page(wiki, page);
sidebars_fmtr.Init_by_page(page);
skin_fmtr.Bld_bfr_many(bfr, page.Display_ttl(), page.Content_sub(), sidebars_fmtr, body_fmtr);

View File

@ -15,7 +15,8 @@ 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.dbs.hdumps.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
package gplx.xowa.hdumps.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
import gplx.xowa.hdumps.core.*;
import org.junit.*;
public class Hdump_html_mgr_tst {
@Before public void init() {
@ -23,15 +24,15 @@ public class Hdump_html_mgr_tst {
fxt.Init_img(0, 220, 110, "A.png", "commons.wikimedia.org/thumb/7/0/A.png/220.png");
} private Hdump_html_mgr_fxt fxt = new Hdump_html_mgr_fxt();
@Test public void Img() {
fxt .Init_body("~<img|0>")
.Test_html(" src='file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220.png' width='220' height='110'");
fxt .Init_body("<img xowa_img='0' />")
.Test_html("<img src='file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220.png' width='220' height='110' />");
}
@Test public void Img_w() {
fxt .Init_body("~<img.w|0>")
.Test_html("220");
@Test public void Img_style() {
fxt .Init_body("<div xowa_img_style='0'>")
.Test_html("<div style='width:220px;'>");
}
@Test public void Mda_info() {
fxt .Init_body("~<mda.info|0>")
@Test public void File_info() {
fxt .Init_body("<xowa_info id='0'/>")
.Test_html(String_.Concat_lines_nl_skip_last
( ""
, " <div>"
@ -41,8 +42,8 @@ public class Hdump_html_mgr_tst {
, " </div>"
));
}
@Test public void Mda_mgnf() {
fxt .Init_body("~<mda.mgnf|0>")
@Test public void File_mgnf() {
fxt .Init_body("<xowa_mgnf id='0'/>")
.Test_html(String_.Concat_lines_nl_skip_last
( ""
, " <div class=\"magnify\">"
@ -52,8 +53,8 @@ public class Hdump_html_mgr_tst {
, " </div>"
));
}
@Test public void Mda_play() {
fxt .Init_body("~<mda.play|0>")
@Test public void File_play() {
fxt .Init_body("<xowa_play id='0'/>")
.Test_html(String_.Concat_lines_nl_skip_last
( ""
, " <div>"
@ -68,7 +69,6 @@ class Hdump_html_mgr_fxt {
private Hdump_html_mgr html_mgr = new Hdump_html_mgr();
private Hdump_page_itm page = new Hdump_page_itm();
private Bry_bfr bfr = Bry_bfr.reset_(255);
private Bry_fmtr skin_fmtr = Bry_fmtr.new_("~{display_ttl}~{content_sub}~{sidebar_divs}~{body_html}", "display_ttl", "content_sub", "sidebar_divs", "body_html");
private ListAdp img_list = ListAdp_.new_();
private Xow_wiki wiki;
public void Clear() {
@ -80,7 +80,7 @@ class Hdump_html_mgr_fxt {
public Hdump_html_mgr_fxt Init_img(int id, int w, int h, String ttl, String src) {img_list.Add(new Hdump_img_itm(id, w, h, Bry_.new_utf8_(ttl), Bry_.new_utf8_(src))); return this;}
public Hdump_html_mgr_fxt Test_html(String expd) {
if (img_list.Count() > 0) page.Img_itms_((Hdump_img_itm[])img_list.XtoAryAndClear(Hdump_img_itm.class));
html_mgr.Write(bfr, wiki, skin_fmtr, page);
html_mgr.Write(bfr, wiki, page);
Tfds.Eq_str_lines(expd, bfr.XtoStrAndClear());
return this;
}

View File

@ -15,32 +15,30 @@ 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.dbs.hdumps.loads; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
import gplx.dbs.*; import gplx.ios.*;
import gplx.core.btries.*; import gplx.xowa.pages.*;
class Hdump_load_mgr {
private Hdump_db_mgr db_mgr;
package gplx.xowa.hdumps.loads; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
import gplx.core.brys.*; import gplx.core.btries.*; import gplx.dbs.*; import gplx.ios.*; import gplx.xowa.pages.*; import gplx.xowa.hdumps.core.*; import gplx.xowa.hdumps.dbs.*;
public class Hdump_load_mgr {
private Xodb_hdump_mgr hdump_mgr;
private Io_stream_zip_mgr zip_mgr = new Io_stream_zip_mgr();
private int page_version;
private byte[] page_text, display_ttl, content_sub;
private ListAdp sidebar_divs = ListAdp_.new_(), img_itms = ListAdp_.new_();
private Hdump_text_tbl text_tbl = new Hdump_text_tbl(); private ListAdp tmp_text_itms = ListAdp_.new_();
private Bry_rdr bry_rdr = new Bry_rdr();
private byte zip_tid;
public Hdump_load_mgr(Hdump_db_mgr db_mgr, byte zip_tid) {this.db_mgr = db_mgr; this.zip_tid = zip_tid;}
public Hdump_load_mgr(Xodb_hdump_mgr hdump_mgr) {this.hdump_mgr = hdump_mgr;}
public byte Zip_tid() {return zip_tid;} public void Zip_tid_(byte v) {zip_tid = v;} private byte zip_tid = gplx.ios.Io_stream_.Tid_file;
public void Tbl_(Hdump_text_tbl v) {text_tbl = v;}
public void Clear() {
page_version = -1;
page_text = display_ttl = content_sub = null;
sidebar_divs.Clear();
img_itms.Clear();
}
public void Load(Hdump_page_itm page, int page_id, byte[] page_url) {
Db_provider provider = db_mgr.Db_provider_by_page(page_id);
public void Load(Hdump_page_itm page, int page_id, Xoa_url page_url) {
Db_provider provider = hdump_mgr.Db_provider_by_page(page_id);
text_tbl.Provider_(provider);
text_tbl.Select_by_page(tmp_text_itms, page_id);
Load_itm(page, page_id, page_url, tmp_text_itms);
}
public void Load_itm(Hdump_page_itm page, int page_id, byte[] page_url, ListAdp itms) {
public void Load_itm(Hdump_page_itm page, int page_id, Xoa_url page_url, ListAdp itms) {
this.Clear();
int len = itms.Count();
for (int i = 0; i < len; ++i) {
@ -53,23 +51,25 @@ class Hdump_load_mgr {
case Hdump_text_row_tid.Tid_content_sub: content_sub = zip_mgr.Unzip(zip_tid, itm.Data()); break;
}
}
page.Init(page_id, page_url, page_version, display_ttl, content_sub, page_text
page.Init(page_id, page_url, 0, display_ttl, content_sub, page_text
, (byte[][])sidebar_divs.XtoAryAndClear(byte[].class)
, (Hdump_img_itm[])img_itms.XtoAryAndClear(Hdump_img_itm.class)
);
itms.Clear();
}
public void Load_itm_body(Hdump_text_row itm) {
page_version = itm.Version_id();
page_text = zip_mgr.Unzip(zip_tid, itm.Data());
}
public void Load_itm_img(Hdump_text_row itm) {
bry_rdr.Src_(itm.Data());
while (!bry_rdr.Pos_is_eos()) {
int uid = bry_rdr.Read_int_to_pipe();
int w = bry_rdr.Read_int_to_pipe();
int h = bry_rdr.Read_int_to_pipe();
byte[] ttl = bry_rdr.Read_bry_to_pipe();
byte[] src = bry_rdr.Read_bry_to_pipe();
byte[] src = bry_rdr.Read_bry_to_nl();
Hdump_img_itm img_itm = new Hdump_img_itm(uid, w, h, ttl, src);
img_itms.Add(img_itm);
}
}
}

View File

@ -15,8 +15,8 @@ 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.dbs.hdumps.loads; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
import org.junit.*;
package gplx.xowa.hdumps.loads; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
import org.junit.*; import gplx.xowa.files.*; import gplx.xowa.hdumps.dbs.*; import gplx.xowa.hdumps.core.*; import gplx.xowa.hdumps.saves.*;
public class Hdump_load_mgr_tst {
@Before public void init() {fxt.Clear();} private Hdump_load_mgr_fxt fxt = new Hdump_load_mgr_fxt();
@Test public void Body() {
@ -25,8 +25,10 @@ public class Hdump_load_mgr_tst {
fxt.Test_load(0);
}
@Test public void Img() {
fxt.Init_row_img(0, "0|220|110|A.png|commons.wikimedia.org/thumb/7/0/A.png/220.png");
fxt.Init_row_img(1, "1|200|100|B.png|commons.wikimedia.org/thumb/7/0/B.png/200.png");
fxt.Init_row_img
( fxt.Make_img(0, 220, 110, "A.png", "commons.wikimedia.org/thumb/7/0/A.png/220.png")
, fxt.Make_img(1, 200, 100, "B.png", "commons.wikimedia.org/thumb/7/0/B.png/200.png")
);
fxt.Expd_img(0, 220, 110, "A.png", "commons.wikimedia.org/thumb/7/0/A.png/220.png");
fxt.Expd_img(1, 200, 100, "B.png", "commons.wikimedia.org/thumb/7/0/B.png/200.png");
fxt.Test_load(0);
@ -38,19 +40,29 @@ class Hdump_load_mgr_fxt {
private ListAdp init_rows = ListAdp_.new_();
private String expd_body;
private ListAdp expd_imgs = ListAdp_.new_();
private int page_id = 0;
private int page_id = 0; private Xoa_url page_url;
public void Clear() {
load_mgr = new Hdump_load_mgr(null, gplx.ios.Io_stream_.Tid_file);
load_mgr = new Hdump_load_mgr(null);
load_mgr.Zip_tid_(gplx.ios.Io_stream_.Tid_file);
init_rows.Clear();
expd_body = null;
expd_imgs.Clear();
page_url = Xoa_url.new_(Bry_.new_ascii_("enwiki"), Bry_.new_ascii_("Page_1"));
}
public Hdump_load_mgr_fxt Init_row_body(String data) {init_rows.Add(new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_body, 0, 0, Bry_.new_utf8_(data))); return this;}
public Hdump_load_mgr_fxt Init_row_img (int uid, String data) {init_rows.Add(new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_img , uid, 0, Bry_.new_utf8_(data))); return this;}
public Xof_xfer_itm Make_img(int uid, int img_w, int img_h, String lnki_ttl, String img_src_rel) {return new Xof_xfer_itm().Init_for_test__hdump(uid, img_w, img_h, Bry_.new_utf8_(lnki_ttl), Bry_.new_utf8_(img_src_rel));}
public void Init_row_img(Xof_xfer_itm... itms) {
ListAdp tmp_list = ListAdp_.new_();
Bry_bfr bfr = Bry_bfr.new_(255);
tmp_list.AddMany((Object[])itms);
byte[] imgs_bry = Hdump_save_mgr.Write_imgs(bfr, tmp_list);
init_rows.Add(new Hdump_text_row(0, Hdump_text_row_tid.Tid_img, imgs_bry));
}
public Hdump_load_mgr_fxt Init_row_body(String data) {init_rows.Add(new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_body, Bry_.new_utf8_(data))); return this;}
public Hdump_load_mgr_fxt Init_row_img (String data) {init_rows.Add(new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_img , Bry_.new_utf8_(data))); return this;}
public Hdump_load_mgr_fxt Expd_body(String v) {this.expd_body = v; return this;}
public Hdump_load_mgr_fxt Expd_img(int idx, int w, int h, String ttl, String src) {expd_imgs.Add(new Hdump_img_itm(idx, w, h, Bry_.new_utf8_(ttl), Bry_.new_utf8_(src))); return this;}
public Hdump_load_mgr_fxt Test_load(int page_id) {
load_mgr.Load_itm(page, page_id, Bry_.Empty, init_rows);
load_mgr.Load_itm(page, page_id, page_url, init_rows);
if (expd_body != null) Tfds.Eq(expd_body, String_.new_utf8_(page.Page_body()));
if (expd_imgs.Count() != 0) Tfds.Eq_ary_str((Hdump_img_itm[])expd_imgs.XtoAryAndClear(Hdump_img_itm.class), page.Img_itms());
return this;

View File

@ -15,9 +15,9 @@ 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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
package gplx.xowa.hdumps.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
public class Xopg_hdump_data {
public ListAdp Imgs() {return imgs;} private ListAdp imgs = ListAdp_.new_();
public ListAdp Imgs() {return imgs;} private final ListAdp imgs = ListAdp_.new_();
public byte[] Body() {return body;} public void Body_(byte[] v) {body = v;} private byte[] body;
public void Clear() {
imgs.Clear();

View File

@ -15,15 +15,15 @@ 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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
package gplx.xowa.hdumps.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
public class Xopg_hdump_img_itm {
public int Uid() {return uid;} private int uid;
public int Img_w() {return img_w;} private int img_w;
public int Img_h() {return img_h;} private int img_h;
public byte[] Img_src() {return img_src;} private byte[] img_src;
public Xopg_hdump_img_itm(int uid, int img_w, int img_h, byte[] img_src) {
this.uid = uid; this.img_w = img_w; this.img_h = img_h; this.img_src = img_src;
}
public int Uid() {return uid;} private final int uid;
public int Img_w() {return img_w;} private final int img_w;
public int Img_h() {return img_h;} private final int img_h;
public byte[] Img_src() {return img_src;} private final byte[] img_src;
@Override public String toString() {
return String_.Concat_with_str("|", Int_.XtoStr(uid), Int_.XtoStr(img_w), Int_.XtoStr(img_h), String_.new_utf8_(img_src));
}

View File

@ -15,8 +15,9 @@ 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.dbs.hdumps.saves; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
import gplx.dbs.*; import gplx.xowa.files.*; import gplx.xowa.pages.*; import gplx.xowa.pages.skins.*;
package gplx.xowa.hdumps.saves; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
import gplx.dbs.*; import gplx.xowa.files.*; import gplx.xowa.hdumps.dbs.*;
import gplx.xowa.hdumps.pages.*; import gplx.xowa.pages.*; import gplx.xowa.pages.skins.*;
public class Hdump_save_mgr {
private Bry_bfr tmp_bfr = Bry_bfr.reset_(10 * Io_mgr.Len_mb);
private Hdump_text_tbl text_tbl;
@ -27,27 +28,24 @@ public class Hdump_save_mgr {
this.Insert(page);
}
public void Insert(Xoa_page page) {
tmp_bfr.Clear();
int page_id = page.Revision_data().Id();
Xopg_html_data html_data = page.Html_data();
Xopg_hdump_data hdump_data = page.Hdump_data();
text_tbl.Insert(page_id, Hdump_text_row_tid.Tid_body, 0, 0, hdump_data.Body());
text_tbl.Insert(page_id, Hdump_text_row_tid.Tid_body, hdump_data.Body());
Insert_files(page_id, hdump_data.Imgs());
Insert_if_exists(page_id, Hdump_text_row_tid.Tid_display_ttl, html_data.Display_ttl());
Insert_if_exists(page_id, Hdump_text_row_tid.Tid_content_sub, html_data.Content_sub());
Insert_sidebars(page_id, page, html_data.Xtn_skin_mgr());
}
private void Insert_files(int page_id, ListAdp imgs) {
int len = imgs.Count();
for (int i = 0; i < len; ++i) {
Xof_xfer_itm img = (Xof_xfer_itm)imgs.FetchAt(i);
int uid = img.Html_uid();
byte[] data = Hdump_text_row.data_img_(tmp_bfr, uid, img.Html_w(), img.Html_h(), img.Lnki_ttl(), img.Html_view_src_rel());
text_tbl.Insert(page_id, Hdump_text_row_tid.Tid_img, uid, 0, data);
}
byte[] imgs_bry = Write_imgs(tmp_bfr, imgs);
if (imgs_bry != null)
text_tbl.Insert(page_id, Hdump_text_row_tid.Tid_img, imgs_bry);
}
private void Insert_if_exists(int page_id, int tid, byte[] val) {
if (Bry_.Len_gt_0(val))
text_tbl.Insert(page_id, tid, 0, 0, val);
text_tbl.Insert(page_id, tid, val);
}
private void Insert_sidebars(int page_id, Xoa_page page, Xopg_xtn_skin_mgr xtn_skin_mgr) {
int len = xtn_skin_mgr.Count();
@ -55,8 +53,32 @@ public class Hdump_save_mgr {
Xopg_xtn_skin_itm itm = xtn_skin_mgr.Get_at(i);
if (itm.Tid() == Xopg_xtn_skin_itm_tid.Tid_sidebar) {
itm.Write(tmp_bfr, page);
text_tbl.Insert(page_id, Hdump_text_row_tid.Tid_sidebar_div, i, 0, tmp_bfr.XtoAryAndClear());
text_tbl.Insert(page_id, Hdump_text_row_tid.Tid_sidebar_div, tmp_bfr.XtoAryAndClear());
}
}
}
public static byte[] Write_imgs(Bry_bfr bfr, ListAdp imgs) {
int len = imgs.Count(); if (len == 0) return null; // no images; exit early, else will write blank String
for (int i = 0; i < len; ++i) {
Xof_xfer_itm img = (Xof_xfer_itm)imgs.FetchAt(i);
Write_img(bfr, img.Html_uid(), img.Html_w(), img.Html_h(), img.Lnki_ttl(), img.Html_view_src_rel());
}
return bfr.XtoAryAndClear();
}
private static void Write_img(Bry_bfr bfr, int uid, int img_w, int img_h, byte[] lnki_ttl, byte[] img_src_rel) {
bfr .Add_int_variable(uid)
.Add_byte_pipe().Add_int_variable(img_w)
.Add_byte_pipe().Add_int_variable(img_h)
.Add_byte_pipe().Add(lnki_ttl)
.Add_byte_pipe().Add(img_src_rel)
.Add_byte_nl()
;
}
}
/*
<0/>|0|metadata
<1/>|title
<2/>|content_sub
<3/>|sidebar
<4/>|body
*/

View File

@ -94,8 +94,8 @@ public class Xoh_page_wtr_mgr implements GfoInvkAble {
Xow_wiki wiki = page.Wiki();
if (init) {
init = false;
page_edit_fmtr.Eval_mgr_(wiki.Eval_mgr());
page_read_fmtr.Eval_mgr_(wiki.Eval_mgr());
page_edit_fmtr.Eval_mgr_(wiki.Eval_mgr());
page_html_fmtr.Eval_mgr_(wiki.Eval_mgr());
}
Bry_bfr tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_m001();

View File

@ -106,6 +106,11 @@ public class Xoh_page_wtr_wkr implements Bry_fmtr_arg {
}
}
private void Write_body_wikitext(Bry_bfr bfr, Xoa_app app, Xow_wiki wiki, byte[] data_raw, Xoh_wtr_ctx hctx, Xoa_page page, int ns_id) {
byte[] hdump_data = page.Hdump_data().Body();
if (Bry_.Len_gt_0(hdump_data)) {
bfr.Add(hdump_data);
return;
}
if (ns_id == Xow_ns_.Id_mediawiki) { // if MediaWiki and wikitext, must be a message; convert args back to php; DATE:2014-06-13
bfr.Add(gplx.xowa.apps.Xoa_gfs_php_mgr.Xto_php(tmp_bfr, Bool_.N, data_raw));
return;

View File

@ -16,26 +16,30 @@ 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.html.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*;
import gplx.xowa.files.*; import gplx.xowa.dbs.hdumps.htmls.*;
import gplx.xowa.files.*; import gplx.xowa.hdumps.htmls.*;
class Xoh_file_html_fmtr__hdump extends Xoh_file_html_fmtr__base {
private Bry_bfr tmp_bfr = Bry_bfr.reset_(128);
@gplx.Internal @Override protected Xoh_arg_img_core New_arg_img_core() {return new Xoh_arg_img_core__hdump();}
@Override public void Html_thumb_core(Bry_bfr tmp_bfr, int uid, byte[] div1_halign, int div2_width, byte[] div2_content) {
Write_fmt(tmp_bfr, Hdump_html_fmtr__body.Key_img_w, uid);
@Override public void Html_thumb_core(Bry_bfr bfr, int uid, byte[] div1_halign, int div2_width, byte[] div2_content) {
tmp_bfr.Add(Hdump_html_fmtr__body.Key_img_style);
tmp_bfr.Add_int_variable(uid);
tmp_bfr.Add_byte_apos();
byte[] div2_width_repl = tmp_bfr.XtoAryAndClear();
fmtr_thumb_core.Bld_bfr_many(tmp_bfr, uid, div1_halign, div2_width_repl, div2_content);
fmtr_thumb_core.Bld_bfr_many(bfr, uid, div1_halign, div2_width_repl, div2_content);
}
@Override public void Html_thumb_part_magnify(Bry_bfr tmp_bfr, int uid, byte[] a_href, byte[] a_title, byte[] img_src) {Write_fmt(tmp_bfr, Hdump_html_fmtr__body.Key_mda_mgnf, uid);}
@Override public void Html_thumb_part_info(Bry_bfr tmp_bfr, int uid, byte[] a_href, byte[] img_src) {Write_fmt(tmp_bfr, Hdump_html_fmtr__body.Key_mda_info, uid);}
@Override public void Html_thumb_part_play(Bry_bfr tmp_bfr, int uid, int a_width, int a_max_width, byte[] a_href, byte[] a_xowa_title, byte[] img_src) {Write_fmt(tmp_bfr, Hdump_html_fmtr__body.Key_mda_play, uid);}
public static void Write_fmt(Bry_bfr bfr, byte[] key, int uid) {
@Override public void Html_thumb_part_magnify(Bry_bfr bfr, int uid, byte[] a_href, byte[] a_title, byte[] img_src) {Write_xnde(bfr, Hdump_html_fmtr__body.Key_file_mgnf, uid);}
@Override public void Html_thumb_part_info(Bry_bfr bfr, int uid, byte[] a_href, byte[] img_src) {Write_xnde(bfr, Hdump_html_fmtr__body.Key_file_info, uid);}
@Override public void Html_thumb_part_play(Bry_bfr bfr, int uid, int a_width, int a_max_width, byte[] a_href, byte[] a_xowa_title, byte[] img_src) {Write_xnde(bfr, Hdump_html_fmtr__body.Key_file_play, uid);}
public static void Write_xnde(Bry_bfr bfr, byte[] key, int uid) {
bfr.Add(key);
bfr.Add_int_variable(uid);
bfr.Add_byte(Byte_ascii.Gt);
}
bfr.Add(Bry_xnde_end);
} private static final byte[] Bry_xnde_end = Bry_.new_ascii_("'/>");
public static final Xoh_file_html_fmtr__hdump Hdump = new Xoh_file_html_fmtr__hdump(); Xoh_file_html_fmtr__hdump() {}
}
public class Xoh_file_html_fmtr__base implements Xoh_file_img_wkr {
private final Xoh_arg_img_core arg_img_core; //Xoh_arg_img_core arg_img_mgnf;
private final Xoh_arg_img_core arg_img_core;
private Bry_bfr scratch_bfr = Bry_bfr.reset_(128);
public Xoh_file_html_fmtr__base() {
arg_img_core = New_arg_img_core();
}
@ -56,16 +60,19 @@ public class Xoh_file_html_fmtr__base implements Xoh_file_img_wkr {
);
@gplx.Virtual public void Html_thumb_core(Bry_bfr tmp_bfr, int uid, byte[] div1_halign, int div2_width, byte[] div2_content) {
fmtr_thumb_core.Bld_bfr_many(tmp_bfr, uid, div1_halign, div2_width, div2_content);
}
scratch_bfr.Add(Bry_style_bgn);
scratch_bfr.Add_int_variable(div2_width);
scratch_bfr.Add(Bry_style_end);
fmtr_thumb_core.Bld_bfr_many(tmp_bfr, uid, div1_halign, scratch_bfr.XtoAryAndClear(), div2_content);
} private static final byte[] Bry_style_bgn = Bry_.new_ascii_("style=\"width:"), Bry_style_end = Bry_.new_ascii_("px;\"");
protected Bry_fmtr fmtr_thumb_core = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last // REF.MW: Linker.php|makeImageLink2
( "<div class=\"thumb t~{div1_halign}\">"
, " <div id=\"xowa_file_div_~{uid}\" class=\"thumbinner\" style=\"width:~{div2_width}px;\">"
, " <div id=\"xowa_file_div_~{uid}\" class=\"thumbinner\" ~{style}>"
, "~{div2_content}"
, " </div>"
, "</div>"
, ""
), "uid", "div1_halign", "div2_width", "div2_content"
), "uid", "div1_halign", "style", "div2_content"
);
public byte[] Html_thumb_part_img(Bry_bfr tmp_bfr, Xoa_page page, Xof_xfer_itm xfer_itm, Xop_lnki_tkn lnki, int uid, byte[] a_href, byte[] img_src, byte[] img_alt) {
Html_thumb_part_img(tmp_bfr, page, xfer_itm, uid, a_href, lnki.Ttl().Page_txt(), xfer_itm.Html_w(), xfer_itm.Html_h(), img_src, img_alt);
@ -162,7 +169,10 @@ class Xoh_arg_img_core__hdump implements Xoh_arg_img_core {
return this;
}
public void XferAry(Bry_bfr bfr, int idx) {
Xoh_file_html_fmtr__hdump.Write_fmt(bfr, Hdump_html_fmtr__body.Key_img, uid);
bfr.Add_str(" xowa_img='");
bfr.Add_int_variable(uid);
bfr.Add_str("'");
// Xoh_file_html_fmtr__hdump.Write_fmt(bfr, Hdump_html_fmtr__body.Key_img, uid);
}
}
class Xoh_arg_img_core__basic implements Xoh_arg_img_core {

View File

@ -57,10 +57,9 @@ public class Xoh_file_wtr__basic {
) {
img_orig_src = img_view_src = Bry_.Empty; // null out src
}
if (lnki.Ns_id() == Xow_ns_.Id_media) { // NOTE: regardless of ext (ogg vs jpeg) and literal status (Media vs :Media), [[Media]] links are always rendered the same way; REF.MW:Linker.php|makeMediaLinkObj; PAGE:en.w:Beethoven; EX: [[:Media:De-Ludwig_van_Beethoven.ogg|listen]]); [[File:Beethoven 3.jpg|The [[Media:BeethovenWithLyreGuitar( W. J. Mahler - 1804).jpg|complete painting]]...]]
if (lnki.Ns_id() == Xow_ns_.Id_media) // NOTE: regardless of ext (ogg vs jpeg) and literal status (Media vs :Media), [[Media]] links are always rendered the same way; REF.MW:Linker.php|makeMediaLinkObj; PAGE:en.w:Beethoven; EX: [[:Media:De-Ludwig_van_Beethoven.ogg|listen]]); [[File:Beethoven 3.jpg|The [[Media:BeethovenWithLyreGuitar( W. J. Mahler - 1804).jpg|complete painting]]...]]
this.Write_file_ns_media(bfr, ctx, src, lnki, img_orig_src);
return;
}
else {
if ( Xof_ext_.Id_is_video_strict(lnki_ext.Id()) // id is .ogv or .webm
|| ( lnki_ext.Id_is_ogg() // id is ogg
&& wiki.File_mgr().Version_1_y() // version is v1 (v2 always marks ogg as aud); DATE:2014-02-01
@ -76,8 +75,9 @@ public class Xoh_file_wtr__basic {
this.Write_file_audio(bfr, ctx, src, lnki, uid, div_width, lnki_halign_bry, lnki_href, img_orig_src, img_alt);
else // image
this.Write_file_image(bfr, ctx, hctx, src, lnki, xfer_itm, uid, div_width, lnki_halign, lnki_halign_bry, lnki_ttl, lnki_ext, lnki_href, img_view_src, img_orig_src, img_alt);
}
if (hctx.Mode_is_hdump()) {
byte[] rel_src = Bry_.Len_eq_0(img_view_src) ? Bry_.Empty : Bry_.Mid(img_view_src, xfer_itm.Trg_repo_root().length);
byte[] rel_src = Bry_.Len_eq_0(img_view_src) ? Bry_.Empty : Bry_.Mid(img_view_src, wiki.App().Fsys_mgr().File_dir().To_http_file_bry().length);
xfer_itm.Html_view_src_rel_(rel_src);
page.Hdump_data().Imgs().Add(xfer_itm.Clone());
}

View File

@ -92,7 +92,14 @@ public class Xow_popup_mgr implements GfoInvkAble, GfoEvObj {
}
private byte[] Get_popup_html(Xoa_page cur_page, Xow_popup_itm itm) {
try {
synchronized (async_thread_guard) {
synchronized (async_thread_guard) { // queue popups to reduce contention with Load_page_wkr; DATE:2014-08-24
// Load_popup_wkr load_popup_wkr = new Load_popup_wkr(wiki, cur_page, itm, temp_href, ns_allowed_regy, ns_allowed_regy_key);
// app.Thread_mgr().Page_load_mgr().Add_at_end(load_popup_wkr);
// load_popup_wkr.Exec();
// while (!load_popup_wkr.Rslt_done()) {
// ThreadAdp_.Sleep(100);
// }
// return load_popup_wkr.Rslt_bry();
if (itm.Canceled()) return null;
cur_page.Popup_mgr().Itms().AddReplace(itm.Popup_id(), itm);
app.Href_parser().Parse(temp_href, itm.Page_href(), wiki, cur_page.Ttl().Full_url()); // NOTE: use Full_url, not Page_url, else anchors won't work for non-main ns; PAGE:en.w:Project:Sandbox; DATE:2014-08-07
@ -112,7 +119,7 @@ public class Xow_popup_mgr implements GfoInvkAble, GfoEvObj {
return null;
}
}
private static void Update_progress_bar(Xoa_app app, Xoa_page cur_page, Xow_popup_itm itm) {
public static void Update_progress_bar(Xoa_app app, Xoa_page cur_page, Xow_popup_itm itm) {
byte[] href = itm.Page_href();
byte[] tooltip = itm.Tooltip();
if (Bry_.Len_gt_0(tooltip))
@ -216,3 +223,41 @@ class Xow_popup_mgr_ {
return js_wtr.Xto_str_and_clear();
}
}
class Load_popup_wkr implements Gfo_thread_wkr {
private Xow_popup_itm itm; private Xoa_page cur_page; private Xoh_href temp_href;
private HashAdp ns_allowed_regy;
private Int_obj_ref ns_allowed_regy_key = Int_obj_ref.zero_();
public Load_popup_wkr(Xow_wiki wiki, Xoa_page cur_page, Xow_popup_itm itm, Xoh_href temp_href, HashAdp ns_allowed_regy, Int_obj_ref ns_allowed_regy_key) {
this.wiki = wiki; this.cur_page = cur_page; this.itm = itm; this.temp_href = temp_href; this.ns_allowed_regy = ns_allowed_regy; this.ns_allowed_regy_key = ns_allowed_regy_key;
}
public String Name() {return "xowa.load_popup_wkr";}
public boolean Resume() {return false;}
public Xow_wiki Wiki() {return wiki;} private Xow_wiki wiki;
public byte[] Rslt_bry() {return rslt_bry;} private byte[] rslt_bry;
public boolean Rslt_done() {return rslt_done;} private boolean rslt_done;
public void Rslt_(byte[] bry) {this.rslt_done = true; rslt_bry = bry;}
public void Exec() {
Xoa_app app = wiki.App();
try {
if (itm.Canceled()) {Rslt_(null); return;}
cur_page.Popup_mgr().Itms().AddReplace(itm.Popup_id(), itm);
app.Href_parser().Parse(temp_href, itm.Page_href(), wiki, cur_page.Ttl().Full_url()); // NOTE: use Full_url, not Page_url, else anchors won't work for non-main ns; PAGE:en.w:Project:Sandbox; DATE:2014-08-07
Xow_wiki popup_wiki = app.Wiki_mgr().Get_by_key_or_null(temp_href.Wiki());
popup_wiki.Init_assert();
Xoa_ttl popup_ttl = Xoa_ttl.parse_(popup_wiki, temp_href.Page_and_anchor());
if (ns_allowed_regy.Count() > 0 && !ns_allowed_regy.Has(ns_allowed_regy_key.Val_(popup_ttl.Ns().Id()))) {Rslt_(Bry_.Empty); return;}
itm.Init(popup_wiki.Domain_bry(), popup_ttl);
Xoa_page popup_page = popup_wiki.Data_mgr().Get_page(popup_ttl, false);
byte[] rv = popup_wiki.Html_mgr().Module_mgr().Popup_mgr().Parser().Parse(wiki, popup_page, cur_page.Tab(), itm);
Xow_popup_mgr.Update_progress_bar(app, cur_page, itm);
Rslt_(rv);
}
catch(Exception e) {
app.Usr_dlg().Warn_many("", "", "failed to get popup: href=~{0} err=~{1}", String_.new_utf8_(itm.Page_href()), Err_.Message_gplx_brief(e));
Rslt_(null);
}
finally {
app.Thread_mgr().Page_load_mgr().Resume();
}
}
}

View File

@ -98,7 +98,7 @@ public class Xow_toc_mgr implements Bry_fmtr_arg {
trg.Add(Bry_list_end);
}
}
public static byte[] Toc_text(Xop_ctx ctx, Xoa_page page, byte[] src, Xop_hdr_tkn hdr) {
public static byte[] Toc_text(Xop_ctx ctx, Xoa_page page, byte[] src, Xop_tkn_itm hdr) {
try {
Xow_wiki wiki = page.Wiki();
Bry_bfr bfr = wiki.Utl_bry_bfr_mkr().Get_b128();

View File

@ -0,0 +1,61 @@
/*
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.pages; import gplx.*; import gplx.xowa.*;
import gplx.core.btries.*;
public class Xopg_tmpl_prepend_mgr {
private Bry_bfr[] stack = Bry_bfr_.Ary_empty; private int stack_len, stack_max;
public void Clear() {
stack = Bry_bfr_.Ary_empty; stack_len = stack_max = 0;
}
public boolean Tmpl_args_parsing() {return tmpl_args_parsing;} public void Tmpl_args_parsing_(boolean v) {tmpl_args_parsing = v;} private boolean tmpl_args_parsing;
public Xopg_tmpl_prepend_mgr Bgn(Bry_bfr bfr) {
int new_len = stack_len + 1;
if (new_len > stack_max) {
stack_max += 8;
Bry_bfr[] new_stack = new Bry_bfr[stack_max];
Array_.CopyTo(stack, new_stack, 0);
stack = new_stack;
}
stack[stack_len] = bfr;
stack_len = new_len;
return this;
}
public void End(Xop_ctx ctx, Bry_bfr bfr, byte[] val, int val_len, boolean called_from_tmpl) {
if ( val_len > 0 // val is not empty
&& tmpl_prepend_nl_trie.Match_bgn(val, 0, val_len) != null // val starts with {| : ; # *; REF.MW:Parser.php|braceSubstitution
) {
boolean add = true;
if (called_from_tmpl) { // called from tmpl
for (int i = stack_len - 1; i > -1; --i) { // iterate backwards over tmpl_stack;
Bry_bfr stack_bfr = stack[i];
switch (stack_bfr.Get_at_last_or_nil_if_empty()) {
case Byte_ascii.Nil: continue; // bfr is empty; ignore it
case Byte_ascii.NewLine: add = false; i = -1; break; // bfr ends in \n; don't add and stop; PAGE:bn.w:িওনল_মি |ko.w:도쿄_지하철_히비야_선|DATE:2014-05-27
default: i = -1; break; // bfr has char; stop
}
}
}
else // called from func arg; always add \n; EX:vi.w:Friedrich_II_của_Phổ; DATE:2014-04-26
add = true;
if (add)
bfr.Add_byte(Byte_ascii.NewLine);
}
if (called_from_tmpl) --stack_len;
}
private static final Btrie_fast_mgr tmpl_prepend_nl_trie = Xop_curly_bgn_lxr.tmpl_bgn_trie_();
}

View File

@ -67,6 +67,7 @@ class Xou_history_mgr_fxt {
byte[] ttl_bry = Bry_.new_utf8_(ttl_str);
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, ttl_bry);
Xoa_page page = Xoa_page.test_(wiki, ttl);
page.Revision_data().Modified_on_(DateAdp_.Now());
byte[] url_bry = ttl_bry;
if (arg_str != null) url_bry = Bry_.Add(url_bry, Bry_.new_utf8_(arg_str));
Xoa_url url = app.Url_parser().Parse(url_bry);

View File

@ -34,6 +34,7 @@ public class Xoa_wiki_mgr implements GfoInvkAble {
css_installer.Init_by_app(app);
}
public int Count() {return hash.Count();}
public void Del(byte[] key) {hash.Del(key);}
public Xow_wiki Get_at(int i) {return Int_.Between(i, 0, this.Count() - 1) ? (Xow_wiki)list.FetchAt(i) : null;}
public Xow_wiki Get_by_key_or_null(byte[] key) {return Bry_.Len_eq_0(key) ? null : (Xow_wiki)hash.Fetch(key);}
public Xow_wiki Get_by_key_or_null(byte[] src, int bgn, int end) {return (Xow_wiki)hash.Get_by_mid(src, bgn, end);}

View File

@ -22,7 +22,7 @@ public class Xow_page_cache {
public Xow_page_cache(Xow_wiki wiki) {this.wiki = wiki;}
public byte[] Get_or_load_as_src(Xoa_ttl ttl) {
Xow_page_cache_itm rv = Get_or_load_as_itm(ttl);
return rv == null ? null : rv.Src();
return rv == null ? null : rv.Wtxt();
}
public Xow_page_cache_itm Get_or_load_as_itm(Xoa_ttl ttl) {
byte[] ttl_full_db = ttl.Full_db();

View File

@ -17,12 +17,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
public class Xow_page_cache_itm {
public Xow_page_cache_itm(Xoa_ttl ttl, byte[] src, byte[] redirected_src) {
this.ttl = ttl; this.src = src;
this.redirected_src = redirected_src;
public Xow_page_cache_itm(Xoa_ttl ttl, byte[] wtxt, byte[] redirected_src_wtxt) {
this.ttl = ttl; this.wtxt = wtxt; this.redirected_src_wtxt = redirected_src_wtxt;
}
public Xoa_ttl Ttl() {return ttl;} private Xoa_ttl ttl;
public byte[] Src() {return src;} private byte[] src;
public byte[] Redirected_src() {return redirected_src;} private byte[] redirected_src;
public byte[] Wtxt() {return wtxt;} private byte[] wtxt;
public byte[] Redirected_src_wtxt() {return redirected_src_wtxt;} private byte[] redirected_src_wtxt;
public static final Xow_page_cache_itm Null = null;
}

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.xtns.flaggedRevs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.html.*; import gplx.xowa.pages.skins.*; import gplx.xowa.xtns.pfuncs.*;
public class Pages_using_pending_changes_func extends Pf_func_base {
@Override public int Id() {return Xol_kwd_grp_.Id_pagesUsingPendingChanges;}
@Override public Pf_func New(int id, byte[] name) {return new Pages_using_pending_changes_func().Name_(name);}
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) {
bfr.Add_int_fixed(0, 1);
}
public static final Pages_using_pending_changes_func _ = new Pages_using_pending_changes_func(); Pages_using_pending_changes_func() {}
}

View File

@ -0,0 +1,25 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.flaggedRevs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*; import gplx.xowa.pages.skins.*;
public class Pages_using_pending_changes_func_tst {
@Before public void init() {fxt.Reset();} private Xop_fxt fxt = new Xop_fxt();
@Test public void Basic() {
fxt.Test_html_full_str("{{PAGESUSINGPENDINGCHANGES}}", "0");
}
}

View File

@ -0,0 +1,25 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.flaggedRevs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.html.*; import gplx.xowa.pages.skins.*; import gplx.xowa.xtns.pfuncs.*;
public class Pending_change_level_func extends Pf_func_base {
@Override public int Id() {return Xol_kwd_grp_.Id_pendingChangeLevel;}
@Override public Pf_func New(int id, byte[] name) {return new Pending_change_level_func().Name_(name);}
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) {}// NOOP
public static final Pending_change_level_func _ = new Pending_change_level_func(); Pending_change_level_func() {}
}

View File

@ -0,0 +1,25 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.flaggedRevs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*; import gplx.xowa.pages.skins.*;
public class Pending_change_level_func_tst {
@Before public void init() {fxt.Reset();} private Xop_fxt fxt = new Xop_fxt();
@Test public void Basic() {
fxt.Test_html_full_str("{{PENDINGCHANGELEVEL}}", "");
}
}

View File

@ -125,7 +125,10 @@ public class Gallery_mgr_base_basic_tst {
@Test public void Link_is_empty() { // PURPOSE: "link=" causes null pointer exception; DATE:2014-06-15
fxt.Test_html_frag("<gallery>File:A.png|link=</gallery>", "href=\"/wiki/File:A.png\"");
}
// @Test public void Ttl_caption() { // PURPOSE: category entries get rendered with name only (no ns)
@Test public void Dangling_autcloses() { // PURPOSE: dangling gallery should auto-close, not escape; PAGE:en.w:Wikipedia:Featured_pictures_thumbs_43 DATE:2014-08-23
fxt.Test_html_frag("<gallery>File:A.png|b", "<ul id=\"xowa_gallery_ul_0\"");
}
// @Test public void Ttl_caption() { // TODO: category entries get rendered with name only (no ns)
// fxt.Test_html_frag
// ( "<gallery>Category:A</gallery>"
// , "<li class='gallerycaption'>B</li>"

View File

@ -66,7 +66,7 @@ class Imap_parser {
}
try {
if (itm_idx == 0)
Parse_img(rv, itm_bgn, itm_end);
itm_end = Parse_img(rv, itm_bgn, itm_end, src_end);
else {
Object tid_obj = tid_trie.Match_bgn_w_byte(b, src, itm_bgn, itm_end);
byte tid_val = tid_obj == null ? Imap_itm_.Tid_invalid : ((Byte_obj_val)tid_obj).Val();
@ -208,11 +208,12 @@ class Imap_parser {
pts.Add(Double_obj_val.new_(num));
return Bry_finder.Trim_fwd_space_tab(src, num_end, itm_end);
}
private void Parse_img(Imap_map imap, int itm_bgn, int itm_end) {
int pos = Bry_finder.Trim_fwd_space_tab(src, itm_bgn, itm_end);
imap_img_src = Bry_.Add(Xop_tkn_.Lnki_bgn, Bry_.Mid(src, pos, itm_end), Xop_tkn_.Lnki_end);
private int Parse_img(Imap_map imap, int itm_bgn, int itm_end, int src_end) {
int img_bgn = Bry_finder.Trim_fwd_space_tab(src, itm_bgn, itm_end); // trim ws
int img_end = Parse_img__get_img_end(itm_end, src_end);
imap_img_src = Bry_.Add(Xop_tkn_.Lnki_bgn, Bry_.Mid(src, img_bgn, img_end), Xop_tkn_.Lnki_end);
Xop_lnki_tkn lnki_tkn = (Xop_lnki_tkn)Parse_link(imap_img_src);
imap_img_src = imap_root.Data_mid(); // NOTE: need to re-set src to pick up templates; EX: <imagemap>File:A.png|thumb|{{Test_template}}\n</imagemap>; PAGE:en.w:Kilauea; DATE:2014-07-27
imap_img_src = imap_root.Data_mid(); // need to re-set src to pick up templates; EX: <imagemap>File:A.png|thumb|{{Test_template}}\n</imagemap>; PAGE:en.w:Kilauea; DATE:2014-07-27
Xop_lnki_logger file_wkr = wiki_ctx.Lnki().File_wkr(); // NOTE: do not do imap_ctx.Lnki(); imap_ctx is brand new
if (lnki_tkn == null)
imap_ctx.Wiki().App().Usr_dlg().Warn_many("", "", "image_map failed to find lnki; page=~{0} imageMap=~{1}", String_.new_utf8_(imap_ctx.Cur_page().Ttl().Full_txt()), String_.new_utf8_(imap_img_src));
@ -222,8 +223,33 @@ class Imap_parser {
wiki_ctx.Cur_page().Lnki_list().Add(lnki_tkn);
if (file_wkr != null) file_wkr.Wkr_exec(wiki_ctx, src, lnki_tkn, gplx.xowa.bldrs.files.Xob_lnki_src_tid.Tid_imageMap);
}
return img_end;
}
private static Btrie_slim_mgr tid_trie = Btrie_slim_mgr.ci_ascii_() // NOTE: names are not i18n'd; // NOTE:ci.ascii:MW_const.en
private int Parse_img__get_img_end(int line_end, int src_end) { // heuristic to handle images that span more than one line via ref; en.w:Archaea DATE:2014-08-22
int rv = line_end;
int pos = line_end + 1;
while (pos < src_end) {
pos = Bry_finder.Trim_fwd_space_tab(src, pos, src_end); // trim ws
if (pos == src_end) break;
byte b = src[pos];
if (b == Byte_ascii.NewLine) // new-line; end
break;
else {
Object tid_obj = tid_trie.Match_bgn_w_byte(b, src, pos, src_end);
if (tid_obj == null) { // not a known imap line; assume continuation of img line and skip to next line
imap_ctx.Wiki().App().Usr_dlg().Note_many("", "", "image_map extending image over multiple lines; page=~{0} imageMap=~{1}", String_.new_utf8_(imap_ctx.Cur_page().Ttl().Full_txt()), String_.new_utf8_(imap_img_src));
int next_line = Bry_finder.Find_fwd(src, Byte_ascii.NewLine, pos);
if (next_line == Bry_finder.Not_found) next_line = src_end;
rv = next_line;
pos = rv + 1;
}
else // known imap line; stop
break;
}
}
return rv;
}
private static Btrie_slim_mgr tid_trie = Btrie_slim_mgr.ci_ascii_() // names are not i18n'd; // NOTE:ci.ascii:MW_const.en
.Add_str_byte("desc" , Imap_itm_.Tid_desc)
.Add_str_byte("#" , Imap_itm_.Tid_comment)
.Add_bry_bval(Imap_itm_.Key_dflt , Imap_itm_.Tid_dflt)

View File

@ -198,6 +198,14 @@ public class Imap_xnde_html_all_tst {
, "</div>"
));
}
@Test public void Template_multi_line() { // PURPOSE: handle multiple-line captions; PAGE:en.w:Archaea; DATE:2014-08-22
fxt.Test_html_full_frag(String_.Concat_lines_nl_skip_last
( "<imagemap>"
, "File:A.png|thumb|<ref>text"
, "</ref>"
, "</imagemap>"
), "id=\"cite_ref-0\"");
}
}
class Imap_xnde_html_fxt {
public void Reset() {

View File

@ -205,7 +205,8 @@ public class Pf_func_ {
, Xol_kwd_grp_.Id_insider
, Xol_kwd_grp_.Id_massMessage_target
, Xol_kwd_grp_.Id_cascadingSources
, Xol_kwd_grp_.Id_pendingChangesLevel
, Xol_kwd_grp_.Id_pendingChangeLevel
, Xol_kwd_grp_.Id_pagesUsingPendingChanges
, Xol_kwd_grp_.Id_bang
};
public static Xot_defn Get_prototype(int id) {
@ -360,8 +361,10 @@ public class Pf_func_ {
case Xol_kwd_grp_.Id_massMessage_target: return gplx.xowa.xtns.massMessage.Message_target_func._;
case Xol_kwd_grp_.Id_pendingChangeLevel: return gplx.xowa.xtns.flaggedRevs.Pending_change_level_func._;
case Xol_kwd_grp_.Id_pagesUsingPendingChanges: return gplx.xowa.xtns.flaggedRevs.Pages_using_pending_changes_func._;
case Xol_kwd_grp_.Id_cascadingSources:
case Xol_kwd_grp_.Id_pendingChangesLevel:
return new Pf_func_noop(id);
case Xol_kwd_grp_.Id_bang: return Pf_func_bang._;
default: throw Err_mgr._.unhandled_(id);

View File

@ -16,18 +16,32 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.pfuncs.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.html.*;
public class Pfunc_displaytitle extends Pf_func_base {
@Override public int Id() {return Xol_kwd_grp_.Id_page_displaytitle;}
@Override public Pf_func New(int id, byte[] name) {return new Pfunc_displaytitle().Name_(name);}
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) {
byte[] val_dat_ary = Eval_argx(ctx, src, caller, self);
Xow_wiki wiki = ctx.Wiki(); Xop_parser parser = wiki.Parser();
Xop_ctx new_ctx = Xop_ctx.new_sub_(wiki);
Xop_root_tkn new_root = parser.Parse_text_to_wdom(new_ctx, val_dat_ary, false);
Xop_ctx display_ttl_ctx = Xop_ctx.new_sub_(wiki);
Xop_root_tkn display_ttl_root = parser.Parse_text_to_wdom(display_ttl_ctx, val_dat_ary, false);
Bry_bfr tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_b512();
wiki.Html_mgr().Html_wtr().Write_tkn(tmp_bfr, new_ctx, gplx.xowa.html.Xoh_wtr_ctx.Display_title, new_root.Data_mid(), new_root, 0, new_root);
byte[] val_html = tmp_bfr.Mkr_rls().XtoAryAndClear();
boolean restrict = wiki.Cfg_parser().Display_title_restrict();
Xoh_wtr_ctx hctx = restrict ? Xoh_wtr_ctx.Display_title : Xoh_wtr_ctx.Basic; // restrict removes certain HTML (display:none)
wiki.Html_mgr().Html_wtr().Write_tkn(tmp_bfr, display_ttl_ctx, hctx, display_ttl_root.Data_mid(), display_ttl_root, 0, display_ttl_root);
byte[] val_html = tmp_bfr.XtoAryAndClear();
if (restrict) { // restrict only allows displayTitles which have text similar to the pageTitle; PAGE:de.b:Kochbuch/_Druckversion; DATE:2014-08-18
Xoa_page page = ctx.Cur_page();
wiki.Html_mgr().Html_wtr().Write_tkn(tmp_bfr, display_ttl_ctx, Xoh_wtr_ctx.Alt, display_ttl_root.Data_mid(), display_ttl_root, 0, display_ttl_root);
byte[] val_html_as_text_only = tmp_bfr.XtoAryAndClear();
gplx.xowa.langs.cases.Xol_case_mgr case_mgr = wiki.Lang().Case_mgr();
val_html_as_text_only = case_mgr.Case_build_lower(val_html_as_text_only);
byte[] page_ttl_lc = case_mgr.Case_build_lower(page.Ttl().Page_txt());
if (!Bry_.Eq(val_html_as_text_only, page_ttl_lc))
val_html = null;
}
ctx.Cur_page().Html_data().Display_ttl_(val_html);
tmp_bfr.Mkr_rls();
}
public static final Pfunc_displaytitle _ = new Pfunc_displaytitle(); Pfunc_displaytitle() {}
}

View File

@ -19,22 +19,29 @@ package gplx.xowa.xtns.pfuncs.pages; import gplx.*; import gplx.xowa.*; import g
import org.junit.*;
public class Pfunc_displaytitle_tst {
@Before public void init() {fxt.Reset();} private Pfunc_displaytitle_fxt fxt = new Pfunc_displaytitle_fxt();
@Test public void Basic() {fxt.Test("{{DISPLAYTITLE:a}}" , "a");}
@Test public void Apos_italic() {fxt.Test("{{DISPLAYTITLE:''a''}}" , "<i>a</i>");}
@Test public void Basic() {fxt.Init_restrict(Bool_.N).Test("{{DISPLAYTITLE:B A}}" , "B A");}
@Test public void Apos_italic() {fxt.Init_restrict(Bool_.N).Test("{{DISPLAYTITLE:''B A''}}" , "<i>B A</i>");}
@Test public void Restrict_skip() {fxt.Init_restrict(Bool_.Y).Test("{{DISPLAYTITLE:B A}}" , null);} // PURPOSE: skip if text does not match title; PAGE:de.b:Kochbuch/_Druckversion; DATE:2014-08-18
@Test public void Restrict_keep_ci() {fxt.Init_restrict(Bool_.Y).Test("{{DISPLAYTITLE:a B}}" , "a B");} // PURPOSE: keep b/c case-insensitiv match; DATE:2014-08-18
@Test public void Restrict_keep_tags() {fxt.Init_restrict(Bool_.Y).Test("{{DISPLAYTITLE:<b>a</b> <i>B</i>}}" , "<b>a</b> <i>B</i>");}// PURPOSE: keep b/c text match (tags ignored); DATE:2014-08-18
@Test public void Strip_display() {
String expd_fail = "<span style='/* attempt to bypass $wgRestrictDisplayTitle */'>a</span>";
fxt.Test("{{DISPLAYTITLE:<span style='display:none;'>a</span>}}" , expd_fail);
fxt.Test("{{DISPLAYTITLE:<span style='user-select:n;'>a</span>}}" , expd_fail);
fxt.Test("{{DISPLAYTITLE:<span style='visibility:n;'>a</span>}}" , expd_fail);
fxt.Test("{{DISPLAYTITLE:<span style=''>display:none</span>}}" , "<span style=''>display:none</span>");
String expd_fail = "<span style='/* attempt to bypass $wgRestrictDisplayTitle */'>A b</span>";
fxt.Init_restrict(Bool_.Y);
fxt.Test("{{DISPLAYTITLE:<span style='display:none;'>A b</span>}}" , expd_fail);
fxt.Test("{{DISPLAYTITLE:<span style='user-select:n;'>A b</span>}}" , expd_fail);
fxt.Test("{{DISPLAYTITLE:<span style='visibility:n;'>A b</span>}}" , expd_fail);
fxt.Test("{{DISPLAYTITLE:<span style=''>display:none</span>}}" , null);
}
}
class Pfunc_displaytitle_fxt {
private Xop_fxt fxt = new Xop_fxt();
public void Reset() {
fxt.Reset();
fxt.Page_ttl_("A b");
}
public Pfunc_displaytitle_fxt Init_restrict(boolean v) {fxt.Wiki().Cfg_parser().Display_title_restrict_(v); return this;}
public void Test(String raw, String expd) {
fxt.Page().Html_data().Display_ttl_(null); // TEST: always reset; needed for Strip_display which calls multiple times
fxt.Test_parse_tmpl_str_test(raw, "{{test}}", "");
Tfds.Eq(expd, String_.new_utf8_(fxt.Page().Html_data().Display_ttl()));
}

View File

@ -21,5 +21,4 @@ public class Pfunc_misc_tst {
private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();}
@Test public void CascadingSources() {fxt.Test_parse_page_all_str("{{CASCADINGSOURCES}}", "");} // PURPOSE: noop; DATE:2014-04-09
@Test public void PendingChangesLevel() {fxt.Test_parse_page_all_str("{{PENDINGCHANGESLEVEL}}", "");} // PURPOSE: noop; DATE:2014-04-09
}

View File

@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.proofreadPage; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.html.*; import gplx.xowa.parsers.amps.*;
import gplx.xowa.xtns.lst.*;
import gplx.xowa.xtns.lst.*; import gplx.xowa.pages.*;
public class Pp_pages_nde implements Xox_xnde, Xop_xnde_atr_parser {
private boolean xtn_literal = false;
private Xop_root_tkn xtn_root;
@ -345,8 +345,9 @@ public class Pp_pages_nde implements Xox_xnde, Xop_xnde_atr_parser {
if (end_sect_bry != null)
cur_sect_end = end_sect_bry;
}
Xopg_tmpl_prepend_mgr prepend_mgr = ctx.Cur_page().Tmpl_prepend_mgr().Bgn(full_bfr);
lst_pfunc_wkr.Init_include(ttl.Full_db(), cur_sect_bgn, cur_sect_end).Exec(page_bfr, ctx);
ctx.Tmpl_prepend_nl(full_bfr, page_bfr.Bfr(), page_bfr.Len());
prepend_mgr.End(ctx, full_bfr, page_bfr.Bfr(), page_bfr.Len(), Bool_.Y);
full_bfr.Add_bfr_and_clear(page_bfr);
full_bfr.Add(gplx.html.Html_entity_.Space_bry);
}

View File

@ -137,13 +137,13 @@ public class Scrib_lib_title implements Scrib_lib {
Xow_page_cache_itm page_itm = wiki.Cache_mgr().Page_cache().Get_or_load_as_itm(ttl);
byte[] rv = null;
if (page_itm != null) {
byte[] redirected_src = page_itm.Redirected_src();
byte[] redirected_src = page_itm.Redirected_src_wtxt();
if (redirected_src != null) { // page is redirect; use its src, not its target's src; DATE:2014-07-11
rv = redirected_src;
core.Frame_parent().Rslt_is_redirect_(true); // flag frame as redirect, so that \n won't be prepended; EX:"#REDIRECT" x> "\n#REDIRECT"
}
else
rv = page_itm.Src();
rv = page_itm.Wtxt();
}
return rv == null ? rslt.Init_obj(null) : rslt.Init_obj(String_.new_utf8_(rv));
}

View File

@ -128,9 +128,9 @@ public class Xow_wiki implements GfoInvkAble {
file_mgr.Meta_mgr().Clear();
db_mgr.Load_mgr().Clear();
}
public Xoa_page GetPageByTtl(Xoa_url url, Xoa_ttl ttl) {return GetPageByTtl(url, ttl, lang, app.Gui_mgr().Browser_win().Active_tab());}
public Xoa_page GetPageByTtl(Xoa_url url, Xoa_ttl ttl, Xog_tab_itm tab) {return GetPageByTtl(url, ttl, lang, tab);}
private Xoa_page GetPageByTtl(Xoa_url url, Xoa_ttl ttl, Xol_lang lang, Xog_tab_itm tab) {
public Xoa_page GetPageByTtl(Xoa_url url, Xoa_ttl ttl) {return GetPageByTtl(url, ttl, lang, app.Gui_mgr().Browser_win().Active_tab(), true);}
public Xoa_page GetPageByTtl(Xoa_url url, Xoa_ttl ttl, Xog_tab_itm tab) {return GetPageByTtl(url, ttl, lang, tab, true);}
public Xoa_page GetPageByTtl(Xoa_url url, Xoa_ttl ttl, Xol_lang lang, Xog_tab_itm tab, boolean parse_page) {
if (init_needed) Init_wiki(app.User());
Xoa_page page = data_mgr.Get_page(url, ttl, false, false); // get page from data_mgr
if (page.Missing()) { // page doesn't exist
@ -138,7 +138,7 @@ public class Xow_wiki implements GfoInvkAble {
Xow_wiki commons_wiki = app.Wiki_mgr().Get_by_key_or_null(commons_wiki_key);
if (commons_wiki != null
&& !Bry_.Eq(domain_bry, commons_wiki.Domain_bry())) // if file, check commons wiki; note that !Bry_.Eq is recursion guard
return commons_wiki.GetPageByTtl(url, ttl, this.lang, tab);
return commons_wiki.GetPageByTtl(url, ttl, this.lang, tab, true);
}
else
return page.Missing_();
@ -146,15 +146,14 @@ public class Xow_wiki implements GfoInvkAble {
if (page.Missing()) return page; // NOTE: commons can return null page
page.Tab_(tab);
page.Lang_(lang);
gplx.xowa.xtns.scribunto.Scrib_core.Core_page_changed(page); // notify scribunto about page changed
if (parse_page)
ParsePage(page, false); // NOTE: do not clear page b/c reused for search
return page;
}
public void ParsePage_root(Xoa_page page, boolean clear) {
ParsePage(page, clear);
}
public void ParsePage_root(Xoa_page page, boolean clear) {ParsePage(page, clear);}
public void ParsePage(Xoa_page page, boolean clear) {
if (init_needed && !Env_.Mode_testing()) Init_wiki(app.User());
gplx.xowa.xtns.scribunto.Scrib_core.Core_page_changed(page); // notify scribunto about page changed
ctx.Cur_page_(page);
Xop_root_tkn root = ctx.Tkn_mkr().Root(page.Data_raw());
if (clear) {page.Clear();}
@ -224,8 +223,9 @@ public class Xow_wiki implements GfoInvkAble {
if (sqlite_url != null) {
Xodb_mgr_sql db_mgr_sql = this.Db_mgr_create_as_sql();
db_mgr_sql.Init_load(gplx.dbs.Db_connect_.sqlite_(sqlite_url));
db_mgr_sql.Html_mgr().Enabled_(hdump_enabled);
db_mgr_sql.Html_db_enabled_(hdump_enabled);
}
if (!Xob_import_marker.Check(this)) {app.Wiki_mgr().Del(domain_bry); init_needed = false; return;} // NOTE: must call after Db_mgr_create_as_sql(); also, must delete wiki from mgr; DATE:2014-08-24
db_mgr.Load_mgr().Load_init(this);
app.Gfs_mgr().Run_url_for(this, fsys_mgr.Cfg_wiki_core_fil());
gplx.xowa.utls.upgrades.Xoa_upgrade_mgr.Check(this);

View File

@ -21,12 +21,16 @@ public class Xowc_parser implements GfoInvkAble {
public Xowc_parser(Xow_wiki wiki) {
lnki_cfg = new Xoc_lnki_cfg(wiki);
}
public boolean Flag_xtns_pages_init() {return flag_xtns_pages_init;} public Xowc_parser Flag_xtns_pages_init_(boolean v) {flag_xtns_pages_init = v; return this;} private boolean flag_xtns_pages_init = true;
public Xoc_lnki_cfg Lnki_cfg() {return lnki_cfg;} private Xoc_lnki_cfg lnki_cfg;
public Xowc_xtns Xtns() {return xtns;} private Xowc_xtns xtns = new Xowc_xtns();
public boolean Display_title_restrict() {return display_title_restrict;} public void Display_title_restrict_(boolean v) {display_title_restrict = v;} private boolean display_title_restrict = true;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_xtns)) return xtns;
else if (ctx.Match(k, Invk_lnki)) return lnki_cfg;
else if (ctx.Match(k, Invk_display_title_restrict)) return display_title_restrict;
else if (ctx.Match(k, Invk_display_title_restrict_)) display_title_restrict = m.ReadYn("v");
else return GfoInvkAble_.Rv_unhandled;
} private static final String Invk_xtns = "xtns", Invk_lnki = "lnki";
return this;
}
private static final String Invk_xtns = "xtns", Invk_lnki = "lnki", Invk_display_title_restrict = "display_title_restrict", Invk_display_title_restrict_ = "display_title_restrict_";
}

View File

@ -28,6 +28,7 @@ public class Xodb_page implements Xobl_data_itm {
public boolean Exists() {return exists;} public Xodb_page Exists_(boolean v) {exists = v; return this;} private boolean exists;
public int Db_file_idx() {return db_file_idx;} public Xodb_page Db_file_idx_(int v) {db_file_idx = v; return this;} private int db_file_idx;
public int Db_row_idx() {return db_row_idx;} public Xodb_page Db_row_idx_(int v) {db_row_idx = v; return this;} private int db_row_idx;
public int Html_db_id() {return html_db_id;} public Xodb_page Html_db_id_(int v) {html_db_id = v; return this;} private int html_db_id;
public DateAdp Modified_on() {return modified_on;} public Xodb_page Modified_on_(DateAdp v) {modified_on = v; return this;} DateAdp modified_on;
public Xow_ns Ns() {return ns;} private Xow_ns ns;
public Object Xtn() {return xtn;} public Xodb_page Xtn_(Object v) {this.xtn = v; return this;} Object xtn;
@ -69,6 +70,7 @@ public class Xodb_page implements Xobl_data_itm {
type_redirect = exists = false;
modified_on = DateAdp_.MinValue;
id_val = null;
html_db_id = -1;
}
public void Copy(Xodb_page orig) {
this.id = orig.id;
@ -84,6 +86,7 @@ public class Xodb_page implements Xobl_data_itm {
this.exists = orig.exists;
this.modified_on = orig.modified_on;
this.id_val = null;
this.html_db_id = orig.html_db_id;
}
public Xodb_page Set_all_(int id, int db_file_idx, int db_row_idx, boolean redirect, int text_len, byte[] ttl_wo_ns) {
this.id = id; this.db_file_idx = db_file_idx; this.db_row_idx = db_row_idx; this.type_redirect = redirect; this.text_len = text_len; this.ttl_wo_ns = ttl_wo_ns;

View File

@ -19,10 +19,9 @@ package gplx.xowa; import gplx.*;
import gplx.lists.*; /*ComparerAble*/ import gplx.xowa.bldrs.imports.ctgs.*;
import gplx.xowa.dbs.*; import gplx.xowa.wikis.*; import gplx.xowa.langs.msgs.*;
public class Xow_data_mgr implements GfoInvkAble {
public Xow_data_mgr(Xow_wiki wiki) {
this.wiki = wiki; this.redirect_mgr = wiki.Redirect_mgr();
} private Xop_redirect_mgr redirect_mgr;
private Xop_redirect_mgr redirect_mgr;
private Xoa_url tmp_url = Xoa_url.blank_();
public Xow_data_mgr(Xow_wiki wiki) {this.wiki = wiki; this.redirect_mgr = wiki.Redirect_mgr();}
public Xow_wiki Wiki() {return wiki;} private Xow_wiki wiki;
public Xoa_page Get_page(Xoa_ttl ttl, boolean called_from_tmpl) {wiki.App().Url_parser().Parse(tmp_url, ttl.Raw()); return Get_page(tmp_url, ttl, called_from_tmpl, false);}
public Xoa_page Get_page_from_msg(Xoa_ttl ttl) {wiki.App().Url_parser().Parse(tmp_url, ttl.Raw()); return Get_page(tmp_url, ttl, false, true);}
@ -60,7 +59,7 @@ public class Xow_data_mgr implements GfoInvkAble {
wiki.App().Gui_wtr().Prog_many(GRP_KEY, "file_load", "loading page for ~{0}", String_.new_utf8_(ttl.Raw()));
wiki.Db_mgr().Load_mgr().Load_page(db_page, ns, !called_from_tmpl);
byte[] bry = db_page.Text();
rv.Data_raw_(bry).Revision_data().Modified_on_(db_page.Modified_on()).Id_(db_page.Id());
rv.Data_raw_(bry).Revision_data().Modified_on_(db_page.Modified_on()).Id_(db_page.Id()).Html_db_id_(db_page.Html_db_id());
if (redirect_force) return rv;
Xoa_ttl redirect_ttl = redirect_mgr.Extract_redirect(bry, bry.length);
if ( redirect_ttl == null // not a redirect

View File

@ -206,10 +206,11 @@ public static final int
, Id_insider = 185
, Id_massMessage_target = 186
, Id_cascadingSources = 187
, Id_pendingChangesLevel = 188
, Id_bang = 189
, Id_pendingChangeLevel = 188
, Id_pagesUsingPendingChanges = 189
, Id_bang = 190
;
public static final int Id__max = 190;
public static final int Id__max = 191;
private static byte[] ary_itm_(int id) {
switch (id) {
@ -401,7 +402,8 @@ case Xol_kwd_grp_.Id_relatedArticles: return Bry_.new_utf8_("relatedArticles");
case Xol_kwd_grp_.Id_insider: return Bry_.new_utf8_("insider");
case Xol_kwd_grp_.Id_massMessage_target: return Bry_.new_utf8_("target");
case Xol_kwd_grp_.Id_cascadingSources: return Bry_.new_utf8_("cascadingSources");
case Xol_kwd_grp_.Id_pendingChangesLevel: return Bry_.new_utf8_("pendingChangesLevel");
case Xol_kwd_grp_.Id_pendingChangeLevel: return Bry_.new_utf8_("pendingChangeLevel");
case Xol_kwd_grp_.Id_pagesUsingPendingChanges: return Bry_.new_utf8_("pagesUsingPendingChanges");
case Xol_kwd_grp_.Id_bang: return Bry_.new_utf8_("!");
default: throw Err_mgr._.unhandled_(id);
}

View File

@ -234,7 +234,8 @@ kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_relatedArticles , "#related");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_insider , "#insider");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_massMessage_target , "#target");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_cascadingSources , "CASCADINGSOURCES");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_pendingChangesLevel , "PENDINGCHANGESLEVEL");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_pendingChangeLevel , "PENDINGCHANGELEVEL");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_pagesUsingPendingChanges , "PAGESUSINGPENDINGCHANGES");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_bang , "!");
}
}

View File

@ -1,163 +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/>.
*/
//namespace gplx.xowa {
// using gplx.xowa.bldrs; using gplx.xowa.wikis.caches; using gplx.xowa.parsers.lnkis; using gplx.xowa.xtns.pfuncs.ifs;
// public class Xobc_parse_run : Xob_itm_basic_base, Xob_cmd, GfoInvkAble {
// public Xobc_parse_run(Xob_bldr bldr, Xow_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
// public String Cmd_key() {return KEY;} public static final String KEY = "parse.run";
// public void Cmd_ini(Xob_bldr bldr) {}
// public void Cmd_bgn(Xob_bldr bldr) {
// Xow_ns_mgr_.rebuild_(wiki.Lang(), wiki.Ns_mgr()); // rebuild; different lang will change namespaces; EX: de.wikisource.org will have Seite for File and none of {{#lst}} will work
// ctx = wiki.Ctx(); parser = wiki.Parser();
// msg_log = ctx.Msg_log();
// log_dump = new Xoad_wtr_dump(bldr.App().Fsys_mgr().Temp_dir().GenSubDir("parser_dump"));
// root = ctx.Tkn_mkr().Root(Bry_.Empty);
// img_dump = new Xobc_lnki_wkr_file(bldr, wiki);
// ctx.Lnki().File_wkr_(img_dump);
// math_dump = new Xobc_xnde_math_dump(bldr, wiki);
// math_dump.Wkr_bgn(bldr);
// ctg_dump = new Xobc_lnki_wkr_ctg(bldr, wiki);
// ctx.Xnde().File_wkr_(math_dump);
// ctx.Tmpl_load_enabled_(false);
// if (tmpl_on) Tmpl_load(wiki);
// img_dump.Wkr_bgn(bldr);
// cur_ns = wiki.Ns_mgr().Ns_main();
// redirect_mgr = wiki.Redirect_mgr();
// Xot_invk_tkn.Cache_enabled = true;
// bldr.App().Wiki_mgr().Wdata_mgr().Enabled_(false);
// } private Xop_parser parser; Xop_ctx ctx; Gfo_msg_log msg_log; Xoad_wtr_dump log_dump; Xop_root_tkn root;
// public boolean Tmpl_on() {return tmpl_on;} public Xobc_parse_run Tmpl_on_(boolean v) {tmpl_on = v; return this;} private boolean tmpl_on;
//// Xobc_lnki_wkr_file img_dump; Xobc_xnde_math_dump math_dump; Xobc_lnki_wkr_ctg ctg_dump;
// public void Cmd_run() {
// raw_parser.Init(bldr.Usr_dlg(), wiki, load_len);
//// compress_max = 50;
//// Parse_ns(wiki.Ns_mgr().Get_by_id(Xow_ns_.Id_help));
// compress_max = 10;
// Parse_ns(wiki.Ns_mgr().Ns_main());
// compress_max = 5;
// Parse_ns(wiki.Ns_mgr().Ns_category());
// compress_max = 20;
// Parse_ns(wiki.Ns_mgr().Ns_template());
//// ConsoleAdp._.WriteLine(Int_.XtoStr(Pfunc_ifexist.Count));
// }
// public void Cmd_end() {
// img_dump.Wkr_end();
// math_dump.Wkr_end();
// wiki.Cache_mgr().Free_mem_all();
// }
// public void Cmd_print() {}
// private void Parse_ns(Xow_ns ns) {
// cur_ns = ns;
// Io_url ns_dir = wiki.Fsys_mgr().Ns_dir().GenSubDir_nest(ns.Num_str(), Xow_dir_info_.Name_page);
// raw_parser.Init_ns(ns);
// ns_is_tmpl = ns.Id() == Xow_ns_.Id_template;
// Parse_dir(ns_dir);
// Free();
// log_dump.Flush();
// } boolean ns_is_tmpl; int compress_max = 20, compress_idx = 0; Xow_ns cur_ns;
// private void Parse_dir(Io_url dir) {
// Io_url[] itms = Io_mgr._.QueryDir_args(dir).DirInclude_().ExecAsUrlAry();
// bldr.Usr_dlg().Prog_many(GRP_KEY, "load_dir", "loading dir: ~{0}", dir.NameAndExt());
// int itms_len = itms.length;
// for (int i = 0; i < itms_len; i++) {
// Io_url itm = itms[i];
// if (itm.Type_dir()) Parse_dir(itm);
// else Parse_fil(itm);
// }
// }
// private void Parse_fil(Io_url fil) {
//// if (String_.Compare(fil.NameOnly(), "0000000927") <= CompareAble_.Same) return;
// raw_parser.Reset_one(fil);
// while (raw_parser.Read(raw_page)) {
// Parse_page(raw_page);
// }
// if (++compress_idx >= compress_max) {
// Free();
// compress_idx = 0;
//// Io_mgr._.AppendFilStr("C:\\dump.txt", Xop_xnde_wkr.TEMP_TIMELINE.XtoStrAndClear());
// }
// } private Xodb_page_raw_parser raw_parser = new Xodb_page_raw_parser(); Xodb_page raw_page = new Xodb_page();
// private void Free() {
// ctx.App().Free_mem(true);
// gplx.xowa.xtns.scribunto.Scrib_core.Core_invalidate();
// Env_.GarbageCollect();
//// Tfds.Write(ctx.App().Tmpl_result_cache().Count());
// }
// public void Parse_page(Xodb_page xml_page) {
// byte[] src = xml_page.Text(), ttl_bry = xml_page.Ttl_w_ns();
//// Io_mgr._.AppendFilStr("C:\\dump.txt", String_.new_utf8_(ttl_bry) + "\n");
//// if (String_.Eq(String_.new_utf8_(ttl_bry), "en:Iowa"))
//// Tfds.Write();
//// Tfds.Write(String_.new_utf8_(ttl_bry));
// if (cur_ns.Id() != Xow_ns_.Id_main) // add ns to ttl_bry; EX: A -> Category:A
// ttl_bry = Bry_.Add(cur_ns.Name_db_w_colon(), ttl_bry);
// ctx.Cur_page().Ttl_(Xoa_ttl.parse_(wiki, ttl_bry));
// try {
// msg_log.Clear();
// if (ns_is_tmpl)
// parser.Parse_text_to_defn_obj(ctx, ctx.Tkn_mkr(), wiki.Ns_mgr().Ns_template(), ttl_bry, src);
// else {
// parser.Parse_page_all_clear(root, ctx, ctx.Tkn_mkr(), src);
// root.Clear();
// }
// pageCount++;
// redirect_mgr.Extract_redirect(src, src.length);
// if (msg_log.Ary_len() > 0) {
// pageError++;
// log_dump.Write(ttl_bry, pageCount, ctx.Msg_log());
// }
// if (ctx.Wiki().Cache_mgr().Tmpl_result_cache().Count() > 50000) {
//// sm.Write_info("clearing tmpls");
// ctx.Wiki().Cache_mgr().Tmpl_result_cache().Clear();
// }
// ctx.App().Utl_bry_bfr_mkr().Clear_fail_check();
// }
// catch (Exception exc) {
// bldr.Usr_dlg().Warn_many(GRP_KEY, "parse", "failed to parse ~{0} error ~{1}", ctx.Cur_page().Url().Xto_full_str_safe(), Err_.Message_gplx_brief(exc));
// ctx.App().Utl_bry_bfr_mkr().Clear();
// }
// } private Xop_redirect_mgr redirect_mgr;
// private void Tmpl_load(Xow_wiki wiki) {
// Xodb_page_raw_parser raw_parser = new Xodb_page_raw_parser();
// Io_url dir = wiki.Fsys_mgr().Tmp_dir().GenSubDir_nest(Xobc_parse_dump_templates.KEY, "dump");
// Io_url[] urls = Io_mgr._.QueryDir_fils(dir);
// if (urls.length == 0) {
// bldr.Usr_dlg().Note_many(GRP_KEY, "tmpl_load", "no templates found: ~{0}", dir.Raw());
// return;
// }
// Xow_ns ns_tmpl = wiki.Ns_mgr().Ns_template();
// raw_parser.Load(bldr.Usr_dlg(), wiki, ns_tmpl, urls, load_len);
// Xodb_page xml_page = new Xodb_page();
// Xow_defn_cache tmpl_regy = wiki.Cache_mgr().Defn_cache();
// while (raw_parser.Read(xml_page)) {
// Xot_defn_tmpl defn = new Xot_defn_tmpl();
// defn.Init_by_new(ns_tmpl, xml_page.Ttl_w_ns(), xml_page.Text(), null, false); // NOTE: passing null, false; will be overriden later when Parse is called
// tmpl_regy.Add(defn, ns_tmpl.Case_match() );
// }
// bldr.Usr_dlg().Prog_none(GRP_KEY, "done", "tmpl_load done");
// }
// public override Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
// if (ctx.Match(k, Invk_templates_on_)) tmpl_on = m.ReadBoolOrFalse("v");
// else return super.Invk(ctx, ikey, k, m);
// return this;
// } private static final String Invk_templates_on_ = "templates_on_";
// public int Load_len() {return load_len;} public Xobc_parse_run Load_len_(int v) {load_len = v; return this;} private int load_len = Io_mgr.Len_mb;
// public static int pageCount; int pageError;
// static final String GRP_KEY = "xowa.bldr.parse";
// }
//}

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.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.html.modules.popups.*; import gplx.xowa.dbs.hdumps.*;
import gplx.xowa.html.modules.popups.*; import gplx.xowa.hdumps.pages.*;
public class Xoa_page {
Xoa_page(Xow_wiki wiki, Xoa_ttl ttl) {
this.wiki = wiki; this.ttl = ttl;
@ -58,6 +58,7 @@ public class Xoa_page {
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 Xopg_tmpl_prepend_mgr Tmpl_prepend_mgr() {return tmpl_prepend_mgr;} private Xopg_tmpl_prepend_mgr tmpl_prepend_mgr = new Xopg_tmpl_prepend_mgr();
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++) {
@ -90,6 +91,8 @@ public class Xoa_page {
tmpl_stack_ary = Bry_.Ary_empty;
tmpl_stack_ary_len = tmpl_stack_ary_max = 0;
popup_mgr.Clear();
revision_data.Clear();
tmpl_prepend_mgr.Clear();
}
public static final Xoa_page Empty = new Xoa_page().Missing_();
public static final Xoa_page Null = null;

View File

@ -18,7 +18,10 @@ 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 DateAdp Modified_on() {return modified_on;} public Xoa_revision_data Modified_on_(DateAdp v) {modified_on = v; return this;} private DateAdp modified_on = DateAdp_.MinValue;
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;
public int Html_db_id() {return html_db_id;} public void Html_db_id_(int v) {html_db_id = v;} private int html_db_id = -1;
public void Clear() {// NOTE: do not clear data b/c saving in Edit will call clear and id will be reset to 0
}
}

View File

@ -51,7 +51,7 @@ public class Xop_ctx {
public int Tmpl_tkn_max() {return tmpl_tkn_max;} public void Tmpl_tkn_max_(int v) {tmpl_tkn_max = v;} private int tmpl_tkn_max = Int_.MaxValue;
public Xop_keeplist_wiki Tmpl_keeplist() {return tmpl_keeplist;} public void Tmpl_keeplist_(Xop_keeplist_wiki v) {this.tmpl_keeplist = v;} private Xop_keeplist_wiki tmpl_keeplist;
public boolean Tmpl_args_parsing() {return tmpl_args_parsing;} public Xop_ctx Tmpl_args_parsing_(boolean v) {tmpl_args_parsing = v; return this;} private boolean tmpl_args_parsing;
public Bry_bfr Tmpl_output() {return tmpl_output;} public Xop_ctx Tmpl_output_(Bry_bfr v) {tmpl_output = v; return this;} private Bry_bfr tmpl_output;
public Bry_bfr Tmpl_output() {return tmpl_output;} public Xop_ctx Tmpl_output_(Bry_bfr v) {tmpl_output = v; return this;} private Bry_bfr tmpl_output; // OBSOLETE: after tmpl_prepend_nl rewrite; DATE:2014-08-21
public Xot_defn_trace Defn_trace() {return defn_trace;} public Xop_ctx Defn_trace_(Xot_defn_trace v) {defn_trace = v; return this;} private Xot_defn_trace defn_trace = Xot_defn_trace_null._;
public boolean Only_include_evaluate() {return only_include_evaluate;} public Xop_ctx Only_include_evaluate_(boolean v) {only_include_evaluate = v; return this;} private boolean only_include_evaluate;
public Lst_section_nde_mgr Lst_section_mgr() {if (lst_section_mgr == null) lst_section_mgr = new Lst_section_nde_mgr(); return lst_section_mgr;} private Lst_section_nde_mgr lst_section_mgr;
@ -298,22 +298,6 @@ public class Xop_ctx {
if (stack_pos == -1) return;
ctx.Stack_pop_til(root, src, stack_pos, true, bgn_pos, cur_pos, Xop_tkn_itm_.Tid_txt);
}
public void Tmpl_prepend_nl(Bry_bfr cur, byte[] val, int val_len) { // cur=current bfr; tmpl_output=main bfr that cur will eventually be appended to; val=result of template
if ( val_len == 0 // val is empty
|| cur.Match_end_byt(Byte_ascii.NewLine) // if cur has \n already, don't add; bn.w:িওনল_মি |ko.w:도쿄_지하철_히비야_선|DATE:2014-05-27
|| tmpl_prepend_nl_trie.Match_bgn(val, 0, val_len) == null // val does not start with {| : ; # *; REF.MW:Parser.php|braceSubstitution
) return;
Bry_bfr prv_bfr = cur.Len() == 0 // note that cur_bfr should be checked first before tmpl_output
? tmpl_output // main template bfr
: cur // current bfr, which may be localized to within a template; see prepend tests
;
if ( tmpl_args_parsing // if processing template args, always add \n; EX:vi.w:Friedrich_II_của_Phổ; DATE:2014-04-26
|| ( prv_bfr != null // note that prv_bfr can be null when called from a subparse, as in Scrib.Preprocess; EX:w:Portal:Canada; DATE:2014-02-13
&& !prv_bfr.Match_end_byt(Byte_ascii.NewLine)) // previous char is not \n;
) {
cur.Add_byte(Byte_ascii.NewLine);
}
} private static final Btrie_fast_mgr tmpl_prepend_nl_trie = Xop_curly_bgn_lxr.tmpl_bgn_trie_();
public static Xop_ctx new_(Xow_wiki wiki) {
Xop_ctx rv = new Xop_ctx(wiki, Xoa_page.new_(wiki, Xoa_ttl.parse_(wiki, Xoa_page_.Main_page_bry))); // HACK: use "Main_Page" to put in valid page title
return rv;

View File

@ -60,6 +60,7 @@ public class Xop_fxt {
wiki.Db_mgr().Load_mgr().Clear();
app.Wiki_mgr().Clear();
Io_mgr._.InitEngine_mem(); // clear created pages
wiki.Cfg_parser().Display_title_restrict_(false); // default to false, as a small number of tests assume restrict = false;
return this;
}
public Xop_fxt Reset_for_msgs() {
@ -226,6 +227,12 @@ public class Xop_fxt {
Tfds.Eq(expd, String_.new_utf8_(actl));
tst_Log_check();
}
public Xop_root_tkn Test_parse_page_tmpl_tkn(String raw) {
byte[] raw_bry = Bry_.new_utf8_(raw);
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
parser.Parse_text_to_wtxt(root, ctx, tkn_mkr, raw_bry);
return root;
}
public void Test_parse_page_tmpl(String raw, Tst_chkr... expd_ary) {
byte[] raw_bry = Bry_.new_utf8_(raw);
Xop_root_tkn root = tkn_mkr.Root(raw_bry);

View File

@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa; import gplx.*;
import gplx.xowa.html.*;
public class Xop_redirect_mgr {
private Hash_adp_bry redirect_hash;
public Xop_redirect_mgr(Xow_wiki wiki) {this.wiki = wiki;} private Xow_wiki wiki;
private final Xow_wiki wiki; private final Url_encoder url_decoder; private Hash_adp_bry redirect_hash;
public Xop_redirect_mgr(Xow_wiki wiki) {this.wiki = wiki; this.url_decoder = wiki.App().Encoder_mgr().Url_ttl();} // NOTE: must be Url_ttl, not Url; PAGE:en.w:Template:Positionskarte+ -> Template:Location_map+, not Template:Location_map DATE:2014-08-21
public void Clear() {redirect_hash = null;} // TEST:
public boolean Is_redirect(byte[] text, int text_len) {return this.Extract_redirect(text, text_len) != null;}
public Xoa_ttl Extract_redirect_loop(byte[] src) {
@ -45,8 +45,9 @@ public class Xop_redirect_mgr {
ttl_bgn += Xop_tkn_.Lnki_bgn.length;
int ttl_end = Bry_finder.Find_fwd(src, Xop_tkn_.Lnki_end, ttl_bgn);
if (ttl_end == Bry_.NotFound) return Redirect_null_ttl;
byte[] redirect_ary = Bry_.Mid(src, ttl_bgn, ttl_end);
return Xoa_ttl.parse_(wiki, redirect_ary);
byte[] redirect_bry = Bry_.Mid(src, ttl_bgn, ttl_end);
redirect_bry = url_decoder.Decode(redirect_bry); // NOTE: url-decode links; PAGE: en.w:Watcher_(Buffy_the_Vampire_Slayer); DATE:2014-08-18
return Xoa_ttl.parse_(wiki, redirect_bry);
}
public static final Xoa_ttl Extract_redirect_is_null = null;
public static final int Redirect_max_allowed = 4;

View File

@ -34,6 +34,11 @@ public class Xop_redirect_mgr_tst {
fxt.Test_redirect("#перенаправление [[A]]", "A");
fxt.Test_redirect("#ПЕРЕНАПРАВЛЕНИЕ [[A]]", "A");
}
@Test public void Url_decode() {fxt.Test_redirect("#REDIRECT [[A%28B%29]]" , "A(B)");} // PURPOSE: url-decode links; PAGE:en.w:Watcher_(Buffy_the_Vampire_Slayer); DATE:2014-08-18
@Test public void Url_decode_plus() {fxt.Test_redirect("#REDIRECT [[A%28B%29+]]", "A(B)+");} // PURPOSE: do not url-decode +; PAGE:en.w:Template:Positionskarte+; DATE:2014-08-22
@Test public void Frame_ttl() { // PURPOSE: redirect should set invk frame title to redirect_trg, not original; PAGE:en.w:Statutory_city DATE:2014-08-22
fxt.Test_frame_ttl("Template:A", "#REDIRECT [[Template:B]]", "Template:B", "Template:B");
}
}
class Xop_redirect_mgr_fxt {
private Xop_fxt fxt = new Xop_fxt();
@ -44,6 +49,14 @@ class Xop_redirect_mgr_fxt {
public void Init_utf8() {
fxt.Wiki().Lang().Case_mgr_utf8_();
}
public void Test_frame_ttl(String tmpl_ttl_str, String tmpl_wtxt_str, String redirect_ttl, String expd_frame_ttl) {
fxt.Init_page_create(tmpl_ttl_str, tmpl_wtxt_str); // create redirect_src
fxt.Init_page_create(redirect_ttl, "test"); // create redirect_trg
fxt.Test_parse_page_tmpl_tkn("{{" + tmpl_ttl_str + "}}"); // parse {{redirect_src}}
Xoa_ttl tmpl_ttl = Xoa_ttl.parse_(fxt.Wiki(), Bry_.new_utf8_(tmpl_ttl_str));
Xot_defn_tmpl defn_tmpl = (Xot_defn_tmpl)fxt.Wiki().Cache_mgr().Defn_cache().Get_by_key(tmpl_ttl.Page_db()); // get defn (which parse should have created)
Tfds.Eq(expd_frame_ttl, String_.new_utf8_(defn_tmpl.Frame_ttl())); // check frame_ttl
}
public void Test_redirect(String raw_str, String expd_str) {
Xop_redirect_mgr redirect_mgr = fxt.Ctx().Wiki().Redirect_mgr();
redirect_mgr.Clear();

View File

@ -42,12 +42,10 @@ public class Xop_lnki_wkr implements Xop_ctx_wkr, Xop_arg_wkr {
int stack_pos = ctx.Stack_idx_typ(Xop_tkn_itm_.Tid_lnki);
if (stack_pos == Xop_ctx.Stack_not_found) return ctx.Lxr_make_txt_(cur_pos); // "]]" found but no "[[" in stack; return literal "]]"
Xop_lnki_tkn lnki = (Xop_lnki_tkn)ctx.Stack_pop_til(root, src, stack_pos, false, bgn_pos, cur_pos, Xop_tkn_itm_.Tid_lnki_end);
if (Xop_lnki_wkr_.Adjust_for_brack_end_len_of_3(ctx, tkn_mkr, root, src, src_len, cur_pos, lnki)) { // convert "]]]" into "]" + "]]", not "]]" + "]"
root.Subs_add(tkn_mkr.Bry(bgn_pos, bgn_pos + 1, Byte_ascii.Brack_end_bry)); // add "]" as bry
++bgn_pos; ++cur_pos; // position "]]" at end of "]]]"
}
if (!arg_bldr.Bld(ctx, tkn_mkr, this, Xop_arg_wkr_.Typ_lnki, root, lnki, bgn_pos, cur_pos, lnki.Tkn_sub_idx() + 1, root.Subs_len(), src))
return Xop_lnki_wkr_.Invalidate_lnki(ctx, src, root, lnki, bgn_pos);
if (Xop_lnki_wkr_.Adjust_for_brack_end_len_of_3(ctx, tkn_mkr, root, src, src_len, cur_pos, lnki)) // convert "]]]" into "]" + "]]", not "]]" + "]"
++cur_pos; // position "]]" at end of "]]]"
cur_pos = Xop_lnki_wkr_.Chk_for_tail(ctx.Lang(), src, cur_pos, src_len, lnki);
lnki.Src_end_(cur_pos); // NOTE: must happen after Chk_for_tail; redundant with above, but above needed b/c of returns
root.Subs_del_after(lnki.Tkn_sub_idx() + 1); // all tkns should now be converted to args in owner; delete everything in root
@ -274,7 +272,15 @@ class Xop_lnki_wkr_ {
&& src[nxt_pos] != Byte_ascii.Brack_end // is next char after "]]]", "]"; i.e.: not "]]]]"; PAGE:ru.w:Меркатале_ин_Валь_ди_Песа; DATE:2014-02-04
)
) {
return lnki.Ttl() != null; // only change "]]]" to "]" + "]]" if lnki is not title; otherwise [[A]]] -> "A]" which will be invalid; PAGE:en.w: Tall_poppy_syndrome DATE:2014-07-23
if ( lnki.Caption_exists() // does a caption exist?
&& lnki.Caption_tkn().Src_end() + 2 == cur_pos // is "]]]" at end of caption?; 2="]]".Len; handle [http://a.org [[File:A.png|123px]]] PAGE:ar.w:محمد; DATE:2014-08-20
&& lnki.Ttl() != null // only change "]]]" to "]" + "]]" if lnki is not title; otherwise [[A]]] -> "A]" which will be invalid; PAGE:en.w:Tall_poppy_syndrome DATE:2014-07-23
) {
Xop_tkn_itm caption_val_tkn = lnki.Caption_val_tkn();
caption_val_tkn.Subs_add(tkn_mkr.Bry(cur_pos, cur_pos + 1, Byte_ascii.Brack_end_bry)); // add "]" as bry
caption_val_tkn.Src_end_(caption_val_tkn.Src_end() + 1);
return true;
}
}
}
return false;

View File

@ -30,6 +30,11 @@ public class Xop_lnki_wkr__uncommon_tst {
fxt.Test_parse_page_all_str("[[A]]]" , "<a href=\"/wiki/A\">A</a>]"); // title only
fxt.Test_parse_page_all_str("[[A|B]]]" , "<a href=\"/wiki/A\">B]</a>"); // title + caption; note that ] should be outside </a> b/c MW has more logic that says "if caption starts with '['", but leaving as is; DATE:2014-07-23
}
@Test public void Triple_bracket_with_lnke_lnki() { // PURPOSE: handle [http://a.org [[File:A.png|123px]]]; PAGE:ar.w:محمد DATE:2014-08-20
fxt.Test_parse_page_all_str("[http://a.org [[File:A.png|123px]]]"
, "<a href=\"http://a.org\" class=\"external text\" rel=\"nofollow\"><a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/123px.png\" width=\"123\" height=\"0\" /></a></a>"
);
}
@Test public void Multiple_captions() { // PURPOSE: multiple captions should be concatenated (used to only take first); EX:zh.d:维基词典:Unicode字符索引/00000FFF; DATE:2014-05-05
fxt.Test_parse_page_all_str("[[A|B|C|D]]" , "<a href=\"/wiki/A\">B|C|D</a>");
}

View File

@ -212,7 +212,7 @@ public class Xop_xnde_tag_ {
, Tag_references = new_(Tid_references, "references").Xtn_().Nest_()
, Tag_source = new_(Tid_source, "source").Xtn_().Block_open_bgn_().Block_close_end_() // deactivate pre; pre; PAGE:en.w:Comment_(computer_programming); DATE:2014-06-23
, Tag_syntaxHighlight = new_(Tid_syntaxHighlight, "syntaxHighlight").Xtn_().Block_open_bgn_().Block_close_end_() // deactivate pre; pre; PAGE:en.w:Comment_(computer_programming); DATE:2014-06-23
, Tag_gallery = new_(Tid_gallery, "gallery").Xtn_().Block_open_bgn_().Block_close_end_()
, Tag_gallery = new_(Tid_gallery, "gallery").Xtn_().Block_open_bgn_().Block_close_end_().Xtn_auto_close_()
, Tag_imageMap = new_(Tid_imageMap, "imageMap").Xtn_()
, Tag_timeline = new_(Tid_timeline, "timeline").Xtn_()
, Tag_hiero = new_(Tid_hiero, "hiero").Xtn_()

View File

@ -590,12 +590,7 @@ public class Xop_xnde_wkr implements Xop_ctx_wkr {
close_bry[i] = src[src_offset + i];
boolean auto_close = false;
int close_bgn = Find_xtn_end_lhs(ctx, tag, src, src_len, open_bgn, open_end, close_bry);
if (close_bgn == Bry_.NotFound) {
if (tag.Xtn_auto_close())
auto_close = true;
else
return ctx.Lxr_make_log_(Xop_xnde_log.Xtn_end_not_found, src, open_bgn, open_end);
}
if (close_bgn == Bry_.NotFound) auto_close = true; // auto-close if end not found; verified with <poem>, <gallery>, <imagemap>, <hiero>, <references> DATE:2014-08-23
int close_end = -1;
if (auto_close) {
xnde_end = close_bgn = close_end = src_len;

View 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.core.btries.*;
public class Xop_curly_bgn_lxr implements Xop_lxr {
public byte Lxr_tid() {return Xop_lxr_.Tid_curly_bgn;}
public void Init_by_wiki(Xow_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Hook, this);} public static final byte[] Hook = new byte[] {Byte_ascii.Curly_bgn, Byte_ascii.Curly_bgn};
public void Init_by_lang(Xol_lang lang, Btrie_fast_mgr core_trie) {}
public int Make_tkn(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int bgn_pos, int cur_pos) {return ctx.Curly().MakeTkn_bgn(ctx, tkn_mkr, root, src, src_len, bgn_pos, cur_pos);}
public static final Xop_curly_bgn_lxr _ = new Xop_curly_bgn_lxr(); Xop_curly_bgn_lxr() {}
public static Btrie_fast_mgr tmpl_bgn_trie_() { // hook sequences for adding new_line to tmpl return; "{|" "|-" ":" ";" "#" "*"; EX: "{{a}}" returns "*"; convert to "\n*"
Btrie_fast_mgr rv = Btrie_fast_mgr.cs_();
rv.Add(Xop_tblw_lxr_ws.Hook_tb, Bry_.Empty);
rv.Add(Bry_.new_ascii_("|-"), Bry_.Empty);
rv.Add(Byte_ascii.Colon, Bry_.Empty);
rv.Add(Byte_ascii.Semic, Bry_.Empty);
rv.Add(Byte_ascii.Hash, Bry_.Empty);
rv.Add(Byte_ascii.Asterisk, Bry_.Empty);
return rv;
}
}

Some files were not shown because too many files have changed in this diff Show More