1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

Xomw: Add XomwMessage class and related

This commit is contained in:
gnosygnu
2017-02-27 08:36:18 -05:00
parent 2416ccb7e9
commit 1f10e61371
24 changed files with 3077 additions and 17 deletions

View File

@@ -0,0 +1,179 @@
/*
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.interwiki; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
/**
* Value Object for representing interwiki records.
*/
public class XomwInterwiki {
/** @var String The interwiki prefix, (e.g. "Meatball", or the language prefix "de") */
private byte[] mPrefix;
/** @var String The URL of the wiki, with "1" as a placeholder for an article name. */
private byte[] mURL;
/** @var String The URL of the file api.php */
private byte[] mAPI;
/** @var String The name of the database (for a connection to be established
* with wfGetLB('wikiid'))
*/
private byte[] mWikiID;
/** @var boolean Whether the wiki is in this project */
private boolean mLocal;
/** @var boolean Whether interwiki transclusions are allowed */
private boolean mTrans;
public XomwInterwiki(byte[] prefix, byte[] url, byte[] api, byte[] wikiId, boolean local, boolean trans) {
this.mPrefix = prefix;
this.mURL = url;
this.mAPI = api;
this.mWikiID = wikiId;
this.mLocal = local;
this.mTrans = trans;
}
// /**
// * Check whether an interwiki prefix exists
// *
// * @deprecated since 1.28, use InterwikiLookup instead
// *
// * @param String prefix Interwiki prefix to use
// * @return boolean Whether it exists
// */
// public static function isValidInterwiki(prefix) {
// return MediaWikiServices::getInstance().getInterwikiLookup().isValidInterwiki(prefix);
// }
//
// /**
// * Fetch an Interwiki Object
// *
// * @deprecated since 1.28, use InterwikiLookup instead
// *
// * @param String prefix Interwiki prefix to use
// * @return Interwiki|null|boolean
// */
// public static function fetch(prefix) {
// return MediaWikiServices::getInstance().getInterwikiLookup().fetch(prefix);
// }
//
// /**
// * Purge the cache (local and persistent) for an interwiki prefix.
// *
// * @param String prefix
// * @since 1.26
// */
// public static function invalidateCache(prefix) {
// return MediaWikiServices::getInstance().getInterwikiLookup().invalidateCache(prefix);
// }
//
// /**
// * Returns all interwiki prefixes
// *
// * @deprecated since 1.28, unused. Use InterwikiLookup instead.
// *
// * @param String|null local If set, limits output to local/non-local interwikis
// * @return array List of prefixes
// * @since 1.19
// */
// public static function getAllPrefixes(local = null) {
// return MediaWikiServices::getInstance().getInterwikiLookup().getAllPrefixes(local);
// }
/**
* Get the URL for a particular title (or with 1 if no title given)
*
* @param String title What text to put for the article name
* @return String The URL
* @note Prior to 1.19 The getURL with an argument was broken.
* If you if you use this arg in an extension that supports MW earlier
* than 1.19 please wfUrlencode and substitute 1 on your own.
*/
// title=null
public byte[] getURL(byte[] title) {
byte[] url = this.mURL;
if (title != null) {
url = XophpString.str_replace(ARG_1, XomwGlobalFunctions.wfUrlencode(title), url);
}
return url;
}
/**
* Get the API URL for this wiki
*
* @return String The URL
*/
public byte[] getAPI() {
return this.mAPI;
}
/**
* Get the DB name for this wiki
*
* @return String The DB name
*/
public byte[] getWikiID() {
return this.mWikiID;
}
/**
* Is this a local link from a sister project, or is
* it something outside, like Google
*
* @return boolean
*/
public boolean isLocal() {
return this.mLocal;
}
/**
* Can pages from this wiki be transcluded?
* Still requires wgEnableScaryTransclusion
*
* @return boolean
*/
public boolean isTranscludable() {
return this.mTrans;
}
/**
* Get the name for the interwiki site
*
* @return String
*/
public byte[] getName(XomwEnv env) {
// XomwMessage msg = XomwGlobalFunctions.wfMessage(env, "interwiki-name-" + this.mPrefix).inContentLanguage();
//
// return !msg.exists() ? Bry_.Empty : msg.text();
Tfds.Write(mPrefix);
return null;
}
// /**
// * Get a description for this interwiki
// *
// * @return String
// */
// public function getDescription() {
// msg = wfMessage('interwiki-desc-' . this.mPrefix).inContentLanguage();
//
// return !msg.exists() ? '' : msg.text();
// }
private static final byte[] ARG_1 = Bry_.new_a7("$1");
}

View File

