MediaWiki
master
|
Public Member Functions | |
__construct ($modelId, $formats) | |
Constructor, initializing the ContentHandler instance with its model ID and a list of supported formats. | |
canBeUsedOn (Title $title) | |
Determines whether the content type handled by this ContentHandler can be used on the given page. | |
createDifferenceEngine (IContextSource $context, $old=0, $new=0, $rcid=0,#FIXME:use everywhere!$refreshCache=false, $unhide=false) | |
Factory for creating an appropriate DifferenceEngine for this content model. | |
getActionOverrides () | |
Returns overrides for action handlers. | |
getAutoDeleteReason (Title $title, &$hasHistory) | |
Auto-generates a deletion reason. | |
getAutosummary (Content $oldContent=null, Content $newContent=null, $flags) | |
Return an applicable auto-summary if one exists for the given edit. | |
getDefaultFormat () | |
The format used for serialization/deserialization by default by this ContentHandler. | |
getModelID () | |
Returns the model id that identifies the content model this ContentHandler can handle. | |
getPageLanguage (Title $title, Content $content=null) | |
Get the language in which the content of the given page is written. | |
getPageViewLanguage (Title $title, Content $content=null) | |
Get the language in which the content of this page is written when viewed by user. | |
getSupportedFormats () | |
Returns a list of serialization formats supported by the serializeContent() and unserializeContent() methods of this ContentHandler. | |
getUndoContent (Revision $current, Revision $undo, Revision $undoafter) | |
Get the Content object that needs to be saved in order to undo all revisions between $undo and $undoafter. | |
isParserCacheSupported () | |
Returns true for content models that support caching using the ParserCache mechanism. | |
isSupportedFormat ($format) | |
Returns true if $format is a serialization format supported by this ContentHandler, and false otherwise. | |
makeEmptyContent () | |
Creates an empty Content object of the type supported by this ContentHandler. | |
makeParserOptions ($context) | |
Get parser options suitable for rendering the primary article wikitext. | |
makeRedirectContent (Title $destination) | |
Creates a new Content object that acts as a redirect to the given page, or null of redirects are not supported by this content model. | |
merge3 (Content $oldContent, Content $myContent, Content $yourContent) | |
Attempts to merge differences between three versions. | |
serializeContent (Content $content, $format=null) | |
Serializes a Content object of the type supported by this ContentHandler. | |
supportsSections () | |
Returns true if this content model supports sections. | |
unserializeContent ($blob, $format=null) | |
Unserializes a Content object of the type supported by this ContentHandler. | |
Static Public Member Functions | |
static | deprecated ($func, $version, $component=false) |
Logs a deprecation warning, visible if $wgDevelopmentWarnings, but only if self::$enableDeprecationWarnings is set to true. | |
static | getAllContentFormats () |
static | getContentModels () |
static | getContentText (Content $content=null) |
Convenience function for getting flat text from a Content object. | |
static | getDefaultModelFor (Title $title) |
Returns the name of the default content model to be used for the page with the given title. | |
static | getForContent (Content $content) |
Returns the appropriate ContentHandler singleton for the given Content object. | |
static | getForModelID ($modelId) |
Returns the ContentHandler singleton for the given model ID. | |
static | getForTitle (Title $title) |
Returns the appropriate ContentHandler singleton for the given title. | |
static | getLocalizedName ($name) |
Returns the localized name for a given content model. | |
static | makeContent ($text, Title $title=null, $modelId=null, $format=null) |
Convenience function for creating a Content object from a given textual representation. | |
static | runLegacyHooks ($event, $args=array(), $warn=null) |
Call a legacy hook that uses text instead of Content objects. | |
Static Public Attributes | |
static | $handlers |
Protected Member Functions | |
checkFormat ($format) | |
Throws an MWException if isSupportedFormat( $format ) is not true. | |
checkModelID ($model_id) | |
Throws an MWException if $model_id is not the ID of the content model supported by this ContentHandler. | |
getDiffEngineClass () | |
Returns the name of the diff engine to use. | |
Protected Attributes | |
$mModelID | |
$mSupportedFormats | |
Static Protected Attributes | |
static | $enableDeprecationWarnings = false |
Switch for enabling deprecation warnings. |
Definition at line 49 of file ContentHandler.php.
ContentHandler::__construct | ( | $ | modelId, |
$ | formats | ||
) |
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.
$modelId | String (use CONTENT_MODEL_XXX constants). |
$formats | array List for supported serialization formats (typically as MIME types) |
Reimplemented in TextContentHandler.
Definition at line 396 of file ContentHandler.php.
ContentHandler::canBeUsedOn | ( | Title $ | title | ) |
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).
Title | $title | the page's title. |
Definition at line 669 of file ContentHandler.php.
ContentHandler::checkFormat | ( | $ | format | ) | [protected] |
Throws an MWException if isSupportedFormat( $format ) is not true.
Convenient for checking whether a format provided as a parameter is actually supported.
$format | string the serialization format to check |
MWException |
Definition at line 542 of file ContentHandler.php.
References getModelID(), and isSupportedFormat().
Referenced by TextContentHandler\serializeContent(), WikitextContentHandler\unserializeContent(), CssContentHandler\unserializeContent(), JavaScriptContentHandler\unserializeContent(), and TextContentHandler\unserializeContent().
ContentHandler::checkModelID | ( | $ | model_id | ) | [protected] |
Throws an MWException if $model_id is not the ID of the content model supported by this ContentHandler.
String | $model_id | The model to check |
MWException |
Definition at line 476 of file ContentHandler.php.
Referenced by getAutoDeleteReason(), getUndoContent(), and TextContentHandler\merge3().
ContentHandler::createDifferenceEngine | ( | IContextSource $ | context, |
$ | old = 0 , |
||
$ | new = 0 , |
||
$ | rcid = 0 , |
||
#FIXME:use everywhere!$ | refreshCache = false , |
||
$ | unhide = false |
||
) |
Factory for creating an appropriate DifferenceEngine for this content model.
$context | IContextSource context to use, anything else will be ignored |
$old | Integer Old ID we want to show and diff with. |
$new | int|string String either 'prev' or 'next'. |
$rcid | Integer ??? FIXME (default 0) |
$refreshCache | boolean If set, refreshes the diff cache |
$unhide | boolean If set, allow viewing deleted revs |
Definition at line 580 of file ContentHandler.php.
References getDiffEngineClass().
static ContentHandler::deprecated | ( | $ | func, |
$ | version, | ||
$ | component = false |
||
) | [static] |
Logs a deprecation warning, visible if $wgDevelopmentWarnings, but only if self::$enableDeprecationWarnings is set to true.
String | $func | The name of the deprecated function |
string | $version | The version since the method is deprecated. Usually 1.21 for ContentHandler related stuff. |
String | bool | $component,: | Component to which the function belongs. If false, it is assumed the function is in MediaWiki core. |
Definition at line 991 of file ContentHandler.php.
References $version, and wfDeprecated().
Referenced by WikiPage\getRawText(), Title\newFromRedirect(), Title\newFromRedirectArray(), Title\newFromRedirectRecurse(), and WikiPage\prepareTextForEdit().
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.
Definition at line 561 of file ContentHandler.php.
References array().
static ContentHandler::getAllContentFormats | ( | ) | [static] |
Definition at line 368 of file ContentHandler.php.
References array(), as, getForModelID(), and global.
Referenced by ApiEditPage\getAllowedParams(), and ApiQueryRevisions\getAllowedParams().
ContentHandler::getAutoDeleteReason | ( | Title $ | title, |
&$ | hasHistory | ||
) |
Auto-generates a deletion reason.
$title | Title: the page's title |
&$hasHistory | Boolean: whether the page has a history |
&$hasHistory is extremely ugly, it's here because WikiPage::getAutoDeleteReason() and Article::getReason() have it / want it.
Definition at line 791 of file ContentHandler.php.
References $res, array(), as, checkModelID(), Revision\DELETED_USER, Title\getArticleID(), Revision\newFromTitle(), wfGetDB(), and wfMessage().
ContentHandler::getAutosummary | ( | Content $ | oldContent = null , |
Content $ | newContent = null , |
||
$ | flags | ||
) |
Return an applicable auto-summary if one exists for the given edit.
$oldContent | Content|null: the previous text of the page. |
$newContent | Content|null: The submitted text of the page. |
$flags | int Bit mask: a bit mask of flags submitted for the edit. |
Definition at line 714 of file ContentHandler.php.
References $flags, $wgContLang, empty, global, text, and wfMessage().
static ContentHandler::getContentModels | ( | ) | [static] |
Definition at line 362 of file ContentHandler.php.
References global.
Referenced by ApiEditPage\getAllowedParams().
static ContentHandler::getContentText | ( | Content $ | content = null | ) | [static] |
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:
$content | Content|null |
MWException | if $content is not an instance of TextContent and $wgContentHandlerTextFallback was set to 'fail'. |
Definition at line 88 of file ContentHandler.php.
References global, and wfDebugLog().
Referenced by EditPageTest\assertEdit(), ContentHandlerTest\testGetContentText_NonTextContent(), ContentHandlerTest\testGetContentText_Null(), and ContentHandlerTest\testGetContentText_TextContent().
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.
Definition at line 508 of file ContentHandler.php.
Referenced by TextContentHandler\merge3().
static ContentHandler::getDefaultModelFor | ( | Title $ | title | ) | [static] |
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:
If none of the above applies, the wikitext model is used.
Note: this is used by, and may thus not use, Title::getContentModel()
$title | Title |
Definition at line 187 of file ContentHandler.php.
References $ext, array(), empty, Title\getNamespace(), Title\getText(), global, and wfRunHooks().
Referenced by Title\getContentModel(), ContentHandlerTest\testGetDefaultModelFor(), and WikiPageTest\testIsCountable().
ContentHandler::getDiffEngineClass | ( | ) | [protected] |
Returns the name of the diff engine to use.
Definition at line 680 of file ContentHandler.php.
Referenced by createDifferenceEngine().
static ContentHandler::getForContent | ( | Content $ | content | ) | [static] |
Returns the appropriate ContentHandler singleton for the given Content object.
$content | Content |
Definition at line 272 of file ContentHandler.php.
References getForModelID(), and Content\getModel().
static ContentHandler::getForModelID | ( | $ | modelId | ) | [static] |
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.
$modelId | String The ID of the content model for which to get a handler. Use CONTENT_MODEL_XXX constants. |
MWException | if no handler is known for $modelId. |
Definition at line 307 of file ContentHandler.php.
References $handlers, array(), empty, global, wfDebugLog(), and wfRunHooks().
Referenced by EditPage\__construct(), TextContent\convert(), ApiEditPage\execute(), ApiQueryRevisions\extractRowInfo(), getAllContentFormats(), getForContent(), getForTitle(), makeContent(), WikitextContentHandlerTest\setUp(), and EditPage\showConflict().
static ContentHandler::getForTitle | ( | Title $ | title | ) | [static] |
Returns the appropriate ContentHandler singleton for the given title.
$title | Title |
Definition at line 258 of file ContentHandler.php.
References Title\getContentModel(), and getForModelID().
Referenced by CleanupSpam\cleanupArticle(), FeedUtils\formatDiffRow(), Title\getPageLanguage(), Title\getPageViewLanguage(), EditPage\importFormData(), SpecialMergeHistory\merge(), Title\moveToInternal(), ContentHandlerTest\testGetForTitle(), and ContentHandlerTest\testGetPageLanguage().
static ContentHandler::getLocalizedName | ( | $ | name | ) | [static] |
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 ).
$name | String The content model ID, as given by a CONTENT_MODEL_XXX constant or returned by Revision::getContentModel(). |
MWException | if the model id isn't known. |
Definition at line 354 of file ContentHandler.php.
References $name, and wfMessage().
Referenced by Title\isValidMoveOperation(), and ContentHandlerTest\testGetLocalizedName().
Returns the model id that identifies the content model this ContentHandler can handle.
Use with the CONTENT_MODEL_XXX constants.
Definition at line 462 of file ContentHandler.php.
Referenced by checkFormat().
ContentHandler::getPageLanguage | ( | Title $ | title, |
Content $ | content = null |
||
) |
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.
Title | $title | the page to determine the language for. |
Content | null | $content | the page's content, if you have it handy, to avoid reloading it. |
Reimplemented in JavaScriptContentHandler, and CssContentHandler.
Definition at line 607 of file ContentHandler.php.
References $wgContLang, $wgLang, array(), Title\getNamespace(), Title\getText(), global, list, MessageCache\singleton(), wfGetLangObj(), and wfRunHooks().
Referenced by getPageViewLanguage().
ContentHandler::getPageViewLanguage | ( | Title $ | title, |
Content $ | content = null |
||
) |
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.
Title | $title | the page to determine the language for. |
Content | null | $content | the page's content, if you have it handy, to avoid reloading it. |
Reimplemented in JavaScriptContentHandler, and CssContentHandler.
Definition at line 641 of file ContentHandler.php.
References Language\factory(), Title\getNamespace(), and getPageLanguage().
Returns a list of serialization formats supported by the serializeContent() and unserializeContent() methods of this ContentHandler.
Definition at line 493 of file ContentHandler.php.
ContentHandler::getUndoContent | ( | Revision $ | current, |
Revision $ | undo, | ||
Revision $ | undoafter | ||
) |
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.
$current | Revision The current text |
$undo | Revision The revision to undo |
$undoafter | Revision Must be an earlier revision than $undo |
Definition at line 896 of file ContentHandler.php.
References checkModelID(), empty, Revision\getContent(), and merge3().
Returns true for content models that support caching using the ParserCache mechanism.
See WikiPage::isParserCacheUsed().
Reimplemented in WikitextContentHandler.
Definition at line 963 of file ContentHandler.php.
ContentHandler::isSupportedFormat | ( | $ | format | ) |
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".
$format | string the serialization format to check |
Definition at line 524 of file ContentHandler.php.
Referenced by checkFormat().
static ContentHandler::makeContent | ( | $ | text, |
Title $ | title = null , |
||
$ | modelId = null , |
||
$ | format = null |
||
) | [static] |
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.
$text | string the textual representation, will be unserialized to create the Content object |
$title | null|Title the title of the page this text belongs to. Required if $modelId is not provided. |
$modelId | null|string the model to deserialize to. If not provided, $title->getContentModel() is used. |
$format | null|string the format to use for deserialization. If not given, the model's default format is used. |
MWException | if $model or $format is not supported or if $text can not be unserialized using $format. |
Definition at line 139 of file ContentHandler.php.
References $title, and getForModelID().
Referenced by PoolWorkArticleView\__construct(), EditPageTest\assertEdit(), WikiPageTest\createPage(), RevisionStorageTest\createPage(), ApiEditPage\execute(), ImportSiteScripts\execute(), EditCLI\execute(), ApiQueryRevisions\extractRowInfo(), SearchEngineTest\insertPage(), Title\newFromRedirect(), Title\newFromRedirectArray(), Title\newFromRedirectRecurse(), RevisionTest\newTestRevision(), WikiPage\prepareTextForEdit(), RevisionTest\testConstructWithContent(), TextContentTest\testDeletionUpdates(), WikiPageTest\testDoEditContent(), WikiPageTest\testDoQuickEditContent(), TextContentTest\testGetParserOutput(), WikitextContentTest\testGetSecondaryDataUpdates(), and ContentHandlerTest\testMakeContent().
ContentHandler::makeEmptyContent | ( | ) | [abstract] |
Creates an empty Content object of the type supported by this ContentHandler.
Reimplemented in RevisionTestModifyableContentHandler, DummyContentHandlerForTesting, TextContentHandler, WikitextContentHandler, JavaScriptContentHandler, and CssContentHandler.
ContentHandler::makeParserOptions | ( | $ | context | ) |
Get parser options suitable for rendering the primary article wikitext.
IContextSource | User | string | $context | One of the following:
|
IContextSource | User | string | $context |
MWException |
Definition at line 936 of file ContentHandler.php.
References $options, $wgContLang, global, ParserOptions\newFromContext(), ParserOptions\newFromUser(), and ParserOptions\newFromUserAndLang().
ContentHandler::makeRedirectContent | ( | Title $ | destination | ) |
Creates a new Content object that acts as a redirect to the given page, or null of redirects are not supported by this content model.
This default implementation always returns null. Subclasses supporting redirects must override this method.
Title | $destination | the page to redirect to. |
Reimplemented in WikitextContentHandler.
Definition at line 450 of file ContentHandler.php.
ContentHandler::merge3 | ( | Content $ | oldContent, |
Content $ | myContent, | ||
Content $ | yourContent | ||
) |
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.
$oldContent | Content|string String |
$myContent | Content|string String |
$yourContent | Content|string String |
Reimplemented in TextContentHandler.
Definition at line 699 of file ContentHandler.php.
Referenced by getUndoContent().
static ContentHandler::runLegacyHooks | ( | $ | event, |
$ | args = array() , |
||
$ | warn = null |
||
) | [static] |
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.
$event | String: event name |
$args | Array: parameters passed to hook functions |
$warn | bool: whether to log a warning. Default to self::$enableDeprecationWarnings. May be set to false for testing. |
Definition at line 1014 of file ContentHandler.php.
References $enableDeprecationWarnings, $handlers, $ok, array(), as, Hooks\getHandlers(), Hooks\isRegistered(), wfRestoreWarnings(), wfRunHooks(), wfSuppressWarnings(), and wfWarn().
Referenced by ContentHandlerTest\testRunLegacyHooks().
ContentHandler::serializeContent | ( | Content $ | content, |
$ | format = null |
||
) | [abstract] |
Serializes a Content object of the type supported by this ContentHandler.
$content | Content The Content object to serialize |
$format | null|String The desired serialization format |
Reimplemented in DummyContentHandlerForTesting, and TextContentHandler.
Returns true if this content model supports sections.
This default implementation returns false.
Reimplemented in WikitextContentHandler.
Definition at line 974 of file ContentHandler.php.
ContentHandler::unserializeContent | ( | $ | blob, |
$ | format = null |
||
) | [abstract] |
Unserializes a Content object of the type supported by this ContentHandler.
$blob | string serialized form of the content |
$format | null|String the format used for serialization |
Reimplemented in RevisionTestModifyableContentHandler, DummyContentHandlerForTesting, TextContentHandler, JavaScriptContentHandler, CssContentHandler, and WikitextContentHandler.
ContentHandler::$enableDeprecationWarnings = false [static, protected] |
Switch for enabling deprecation warnings.
Used by ContentHandler::deprecated() and ContentHandler::runLegacyHooks().
Once the ContentHandler code has settled in a bit, this should be set to true to make extensions etc. show warnings when using deprecated functions and hooks.
Definition at line 58 of file ContentHandler.php.
Referenced by runLegacyHooks().
ContentHandler::$handlers [static] |
Definition at line 280 of file ContentHandler.php.
Referenced by getForModelID(), and runLegacyHooks().
ContentHandler::$mModelID [protected] |
Definition at line 384 of file ContentHandler.php.
ContentHandler::$mSupportedFormats [protected] |
Definition at line 385 of file ContentHandler.php.