[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/includes/content/ -> ContentHandler.php (summary)

Base class for content handling. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

Author: Daniel Kinzler
File Size: 1173 lines (37 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

MWContentSerializationException:: (35 methods):
  getContentText()
  makeContent()
  getDefaultModelFor()
  getForTitle()
  getForContent()
  getForModelID()
  getLocalizedName()
  getContentModels()
  getAllContentFormats()
  __construct()
  exportTransform()
  importTransform()
  makeRedirectContent()
  getModelID()
  checkModelID()
  getSupportedFormats()
  getDefaultFormat()
  isSupportedFormat()
  checkFormat()
  getActionOverrides()
  createDifferenceEngine()
  getPageLanguage()
  getPageViewLanguage()
  canBeUsedOn()
  getDiffEngineClass()
  merge3()
  getAutosummary()
  getAutoDeleteReason()
  getUndoContent()
  makeParserOptions()
  isParserCacheSupported()
  supportsSections()
  supportsRedirects()
  deprecated()
  runLegacyHooks()


Class: MWContentSerializationException  - X-Ref

Exception representing a failure to serialize or unserialize a content object.

getContentText( Content $content = null )   X-Ref
Convenience function for getting flat text from a Content object. This
should only be used in the context of backwards compatibility with code
that is not yet able to handle Content objects!

If $content is null, this method returns the empty string.

If $content is an instance of TextContent, this method returns the flat
text as returned by $content->getNativeData().

If $content is not a TextContent object, the behavior of this method
depends on the global $wgContentHandlerTextFallback:
- If $wgContentHandlerTextFallback is 'fail' and $content is not a
TextContent object, an MWException is thrown.
- If $wgContentHandlerTextFallback is 'serialize' and $content is not a
TextContent object, $content->serialize() is called to get a string
form of the content.
- If $wgContentHandlerTextFallback is 'ignore' and $content is not a
TextContent object, this method returns null.
- otherwise, the behavior is undefined.

param: Content $content
return: string|null Textual form of the content, if available.

makeContent( $text, Title $title = null,$modelId = null, $format = null )   X-Ref
Convenience function for creating a Content object from a given textual
representation.

$text will be deserialized into a Content object of the model specified
by $modelId (or, if that is not given, $title->getContentModel()) using
the given format.

param: string $text The textual representation, will be
param: Title $title The title of the page this text belongs to.
param: string $modelId The model to deserialize to. If not provided,
param: string $format The format to use for deserialization. If not
return: Content A Content object representing the text.

getDefaultModelFor( Title $title )   X-Ref
Returns the name of the default content model to be used for the page
with the given title.

Note: There should rarely be need to call this method directly.
To determine the actual content model for a given page, use
Title::getContentModel().

Which model is to be used by default for the page is determined based
on several factors:
- The global setting $wgNamespaceContentModels specifies a content model
per namespace.
- The hook ContentHandlerDefaultModelFor may be used to override the page's default
model.
- Pages in NS_MEDIAWIKI and NS_USER default to the CSS or JavaScript
model if they end in .js or .css, respectively.
- Pages in NS_MEDIAWIKI default to the wikitext model otherwise.
- The hook TitleIsCssOrJsPage may be used to force a page to use the CSS
or JavaScript model. This is a compatibility feature. The ContentHandlerDefaultModelFor
hook should be used instead if possible.
- The hook TitleIsWikitextPage may be used to force a page to use the
wikitext model. This is a compatibility feature. The ContentHandlerDefaultModelFor
hook should be used instead if possible.

If none of the above applies, the wikitext model is used.

Note: this is used by, and may thus not use, Title::getContentModel()

param: Title $title
return: string Default model name for the page given by $title

getForTitle( Title $title )   X-Ref
Returns the appropriate ContentHandler singleton for the given title.

param: Title $title
return: ContentHandler

getForContent( Content $content )   X-Ref
Returns the appropriate ContentHandler singleton for the given Content
object.

param: Content $content
return: ContentHandler

getForModelID( $modelId )   X-Ref
Returns the ContentHandler singleton for the given model ID. Use the
CONTENT_MODEL_XXX constants to identify the desired content model.

ContentHandler singletons are taken from the global $wgContentHandlers
array. Keys in that array are model names, the values are either
ContentHandler singleton objects, or strings specifying the appropriate
subclass of ContentHandler.

If a class name is encountered when looking up the singleton for a given
model name, the class is instantiated and the class name is replaced by
the resulting singleton in $wgContentHandlers.

If no ContentHandler is defined for the desired $modelId, the
ContentHandler may be provided by the ContentHandlerForModelID hook.
If no ContentHandler can be determined, an MWException is raised.

param: string $modelId The ID of the content model for which to get a
return: ContentHandler The ContentHandler singleton for handling the model given by the ID.

getLocalizedName( $name )   X-Ref
Returns the localized name for a given content model.

Model names are localized using system messages. Message keys
have the form content-model-$name, where $name is getContentModelName( $id ).

param: string $name The content model ID, as given by a CONTENT_MODEL_XXX
return: string The content model's localized name.

getContentModels()   X-Ref
No description

getAllContentFormats()   X-Ref
No description

__construct( $modelId, $formats )   X-Ref
Constructor, initializing the ContentHandler instance with its model ID
and a list of supported formats. Values for the parameters are typically
provided as literals by subclass's constructors.

param: string $modelId (use CONTENT_MODEL_XXX constants).
param: string[] $formats List for supported serialization formats

exportTransform( $blob, $format = null )   X-Ref
Applies transformations on export (returns the blob unchanged per default).
Subclasses may override this to perform transformations such as conversion
of legacy formats or filtering of internal meta-data.

param: string $blob The blob to be exported
param: string|null $format The blob's serialization format
return: string

importTransform( $blob, $format = null )   X-Ref
Apply import transformation (per default, returns $blob unchanged).
This gives subclasses an opportunity to transform data blobs on import.

param: string $blob
param: string|null $format
return: string

makeRedirectContent( Title $destination, $text = '' )   X-Ref
Creates a new Content object that acts as a redirect to the given page,
or null if redirects are not supported by this content model.

This default implementation always returns null. Subclasses supporting redirects
must override this method.

Note that subclasses that override this method to return a Content object
should also override supportsRedirects() to return true.

param: Title $destination The page to redirect to.
param: string $text Text to include in the redirect, if possible.
return: Content Always null.

getModelID()   X-Ref
Returns the model id that identifies the content model this
ContentHandler can handle. Use with the CONTENT_MODEL_XXX constants.

return: string The model ID

checkModelID( $model_id )   X-Ref

param: string $model_id The model to check

getSupportedFormats()   X-Ref
Returns a list of serialization formats supported by the
serializeContent() and unserializeContent() methods of this
ContentHandler.

return: string[] List of serialization formats as MIME type like strings

getDefaultFormat()   X-Ref
The format used for serialization/deserialization by default by this
ContentHandler.

This default implementation will return the first element of the array
of formats that was passed to the constructor.

return: string The name of the default serialization format as a MIME type

isSupportedFormat( $format )   X-Ref
Returns true if $format is a serialization format supported by this
ContentHandler, and false otherwise.

Note that if $format is null, this method always returns true, because
null means "use the default format".

param: string $format The serialization format to check
return: bool

checkFormat( $format )   X-Ref
Convenient for checking whether a format provided as a parameter is actually supported.

param: string $format The serialization format to check

getActionOverrides()   X-Ref
Returns overrides for action handlers.
Classes listed here will be used instead of the default one when
(and only when) $wgActions[$action] === true. This allows subclasses
to override the default action handlers.

return: array Always an empty array.

createDifferenceEngine( IContextSource $context, $old = 0, $new = 0,$rcid = 0, $refreshCache = false, $unhide = false )   X-Ref
Factory for creating an appropriate DifferenceEngine for this content model.

param: IContextSource $context Context to use, anything else will be ignored.
param: int $old Revision ID we want to show and diff with.
param: int|string $new Either a revision ID or one of the strings 'cur', 'prev' or 'next'.
param: int $rcid FIXME: Deprecated, no longer used. Defaults to 0.
param: bool $refreshCache If set, refreshes the diff cache. Defaults to false.
param: bool $unhide If set, allow viewing deleted revs. Defaults to false.
return: DifferenceEngine

getPageLanguage( Title $title, Content $content = null )   X-Ref
Get the language in which the content of the given page is written.

This default implementation just returns $wgContLang (except for pages
in the MediaWiki namespace)

Note that the pages language is not cacheable, since it may in some
cases depend on user settings.

Also note that the page language may or may not depend on the actual content of the page,
that is, this method may load the content in order to determine the language.

param: Title $title The page to determine the language for.
param: Content $content The page's content, if you have it handy, to avoid reloading it.
return: Language The page's language

getPageViewLanguage( Title $title, Content $content = null )   X-Ref
Get the language in which the content of this page is written when
viewed by user. Defaults to $this->getPageLanguage(), but if the user
specified a preferred variant, the variant will be used.

This default implementation just returns $this->getPageLanguage( $title, $content ) unless
the user specified a preferred variant.

Note that the pages view language is not cacheable, since it depends on user settings.

Also note that the page language may or may not depend on the actual content of the page,
that is, this method may load the content in order to determine the language.

param: Title $title The page to determine the language for.
param: Content $content The page's content, if you have it handy, to avoid reloading it.
return: Language The page's language for viewing

canBeUsedOn( Title $title )   X-Ref
Determines whether the content type handled by this ContentHandler
can be used on the given page.

This default implementation always returns true.
Subclasses may override this to restrict the use of this content model to specific locations,
typically based on the namespace or some other aspect of the title, such as a special suffix
(e.g. ".svg" for SVG content).

param: Title $title The page's title.
return: bool True if content of this kind can be used on the given page, false otherwise.

getDiffEngineClass()   X-Ref
Returns the name of the diff engine to use.

return: string

merge3( Content $oldContent, Content $myContent, Content $yourContent )   X-Ref
Attempts to merge differences between three versions. Returns a new
Content object for a clean merge and false for failure or a conflict.

This default implementation always returns false.

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|bool Always false.

getAutosummary( Content $oldContent = null, Content $newContent = null,$flags )   X-Ref
Return an applicable auto-summary if one exists for the given edit.

param: Content $oldContent The previous text of the page.
param: Content $newContent The submitted text of the page.
param: int $flags Bit mask: a bit mask of flags submitted for the edit.
return: string An appropriate auto-summary, or an empty string.

getAutoDeleteReason( Title $title, &$hasHistory )   X-Ref
Auto-generates a deletion reason

param: Title $title The page's title
param: bool &$hasHistory Whether the page has a history
return: mixed String containing deletion reason or empty string, or

getUndoContent( Revision $current, Revision $undo, Revision $undoafter )   X-Ref
Get the Content object that needs to be saved in order to undo all revisions
between $undo and $undoafter. Revisions must belong to the same page,
must exist and must not be deleted.

param: Revision $current The current text
param: Revision $undo The revision to undo
param: Revision $undoafter Must be an earlier revision than $undo
return: mixed String on success, false on failure

makeParserOptions( $context )   X-Ref
Get parser options suitable for rendering and caching the article

param: IContextSource|User|string $context One of the following:
return: ParserOptions

isParserCacheSupported()   X-Ref
Returns true for content models that support caching using the
ParserCache mechanism. See WikiPage::isParserCacheUsed().

return: bool Always false.

supportsSections()   X-Ref
Returns true if this content model supports sections.
This default implementation returns false.

Content models that return true here should also implement
Content::getSection, Content::replaceSection, etc. to handle sections..

return: bool Always false.

supportsRedirects()   X-Ref
Returns true if this content model supports redirects.
This default implementation returns false.

Content models that return true here should also implement
ContentHandler::makeRedirectContent to return a Content object.

return: bool Always false.

deprecated( $func, $version, $component = false )   X-Ref
Logs a deprecation warning, visible if $wgDevelopmentWarnings, but only if
self::$enableDeprecationWarnings is set to true.

param: string $func The name of the deprecated function
param: string $version The version since the method is deprecated. Usually 1.21
param: string|bool $component : Component to which the function belongs.

runLegacyHooks( $event, $args = array()   X-Ref
Call a legacy hook that uses text instead of Content objects.
Will log a warning when a matching hook function is registered.
If the textual representation of the content is changed by the
hook function, a new Content object is constructed from the new
text.

param: string $event Event name
param: array $args Parameters passed to hook functions
param: bool $warn Whether to log a warning.
return: bool True if no handler aborted the hook



Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1