mirror of
https://github.com/gnosygnu/xowa.git
synced 2025-05-31 22:44:34 +00:00
Xomw: Add getNamespaceIds, getNamespaceAliases
This commit is contained in:
parent
5a6ac3a335
commit
1cab009d3c
@ -19,9 +19,9 @@ public class XophpUtility {
|
|||||||
public static boolean empty(boolean v) {return v == false;}
|
public static boolean empty(boolean v) {return v == false;}
|
||||||
public static boolean empty(int v) {return v == 0;}
|
public static boolean empty(int v) {return v == 0;}
|
||||||
public static boolean isset(byte[] v) {return v != null;}
|
public static boolean isset(byte[] v) {return v != null;}
|
||||||
public static boolean isset(int v) {return v != Null_int;}
|
public static boolean isset(int v) {return v != NULL_INT;}
|
||||||
public static boolean isset(double v) {return v != Null_double;}
|
public static boolean isset(double v) {return v != NULL_DOUBLE;}
|
||||||
public static boolean istrue(int v) {return v != Null_int;}
|
public static boolean istrue(int v) {return v != NULL_INT;}
|
||||||
public static boolean isnumeric(byte[] src) {
|
public static boolean isnumeric(byte[] src) {
|
||||||
if (src == null) return false;
|
if (src == null) return false;
|
||||||
int len = src.length;
|
int len = src.length;
|
||||||
@ -38,7 +38,7 @@ public class XophpUtility {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final int Null_int = Int_.Max_value;
|
public static final int NULL_INT = Int_.Max_value;
|
||||||
public static final double Null_double = Double_.MinValue;
|
public static final double NULL_DOUBLE = Double_.MinValue;
|
||||||
public static final byte[] Null_bry = null;
|
public static final byte[] NULL_BRY = null;
|
||||||
}
|
}
|
||||||
|
@ -377,7 +377,7 @@ public class XomwLinker {
|
|||||||
|| XophpUtility.isset(frameParams.frameless)
|
|| XophpUtility.isset(frameParams.frameless)
|
||||||
|| !XophpUtility.istrue(handlerParams.width)
|
|| !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;
|
widthOption = env.User__default__thumbsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -395,7 +395,7 @@ public class XomwLinker {
|
|||||||
|
|
||||||
// Use width which is smaller: real image width or user preference width
|
// Use width which is smaller: real image width or user preference width
|
||||||
// Unless image is scalable vector.
|
// 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()) {
|
prefWidth < handlerParams.width || file.isVectorized()) {
|
||||||
handlerParams.width = prefWidth;
|
handlerParams.width = prefWidth;
|
||||||
}
|
}
|
||||||
|
@ -188,9 +188,9 @@ public class XomwNamespace {
|
|||||||
* @return array
|
* @return array
|
||||||
* @since 1.17
|
* @since 1.17
|
||||||
*/
|
*/
|
||||||
private static XomwNamespaceHash namespaces = null;
|
private static XomwNamespacesById namespaces = null;
|
||||||
public static XomwNamespaceHash getCanonicalNamespaces() {return getCanonicalNamespaces(false);}
|
public static XomwNamespacesById getCanonicalNamespaces() {return getCanonicalNamespaces(false);}
|
||||||
public static XomwNamespaceHash getCanonicalNamespaces(boolean rebuild) {
|
public static XomwNamespacesById getCanonicalNamespaces(boolean rebuild) {
|
||||||
if (namespaces == null || rebuild) {
|
if (namespaces == null || rebuild) {
|
||||||
// global $wgExtraNamespaces, $wgCanonicalNamespaceNames;
|
// global $wgExtraNamespaces, $wgCanonicalNamespaceNames;
|
||||||
namespaces = XomwSetup.wgCanonicalNamespaceNames.Clone();
|
namespaces = XomwSetup.wgCanonicalNamespaceNames.Clone();
|
||||||
@ -234,8 +234,8 @@ public class XomwNamespace {
|
|||||||
xNamespaces = Hash_adp_bry.cs();
|
xNamespaces = Hash_adp_bry.cs();
|
||||||
int len = namespaces.Len();
|
int len = namespaces.Len();
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
XomwNamespaceItem item = (XomwNamespaceItem)namespaces.GetItemOrNull(i);
|
XomwNamespaceItem item = (XomwNamespaceItem)namespaces.GetAtOrNull(i);
|
||||||
xNamespaces.Add(Bry_.Lcase__all(item.text), item); // NOTE: MW does "strtolower($text)"; canonical namespaces are always ascii
|
xNamespaces.Add(Bry_.Lcase__all(item.name), item); // NOTE: MW does "strtolower($text)"; canonical namespaces are always ascii
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if (array_key_exists($name, $xNamespaces)) {
|
// if (array_key_exists($name, $xNamespaces)) {
|
||||||
@ -498,5 +498,5 @@ public class XomwNamespace {
|
|||||||
//
|
//
|
||||||
// return $usableLevels;
|
// 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.*;
|
package gplx.xowa.mediawiki.includes; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*;
|
||||||
public class XomwNamespaceItem {
|
public class XomwNamespaceItem {
|
||||||
public final int id;
|
public final int id;
|
||||||
public final byte[] text;
|
public final byte[] name;
|
||||||
public XomwNamespaceItem(int id, byte[] text) {
|
public XomwNamespaceItem(int id, byte[] name) {
|
||||||
this.id = id;
|
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.*;
|
package gplx.xowa.mediawiki.includes; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*;
|
||||||
import gplx.core.lists.*;
|
import gplx.core.lists.*;
|
||||||
public class XomwNamespaceHash {
|
public class XomwNamespacesById {
|
||||||
private HashByInt hash = new HashByInt();
|
private HashByInt hash = new HashByInt();
|
||||||
public int Len() {return hash.Len();}
|
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);
|
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);
|
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)));
|
hash.Add(id, new XomwNamespaceItem(id, Bry_.new_u8(text)));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public XomwNamespaceHash Clone() {
|
public XomwNamespacesById Clone() {
|
||||||
XomwNamespaceHash rv = new XomwNamespaceHash();
|
XomwNamespacesById rv = new XomwNamespacesById();
|
||||||
rv.hash = hash.Clone();
|
rv.hash = hash.Clone();
|
||||||
return rv;
|
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.
|
// * all users if desired.
|
||||||
// */
|
// */
|
||||||
// $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
|
// $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
|
||||||
//
|
|
||||||
// /**
|
/**
|
||||||
// * The canonical names of namespaces 6 and 7 are, as of v1.14, "File"
|
* 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
|
* and "File_talk". The old names "Image" and "Image_talk" are
|
||||||
// * retained as aliases for backwards compatibility.
|
* retained as aliases for backwards compatibility.
|
||||||
// */
|
*/
|
||||||
// $wgNamespaceAliases['Image'] = NS_FILE;
|
public static final XomwNamespacesByName wgNamespaceAliases = new XomwNamespacesByName()
|
||||||
// $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
|
.Add("Image", XomwDefines.NS_FILE)
|
||||||
//
|
.Add("Image_talk", XomwDefines.NS_FILE_TALK)
|
||||||
|
;
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
// * Initialise $wgLockManagers to include basic FS version
|
// * Initialise $wgLockManagers to include basic FS version
|
||||||
// */
|
// */
|
||||||
@ -392,7 +394,7 @@ public class XomwSetup {
|
|||||||
* Definitions of the NS_ constants are in Defines.php
|
* Definitions of the NS_ constants are in Defines.php
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
public static XomwNamespaceHash wgCanonicalNamespaceNames = new XomwNamespaceHash()
|
public static XomwNamespacesById wgCanonicalNamespaceNames = new XomwNamespacesById()
|
||||||
.Add(XomwDefines.NS_MEDIA , "Media")
|
.Add(XomwDefines.NS_MEDIA , "Media")
|
||||||
.Add(XomwDefines.NS_SPECIAL , "Special")
|
.Add(XomwDefines.NS_SPECIAL , "Special")
|
||||||
.Add(XomwDefines.NS_TALK , "Talk")
|
.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
|
// 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"
|
// if (Bry_.Match(src, pos, len, Xomw_lnki_wkr.Bry__px)) { // matches "px"
|
||||||
// Xomw_params_handler rv = new Xomw_params_handler();
|
// 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;
|
// return rv;
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
@ -130,7 +130,7 @@ public abstract class XomwImageHandler extends XomwMediaHandler { private final
|
|||||||
handlerParams.physicalWidth = handlerParams.width;
|
handlerParams.physicalWidth = handlerParams.width;
|
||||||
} else {
|
} else {
|
||||||
// Height was crap, unset it so that it will be calculated later
|
// 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() {
|
public XomwImageHandler_fxt() {
|
||||||
this.handler = new XomwTransformationalImageHandler(Bry_.new_a7("test_handler"));
|
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) {
|
public Xomw_params_handler Make__handlerParams(int w, int h, int phys_w, int phys_h) {
|
||||||
Xomw_params_handler rv = new Xomw_params_handler();
|
Xomw_params_handler rv = new Xomw_params_handler();
|
||||||
rv.width = w;
|
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
|
// Parsed a width param of imagelink like 300px or 200x300px
|
||||||
// XO.MW.NOTE: for MW, "" -> null, null while "AxB" -> 0x0
|
// XO.MW.NOTE: for MW, "" -> null, null while "AxB" -> 0x0
|
||||||
public void parseWidthParam(int[] img_size, byte[] src) {
|
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) {
|
if (src == Bry_.Empty) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -44,12 +44,12 @@ public class Xomw_params_frame {
|
|||||||
}
|
}
|
||||||
public Xomw_params_frame Clear() {
|
public Xomw_params_frame Clear() {
|
||||||
desc_link = false;
|
desc_link = false;
|
||||||
upright = XophpUtility.Null_double;
|
upright = XophpUtility.NULL_DOUBLE;
|
||||||
align = valign = caption = frame = framed = frameless
|
align = valign = caption = frame = framed = frameless
|
||||||
= thumbnail = manualthumb = alt = title = cls = img_cls
|
= thumbnail = manualthumb = alt = title = cls = img_cls
|
||||||
= link_title = link_url = link_target = no_link
|
= link_title = link_url = link_target = no_link
|
||||||
= custom_url_link = custom_target_link = desc_query
|
= custom_url_link = custom_target_link = desc_query
|
||||||
= XophpUtility.Null_bry;
|
= XophpUtility.NULL_BRY;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public void Copy_to(Xomw_params_frame src) {
|
public void Copy_to(Xomw_params_frame src) {
|
||||||
|
@ -22,7 +22,7 @@ public class Xomw_params_handler {
|
|||||||
public int physicalHeight;
|
public int physicalHeight;
|
||||||
public Xomw_params_handler Clear() {
|
public Xomw_params_handler Clear() {
|
||||||
width = height = page
|
width = height = page
|
||||||
= physicalWidth = physicalHeight = XophpUtility.Null_int;
|
= physicalWidth = physicalHeight = XophpUtility.NULL_INT;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public void Copy_to(Xomw_params_handler src) {
|
public void Copy_to(Xomw_params_handler src) {
|
||||||
|
@ -28,6 +28,6 @@ public class Xomw_params_scalar {
|
|||||||
public byte[] dstUrl;
|
public byte[] dstUrl;
|
||||||
public byte[] interlace;
|
public byte[] interlace;
|
||||||
public Xomw_params_scalar() {
|
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)) {
|
// if (XomwRegexTitlePrefix.preg_match(m, dbkey)) {
|
||||||
// byte[] p = m[0];
|
// byte[] p = m[0];
|
||||||
// int ns = this.language.getNsIndex(p);
|
// int ns = this.language.getNsIndex(p);
|
||||||
// }
|
// if (ns != XophpUtility.NULL_INT) {
|
||||||
// } while (true);
|
|
||||||
// do {
|
|
||||||
// $m = [];
|
|
||||||
// if (preg_match($prefixRegexp, dbkey, $m)) {
|
|
||||||
// $p = $m[1];
|
|
||||||
// $ns = $this->language->getNsIndex($p);
|
|
||||||
// if ($ns !== false) {
|
|
||||||
// // Ordinary namespace
|
// // Ordinary namespace
|
||||||
// dbkey = $m[2];
|
// dbkey = m[1];
|
||||||
// parts['namespace'] = $ns;
|
// parts.ns = ns;
|
||||||
// // For Talk:X pages, check if X has a "namespace" prefix
|
// // For Talk:X pages, check if X has a "namespace" prefix
|
||||||
// if ($ns == NS_TALK && preg_match($prefixRegexp, dbkey, $x)) {
|
// if (ns == XomwDefines.NS_TALK && XomwRegexTitlePrefix.preg_match(m, dbkey)) {
|
||||||
// if ($this->language->getNsIndex($x[1])) {
|
// if (this.language.getNsIndex(m[0]) != XophpUtility.NULL_INT) {
|
||||||
// // Disallow Talk:File:x type titles...
|
// // Disallow Talk:File:x type titles...
|
||||||
// throw new XomwMalformedTitleException('title-invalid-talk-namespace', text);
|
// 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);
|
|
||||||
// }
|
// }
|
||||||
// }
|
//// else if (Interwiki::isValidInterwiki($x[1])) {
|
||||||
// } elseif (Interwiki::isValidInterwiki($p)) {
|
//// // TODO: get rid of global state!
|
||||||
// // Interwiki link
|
//// // Disallow Talk:Interwiki:x type titles...
|
||||||
// dbkey = $m[2];
|
//// throw new XomwMalformedTitleException('title-invalid-talk-namespace', text);
|
||||||
// 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($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,
|
// // If there's no recognized interwiki or namespace,
|
||||||
// // then let the colon expression be part of the title.
|
// // then let the colon expression be part of the title.
|
||||||
// }
|
// }
|
||||||
|
@ -30,9 +30,9 @@ public class XomwLanguage {
|
|||||||
// public $mExtendedSpecialPageAliases;
|
// public $mExtendedSpecialPageAliases;
|
||||||
//
|
//
|
||||||
// /** @var array|null */
|
// /** @var array|null */
|
||||||
private XomwNamespaceHash namespaceNames;
|
private XomwNamespacesById namespaceNames;
|
||||||
// protected $mNamespaceIds, $namespaceAliases;
|
private XomwNamespacesByName mNamespaceIds, namespaceAliases;
|
||||||
//
|
|
||||||
// /**
|
// /**
|
||||||
// * ReplacementArray Object caches
|
// * ReplacementArray Object caches
|
||||||
// */
|
// */
|
||||||
@ -485,11 +485,11 @@ public class XomwLanguage {
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public XomwNamespaceHash getNamespaces() {
|
public XomwNamespacesById getNamespaces() {
|
||||||
if (this.namespaceNames == null) {
|
if (this.namespaceNames == null) {
|
||||||
// global $wgMetaNamespace, $wgMetaNamespaceTalk, $wgExtraNamespaces;
|
// global $wgMetaNamespace, $wgMetaNamespaceTalk, $wgExtraNamespaces;
|
||||||
//
|
//
|
||||||
XomwNamespaceHash validNamespaces = XomwNamespace.getCanonicalNamespaces();
|
XomwNamespacesById validNamespaces = XomwNamespace.getCanonicalNamespaces();
|
||||||
//
|
//
|
||||||
// this.namespaceNames = $wgExtraNamespaces +
|
// this.namespaceNames = $wgExtraNamespaces +
|
||||||
// self::$dataCache->getItem(this.mCode, 'namespaceNames');
|
// self::$dataCache->getItem(this.mCode, 'namespaceNames');
|
||||||
@ -566,8 +566,8 @@ public class XomwLanguage {
|
|||||||
* @return String|boolean String if the namespace value exists, otherwise false
|
* @return String|boolean String if the namespace value exists, otherwise false
|
||||||
*/
|
*/
|
||||||
public byte[] getNsText(int index) {
|
public byte[] getNsText(int index) {
|
||||||
XomwNamespaceHash nsHash = this.getNamespaces();
|
XomwNamespacesById nsHash = this.getNamespaces();
|
||||||
return nsHash.GetTextOrNull(index);
|
return nsHash.GetNameOrNull(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
@ -640,12 +640,14 @@ public class XomwLanguage {
|
|||||||
// $ids = this.getNamespaceIds();
|
// $ids = this.getNamespaceIds();
|
||||||
// return isset($ids[$lctext]) ? $ids[$lctext] : false;
|
// return isset($ids[$lctext]) ? $ids[$lctext] : false;
|
||||||
// }
|
// }
|
||||||
//
|
|
||||||
// /**
|
/**
|
||||||
// * @return array
|
* @return array
|
||||||
// */
|
*/
|
||||||
// public function getNamespaceAliases() {
|
public XomwNamespacesByName getNamespaceAliases() {
|
||||||
// if (is_null(this.namespaceAliases)) {
|
if (this.namespaceAliases == null) {
|
||||||
|
// XO.MW: MW uses two sets: "aliases" + "convertedNames" and then combines them; XO just uses one
|
||||||
|
this.namespaceAliases = new XomwNamespacesByName();
|
||||||
// $aliases = self::$dataCache->getItem(this.mCode, 'namespaceAliases');
|
// $aliases = self::$dataCache->getItem(this.mCode, 'namespaceAliases');
|
||||||
// if (!$aliases) {
|
// if (!$aliases) {
|
||||||
// $aliases = [];
|
// $aliases = [];
|
||||||
@ -667,8 +669,8 @@ public class XomwLanguage {
|
|||||||
// $aliases[$alias] = $index;
|
// $aliases[$alias] = $index;
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
//
|
|
||||||
// # Also add converted namespace names as aliases, to avoid confusion.
|
// Also add converted namespace names as aliases, to avoid confusion.
|
||||||
// $convertedNames = [];
|
// $convertedNames = [];
|
||||||
// foreach (this.getVariants() as $variant) {
|
// foreach (this.getVariants() as $variant) {
|
||||||
// if ($variant === this.mCode) {
|
// if ($variant === this.mCode) {
|
||||||
@ -680,36 +682,42 @@ public class XomwLanguage {
|
|||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// this.namespaceAliases = $aliases + $convertedNames;
|
// this.namespaceAliases = $aliases + $convertedNames;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// return this.namespaceAliases;
|
return this.namespaceAliases;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// /**
|
/**
|
||||||
// * @return array
|
* @return array
|
||||||
// */
|
*/
|
||||||
// public function getNamespaceIds() {
|
public XomwNamespacesByName getNamespaceIds() {
|
||||||
// if (is_null(this.mNamespaceIds)) {
|
if (this.mNamespaceIds == null) {
|
||||||
// global $wgNamespaceAliases;
|
// Put namespace names and aliases into a hashtable.
|
||||||
// # Put namespace names and aliases into a hashtable.
|
// If this is too slow, then we should arrange it so that it is done
|
||||||
// # If this is too slow, then we should arrange it so that it is done
|
// before caching. The catch is that at pre-cache time, the above
|
||||||
// # before caching. The catch is that at pre-cache time, the above
|
// class-specific fixup hasn't been done.
|
||||||
// # class-specific fixup hasn't been done.
|
this.mNamespaceIds = new XomwNamespacesByName();
|
||||||
// this.mNamespaceIds = [];
|
XomwNamespacesById getNamespacesHash = this.getNamespaces();
|
||||||
// foreach (this.getNamespaces() as $index => $name) {
|
int len = getNamespacesHash.Len();
|
||||||
// this.mNamespaceIds[this.lc($name)] = $index;
|
for (int i = 0; i < len; i++) {
|
||||||
// }
|
XomwNamespaceItem item = (XomwNamespaceItem)getNamespacesHash.GetAtOrNull(i);
|
||||||
// foreach (this.getNamespaceAliases() as $name => $index) {
|
this.mNamespaceIds.Add(this.lc(item.name), item);
|
||||||
// this.mNamespaceIds[this.lc($name)] = $index;
|
}
|
||||||
// }
|
XomwNamespacesByName getNamespaceAliasesHash = this.getNamespaceAliases();
|
||||||
// if ($wgNamespaceAliases) {
|
len = getNamespaceAliasesHash.Len();
|
||||||
// foreach ($wgNamespaceAliases as $name => $index) {
|
for (int i = 0; i < len; i++) {
|
||||||
// this.mNamespaceIds[this.lc($name)] = $index;
|
XomwNamespaceItem item = (XomwNamespaceItem)getNamespaceAliasesHash.GetAtOrNull(i);
|
||||||
// }
|
this.mNamespaceIds.Add(this.lc(item.name), item);
|
||||||
// }
|
}
|
||||||
// }
|
XomwNamespacesByName wgNamespaceAliases = XomwSetup.wgNamespaceAliases;
|
||||||
// return this.mNamespaceIds;
|
len = wgNamespaceAliases.Len();
|
||||||
// }
|
for (int i = 0; i < len; i++) {
|
||||||
|
XomwNamespaceItem item = (XomwNamespaceItem)wgNamespaceAliases.GetAtOrNull(i);
|
||||||
|
this.mNamespaceIds.Add(this.lc(item.name), item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.mNamespaceIds;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a namespace key by value, case insensitive. Canonical namespace
|
* Get a namespace key by value, case insensitive. Canonical namespace
|
||||||
@ -724,9 +732,8 @@ public class XomwLanguage {
|
|||||||
if (ns != XomwNamespace.NULL_NS_ID) {
|
if (ns != XomwNamespace.NULL_NS_ID) {
|
||||||
return ns;
|
return ns;
|
||||||
}
|
}
|
||||||
// $ids = this.getNamespaceIds();
|
XomwNamespacesByName ids = this.getNamespaceIds();
|
||||||
// return isset($ids[$lctext]) ? $ids[$lctext] : false;
|
return ids.GetAsIdOrNullInt(lctext);
|
||||||
return XophpUtility.Null_int;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
|
Loading…
Reference in New Issue
Block a user