mirror of https://github.com/gnosygnu/xowa
Wikibase: Do not fail for FormatStatements and getPropertyOrder [#658]
parent
bc2beba148
commit
775bff3bac
@ -0,0 +1,19 @@
|
||||
/*
|
||||
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; import gplx.*; import gplx.xowa.*;
|
||||
public interface XophpCallbackOwner {
|
||||
Object Callback(String method, Object... args);
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
/*
|
||||
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; import gplx.*; import gplx.xowa.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.langs.regxs.*;
|
||||
public class XophpRegex_match_all_tst {
|
||||
private final XophpRegex_match_all_fxt fxt = new XophpRegex_match_all_fxt();
|
||||
@Test public void Pattern_order() {
|
||||
fxt.Test__preg_match_all
|
||||
( XophpRegex_.Pattern("<[^>]+>(.*)</[^>]+>", XophpRegex_.MODIFIER_U)
|
||||
, "<b>example: </b><div align=left>this is a test</div>"
|
||||
, XophpRegex_.PREG_PATTERN_ORDER
|
||||
, fxt.Expd()
|
||||
.Add_many(XophpArray.New("<b>example: </b>", "<div align=left>this is a test</div>"))
|
||||
.Add_many(XophpArray.New("example: ", "this is a test"))
|
||||
);
|
||||
}
|
||||
// @Test public void Pattern_order_matches() {
|
||||
// // PCRE does not allow duplicate named groups by default. PCRE 6.7 and later allow them if you turn on that option or use the mode modifier (?J).
|
||||
// fxt.Test__preg_match_all
|
||||
// ( XophpRegex_.Pattern("(?<match>foo)|(?<match>bar)", XophpRegex_.MODIFIER_U | XophpRegex_.MODIFIER_J) // (?J) changed to MODIFIER_J
|
||||
// , "foo bar"
|
||||
// , XophpRegex_.PREG_PATTERN_ORDER
|
||||
// , fxt.Expd()
|
||||
// .Add(0, "<b>example: </b>").Add(0, "<div align=left>this is a test</div>")
|
||||
// .Add(1, "example: ").Add(1, "this is a test")
|
||||
// );
|
||||
// }
|
||||
@Test public void Set_order() {
|
||||
fxt.Test__preg_match_all
|
||||
( XophpRegex_.Pattern("<[^>]+>(.*)</[^>]+>", XophpRegex_.MODIFIER_U)
|
||||
, "<b>example: </b><div align=left>this is a test</div>"
|
||||
, XophpRegex_.PREG_SET_ORDER
|
||||
, fxt.Expd()
|
||||
.Add_many(XophpArray.New("<b>example: </b>", "example: "))
|
||||
.Add_many(XophpArray.New("<div align=left>this is a test</div>", "this is a test"))
|
||||
);
|
||||
}
|
||||
@Test public void Offset_capture() {
|
||||
fxt.Test__preg_match_all
|
||||
( XophpRegex_.Pattern("(foo)(bar)(baz)", XophpRegex_.MODIFIER_U)
|
||||
, "foobarbaz"
|
||||
, XophpRegex_.PREG_OFFSET_CAPTURE
|
||||
, fxt.Expd()
|
||||
.Add_many
|
||||
( XophpArray.New("foobarbaz", "0")
|
||||
, XophpArray.New("foo", "0")
|
||||
, XophpArray.New("bar", "3")
|
||||
, XophpArray.New("baz", "6")
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
class XophpRegex_match_all_fxt {
|
||||
public XophpRegex_match_all_expd Expd() {return new XophpRegex_match_all_expd();}
|
||||
public void Test__preg_match_all(Regx_adp pattern, String subject, XophpRegex_match_all_expd rslt) {Test__preg_match_all(pattern, subject, XophpRegex_.PREG_NO_FLAG, 0, rslt);}
|
||||
public void Test__preg_match_all(Regx_adp pattern, String subject, int flags, XophpRegex_match_all_expd rslt) {Test__preg_match_all(pattern, subject, flags, 0, rslt);}
|
||||
public void Test__preg_match_all(Regx_adp pattern, String subject, int flags, int offset, XophpRegex_match_all_expd expd) {
|
||||
XophpArray actl = XophpArray.New();
|
||||
XophpRegex_.preg_match_all(pattern, subject, actl, flags, offset);
|
||||
|
||||
Gftest.Eq__ary__lines(expd.Ary().To_str(), actl.To_str());
|
||||
}
|
||||
}
|
||||
class XophpRegex_match_all_expd {
|
||||
public XophpArray Ary() {return ary;} private final XophpArray ary = XophpArray.New();
|
||||
public XophpRegex_match_all_expd Add(int idx, Object val) {
|
||||
XophpArray sub = ary.Get_at_ary(idx);
|
||||
if (sub == null) {
|
||||
sub = XophpArray.New();
|
||||
ary.Set(idx, sub);
|
||||
}
|
||||
sub.Add(val);
|
||||
return this;
|
||||
}
|
||||
public XophpRegex_match_all_expd Add_many(Object... vals) {
|
||||
for (Object val : vals)
|
||||
ary.Add(val);
|
||||
return this;
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
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; import gplx.*; import gplx.xowa.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.langs.regxs.*;
|
||||
public class XophpRegex_replace_tst {
|
||||
private final XophpRegex_replace_fxt fxt = new XophpRegex_replace_fxt();
|
||||
@Test public void Basic() {
|
||||
// basic
|
||||
fxt.Test__preg_replace("0", "1", "0ab0cd0ef", fxt.Expd("1ab1cd1ef").Count_(3));
|
||||
|
||||
// limit
|
||||
fxt.Test__preg_replace("0", "1", "0ab0cd0ef", 2, fxt.Expd("1ab1cd0ef").Count_(2));
|
||||
}
|
||||
}
|
||||
class XophpRegex_replace_fxt {
|
||||
public XophpRegex_replace_expd Expd(String rslt) {return new XophpRegex_replace_expd(rslt);}
|
||||
public void Test__preg_replace(String pattern, String replacement, String subject, XophpRegex_replace_expd rslt) {Test__preg_replace(pattern, replacement, subject, XophpRegex_.preg_replace_limit_none, rslt);}
|
||||
public void Test__preg_replace(String pattern, String replacement, String subject, int limit, XophpRegex_replace_expd expd) {
|
||||
Int_obj_ref actl_count = Int_obj_ref.New_zero();
|
||||
String actl = XophpRegex_.preg_replace(Regx_adp_.new_(pattern), replacement, subject, limit, actl_count);
|
||||
|
||||
Gftest.Eq__str(expd.Rslt(), actl);
|
||||
if (expd.Count() != -1)
|
||||
Gftest.Eq__int(expd.Count(), actl_count.Val());
|
||||
}
|
||||
}
|
||||
class XophpRegex_replace_expd {
|
||||
public XophpRegex_replace_expd(String rslt) {
|
||||
this.rslt = rslt;
|
||||
}
|
||||
public String Rslt() {return rslt;} private final String rslt;
|
||||
public int Count() {return count;} private int count = -1;
|
||||
public XophpRegex_replace_expd Count_(int v) {count = v; return this;}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
/*
|
||||
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; import gplx.*; import gplx.xowa.*;
|
||||
public class XophpRuntimeException extends XophpError { public XophpRuntimeException(String msg) {super(msg);
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
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.extensions.Wikibase.client.includes; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.extensions.*; import gplx.xowa.mediawiki.extensions.Wikibase.*; import gplx.xowa.mediawiki.extensions.Wikibase.client.*;
|
||||
import gplx.xowa.mediawiki.*;
|
||||
public class Wbase_client {
|
||||
private Wbase_repo_linker repoLinker;
|
||||
public Wbase_client(Wbase_settings settings) {
|
||||
this.repoLinker = new Wbase_repo_linker
|
||||
( settings.getSetting(Wbase_settings.Setting_repoUrl)
|
||||
, settings.getSetting(Wbase_settings.Setting_repoArticlePath)
|
||||
, settings.getSetting(Wbase_settings.Setting_repoScriptPath)
|
||||
);
|
||||
}
|
||||
public Wbase_repo_linker RepoLinker() {return repoLinker;}
|
||||
|
||||
private static Wbase_client defaultInstance;
|
||||
public static Wbase_client getDefaultInstance() {
|
||||
if (defaultInstance == null) {
|
||||
defaultInstance = new Wbase_client(Wbase_settings.New_dflt());
|
||||
}
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,20 @@
|
||||
/*
|
||||
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.extensions.Wikibase.lib.includes.Store; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.extensions.*; import gplx.xowa.mediawiki.extensions.Wikibase.*; import gplx.xowa.mediawiki.extensions.Wikibase.lib.*; import gplx.xowa.mediawiki.extensions.Wikibase.lib.includes.*;
|
||||
// REF.WBASE:2020-01-19
|
||||
class XomwPropertyOrderProviderException extends XophpRuntimeException { public XomwPropertyOrderProviderException(String msg) {super(msg);
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
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.extensions.Wikibase.lib.includes.Store; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.extensions.*; import gplx.xowa.mediawiki.extensions.Wikibase.*; import gplx.xowa.mediawiki.extensions.Wikibase.lib.*; import gplx.xowa.mediawiki.extensions.Wikibase.lib.includes.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
import gplx.xowa.mediawiki.includes.xohtml.*;
|
||||
public class XomwWikiTextPropertyOrderProvider_tst {
|
||||
private final XomwWikiTextPropertyOrderProvider_fxt fxt = new XomwWikiTextPropertyOrderProvider_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test__getPropertyOrder(String_.Concat_lines_nl
|
||||
( "* [[Property:P1]]"
|
||||
, "* [[Property:P2]]"
|
||||
), XophpArray.New()
|
||||
.Add("P1", "0")
|
||||
.Add("P2", "1")
|
||||
);
|
||||
}
|
||||
@Test public void Comments() {
|
||||
fxt.Test__getPropertyOrder(String_.Concat_lines_nl
|
||||
( "<!--* [[Property:P0]]-->"
|
||||
, "* [[Property:P1]]"
|
||||
, "* [[Property:P2]]"
|
||||
), XophpArray.New()
|
||||
.Add("P1", "0")
|
||||
.Add("P2", "1")
|
||||
);
|
||||
}
|
||||
@Test public void Invalid_properties() {
|
||||
fxt.Test__getPropertyOrder(String_.Concat_lines_nl
|
||||
( "* [[Property:P0a]]"
|
||||
, "* [[Property:P1]]"
|
||||
, "* [[Property:P2]]"
|
||||
), XophpArray.New()
|
||||
.Add("P1", "0")
|
||||
.Add("P2", "1")
|
||||
);
|
||||
}
|
||||
}
|
||||
class XomwWikiTextPropertyOrderProvider_fxt {
|
||||
public void Test__getPropertyOrder(String page, XophpArray expd) {
|
||||
MockXomwWikiTextPropertyOrderProvider provider = new MockXomwWikiTextPropertyOrderProvider(page);
|
||||
XophpArray actl = provider.getPropertyOrder();
|
||||
Gftest.Eq__str(expd.To_str(), actl.To_str());
|
||||
}
|
||||
}
|
||||
class MockXomwWikiTextPropertyOrderProvider extends XomwWikiTextPropertyOrderProvider { private final String text;
|
||||
public MockXomwWikiTextPropertyOrderProvider(String text) {this.text = text;}
|
||||
@Override protected String getPropertyOrderWikitext() {
|
||||
return text;
|
||||
}
|
||||
}
|
@ -0,0 +1,190 @@
|
||||
/*
|
||||
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.*;
|
||||
/**
|
||||
* Hooks cl+ass.
|
||||
*
|
||||
* Used to supersede $wgHooks, because globals are EVIL.
|
||||
*
|
||||
* @since 1.18
|
||||
*/
|
||||
public class XomwHooks {
|
||||
// /**
|
||||
// * Array of events mapped to an array of callbacks to be run
|
||||
// * when that event is triggered.
|
||||
// */
|
||||
// protected static $handlers = [];
|
||||
//
|
||||
// /**
|
||||
// * Attach an event handler to a given hook.
|
||||
// *
|
||||
// * @param String $name Name of hook
|
||||
// * @param callable $callback Callback function to attach
|
||||
// *
|
||||
// * @since 1.18
|
||||
// */
|
||||
// public static function register( $name, $callback ) {
|
||||
// if ( !isset( self::$handlers[$name] ) ) {
|
||||
// self::$handlers[$name] = [];
|
||||
// }
|
||||
//
|
||||
// self::$handlers[$name][] = $callback;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Clears hooks registered via Hooks::register(). Does not touch $wgHooks.
|
||||
// * This is intended for use while testing and will fail if MW_PHPUNIT_TEST is not defined.
|
||||
// *
|
||||
// * @param String $name The name of the hook to clear.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// * @throws MWException If not in testing mode.
|
||||
// */
|
||||
// public static function clear( $name ) {
|
||||
// if ( !defined( 'MW_PHPUNIT_TEST' ) && !defined( 'MW_PARSER_TEST' ) ) {
|
||||
// throw new MWException( 'Cannot reset hooks in operation.' );
|
||||
// }
|
||||
//
|
||||
// unset( self::$handlers[$name] );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns true if a hook has a function registered to it.
|
||||
// * The function may have been registered either via Hooks::register or in $wgHooks.
|
||||
// *
|
||||
// * @since 1.18
|
||||
// *
|
||||
// * @param String $name Name of hook
|
||||
// * @return boolean True if the hook has a function registered to it
|
||||
// */
|
||||
// public static function isRegistered( $name ) {
|
||||
// global $wgHooks;
|
||||
// return !empty( $wgHooks[$name] ) || !empty( self::$handlers[$name] );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns an array of all the event functions attached to a hook
|
||||
// * This combines functions registered via Hooks::register and with $wgHooks.
|
||||
// *
|
||||
// * @since 1.18
|
||||
// *
|
||||
// * @param String $name Name of the hook
|
||||
// * @return array
|
||||
// */
|
||||
// public static function getHandlers( $name ) {
|
||||
// global $wgHooks;
|
||||
//
|
||||
// if ( !self::isRegistered( $name ) ) {
|
||||
// return [];
|
||||
// } elseif ( !isset( self::$handlers[$name] ) ) {
|
||||
// return $wgHooks[$name];
|
||||
// } elseif ( !isset( $wgHooks[$name] ) ) {
|
||||
// return self::$handlers[$name];
|
||||
// } else {
|
||||
// return array_merge( self::$handlers[$name], $wgHooks[$name] );
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Call hook functions defined in Hooks::register and $wgHooks.
|
||||
// *
|
||||
// * For a certain hook event, fetch the array of hook events and
|
||||
// * process them. Determine the proper callback for each hook and
|
||||
// * then call the actual hook using the appropriate arguments.
|
||||
// * Finally, process the return value and return/throw accordingly.
|
||||
// *
|
||||
// * @param String $event Event name
|
||||
// * @param array $args Array of parameters passed to hook functions
|
||||
// * @param String|null $deprecatedVersion Optionally, mark hook as deprecated with version number
|
||||
// * @return boolean True if no handler aborted the hook
|
||||
// *
|
||||
// * @throws Exception
|
||||
// * @throws FatalError
|
||||
// * @throws MWException
|
||||
// * @since 1.22 A hook function is not required to return a value for
|
||||
// * processing to continue. Not returning a value (or explicitly
|
||||
// * returning null) is equivalent to returning true.
|
||||
// */
|
||||
// public static function run( $event, array $args = [], $deprecatedVersion = null ) {
|
||||
// foreach ( self::getHandlers( $event ) as $hook ) {
|
||||
// // Turn non-array values into an array. (Can't use casting because of objects.)
|
||||
// if ( !is_array( $hook ) ) {
|
||||
// $hook = [ $hook ];
|
||||
// }
|
||||
//
|
||||
// if ( !array_filter( $hook ) ) {
|
||||
// // Either array is empty or it's an array filled with null/false/empty.
|
||||
// continue;
|
||||
// } elseif ( is_array( $hook[0] ) ) {
|
||||
// // First element is an array, meaning the developer intended
|
||||
// // the first element to be a callback. Merge it in so that
|
||||
// // processing can be uniform.
|
||||
// $hook = array_merge( $hook[0], array_slice( $hook, 1 ) );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * $hook can be: a function, an Object, an array of $function and
|
||||
// * $data, an array of just a function, an array of Object and
|
||||
// * method, or an array of Object, method, and data.
|
||||
// */
|
||||
// if ( $hook[0] instanceof Closure ) {
|
||||
// $func = "hook-$event-closure";
|
||||
// $callback = array_shift( $hook );
|
||||
// } elseif ( is_object( $hook[0] ) ) {
|
||||
// $Object = array_shift( $hook );
|
||||
// $method = array_shift( $hook );
|
||||
//
|
||||
// // If no method was specified, default to on$event.
|
||||
// if ( $method === null ) {
|
||||
// $method = "on$event";
|
||||
// }
|
||||
//
|
||||
// $func = get_class( $Object ) . '::' . $method;
|
||||
// $callback = [ $Object, $method ];
|
||||
// } elseif ( is_string( $hook[0] ) ) {
|
||||
// $func = $callback = array_shift( $hook );
|
||||
// } else {
|
||||
// throw new MWException( 'Unknown datatype in hooks for ' . $event . "\n" );
|
||||
// }
|
||||
//
|
||||
// // Run autoloader (workaround for call_user_func_array bug)
|
||||
// // and throw error if not callable.
|
||||
// if ( !is_callable( $callback ) ) {
|
||||
// throw new MWException( 'Invalid callback ' . $func . ' in hooks for ' . $event . "\n" );
|
||||
// }
|
||||
//
|
||||
// // mark hook as deprecated, if deprecation version is specified
|
||||
// if ( $deprecatedVersion !== null ) {
|
||||
// wfDeprecated( "$event hook (used in $func)", $deprecatedVersion );
|
||||
// }
|
||||
//
|
||||
// // Call the hook.
|
||||
// $hook_args = array_merge( $hook, $args );
|
||||
// $retval = call_user_func_array( $callback, $hook_args );
|
||||
//
|
||||
// // Process the return value.
|
||||
// if ( is_string( $retval ) ) {
|
||||
// // String returned means error.
|
||||
// throw new FatalError( $retval );
|
||||
// } elseif ( $retval === false ) {
|
||||
// // False was returned. Stop processing, but no error.
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,49 @@
|
||||
/*
|
||||
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.dao; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
/**
|
||||
* Interface for database access objects.
|
||||
*
|
||||
* Classes using this support a set of constants in a bitfield argument to their data loading
|
||||
* functions. In general, objects should assume READ_NORMAL if no flags are explicitly given,
|
||||
* though certain objects may assume READ_LATEST for common use case or legacy reasons.
|
||||
*
|
||||
* There are four types of reads:
|
||||
* - READ_NORMAL : Potentially cached read of data (e.g. from a replica DB or stale replica)
|
||||
* - READ_LATEST : Up-to-date read as of transaction start (e.g. from master or a quorum read)
|
||||
* - READ_LOCKING : Up-to-date read as of now, that locks (shared) the records
|
||||
* - READ_EXCLUSIVE : Up-to-date read as of now, that locks (exclusive) the records
|
||||
* All record locks persist for the duration of the transaction.
|
||||
*
|
||||
* A special constant READ_LATEST_IMMUTABLE can be used for fetching append-only data. Such
|
||||
* data is either (a) on a replica DB and up-to-date or (b) not yet there, but on the master/quorum.
|
||||
* Because the data is append-only, it can never be stale on a replica DB if present.
|
||||
*
|
||||
* Callers should use READ_NORMAL (or pass in no flags) unless the read determines a write.
|
||||
* In theory, such cases may require READ_LOCKING, though to avoid contention, READ_LATEST is
|
||||
* often good enough. If UPDATE race condition checks are required on a row and expensive code
|
||||
* must run after the row is fetched to determine the UPDATE, it may help to do something like:
|
||||
* - a) Start transaction
|
||||
* - b) Read the current row with READ_LATEST
|
||||
* - c) Determine the new row (expensive, so we don't want to hold locks now)
|
||||
* - d) Re-read the current row with READ_LOCKING; if it changed then bail out
|
||||
* - e) otherwise, do the updates
|
||||
* - f) Commit transaction
|
||||
*
|
||||
* @since 1.20
|
||||
*/
|
||||
public interface XomwIDBAccessObject {
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
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.dao; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
public class XomwIDBAccessObject_ {
|
||||
/** Constants for Object loading bitfield flags (higher => higher QoS) */
|
||||
/** @var int Read from a replica DB/non-quorum */
|
||||
public static final int READ_NORMAL = 0;
|
||||
|
||||
/** @var int Read from the master/quorum */
|
||||
public static final int READ_LATEST = 1;
|
||||
|
||||
/* @var int Read from the master/quorum and synchronized out other writers */
|
||||
public static final int READ_LOCKING = READ_LATEST | 2; // READ_LATEST (1) and "LOCK IN SHARE MODE" (2)
|
||||
|
||||
/** @var int Read from the master/quorum and synchronized out other writers and locking readers */
|
||||
public static final int READ_EXCLUSIVE = READ_LOCKING | 4; // READ_LOCKING (3) and "FOR UPDATE" (4)
|
||||
|
||||
/** @var int Read from a replica DB or without a quorum, using the master/quorum on miss */
|
||||
public static final int READ_LATEST_IMMUTABLE = 8;
|
||||
|
||||
// Convenience constant for tracking how data was loaded (higher => higher QoS)
|
||||
public static final int READ_NONE = -1; // not loaded yet (or the Object was cleared)
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
/*
|
||||
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.page; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
// MW.SRC:1.33.1
|
||||
/**
|
||||
* Interface for type hinting (accepts WikiPage, Article, ImagePage, CategoryPage)
|
||||
*/
|
||||
public interface XomwPage {
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
/*
|
||||
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.page; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
// MW.SRC:1.33.1
|
||||
/**
|
||||
* Special handling for category pages
|
||||
*/
|
||||
public class XomwWikiCategoryPage extends XomwWikiPage { public XomwWikiCategoryPage(XomwTitle title) {super(title);
|
||||
}
|
||||
//
|
||||
// /**
|
||||
// * Don't return a 404 for categories in use.
|
||||
// * In use defined as: either the actual page exists
|
||||
// * or the category currently has members.
|
||||
// *
|
||||
// * @return boolean
|
||||
// */
|
||||
// public function hasViewableContent() {
|
||||
// if ( parent::hasViewableContent() ) {
|
||||
// return true;
|
||||
// } else {
|
||||
// $cat = Category::newFromTitle( $this->mTitle );
|
||||
// // If any of these are not 0, then has members
|
||||
// if ( $cat->getPageCount()
|
||||
// || $cat->getSubcatCount()
|
||||
// || $cat->getFileCount()
|
||||
// ) {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Checks if a category is hidden.
|
||||
// *
|
||||
// * @since 1.27
|
||||
// *
|
||||
// * @return boolean
|
||||
// */
|
||||
// public function isHidden() {
|
||||
// $pageId = $this->getTitle()->getArticleID();
|
||||
// $pageProps = PageProps::getInstance()->getProperties( $this->getTitle(), 'hiddencat' );
|
||||
//
|
||||
// return isset( $pageProps[$pageId] );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Checks if a category is expected to be an unused category.
|
||||
// *
|
||||
// * @since 1.33
|
||||
// *
|
||||
// * @return boolean
|
||||
// */
|
||||
// public function isExpectedUnusedCategory() {
|
||||
// $pageId = $this->getTitle()->getArticleID();
|
||||
// $pageProps = PageProps::getInstance()->getProperties( $this->getTitle(), 'expectunusedcategory' );
|
||||
//
|
||||
// return isset( $pageProps[$pageId] );
|
||||
// }
|
||||
}
|
@ -0,0 +1,250 @@
|
||||
/*
|
||||
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.page; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
// MW.SRC:1.33.1
|
||||
/**
|
||||
* Special handling for file pages
|
||||
*
|
||||
* @ingroup Media
|
||||
*/
|
||||
public class XomwWikiFilePage extends XomwWikiPage { // /** @var File */
|
||||
// protected $mFile = false;
|
||||
// /** @var LocalRepo */
|
||||
// protected $mRepo = null;
|
||||
// /** @var boolean */
|
||||
// protected $mFileLoaded = false;
|
||||
// /** @var array */
|
||||
// protected $mDupes = null;
|
||||
|
||||
public XomwWikiFilePage(XomwTitle title) {super(title);
|
||||
// $this->mDupes = null;
|
||||
// $this->mRepo = null;
|
||||
}
|
||||
//
|
||||
// /**
|
||||
// * @param File $file
|
||||
// */
|
||||
// public function setFile( $file ) {
|
||||
// $this->mFile = $file;
|
||||
// $this->mFileLoaded = true;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @return boolean
|
||||
// */
|
||||
// protected function loadFile() {
|
||||
// if ( $this->mFileLoaded ) {
|
||||
// return true;
|
||||
// }
|
||||
// $this->mFileLoaded = true;
|
||||
//
|
||||
// $this->mFile = wfFindFile( $this->mTitle );
|
||||
// if ( !$this->mFile ) {
|
||||
// $this->mFile = wfLocalFile( $this->mTitle ); // always a File
|
||||
// }
|
||||
// $this->mRepo = $this->mFile->getRepo();
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @return mixed|null|Title
|
||||
// */
|
||||
// public function getRedirectTarget() {
|
||||
// $this->loadFile();
|
||||
// if ( $this->mFile->isLocal() ) {
|
||||
// return parent::getRedirectTarget();
|
||||
// }
|
||||
// // Foreign image page
|
||||
// $from = $this->mFile->getRedirected();
|
||||
// $to = $this->mFile->getName();
|
||||
// if ( $from == $to ) {
|
||||
// return null;
|
||||
// }
|
||||
// $this->mRedirectTarget = Title::makeTitle( NS_FILE, $to );
|
||||
// return $this->mRedirectTarget;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @return boolean|mixed|Title
|
||||
// */
|
||||
// public function followRedirect() {
|
||||
// $this->loadFile();
|
||||
// if ( $this->mFile->isLocal() ) {
|
||||
// return parent::followRedirect();
|
||||
// }
|
||||
// $from = $this->mFile->getRedirected();
|
||||
// $to = $this->mFile->getName();
|
||||
// if ( $from == $to ) {
|
||||
// return false;
|
||||
// }
|
||||
// return Title::makeTitle( NS_FILE, $to );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @return boolean
|
||||
// */
|
||||
// public function isRedirect() {
|
||||
// $this->loadFile();
|
||||
// if ( $this->mFile->isLocal() ) {
|
||||
// return parent::isRedirect();
|
||||
// }
|
||||
//
|
||||
// return (boolean)$this->mFile->getRedirected();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @return boolean
|
||||
// */
|
||||
// public function isLocal() {
|
||||
// $this->loadFile();
|
||||
// return $this->mFile->isLocal();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @return boolean|File
|
||||
// */
|
||||
// public function getFile() {
|
||||
// $this->loadFile();
|
||||
// return $this->mFile;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @return array|null
|
||||
// */
|
||||
// public function getDuplicates() {
|
||||
// $this->loadFile();
|
||||
// if ( !is_null( $this->mDupes ) ) {
|
||||
// return $this->mDupes;
|
||||
// }
|
||||
// $hash = $this->mFile->getSha1();
|
||||
// if ( !( $hash ) ) {
|
||||
// $this->mDupes = [];
|
||||
// return $this->mDupes;
|
||||
// }
|
||||
// $dupes = RepoGroup::singleton()->findBySha1( $hash );
|
||||
// // Remove duplicates with self and non matching file sizes
|
||||
// $self = $this->mFile->getRepoName() . ':' . $this->mFile->getName();
|
||||
// $size = $this->mFile->getSize();
|
||||
//
|
||||
// /**
|
||||
// * @var $file File
|
||||
// */
|
||||
// foreach ( $dupes as $index => $file ) {
|
||||
// $key = $file->getRepoName() . ':' . $file->getName();
|
||||
// if ( $key == $self ) {
|
||||
// unset( $dupes[$index] );
|
||||
// }
|
||||
// if ( $file->getSize() != $size ) {
|
||||
// unset( $dupes[$index] );
|
||||
// }
|
||||
// }
|
||||
// $this->mDupes = $dupes;
|
||||
// return $this->mDupes;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Override handling of action=purge
|
||||
// * @return boolean
|
||||
// */
|
||||
// public function doPurge() {
|
||||
// $this->loadFile();
|
||||
//
|
||||
// if ( $this->mFile->exists() ) {
|
||||
// wfDebug( 'ImagePage::doPurge purging ' . $this->mFile->getName() . "\n" );
|
||||
// DeferredUpdates::addUpdate(
|
||||
// new HTMLCacheUpdate( $this->mTitle, 'imagelinks', 'file-purge' )
|
||||
// );
|
||||
// } else {
|
||||
// wfDebug( 'ImagePage::doPurge no image for '
|
||||
// . $this->mFile->getName() . "; limiting purge to cache only\n" );
|
||||
// }
|
||||
//
|
||||
// // even if the file supposedly doesn't exist, force any cached information
|
||||
// // to be updated (in case the cached information is wrong)
|
||||
//
|
||||
// // Purge current version and its thumbnails
|
||||
// $this->mFile->purgeCache( [ 'forThumbRefresh' => true ] );
|
||||
//
|
||||
// // Purge the old versions and their thumbnails
|
||||
// foreach ( $this->mFile->getHistory() as $oldFile ) {
|
||||
// $oldFile->purgeCache( [ 'forThumbRefresh' => true ] );
|
||||
// }
|
||||
//
|
||||
// if ( $this->mRepo ) {
|
||||
// // Purge redirect cache
|
||||
// $this->mRepo->invalidateImageRedirect( $this->mTitle );
|
||||
// }
|
||||
//
|
||||
// return parent::doPurge();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Get the categories this file is a member of on the wiki where it was uploaded.
|
||||
// * For local files, this is the same as getCategories().
|
||||
// * For foreign API files (InstantCommons), this is not supported currently.
|
||||
// * Results will include hidden categories.
|
||||
// *
|
||||
// * @return TitleArray|Title[]
|
||||
// * @since 1.23
|
||||
// */
|
||||
// public function getForeignCategories() {
|
||||
// $this->loadFile();
|
||||
// $title = $this->mTitle;
|
||||
// $file = $this->mFile;
|
||||
//
|
||||
// if ( !$file instanceof LocalFile ) {
|
||||
// wfDebug( __CLASS__ . '::' . __METHOD__ . " is not supported for this file\n" );
|
||||
// return TitleArray::newFromResult( new FakeResultWrapper( [] ) );
|
||||
// }
|
||||
//
|
||||
// /** @var LocalRepo $repo */
|
||||
// $repo = $file->getRepo();
|
||||
// $dbr = $repo->getReplicaDB();
|
||||
//
|
||||
// $res = $dbr->select(
|
||||
// [ 'page', 'categorylinks' ],
|
||||
// [
|
||||
// 'page_title' => 'cl_to',
|
||||
// 'page_namespace' => NS_CATEGORY,
|
||||
// ],
|
||||
// [
|
||||
// 'page_namespace' => $title->getNamespace(),
|
||||
// 'page_title' => $title->getDBkey(),
|
||||
// ],
|
||||
// __METHOD__,
|
||||
// [],
|
||||
// [ 'categorylinks' => [ 'JOIN', 'page_id = cl_from' ] ]
|
||||
// );
|
||||
//
|
||||
// return TitleArray::newFromResult( $res );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @since 1.28
|
||||
// * @return String
|
||||
// */
|
||||
// public function getWikiDisplayName() {
|
||||
// return $this->getFile()->getRepo()->getDisplayName();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @since 1.28
|
||||
// * @return String
|
||||
// */
|
||||
// public function getSourceURL() {
|
||||
// return $this->getFile()->getDescriptionUrl();
|
||||
// }
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue