1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-09-28 14:30:51 +00:00

Mw_parse: Refactor Linker class

This commit is contained in:
gnosygnu 2017-02-08 11:37:14 -05:00
parent 26527a8800
commit 85f05bfd02
14 changed files with 2888 additions and 463 deletions

File diff suppressed because it is too large Load Diff

View File

@ -36,7 +36,7 @@ class Xomw_linker__normalize_subpage_link__fxt {
this.wiki = Xoa_app_fxt.Make__wiki__edit(app);
}
public void Test__normalize_subpage_link(String page_title_str, String link, String text, String expd_link, String expd_text) {
mgr.Normalize_subpage_link(normalize_subpage_link, wiki.Ttl_parse(Bry_.new_u8(page_title_str)), Bry_.new_u8(link), Bry_.new_u8(text));
mgr.normalizeSubpageLink(normalize_subpage_link, wiki.Ttl_parse(Bry_.new_u8(page_title_str)), Bry_.new_u8(link), Bry_.new_u8(text));
Gftest.Eq__str(expd_link, String_.new_u8(normalize_subpage_link.link));
Gftest.Eq__str(expd_text, String_.new_u8(normalize_subpage_link.text));
}

View File

@ -32,7 +32,7 @@ class Xomw_linker__split_trail__fxt {
linker.Init_by_wiki(new Xomw_parser_env(), trie);
}
public void Test__split_trail(String trail_str, String expd_inside, String expd_trail) {
byte[][] split_trail = linker.Split_trail(Bry_.new_u8(trail_str));
byte[][] split_trail = linker.splitTrail(Bry_.new_u8(trail_str));
Gftest.Eq__str(expd_inside, String_.new_u8(split_trail[0]));
Gftest.Eq__str(expd_trail , String_.new_u8(split_trail[1]));
}

View File

