82 if ( is_null( $content ) ) {
87 return $content->getNativeData();
90 wfDebugLog(
'ContentHandler',
'Accessing ' . $content->getModel() .
' content as text!' );
94 "Attempt to get text from Content with model " .
100 return $content->serialize();
130 $modelId =
null, $format =
null ) {
131 if ( is_null( $modelId ) ) {
132 if ( is_null( $title ) ) {
133 throw new MWException(
"Must provide a Title object or a content model ID." );
136 $modelId = $title->getContentModel();
139 $handler = self::getForModelID( $modelId );
141 return $handler->unserializeContent( $text, $format );
182 $ns = $title->getNamespace();
186 $model = MWNamespace::getNamespaceContentModel( $ns );
189 if ( !Hooks::run(
'ContentHandlerDefaultModelFor', [ $title, &$model ] ) ) {
190 if ( !is_null( $model ) ) {
196 $isCodePage = NS_MEDIAWIKI == $ns && preg_match(
'!\.(css|js|json)$!u', $title->getText(), $m );
202 $isCodeSubpage = NS_USER == $ns
204 && preg_match(
"/\\/.*\\.(js|css|json)$/", $title->getText(), $m );
205 if ( $isCodeSubpage ) {
211 $isWikitext = $isWikitext && !$isCodePage && !$isCodeSubpage;
213 if ( !$isWikitext ) {
241 $modelId = $title->getContentModel();
243 return self::getForModelID( $modelId );
259 return self::getForModelID( $modelId );
296 if ( isset( self::$handlers[$modelId] ) ) {
297 return self::$handlers[$modelId];
303 Hooks::run(
'ContentHandlerForModelID', [ $modelId, &
$handler ] );
310 throw new MWException(
"ContentHandlerForModelID must supply a ContentHandler instance" );
315 if ( is_callable( $classOrCallback ) ) {
316 $handler = call_user_func( $classOrCallback, $modelId );
318 $handler =
new $classOrCallback( $modelId );
322 throw new MWException(
"$classOrCallback from \$wgContentHandlers is not " .
323 "compatible with ContentHandler" );
327 wfDebugLog(
'ContentHandler',
'Created handler for ' . $modelId
330 self::$handlers[$modelId] =
$handler;
332 return self::$handlers[$modelId];
339 self::$handlers = [];
358 $key =
"content-model-$name";
362 $msg->inLanguage(
$lang );
365 return $msg->exists() ? $msg->plain() :
$name;
372 Hooks::run(
'GetContentModels', [ &$models ] );
382 $handler = self::getForModelID( $model );
383 $formats = array_merge( $formats,
$handler->getSupportedFormats() );
386 $formats = array_unique( $formats );
413 $this->mModelID = $modelId;
414 $this->mSupportedFormats = $formats;
510 return $this->mModelID;
522 if ( $model_id !== $this->mModelID ) {
524 "expected {$this->mModelID} " .
525 "but got $model_id." );
539 return $this->mSupportedFormats;
554 return $this->mSupportedFormats[0];
575 return in_array( $format, $this->mSupportedFormats );
588 "Format $format is not supported for content model "
633 if ( !Hooks::run(
'GetDifferenceEngine',
665 if ( $title->getNamespace() == NS_MEDIAWIKI ) {
668 $pageLang = Language::factory(
$lang );
671 Hooks::run(
'PageContentLanguage', [ $title, &$pageLang,
$wgLang ] );
699 if ( $title->getNamespace() !== NS_MEDIAWIKI ) {
702 $variant = $pageLang->getPreferredVariant();
703 if ( $pageLang->getCode() !== $variant ) {
704 $pageLang = Language::factory( $variant );
730 Hooks::run(
'ContentModelCanBeUsedOn', [ $this->
getModelID(), $title, &$ok ] );
743 return DifferenceEngine::class;
780 $oldTarget = $oldContent !==
null ? $oldContent->getRedirectTarget() :
null;
781 $newTarget = $newContent !==
null ? $newContent->getRedirectTarget() :
null;
786 if ( $oldContent && $oldContent->getSize() > 0 &&
787 $newContent && $newContent->getSize() === 0
796 return 'new-redirect';
797 } elseif ( !$newTarget->equals( $oldTarget ) ||
798 $oldTarget->getFragment() !== $newTarget->getFragment()
801 return 'changed-redirect-target';
803 } elseif ( $oldTarget ) {
805 return 'removed-redirect';
809 if ( $flags &
EDIT_NEW && $newContent ) {
810 if ( $newContent->getSize() === 0 ) {
819 if ( $oldContent && $newContent && $oldContent->getSize() > 10 * $newContent->getSize() ) {
824 if ( $oldContent && $newContent && $oldContent->getModel() !== $newContent->getModel() ) {
825 return 'contentmodelchange';
847 $changeType = $this->
getChangeType( $oldContent, $newContent, $flags );
850 if ( !$changeType ) {
855 switch ( $changeType ) {
857 $newTarget = $newContent->getRedirectTarget();
858 $truncatedtext = $newContent->getTextForSummary(
860 - strlen(
wfMessage(
'autoredircomment' )->inContentLanguage()->
text() )
861 - strlen( $newTarget->getFullText() )
864 return wfMessage(
'autoredircomment', $newTarget->getFullText() )
865 ->plaintextParams( $truncatedtext )->inContentLanguage()->text();
866 case 'changed-redirect-target':
867 $oldTarget = $oldContent->getRedirectTarget();
868 $newTarget = $newContent->getRedirectTarget();
870 $truncatedtext = $newContent->getTextForSummary(
872 - strlen(
wfMessage(
'autosumm-changed-redirect-target' )
873 ->inContentLanguage()->
text() )
874 - strlen( $oldTarget->getFullText() )
875 - strlen( $newTarget->getFullText() )
878 return wfMessage(
'autosumm-changed-redirect-target',
879 $oldTarget->getFullText(),
880 $newTarget->getFullText() )
881 ->rawParams( $truncatedtext )->inContentLanguage()->text();
882 case 'removed-redirect':
883 $oldTarget = $oldContent->getRedirectTarget();
884 $truncatedtext = $newContent->getTextForSummary(
886 - strlen(
wfMessage(
'autosumm-removed-redirect' )
887 ->inContentLanguage()->
text() )
888 - strlen( $oldTarget->getFullText() ) );
890 return wfMessage(
'autosumm-removed-redirect', $oldTarget->getFullText() )
891 ->rawParams( $truncatedtext )->inContentLanguage()->text();
894 $truncatedtext = $newContent->getTextForSummary(
895 200 - strlen(
wfMessage(
'autosumm-new' )->inContentLanguage()->
text() ) );
897 return wfMessage(
'autosumm-new' )->rawParams( $truncatedtext )
898 ->inContentLanguage()->text();
900 return wfMessage(
'autosumm-blank' )->inContentLanguage()->text();
902 $truncatedtext = $newContent->getTextForSummary(
903 200 - strlen(
wfMessage(
'autosumm-replace' )->inContentLanguage()->
text() ) );
905 return wfMessage(
'autosumm-replace' )->rawParams( $truncatedtext )
906 ->inContentLanguage()->text();
908 return wfMessage(
'autosumm-newblank' )->inContentLanguage()->text();
930 $changeType = $this->
getChangeType( $oldContent, $newContent, $flags );
933 if ( !$changeType ) {
940 $tag =
'mw-' . $changeType;
969 $rev = Revision::newFromTitle( $title );
971 if ( is_null(
$rev ) ) {
976 $content =
$rev->getContent();
982 if ( !$content || $content->isEmpty() ) {
983 $prev =
$rev->getPrevious();
987 $content =
$rev->getContent();
999 [
'rev_user_text' =>
$revQuery[
'fields'][
'rev_user_text'] ],
1001 'rev_page' => $title->getArticleID(),
1002 $dbr->bitAnd(
'rev_deleted', Revision::DELETED_USER ) .
' = 0'
1009 if (
$res ===
false ) {
1014 $hasHistory = (
$res->numRows() > 1 );
1018 $onlyAuthor = $row->rev_user_text;
1020 foreach (
$res as $row ) {
1021 if ( $row->rev_user_text != $onlyAuthor ) {
1022 $onlyAuthor =
false;
1027 $onlyAuthor =
false;
1034 $reason =
wfMessage(
'exbeforeblank',
'$1' )->inContentLanguage()->text();
1036 if ( $onlyAuthor ) {
1041 )->inContentLanguage()->text();
1043 $reason =
wfMessage(
'excontent',
'$1' )->inContentLanguage()->text();
1047 if ( $reason ==
'-' ) {
1053 $text = $content ? $content->getTextForSummary( 255 - ( strlen( $reason ) - 2 ) ) :
'';
1056 $reason = str_replace(
'$1', $text, $reason );
1077 if ( empty( $cur_content ) ) {
1081 $undo_content = $undo->getContent();
1082 $undoafter_content = $undoafter->getContent();
1084 if ( !$undo_content || !$undoafter_content ) {
1091 if ( $current->
getId() !== $undo->getId() ) {
1104 if ( $cur_content->equals( $undo_content ) ) {
1106 return $undoafter_content;
1109 $undone_content = $this->
merge3( $undo_content, $undoafter_content, $cur_content );
1111 return $undone_content;
1137 } elseif (
$context ===
'canonical' ) {
1141 throw new MWException(
"Bad context for parser options: $context" );
1144 return ParserOptions::newCanonical( $user,
$lang );
1224 $fields[
'category'] =
$engine->makeSearchFieldMapping(
1230 $fields[
'external_link'] =
$engine->makeSearchFieldMapping(
1235 $fields[
'outgoing_link'] =
$engine->makeSearchFieldMapping(
1240 $fields[
'template'] =
$engine->makeSearchFieldMapping(
1246 $fields[
'content_model'] =
$engine->makeSearchFieldMapping(
1290 $fieldData[
'category'] = $searchDataExtractor->getCategories(
$output );
1291 $fieldData[
'external_link'] = $searchDataExtractor->getExternalLinks(
$output );
1292 $fieldData[
'outgoing_link'] = $searchDataExtractor->getOutgoingLinks(
$output );
1293 $fieldData[
'template'] = $searchDataExtractor->getTemplates(
$output );
1295 $text = $content->getTextForSearchIndex();
1297 $fieldData[
'text'] = $text;
1298 $fieldData[
'source_text'] = $text;
1299 $fieldData[
'text_bytes'] = $content->getSize();
1300 $fieldData[
'content_model'] = $content->getModel();
1303 Hooks::run(
'SearchDataForIndex', [ &$fieldData, $this, $page,
$output,
$engine ] );
1320 $parserOutput =
$cache->get( $page, $parserOptions );
1322 if ( empty( $parserOutput ) ) {
1326 $cache->save( $parserOutput, $page, $parserOptions );
1329 return $parserOutput;
$wgContentHandlerTextFallback
How to react if a plain text version of a non-text Content object is requested using ContentHandler::...
$wgContentHandlers
Plugins for page content model handling.
wfGetLangObj( $langcode=false)
Return a Language object from $langcode.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
A content handler knows how do deal with a specific type of content on a wiki page.
getParserOutputForIndexing(WikiPage $page, ParserCache $cache=null)
Produce page output suitable for indexing.
getModelID()
Returns the model id that identifies the content model this ContentHandler can handle.
makeRedirectContent(Title $destination, $text='')
Creates a new Content object that acts as a redirect to the given page, or null if redirects are not ...
__construct( $modelId, $formats)
Constructor, initializing the ContentHandler instance with its model ID and a list of supported forma...
static getAllContentFormats()
string[] $mSupportedFormats
getChangeType(Content $oldContent=null, Content $newContent=null, $flags=0)
Return type of change if one exists for the given edit.
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
importTransform( $blob, $format=null)
Apply import transformation (per default, returns $blob unchanged).
isParserCacheSupported()
Returns true for content models that support caching using the ParserCache mechanism.
static getForModelID( $modelId)
Returns the ContentHandler singleton for the given model ID.
supportsDirectApiEditing()
Whether or not this content model supports direct editing via ApiEditPage.
getAutoDeleteReason(Title $title, &$hasHistory)
Auto-generates a deletion reason.
getChangeTag(Content $oldContent=null, Content $newContent=null, $flags=0)
Return an applicable tag if one exists for the given edit or return null.
getDiffEngineClass()
Returns the name of the diff engine to use.
static getForTitle(Title $title)
Returns the appropriate ContentHandler singleton for the given title.
exportTransform( $blob, $format=null)
Applies transformations on export (returns the blob unchanged per default).
merge3(Content $oldContent, Content $myContent, Content $yourContent)
Attempts to merge differences between three versions.
getAutosummary(Content $oldContent=null, Content $newContent=null, $flags=0)
Return an applicable auto-summary if one exists for the given edit.
checkFormat( $format)
Convenient for checking whether a format provided as a parameter is actually supported.
addSearchField(&$fields, SearchEngine $engine, $name, $type)
Add new field definition to array.
getActionOverrides()
Returns overrides for action handlers.
createDifferenceEngine(IContextSource $context, $old=0, $new=0, $rcid=0, $refreshCache=false, $unhide=false)
Factory for creating an appropriate DifferenceEngine for this content model.
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 $undoa...
static getContentModels()
getPageLanguage(Title $title, Content $content=null)
Get the language in which the content of the given page is written.
getDefaultFormat()
The format used for serialization/deserialization by default by this ContentHandler.
static getDefaultModelFor(Title $title)
Returns the name of the default content model to be used for the page with the given title.
unserializeContent( $blob, $format=null)
Unserializes a Content object of the type supported by this ContentHandler.
static getLocalizedName( $name, Language $lang=null)
Returns the localized name for a given content model.
supportsDirectEditing()
Return true if this content model supports direct editing, such as via EditPage.
isSupportedFormat( $format)
Returns true if $format is a serialization format supported by this ContentHandler,...
getSupportedFormats()
Returns a list of serialization formats supported by the serializeContent() and unserializeContent() ...
supportsSections()
Returns true if this content model supports sections.
static cleanupHandlersCache()
Clean up handlers cache.
static getContentText(Content $content=null)
Convenience function for getting flat text from a Content object.
getDataForSearchIndex(WikiPage $page, ParserOutput $output, SearchEngine $engine)
Return fields to be indexed by search engine as representation of this document.
supportsCategories()
Returns true if this content model supports categories.
static getForContent(Content $content)
Returns the appropriate ContentHandler singleton for the given Content object.
supportsRedirects()
Returns true if this content model supports redirects.
canBeUsedOn(Title $title)
Determines whether the content type handled by this ContentHandler can be used on the given page.
serializeContent(Content $content, $format=null)
Serializes a Content object of the type supported by this ContentHandler.
makeEmptyContent()
Creates an empty Content object of the type supported by this ContentHandler.
static array $handlers
A Cache of ContentHandler instances by model id.
makeParserOptions( $context)
Get parser options suitable for rendering and caching the article.
getFieldsForSearchIndex(SearchEngine $engine)
Get fields definition for search index.
getPageViewLanguage(Title $title, Content $content=null)
Get the language in which the content of this page is written when viewed by user.
Internationalisation code.
Exception thrown when an unregistered content model is requested.
static singleton()
Get the signleton instance of this class.
getContent( $audience=self::FOR_PUBLIC, User $user=null)
Fetch revision content if it's available to the specified audience.
Contain a class for special pages.
Content object implementation for representing flat text.
Represents a title within MediaWiki.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Class representing a MediaWiki article and history.
getRevision()
Get the latest revision.
makeParserOptions( $context)
Get parser options suitable for rendering the primary article wikitext.
getContent( $audience=Revision::FOR_PUBLIC, User $user=null)
Get the content of the current revision.
getTitle()
Get the title object of the article.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as $wgLang
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify as strings Extensions should add to this list prev or next $refreshCache
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify as strings Extensions should add to this list prev or next refreshes the diff cache $unhide
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place $output
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "<div ...>$1</div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify as strings Extensions should add to this list prev or next refreshes the diff cache allow viewing deleted revs & $differenceEngine
Allows to change the fields on the form that will be generated $name
the value to return A Title object or null for latest all implement SearchIndexField $engine
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves $handler
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
returning false will NOT prevent logging $e
const CONTENT_MODEL_WIKITEXT
const CONTENT_MODEL_JAVASCRIPT
Base interface for content objects.
getModel()
Returns the ID of the content model used by this Content object.
Interface for objects which can provide a MediaWiki context on request.
const INDEX_TYPE_TEXT
Field types.
const FLAG_CASEFOLD
Generic field flags.
if(!is_readable( $file)) $ext
if(!isset( $args[0])) $lang