mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
parse wgCategoryCollation to create cfg lines in bin\any\xowa\cfg\wiki
This commit is contained in:
parent
3fc2e0741f
commit
d0769c32b4
@ -32,7 +32,7 @@ public class Xoa_app_ {
|
||||
}
|
||||
}
|
||||
public static final String Name = "xowa";
|
||||
public static final String Version = "3.9.4.4";
|
||||
public static final String Version = "3.9.4.5";
|
||||
public static String Build_date = "2012-12-30 00:00:00";
|
||||
public static String Op_sys_str;
|
||||
public static String User_agent = "";
|
||||
|
@ -20,8 +20,7 @@ import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
|
||||
public class Xowm_server_cfg_cmd extends Xob_cmd__base {
|
||||
public Xowm_server_cfg_cmd(Xob_bldr bldr, Xowe_wiki wiki) {super(bldr, wiki);}
|
||||
@Override public void Cmd_run() {
|
||||
// wiki.Init_assert();
|
||||
// mgr.Exec(wiki);
|
||||
new Xowm_server_cfg_mgr().Exec(bldr.App());
|
||||
}
|
||||
|
||||
public static final String BLDR_CMD_KEY = "cfg.wikis.wm_server_cfg";
|
||||
|
@ -16,21 +16,68 @@ 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.addons.bldrs.app_cfgs.wm_server_cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.app_cfgs.*;
|
||||
import gplx.core.ios.*;
|
||||
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
|
||||
import gplx.langs.phps.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
public class Xowm_server_cfg_mgr {
|
||||
public void Exec() {
|
||||
byte[] src = Load_or_download();
|
||||
public void Exec(Xoa_app app) {
|
||||
// get local file
|
||||
Io_url tmp_url = app.Fsys_mgr().Bin_xowa_dir().GenSubFil_nest("cfg", "wiki", "InitialiseSettings.php.txt");
|
||||
Assert_recent_or_download(tmp_url, "https://noc.wikimedia.org/conf/InitialiseSettings.php.txt", 1440);
|
||||
byte[] src = Io_mgr.Instance.LoadFilBry(tmp_url);
|
||||
Parse_cat_collation(src);
|
||||
}
|
||||
private byte[] Load_or_download() {
|
||||
// Io_mgr.Instance.DownloadFil_args("", Io_url_.NullPtr).Exec_as_bry("https://noc.wikimedia.org/conf/InitialiseSettings.php.txt");
|
||||
return null;
|
||||
}
|
||||
private void Parse_cat_collation(byte[] src) {
|
||||
int bgn_pos = Bry_find_.Find_fwd(src, Bry_.new_a7("wgCategoryCollation"));
|
||||
private void Parse_cat_collation(byte[] all) {
|
||||
// extract cat_collation
|
||||
int bgn_pos = Bry_find_.Find_fwd(all, Bry_.new_a7("wgCategoryCollation"));
|
||||
if (bgn_pos == Bry_find_.Not_found) throw Err_.new_wo_type("could not find wgCategoryCollation bgn");
|
||||
int end_pos = Bry_find_.Find_fwd(src, Bry_.new_a7("],"));
|
||||
bgn_pos = Bry_find_.Move_fwd(all, Byte_ascii.Nl_bry, bgn_pos);
|
||||
|
||||
int end_pos = Bry_find_.Find_fwd(all, Bry_.new_a7("\n],"), bgn_pos);
|
||||
if (end_pos == Bry_find_.Not_found) throw Err_.new_wo_type("could not find wgCategoryCollation end");
|
||||
Tfds.Write(src, bgn_pos, end_pos);
|
||||
byte[] src = Bry_.Mid(all, bgn_pos, end_pos + 2); // +2="],"
|
||||
src = Bry_.Add(Bry_.new_a7("$test=["), src, Bry_.new_a7("];"));
|
||||
|
||||
// parse php
|
||||
Php_parser php_parser = new Php_parser();
|
||||
Php_evaluator eval = new Php_evaluator(new gplx.core.log_msgs.Gfo_msg_log("test"));
|
||||
php_parser.Parse_tkns(src, eval);
|
||||
Php_line[] lines = (Php_line[])eval.List().To_ary(Php_line.class);
|
||||
Php_line_assign line = (Php_line_assign)lines[0];
|
||||
Php_itm_ary root_ary = (Php_itm_ary)line.Val();
|
||||
|
||||
// loop tkns and build String
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
bfr.Add_byte_nl();
|
||||
int len = root_ary.Subs_len();
|
||||
byte[] wiki_abrv__default = Bry_.new_a7("default");
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Php_itm_kv kv = (Php_itm_kv)root_ary.Subs_get(i);
|
||||
byte[] wiki_abrv = kv.Key().Val_obj_bry();
|
||||
byte[] collation = kv.Val().Val_obj_bry();
|
||||
|
||||
if (Bry_.Eq(wiki_abrv, wiki_abrv__default)) continue; // skip "'default' => 'uppercase',"
|
||||
try {
|
||||
byte[] wiki_domain = Xow_abrv_wm_.Parse_to_domain_bry(wiki_abrv);
|
||||
|
||||
Xow_domain_itm itm = Xow_domain_itm_.parse(wiki_domain);
|
||||
bfr.Add_str_u8_fmt("app.bldr.wiki_cfg_bldr.get('{0}').new_cmd_('wiki.ctgs.collations', \"catpage_mgr.collation_('{1}');\");\n", itm.Domain_bry(), collation);
|
||||
} catch (Exception e) {throw Err_.new_("failed to parse line", "wiki", wiki_abrv, "collation", collation, "err", Err_.Message_lang(e));}
|
||||
}
|
||||
Tfds.Write(bfr.To_str_and_clear());
|
||||
}
|
||||
private static void Assert_recent_or_download(Io_url trg, String src, int min) {
|
||||
// get file
|
||||
IoItmFil trg_fil = Io_mgr.Instance.QueryFil(trg);
|
||||
|
||||
// exit if file exists and is recent
|
||||
if (trg_fil != null) {
|
||||
DateAdp now = Datetime_now.Get();
|
||||
if (now.Diff(trg_fil.ModifiedTime()).Total_mins().To_int() < min) return;
|
||||
}
|
||||
|
||||
// load b/c file doesn't exist, or is not recent
|
||||
Io_mgr.Instance.DownloadFil(src, trg);
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public class Xoctg_catpage_itm {
|
||||
public byte[] Sortkey_handle_make(Bry_bfr tmp_bfr, byte[] prv_sortkey_handle) {
|
||||
// page.tbl missing even though in cat_link.tbl; happens for "User:" namespace pages;
|
||||
if (page_ttl == Xoa_ttl.Null) {
|
||||
// sortkey_prefix exists; happens for [[Category:A]] as opposed to [[Category:A|some_sortkey_prefix]]
|
||||
// sortkey_prefix exists; happens for [[Category:A]] as opposed to [[Category:A|some_sortkey_prefix]]; also, {{DEFAULTSORTKEY:some_sortkey_prefix}}
|
||||
if (Bry_.Len_gt_0(sortkey_prefix)) {
|
||||
sortkey_handle = sortkey_prefix;
|
||||
return sortkey_handle; // set sortkey_prefix as new prv_sortkey_handle;
|
||||
|
Loading…
Reference in New Issue
Block a user