mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Xomw: Add getNamespaceIds, getNamespaceAliases
This commit is contained in:
@@ -377,7 +377,7 @@ public class XomwLinker {
|
||||
|| XophpUtility.isset(frameParams.frameless)
|
||||
|| !XophpUtility.istrue(handlerParams.width)
|
||||
) {
|
||||
if (widthOption == XophpUtility.Null_int) { // XO.MW: MW does extra validation that widthOption is in array; ("!isset( $wgThumbLimits[$widthOption] )")
|
||||
if (widthOption == XophpUtility.NULL_INT) { // XO.MW: MW does extra validation that widthOption is in array; ("!isset( $wgThumbLimits[$widthOption] )")
|
||||
widthOption = env.User__default__thumbsize;
|
||||
}
|
||||
|
||||
@@ -395,7 +395,7 @@ public class XomwLinker {
|
||||
|
||||
// Use width which is smaller: real image width or user preference width
|
||||
// Unless image is scalable vector.
|
||||
if (handlerParams.height == XophpUtility.Null_int && handlerParams.width <= 0 ||
|
||||
if (handlerParams.height == XophpUtility.NULL_INT && handlerParams.width <= 0 ||
|
||||
prefWidth < handlerParams.width || file.isVectorized()) {
|
||||
handlerParams.width = prefWidth;
|
||||
}
|
||||
|
||||
@@ -188,9 +188,9 @@ public class XomwNamespace {
|
||||
* @return array
|
||||
* @since 1.17
|
||||
*/
|
||||
private static XomwNamespaceHash namespaces = null;
|
||||
public static XomwNamespaceHash getCanonicalNamespaces() {return getCanonicalNamespaces(false);}
|
||||
public static XomwNamespaceHash getCanonicalNamespaces(boolean rebuild) {
|
||||
private static XomwNamespacesById namespaces = null;
|
||||
public static XomwNamespacesById getCanonicalNamespaces() {return getCanonicalNamespaces(false);}
|
||||
public static XomwNamespacesById getCanonicalNamespaces(boolean rebuild) {
|
||||
if (namespaces == null || rebuild) {
|
||||
// global $wgExtraNamespaces, $wgCanonicalNamespaceNames;
|
||||
namespaces = XomwSetup.wgCanonicalNamespaceNames.Clone();
|
||||
@@ -234,8 +234,8 @@ public class XomwNamespace {
|
||||
xNamespaces = Hash_adp_bry.cs();
|
||||
int len = namespaces.Len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
XomwNamespaceItem item = (XomwNamespaceItem)namespaces.GetItemOrNull(i);
|
||||
xNamespaces.Add(Bry_.Lcase__all(item.text), item); // NOTE: MW does "strtolower($text)"; canonical namespaces are always ascii
|
||||
XomwNamespaceItem item = (XomwNamespaceItem)namespaces.GetAtOrNull(i);
|
||||
xNamespaces.Add(Bry_.Lcase__all(item.name), item); // NOTE: MW does "strtolower($text)"; canonical namespaces are always ascii
|
||||
}
|
||||
}
|
||||
// if (array_key_exists($name, $xNamespaces)) {
|
||||
@@ -498,5 +498,5 @@ public class XomwNamespace {
|
||||
//
|
||||
// return $usableLevels;
|
||||
// }
|
||||
public static final int NULL_NS_ID = XophpUtility.Null_int;
|
||||
public static final int NULL_NS_ID = XophpUtility.NULL_INT;
|
||||
}
|
||||
|
||||
@@ -16,9 +16,9 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
package gplx.xowa.mediawiki.includes; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*;
|
||||
public class XomwNamespaceItem {
|
||||
public final int id;
|
||||
public final byte[] text;
|
||||
public XomwNamespaceItem(int id, byte[] text) {
|
||||
public final byte[] name;
|
||||
public XomwNamespaceItem(int id, byte[] name) {
|
||||
this.id = id;
|
||||
this.text = text;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,22 +15,22 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.mediawiki.includes; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*;
|
||||
import gplx.core.lists.*;
|
||||
public class XomwNamespaceHash {
|
||||
public class XomwNamespacesById {
|
||||
private HashByInt hash = new HashByInt();
|
||||
public int Len() {return hash.Len();}
|
||||
public byte[] GetTextOrNull(int id) {
|
||||
public byte[] GetNameOrNull(int id) {
|
||||
XomwNamespaceItem item = (XomwNamespaceItem)hash.Get_by_or_null(id);
|
||||
return item == null ? null : item.text;
|
||||
return item == null ? null : item.name;
|
||||
}
|
||||
public XomwNamespaceItem GetItemOrNull(int idx) {
|
||||
public XomwNamespaceItem GetAtOrNull(int idx) {
|
||||
return (XomwNamespaceItem)hash.Get_at_or_null(idx);
|
||||
}
|
||||
public XomwNamespaceHash Add(int id, String text) {
|
||||
public XomwNamespacesById Add(int id, String text) {
|
||||
hash.Add(id, new XomwNamespaceItem(id, Bry_.new_u8(text)));
|
||||
return this;
|
||||
}
|
||||
public XomwNamespaceHash Clone() {
|
||||
XomwNamespaceHash rv = new XomwNamespaceHash();
|
||||
public XomwNamespacesById Clone() {
|
||||
XomwNamespacesById rv = new XomwNamespacesById();
|
||||
rv.hash = hash.Clone();
|
||||
return rv;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.mediawiki.includes; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*;
|
||||
public class XomwNamespacesByName {
|
||||
private final Ordered_hash hash = Ordered_hash_.New_bry();
|
||||
public int Len() {return hash.Len();}
|
||||
public int GetAsIdOrNullInt(byte[] name) {
|
||||
XomwNamespaceItem item = (XomwNamespaceItem)hash.Get_by(name);
|
||||
return item == null ? XophpUtility.NULL_INT : item.id;
|
||||
}
|
||||
public XomwNamespaceItem GetAtOrNull(int idx) {
|
||||
return (XomwNamespaceItem)hash.Get_at(idx);
|
||||
}
|
||||
public void Add(byte[] name, XomwNamespaceItem item) {
|
||||
hash.Add(name, item);
|
||||
}
|
||||
public XomwNamespacesByName Add(String name, int id) {
|
||||
byte[] nameBry = Bry_.new_u8(name);
|
||||
hash.Add(nameBry, new XomwNamespaceItem(id, nameBry));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -169,15 +169,17 @@ public class XomwSetup {
|
||||
// * all users if desired.
|
||||
// */
|
||||
// $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
|
||||
//
|
||||
// /**
|
||||
// * The canonical names of namespaces 6 and 7 are, as of v1.14, "File"
|
||||
// * and "File_talk". The old names "Image" and "Image_talk" are
|
||||
// * retained as aliases for backwards compatibility.
|
||||
// */
|
||||
// $wgNamespaceAliases['Image'] = NS_FILE;
|
||||
// $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
|
||||
//
|
||||
|
||||
/**
|
||||
* The canonical names of namespaces 6 and 7 are, as of v1.14, "File"
|
||||
* and "File_talk". The old names "Image" and "Image_talk" are
|
||||
* retained as aliases for backwards compatibility.
|
||||
*/
|
||||
public static final XomwNamespacesByName wgNamespaceAliases = new XomwNamespacesByName()
|
||||
.Add("Image", XomwDefines.NS_FILE)
|
||||
.Add("Image_talk", XomwDefines.NS_FILE_TALK)
|
||||
;
|
||||
|
||||
// /**
|
||||
// * Initialise $wgLockManagers to include basic FS version
|
||||
// */
|
||||
@@ -392,7 +394,7 @@ public class XomwSetup {
|
||||
* Definitions of the NS_ constants are in Defines.php
|
||||
* @private
|
||||
*/
|
||||
public static XomwNamespaceHash wgCanonicalNamespaceNames = new XomwNamespaceHash()
|
||||
public static XomwNamespacesById wgCanonicalNamespaceNames = new XomwNamespacesById()
|
||||
.Add(XomwDefines.NS_MEDIA , "Media")
|
||||
.Add(XomwDefines.NS_SPECIAL , "Special")
|
||||
.Add(XomwDefines.NS_TALK , "Talk")
|
||||
|
||||
@@ -76,7 +76,7 @@ public abstract class XomwImageHandler extends XomwMediaHandler { private final
|
||||
// pos = Bry_find_.Find_fwd_while_num(src, 1, len); // skip numeric
|
||||
// if (Bry_.Match(src, pos, len, Xomw_lnki_wkr.Bry__px)) { // matches "px"
|
||||
// Xomw_params_handler rv = new Xomw_params_handler();
|
||||
// rv.width = Bry_.To_int_or(src, 0, pos, XophpUtility.Null_int);
|
||||
// rv.width = Bry_.To_int_or(src, 0, pos, XophpUtility.NULL_INT);
|
||||
// return rv;
|
||||
// }
|
||||
// }
|
||||
@@ -130,7 +130,7 @@ public abstract class XomwImageHandler extends XomwMediaHandler { private final
|
||||
handlerParams.physicalWidth = handlerParams.width;
|
||||
} else {
|
||||
// Height was crap, unset it so that it will be calculated later
|
||||
handlerParams.height = XophpUtility.Null_int;
|
||||
handlerParams.height = XophpUtility.NULL_INT;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ class XomwImageHandler_fxt {
|
||||
public XomwImageHandler_fxt() {
|
||||
this.handler = new XomwTransformationalImageHandler(Bry_.new_a7("test_handler"));
|
||||
}
|
||||
public Xomw_params_handler Make__handlerParams(int w) {return Make__handlerParams(w, XophpUtility.Null_int, XophpUtility.Null_int, XophpUtility.Null_int);}
|
||||
public Xomw_params_handler Make__handlerParams(int w) {return Make__handlerParams(w, XophpUtility.NULL_INT, XophpUtility.NULL_INT, XophpUtility.NULL_INT);}
|
||||
public Xomw_params_handler Make__handlerParams(int w, int h, int phys_w, int phys_h) {
|
||||
Xomw_params_handler rv = new Xomw_params_handler();
|
||||
rv.width = w;
|
||||
|
||||
@@ -724,7 +724,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
|
||||
// Parsed a width param of imagelink like 300px or 200x300px
|
||||
// XO.MW.NOTE: for MW, "" -> null, null while "AxB" -> 0x0
|
||||
public void parseWidthParam(int[] img_size, byte[] src) {
|
||||
img_size[0] = img_size[1] = XophpUtility.Null_int;
|
||||
img_size[0] = img_size[1] = XophpUtility.NULL_INT;
|
||||
if (src == Bry_.Empty) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -44,12 +44,12 @@ public class Xomw_params_frame {
|
||||
}
|
||||
public Xomw_params_frame Clear() {
|
||||
desc_link = false;
|
||||
upright = XophpUtility.Null_double;
|
||||
upright = XophpUtility.NULL_DOUBLE;
|
||||
align = valign = caption = frame = framed = frameless
|
||||
= thumbnail = manualthumb = alt = title = cls = img_cls
|
||||
= link_title = link_url = link_target = no_link
|
||||
= custom_url_link = custom_target_link = desc_query
|
||||
= XophpUtility.Null_bry;
|
||||
= XophpUtility.NULL_BRY;
|
||||
return this;
|
||||
}
|
||||
public void Copy_to(Xomw_params_frame src) {
|
||||
|
||||
@@ -22,7 +22,7 @@ public class Xomw_params_handler {
|
||||
public int physicalHeight;
|
||||
public Xomw_params_handler Clear() {
|
||||
width = height = page
|
||||
= physicalWidth = physicalHeight = XophpUtility.Null_int;
|
||||
= physicalWidth = physicalHeight = XophpUtility.NULL_INT;
|
||||
return this;
|
||||
}
|
||||
public void Copy_to(Xomw_params_handler src) {
|
||||
|
||||
@@ -28,6 +28,6 @@ public class Xomw_params_scalar {
|
||||
public byte[] dstUrl;
|
||||
public byte[] interlace;
|
||||
public Xomw_params_scalar() {
|
||||
physicalWidth = physicalHeight = clientWidth = clientHeight = srcWidth = srcHeight = XophpUtility.Null_int;
|
||||
physicalWidth = physicalHeight = clientWidth = clientHeight = srcWidth = srcHeight = XophpUtility.NULL_INT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,65 +285,60 @@ public class XomwMediaWikiTitleCodec implements XomwTitleFormatter {
|
||||
// if (XomwRegexTitlePrefix.preg_match(m, dbkey)) {
|
||||
// byte[] p = m[0];
|
||||
// int ns = this.language.getNsIndex(p);
|
||||
// }
|
||||
// } while (true);
|
||||
// do {
|
||||
// $m = [];
|
||||
// if (preg_match($prefixRegexp, dbkey, $m)) {
|
||||
// $p = $m[1];
|
||||
// $ns = $this->language->getNsIndex($p);
|
||||
// if ($ns !== false) {
|
||||
// if (ns != XophpUtility.NULL_INT) {
|
||||
// // Ordinary namespace
|
||||
// dbkey = $m[2];
|
||||
// parts['namespace'] = $ns;
|
||||
// dbkey = m[1];
|
||||
// parts.ns = ns;
|
||||
// // For Talk:X pages, check if X has a "namespace" prefix
|
||||
// if ($ns == NS_TALK && preg_match($prefixRegexp, dbkey, $x)) {
|
||||
// if ($this->language->getNsIndex($x[1])) {
|
||||
// if (ns == XomwDefines.NS_TALK && XomwRegexTitlePrefix.preg_match(m, dbkey)) {
|
||||
// if (this.language.getNsIndex(m[0]) != XophpUtility.NULL_INT) {
|
||||
// // Disallow Talk:File:x type titles...
|
||||
// throw new XomwMalformedTitleException('title-invalid-talk-namespace', text);
|
||||
// } elseif (Interwiki::isValidInterwiki($x[1])) {
|
||||
// // TODO: get rid of global state!
|
||||
// // Disallow Talk:Interwiki:x type titles...
|
||||
// throw new XomwMalformedTitleException('title-invalid-talk-namespace', text);
|
||||
// throw new XomwMalformedTitleException("title-invalid-talk-namespace", text);
|
||||
// }
|
||||
// }
|
||||
// } elseif (Interwiki::isValidInterwiki($p)) {
|
||||
// // Interwiki link
|
||||
// dbkey = $m[2];
|
||||
// parts['interwiki'] = $this->language->lc($p);
|
||||
//
|
||||
// // Redundant interwiki prefix to the local wiki
|
||||
// foreach ($this->localInterwikis as $localIW) {
|
||||
// if (0 == strcasecmp(parts['interwiki'], $localIW)) {
|
||||
// if (dbkey == '') {
|
||||
// // Empty self-links should point to the Main Page, to ensure
|
||||
// // compatibility with cross-wiki transclusions and the like.
|
||||
// $mainPage = Title::newMainPage();
|
||||
// return [
|
||||
// 'interwiki' => $mainPage->getInterwiki(),
|
||||
// 'local_interwiki' => true,
|
||||
// 'fragment' => $mainPage->getFragment(),
|
||||
// 'namespace' => $mainPage->getNamespace(),
|
||||
// 'dbkey' => $mainPage->getDBkey(),
|
||||
// 'user_case_dbkey' => $mainPage->getUserCaseDBKey()
|
||||
// ];
|
||||
// }
|
||||
// parts['interwiki'] = '';
|
||||
// // local interwikis should behave like initial-colon links
|
||||
// parts['local_interwiki'] = true;
|
||||
//
|
||||
// // Do another namespace split...
|
||||
// continue 2;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // If there's an initial colon after the interwiki, that also
|
||||
// // resets the default namespace
|
||||
// if (dbkey !== '' && dbkey[0] == ':') {
|
||||
// parts['namespace'] = NS_MAIN;
|
||||
// dbkey = substr(dbkey, 1);
|
||||
//// else if (Interwiki::isValidInterwiki($x[1])) {
|
||||
//// // TODO: get rid of global state!
|
||||
//// // Disallow Talk:Interwiki:x type titles...
|
||||
//// throw new XomwMalformedTitleException('title-invalid-talk-namespace', text);
|
||||
//// }
|
||||
// }
|
||||
// }
|
||||
//// else if (Interwiki::isValidInterwiki($p)) {
|
||||
//// // Interwiki link
|
||||
//// dbkey = $m[2];
|
||||
//// parts['interwiki'] = this.language->lc($p);
|
||||
////
|
||||
//// // Redundant interwiki prefix to the local wiki
|
||||
//// foreach (this.localInterwikis as $localIW) {
|
||||
//// if (0 == strcasecmp(parts['interwiki'], $localIW)) {
|
||||
//// if (dbkey == '') {
|
||||
//// // Empty self-links should point to the Main Page, to ensure
|
||||
//// // compatibility with cross-wiki transclusions and the like.
|
||||
//// $mainPage = Title::newMainPage();
|
||||
//// return [
|
||||
//// 'interwiki' => $mainPage->getInterwiki(),
|
||||
//// 'local_interwiki' => true,
|
||||
//// 'fragment' => $mainPage->getFragment(),
|
||||
//// 'namespace' => $mainPage->getNamespace(),
|
||||
//// 'dbkey' => $mainPage->getDBkey(),
|
||||
//// 'user_case_dbkey' => $mainPage->getUserCaseDBKey()
|
||||
//// ];
|
||||
//// }
|
||||
//// parts['interwiki'] = '';
|
||||
//// // local interwikis should behave like initial-colon links
|
||||
//// parts['local_interwiki'] = true;
|
||||
////
|
||||
//// // Do another namespace split...
|
||||
//// continue 2;
|
||||
//// }
|
||||
//// }
|
||||
////
|
||||
//// // If there's an initial colon after the interwiki, that also
|
||||
//// // resets the default namespace
|
||||
//// if (dbkey !== '' && dbkey[0] == ':') {
|
||||
//// parts['namespace'] = NS_MAIN;
|
||||
//// dbkey = substr(dbkey, 1);
|
||||
//// }
|
||||
//// }
|
||||
// // If there's no recognized interwiki or namespace,
|
||||
// // then let the colon expression be part of the title.
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user