@ -157,7 +157,7 @@ public class Xomw_link_renderer {
}
// XO.MW:SYNC:1.29; DATE:2017-01-31
private Xoa_ttl Normalize_target(Xoa_ttl target) {
return Xomw_linker.Normalise_special_page(target);
return Xomw_linker.normaliseSpecialPage(target);
}
// XO.MW:SYNC:1.29; DATE:2017-02-01
private void Merge_attribs(Xomw_atr_mgr src, Xomw_atr_mgr trg) {

View File

@ -138,54 +138,54 @@ public class Xomw_ThumbnailImage extends Xomw_MediaTransformOutput { private fin
attribs.Add_many(Gfh_atr_.Bry__alt, alt);
attribs.Add_many(Gfh_atr_.Bry__src, url);
boolean link_attribs_is_null = false;
if (!Php_utl_.Empty(options.custom_url_link)) {
if (!Php_utl_.empty(options.custom_url_link)) {
link_attribs.Clear();
link_attribs.Add_many(Gfh_atr_.Bry__href, options.custom_url_link);
if (!Php_utl_.Empty(options.title)) {
if (!Php_utl_.empty(options.title)) {
link_attribs.Add_many(Gfh_atr_.Bry__title, options.title);
}
if (Php_utl_.Empty(options.custom_target_link)) {
if (Php_utl_.empty(options.custom_target_link)) {
link_attribs.Add_many(Gfh_atr_.Bry__target, options.custom_target_link);
}
else if (Php_utl_.Empty(options.parser_extlink_target)) {
else if (Php_utl_.empty(options.parser_extlink_target)) {
link_attribs.Add_many(Gfh_atr_.Bry__target, options.parser_extlink_target);
}
if (Php_utl_.Empty(options.parser_extlink_rel)) {
if (Php_utl_.empty(options.parser_extlink_rel)) {
link_attribs.Add_many(Gfh_atr_.Bry__rel, options.parser_extlink_rel);
}
}
else if (!Php_utl_.Empty(options.custom_title_link)) {
else if (!Php_utl_.empty(options.custom_title_link)) {
// byte[] title = options.custom_title_link;
// link_attribs.Clear();
// link_attribs.Add_many(Gfh_atr_.Bry__href, title.Get_link_url());
// byte[] options_title = options.title;
// link_attribs.Add_many(Gfh_atr_.Bry__title, Php_utl_.Empty(options_title) ? title.Get_full_text() : options_title);
// link_attribs.Add_many(Gfh_atr_.Bry__title, Php_utl_.empty(options_title) ? title.Get_full_text() : options_title);
}
else if (!Php_utl_.Empty(options.desc_link)) {
else if (!Php_utl_.empty(options.desc_link)) {
// link_attribs = this.getDescLinkAttribs(
// empty(options['title']) ? null : options['title'],
// $query
// );
}
else if (!Php_utl_.Empty(options.file_link)) {
else if (!Php_utl_.empty(options.file_link)) {
// link_attribs.Clear();
// link_attribs.Add_many(Gfh_atr_.Bry__href, file.Get_url());
}
else {
link_attribs_is_null = true;
if (!Php_utl_.Empty(options.title)) {
if (!Php_utl_.empty(options.title)) {
attribs.Add_many(Gfh_atr_.Bry__title, options.title);
}
}
if (!Php_utl_.Empty(options.no_dimensions)) {
if (!Php_utl_.empty(options.no_dimensions)) {
attribs.Add_many(Gfh_atr_.Bry__width, Int_.To_bry(width));
attribs.Add_many(Gfh_atr_.Bry__height, Int_.To_bry(height));
}
if (!Php_utl_.Empty(options.valign)) {
if (!Php_utl_.empty(options.valign)) {
attribs.Add_many(Gfh_atr_.Bry__style, Bry_.Add(Bry__vertical_align, options.valign));
}
if (!Php_utl_.Empty(options.img_cls)) {
if (!Php_utl_.empty(options.img_cls)) {
attribs.Add_many(Gfh_atr_.Bry__class, options.img_cls);
}
if (Php_utl_.isset(options.override_height)) {
@ -198,7 +198,7 @@ public class Xomw_ThumbnailImage extends Xomw_MediaTransformOutput { private fin
// Additional densities for responsive images, if specified.
// If any of these urls is the same as src url, it'll be excluded.
// $responsiveUrls = array_diff(this.responsiveUrls, [ this.url ]);
// if (!Php_utl_.Empty($responsiveUrls)) {
// if (!Php_utl_.empty($responsiveUrls)) {
// $attribs['srcset'] = Html::srcSet($responsiveUrls);
// }

View File

@ -44,6 +44,7 @@ public class Xomw_parser {
private int marker_index = 0;
// private final Xomw_prepro_wkr prepro_wkr = new Xomw_prepro_wkr();
public Xomw_parser_env Env() {return env;} private final Xomw_parser_env env = new Xomw_parser_env();
public Xomw_parser_options Options() {return options;} private final Xomw_parser_options options = new Xomw_parser_options();
public Xomw_strip_state Strip_state() {return strip_state;} private final Xomw_strip_state strip_state = new Xomw_strip_state();
public Xomw_sanitizer Sanitizer() {return sanitizer;} private final Xomw_sanitizer sanitizer = new Xomw_sanitizer();
public Xomw_linker Linker() {return linker;} private final Xomw_linker linker;

View File

@ -20,6 +20,11 @@ import gplx.xowa.mws.filerepo.file.*; import gplx.xowa.mws.media.*;
public class Xomw_parser_env {
public byte[] Lang__align_end = Bry_.new_a7("right");
public int User__default__thumbsize = 220;
public int Global__wgSVGMaxSize = 5120;
public double Global__wgThumbUpright = .75d;
public int[] Global__wgThumbLimits = new int[] {120, 150, 180, 200, 250, 300};
public Xomw_MagicWordMgr Magic_word_mgr() {return magic_word_mgr;} private final Xomw_MagicWordMgr magic_word_mgr = new Xomw_MagicWordMgr();
public Xomw_message_mgr Message_mgr() {return message_mgr;} private final Xomw_message_mgr message_mgr = new Xomw_message_mgr();
public Xomw_file_finder File_finder() {return file_finder;} private Xomw_file_finder file_finder = new Xomw_file_finder__noop();

View File

@ -0,0 +1,933 @@
/*
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.mws.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*;
public class Xomw_parser_options {
public Xomw_parser_options() {
this.mThumbSize = 220;
}
// /**
// * Interlanguage links are removed and returned in an array
// */
// private $mInterwikiMagic;
//
// /**
// * Allow external images inline?
// */
// private $mAllowExternalImages;
//
// /**
// * If not, any exception?
// */
// private $mAllowExternalImagesFrom;
//
// /**
// * If not or it doesn't match, should we check an on-wiki whitelist?
// */
// private $mEnableImageWhitelist;
//
// /**
// * Date format index
// */
// private $mDateFormat = null;
//
// /**
// * Create "edit section" links?
// */
// private $mEditSection = true;
//
// /**
// * Allow inclusion of special pages?
// */
// private $mAllowSpecialInclusion;
//
// /**
// * Use tidy to cleanup output HTML?
// */
// private $mTidy = false;
//
// /**
// * Which lang to call for PLURAL and GRAMMAR
// */
// private $mInterfaceMessage = false;
//
// /**
// * Overrides $mInterfaceMessage with arbitrary language
// */
// private $mTargetLanguage = null;
//
// /**
// * Maximum size of template expansions, in bytes
// */
// private $mMaxIncludeSize;
//
// /**
// * Maximum number of nodes touched by PPFrame::expand()
// */
// private $mMaxPPNodeCount;
//
// /**
// * Maximum number of nodes generated by Preprocessor::preprocessToObj()
// */
// private $mMaxGeneratedPPNodeCount;
//
// /**
// * Maximum recursion depth in PPFrame::expand()
// */
// private $mMaxPPExpandDepth;
//
// /**
// * Maximum recursion depth for templates within templates
// */
// private $mMaxTemplateDepth;
//
// /**
// * Maximum number of calls per parse to expensive parser functions
// */
// private $mExpensiveParserFunctionLimit;
//
// /**
// * Remove HTML comments. ONLY APPLIES TO PREPROCESS OPERATIONS
// */
// private $mRemoveComments = true;
//
// /**
// * @var callable Callback for current revision fetching; first argument to call_user_func().
// */
// private $mCurrentRevisionCallback =
// [ 'Parser', 'statelessFetchRevision' ];
//
// /**
// * @var callable Callback for template fetching; first argument to call_user_func().
// */
// private $mTemplateCallback =
// [ 'Parser', 'statelessFetchTemplate' ];
//
// /**
// * @var callable|null Callback to generate a guess for {{REVISIONID}}
// */
// private $mSpeculativeRevIdCallback;
//
// /**
// * Enable limit report in an HTML comment on output
// */
// private $mEnableLimitReport = false;
//
// /**
// * Timestamp used for {{CURRENTDAY}} etc.
// */
// private $mTimestamp;
//
// /**
// * Target attribute for external links
// */
// private $mExternalLinkTarget;
//
// /**
// * Clean up signature texts?
// * @see Parser::cleanSig
// */
// private $mCleanSignatures;
//
// /**
// * Transform wiki markup when saving the page?
// */
// private $mPreSaveTransform = true;
//
// /**
// * Whether content conversion should be disabled
// */
// private $mDisableContentConversion;
//
// /**
// * Whether title conversion should be disabled
// */
// private $mDisableTitleConversion;
//
// /**
// * Automatically number headings?
// */
// private $mNumberHeadings;
/**
* Thumb size preferred by the user.
*/
private int mThumbSize;
// /**
// * Maximum article size of an article to be marked as "stub"
// */
// private $mStubThreshold;
//
// /**
// * Language Object of the User language.
// */
// private $mUserLang;
//
// /**
// * @var User
// * Stored user Object
// */
// private $mUser;
//
// /**
// * Parsing the page for a "preview" operation?
// */
// private $mIsPreview = false;
//
// /**
// * Parsing the page for a "preview" operation on a single section?
// */
// private $mIsSectionPreview = false;
//
// /**
// * Parsing the printable version of the page?
// */
// private $mIsPrintable = false;
//
// /**
// * Extra key that should be present in the caching key.
// */
// private $mExtraKey = '';
//
// /**
// * Are magic ISBN links enabled?
// */
// private $mMagicISBNLinks = true;
//
// /**
// * Are magic PMID links enabled?
// */
// private $mMagicPMIDLinks = true;
//
// /**
// * Are magic RFC links enabled?
// */
// private $mMagicRFCLinks = true;
//
// /**
// * Function to be called when an option is accessed.
// */
// private $onAccessCallback = null;
//
// /**
// * If the page being parsed is a redirect, this should hold the redirect
// * target.
// * @var Title|null
// */
// private $redirectTarget = null;
//
// public function getInterwikiMagic() {
// return this.mInterwikiMagic;
// }
//
// public function getAllowExternalImages() {
// return this.mAllowExternalImages;
// }
//
// public function getAllowExternalImagesFrom() {
// return this.mAllowExternalImagesFrom;
// }
//
// public function getEnableImageWhitelist() {
// return this.mEnableImageWhitelist;
// }
//
// public function getEditSection() {
// return this.mEditSection;
// }
//
// public function getNumberHeadings() {
// this.optionUsed( 'numberheadings' );
//
// return this.mNumberHeadings;
// }
//
// public function getAllowSpecialInclusion() {
// return this.mAllowSpecialInclusion;
// }
//
// public function getTidy() {
// return this.mTidy;
// }
//
// public function getInterfaceMessage() {
// return this.mInterfaceMessage;
// }
//
// public function getTargetLanguage() {
// return this.mTargetLanguage;
// }
//
// public function getMaxIncludeSize() {
// return this.mMaxIncludeSize;
// }
//
// public function getMaxPPNodeCount() {
// return this.mMaxPPNodeCount;
// }
//
// public function getMaxGeneratedPPNodeCount() {
// return this.mMaxGeneratedPPNodeCount;
// }
//
// public function getMaxPPExpandDepth() {
// return this.mMaxPPExpandDepth;
// }
//
// public function getMaxTemplateDepth() {
// return this.mMaxTemplateDepth;
// }
//
// /* @since 1.20 */
// public function getExpensiveParserFunctionLimit() {
// return this.mExpensiveParserFunctionLimit;
// }
//
// public function getRemoveComments() {
// return this.mRemoveComments;
// }
//
// /* @since 1.24 */
// public function getCurrentRevisionCallback() {
// return this.mCurrentRevisionCallback;
// }
//
// public function getTemplateCallback() {
// return this.mTemplateCallback;
// }
//
// /** @since 1.28 */
// public function getSpeculativeRevIdCallback() {
// return this.mSpeculativeRevIdCallback;
// }
//
// public function getEnableLimitReport() {
// return this.mEnableLimitReport;
// }
//
// public function getCleanSignatures() {
// return this.mCleanSignatures;
// }
//
// public function getExternalLinkTarget() {
// return this.mExternalLinkTarget;
// }
//
// public function getDisableContentConversion() {
// return this.mDisableContentConversion;
// }
//
// public function getDisableTitleConversion() {
// return this.mDisableTitleConversion;
// }
public int getThumbSize() {
// this.optionUsed( 'thumbsize' );
return this.mThumbSize;
}
// public function getStubThreshold() {
// this.optionUsed( 'stubthreshold' );
//
// return this.mStubThreshold;
// }
//
// public function getIsPreview() {
// return this.mIsPreview;
// }
//
// public function getIsSectionPreview() {
// return this.mIsSectionPreview;
// }
//
// public function getIsPrintable() {
// this.optionUsed( 'printable' );
//
// return this.mIsPrintable;
// }
//
// public function getUser() {
// return this.mUser;
// }
//
// public function getPreSaveTransform() {
// return this.mPreSaveTransform;
// }
//
// public function getDateFormat() {
// this.optionUsed( 'dateformat' );
// if ( !isset( this.mDateFormat ) ) {
// this.mDateFormat = this.mUser->getDatePreference();
// }
// return this.mDateFormat;
// }
//
// public function getTimestamp() {
// if ( !isset( this.mTimestamp ) ) {
// this.mTimestamp = wfTimestampNow();
// }
// return this.mTimestamp;
// }
//
// /**
// * Get the user language used by the parser for this page and split the parser cache.
// *
// * @warning: Calling this causes the parser cache to be fragmented by user language!
// * To avoid cache fragmentation, output should not depend on the user language.
// * Use Parser::getFunctionLang() or Parser::getTargetLanguage() instead!
// *
// * @note This function will trigger a cache fragmentation by recording the
// * 'userlang' option, see optionUsed(). This is done to avoid cache pollution
// * when the page is rendered based on the language of the user.
// *
// * @note When saving, this will return the default language instead of the user's.
// * {{int: }} uses this which used to produce inconsistent link tables (bug 14404).
// *
// * @return Language
// * @since 1.19
// */
// public function getUserLangObj() {
// this.optionUsed( 'userlang' );
// return this.mUserLang;
// }
//
// /**
// * Same as getUserLangObj() but returns a String instead.
// *
// * @warning: Calling this causes the parser cache to be fragmented by user language!
// * To avoid cache fragmentation, output should not depend on the user language.
// * Use Parser::getFunctionLang() or Parser::getTargetLanguage() instead!
// *
// * @see getUserLangObj()
// *
// * @return String Language code
// * @since 1.17
// */
// public function getUserLang() {
// return this.getUserLangObj()->getCode();
// }
//
// /**
// * @since 1.28
// * @return boolean
// */
// public function getMagicISBNLinks() {
// return this.mMagicISBNLinks;
// }
//
// /**
// * @since 1.28
// * @return boolean
// */
// public function getMagicPMIDLinks() {
// return this.mMagicPMIDLinks;
// }
// /**
// * @since 1.28
// * @return boolean
// */
// public function getMagicRFCLinks() {
// return this.mMagicRFCLinks;
// }
// public function setInterwikiMagic( $x ) {
// return wfSetVar( this.mInterwikiMagic, $x );
// }
//
// public function setAllowExternalImages( $x ) {
// return wfSetVar( this.mAllowExternalImages, $x );
// }
//
// public function setAllowExternalImagesFrom( $x ) {
// return wfSetVar( this.mAllowExternalImagesFrom, $x );
// }
//
// public function setEnableImageWhitelist( $x ) {
// return wfSetVar( this.mEnableImageWhitelist, $x );
// }
//
// public function setDateFormat( $x ) {
// return wfSetVar( this.mDateFormat, $x );
// }
//
// public function setEditSection( $x ) {
// return wfSetVar( this.mEditSection, $x );
// }
//
// public function setNumberHeadings( $x ) {
// return wfSetVar( this.mNumberHeadings, $x );
// }
//
// public function setAllowSpecialInclusion( $x ) {
// return wfSetVar( this.mAllowSpecialInclusion, $x );
// }
//
// public function setTidy( $x ) {
// return wfSetVar( this.mTidy, $x );
// }
//
// public function setInterfaceMessage( $x ) {
// return wfSetVar( this.mInterfaceMessage, $x );
// }
//
// public function setTargetLanguage( $x ) {
// return wfSetVar( this.mTargetLanguage, $x, true );
// }
//
// public function setMaxIncludeSize( $x ) {
// return wfSetVar( this.mMaxIncludeSize, $x );
// }
//
// public function setMaxPPNodeCount( $x ) {
// return wfSetVar( this.mMaxPPNodeCount, $x );
// }
//
// public function setMaxGeneratedPPNodeCount( $x ) {
// return wfSetVar( this.mMaxGeneratedPPNodeCount, $x );
// }
//
// public function setMaxTemplateDepth( $x ) {
// return wfSetVar( this.mMaxTemplateDepth, $x );
// }
//
// /* @since 1.20 */
// public function setExpensiveParserFunctionLimit( $x ) {
// return wfSetVar( this.mExpensiveParserFunctionLimit, $x );
// }
//
// public function setRemoveComments( $x ) {
// return wfSetVar( this.mRemoveComments, $x );
// }
//
// /* @since 1.24 */
// public function setCurrentRevisionCallback( $x ) {
// return wfSetVar( this.mCurrentRevisionCallback, $x );
// }
//
// /** @since 1.28 */
// public function setSpeculativeRevIdCallback( $x ) {
// return wfSetVar( this.mSpeculativeRevIdCallback, $x );
// }
//
// public function setTemplateCallback( $x ) {
// return wfSetVar( this.mTemplateCallback, $x );
// }
//
// public function enableLimitReport( $x = true ) {
// return wfSetVar( this.mEnableLimitReport, $x );
// }
//
// public function setTimestamp( $x ) {
// return wfSetVar( this.mTimestamp, $x );
// }
//
// public function setCleanSignatures( $x ) {
// return wfSetVar( this.mCleanSignatures, $x );
// }
//
// public function setExternalLinkTarget( $x ) {
// return wfSetVar( this.mExternalLinkTarget, $x );
// }
//
// public function disableContentConversion( $x = true ) {
// return wfSetVar( this.mDisableContentConversion, $x );
// }
//
// public function disableTitleConversion( $x = true ) {
// return wfSetVar( this.mDisableTitleConversion, $x );
// }
//
// public function setUserLang( $x ) {
// if ( is_string( $x ) ) {
// $x = Language::factory( $x );
// }
//
// return wfSetVar( this.mUserLang, $x );
// }
//
// public function setThumbSize( $x ) {
// return wfSetVar( this.mThumbSize, $x );
// }
//
// public function setStubThreshold( $x ) {
// return wfSetVar( this.mStubThreshold, $x );
// }
//
// public function setPreSaveTransform( $x ) {
// return wfSetVar( this.mPreSaveTransform, $x );
// }
//
// public function setIsPreview( $x ) {
// return wfSetVar( this.mIsPreview, $x );
// }
//
// public function setIsSectionPreview( $x ) {
// return wfSetVar( this.mIsSectionPreview, $x );
// }
//
// public function setIsPrintable( $x ) {
// return wfSetVar( this.mIsPrintable, $x );
// }
//
// /**
// * Set the redirect target.
// *
// * Note that setting or changing this does not *make* the page a redirect
// * or change its target, it merely records the information for reference
// * during the parse.
// *
// * @since 1.24
// * @param Title|null $title
// */
// function setRedirectTarget( $title ) {
// this.redirectTarget = $title;
// }
//
// /**
// * Get the previously-set redirect target.
// *
// * @since 1.24
// * @return Title|null
// */
// function getRedirectTarget() {
// return this.redirectTarget;
// }
//
// /**
// * Extra key that should be present in the parser cache key.
// * @param String $key
// */
// public function addExtraKey( $key ) {
// this.mExtraKey .= '!' . $key;
// }
//
// /**
// * Constructor
// * @param User $user
// * @param Language $lang
// */
// public function __construct( $user = null, $lang = null ) {
// if ( $user === null ) {
// global $wgUser;
// if ( $wgUser === null ) {
// $user = new User;
// } else {
// $user = $wgUser;
// }
// }
// if ( $lang === null ) {
// global $wgLang;
// if ( !StubObject::isRealObject( $wgLang ) ) {
// $wgLang->_unstub();
// }
// $lang = $wgLang;
// }
// this.initialiseFromUser( $user, $lang );
// }
//
// /**
// * Get a ParserOptions Object for an anonymous user
// * @since 1.27
// * @return ParserOptions
// */
// public static function newFromAnon() {
// global $wgContLang;
// return new ParserOptions( new User, $wgContLang );
// }
//
// /**
// * Get a ParserOptions Object from a given user.
// * Language will be taken from $wgLang.
// *
// * @param User $user
// * @return ParserOptions
// */
// public static function newFromUser( $user ) {
// return new ParserOptions( $user );
// }
//
// /**
// * Get a ParserOptions Object from a given user and language
// *
// * @param User $user
// * @param Language $lang
// * @return ParserOptions
// */
// public static function newFromUserAndLang( User $user, Language $lang ) {
// return new ParserOptions( $user, $lang );
// }
//
// /**
// * Get a ParserOptions Object from a IContextSource Object
// *
// * @param IContextSource $context
// * @return ParserOptions
// */
// public static function newFromContext( IContextSource $context ) {
// return new ParserOptions( $context->getUser(), $context->getLanguage() );
// }
//
// /**
// * Get user options
// *
// * @param User $user
// * @param Language $lang
// */
// private function initialiseFromUser( $user, $lang ) {
// global $wgInterwikiMagic, $wgAllowExternalImages,
// $wgAllowExternalImagesFrom, $wgEnableImageWhitelist, $wgAllowSpecialInclusion,
// $wgMaxArticleSize, $wgMaxPPNodeCount, $wgMaxTemplateDepth, $wgMaxPPExpandDepth,
// $wgCleanSignatures, $wgExternalLinkTarget, $wgExpensiveParserFunctionLimit,
// $wgMaxGeneratedPPNodeCount, $wgDisableLangConversion, $wgDisableTitleConversion,
// $wgEnableMagicLinks;
//
// // *UPDATE* ParserOptions::matches() if any of this changes as needed
// this.mInterwikiMagic = $wgInterwikiMagic;
// this.mAllowExternalImages = $wgAllowExternalImages;
// this.mAllowExternalImagesFrom = $wgAllowExternalImagesFrom;
// this.mEnableImageWhitelist = $wgEnableImageWhitelist;
// this.mAllowSpecialInclusion = $wgAllowSpecialInclusion;
// this.mMaxIncludeSize = $wgMaxArticleSize * 1024;
// this.mMaxPPNodeCount = $wgMaxPPNodeCount;
// this.mMaxGeneratedPPNodeCount = $wgMaxGeneratedPPNodeCount;
// this.mMaxPPExpandDepth = $wgMaxPPExpandDepth;
// this.mMaxTemplateDepth = $wgMaxTemplateDepth;
// this.mExpensiveParserFunctionLimit = $wgExpensiveParserFunctionLimit;
// this.mCleanSignatures = $wgCleanSignatures;
// this.mExternalLinkTarget = $wgExternalLinkTarget;
// this.mDisableContentConversion = $wgDisableLangConversion;
// this.mDisableTitleConversion = $wgDisableLangConversion || $wgDisableTitleConversion;
// this.mMagicISBNLinks = $wgEnableMagicLinks['ISBN'];
// this.mMagicPMIDLinks = $wgEnableMagicLinks['PMID'];
// this.mMagicRFCLinks = $wgEnableMagicLinks['RFC'];
//
// this.mUser = $user;
// this.mNumberHeadings = $user->getOption( 'numberheadings' );
// this.mThumbSize = $user->getOption( 'thumbsize' );
// this.mStubThreshold = $user->getStubThreshold();
// this.mUserLang = $lang;
// }
//
// /**
// * Check if these options match that of another options set
// *
// * This ignores report limit settings that only affect HTML comments
// *
// * @param ParserOptions $other
// * @return boolean
// * @since 1.25
// */
// public function matches( ParserOptions $other ) {
// $fields = array_keys( get_class_vars( __CLASS__ ) );
// $fields = array_diff( $fields, [
// 'mEnableLimitReport', // only effects HTML comments
// 'onAccessCallback', // only used for ParserOutput option tracking
// ] );
// foreach ( $fields as $field ) {
// if ( !is_object( this.$field ) && this.$field !== $other->$field ) {
// return false;
// }
// }
// // Check the Object and lazy-loaded options
// return (
// this.mUserLang->equals( $other->mUserLang ) &&
// this.getDateFormat() === $other->getDateFormat()
// );
// }
//
// /**
// * Registers a callback for tracking which ParserOptions which are used.
// * This is a private API with the parser.
// * @param callable $callback
// */
// public function registerWatcher( $callback ) {
// this.onAccessCallback = $callback;
// }
//
// /**
// * Called when an option is accessed.
// * Calls the watcher that was set using registerWatcher().
// * Typically, the watcher callback is ParserOutput::registerOption().
// * The information registered that way will be used by ParserCache::save().
// *
// * @param String $optionName Name of the option
// */
// public function optionUsed( $optionName ) {
// if ( this.onAccessCallback ) {
// call_user_func( this.onAccessCallback, $optionName );
// }
// }
//
// /**
// * Returns the full array of options that would have been used by
// * in 1.16.
// * Used to get the old parser cache entries when available.
// * @return array
// */
// public static function legacyOptions() {
// return [
// 'stubthreshold',
// 'numberheadings',
// 'userlang',
// 'thumbsize',
// 'editsection',
// 'printable'
// ];
// }
//
// /**
// * Generate a hash String with the values set on these ParserOptions
// * for the keys given in the array.
// * This will be used as part of the hash key for the parser cache,
// * so users sharing the options with vary for the same page share
// * the same cached data safely.
// *
// * Extensions which require it should install 'PageRenderingHash' hook,
// * which will give them a chance to modify this key based on their own
// * settings.
// *
// * @since 1.17
// * @param array $forOptions
// * @param Title $title Used to get the content language of the page (since r97636)
// * @return String Page rendering hash
// */
// public function optionsHash( $forOptions, $title = null ) {
// global $wgRenderHashAppend;
//
// // FIXME: Once the cache key is reorganized this argument
// // can be dropped. It was used when the math extension was
// // part of core.
// $confstr = '*';
//
// // Space assigned for the stubthreshold but unused
// // since it disables the parser cache, its value will always
// // be 0 when this function is called by parsercache.
// if ( in_array( 'stubthreshold', $forOptions ) ) {
// $confstr .= '!' . this.mStubThreshold;
// } else {
// $confstr .= '!*';
// }
//
// if ( in_array( 'dateformat', $forOptions ) ) {
// $confstr .= '!' . this.getDateFormat();
// }
//
// if ( in_array( 'numberheadings', $forOptions ) ) {
// $confstr .= '!' . ( this.mNumberHeadings ? '1' : '' );
// } else {
// $confstr .= '!*';
// }
//
// if ( in_array( 'userlang', $forOptions ) ) {
// $confstr .= '!' . this.mUserLang->getCode();
// } else {
// $confstr .= '!*';
// }
//
// if ( in_array( 'thumbsize', $forOptions ) ) {
// $confstr .= '!' . this.mThumbSize;
// } else {
// $confstr .= '!*';
// }
//
// // add in language specific options, if any
// // @todo FIXME: This is just a way of retrieving the url/user preferred variant
// if ( !is_null( $title ) ) {
// $confstr .= $title->getPageLanguage()->getExtraHashOptions();
// } else {
// global $wgContLang;
// $confstr .= $wgContLang->getExtraHashOptions();
// }
//
// $confstr .= $wgRenderHashAppend;
//
// // @note: as of Feb 2015, core never sets the editsection flag, since it uses
// // <mw:editsection> tags to inject editsections on the fly. However, extensions
// // may be using it by calling ParserOption::optionUsed resp. ParserOutput::registerOption
// // directly. At least Wikibase does at this point in time.
// if ( !in_array( 'editsection', $forOptions ) ) {
// $confstr .= '!*';
// } elseif ( !this.mEditSection ) {
// $confstr .= '!edit=0';
// }
//
// if ( this.mIsPrintable && in_array( 'printable', $forOptions ) ) {
// $confstr .= '!printable=1';
// }
//
// if ( this.mExtraKey != '' ) {
// $confstr .= this.mExtraKey;
// }
//
// // Give a chance for extensions to modify the hash, if they have
// // extra options or other effects on the parser cache.
// Hooks::run( 'PageRenderingHash', [ &$confstr, this.getUser(), &$forOptions ] );
//
// // Make it a valid memcached key fragment
// $confstr = str_replace( ' ', '_', $confstr );
//
// return $confstr;
// }
//
// /**
// * Sets a hook to force that a page exists, and sets a current revision callback to return
// * a revision with custom content when the current revision of the page is requested.
// *
// * @since 1.25
// * @param Title $title
// * @param Content $content
// * @param User $user The user that the fake revision is attributed to
// * @return ScopedCallback to unset the hook
// */
// public function setupFakeRevision( $title, $content, $user ) {
// $oldCallback = this.setCurrentRevisionCallback(
// function (
// $titleToCheck, $parser = false ) use ( $title, $content, $user, &$oldCallback
// ) {
// if ( $titleToCheck->equals( $title ) ) {
// return new Revision( [
// 'page' => $title->getArticleID(),
// 'user_text' => $user->getName(),
// 'user' => $user->getId(),
// 'parent_id' => $title->getLatestRevID(),
// 'title' => $title,
// 'content' => $content
// ] );
// } else {
// return call_user_func( $oldCallback, $titleToCheck, $parser );
// }
// }
// );
//
// global $wgHooks;
// $wgHooks['TitleExists'][] =
// function ( $titleToCheck, &$exists ) use ( $title ) {
// if ( $titleToCheck->equals( $title ) ) {
// $exists = true;
// }
// };
// end( $wgHooks['TitleExists'] );
// $key = key( $wgHooks['TitleExists'] );
// LinkCache::singleton()->clearBadLink( $title->getPrefixedDBkey() );
// return new ScopedCallback( function () use ( $title, $key ) {
// global $wgHooks;
// unset( $wgHooks['TitleExists'][$key] );
// LinkCache::singleton()->clearLink( $title );
// } );
// }
}

View File

@ -213,7 +213,7 @@ public class Xomw_lnke_wkr {// THREAD.UNSAFE: caching for repeated calls
// This means that users can paste URLs directly into the text
// Funny characters like <EFBFBD> aren't valid in URLs anyway
// This was changed in August 2004
linker.Make_external_link(bfr, url, Bry_.Mid(src, text_bgn, text_end), Bool_.N, link_type, parser.Get_external_link_attribs(attribs), Bry_.Empty);
linker.makeExternalLink(bfr, url, Bry_.Mid(src, text_bgn, text_end), Bool_.N, link_type, parser.Get_external_link_attribs(attribs), Bry_.Empty);
// XO.MW.UNSUPPORTED.HOOK: registers link for processing by other extensions?
// Register link in the output Object.

View File

@ -408,7 +408,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
// for linking to a different variant.
if (!ns.Id_is_special() && nt.Eq_full_db(page_title) && !nt.Has_fragment()) {
bfr.Add(prefix);
linker.Make_self_link_obj(bfr, nt, text, Bry_.Empty, trail, Bry_.Empty);
linker.makeSelfLinkObj(bfr, nt, text, Bry_.Empty, trail, Bry_.Empty);
continue;
}
@ -619,7 +619,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
= frameParams.frame != null
|| frameParams.framed != null
|| frameParams.thumbnail != null
|| frameParams.manual_thumb != null
|| frameParams.manualthumb != null
;
// Will the image be presented in a frame, with the caption below?
@ -667,8 +667,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
// Linker does the rest
// byte[] time = options.time;
Object time = null;
// options = $this->mOptions->getThumbSize()
linker.makeImageLink(bfr, pctx, parser, title, file, frameParams, handlerParams, time, desc_query, null);
linker.makeImageLink(bfr, pctx, parser, title, file, frameParams, handlerParams, time, desc_query, parser.Options().getThumbSize());
// Give the handler a chance to modify the parser Object
// if (handler != null) {
@ -813,13 +812,13 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
return file;
}
public void Maybe_do_subpage_link(Xomw_linker__normalize_subpage_link rv, byte[] target, byte[] text) {
linker.Normalize_subpage_link(rv, page_title, target, text);
linker.normalizeSubpageLink(rv, page_title, target, text);
}
public void Replace_link_holders(Xomw_parser_ctx pctx, Xomw_parser_bfr pbfr) {
holders.Replace(pctx, pbfr);
}
public void Make_known_link_holder(Bry_bfr bfr, Xoa_ttl nt, byte[] text, byte[] trail, byte[] prefix) {
byte[][] split_trail = linker.Split_trail(trail);
byte[][] split_trail = linker.splitTrail(trail);
byte[] inside = split_trail[0];
trail = split_trail[1];

View File

@ -16,6 +16,7 @@ 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.mws.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*; import gplx.xowa.mws.parsers.*;
import gplx.xowa.mws.utls.*;
public class Xomw_params_frame {
public byte[] align = null;
public byte[] valign = null;
@ -24,7 +25,7 @@ public class Xomw_params_frame {
public byte[] framed = null;
public byte[] frameless = null;
public byte[] thumbnail = null;
public byte[] manual_thumb = null;
public byte[] manualthumb = null;
public byte[] alt = null;
public byte[] title = null;
public byte[] cls = null;
@ -38,7 +39,7 @@ public class Xomw_params_frame {
public byte[] custom_target_link = null;
public boolean desc_link = false;
public byte[] desc_query = null;
public double upright = -1;
public double upright;
public void Set(int uid, byte[] val_bry, int val_int) {
switch (uid) {
case Xomw_param_itm.Name__thumbnail: thumbnail = val_bry; break;
@ -46,12 +47,12 @@ public class Xomw_params_frame {
}
public Xomw_params_frame Clear() {
desc_link = false;
upright = -1;
upright = Php_utl_.Null_double;
align = valign = caption = frame = framed = frameless
= thumbnail = manual_thumb = alt = title = cls = img_cls
= thumbnail = manualthumb = alt = title = cls = img_cls
= link_title = link_url = link_target = no_link
= custom_url_link = custom_target_link = desc_query
= null;
= Php_utl_.Null_bry;
return this;
}
public void Copy_to(Xomw_params_frame src) {
@ -64,7 +65,7 @@ public class Xomw_params_frame {
this.framed = src.framed;
this.frameless = src.frameless;
this.thumbnail = src.thumbnail;
this.manual_thumb = src.manual_thumb;
this.manualthumb = src.manualthumb;
this.alt = src.alt;
this.title = src.title;
this.cls = src.cls;

View File

@ -261,7 +261,7 @@ public class Xomw_magiclinks_wkr {
byte[] text = null; // $this->maybeMakeExternalImage($url);
if (text == null) {
// Not an image, make a link
linker.Make_external_link(bfr, url
linker.makeExternalLink(bfr, url
, url // $this->getConverterLanguage()->markNoConversion($url, true),
, true, Bry_.new_a7("free")
, parser.Get_external_link_attribs(atrs)

View File

@ -0,0 +1,29 @@
/*
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.mws.utls; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*;
public class Php_math_ {
public static double Round(double v, int places) {
if (places < 0) { // -1 means round to 10; -2 means round to 100; etc..
int factor = (int)Math_.Pow(10, places * -1);
return ((int)(Math_.Round(v, 0) / factor)) * factor; // EX: ((int)Round(123, 0) / 10) * 10: 123 -> 12.3 -> 12 -> 120
}
else {
return Math_.Round(v, places);
}
}
}

View File

@ -17,10 +17,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.mws.utls; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*;
public class Php_utl_ {
public static boolean Empty(byte[] v) {return v == null || v.length == 0;}
public static boolean Empty(boolean v) {return v == false;}
public static boolean isset(byte[] v) {return v != null;}
public static boolean isset(int v) {return v != Null_int;}
public static boolean empty(byte[] v) {return v == null || v.length == 0;}
public static boolean empty(boolean v) {return v == false;}
public static boolean empty(int v) {return v == 0;}
public static boolean isset(byte[] v) {return v != null;}
public static boolean isset(int v) {return v != Null_int;}
public static boolean isset(double v) {return v != Null_double;}
public static boolean istrue(int v) {return v != Null_int;}
public static boolean isnumeric(byte[] src) {
if (src == null) return false;
@ -38,5 +40,6 @@ public class Php_utl_ {
return true;
}
public static final int Null_int = Int_.Max_value;
public static final double Null_double = Double_.MinValue;
public static final byte[] Null_bry = null;
}