mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Xomw: Start converting XomwLinkHolderArray
This commit is contained in:
parent
428f2837c9
commit
7fe4ed59ac
@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.core.lists.hashs; import gplx.*; import gplx.core.*; import gplx.core.lists.*;
|
||||
import gplx.core.primitives.*;
|
||||
public class Hash_adp__int {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
private final Hash_adp hash = Hash_adp_.New();
|
||||
private final Int_obj_ref tmp_key = Int_obj_ref.New_neg1();
|
||||
public void Clear() {hash.Clear();}
|
||||
public int Len() {return hash.Count();}
|
||||
|
65
gplx.xowa.mediawiki/src/gplx/core/lists/HashByInt.java
Normal file
65
gplx.xowa.mediawiki/src/gplx/core/lists/HashByInt.java
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.lists; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.primitives.*;
|
||||
public class HashByInt {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
private final Int_obj_ref tmp_key = Int_obj_ref.New_neg1();
|
||||
public void Clear() {
|
||||
hash.Clear();
|
||||
}
|
||||
public int Len() {
|
||||
return hash.Len();
|
||||
}
|
||||
public Object Get_by_or_fail(int key) {
|
||||
synchronized (tmp_key) {
|
||||
HashByIntItem item = (HashByIntItem)hash.Get_by_or_fail(tmp_key.Val_(key));
|
||||
return item.val;
|
||||
}
|
||||
}
|
||||
public Object Get_by_or_null(int key) {
|
||||
synchronized (tmp_key) {
|
||||
HashByIntItem item = (HashByIntItem)hash.Get_by(tmp_key.Val_(key));
|
||||
return item == null ? null : item.val;
|
||||
}
|
||||
}
|
||||
public HashByInt Add_as_bry(int key, String val) {return Add(key, Bry_.new_u8(val));}
|
||||
public HashByInt Add(int key, Object val) {
|
||||
HashByIntItem item = new HashByIntItem(key, val);
|
||||
hash.Add(Int_obj_ref.New(key), item);
|
||||
return this;
|
||||
}
|
||||
public HashByInt Clone() {
|
||||
HashByInt rv = new HashByInt();
|
||||
|
||||
int len = hash.Len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
HashByIntItem item = (HashByIntItem)hash.Get_at(i);
|
||||
rv.Add(item.key, item);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
class HashByIntItem {
|
||||
public final int key;
|
||||
public final Object val;
|
||||
public HashByIntItem(int key, Object val) {
|
||||
this.key = key;
|
||||
this.val = val;
|
||||
}
|
||||
}
|
@ -16,9 +16,8 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.mediawiki.includes; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*;
|
||||
import gplx.core.lists.hashs.*;
|
||||
import gplx.core.lists.*;
|
||||
public class XomwNamespace {
|
||||
//
|
||||
// /**
|
||||
// * These namespaces should always be first-letter capitalized, now and
|
||||
// * forevermore. Historically, they could've probably been lowercased too,
|
||||
@ -192,12 +191,12 @@ public class XomwNamespace {
|
||||
* @return array
|
||||
* @since 1.17
|
||||
*/
|
||||
private static Hash_adp__int namespaces = null;
|
||||
public static Hash_adp__int getCanonicalNamespaces() {return getCanonicalNamespaces(false);}
|
||||
public static Hash_adp__int getCanonicalNamespaces(boolean rebuild) {
|
||||
private static HashByInt namespaces = null;
|
||||
public static HashByInt getCanonicalNamespaces() {return getCanonicalNamespaces(false);}
|
||||
public static HashByInt getCanonicalNamespaces(boolean rebuild) {
|
||||
if (namespaces == null || rebuild) {
|
||||
// global $wgExtraNamespaces, $wgCanonicalNamespaceNames;
|
||||
namespaces = XomwSetup.wgCanonicalNamespaceNames;
|
||||
namespaces = XomwSetup.wgCanonicalNamespaceNames.Clone();
|
||||
namespaces.Add_as_bry(XomwDefines.NS_MAIN, "");
|
||||
|
||||
// // Add extension namespaces
|
||||
|
@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.mediawiki.includes; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*;
|
||||
import gplx.core.lists.hashs.*;
|
||||
import gplx.core.lists.*;
|
||||
/**
|
||||
* Include most things that are needed to make MediaWiki work.
|
||||
*
|
||||
@ -395,7 +395,7 @@ public class XomwSetup {
|
||||
* Definitions of the NS_ constants are in Defines.php
|
||||
* @private
|
||||
*/
|
||||
public static Hash_adp__int wgCanonicalNamespaceNames = new Hash_adp__int()
|
||||
public static HashByInt wgCanonicalNamespaceNames = new HashByInt()
|
||||
.Add_as_bry(XomwDefines.NS_MEDIA , "Media")
|
||||
.Add_as_bry(XomwDefines.NS_SPECIAL , "Special")
|
||||
.Add_as_bry(XomwDefines.NS_TALK , "Talk")
|
||||
|
@ -204,7 +204,7 @@ public class XomwTitle {
|
||||
// try {
|
||||
// t.secureAndSplit();
|
||||
// return t;
|
||||
// } catch (MalformedTitleException $ex) {
|
||||
// } catch (XomwMalformedTitleException $ex) {
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
@ -266,14 +266,14 @@ public class XomwTitle {
|
||||
|
||||
try {
|
||||
return XomwTitle.newFromTextThrow(text, defaultNamespace);
|
||||
} catch (MalformedTitleException ex) {
|
||||
} catch (XomwMalformedTitleException ex) {
|
||||
Err_.Noop(ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Like Title::newFromText(), but throws MalformedTitleException when the title is invalid,
|
||||
* Like Title::newFromText(), but throws XomwMalformedTitleException when the title is invalid,
|
||||
* rather than returning null.
|
||||
*
|
||||
* The exception subclasses encode detailed information about why the title is invalid.
|
||||
@ -283,7 +283,7 @@ public class XomwTitle {
|
||||
* @since 1.25
|
||||
* @param String $text Title text to check
|
||||
* @param int $defaultNamespace
|
||||
* @throws MalformedTitleException If the title is invalid
|
||||
* @throws XomwMalformedTitleException If the title is invalid
|
||||
* @return Title
|
||||
*/
|
||||
public static XomwTitle newFromTextThrow(byte[] text, int defaultNamespace) {
|
||||
@ -351,7 +351,7 @@ public class XomwTitle {
|
||||
// try {
|
||||
// t.secureAndSplit();
|
||||
// return t;
|
||||
// } catch (MalformedTitleException $ex) {
|
||||
// } catch (XomwMalformedTitleException $ex) {
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
@ -543,7 +543,7 @@ public class XomwTitle {
|
||||
// try {
|
||||
// t.secureAndSplit();
|
||||
// return t;
|
||||
// } catch (MalformedTitleException $ex) {
|
||||
// } catch (XomwMalformedTitleException $ex) {
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
@ -988,7 +988,7 @@ public class XomwTitle {
|
||||
}
|
||||
|
||||
// try {
|
||||
XomwMediaWikiTitleCodec formatter = getTitleFormatter();
|
||||
XomwTitleFormatter formatter = getTitleFormatter();
|
||||
return formatter.getNamespaceName(this.mNamespace, this.mDbkeyform);
|
||||
// } catch (InvalidArgumentException $ex) {
|
||||
// wfDebug(__METHOD__ . ': ' . $ex.getMessage() . "\n");
|
||||
@ -3351,7 +3351,7 @@ public class XomwTitle {
|
||||
* namespace prefixes, sets the other forms, and canonicalizes
|
||||
* everything.
|
||||
*
|
||||
* @throws MalformedTitleException On invalid titles
|
||||
* @throws XomwMalformedTitleException On invalid titles
|
||||
* @return boolean True on success
|
||||
*/
|
||||
private boolean secureAndSplit() {
|
||||
@ -3368,7 +3368,7 @@ public class XomwTitle {
|
||||
// @note: getTitleParser() returns a TitleParser implementation which does not have a
|
||||
// splitTitleString method, but the only implementation (MediaWikiTitleCodec) does
|
||||
XomwMediaWikiTitleCodec titleCodec = XomwMediaWikiServices.getInstance().getTitleParser();
|
||||
// MalformedTitleException can be thrown here
|
||||
// XomwMalformedTitleException can be thrown here
|
||||
XomwMediaWikiTitleCodecParts parts = titleCodec.splitTitleString(dbkey, this.getDefaultNamespace());
|
||||
|
||||
// Fill fields
|
||||
|
@ -0,0 +1,638 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.mediawiki.includes.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
import gplx.langs.htmls.*;
|
||||
/**
|
||||
* Holder of replacement pairs for wiki links
|
||||
*/
|
||||
public class XomwLinkHolderArray {
|
||||
private final Bry_bfr tmp = Bry_bfr_.New();
|
||||
private final Xomw_link_holder_list internals = new Xomw_link_holder_list();
|
||||
// public $interwikis = [];
|
||||
// public $size = 0;
|
||||
//
|
||||
/**
|
||||
* @var Parser
|
||||
*/
|
||||
private final Xomw_parser parent;
|
||||
// protected $tempIdOffset;
|
||||
|
||||
/**
|
||||
* @param Parser $parent
|
||||
*/
|
||||
public XomwLinkHolderArray(Xomw_parser parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Reduce memory usage to reduce the impact of circular references
|
||||
// */
|
||||
// public function __destruct() {
|
||||
// foreach ( $this as $name => $value ) {
|
||||
// unset( $this->$name );
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Don't serialize the parent Object, it is big, and not needed when it is
|
||||
// * a parameter to mergeForeign(), which is the only application of
|
||||
// * serializing at present.
|
||||
// *
|
||||
// * Compact the titles, only serialize the text form.
|
||||
// * @return array
|
||||
// */
|
||||
// public function __sleep() {
|
||||
// foreach ( $this->internals as &$nsLinks ) {
|
||||
// foreach ( $nsLinks as &$entry ) {
|
||||
// unset( $entry['title'] );
|
||||
// }
|
||||
// }
|
||||
// unset( $nsLinks );
|
||||
// unset( $entry );
|
||||
//
|
||||
// foreach ( $this->interwikis as &$entry ) {
|
||||
// unset( $entry['title'] );
|
||||
// }
|
||||
// unset( $entry );
|
||||
//
|
||||
// return [ 'internals', 'interwikis', 'size' ];
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Recreate the Title objects
|
||||
// */
|
||||
// public function __wakeup() {
|
||||
// foreach ( $this->internals as &$nsLinks ) {
|
||||
// foreach ( $nsLinks as &$entry ) {
|
||||
// $entry['title'] = Title::newFromText( $entry['pdbk'] );
|
||||
// }
|
||||
// }
|
||||
// unset( $nsLinks );
|
||||
// unset( $entry );
|
||||
//
|
||||
// foreach ( $this->interwikis as &$entry ) {
|
||||
// $entry['title'] = Title::newFromText( $entry['pdbk'] );
|
||||
// }
|
||||
// unset( $entry );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Merge another LinkHolderArray into this one
|
||||
// * @param LinkHolderArray $other
|
||||
// */
|
||||
// public function merge( $other ) {
|
||||
// foreach ( $other->internals as $ns => $entries ) {
|
||||
// $this->size += count( $entries );
|
||||
// if ( !isset( $this->internals[$ns] ) ) {
|
||||
// $this->internals[$ns] = $entries;
|
||||
// } else {
|
||||
// $this->internals[$ns] += $entries;
|
||||
// }
|
||||
// }
|
||||
// $this->interwikis += $other->interwikis;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Merge a LinkHolderArray from another parser instance into this one. The
|
||||
// * keys will not be preserved. Any text which went with the old
|
||||
// * LinkHolderArray and needs to work with the new one should be passed in
|
||||
// * the $texts array. The strings in this array will have their link holders
|
||||
// * converted for use in the destination link holder. The resulting array of
|
||||
// * strings will be returned.
|
||||
// *
|
||||
// * @param LinkHolderArray $other
|
||||
// * @param array $texts Array of strings
|
||||
// * @return array
|
||||
// */
|
||||
// public function mergeForeign( $other, $texts ) {
|
||||
// $this->tempIdOffset = $idOffset = $this->parent->nextLinkID();
|
||||
// $maxId = 0;
|
||||
//
|
||||
// # Renumber @gplx.Internal protected links
|
||||
// foreach ( $other->internals as $ns => $nsLinks ) {
|
||||
// foreach ( $nsLinks as $key => $entry ) {
|
||||
// $newKey = $idOffset + $key;
|
||||
// $this->internals[$ns][$newKey] = $entry;
|
||||
// $maxId = $newKey > $maxId ? $newKey : $maxId;
|
||||
// }
|
||||
// }
|
||||
// $texts = preg_replace_callback( '/(<!--LINK \d+:)(\d+)(-->)/',
|
||||
// [ $this, 'mergeForeignCallback' ], $texts );
|
||||
//
|
||||
// # Renumber interwiki links
|
||||
// foreach ( $other->interwikis as $key => $entry ) {
|
||||
// $newKey = $idOffset + $key;
|
||||
// $this->interwikis[$newKey] = $entry;
|
||||
// $maxId = $newKey > $maxId ? $newKey : $maxId;
|
||||
// }
|
||||
// $texts = preg_replace_callback( '/(<!--IWLINK )(\d+)(-->)/',
|
||||
// [ $this, 'mergeForeignCallback' ], $texts );
|
||||
//
|
||||
// # Set the parent link ID to be beyond the highest used ID
|
||||
// $this->parent->setLinkID( $maxId + 1 );
|
||||
// $this->tempIdOffset = null;
|
||||
// return $texts;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @param array $m
|
||||
// * @return String
|
||||
// */
|
||||
// protected function mergeForeignCallback( $m ) {
|
||||
// return $m[1] . ( $m[2] + $this->tempIdOffset ) . $m[3];
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Get a subset of the current LinkHolderArray which is sufficient to
|
||||
// * interpret the given text.
|
||||
// * @param String $text
|
||||
// * @return LinkHolderArray
|
||||
// */
|
||||
// public function getSubArray( $text ) {
|
||||
// $sub = new LinkHolderArray( $this->parent );
|
||||
//
|
||||
// # Internal links
|
||||
// $pos = 0;
|
||||
// while ( $pos < strlen( $text ) ) {
|
||||
// if ( !preg_match( '/<!--LINK (\d+):(\d+)-->/',
|
||||
// $text, $m, PREG_OFFSET_CAPTURE, $pos )
|
||||
// ) {
|
||||
// break;
|
||||
// }
|
||||
// $ns = $m[1][0];
|
||||
// $key = $m[2][0];
|
||||
// $sub->internals[$ns][$key] = $this->internals[$ns][$key];
|
||||
// $pos = $m[0][1] + strlen( $m[0][0] );
|
||||
// }
|
||||
//
|
||||
// # Interwiki links
|
||||
// $pos = 0;
|
||||
// while ( $pos < strlen( $text ) ) {
|
||||
// if ( !preg_match( '/<!--IWLINK (\d+)-->/', $text, $m, PREG_OFFSET_CAPTURE, $pos ) ) {
|
||||
// break;
|
||||
// }
|
||||
// $key = $m[1][0];
|
||||
// $sub->interwikis[$key] = $this->interwikis[$key];
|
||||
// $pos = $m[0][1] + strlen( $m[0][0] );
|
||||
// }
|
||||
// return $sub;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns true if the memory requirements of this Object are getting large
|
||||
// * @return boolean
|
||||
// */
|
||||
// public function isBig() {
|
||||
// global $wgLinkHolderBatchSize;
|
||||
// return $this->size > $wgLinkHolderBatchSize;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Clear all stored link holders.
|
||||
// * Make sure you don't have any text left using these link holders, before you call this
|
||||
// */
|
||||
// public function clear() {
|
||||
// $this->internals = [];
|
||||
// $this->interwikis = [];
|
||||
// $this->size = 0;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Make a link placeholder. The text returned can be later resolved to a real link with
|
||||
* replaceLinkHolders(). This is done for two reasons: firstly to avoid further
|
||||
* parsing of interwiki links, and secondly to allow all existence checks and
|
||||
* article length checks (for stub links) to be bundled into a single query.
|
||||
*
|
||||
* @param Title $nt
|
||||
* @param String $text
|
||||
* @param array $query [optional]
|
||||
* @param String $trail [optional]
|
||||
* @param String $prefix [optional]
|
||||
* @return String
|
||||
*/
|
||||
public void makeHolder(Bry_bfr bfr, XomwTitle nt, byte[] text, byte[][] query, byte[] trail, byte[] prefix) {
|
||||
if (nt == null) {
|
||||
// Fail gracefully
|
||||
bfr.Add_str_a7("<!-- ERROR -->").Add(prefix).Add(text).Add(trail);
|
||||
}
|
||||
else {
|
||||
// Separate the link trail from the rest of the link
|
||||
// list( $inside, $trail ) = Linker::splitTrail( $trail );
|
||||
byte[] inside = Bry_.Empty;
|
||||
|
||||
Xomw_link_holder_item entry = new Xomw_link_holder_item
|
||||
( nt
|
||||
, tmp.Add_bry_many(prefix, text, inside).To_bry_and_clear()
|
||||
, query);
|
||||
|
||||
if (nt.isExternal()) {
|
||||
// Use a globally unique ID to keep the objects mergable
|
||||
// $key = $this->parent->nextLinkID();
|
||||
// $this->interwikis[$key] = $entry;
|
||||
// $retVal = "<!--IWLINK $key-->{$trail}";
|
||||
}
|
||||
else {
|
||||
int key = this.parent.nextLinkID();
|
||||
this.internals.Add(key, entry);
|
||||
bfr.Add(Bry__link__bgn).Add_int_variable(key).Add(Gfh_tag_.Comm_end).Add(trail); // "<!--LINK $ns:$key-->{$trail}";
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// /**
|
||||
// * Replace <!--LINK--> link placeholders with actual links, in the buffer
|
||||
// *
|
||||
// * @param String $text
|
||||
// */
|
||||
// public function replace( &$text ) {
|
||||
// $this->replaceInternal( $text );
|
||||
// $this->replaceInterwiki( $text );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Replace @gplx.Internal protected links
|
||||
// * @param String $text
|
||||
// */
|
||||
// protected function replaceInternal( &$text ) {
|
||||
// if ( !$this->internals ) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// global $wgContLang;
|
||||
//
|
||||
// $colours = [];
|
||||
// $linkCache = LinkCache::singleton();
|
||||
// $output = $this->parent->getOutput();
|
||||
// $linkRenderer = $this->parent->getLinkRenderer();
|
||||
//
|
||||
// $dbr = wfGetDB( DB_REPLICA );
|
||||
//
|
||||
// # Sort by namespace
|
||||
// ksort( $this->internals );
|
||||
//
|
||||
// $linkcolour_ids = [];
|
||||
//
|
||||
// # Generate query
|
||||
// $lb = new LinkBatch();
|
||||
// $lb->setCaller( __METHOD__ );
|
||||
//
|
||||
// foreach ( $this->internals as $ns => $entries ) {
|
||||
// foreach ( $entries as $entry ) {
|
||||
// /** @var Title $title */
|
||||
// $title = $entry['title'];
|
||||
// $pdbk = $entry['pdbk'];
|
||||
//
|
||||
// # Skip invalid entries.
|
||||
// # Result will be ugly, but prevents crash.
|
||||
// if ( is_null( $title ) ) {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// # Check if it's a static known link, e.g. interwiki
|
||||
// if ( $title->isAlwaysKnown() ) {
|
||||
// $colours[$pdbk] = '';
|
||||
// } elseif ( $ns == NS_SPECIAL ) {
|
||||
// $colours[$pdbk] = 'new';
|
||||
// } else {
|
||||
// $id = $linkCache->getGoodLinkID( $pdbk );
|
||||
// if ( $id != 0 ) {
|
||||
// $colours[$pdbk] = $linkRenderer->getLinkClasses( $title );
|
||||
// $output->addLink( $title, $id );
|
||||
// $linkcolour_ids[$id] = $pdbk;
|
||||
// } elseif ( $linkCache->isBadLink( $pdbk ) ) {
|
||||
// $colours[$pdbk] = 'new';
|
||||
// } else {
|
||||
// # Not in the link cache, add it to the query
|
||||
// $lb->addObj( $title );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if ( !$lb->isEmpty() ) {
|
||||
// $fields = array_merge(
|
||||
// LinkCache::getSelectFields(),
|
||||
// [ 'page_namespace', 'page_title' ]
|
||||
// );
|
||||
//
|
||||
// $res = $dbr->select(
|
||||
// 'page',
|
||||
// $fields,
|
||||
// $lb->constructSet( 'page', $dbr ),
|
||||
// __METHOD__
|
||||
// );
|
||||
//
|
||||
// # Fetch data and form into an associative array
|
||||
// # non-existent = broken
|
||||
// foreach ( $res as $s ) {
|
||||
// $title = Title::makeTitle( $s->page_namespace, $s->page_title );
|
||||
// $pdbk = $title->getPrefixedDBkey();
|
||||
// $linkCache->addGoodLinkObjFromRow( $title, $s );
|
||||
// $output->addLink( $title, $s->page_id );
|
||||
// $colours[$pdbk] = $linkRenderer->getLinkClasses( $title );
|
||||
// // add id to the extension todolist
|
||||
// $linkcolour_ids[$s->page_id] = $pdbk;
|
||||
// }
|
||||
// unset( $res );
|
||||
// }
|
||||
// if ( count( $linkcolour_ids ) ) {
|
||||
// // pass an array of page_ids to an extension
|
||||
// Hooks::run( 'GetLinkColours', [ $linkcolour_ids, &$colours ] );
|
||||
// }
|
||||
//
|
||||
// # Do a second query for different language variants of links and categories
|
||||
// if ( $wgContLang->hasVariants() ) {
|
||||
// $this->doVariants( $colours );
|
||||
// }
|
||||
//
|
||||
// # Construct search and replace arrays
|
||||
// $replacePairs = [];
|
||||
// foreach ( $this->internals as $ns => $entries ) {
|
||||
// foreach ( $entries as $index => $entry ) {
|
||||
// $pdbk = $entry['pdbk'];
|
||||
// $title = $entry['title'];
|
||||
// $query = isset( $entry['query'] ) ? $entry['query'] : [];
|
||||
// $key = "$ns:$index";
|
||||
// $searchkey = "<!--LINK $key-->";
|
||||
// $displayText = $entry['text'];
|
||||
// if ( isset( $entry['selflink'] ) ) {
|
||||
// $replacePairs[$searchkey] = Linker::makeSelfLinkObj( $title, $displayText, $query );
|
||||
// continue;
|
||||
// }
|
||||
// if ( $displayText === '' ) {
|
||||
// $displayText = null;
|
||||
// } else {
|
||||
// $displayText = new HtmlArmor( $displayText );
|
||||
// }
|
||||
// if ( !isset( $colours[$pdbk] ) ) {
|
||||
// $colours[$pdbk] = 'new';
|
||||
// }
|
||||
// $attribs = [];
|
||||
// if ( $colours[$pdbk] == 'new' ) {
|
||||
// $linkCache->addBadLinkObj( $title );
|
||||
// $output->addLink( $title, 0 );
|
||||
// $link = $linkRenderer->makeBrokenLink(
|
||||
// $title, $displayText, $attribs, $query
|
||||
// );
|
||||
// } else {
|
||||
// $link = $linkRenderer->makePreloadedLink(
|
||||
// $title, $displayText, $colours[$pdbk], $attribs, $query
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// $replacePairs[$searchkey] = $link;
|
||||
// }
|
||||
// }
|
||||
// $replacer = new HashtableReplacer( $replacePairs, 1 );
|
||||
//
|
||||
// # Do the thing
|
||||
// $text = preg_replace_callback(
|
||||
// '/(<!--LINK .*?-->)/',
|
||||
// $replacer->cb(),
|
||||
// $text
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Replace interwiki links
|
||||
// * @param String $text
|
||||
// */
|
||||
// protected function replaceInterwiki( &$text ) {
|
||||
// if ( empty( $this->interwikis ) ) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// # Make interwiki link HTML
|
||||
// $output = $this->parent->getOutput();
|
||||
// $replacePairs = [];
|
||||
// $linkRenderer = $this->parent->getLinkRenderer();
|
||||
// foreach ( $this->interwikis as $key => $link ) {
|
||||
// $replacePairs[$key] = $linkRenderer->makeLink(
|
||||
// $link['title'],
|
||||
// new HtmlArmor( $link['text'] )
|
||||
// );
|
||||
// $output->addInterwikiLink( $link['title'] );
|
||||
// }
|
||||
// $replacer = new HashtableReplacer( $replacePairs, 1 );
|
||||
//
|
||||
// $text = preg_replace_callback(
|
||||
// '/<!--IWLINK (.*?)-->/',
|
||||
// $replacer->cb(),
|
||||
// $text );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Modify $this->internals and $colours according to language variant linking rules
|
||||
// * @param array $colours
|
||||
// */
|
||||
// protected function doVariants( &$colours ) {
|
||||
// global $wgContLang;
|
||||
// $linkBatch = new LinkBatch();
|
||||
// $variantMap = []; // maps $pdbkey_Variant => $keys (of link holders)
|
||||
// $output = $this->parent->getOutput();
|
||||
// $linkCache = LinkCache::singleton();
|
||||
// $titlesToBeConverted = '';
|
||||
// $titlesAttrs = [];
|
||||
//
|
||||
// // Concatenate titles to a single String, thus we only need auto convert the
|
||||
// // single String to all variants. This would improve parser's performance
|
||||
// // significantly.
|
||||
// foreach ( $this->internals as $ns => $entries ) {
|
||||
// if ( $ns == NS_SPECIAL ) {
|
||||
// continue;
|
||||
// }
|
||||
// foreach ( $entries as $index => $entry ) {
|
||||
// $pdbk = $entry['pdbk'];
|
||||
// // we only deal with new links (in its first query)
|
||||
// if ( !isset( $colours[$pdbk] ) || $colours[$pdbk] === 'new' ) {
|
||||
// $titlesAttrs[] = [ $index, $entry['title'] ];
|
||||
// // separate titles with \0 because it would never appears
|
||||
// // in a valid title
|
||||
// $titlesToBeConverted .= $entry['title']->getText() . "\0";
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Now do the conversion and explode String to text of titles
|
||||
// $titlesAllVariants = $wgContLang->autoConvertToAllVariants( rtrim( $titlesToBeConverted, "\0" ) );
|
||||
// $allVariantsName = array_keys( $titlesAllVariants );
|
||||
// foreach ( $titlesAllVariants as &$titlesVariant ) {
|
||||
// $titlesVariant = explode( "\0", $titlesVariant );
|
||||
// }
|
||||
//
|
||||
// // Then add variants of links to link batch
|
||||
// $parentTitle = $this->parent->getTitle();
|
||||
// foreach ( $titlesAttrs as $i => $attrs ) {
|
||||
// /** @var Title $title */
|
||||
// list( $index, $title ) = $attrs;
|
||||
// $ns = $title->getNamespace();
|
||||
// $text = $title->getText();
|
||||
//
|
||||
// foreach ( $allVariantsName as $variantName ) {
|
||||
// $textVariant = $titlesAllVariants[$variantName][$i];
|
||||
// if ( $textVariant === $text ) {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// $variantTitle = Title::makeTitle( $ns, $textVariant );
|
||||
//
|
||||
// // Self-link checking for mixed/different variant titles. At this point, we
|
||||
// // already know the exact title does not exist, so the link cannot be to a
|
||||
// // variant of the current title that exists as a separate page.
|
||||
// if ( $variantTitle->equals( $parentTitle ) && !$title->hasFragment() ) {
|
||||
// $this->internals[$ns][$index]['selflink'] = true;
|
||||
// continue 2;
|
||||
// }
|
||||
//
|
||||
// $linkBatch->addObj( $variantTitle );
|
||||
// $variantMap[$variantTitle->getPrefixedDBkey()][] = "$ns:$index";
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // process categories, check if a category exists in some variant
|
||||
// $categoryMap = []; // maps $category_variant => $category (dbkeys)
|
||||
// $varCategories = []; // category replacements oldDBkey => newDBkey
|
||||
// foreach ( $output->getCategoryLinks() as $category ) {
|
||||
// $categoryTitle = Title::makeTitleSafe( NS_CATEGORY, $category );
|
||||
// $linkBatch->addObj( $categoryTitle );
|
||||
// $variants = $wgContLang->autoConvertToAllVariants( $category );
|
||||
// foreach ( $variants as $variant ) {
|
||||
// if ( $variant !== $category ) {
|
||||
// $variantTitle = Title::makeTitleSafe( NS_CATEGORY, $variant );
|
||||
// if ( is_null( $variantTitle ) ) {
|
||||
// continue;
|
||||
// }
|
||||
// $linkBatch->addObj( $variantTitle );
|
||||
// $categoryMap[$variant] = [ $category, $categoryTitle ];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if ( !$linkBatch->isEmpty() ) {
|
||||
// // construct query
|
||||
// $dbr = wfGetDB( DB_REPLICA );
|
||||
// $fields = array_merge(
|
||||
// LinkCache::getSelectFields(),
|
||||
// [ 'page_namespace', 'page_title' ]
|
||||
// );
|
||||
//
|
||||
// $varRes = $dbr->select( 'page',
|
||||
// $fields,
|
||||
// $linkBatch->constructSet( 'page', $dbr ),
|
||||
// __METHOD__
|
||||
// );
|
||||
//
|
||||
// $linkcolour_ids = [];
|
||||
// $linkRenderer = $this->parent->getLinkRenderer();
|
||||
//
|
||||
// // for each found variants, figure out link holders and replace
|
||||
// foreach ( $varRes as $s ) {
|
||||
// $variantTitle = Title::makeTitle( $s->page_namespace, $s->page_title );
|
||||
// $varPdbk = $variantTitle->getPrefixedDBkey();
|
||||
// $vardbk = $variantTitle->getDBkey();
|
||||
//
|
||||
// $holderKeys = [];
|
||||
// if ( isset( $variantMap[$varPdbk] ) ) {
|
||||
// $holderKeys = $variantMap[$varPdbk];
|
||||
// $linkCache->addGoodLinkObjFromRow( $variantTitle, $s );
|
||||
// $output->addLink( $variantTitle, $s->page_id );
|
||||
// }
|
||||
//
|
||||
// // loop over link holders
|
||||
// foreach ( $holderKeys as $key ) {
|
||||
// list( $ns, $index ) = explode( ':', $key, 2 );
|
||||
// $entry =& $this->internals[$ns][$index];
|
||||
// $pdbk = $entry['pdbk'];
|
||||
//
|
||||
// if ( !isset( $colours[$pdbk] ) || $colours[$pdbk] === 'new' ) {
|
||||
// // found link in some of the variants, replace the link holder data
|
||||
// $entry['title'] = $variantTitle;
|
||||
// $entry['pdbk'] = $varPdbk;
|
||||
//
|
||||
// // set pdbk and colour
|
||||
// $colours[$varPdbk] = $linkRenderer->getLinkClasses( $variantTitle );
|
||||
// $linkcolour_ids[$s->page_id] = $pdbk;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // check if the Object is a variant of a category
|
||||
// if ( isset( $categoryMap[$vardbk] ) ) {
|
||||
// list( $oldkey, $oldtitle ) = $categoryMap[$vardbk];
|
||||
// if ( !isset( $varCategories[$oldkey] ) && !$oldtitle->exists() ) {
|
||||
// $varCategories[$oldkey] = $vardbk;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// Hooks::run( 'GetLinkColours', [ $linkcolour_ids, &$colours ] );
|
||||
//
|
||||
// // rebuild the categories in original order (if there are replacements)
|
||||
// if ( count( $varCategories ) > 0 ) {
|
||||
// $newCats = [];
|
||||
// $originalCats = $output->getCategories();
|
||||
// foreach ( $originalCats as $cat => $sortkey ) {
|
||||
// // make the replacement
|
||||
// if ( array_key_exists( $cat, $varCategories ) ) {
|
||||
// $newCats[$varCategories[$cat]] = $sortkey;
|
||||
// } else {
|
||||
// $newCats[$cat] = $sortkey;
|
||||
// }
|
||||
// }
|
||||
// $output->setCategoryLinks( $newCats );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Replace <!--LINK--> link placeholders with plain text of links
|
||||
// * (not HTML-formatted).
|
||||
// *
|
||||
// * @param String $text
|
||||
// * @return String
|
||||
// */
|
||||
// public function replaceText( $text ) {
|
||||
// $text = preg_replace_callback(
|
||||
// '/<!--(LINK|IWLINK) (.*?)-->/',
|
||||
// [ &$this, 'replaceTextCallback' ],
|
||||
// $text );
|
||||
//
|
||||
// return $text;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Callback for replaceText()
|
||||
// *
|
||||
// * @param array $matches
|
||||
// * @return String
|
||||
// * @private
|
||||
// */
|
||||
// public function replaceTextCallback( $matches ) {
|
||||
// $type = $matches[1];
|
||||
// $key = $matches[2];
|
||||
// if ( $type == 'LINK' ) {
|
||||
// list( $ns, $index ) = explode( ':', $key, 2 );
|
||||
// if ( isset( $this->internals[$ns][$index]['text'] ) ) {
|
||||
// return $this->internals[$ns][$index]['text'];
|
||||
// }
|
||||
// } elseif ( $type == 'IWLINK' ) {
|
||||
// if ( isset( $this->interwikis[$key]['text'] ) ) {
|
||||
// return $this->interwikis[$key]['text'];
|
||||
// }
|
||||
// }
|
||||
// return $matches[0];
|
||||
// }
|
||||
private static final byte[] Bry__link__bgn = Bry_.new_a7("<!--LINK ");
|
||||
}
|
@ -52,6 +52,17 @@ public class Xomw_parser {
|
||||
public Xomw_quote_wkr Quote_wkr() {return quote_wkr;} private final Xomw_quote_wkr quote_wkr;
|
||||
public Xomw_lnki_wkr Lnki_wkr() {return lnki_wkr;} private final Xomw_lnki_wkr lnki_wkr;
|
||||
public boolean Output_type__wiki() {return output_type__wiki;} private final boolean output_type__wiki = false;
|
||||
|
||||
|
||||
private int mLinkID;
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public int nextLinkID() {
|
||||
return this.mLinkID++;
|
||||
}
|
||||
|
||||
|
||||
public Xomw_parser() {
|
||||
if (regex_space == null) {
|
||||
synchronized (Type_adp_.ClassOf_obj(this)) {
|
||||
|
@ -675,16 +675,17 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
|
||||
// $handler->parserTransformHook($this, $file);
|
||||
// }
|
||||
}
|
||||
// protected function stripAltText( $caption, $holders ) {
|
||||
// private byte[] stripAltText(byte[] caption, Xomw_link_holders holders) {
|
||||
// // Strip bad stuff out of the title (tooltip). We can't just use
|
||||
// // replaceLinkHoldersText() here, because if this function is called
|
||||
// // from replaceInternalLinks2(), mLinkHolders won't be up-to-date.
|
||||
// if ( $holders ) {
|
||||
// $tooltip = $holders->replaceText( $caption );
|
||||
// byte[] tooltip;
|
||||
// if (holders != null) {
|
||||
// tooltip = holders.Replace(caption);
|
||||
// } else {
|
||||
// $tooltip = $this->replaceLinkHoldersText( $caption );
|
||||
// tooltip = this.Replace_link_holders(caption);
|
||||
// }
|
||||
//
|
||||
|
||||
// // make sure there are no placeholders in thumbnail attributes
|
||||
// // that are later expanded to html- so expand them now and
|
||||
// // remove the tags
|
||||
|
@ -16,5 +16,5 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.mediawiki.includes.title; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
public class MalformedTitleException extends Err { public MalformedTitleException(String name, byte[] text) {super(false, "", name, name);}
|
||||
public class XomwMalformedTitleException extends Err { public XomwMalformedTitleException(String name, byte[] text) {super(false, "", name, name);}
|
||||
}
|
@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.mediawiki.includes.title; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
import gplx.xowa.mediawiki.languages.*;
|
||||
import gplx.xowa.mediawiki.includes.utls.*;
|
||||
public class XomwMediaWikiTitleCodec {
|
||||
public class XomwMediaWikiTitleCodec implements XomwTitleFormatter {
|
||||
/**
|
||||
* @var Language
|
||||
*/
|
||||
@ -120,7 +120,7 @@ public class XomwMediaWikiTitleCodec {
|
||||
// * @param String $text The text to parse
|
||||
// * @param int $defaultNamespace Namespace to assume per default (usually NS_MAIN)
|
||||
// *
|
||||
// * @throws MalformedTitleException
|
||||
// * @throws XomwMalformedTitleException
|
||||
// * @return TitleValue
|
||||
// */
|
||||
// public function parseTitle($text, $defaultNamespace) {
|
||||
@ -131,7 +131,7 @@ public class XomwMediaWikiTitleCodec {
|
||||
//
|
||||
// // Relative fragment links are not supported by TitleValue
|
||||
// if ($parts['dbkey'] === '') {
|
||||
// throw new MalformedTitleException('title-invalid-empty', $text);
|
||||
// throw new XomwMalformedTitleException('title-invalid-empty', $text);
|
||||
// }
|
||||
//
|
||||
// return new TitleValue(
|
||||
@ -232,7 +232,7 @@ public class XomwMediaWikiTitleCodec {
|
||||
* @param String $text
|
||||
* @param int $defaultNamespace
|
||||
*
|
||||
* @throws MalformedTitleException If $text is not a valid title String.
|
||||
* @throws XomwMalformedTitleException If $text is not a valid title String.
|
||||
* @return array A map with the fields 'interwiki', 'fragment', 'namespace',
|
||||
* 'user_case_dbkey', and 'dbkey'.
|
||||
*/
|
||||
@ -260,7 +260,7 @@ public class XomwMediaWikiTitleCodec {
|
||||
|
||||
// if (strpos(dbkey, UtfNormal\Constants::UTF8_REPLACEMENT) !== false) {
|
||||
// // Contained illegal UTF-8 sequences or forbidden Unicode chars.
|
||||
// throw new MalformedTitleException('title-invalid-utf8', text);
|
||||
// throw new XomwMalformedTitleException('title-invalid-utf8', text);
|
||||
// }
|
||||
|
||||
parts.dbkey = dbkey;
|
||||
@ -274,7 +274,7 @@ public class XomwMediaWikiTitleCodec {
|
||||
// }
|
||||
|
||||
if (dbkey == Bry_.Empty) {
|
||||
throw new MalformedTitleException("title-invalid-empty", text);
|
||||
throw new XomwMalformedTitleException("title-invalid-empty", text);
|
||||
}
|
||||
|
||||
// Namespace or interwiki prefix
|
||||
@ -296,11 +296,11 @@ public class XomwMediaWikiTitleCodec {
|
||||
// if ($ns == NS_TALK && preg_match($prefixRegexp, dbkey, $x)) {
|
||||
// if ($this->language->getNsIndex($x[1])) {
|
||||
// // Disallow Talk:File:x type titles...
|
||||
// throw new MalformedTitleException('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 MalformedTitleException('title-invalid-talk-namespace', text);
|
||||
// throw new XomwMalformedTitleException('title-invalid-talk-namespace', text);
|
||||
// }
|
||||
// }
|
||||
// } elseif (Interwiki::isValidInterwiki($p)) {
|
||||
@ -359,7 +359,7 @@ public class XomwMediaWikiTitleCodec {
|
||||
// $rxTc = self::getTitleInvalidRegex();
|
||||
// $matches = [];
|
||||
// if (preg_match($rxTc, dbkey, $matches)) {
|
||||
// throw new MalformedTitleException('title-invalid-characters', text, [ $matches[0] ]);
|
||||
// throw new XomwMalformedTitleException('title-invalid-characters', text, [ $matches[0] ]);
|
||||
// }
|
||||
|
||||
// Pages with "/./" or "/../" appearing in the URLs will often be un-
|
||||
@ -377,12 +377,12 @@ public class XomwMediaWikiTitleCodec {
|
||||
// substr(dbkey, -3) == '/..'
|
||||
// )
|
||||
// ) {
|
||||
// throw new MalformedTitleException('title-invalid-relative', text);
|
||||
// throw new XomwMalformedTitleException('title-invalid-relative', text);
|
||||
// }
|
||||
|
||||
// Magic tilde sequences? Nu-uh!
|
||||
// if (strpos(dbkey, '~~~') !== false) {
|
||||
// throw new MalformedTitleException('title-invalid-magic-tilde', text);
|
||||
// throw new XomwMalformedTitleException('title-invalid-magic-tilde', text);
|
||||
// }
|
||||
|
||||
// Limit the size of titles to 255 bytes. This is typically the size of the
|
||||
@ -391,7 +391,7 @@ public class XomwMediaWikiTitleCodec {
|
||||
// to subpage syntax for long titles, e.g. [[Special:Block/Long name]]
|
||||
// $maxLength = (parts['namespace'] != NS_SPECIAL) ? 255 : 512;
|
||||
// if (strlen(dbkey) > $maxLength) {
|
||||
// throw new MalformedTitleException('title-invalid-too-long', text,
|
||||
// throw new XomwMalformedTitleException('title-invalid-too-long', text,
|
||||
// [ Message::numParam($maxLength) ]);
|
||||
// }
|
||||
|
||||
@ -407,7 +407,7 @@ public class XomwMediaWikiTitleCodec {
|
||||
// self-links with a fragment identifier.
|
||||
// if (dbkey == '' && parts['interwiki'] === '') {
|
||||
// if (parts['namespace'] != NS_MAIN) {
|
||||
// throw new MalformedTitleException('title-invalid-empty', text);
|
||||
// throw new XomwMalformedTitleException('title-invalid-empty', text);
|
||||
// }
|
||||
// }
|
||||
|
||||
@ -423,7 +423,7 @@ public class XomwMediaWikiTitleCodec {
|
||||
|
||||
// Any remaining initial :s are illegal.
|
||||
if (dbkey != Bry_.Empty && Byte_ascii.Colon == dbkey[0]) {
|
||||
throw new MalformedTitleException("title-invalid-leading-colon", text);
|
||||
throw new XomwMalformedTitleException("title-invalid-leading-colon", text);
|
||||
}
|
||||
|
||||
// Fill fields
|
||||
|
@ -0,0 +1,98 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.mediawiki.includes.title; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
/**
|
||||
* A title formatter service for MediaWiki.
|
||||
*
|
||||
* This is designed to encapsulate knowledge about conventions for the title
|
||||
* forms to be used in the database, in urls, in wikitext, etc.
|
||||
*
|
||||
* @see https://www.mediawiki.org/wiki/Requests_for_comment/TitleValue
|
||||
* @since 1.23
|
||||
*/
|
||||
public interface XomwTitleFormatter {
|
||||
// /**
|
||||
// * Returns the title formatted for display.
|
||||
// * Per default, this includes the namespace but not the fragment.
|
||||
// *
|
||||
// * @note Normalization is applied if $title is not in TitleValue::TITLE_FORM.
|
||||
// *
|
||||
// * @param int|boolean $namespace The namespace ID (or false, if the namespace should be ignored)
|
||||
// * @param String $text The page title
|
||||
// * @param String $fragment The fragment name (may be empty).
|
||||
// * @param String $interwiki The interwiki prefix (may be empty).
|
||||
// *
|
||||
// * @return String
|
||||
// */
|
||||
// public function formatTitle($namespace, $text, $fragment = '', $interwiki = '');
|
||||
//
|
||||
// /**
|
||||
// * Returns the title text formatted for display, without namespace of fragment.
|
||||
// *
|
||||
// * @note Only minimal normalization is applied. Consider using TitleValue::getText() directly.
|
||||
// *
|
||||
// * @param LinkTarget $title The title to format
|
||||
// *
|
||||
// * @return String
|
||||
// */
|
||||
// public function getText(LinkTarget $title);
|
||||
//
|
||||
// /**
|
||||
// * Returns the title formatted for display, including the namespace name.
|
||||
// *
|
||||
// * @param LinkTarget $title The title to format
|
||||
// *
|
||||
// * @return String
|
||||
// */
|
||||
// public function getPrefixedText(LinkTarget $title);
|
||||
//
|
||||
// /**
|
||||
// * Return the title in prefixed database key form, with interwiki
|
||||
// * and namespace.
|
||||
// *
|
||||
// * @since 1.27
|
||||
// *
|
||||
// * @param LinkTarget $target
|
||||
// *
|
||||
// * @return String
|
||||
// */
|
||||
// public function getPrefixedDBkey(LinkTarget $target);
|
||||
//
|
||||
// /**
|
||||
// * Returns the title formatted for display, with namespace and fragment.
|
||||
// *
|
||||
// * @param LinkTarget $title The title to format
|
||||
// *
|
||||
// * @return String
|
||||
// */
|
||||
// public function getFullText(LinkTarget $title);
|
||||
|
||||
/**
|
||||
* Returns the name of the namespace for the given title.
|
||||
*
|
||||
* @note This must take into account gender sensitive namespace names.
|
||||
* @todo Move this to a separate interface
|
||||
*
|
||||
* @param int $namespace
|
||||
* @param String $text
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
* @return String
|
||||
*/
|
||||
byte[] getNamespaceName(int ns, byte[] text);
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.mediawiki.includes.title; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
/**
|
||||
* A title parser service for %MediaWiki.
|
||||
*
|
||||
* This is designed to encapsulate knowledge about conventions for the title
|
||||
* forms to be used in the database, in urls, in wikitext, etc.
|
||||
*
|
||||
* @see https://www.mediawiki.org/wiki/Requests_for_comment/TitleValue
|
||||
* @since 1.23
|
||||
*/
|
||||
public interface XomwTitleParser {
|
||||
/**
|
||||
* Parses the given text and constructs a TitleValue. Normalization
|
||||
* is applied according to the rules appropriate for the form specified by $form.
|
||||
*
|
||||
* @note this only parses local page links, interwiki-prefixes etc. are not considered!
|
||||
*
|
||||
* @param String $text The text to parse
|
||||
* @param int $defaultNamespace Namespace to assume per default (usually NS_MAIN)
|
||||
*
|
||||
* @throws MalformedTitleException If the text is not a valid representation of a page title.
|
||||
* @return TitleValue
|
||||
*/
|
||||
XomwTitle parseTitle(byte[] text, int defaultNamespace);
|
||||
}
|
@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.mediawiki.languages; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*;
|
||||
import gplx.core.lists.hashs.*;
|
||||
import gplx.core.lists.*;
|
||||
import gplx.xowa.mediawiki.includes.*;
|
||||
public class XomwLanguage {
|
||||
// /**
|
||||
@ -32,7 +32,7 @@ public class XomwLanguage {
|
||||
// public $mExtendedSpecialPageAliases;
|
||||
//
|
||||
// /** @var array|null */
|
||||
private Hash_adp__int namespaceNames;
|
||||
private HashByInt namespaceNames;
|
||||
// protected $mNamespaceIds, $namespaceAliases;
|
||||
//
|
||||
// /**
|
||||
@ -482,11 +482,11 @@ public class XomwLanguage {
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public Hash_adp__int getNamespaces() {
|
||||
public HashByInt getNamespaces() {
|
||||
if (this.namespaceNames == null) {
|
||||
// global $wgMetaNamespace, $wgMetaNamespaceTalk, $wgExtraNamespaces;
|
||||
//
|
||||
Hash_adp__int validNamespaces = XomwNamespace.getCanonicalNamespaces();
|
||||
HashByInt validNamespaces = XomwNamespace.getCanonicalNamespaces();
|
||||
//
|
||||
// this.namespaceNames = $wgExtraNamespaces +
|
||||
// self::$dataCache->getItem(this.mCode, 'namespaceNames');
|
||||
@ -563,9 +563,8 @@ public class XomwLanguage {
|
||||
* @return String|boolean String if the namespace value exists, otherwise false
|
||||
*/
|
||||
public byte[] getNsText(int index) {
|
||||
Hash_adp__int ns = this.getNamespaces();
|
||||
HashByInt ns = this.getNamespaces();
|
||||
return (byte[])ns.Get_by_or_null(index);
|
||||
// return isset($ns[$index]) ? $ns[$index] : false;
|
||||
}
|
||||
|
||||
// /**
|
||||
|
Loading…
Reference in New Issue
Block a user