mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-09-28 14:30:51 +00:00
Xomw: Add XomwMessageContent and related classes
This commit is contained in:
parent
39830cfa4f
commit
7e476fde06
@ -22,7 +22,7 @@ public class Pack_zip_name_bldr__tst {
|
||||
}
|
||||
@Test public void Bld_by_suffix() {
|
||||
Pack_zip_name_bldr bldr = fxt.Make__bldr("mem/wiki/en.wikipedia.org/tmp/pack/", "en.wikipedia.org", "enwiki", "2017-03", null);
|
||||
fxt.Test__bld_by_suffix(bldr, "xtn.fulltext_search", 1, "mem/wiki/en.wikipedia.org/tmp/pack/Xowa_enwiki_2017-03_xtn.fulltext_search.001.zip");
|
||||
fxt.Test__bld_by_suffix(bldr, "xtn.fulltext_search", 1, "mem/wiki/en.wikipedia.org/tmp/pack/Xowa_enwiki_2017-03_xtn.fulltext_search.002.zip");
|
||||
}
|
||||
}
|
||||
class Pack_zip_name_bldr__fxt {
|
||||
|
@ -959,14 +959,29 @@ public class XomwDefaultSettings {
|
||||
// * and extensions should use extension.json.
|
||||
// */
|
||||
// $wgMediaHandlers = [];
|
||||
//
|
||||
// /**
|
||||
// * Plugins for page content model handling.
|
||||
// * Each entry in the array maps a model id to a class name or callback
|
||||
// * that creates an instance of the appropriate ContentHandler subclass.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// */
|
||||
|
||||
/**
|
||||
* Plugins for page content model handling.
|
||||
* Each entry in the array maps a model id to a class name or callback
|
||||
* that creates an instance of the appropriate ContentHandler subclass.
|
||||
*
|
||||
* @since 1.21
|
||||
*/
|
||||
public static final int
|
||||
// the usual case
|
||||
CONTENT_MODEL_WIKITEXT = 0
|
||||
// dumb version, no syntax highlighting
|
||||
, CONTENT_MODEL_JAVASCRIPT = 1
|
||||
// simple implementation, for use by extensions, etc.
|
||||
, CONTENT_MODEL_JSON = 2
|
||||
// dumb version, no syntax highlighting
|
||||
, CONTENT_MODEL_CSS = 3
|
||||
// plain text, for use by extensions, etc.
|
||||
, CONTENT_MODEL_TEXT = 4
|
||||
// XO:max for array
|
||||
, CONTENT_MODEL__MAX = 5
|
||||
;
|
||||
|
||||
// $wgContentHandlers = [
|
||||
// // the usual case
|
||||
// CONTENT_MODEL_WIKITEXT => 'WikitextContentHandler',
|
||||
@ -979,7 +994,7 @@ public class XomwDefaultSettings {
|
||||
// // plain text, for use by extensions, etc.
|
||||
// CONTENT_MODEL_TEXT => 'TextContentHandler',
|
||||
// ];
|
||||
//
|
||||
|
||||
// /**
|
||||
// * Whether to enable server-side image thumbnailing. If false, images will
|
||||
// * always be sent to the client in full resolution, with appropriate width= and
|
||||
|
@ -275,32 +275,32 @@ public class XomwDefines {
|
||||
// define( 'CONTENT_MODEL_TEXT', 'text' );
|
||||
// define( 'CONTENT_MODEL_JSON', 'json' );
|
||||
// /**@}*/
|
||||
//
|
||||
// /**@{
|
||||
// * Content formats, used by Content and ContentHandler.
|
||||
// * These should be MIME types, and will be exposed in the API and XML dumps.
|
||||
// *
|
||||
// * Extensions are free to use the below formats, or define their own.
|
||||
// * It is recommended to stick with the conventions for MIME types.
|
||||
// */
|
||||
// // wikitext
|
||||
// define( 'CONTENT_FORMAT_WIKITEXT', 'text/x-wiki' );
|
||||
// // for js pages
|
||||
// define( 'CONTENT_FORMAT_JAVASCRIPT', 'text/javascript' );
|
||||
// // for css pages
|
||||
// define( 'CONTENT_FORMAT_CSS', 'text/css' );
|
||||
// // for future use, e.g. with some plain-html messages.
|
||||
// define( 'CONTENT_FORMAT_TEXT', 'text/plain' );
|
||||
// // for future use, e.g. with some plain-html messages.
|
||||
// define( 'CONTENT_FORMAT_HTML', 'text/html' );
|
||||
// // for future use with the api and for extensions
|
||||
// define( 'CONTENT_FORMAT_SERIALIZED', 'application/vnd.php.serialized' );
|
||||
// // for future use with the api, and for use by extensions
|
||||
// define( 'CONTENT_FORMAT_JSON', 'application/json' );
|
||||
// // for future use with the api, and for use by extensions
|
||||
// define( 'CONTENT_FORMAT_XML', 'application/xml' );
|
||||
// /**@}*/
|
||||
//
|
||||
|
||||
/**@{
|
||||
* Content formats, used by Content and ContentHandler.
|
||||
* These should be MIME types, and will be exposed in the API and XML dumps.
|
||||
*
|
||||
* Extensions are free to use the below formats, or define their own.
|
||||
* It is recommended to stick with the conventions for MIME types.
|
||||
*/
|
||||
// wikitext
|
||||
public static final String CONTENT_FORMAT_WIKITEXT = "text/x-wiki";
|
||||
// for js pages
|
||||
public static final String CONTENT_FORMAT_JAVASCRIPT = "text/javascript";
|
||||
// for css pages
|
||||
public static final String CONTENT_FORMAT_CSS = "text/css";
|
||||
// for future use, e.g. with some plain-html messages.
|
||||
public static final String CONTENT_FORMAT_TEXT = "text/plain";
|
||||
// for future use, e.g. with some plain-html messages.
|
||||
public static final String CONTENT_FORMAT_HTML = "text/html";
|
||||
// for future use with the api and for extensions
|
||||
public static final String CONTENT_FORMAT_SERIALIZED = "application/vnd.php.serialized";
|
||||
// for future use with the api, and for use by extensions
|
||||
public static final String CONTENT_FORMAT_JSON = "application/json";
|
||||
// for future use with the api, and for use by extensions
|
||||
public static final String CONTENT_FORMAT_XML = "application/xml";
|
||||
/**@}*/
|
||||
|
||||
// /**@{
|
||||
// * Max String length for shell invocations; based on binfmts.h
|
||||
// */
|
||||
|
@ -14,108 +14,109 @@ 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.content; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
// <?php
|
||||
// /**
|
||||
// * A content Object represents page content, e.g. the text to show on a page.
|
||||
// * Content objects have no knowledge about how they relate to Wiki pages.
|
||||
// */
|
||||
//
|
||||
// /**
|
||||
// * Base implementation for content objects.
|
||||
// *
|
||||
// * @ingroup Content
|
||||
// */
|
||||
// abstract class AbstractContent implements Content {
|
||||
// /**
|
||||
// * Name of the content model this Content Object represents.
|
||||
// * Use with CONTENT_MODEL_XXX constants
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @var String $model_id
|
||||
// */
|
||||
// protected $model_id;
|
||||
//
|
||||
// /**
|
||||
// * @param String $modelId
|
||||
// *
|
||||
// * @since 1.21
|
||||
// */
|
||||
// public function __construct( $modelId = null ) {
|
||||
// $this->model_id = $modelId;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @see Content::getModel
|
||||
// */
|
||||
// public function getModel() {
|
||||
// return $this->model_id;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param String $modelId The model to check
|
||||
// *
|
||||
// * @throws MWException If the provided ID is not the ID of the content model supported by this
|
||||
// * Content Object.
|
||||
// */
|
||||
// protected function checkModelID( $modelId ) {
|
||||
// if ( $modelId !== $this->model_id ) {
|
||||
// throw new MWException(
|
||||
// "Bad content model: " .
|
||||
// "expected {$this->model_id} " .
|
||||
// "but got $modelId."
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @see Content::getContentHandler
|
||||
// */
|
||||
// public function getContentHandler() {
|
||||
// return ContentHandler::getForContent( $this );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @see Content::getDefaultFormat
|
||||
// */
|
||||
// public function getDefaultFormat() {
|
||||
// return $this->getContentHandler()->getDefaultFormat();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @see Content::getSupportedFormats
|
||||
// */
|
||||
// public function getSupportedFormats() {
|
||||
// return $this->getContentHandler()->getSupportedFormats();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param String $format
|
||||
// *
|
||||
// * @return boolean
|
||||
// *
|
||||
// * @see Content::isSupportedFormat
|
||||
// */
|
||||
// public function isSupportedFormat( $format ) {
|
||||
// if ( !$format ) {
|
||||
// return true; // this means "use the default"
|
||||
// }
|
||||
//
|
||||
// return $this->getContentHandler()->isSupportedFormat( $format );
|
||||
// }
|
||||
//
|
||||
import gplx.xowa.mediawiki.includes.exception.*;
|
||||
import gplx.xowa.mediawiki.includes.parsers.*;
|
||||
/**
|
||||
* A content Object represents page content, e.g. the text to show on a page.
|
||||
* Content objects have no knowledge about how they relate to Wiki pages.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base implementation for content objects.
|
||||
*
|
||||
* @ingroup Content
|
||||
*/
|
||||
abstract class XomwAbstractContent implements XomwContent {
|
||||
/**
|
||||
* Name of the content model this Content Object represents.
|
||||
* Use with CONTENT_MODEL_XXX constants
|
||||
*
|
||||
* @since 1.21
|
||||
*
|
||||
* @var String $model_id
|
||||
*/
|
||||
private int model_id;
|
||||
|
||||
/**
|
||||
* @param String $modelId
|
||||
*
|
||||
* @since 1.21
|
||||
*/
|
||||
public XomwAbstractContent(int modelId) {
|
||||
this.model_id = modelId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.21
|
||||
*
|
||||
* @see Content::getModel
|
||||
*/
|
||||
public int getModel() {
|
||||
return this.model_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.21
|
||||
*
|
||||
* @param String $modelId The model to check
|
||||
*
|
||||
* @throws MWException If the provided ID is not the ID of the content model supported by this
|
||||
* Content Object.
|
||||
*/
|
||||
protected void checkModelID(int modelId) {
|
||||
if (modelId != this.model_id) {
|
||||
throw new XomwMWException(
|
||||
"Bad content model: " +
|
||||
"expected " + this.model_id +
|
||||
"but got " + modelId
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.21
|
||||
*
|
||||
* @see Content::getContentHandler
|
||||
*/
|
||||
public XomwContentHandler getContentHandler() {
|
||||
return XomwContentHandler.getForContent(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.21
|
||||
*
|
||||
* @see Content::getDefaultFormat
|
||||
*/
|
||||
public String getDefaultFormat() {
|
||||
return this.getContentHandler().getDefaultFormat();
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.21
|
||||
*
|
||||
* @see Content::getSupportedFormats
|
||||
*/
|
||||
public String[] getSupportedFormats() {
|
||||
return this.getContentHandler().getSupportedFormats();
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.21
|
||||
*
|
||||
* @param String $format
|
||||
*
|
||||
* @return boolean
|
||||
*
|
||||
* @see Content::isSupportedFormat
|
||||
*/
|
||||
public boolean isSupportedFormat(String format) {
|
||||
if (format == null) {
|
||||
return true; // this means "use the default"
|
||||
}
|
||||
|
||||
return this.getContentHandler().isSupportedFormat(format);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @since 1.21
|
||||
// *
|
||||
@ -123,11 +124,11 @@ package gplx.xowa.mediawiki.includes.content; import gplx.*; import gplx.xowa.*;
|
||||
// *
|
||||
// * @throws MWException If the format is not supported by this content handler.
|
||||
// */
|
||||
// protected function checkFormat( $format ) {
|
||||
// if ( !$this->isSupportedFormat( $format ) ) {
|
||||
// protected function checkFormat($format) {
|
||||
// if (!this.isSupportedFormat($format)) {
|
||||
// throw new MWException(
|
||||
// "Format $format is not supported for content model " .
|
||||
// $this->getModel()
|
||||
// this.getModel()
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
@ -141,8 +142,8 @@ package gplx.xowa.mediawiki.includes.content; import gplx.*; import gplx.xowa.*;
|
||||
// *
|
||||
// * @see Content::serialize
|
||||
// */
|
||||
// public function serialize( $format = null ) {
|
||||
// return $this->getContentHandler()->serializeContent( $this, $format );
|
||||
// public function serialize($format = null) {
|
||||
// return this.getContentHandler().serializeContent($this, $format);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
@ -153,7 +154,7 @@ package gplx.xowa.mediawiki.includes.content; import gplx.*; import gplx.xowa.*;
|
||||
// * @see Content::isEmpty
|
||||
// */
|
||||
// public function isEmpty() {
|
||||
// return $this->getSize() === 0;
|
||||
// return this.getSize() === 0;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
@ -178,20 +179,20 @@ package gplx.xowa.mediawiki.includes.content; import gplx.*; import gplx.xowa.*;
|
||||
// *
|
||||
// * @see Content::equals
|
||||
// */
|
||||
// public function equals( Content $that = null ) {
|
||||
// if ( is_null( $that ) ) {
|
||||
// public function equals(Content $that = null) {
|
||||
// if (is_null($that)) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// if ( $that === $this ) {
|
||||
// if ($that === $this) {
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// if ( $that->getModel() !== $this->getModel() ) {
|
||||
// if ($that.getModel() !== this.getModel()) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// return $this->getNativeData() === $that->getNativeData();
|
||||
// return this.getNativeData() === $that.getNativeData();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
@ -217,18 +218,18 @@ package gplx.xowa.mediawiki.includes.content; import gplx.*; import gplx.xowa.*;
|
||||
// *
|
||||
// * @see Content::getSecondaryDataUpdates()
|
||||
// */
|
||||
// public function getSecondaryDataUpdates( Title $title, Content $old = null,
|
||||
// public function getSecondaryDataUpdates(Title $title, Content $old = null,
|
||||
// $recursive = true, ParserOutput $parserOutput = null
|
||||
// ) {
|
||||
// if ( $parserOutput === null ) {
|
||||
// $parserOutput = $this->getParserOutput( $title, null, null, false );
|
||||
// if ($parserOutput === null) {
|
||||
// $parserOutput = this.getParserOutput($title, null, null, false);
|
||||
// }
|
||||
//
|
||||
// $updates = [
|
||||
// new LinksUpdate( $title, $parserOutput, $recursive )
|
||||
// new LinksUpdate($title, $parserOutput, $recursive)
|
||||
// ];
|
||||
//
|
||||
// Hooks::run( 'SecondaryDataUpdates', [ $title, $old, $recursive, $parserOutput, &$updates ] );
|
||||
// Hooks::run('SecondaryDataUpdates', [ $title, $old, $recursive, $parserOutput, &$updates ]);
|
||||
//
|
||||
// return $updates;
|
||||
// }
|
||||
@ -242,22 +243,22 @@ package gplx.xowa.mediawiki.includes.content; import gplx.*; import gplx.xowa.*;
|
||||
// */
|
||||
// public function getRedirectChain() {
|
||||
// global $wgMaxRedirects;
|
||||
// $title = $this->getRedirectTarget();
|
||||
// if ( is_null( $title ) ) {
|
||||
// $title = this.getRedirectTarget();
|
||||
// if (is_null($title)) {
|
||||
// return null;
|
||||
// }
|
||||
// // recursive check to follow double redirects
|
||||
// $recurse = $wgMaxRedirects;
|
||||
// $titles = [ $title ];
|
||||
// while ( --$recurse > 0 ) {
|
||||
// if ( $title->isRedirect() ) {
|
||||
// $page = WikiPage::factory( $title );
|
||||
// $newtitle = $page->getRedirectTarget();
|
||||
// while (--$recurse > 0) {
|
||||
// if ($title.isRedirect()) {
|
||||
// $page = WikiPage::factory($title);
|
||||
// $newtitle = $page.getRedirectTarget();
|
||||
// } else {
|
||||
// break;
|
||||
// }
|
||||
// // Redirects to some special pages are not permitted
|
||||
// if ( $newtitle instanceof Title && $newtitle->isValidRedirectTarget() ) {
|
||||
// if ($newtitle instanceof Title && $newtitle.isValidRedirectTarget()) {
|
||||
// // The new title passes the checks, so make that our current
|
||||
// // title so that further recursion can be checked
|
||||
// $title = $newtitle;
|
||||
@ -293,9 +294,9 @@ package gplx.xowa.mediawiki.includes.content; import gplx.*; import gplx.xowa.*;
|
||||
// * @see Content::getUltimateRedirectTarget
|
||||
// */
|
||||
// public function getUltimateRedirectTarget() {
|
||||
// $titles = $this->getRedirectChain();
|
||||
// $titles = this.getRedirectChain();
|
||||
//
|
||||
// return $titles ? array_pop( $titles ) : null;
|
||||
// return $titles ? array_pop($titles) : null;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
@ -306,7 +307,7 @@ package gplx.xowa.mediawiki.includes.content; import gplx.*; import gplx.xowa.*;
|
||||
// * @see Content::isRedirect
|
||||
// */
|
||||
// public function isRedirect() {
|
||||
// return $this->getRedirectTarget() !== null;
|
||||
// return this.getRedirectTarget() !== null;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
@ -321,7 +322,7 @@ package gplx.xowa.mediawiki.includes.content; import gplx.*; import gplx.xowa.*;
|
||||
// *
|
||||
// * @see Content::updateRedirect
|
||||
// */
|
||||
// public function updateRedirect( Title $target ) {
|
||||
// public function updateRedirect(Title $target) {
|
||||
// return $this;
|
||||
// }
|
||||
//
|
||||
@ -332,7 +333,7 @@ package gplx.xowa.mediawiki.includes.content; import gplx.*; import gplx.xowa.*;
|
||||
// *
|
||||
// * @see Content::getSection
|
||||
// */
|
||||
// public function getSection( $sectionId ) {
|
||||
// public function getSection($sectionId) {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
@ -343,7 +344,7 @@ package gplx.xowa.mediawiki.includes.content; import gplx.*; import gplx.xowa.*;
|
||||
// *
|
||||
// * @see Content::replaceSection
|
||||
// */
|
||||
// public function replaceSection( $sectionId, Content $with, $sectionTitle = '' ) {
|
||||
// public function replaceSection($sectionId, Content $with, $sectionTitle = '') {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
@ -354,7 +355,7 @@ package gplx.xowa.mediawiki.includes.content; import gplx.*; import gplx.xowa.*;
|
||||
// *
|
||||
// * @see Content::preSaveTransform
|
||||
// */
|
||||
// public function preSaveTransform( Title $title, User $user, ParserOptions $popts ) {
|
||||
// public function preSaveTransform(Title $title, User $user, ParserOptions $popts) {
|
||||
// return $this;
|
||||
// }
|
||||
//
|
||||
@ -365,7 +366,7 @@ package gplx.xowa.mediawiki.includes.content; import gplx.*; import gplx.xowa.*;
|
||||
// *
|
||||
// * @see Content::addSectionHeader
|
||||
// */
|
||||
// public function addSectionHeader( $header ) {
|
||||
// public function addSectionHeader($header) {
|
||||
// return $this;
|
||||
// }
|
||||
//
|
||||
@ -376,7 +377,7 @@ package gplx.xowa.mediawiki.includes.content; import gplx.*; import gplx.xowa.*;
|
||||
// *
|
||||
// * @see Content::preloadTransform
|
||||
// */
|
||||
// public function preloadTransform( Title $title, ParserOptions $popts, $params = [] ) {
|
||||
// public function preloadTransform(Title $title, ParserOptions $popts, $params = []) {
|
||||
// return $this;
|
||||
// }
|
||||
//
|
||||
@ -387,11 +388,11 @@ package gplx.xowa.mediawiki.includes.content; import gplx.*; import gplx.xowa.*;
|
||||
// *
|
||||
// * @see Content::prepareSave
|
||||
// */
|
||||
// public function prepareSave( WikiPage $page, $flags, $parentRevId, User $user ) {
|
||||
// if ( $this->isValid() ) {
|
||||
// public function prepareSave(WikiPage $page, $flags, $parentRevId, User $user) {
|
||||
// if (this.isValid()) {
|
||||
// return Status::newGood();
|
||||
// } else {
|
||||
// return Status::newFatal( "invalid-content-data" );
|
||||
// return Status::newFatal("invalid-content-data");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
@ -405,9 +406,9 @@ package gplx.xowa.mediawiki.includes.content; import gplx.*; import gplx.xowa.*;
|
||||
// *
|
||||
// * @see Content::getDeletionUpdates
|
||||
// */
|
||||
// public function getDeletionUpdates( WikiPage $page, ParserOutput $parserOutput = null ) {
|
||||
// public function getDeletionUpdates(WikiPage $page, ParserOutput $parserOutput = null) {
|
||||
// return [
|
||||
// new LinksDeletionUpdate( $page ),
|
||||
// new LinksDeletionUpdate($page),
|
||||
// ];
|
||||
// }
|
||||
//
|
||||
@ -423,7 +424,7 @@ package gplx.xowa.mediawiki.includes.content; import gplx.*; import gplx.xowa.*;
|
||||
// *
|
||||
// * @see Content::matchMagicWord
|
||||
// */
|
||||
// public function matchMagicWord( MagicWord $word ) {
|
||||
// public function matchMagicWord(MagicWord $word) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
@ -438,16 +439,16 @@ package gplx.xowa.mediawiki.includes.content; import gplx.*; import gplx.xowa.*;
|
||||
// *
|
||||
// * @see Content::convert()
|
||||
// */
|
||||
// public function convert( $toModel, $lossy = '' ) {
|
||||
// if ( $this->getModel() === $toModel ) {
|
||||
// public function convert($toModel, $lossy = '') {
|
||||
// if (this.getModel() === $toModel) {
|
||||
// // nothing to do, shorten out.
|
||||
// return $this;
|
||||
// }
|
||||
//
|
||||
// $lossy = ( $lossy === 'lossy' ); // String flag, convert to boolean for convenience
|
||||
// $lossy = ($lossy === 'lossy'); // String flag, convert to boolean for convenience
|
||||
// $result = false;
|
||||
//
|
||||
// Hooks::run( 'ConvertContent', [ $this, $toModel, $lossy, &$result ] );
|
||||
// Hooks::run('ConvertContent', [ $this, $toModel, $lossy, &$result ]);
|
||||
//
|
||||
// return $result;
|
||||
// }
|
||||
@ -472,27 +473,27 @@ package gplx.xowa.mediawiki.includes.content; import gplx.*; import gplx.xowa.*;
|
||||
// *
|
||||
// * @return ParserOutput Containing information derived from this content.
|
||||
// */
|
||||
// public function getParserOutput( Title $title, $revId = null,
|
||||
// public function getParserOutput(Title $title, $revId = null,
|
||||
// ParserOptions $options = null, $generateHtml = true
|
||||
// ) {
|
||||
// if ( $options === null ) {
|
||||
// $options = $this->getContentHandler()->makeParserOptions( 'canonical' );
|
||||
// if ($options === null) {
|
||||
// $options = this.getContentHandler().makeParserOptions('canonical');
|
||||
// }
|
||||
//
|
||||
// $po = new ParserOutput();
|
||||
//
|
||||
// if ( Hooks::run( 'ContentGetParserOutput',
|
||||
// [ $this, $title, $revId, $options, $generateHtml, &$po ] ) ) {
|
||||
// if (Hooks::run('ContentGetParserOutput',
|
||||
// [ $this, $title, $revId, $options, $generateHtml, &$po ])) {
|
||||
//
|
||||
// // Save and restore the old value, just in case something is reusing
|
||||
// // the ParserOptions Object in some weird way.
|
||||
// $oldRedir = $options->getRedirectTarget();
|
||||
// $options->setRedirectTarget( $this->getRedirectTarget() );
|
||||
// $this->fillParserOutput( $title, $revId, $options, $generateHtml, $po );
|
||||
// $options->setRedirectTarget( $oldRedir );
|
||||
// $oldRedir = $options.getRedirectTarget();
|
||||
// $options.setRedirectTarget(this.getRedirectTarget());
|
||||
// this.fillParserOutput($title, $revId, $options, $generateHtml, $po);
|
||||
// $options.setRedirectTarget($oldRedir);
|
||||
// }
|
||||
//
|
||||
// Hooks::run( 'ContentAlterParserOutput', [ $this, $title, $po ] );
|
||||
// Hooks::run('ContentAlterParserOutput', [ $this, $title, $po ]);
|
||||
//
|
||||
// return $po;
|
||||
// }
|
||||
@ -517,10 +518,66 @@ package gplx.xowa.mediawiki.includes.content; import gplx.*; import gplx.xowa.*;
|
||||
// *
|
||||
// * @throws MWException
|
||||
// */
|
||||
// protected function fillParserOutput( Title $title, $revId,
|
||||
// protected function fillParserOutput(Title $title, $revId,
|
||||
// ParserOptions $options, $generateHtml, ParserOutput &$output
|
||||
// ) {
|
||||
// // Don't make abstract, so subclasses that override getParserOutput() directly don't fail.
|
||||
// throw new MWException( 'Subclasses of AbstractContent must override fillParserOutput!' );
|
||||
// throw new MWException('Subclasses of AbstractContent must override fillParserOutput!');
|
||||
// }
|
||||
// }
|
||||
public abstract byte[] getTextForSearchIndex();
|
||||
|
||||
public abstract byte[] getWikitextForTransclusion();
|
||||
|
||||
public abstract byte[] getTextForSummary(int maxLength);
|
||||
|
||||
public abstract Object getNativeData();
|
||||
|
||||
public abstract int getSize();
|
||||
|
||||
public abstract byte[] serialize(byte[] format);
|
||||
|
||||
public abstract boolean isEmpty();
|
||||
|
||||
public abstract boolean isValid();
|
||||
|
||||
public abstract boolean equals(XomwContent that);
|
||||
|
||||
public abstract XomwContent copy();
|
||||
|
||||
public abstract boolean isCountable(boolean hasLinks);
|
||||
|
||||
public abstract XomwParserOutput getParserOutput(XomwTitle title, int revId,
|
||||
XomwParserOptions options, boolean generateHtml);
|
||||
|
||||
public abstract Object getSecondaryDataUpdates(XomwTitle title, XomwContent old,
|
||||
boolean recursive, XomwParserOutput parserOutput);
|
||||
|
||||
public abstract XomwTitle[] getRedirectChain();
|
||||
|
||||
public abstract XomwTitle getRedirectTarget();
|
||||
|
||||
public abstract XomwTitle getUltimateRedirectTarget();
|
||||
|
||||
public abstract boolean isRedirect();
|
||||
|
||||
public abstract XomwContent updateRedirect(XomwTitle target);
|
||||
|
||||
public abstract XomwContent getSection(String sectionId);
|
||||
|
||||
public abstract byte[] replaceSection(String sectionId, XomwContent with, String sectionTitle);
|
||||
|
||||
public abstract XomwContent preSaveTransform(XomwTitle title, Object user, XomwParserOptions parserOptions);
|
||||
|
||||
public abstract XomwContent addSectionHeader(byte[] header);
|
||||
|
||||
public abstract XomwContent preloadTransform(XomwTitle title, XomwParserOptions parserOptions, Object[] ary);
|
||||
|
||||
public abstract Object prepareSave(Object page, int flags, int parentRevId, Object user);
|
||||
|
||||
public abstract Object getDeletionUpdates(Object page,
|
||||
XomwParserOutput parserOutput);
|
||||
|
||||
public abstract boolean matchMagicWord(XomwMagicWord word);
|
||||
|
||||
public abstract XomwContent convert(byte[] toModel, byte[] lossy);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,150 @@
|
||||
/*
|
||||
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.content; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
/**
|
||||
* Base content handler implementation for flat text contents.
|
||||
*
|
||||
* @ingroup Content
|
||||
*/
|
||||
class XomwTextContentHandler extends XomwContentHandler {
|
||||
public XomwTextContentHandler() {super(XomwDefaultSettings.CONTENT_MODEL_TEXT, XomwDefines.CONTENT_FORMAT_TEXT);
|
||||
}
|
||||
public XomwTextContentHandler(int modelId, String... formats) {super(modelId, formats);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Returns the content's text as-is.
|
||||
// *
|
||||
// * @param Content $content
|
||||
// * @param String $format The serialization format to check
|
||||
// *
|
||||
// * @return mixed
|
||||
// */
|
||||
// public function serializeContent( Content $content, $format = null ) {
|
||||
// $this->checkFormat( $format );
|
||||
//
|
||||
// return $content->getNativeData();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Attempts to merge differences between three versions. Returns a new
|
||||
// * Content Object for a clean merge and false for failure or a conflict.
|
||||
// *
|
||||
// * All three Content objects passed as parameters must have the same
|
||||
// * content model.
|
||||
// *
|
||||
// * This text-based implementation uses wfMerge().
|
||||
// *
|
||||
// * @param Content $oldContent The page's previous content.
|
||||
// * @param Content $myContent One of the page's conflicting contents.
|
||||
// * @param Content $yourContent One of the page's conflicting contents.
|
||||
// *
|
||||
// * @return Content|boolean
|
||||
// */
|
||||
// public function merge3( Content $oldContent, Content $myContent, Content $yourContent ) {
|
||||
// $this->checkModelID( $oldContent->getModel() );
|
||||
// $this->checkModelID( $myContent->getModel() );
|
||||
// $this->checkModelID( $yourContent->getModel() );
|
||||
//
|
||||
// $format = $this->getDefaultFormat();
|
||||
//
|
||||
// $old = $this->serializeContent( $oldContent, $format );
|
||||
// $mine = $this->serializeContent( $myContent, $format );
|
||||
// $yours = $this->serializeContent( $yourContent, $format );
|
||||
//
|
||||
// $ok = wfMerge( $old, $mine, $yours, $result );
|
||||
//
|
||||
// if ( !$ok ) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// if ( !$result ) {
|
||||
// return $this->makeEmptyContent();
|
||||
// }
|
||||
//
|
||||
// $mergedContent = $this->unserializeContent( $result, $format );
|
||||
//
|
||||
// return $mergedContent;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns the name of the associated Content class, to
|
||||
// * be used when creating new objects. Override expected
|
||||
// * by subclasses.
|
||||
// *
|
||||
// * @since 1.24
|
||||
// *
|
||||
// * @return String
|
||||
// */
|
||||
// protected function getContentClass() {
|
||||
// return TextContent::class;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Unserializes a Content Object of the type supported by this ContentHandler.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param String $text Serialized form of the content
|
||||
// * @param String $format The format used for serialization
|
||||
// *
|
||||
// * @return Content The TextContent Object wrapping $text
|
||||
// */
|
||||
// public function unserializeContent( $text, $format = null ) {
|
||||
// $this->checkFormat( $format );
|
||||
//
|
||||
// $class = $this->getContentClass();
|
||||
// return new $class( $text );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Creates an empty TextContent Object.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @return Content A new TextContent Object with empty text.
|
||||
// */
|
||||
// public function makeEmptyContent() {
|
||||
// $class = $this->getContentClass();
|
||||
// return new $class( '' );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @see ContentHandler::supportsDirectEditing
|
||||
// *
|
||||
// * @return boolean Default is true for TextContent and derivatives.
|
||||
// */
|
||||
// public function supportsDirectEditing() {
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// public function getFieldsForSearchIndex( SearchEngine $engine ) {
|
||||
// $fields = parent::getFieldsForSearchIndex( $engine );
|
||||
// $fields['language'] =
|
||||
// $engine->makeSearchFieldMapping( 'language', SearchIndexField::INDEX_TYPE_KEYWORD );
|
||||
//
|
||||
// return $fields;
|
||||
// }
|
||||
//
|
||||
// public function getDataForSearchIndex( WikiPage $page, ParserOutput $output,
|
||||
// SearchEngine $engine ) {
|
||||
// $fields = parent::getDataForSearchIndex( $page, $output, $engine );
|
||||
// $fields['language'] =
|
||||
// $this->getPageLanguage( $page->getTitle(), $page->getContent() )->getCode();
|
||||
// return $fields;
|
||||
// }
|
||||
|
||||
}
|
@ -0,0 +1,148 @@
|
||||
/*
|
||||
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.content; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
/**
|
||||
* Content handler for wiki text pages.
|
||||
*
|
||||
* @ingroup Content
|
||||
*/
|
||||
class XomwWikitextContentHandler extends XomwTextContentHandler {
|
||||
public XomwWikitextContentHandler() {super(XomwDefaultSettings.CONTENT_MODEL_WIKITEXT, XomwDefines.CONTENT_FORMAT_WIKITEXT);
|
||||
}
|
||||
|
||||
// protected function getContentClass() {
|
||||
// return WikitextContent::class;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns a WikitextContent Object representing a redirect to the given destination page.
|
||||
// *
|
||||
// * @param Title $destination The page to redirect to.
|
||||
// * @param String $text Text to include in the redirect, if possible.
|
||||
// *
|
||||
// * @return Content
|
||||
// *
|
||||
// * @see ContentHandler::makeRedirectContent
|
||||
// */
|
||||
// public function makeRedirectContent( Title $destination, $text = '' ) {
|
||||
// $optionalColon = '';
|
||||
//
|
||||
// if ( $destination->getNamespace() == NS_CATEGORY ) {
|
||||
// $optionalColon = ':';
|
||||
// } else {
|
||||
// $iw = $destination->getInterwiki();
|
||||
// if ( $iw && Language::fetchLanguageName( $iw, null, 'mw' ) ) {
|
||||
// $optionalColon = ':';
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// $mwRedir = MagicWord::get( 'redirect' );
|
||||
// $redirectText = $mwRedir->getSynonym( 0 ) .
|
||||
// ' [[' . $optionalColon . $destination->getFullText() . ']]';
|
||||
//
|
||||
// if ( $text != '' ) {
|
||||
// $redirectText .= "\n" . $text;
|
||||
// }
|
||||
//
|
||||
// $class = $this->getContentClass();
|
||||
// return new $class( $redirectText );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns true because wikitext supports redirects.
|
||||
// *
|
||||
// * @return boolean Always true.
|
||||
// *
|
||||
// * @see ContentHandler::supportsRedirects
|
||||
// */
|
||||
// public function supportsRedirects() {
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns true because wikitext supports sections.
|
||||
// *
|
||||
// * @return boolean Always true.
|
||||
// *
|
||||
// * @see ContentHandler::supportsSections
|
||||
// */
|
||||
// public function supportsSections() {
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns true, because wikitext supports caching using the
|
||||
// * ParserCache mechanism.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @return boolean Always true.
|
||||
// *
|
||||
// * @see ContentHandler::isParserCacheSupported
|
||||
// */
|
||||
// public function isParserCacheSupported() {
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Get file handler
|
||||
// * @return FileContentHandler
|
||||
// */
|
||||
// protected function getFileHandler() {
|
||||
// return new FileContentHandler();
|
||||
// }
|
||||
//
|
||||
// public function getFieldsForSearchIndex( SearchEngine $engine ) {
|
||||
// $fields = parent::getFieldsForSearchIndex( $engine );
|
||||
//
|
||||
// $fields['heading'] =
|
||||
// $engine->makeSearchFieldMapping( 'heading', SearchIndexField::INDEX_TYPE_TEXT );
|
||||
// $fields['heading']->setFlag( SearchIndexField::FLAG_SCORING );
|
||||
//
|
||||
// $fields['auxiliary_text'] =
|
||||
// $engine->makeSearchFieldMapping( 'auxiliary_text', SearchIndexField::INDEX_TYPE_TEXT );
|
||||
//
|
||||
// $fields['opening_text'] =
|
||||
// $engine->makeSearchFieldMapping( 'opening_text', SearchIndexField::INDEX_TYPE_TEXT );
|
||||
// $fields['opening_text']->setFlag( SearchIndexField::FLAG_SCORING |
|
||||
// SearchIndexField::FLAG_NO_HIGHLIGHT );
|
||||
// // Until we have full first-class content handler for files, we invoke it explicitly here
|
||||
// $fields = array_merge( $fields, $this->getFileHandler()->getFieldsForSearchIndex( $engine ) );
|
||||
//
|
||||
// return $fields;
|
||||
// }
|
||||
//
|
||||
// public function getDataForSearchIndex( WikiPage $page, ParserOutput $parserOutput,
|
||||
// SearchEngine $engine ) {
|
||||
// $fields = parent::getDataForSearchIndex( $page, $parserOutput, $engine );
|
||||
//
|
||||
// $structure = new WikiTextStructure( $parserOutput );
|
||||
// $fields['heading'] = $structure->headings();
|
||||
// // text fields
|
||||
// $fields['opening_text'] = $structure->getOpeningText();
|
||||
// $fields['text'] = $structure->getMainText(); // overwrites one from ContentHandler
|
||||
// $fields['auxiliary_text'] = $structure->getAuxiliaryText();
|
||||
// $fields['defaultsort'] = $structure->getDefaultSort();
|
||||
//
|
||||
// // Until we have full first-class content handler for files, we invoke it explicitly here
|
||||
// if ( NS_FILE == $page->getTitle()->getNamespace() ) {
|
||||
// $fields = array_merge( $fields,
|
||||
// $this->getFileHandler()->getDataForSearchIndex( $page, $parserOutput, $engine ) );
|
||||
// }
|
||||
// return $fields;
|
||||
// }
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user