@@ -0,0 +1,52 @@
/*
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.interwiki; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
/**
* Service interface for looking up Interwiki records.
*
* @since 1.28
*/
public interface XomwInterwikiLookup {
/**
* Check whether an interwiki prefix exists
*
* @param String $prefix Interwiki prefix to use
* @return boolean Whether it exists
*/
boolean isValidInterwiki(byte[] prefix);
/**
* Fetch an Interwiki Object
*
* @param String $prefix Interwiki prefix to use
* @return Interwiki|null|boolean
*/
XomwInterwiki fetch(byte[] prefix);
/**
* Returns all interwiki prefixes
*
* @param String|null $local If set, limits output to local/non-local interwikis
* @return String[] List of prefixes
*/
byte[][] getAllPrefixes(byte[] local);
/**
* Purge the in-process and persistent Object cache for an interwiki prefix
* @param String $prefix
*/
void invalidateCache(byte[] prefix);
}

View File

@@ -0,0 +1,156 @@
/*
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.interwiki; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
class XomwInterwikiLookupAdapter {
// /**
// * @var SiteLookup
// */
// private $siteLookup;
//
// /**
// * @var Interwiki[]|null associative array mapping interwiki prefixes to Interwiki objects
// */
// private $interwikiMap;
//
// function __construct(
// SiteLookup $siteLookup,
// array $interwikiMap = null
// ) {
// $this->siteLookup = $siteLookup;
// $this->interwikiMap = $interwikiMap;
// }
//
// /**
// * See InterwikiLookup::isValidInterwiki
// * It loads the whole interwiki map.
// *
// * @param String $prefix Interwiki prefix to use
// * @return boolean Whether it exists
// */
// public function isValidInterwiki( $prefix ) {
//
// return array_key_exists( $prefix, $this->getInterwikiMap() );
// }
//
// /**
// * See InterwikiLookup::fetch
// * It loads the whole interwiki map.
// *
// * @param String $prefix Interwiki prefix to use
// * @return Interwiki|null|boolean
// */
// public function fetch( $prefix ) {
// if ( $prefix == '' ) {
// return null;
// }
//
// if ( !$this->isValidInterwiki( $prefix ) ) {
// return false;
// }
//
// return $this->interwikiMap[$prefix];
// }
//
// /**
// * See InterwikiLookup::getAllPrefixes
// *
// * @param String|null $local If set, limits output to local/non-local interwikis
// * @return String[] List of prefixes
// */
// public function getAllPrefixes( $local = null ) {
// if ( $local === null ) {
// return array_keys( $this->getInterwikiMap() );
// }
// $res = [];
// foreach ( $this->getInterwikiMap() as $interwikiId => $interwiki ) {
// if ( $interwiki->isLocal() === $local ) {
// $res[] = $interwikiId;
// }
// }
// return $res;
// }
//
// /**
// * See InterwikiLookup::invalidateCache
// *
// * @param String $prefix
// */
// public function invalidateCache( $prefix ) {
// if ( !isset( $this->interwikiMap[$prefix] ) ) {
// return;
// }
// $globalId = $this->interwikiMap[$prefix]->getWikiID();
// unset( $this->interwikiMap[$prefix] );
//
// // Reload the interwiki
// $site = $this->siteLookup->getSites()->getSite( $globalId );
// $interwikis = $this->getSiteInterwikis( $site );
// $this->interwikiMap = array_merge( $this->interwikiMap, [ $interwikis[$prefix] ] );
// }
//
// /**
// * Load interwiki map to use as cache
// */
// private function loadInterwikiMap() {
// $interwikiMap = [];
// $siteList = $this->siteLookup->getSites();
// foreach ( $siteList as $site ) {
// $interwikis = $this->getSiteInterwikis( $site );
// $interwikiMap = array_merge( $interwikiMap, $interwikis );
// }
// $this->interwikiMap = $interwikiMap;
// }
//
// /**
// * Get interwikiMap attribute, load if needed.
// *
// * @return Interwiki[]
// */
// private function getInterwikiMap() {
// if ( $this->interwikiMap === null ) {
// $this->loadInterwikiMap();
// }
// return $this->interwikiMap;
// }
//
// /**
// * Load interwikis for the given site
// *
// * @param Site $site
// * @return Interwiki[]
// */
// private function getSiteInterwikis( Site $site ) {
// $interwikis = [];
// foreach ( $site->getInterwikiIds() as $interwiki ) {
// $url = $site->getPageUrl();
// if ( $site instanceof MediaWikiSite ) {
// $path = $site->getFileUrl( 'api.php' );
// } else {
// $path = '';
// }
// $local = $site->getSource() === 'local';
// // TODO: How to adapt trans?
// $interwikis[$interwiki] = new Interwiki(
// $interwiki,
// $url,
// $path,
// $site->getGlobalId(),
// $local
// );
// }
// return $interwikis;
// }
}