Go to the documentation of this file.
95 global $wgContentHandlerTextFallback;
97 if ( is_null( $content ) ) {
102 return $content->getNativeData();
105 wfDebugLog(
'ContentHandler',
'Accessing ' . $content->getModel() .
' content as text!' );
107 if ( $wgContentHandlerTextFallback ==
'fail' ) {
109 "Attempt to get text from Content with model " .
114 if ( $wgContentHandlerTextFallback ==
'serialize' ) {
115 return $content->serialize();
145 $modelId =
null, $format =
null ) {
146 if ( is_null( $modelId ) ) {
147 if ( is_null(
$title ) ) {
148 throw new MWException(
"Must provide a Title object or a content model ID." );
151 $modelId =
$title->getContentModel();
156 return $handler->unserializeContent( $text, $format );
197 $ns =
$title->getNamespace();
205 if ( !is_null( $model ) ) {
211 $isCssOrJsPage =
NS_MEDIAWIKI == $ns && preg_match(
'!\.(css|js)$!u',
$title->getText(), $m );
212 if ( $isCssOrJsPage ) {
220 $isJsCssSubpage =
NS_USER == $ns
222 && preg_match(
"/\\/.*\\.(js|css)$/",
$title->getText(), $m );
223 if ( $isJsCssSubpage ) {
229 $isWikitext = $isWikitext && !$isCssOrJsPage && !$isJsCssSubpage;
234 if ( !$isWikitext ) {
260 $modelId =
$title->getContentModel();
312 global $wgContentHandlers;
318 if ( empty( $wgContentHandlers[$modelId] ) ) {
321 wfRunHooks(
'ContentHandlerForModelID',
array( $modelId, &$handler ) );
323 if ( $handler ===
null ) {
324 throw new MWException(
"No handler for model '$modelId' registered in \$wgContentHandlers" );
328 throw new MWException(
"ContentHandlerForModelID must supply a ContentHandler instance" );
331 $class = $wgContentHandlers[$modelId];
332 $handler =
new $class( $modelId );
335 throw new MWException(
"$class from \$wgContentHandlers is not " .
336 "compatible with ContentHandler" );
340 wfDebugLog(
'ContentHandler',
'Created handler for ' . $modelId
341 .
': ' . get_class( $handler ) );
363 $key =
"content-model-$name";
367 return $msg->exists() ? $msg->plain() :
$name;
371 global $wgContentHandlers;
373 return array_keys( $wgContentHandlers );
377 global $wgContentHandlers;
381 foreach ( $wgContentHandlers
as $model => $class ) {
383 $formats = array_merge( $formats, $handler->getSupportedFormats() );
386 $formats = array_unique( $formats );
412 public function __construct( $modelId, $formats ) {
413 $this->mModelID = $modelId;
414 $this->mSupportedFormats = $formats;
416 $this->mModelName = preg_replace(
'/(Content)?Handler$/',
'', get_class( $this ) );
417 $this->mModelName = preg_replace(
'/[_\\\\]/',
'', $this->mModelName );
418 $this->mModelName = strtolower( $this->mModelName );
497 if ( $model_id !== $this->mModelID ) {
499 "expected {$this->mModelID} " .
500 "but got $model_id." );
529 return $this->mSupportedFormats[0];
550 return in_array( $format, $this->mSupportedFormats );
563 "Format $format is not supported for content model "
599 $refreshCache =
false, $unhide =
false ) {
602 return new $diffEngineClass( $context, $old, $new, $rcid, $refreshCache, $unhide );
665 $variant = $pageLang->getPreferredVariant();
666 if ( $pageLang->getCode() !== $variant ) {
706 return 'DifferenceEngine';
749 $ot = !is_null( $oldContent ) ? $oldContent->getRedirectTarget() :
null;
750 $rt = !is_null( $newContent ) ? $newContent->getRedirectTarget() :
null;
752 if ( is_object( $rt ) ) {
753 if ( !is_object( $ot )
754 || !$rt->equals( $ot )
755 || $ot->getFragment() != $rt->getFragment()
757 $truncatedtext = $newContent->getTextForSummary(
759 - strlen(
wfMessage(
'autoredircomment' )->inContentLanguage()->
text() )
760 - strlen( $rt->getFullText() ) );
762 return wfMessage(
'autoredircomment', $rt->getFullText() )
763 ->rawParams( $truncatedtext )->inContentLanguage()->text();
772 $truncatedtext = $newContent->getTextForSummary(
773 200 - strlen(
wfMessage(
'autosumm-new' )->inContentLanguage()->
text() ) );
775 return wfMessage(
'autosumm-new' )->rawParams( $truncatedtext )
776 ->inContentLanguage()->text();
780 if ( !empty( $oldContent ) && $oldContent->getSize() > 0 && $newContent->getSize() == 0 ) {
781 return wfMessage(
'autosumm-blank' )->inContentLanguage()->text();
782 } elseif ( !empty( $oldContent )
783 && $oldContent->getSize() > 10 * $newContent->getSize()
784 && $newContent->getSize() < 500
788 $truncatedtext = $newContent->getTextForSummary(
789 200 - strlen(
wfMessage(
'autosumm-replace' )->inContentLanguage()->
text() ) );
791 return wfMessage(
'autosumm-replace' )->rawParams( $truncatedtext )
792 ->inContentLanguage()->text();
821 if ( is_null(
$rev ) ) {
826 $content =
$rev->getContent();
832 if ( !$content || $content->isEmpty() ) {
833 $prev =
$rev->getPrevious();
837 $content =
$rev->getContent();
846 $res = $dbw->select(
'revision',
'rev_user_text',
848 'rev_page' =>
$title->getArticleID(),
852 array(
'LIMIT' => 20 )
855 if (
$res ===
false ) {
860 $hasHistory = (
$res->numRows() > 1 );
861 $row = $dbw->fetchObject(
$res );
864 $onlyAuthor = $row->rev_user_text;
866 foreach (
$res as $row ) {
867 if ( $row->rev_user_text != $onlyAuthor ) {
880 $reason =
wfMessage(
'exbeforeblank',
'$1' )->inContentLanguage()->text();
887 )->inContentLanguage()->text();
889 $reason =
wfMessage(
'excontent',
'$1' )->inContentLanguage()->text();
893 if ( $reason ==
'-' ) {
899 $text = $content ? $content->getTextForSummary( 255 - ( strlen( $reason ) - 2 ) ) :
'';
902 $reason = str_replace(
'$1', $text, $reason );
923 if ( empty( $cur_content ) ) {
928 $undoafter_content = $undoafter->
getContent();
930 if ( !$undo_content || !$undoafter_content ) {
938 if ( $cur_content->equals( $undo_content ) ) {
940 return $undoafter_content;
943 $undone_content = $this->
merge3( $undo_content, $undoafter_content, $cur_content );
945 return $undone_content;
967 } elseif ( $context instanceof
User ) {
969 } elseif ( $context ===
'canonical' ) {
972 throw new MWException(
"Bad context for parser options: $context" );
975 $options->enableLimitReport( $wgEnableParserLimitReporting );
1033 if ( self::$enableDeprecationWarnings ) {
1059 if ( $warn ===
null ) {
1072 $handlerInfo =
array();
1077 if ( is_array( $handler ) ) {
1078 if ( is_object( $handler[0] ) ) {
1079 $info = get_class( $handler[0] );
1081 $info = $handler[0];
1084 if ( isset( $handler[1] ) ) {
1085 $info .=
'::' . $handler[1];
1087 } elseif ( is_object( $handler ) ) {
1088 $info = get_class( $handler[0] );
1089 $info .=
'::on' . $event;
1094 $handlerInfo[] = $info;
1099 wfWarn(
"Using obsolete hook $event via ContentHandler::runLegacyHooks()! Handlers: " .
1100 implode(
', ', $handlerInfo ), 2 );
1104 $contentObjects =
array();
1105 $contentTexts =
array();
1107 foreach (
$args as $k => $v ) {
1108 if ( $v instanceof
Content ) {
1111 $contentObjects[$k] = $v;
1113 $v = $v->serialize();
1114 $contentTexts[$k] = $v;
1123 foreach ( $contentTexts
as $k => $orig ) {
1126 $modified =
$args[$k];
1127 $content = $contentObjects[$k];
1129 if ( $modified !== $orig ) {
1131 $content = $content->getContentHandler()->unserializeContent( $modified );
1134 $args[$k] = $content;
static deprecated( $func, $version, $component=false)
Logs a deprecation warning, visible if $wgDevelopmentWarnings, but only if self::$enableDeprecationWa...
A content handler knows how do deal with a specific type of content on a wiki page.
static getForModelID( $modelId)
Returns the ContentHandler singleton for the given model ID.
getAutosummary(Content $oldContent=null, Content $newContent=null, $flags)
Return an applicable auto-summary if one exists for the given edit.
static getAllContentFormats()
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
static getHandlers( $name)
Returns an array of all the event functions attached to a hook This combines functions registered via...
makeParserOptions( $context)
Get parser options suitable for rendering and caching the article.
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
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
getContent( $audience=self::FOR_PUBLIC, User $user=null)
Fetch revision content if it's available to the specified audience.
getActionOverrides()
Returns overrides for action handlers.
static getNamespaceContentModel( $index)
Get the default content model for a namespace This does not mean that all pages in that namespace hav...
getAutoDeleteReason(Title $title, &$hasHistory)
Auto-generates a deletion reason.
wfDebugLog( $logGroup, $text, $dest='all')
Send a line to a supplementary debug log file, if configured, or main debug log if not.
unserializeContent( $blob, $format=null)
Unserializes a Content object of the type supported by this ContentHandler.
wfSuppressWarnings( $end=false)
Reference-counted warning suppression.
getPageViewLanguage(Title $title, Content $content=null)
Get the language in which the content of this page is written when viewed by user.
string[] $mSupportedFormats
static getForTitle(Title $title)
Returns the appropriate ContentHandler singleton for the given title.
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 content language as $wgContLang
const CONTENT_MODEL_WIKITEXT
it s the revision text itself In either if gzip is the revision text is gzipped $flags
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.
static runLegacyHooks( $event, $args=array(), $warn=null)
Call a legacy hook that uses text instead of Content objects.
isSupportedFormat( $format)
Returns true if $format is a serialization format supported by this ContentHandler,...
static getLocalizedName( $name)
Returns the localized name for a given content model.
createDifferenceEngine(IContextSource $context, $old=0, $new=0, $rcid=0, $refreshCache=false, $unhide=false)
Factory for creating an appropriate DifferenceEngine for this content model.
canBeUsedOn(Title $title)
Determines whether the content type handled by this ContentHandler can be used on the given page.
supportsRedirects()
Returns true if this content model supports redirects.
static getDefaultModelFor(Title $title)
Returns the name of the default content model to be used for the page with the given title.
static $enableDeprecationWarnings
Switch for enabling deprecation warnings.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
wfRestoreWarnings()
Restore error level to previous value.
static getContentModels()
static newFromUserAndLang(User $user, Language $lang)
Get a ParserOptions object from a given user and language.
Exception representing a failure to serialize or unserialize a content object.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form externallinks including delete and has completed for all link tables 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 "<
wfRunHooks( $event, array $args=array(), $deprecatedVersion=null)
Call hook functions defined in $wgHooks.
wfGetLangObj( $langcode=false)
Return a Language object from $langcode.
merge3(Content $oldContent, Content $myContent, Content $yourContent)
Attempts to merge differences between three versions.
makeEmptyContent()
Creates an empty Content object of the type supported by this ContentHandler.
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
when a variable name is used in a it is silently declared as a new masking the global
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
static singleton()
Get the signleton instance of this class.
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
getPageLanguage(Title $title, Content $content=null)
Get the language in which the content of the given page is written.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
isParserCacheSupported()
Returns true for content models that support caching using the ParserCache mechanism.
static newFromTitle( $title, $id=0, $flags=0)
Load either the current, or a specified, revision that's attached to a given title.
presenting them properly to the user as errors is done by the caller $title
Allows to change the fields on the form that will be generated $name
getDefaultFormat()
The format used for serialization/deserialization by default by this ContentHandler.
static newFromContext(IContextSource $context)
Get a ParserOptions object from a IContextSource object.
getDiffEngineClass()
Returns the name of the diff engine to use.
Content object implementation for representing flat text.
Interface for objects which can provide a context on request.
Base interface for content objects.
static isRegistered( $name)
Returns true if a hook has a function registered to it.
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
Represents a title within MediaWiki.
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
makeRedirectContent(Title $destination, $text='')
Creates a new Content object that acts as a redirect to the given page, or null of redirects are not ...
checkFormat( $format)
Convenient for checking whether a format provided as a parameter is actually supported.
static getContentText(Content $content=null)
Convenience function for getting flat text from a Content object.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
getModel()
Returns the ID of the content model used by this Content object.
static factory( $code)
Get a cached or new language object for a given language code.
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
const CONTENT_MODEL_JAVASCRIPT
__construct( $modelId, $formats)
Constructor, initializing the ContentHandler instance with its model ID and a list of supported forma...
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
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...
getSupportedFormats()
Returns a list of serialization formats supported by the serializeContent() and unserializeContent() ...
getModelID()
Returns the model id that identifies the content model this ContentHandler can handle.
static getForContent(Content $content)
Returns the appropriate ContentHandler singleton for the given Content object.
static newFromUser( $user)
Get a ParserOptions object from a given user.