mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v3.1.4.1
This commit is contained in:
@@ -1,42 +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.xtns.pagebanners; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.logs.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.htmls.*;
|
||||
public class Pb_xnde implements Xox_xnde {
|
||||
// private Pb_xtn xtn;
|
||||
public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, Object xatr_id_obj) {}
|
||||
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
|
||||
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_bgn);
|
||||
// this.xtn = (Pb_xtn)wiki.Xtn_mgr().Get_or_fail(Pb_xtn.Xtn_key_static);
|
||||
// xtn.Xtn_init_assert(wiki);
|
||||
// ctx.Cur_page().Html_data().Head_mgr().Itm__graph().Enabled_y_();
|
||||
// boolean log_wkr_enabled = Log_wkr != Xop_log_basic_wkr.Null; if (log_wkr_enabled) Log_wkr.Log_end_xnde(ctx.Cur_page(), Xop_log_basic_wkr.Tid_graph, src, xnde);
|
||||
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_end);
|
||||
}
|
||||
public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {
|
||||
// bfr.Add(Html__div_bgn);
|
||||
// bfr.Add_mid(src, xnde.Tag_open_end(), xnde.Tag_close_bgn());
|
||||
// bfr.Add(Html__div_end);
|
||||
}
|
||||
public static Xop_log_basic_wkr Log_wkr = Xop_log_basic_wkr.Null;
|
||||
// private static final byte[]
|
||||
// Html__div_bgn = Bry_.new_a7("<div class='mw-wiki-graph'>\n")
|
||||
// , Html__div_end = Bry_.new_a7("</div>\n")
|
||||
// ;
|
||||
}
|
||||
150
400_xowa/src/gplx/xowa/xtns/pagebanners/Pgbnr_cfg.java
Normal file
150
400_xowa/src/gplx/xowa/xtns/pagebanners/Pgbnr_cfg.java
Normal file
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
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.pagebanners; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.xowa.parsers.*;
|
||||
class Pgbnr_cfg {
|
||||
public byte[] Default_file() {return null;}
|
||||
public boolean Enabled_in_ns(int ns_id) {return false;}
|
||||
}
|
||||
class Pgbnr_icon {
|
||||
public byte[] Name;
|
||||
public byte[] Title;
|
||||
public byte[] Url;
|
||||
public Pgbnr_icon(byte[] name, byte[] title, byte[] url) {
|
||||
this.Name = name; this.Title = title; this.Url = url;
|
||||
}
|
||||
public static final Pgbnr_icon[] Ary_empty = new Pgbnr_icon[0];
|
||||
}
|
||||
class Pgbnr_itm {
|
||||
public byte[] Name;
|
||||
public byte[] Tooltip;
|
||||
public byte[] Title;
|
||||
public boolean Bottomtoc;
|
||||
public boolean Toc;
|
||||
public Xoa_ttl File_ttl;
|
||||
public Pgbnr_icon[] Icons;
|
||||
public Pgbnr_itm(byte[] name, byte[] tooltip, byte[] title, boolean bottomtoc, boolean toc, Xoa_ttl file_ttl, Pgbnr_icon[] icons) {
|
||||
this.Name = name;
|
||||
this.Tooltip = tooltip; this.Title = title; this.Bottomtoc = bottomtoc; this.Toc = toc; this.File_ttl = file_ttl; this.Icons = icons;
|
||||
}
|
||||
// public static void Do(Bry_bfr bfr, Xop_ctx ctx, Pgbnr_cfg cfg, Pgbnr_itm itm) {
|
||||
// if (itm != null) {
|
||||
// byte[] name = itm.Name;
|
||||
//// if ( isset( $params['icons'] ) ){
|
||||
//// $out->enableOOUI();
|
||||
//// $params['icons'] = self::expandIconTemplateOptions( $params['icons'] );
|
||||
//// }
|
||||
// // $banner = $wpbFunctionsClass::getBannerHtml( $bannername, $params );
|
||||
// }
|
||||
// else {}
|
||||
// }
|
||||
public static void Get_banner_html(Bry_bfr bfr, byte[] banner_name, Pgbnr_itm itm, Pgbnr_cfg cfg) {
|
||||
byte[][] urls = Bry_.Ary(Bry_.Empty); // $urls = static::getStandardSizeUrls( $bannername );
|
||||
if (urls.length == 0) return;
|
||||
}
|
||||
// public static function getBannerHtml( $bannername, $options = array() ) {
|
||||
// // @var int index variable
|
||||
// $i = 0;
|
||||
// foreach ( $urls as $url ) {
|
||||
// $size = $config->get( 'WPBStandardSizes' );
|
||||
// $size = $size[$i];
|
||||
// // add url with width and a comma if not adding the last url
|
||||
// if ( $i < count( $urls ) ) {
|
||||
// $srcset[] = "$url {$size}w";
|
||||
// }
|
||||
// $i++;
|
||||
// }
|
||||
// // create full src set from individual urls, separated by comma
|
||||
// $srcset = implode( ',', $srcset );
|
||||
// // use largest image url as src attribute
|
||||
// $bannerurl = $urls[count( $urls ) - 1];
|
||||
// $bannerfile = Title::newFromText( "File:$bannername" );
|
||||
// $templateParser = new TemplateParser( __DIR__ . '/../templates' );
|
||||
// $options['bannerfile'] = $bannerfile->getLocalUrl();
|
||||
// $options['banner'] = $bannerurl;
|
||||
// $options['srcset'] = $srcset;
|
||||
// $file = wfFindFile( $bannerfile );
|
||||
// $options['maxWidth'] = $file->getWidth();
|
||||
// $options['isHeadingOverrideEnabled'] = $config->get( 'WPBEnableHeadingOverride' );
|
||||
// $banner = $templateParser->processTemplate(
|
||||
// 'banner',
|
||||
// $options
|
||||
// );
|
||||
// }
|
||||
|
||||
// public static function addBanner( OutputPage $out, Skin $skin ) {
|
||||
// $config = WikidataPageBannerFunctions::getWPBConfig();
|
||||
// $title = $out->getTitle();
|
||||
// $isDiff = $out->getRequest()->getVal( 'diff' );
|
||||
// $wpbFunctionsClass = self::$wpbFunctionsClass;
|
||||
//
|
||||
// // if banner-options are set and not a diff page, add banner anyway
|
||||
// if ( $out->getProperty( 'wpb-banner-options' ) !== null && !$isDiff ) {
|
||||
// $params = $out->getProperty( 'wpb-banner-options' );
|
||||
// $bannername = $params['name'];
|
||||
// $banner = $wpbFunctionsClass::getBannerHtml( $bannername, $params );
|
||||
// // attempt to get WikidataBanner
|
||||
// if ( $banner === null ) {
|
||||
// $bannername = $wpbFunctionsClass::getWikidataBanner( $title );
|
||||
// $banner = $wpbFunctionsClass::getBannerHtml( $bannername, $params );
|
||||
// }
|
||||
// // only add banner and styling if valid banner generated
|
||||
// if ( $banner !== null ) {
|
||||
// if ( isset( $params['toc'] ) ) {
|
||||
// $out->addModuleStyles( 'ext.WikidataPageBanner.toc.styles' );
|
||||
// }
|
||||
// $wpbFunctionsClass::insertBannerIntoOutputPage( $out, $banner );
|
||||
//
|
||||
// // FIXME: This is currently only needed to support testing
|
||||
// $out->setProperty( 'articlebanner-name', $bannername );
|
||||
// }
|
||||
// }
|
||||
// // if the page uses no 'PAGEBANNER' invocation and if article page, insert default banner
|
||||
// elseif (
|
||||
// $title->isKnown() &&
|
||||
// $out->isArticle() &&
|
||||
// $config->get( 'WPBEnableDefaultBanner' ) &&
|
||||
// !$isDiff
|
||||
// ) {
|
||||
// $ns = $title->getNamespace();
|
||||
// // banner only on specified namespaces, and not Main Page of wiki
|
||||
// if ( in_array( $ns, $config->get( 'WPBNamespaces' ) )
|
||||
// && !$title->isMainPage() ) {
|
||||
// // first try to obtain bannername from Wikidata
|
||||
// $bannername = $wpbFunctionsClass::getWikidataBanner( $title );
|
||||
// if ( $bannername === null ) {
|
||||
// // if Wikidata banner not found, set bannername to default banner
|
||||
// $bannername = $config->get( 'WPBImage' );
|
||||
// }
|
||||
// // add title to template parameters
|
||||
// $paramsForBannerTemplate = array( 'title' => $title );
|
||||
// $banner = $wpbFunctionsClass::
|
||||
// getBannerHtml( $bannername, $paramsForBannerTemplate );
|
||||
// // only add banner and styling if valid banner generated
|
||||
// if ( $banner !== null ) {
|
||||
// $wpbFunctionsClass::insertBannerIntoOutputPage( $out, $banner );
|
||||
//
|
||||
// // set articlebanner property on OutputPage
|
||||
// // FIXME: This is currently only needed to support testing
|
||||
// $out->setProperty( 'articlebanner-name', $bannername );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
}
|
||||
79
400_xowa/src/gplx/xowa/xtns/pagebanners/Pgbnr_func.java
Normal file
79
400_xowa/src/gplx/xowa/xtns/pagebanners/Pgbnr_func.java
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
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.pagebanners; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*; import gplx.xowa.xtns.pfuncs.*; import gplx.xowa.langs.kwds.*;
|
||||
import gplx.xowa.parsers.utils.*;
|
||||
public class Pgbnr_func extends Pf_func_base {
|
||||
@Override public int Id() {return Xol_kwd_grp_.Id_pagebanner;}
|
||||
@Override public Pf_func New(int id, byte[] name) {return new Pgbnr_func().Name_(name);}
|
||||
@Override public void Func_evaluate(Bry_bfr bfr, Xop_ctx ctx, Xot_invk caller, Xot_invk self, byte[] src) { // WikidataPageBanner.hooks.php|addCustomBanner
|
||||
Xowe_wiki wiki = ctx.Wiki();
|
||||
Pgbnr_cfg cfg = new Pgbnr_cfg(); // ctx.Wiki().Xtn_mgr().Xtn_pgbnr();
|
||||
Xoa_ttl ttl = ctx.Cur_page().Ttl();
|
||||
if ( !cfg.Enabled_in_ns(ttl.Ns().Id()) // chk if ns allows banner
|
||||
|| Bry_.Eq(ttl.Page_db(), wiki.Props().Main_page())) // never show on main page
|
||||
return;
|
||||
Bry_bfr tmp_bfr = Bry_bfr.new_();
|
||||
boolean bottomtoc = false, toc = false;
|
||||
byte[] tooltip = ttl.Page_txt();
|
||||
byte[] title = ttl.Page_txt();
|
||||
int args_len = self.Args_len();
|
||||
List_adp icons_list = null;
|
||||
for (int i = 0; i < args_len; ++i) {
|
||||
Arg_nde_tkn arg = self.Args_get_by_idx(i);
|
||||
byte[] key = Pf_func_.Eval_tkn(tmp_bfr, ctx, src, caller, arg.Key_tkn());
|
||||
byte[] val = Pf_func_.Eval_tkn(tmp_bfr, ctx, src, caller, arg.Val_tkn());
|
||||
int tid = arg_hash.Get_as_int_or(key, -1);
|
||||
if (tid == Arg__pgname)
|
||||
tooltip = title = val;
|
||||
if (tid == Arg__tooltip) // note that this overrides pgname above
|
||||
tooltip = val;
|
||||
if (tid == Arg__bottomtoc && Bry_.Eq(val, Bry__yes))
|
||||
bottomtoc = true;
|
||||
if (tid == Arg__toc && Bry_.Eq(val, Bry__yes))
|
||||
toc = true;
|
||||
if (tid == -1 && Bry_.Has_at_bgn(key, Bry__icon) && Bry_.Len_gt_0(val)) {
|
||||
if (icons_list == null) icons_list = List_adp_.new_();
|
||||
byte[] icon_name = Xop_sanitizer.Escape_cls(val);
|
||||
byte[] icon_title = icon_name;
|
||||
Xoa_ttl icon_url_ttl = wiki.Ttl_parse(val);
|
||||
byte[] icon_url_bry = Bry_.Empty;
|
||||
if (icon_url_ttl == null) icon_url_bry = Bry__url_dflt;
|
||||
else {
|
||||
icon_url_bry = Bry_.Empty;// $iconUrl->getLocalUrl();
|
||||
icon_title = ttl.Page_txt();
|
||||
}
|
||||
icons_list.Add(new Pgbnr_icon(icon_name, icon_title, icon_url_bry));
|
||||
tid = Arg__icon;
|
||||
}
|
||||
if (tid == -1) Gfo_usr_dlg_.Instance.Warn_many("", "", "unknown arg type; page=~{0} key=~{1} val=~{2}", "page", ctx.Cur_page().Url_bry_safe(), key, val);
|
||||
// WikidataPageBannerFunctions::addFocus( $paramsForBannerTemplate, $argumentsFromParserFunction );
|
||||
}
|
||||
byte[] name = Eval_argx(ctx, src, caller, self);
|
||||
if (Bry_.Len_eq_0(name))
|
||||
name = cfg.Default_file();
|
||||
Xoa_ttl file_ttl = wiki.Ttl_parse(name);
|
||||
Pgbnr_itm itm = new Pgbnr_itm(name, tooltip, title, bottomtoc, toc, file_ttl, icons_list == null ? Pgbnr_icon.Ary_empty : (Pgbnr_icon[])icons_list.To_ary_and_clear(Pgbnr_icon.class));
|
||||
Tfds.Write(itm);
|
||||
}
|
||||
private static final byte[] Bry__yes = Bry_.new_a7("yes"), Bry__icon = Bry_.new_a7("icon-"), Bry__url_dflt = Bry_.new_a7("#");
|
||||
private static final int Arg__pgname = 0, Arg__tooltip = 1, Arg__bottomtoc = 2, Arg__toc = 3, Arg__icon = 4;
|
||||
private static final Hash_adp_bry arg_hash = Hash_adp_bry.cs().Add_str_int("pgname", Arg__pgname)
|
||||
.Add_str_int("tooltip", Arg__tooltip).Add_str_int("bottomtoc", Arg__bottomtoc).Add_str_int("toc", Arg__toc);
|
||||
}
|
||||
@@ -16,10 +16,10 @@ 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.pagebanners; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
public class Pb_xtn extends Xox_mgr_base implements GfoInvkAble {
|
||||
@Override public boolean Enabled_default() {return true;}
|
||||
@Override public byte[] Xtn_key() {return Xtn_key_static;} public static final byte[] Xtn_key_static = Bry_.new_a7("graph");
|
||||
@Override public Xox_mgr Clone_new() {return new Pb_xtn();}
|
||||
@Override public void Xtn_init_by_wiki(Xowe_wiki wiki) {}
|
||||
public void Xtn_init_assert(Xowe_wiki wiki) {}
|
||||
import org.junit.*; import gplx.xowa.wikis.pages.skins.*;
|
||||
public class Pgbnr_func_tst {
|
||||
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test_html_full_str("{{PAGEBANNER}}", "");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user