mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.9.2.1
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
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.files.repos; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
|
||||
import gplx.xowa.parsers.utils.*;
|
||||
public class Xofw_file_finder_rslt {
|
||||
public byte[] Ttl() {return ttl;} private byte[] ttl;
|
||||
public byte[] Redirect() {return redirect;} private byte[] redirect;
|
||||
public int Repo_idx() {return repo_idx;} private int repo_idx;
|
||||
public byte[] Repo_wiki_key() {return repo_wiki_key;} private byte[] repo_wiki_key;
|
||||
public void Init(byte[] ttl) {
|
||||
this.ttl = ttl; redirect = Xop_redirect_mgr.Redirect_null_bry; repo_wiki_key = null; repo_idx = Byte_.Max_value_127;
|
||||
}
|
||||
public void Done(int repo_idx, byte[] repo_wiki_key, byte[] redirect) {
|
||||
this.repo_idx = repo_idx; this.repo_wiki_key = repo_wiki_key; this.redirect = redirect;
|
||||
}
|
||||
}
|
||||
23
400_xowa/src/gplx/xowa/files/repos/Xofw_wiki_finder.java
Normal file
23
400_xowa/src/gplx/xowa/files/repos/Xofw_wiki_finder.java
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
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.files.repos; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.files.*; import gplx.xowa.files.repos.*;
|
||||
public interface Xofw_wiki_finder {
|
||||
void Find(List_adp repo_pairs, Xof_xfer_itm file);
|
||||
boolean Locate(Xofw_file_finder_rslt rv, List_adp repo_pairs, byte[] ttl_bry);
|
||||
}
|
||||
73
400_xowa/src/gplx/xowa/files/repos/Xofw_wiki_wkr_base.java
Normal file
73
400_xowa/src/gplx/xowa/files/repos/Xofw_wiki_wkr_base.java
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
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.files.repos; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.files.*; import gplx.xowa.files.repos.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.parsers.utils.*;
|
||||
public class Xofw_wiki_wkr_base implements Xofw_wiki_finder {
|
||||
public Xofw_wiki_wkr_base(Xowe_wiki wiki, Xoae_wiki_mgr wiki_mgr) {this.wiki = wiki; this.wiki_mgr = wiki_mgr;} private Xowe_wiki wiki; Xoae_wiki_mgr wiki_mgr;
|
||||
public void Find(List_adp repo_pairs, Xof_xfer_itm file) {
|
||||
byte[] ttl_bry = file.Lnki_ttl();
|
||||
int repo_pairs_len = repo_pairs.Count();
|
||||
for (int i = 0; i < repo_pairs_len; i++) {
|
||||
Xof_repo_pair repo_pair = (Xof_repo_pair)repo_pairs.Get_at(i);
|
||||
byte[] wiki_key = repo_pair.Src().Wiki_domain();
|
||||
if (repo_pair.Src().Wmf_api()) continue;
|
||||
Xowe_wiki repo_wiki = wiki_mgr.Get_by_key_or_null(wiki_key);
|
||||
if (repo_wiki == null) {continue;}
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(repo_wiki, ttl_bry);
|
||||
Xow_ns file_ns = repo_wiki.Ns_mgr().Ns_file();
|
||||
boolean found = repo_wiki.Db_mgr().Load_mgr().Load_by_ttl(tmp_db_page, file_ns, ttl.Page_db());
|
||||
if (!found) {continue;}
|
||||
byte[] redirect = Get_redirect(repo_wiki, file_ns, tmp_db_page);
|
||||
file.Orig_ttl_and_redirect_(ttl.Page_txt(), redirect);
|
||||
file.Orig_repo_id_(i);
|
||||
return;
|
||||
}
|
||||
file.Orig_repo_id_(-1);
|
||||
}
|
||||
public boolean Locate(Xofw_file_finder_rslt rv, List_adp repo_pairs, byte[] ttl_bry) {
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(wiki, ttl_bry); // NOTE: parse(ttl_bry) should be the same across all wikis; i.e.: there should be no aliases/namespaces
|
||||
Xow_ns file_ns = wiki.Ns_mgr().Ns_file(); // NOTE: file_ns should also be the same across all wikis; being used for data_mgr.Parse below
|
||||
byte[] ttl_db_key = ttl.Page_db();
|
||||
rv.Init(ttl_db_key);
|
||||
int repo_pairs_len = repo_pairs.Count();
|
||||
for (int i = 0; i < repo_pairs_len; i++) {
|
||||
Xof_repo_pair repo_pair = (Xof_repo_pair)repo_pairs.Get_at(i);
|
||||
byte[] src_wiki_key = repo_pair.Src().Wiki_domain();
|
||||
Xowe_wiki src_wiki = wiki_mgr.Get_by_key_or_null(src_wiki_key);
|
||||
if (src_wiki == null) continue; // src_wiki defined as repo_pair in cfg, but it has not been downloaded; continue; EX: commons set up but not downloaded
|
||||
boolean found = src_wiki.Db_mgr().Load_mgr().Load_by_ttl(tmp_db_page, file_ns, ttl_db_key);
|
||||
if (!found) continue; // ttl does not exist in src_wiki; continue; EX: file does not exist in commons, but exists in en_wiki
|
||||
byte[] redirect = Get_redirect(src_wiki, file_ns, tmp_db_page);
|
||||
rv.Done(i, src_wiki_key, redirect);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private byte[] Get_redirect(Xowe_wiki wiki, Xow_ns file_ns, Xowd_page_itm db_page) {
|
||||
if (db_page.Redirected()) {
|
||||
wiki.Db_mgr().Load_mgr().Load_page(db_page, file_ns, false);
|
||||
byte[] src = db_page.Text();
|
||||
Xoa_ttl redirect_ttl = wiki.Redirect_mgr().Extract_redirect(src, src.length);
|
||||
return redirect_ttl == Xop_redirect_mgr.Redirect_null_ttl ? Xop_redirect_mgr.Redirect_null_bry : redirect_ttl.Page_db();
|
||||
}
|
||||
else
|
||||
return Xop_redirect_mgr.Redirect_null_bry;
|
||||
}
|
||||
private static final Xowd_page_itm tmp_db_page = Xowd_page_itm.new_tmp();
|
||||
}
|
||||
43
400_xowa/src/gplx/xowa/files/repos/Xofw_wiki_wkr_mock.java
Normal file
43
400_xowa/src/gplx/xowa/files/repos/Xofw_wiki_wkr_mock.java
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
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.files.repos; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.tdbs.metas.*;
|
||||
public class Xofw_wiki_wkr_mock implements Xofw_wiki_finder {
|
||||
int repo_idx; byte[] repo_wiki_key;
|
||||
public Xofw_wiki_wkr_mock Clear_en_wiki() {return Clear(1, Bry_en_wiki);}
|
||||
public Xofw_wiki_wkr_mock Clear_commons() {return Clear(0, Bry_commons);}
|
||||
Xofw_wiki_wkr_mock Clear(int repo_idx, byte[] repo_wiki_key) {
|
||||
this.repo_idx = repo_idx; this.repo_wiki_key = repo_wiki_key;
|
||||
if_ttl = then_redirect = Bry_.Empty;
|
||||
return this;
|
||||
}
|
||||
private static final byte[] Bry_commons = Bry_.new_a7("commons.wikimedia.org"), Bry_en_wiki = Bry_.new_a7("en.wikipedia.org");
|
||||
public Xofw_wiki_wkr_mock Repo_idx_(int v) {this.repo_idx = v; return this;}
|
||||
public Xofw_wiki_wkr_mock Redirect_(String if_ttl_str, String then_redirect_str) {this.if_ttl = Bry_.new_u8(if_ttl_str); this.then_redirect = Bry_.new_u8(then_redirect_str); return this;} private byte[] if_ttl, then_redirect;
|
||||
public void Find(List_adp repo_pairs, Xof_xfer_itm file) {
|
||||
byte[] ttl = file.Lnki_ttl();
|
||||
if (Bry_.Eq(ttl, if_ttl) && repo_idx != -1) {file.Orig_ttl_and_redirect_(ttl, then_redirect); file.Orig_repo_id_(repo_idx);}
|
||||
else {file.Orig_ttl_and_redirect_(ttl, Bry_.Empty) ; file.Orig_repo_id_(Xof_meta_itm.Repo_unknown);} // FUTURE: this should be missing, but haven't implemented unknown yet
|
||||
}
|
||||
public boolean Locate(Xofw_file_finder_rslt rv, List_adp repo_pairs, byte[] ttl) {
|
||||
rv.Init(ttl);
|
||||
byte[] redirect = Bry_.Eq(ttl, if_ttl) ? then_redirect : null;
|
||||
rv.Done(repo_idx, repo_wiki_key, redirect);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.files.repos; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
|
||||
import gplx.xowa.files.xfers.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
import gplx.xowa.parsers.utils.*;
|
||||
import gplx.xowa.tdbs.metas.*;
|
||||
public class Xowe_repo_mgr implements Xow_repo_mgr, GfoInvkAble {
|
||||
private Xowe_wiki wiki; private final List_adp repos = List_adp_.new_();
|
||||
public Xowe_repo_mgr(Xowe_wiki wiki) {
|
||||
|
||||
Reference in New Issue
Block a user