4 * Exception representing a failure to serialize or unserialize a content object.
6 class MWContentSerializationException
extends MWException
{
11 * A content handler knows how do deal with a specific type of content on a wiki
12 * page. Content is stored in the database in a serialized form (using a
13 * serialization format a.k.a. MIME type) and is unserialized into its native
14 * PHP representation (the content model), which is wrapped in an instance of
15 * the appropriate subclass of Content.
17 * ContentHandler instances are stateless singletons that serve, among other
18 * things, as a factory for Content objects. Generally, there is one subclass
19 * of ContentHandler and one subclass of Content for every type of content model.
21 * Some content types have a flat model, that is, their native representation
22 * is the same as their serialized form. Examples would be JavaScript and CSS
23 * code. As of now, this also applies to wikitext (MediaWiki's default content
24 * type), but wikitext content may be represented by a DOM or AST structure in
29 abstract class ContentHandler
{
32 * Convenience function for getting flat text from a Content object. This
33 * should only be used in the context of backwards compatibility with code
34 * that is not yet able to handle Content objects!
36 * If $content is null, this method returns the empty string.
38 * If $content is an instance of TextContent, this method returns the flat
39 * text as returned by $content->getNativeData().
41 * If $content is not a TextContent object, the behavior of this method
42 * depends on the global $wgContentHandlerTextFallback:
43 * - If $wgContentHandlerTextFallback is 'fail' and $content is not a
44 * TextContent object, an MWException is thrown.
45 * - If $wgContentHandlerTextFallback is 'serialize' and $content is not a
46 * TextContent object, $content->serialize() is called to get a string
47 * form of the content.
48 * - If $wgContentHandlerTextFallback is 'ignore' and $content is not a
49 * TextContent object, this method returns null.
50 * - otherwise, the behaviour is undefined.
53 * @deprecated since WD.1. Always try to use the content object.
56 * @param $content Content|null
57 * @return null|string the textual form of $content, if available
58 * @throws MWException if $content is not an instance of TextContent and
59 * $wgContentHandlerTextFallback was set to 'fail'.
61 public static function getContentText( Content
$content = null ) {
62 global $wgContentHandlerTextFallback;
64 if ( is_null( $content ) ) {
68 if ( $content instanceof TextContent
) {
69 return $content->getNativeData();
72 if ( $wgContentHandlerTextFallback == 'fail' ) {
73 throw new MWException(
74 "Attempt to get text from Content with model " .
79 if ( $wgContentHandlerTextFallback == 'serialize' ) {
80 return $content->serialize();
87 * Convenience function for creating a Content object from a given textual
90 * $text will be deserialized into a Content object of the model specified
91 * by $modelId (or, if that is not given, $title->getContentModel()) using
98 * @param $text string the textual representation, will be
99 * unserialized to create the Content object
100 * @param $title null|Title the title of the page this text belongs to.
101 * Required if $modelId is not provided.
102 * @param $modelId null|string the model to deserialize to. If not provided,
103 * $title->getContentModel() is used.
104 * @param $format null|string the format to use for deserialization. If not
105 * given, the model's default format is used.
107 * @return Content a Content object representing $text
109 * @throw MWException if $model or $format is not supported or if $text can
110 * not be unserialized using $format.
112 public static function makeContent( $text, Title
$title = null,
113 $modelId = null, $format = null )
115 if ( is_null( $modelId ) ) {
116 if ( is_null( $title ) ) {
117 throw new MWException( "Must provide a Title object or a content model ID." );
120 $modelId = $title->getContentModel();
123 $handler = ContentHandler
::getForModelID( $modelId );
124 return $handler->unserializeContent( $text, $format );
128 * Returns the name of the default content model to be used for the page
129 * with the given title.
131 * Note: There should rarely be need to call this method directly.
132 * To determine the actual content model for a given page, use
133 * Title::getContentModel().
135 * Which model is to be used by default for the page is determined based
136 * on several factors:
137 * - The global setting $wgNamespaceContentModels specifies a content model
139 * - The hook DefaultModelFor may be used to override the page's default
141 * - Pages in NS_MEDIAWIKI and NS_USER default to the CSS or JavaScript
142 * model if they end in .js or .css, respectively.
143 * - Pages in NS_MEDIAWIKI default to the wikitext model otherwise.
144 * - The hook TitleIsCssOrJsPage may be used to force a page to use the CSS
145 * or JavaScript model if they end in .js or .css, respectively.
146 * - The hook TitleIsWikitextPage may be used to force a page to use the
149 * If none of the above applies, the wikitext model is used.
151 * Note: this is used by, and may thus not use, Title::getContentModel()
156 * @param $title Title
157 * @return null|string default model name for the page given by $title
159 public static function getDefaultModelFor( Title
$title ) {
160 global $wgNamespaceContentModels;
162 // NOTE: this method must not rely on $title->getContentModel() directly or indirectly,
163 // because it is used to initialize the mContentModel member.
165 $ns = $title->getNamespace();
171 if ( !empty( $wgNamespaceContentModels[ $ns ] ) ) {
172 $model = $wgNamespaceContentModels[ $ns ];
175 // Hook can determine default model
176 if ( !wfRunHooks( 'ContentHandlerDefaultModelFor', array( $title, &$model ) ) ) {
177 if ( !is_null( $model ) ) {
182 // Could this page contain custom CSS or JavaScript, based on the title?
183 $isCssOrJsPage = NS_MEDIAWIKI
== $ns && preg_match( '!\.(css|js)$!u', $title->getText(), $m );
184 if ( $isCssOrJsPage ) {
188 // Hook can force JS/CSS
189 wfRunHooks( 'TitleIsCssOrJsPage', array( $title, &$isCssOrJsPage ) );
191 // Is this a .css subpage of a user page?
192 $isJsCssSubpage = NS_USER
== $ns
194 && preg_match( "/\\/.*\\.(js|css)$/", $title->getText(), $m );
195 if ( $isJsCssSubpage ) {
199 // Is this wikitext, according to $wgNamespaceContentModels or the DefaultModelFor hook?
200 $isWikitext = is_null( $model ) ||
$model == CONTENT_MODEL_WIKITEXT
;
201 $isWikitext = $isWikitext && !$isCssOrJsPage && !$isJsCssSubpage;
203 // Hook can override $isWikitext
204 wfRunHooks( 'TitleIsWikitextPage', array( $title, &$isWikitext ) );
206 if ( !$isWikitext ) {
209 return CONTENT_MODEL_JAVASCRIPT
;
211 return CONTENT_MODEL_CSS
;
213 return is_null( $model ) ? CONTENT_MODEL_TEXT
: $model;
217 // We established that it must be wikitext
219 return CONTENT_MODEL_WIKITEXT
;
223 * Returns the appropriate ContentHandler singleton for the given title.
228 * @param $title Title
229 * @return ContentHandler
231 public static function getForTitle( Title
$title ) {
232 $modelId = $title->getContentModel();
233 return ContentHandler
::getForModelID( $modelId );
237 * Returns the appropriate ContentHandler singleton for the given Content
243 * @param $content Content
244 * @return ContentHandler
246 public static function getForContent( Content
$content ) {
247 $modelId = $content->getModel();
248 return ContentHandler
::getForModelID( $modelId );
252 * @var Array A Cache of ContentHandler instances by model id
257 * Returns the ContentHandler singleton for the given model ID. Use the
258 * CONTENT_MODEL_XXX constants to identify the desired content model.
260 * ContentHandler singletons are taken from the global $wgContentHandlers
261 * array. Keys in that array are model names, the values are either
262 * ContentHandler singleton objects, or strings specifying the appropriate
263 * subclass of ContentHandler.
265 * If a class name is encountered when looking up the singleton for a given
266 * model name, the class is instantiated and the class name is replaced by
267 * the resulting singleton in $wgContentHandlers.
269 * If no ContentHandler is defined for the desired $modelId, the
270 * ContentHandler may be provided by the ContentHandlerForModelID hook.
271 * If no ContentHandler can be determined, an MWException is raised.
276 * @param $modelId String The ID of the content model for which to get a
277 * handler. Use CONTENT_MODEL_XXX constants.
278 * @return ContentHandler The ContentHandler singleton for handling the
279 * model given by $modelId
280 * @throws MWException if no handler is known for $modelId.
282 public static function getForModelID( $modelId ) {
283 global $wgContentHandlers;
285 if ( isset( ContentHandler
::$handlers[$modelId] ) ) {
286 return ContentHandler
::$handlers[$modelId];
289 if ( empty( $wgContentHandlers[$modelId] ) ) {
292 wfRunHooks( 'ContentHandlerForModelID', array( $modelId, &$handler ) );
294 if ( $handler === null ) {
295 throw new MWException( "No handler for model #$modelId registered in \$wgContentHandlers" );
298 if ( !( $handler instanceof ContentHandler
) ) {
299 throw new MWException( "ContentHandlerForModelID must supply a ContentHandler instance" );
302 $class = $wgContentHandlers[$modelId];
303 $handler = new $class( $modelId );
305 if ( !( $handler instanceof ContentHandler
) ) {
306 throw new MWException( "$class from \$wgContentHandlers is not compatible with ContentHandler" );
310 ContentHandler
::$handlers[$modelId] = $handler;
311 return ContentHandler
::$handlers[$modelId];
315 * Returns the localized name for a given content model.
317 * Model names are localized using system messages. Message keys
318 * have the form content-model-$name, where $name is getContentModelName( $id ).
321 * @param $name String The content model ID, as given by a CONTENT_MODEL_XXX
322 * constant or returned by Revision::getContentModel().
324 * @return string The content format's localized name.
325 * @throws MWException if the model id isn't known.
327 public static function getLocalizedName( $name ) {
328 $key = "content-model-$name";
330 if ( wfEmptyMsg( $key ) ) return $name;
331 else return wfMsg( $key );
334 public static function getAllContentFormats() {
335 global $wgContentHandlers;
339 foreach ( $wgContentHandlers as $model => $class ) {
340 $handler = ContentHandler
::getForModelID( $model );
341 $formats = array_merge( $formats, $handler->getSupportedFormats() );
344 $formats = array_unique( $formats );
348 // ------------------------------------------------------------------------
351 protected $mSupportedFormats;
354 * Constructor, initializing the ContentHandler instance with its model ID
355 * and a list of supported formats. Values for the parameters are typically
356 * provided as literals by subclass's constructors.
358 * @param $modelId String (use CONTENT_MODEL_XXX constants).
359 * @param $formats array List for supported serialization formats
360 * (typically as MIME types)
362 public function __construct( $modelId, $formats ) {
363 $this->mModelID
= $modelId;
364 $this->mSupportedFormats
= $formats;
366 $this->mModelName
= preg_replace( '/(Content)?Handler$/', '', get_class( $this ) );
367 $this->mModelName
= preg_replace( '/[_\\\\]/', '', $this->mModelName
);
368 $this->mModelName
= strtolower( $this->mModelName
);
372 * Serializes a Content object of the type supported by this ContentHandler.
377 * @param $content Content The Content object to serialize
378 * @param $format null|String The desired serialization format
379 * @return string Serialized form of the content
381 public abstract function serializeContent( Content
$content, $format = null );
384 * Unserializes a Content object of the type supported by this ContentHandler.
389 * @param $blob string serialized form of the content
390 * @param $format null|String the format used for serialization
391 * @return Content the Content object created by deserializing $blob
393 public abstract function unserializeContent( $blob, $format = null );
396 * Creates an empty Content object of the type supported by this
403 public abstract function makeEmptyContent();
406 * Returns the model id that identifies the content model this
407 * ContentHandler can handle. Use with the CONTENT_MODEL_XXX constants.
411 * @return String The model ID
413 public function getModelID() {
414 return $this->mModelID
;
418 * Throws an MWException if $model_id is not the ID of the content model
419 * supported by this ContentHandler.
423 * @param String $model_id The model to check
425 * @throws MWException
427 protected function checkModelID( $model_id ) {
428 if ( $model_id !== $this->mModelID
) {
429 throw new MWException( "Bad content model: " .
430 "expected {$this->mModelID} " .
431 "but got $model_id." );
436 * Returns a list of serialization formats supported by the
437 * serializeContent() and unserializeContent() methods of this
442 * @return array of serialization formats as MIME type like strings
444 public function getSupportedFormats() {
445 return $this->mSupportedFormats
;
449 * The format used for serialization/deserialization by default by this
452 * This default implementation will return the first element of the array
453 * of formats that was passed to the constructor.
457 * @return string the name of the default serialization format as a MIME type
459 public function getDefaultFormat() {
460 return $this->mSupportedFormats
[0];
464 * Returns true if $format is a serialization format supported by this
465 * ContentHandler, and false otherwise.
467 * Note that if $format is null, this method always returns true, because
468 * null means "use the default format".
472 * @param $format string the serialization format to check
475 public function isSupportedFormat( $format ) {
478 return true; // this means "use the default"
481 return in_array( $format, $this->mSupportedFormats
);
485 * Throws an MWException if isSupportedFormat( $format ) is not true.
486 * Convenient for checking whether a format provided as a parameter is
487 * actually supported.
489 * @param $format string the serialization format to check
491 * @throws MWException
493 protected function checkFormat( $format ) {
494 if ( !$this->isSupportedFormat( $format ) ) {
495 throw new MWException(
496 "Format $format is not supported for content model "
497 . $this->getModelID()
503 * Returns overrides for action handlers.
504 * Classes listed here will be used instead of the default one when
505 * (and only when) $wgActions[$action] === true. This allows subclasses
506 * to override the default action handlers.
512 public function getActionOverrides() {
517 * Factory for creating an appropriate DifferenceEngine for this content model.
521 * @param $context IContextSource context to use, anything else will be
523 * @param $old Integer Old ID we want to show and diff with.
524 * @param $new int|string String either 'prev' or 'next'.
525 * @param $rcid Integer ??? FIXME (default 0)
526 * @param $refreshCache boolean If set, refreshes the diff cache
527 * @param $unhide boolean If set, allow viewing deleted revs
529 * @return DifferenceEngine
531 public function createDifferenceEngine( IContextSource
$context,
533 $rcid = 0, # FIXME: use everywhere!
534 $refreshCache = false, $unhide = false
536 $this->checkModelID( $context->getTitle()->getContentModel() );
538 $diffEngineClass = $this->getDiffEngineClass();
540 return new $diffEngineClass( $context, $old, $new, $rcid, $refreshCache, $unhide );
544 * Get the language in which the content of the given page is written.
546 * This default implementation returns $wgContLang->getCode().
548 * Note that a page's language must be permanent and cacheable, that is, it must not depend
549 * on user preferences, request parameters or session state.
551 * Also note that the page language may or may not depend on the actual content of the page,
552 * that is, this method may load the content in order to determine the language.
556 * @param Title $title the page to determine the language for.
557 * @param Content|null $content the page's content, if you have it handy, to avoid reloading it.
559 * @return Language the page's language code
561 public function getPageLanguage( Title
$title, Content
$content = null ) {
567 * Returns the name of the diff engine to use.
573 protected function getDiffEngineClass() {
574 return 'DifferenceEngine';
578 * Attempts to merge differences between three versions.
579 * Returns a new Content object for a clean merge and false for failure or
582 * This default implementation always returns false.
586 * @param $oldContent Content|string String
587 * @param $myContent Content|string String
588 * @param $yourContent Content|string String
590 * @return Content|Bool
592 public function merge3( Content
$oldContent, Content
$myContent, Content
$yourContent ) {
597 * Return an applicable auto-summary if one exists for the given edit.
601 * @param $oldContent Content|null: the previous text of the page.
602 * @param $newContent Content|null: The submitted text of the page.
603 * @param $flags int Bit mask: a bit mask of flags submitted for the edit.
605 * @return string An appropriate auto-summary, or an empty string.
607 public function getAutosummary( Content
$oldContent = null, Content
$newContent = null, $flags ) {
610 // Decide what kind of auto-summary is needed.
612 // Redirect auto-summaries
619 $ot = !is_null( $oldContent ) ?
$oldContent->getRedirectTarget() : null;
620 $rt = !is_null( $newContent ) ?
$newContent->getRedirectTarget() : null;
622 if ( is_object( $rt ) ) {
623 if ( !is_object( $ot )
624 ||
!$rt->equals( $ot )
625 ||
$ot->getFragment() != $rt->getFragment() )
627 $truncatedtext = $newContent->getTextForSummary(
629 - strlen( wfMsgForContent( 'autoredircomment' ) )
630 - strlen( $rt->getFullText() ) );
632 return wfMsgForContent( 'autoredircomment', $rt->getFullText(), $truncatedtext );
636 // New page auto-summaries
637 if ( $flags & EDIT_NEW
&& $newContent->getSize() > 0 ) {
638 // If they're making a new article, give its text, truncated, in
641 $truncatedtext = $newContent->getTextForSummary(
642 200 - strlen( wfMsgForContent( 'autosumm-new' ) ) );
644 return wfMsgForContent( 'autosumm-new', $truncatedtext );
647 // Blanking auto-summaries
648 if ( !empty( $oldContent ) && $oldContent->getSize() > 0 && $newContent->getSize() == 0 ) {
649 return wfMsgForContent( 'autosumm-blank' );
650 } elseif ( !empty( $oldContent )
651 && $oldContent->getSize() > 10 * $newContent->getSize()
652 && $newContent->getSize() < 500 )
654 // Removing more than 90% of the article
656 $truncatedtext = $newContent->getTextForSummary(
657 200 - strlen( wfMsgForContent( 'autosumm-replace' ) ) );
659 return wfMsgForContent( 'autosumm-replace', $truncatedtext );
662 // If we reach this point, there's no applicable auto-summary for our
663 // case, so our auto-summary is empty.
669 * Auto-generates a deletion reason
673 * @param $title Title: the page's title
674 * @param &$hasHistory Boolean: whether the page has a history
675 * @return mixed String containing deletion reason or empty string, or
676 * boolean false if no revision occurred
678 * @XXX &$hasHistory is extremely ugly, it's here because
679 * WikiPage::getAutoDeleteReason() and Article::getReason()
682 public function getAutoDeleteReason( Title
$title, &$hasHistory ) {
683 $dbw = wfGetDB( DB_MASTER
);
685 // Get the last revision
686 $rev = Revision
::newFromTitle( $title );
688 if ( is_null( $rev ) ) {
692 // Get the article's contents
693 $content = $rev->getContent();
696 $this->checkModelID( $content->getModel() );
698 // If the page is blank, use the text from the previous revision,
699 // which can only be blank if there's a move/import/protect dummy
701 if ( $content->getSize() == 0 ) {
702 $prev = $rev->getPrevious();
705 $content = $prev->getContent();
710 // Find out if there was only one contributor
711 // Only scan the last 20 revisions
712 $res = $dbw->select( 'revision', 'rev_user_text',
714 'rev_page' => $title->getArticleID(),
715 $dbw->bitAnd( 'rev_deleted', Revision
::DELETED_USER
) . ' = 0'
718 array( 'LIMIT' => 20 )
721 if ( $res === false ) {
722 // This page has no revisions, which is very weird
726 $hasHistory = ( $res->numRows() > 1 );
727 $row = $dbw->fetchObject( $res );
729 if ( $row ) { // $row is false if the only contributor is hidden
730 $onlyAuthor = $row->rev_user_text
;
731 // Try to find a second contributor
732 foreach ( $res as $row ) {
733 if ( $row->rev_user_text
!= $onlyAuthor ) { // Bug 22999
742 // Generate the summary with a '$1' placeholder
744 // The current revision is blank and the one before is also
745 // blank. It's just not our lucky day
746 $reason = wfMsgForContent( 'exbeforeblank', '$1' );
749 $reason = wfMsgForContent( 'excontentauthor', '$1', $onlyAuthor );
751 $reason = wfMsgForContent( 'excontent', '$1' );
755 if ( $reason == '-' ) {
756 // Allow these UI messages to be blanked out cleanly
760 // Max content length = max comment length - length of the comment (excl. $1)
761 $text = $content->getTextForSummary( 255 - ( strlen( $reason ) - 2 ) );
763 // Now replace the '$1' placeholder
764 $reason = str_replace( '$1', $text, $reason );
770 * Get the Content object that needs to be saved in order to undo all revisions
771 * between $undo and $undoafter. Revisions must belong to the same page,
772 * must exist and must not be deleted.
776 * @param $current Revision The current text
777 * @param $undo Revision The revision to undo
778 * @param $undoafter Revision Must be an earlier revision than $undo
780 * @return mixed String on success, false on failure
782 public function getUndoContent( Revision
$current, Revision
$undo, Revision
$undoafter ) {
783 $cur_content = $current->getContent();
785 if ( empty( $cur_content ) ) {
786 return false; // no page
789 $undo_content = $undo->getContent();
790 $undoafter_content = $undoafter->getContent();
792 $this->checkModelID( $cur_content->getModel() );
793 $this->checkModelID( $undo_content->getModel() );
794 $this->checkModelID( $undoafter_content->getModel() );
796 if ( $cur_content->equals( $undo_content ) ) {
797 // No use doing a merge if it's just a straight revert.
798 return $undoafter_content;
801 $undone_content = $this->merge3( $undo_content, $undoafter_content, $cur_content );
803 return $undone_content;
807 * Returns true for content models that support caching using the
808 * ParserCache mechanism. See WikiPage::isParserCacheUser().
814 public function isParserCacheSupported() {
819 * Returns true if this content model supports sections.
821 * This default implementation returns false.
823 * @return boolean whether sections are supported.
825 public function supportsSections() {
830 * Call a legacy hook that uses text instead of Content objects.
831 * Will log a warning when a matching hook function is registered.
832 * If the textual representation of the content is changed by the
833 * hook function, a new Content object is constructed from the new
836 * @param $event String: event name
837 * @param $args Array: parameters passed to hook functions
839 * @return Boolean True if no handler aborted the hook
841 public static function runLegacyHooks( $event, $args = array() ) {
842 if ( !Hooks
::isRegistered( $event ) ) {
843 return true; // nothing to do here
846 wfWarn( "Using obsolete hook $event" );
848 // convert Content objects to text
849 $contentObjects = array();
850 $contentTexts = array();
852 foreach ( $args as $k => $v ) {
853 if ( $v instanceof Content
) {
854 /* @var Content $v */
856 $contentObjects[$k] = $v;
858 $v = $v->serialize();
859 $contentTexts[ $k ] = $v;
864 // call the hook functions
865 $ok = wfRunHooks( $event, $args );
867 // see if the hook changed the text
868 foreach ( $contentTexts as $k => $orig ) {
869 /* @var Content $content */
871 $modified = $args[ $k ];
872 $content = $contentObjects[$k];
874 if ( $modified !== $orig ) {
875 // text was changed, create updated Content object
876 $content = $content->getContentHandler()->unserializeContent( $modified );
879 $args[ $k ] = $content;
889 abstract class TextContentHandler
extends ContentHandler
{
891 public function __construct( $modelId, $formats ) {
892 parent
::__construct( $modelId, $formats );
896 * Returns the content's text as-is.
898 * @param $content Content
899 * @param $format string|null
902 public function serializeContent( Content
$content, $format = null ) {
903 $this->checkFormat( $format );
904 return $content->getNativeData();
908 * Attempts to merge differences between three versions. Returns a new
909 * Content object for a clean merge and false for failure or a conflict.
911 * All three Content objects passed as parameters must have the same
914 * This text-based implementation uses wfMerge().
916 * @param $oldContent \Content|string String
917 * @param $myContent \Content|string String
918 * @param $yourContent \Content|string String
920 * @return Content|Bool
922 public function merge3( Content
$oldContent, Content
$myContent, Content
$yourContent ) {
923 $this->checkModelID( $oldContent->getModel() );
924 $this->checkModelID( $myContent->getModel() );
925 $this->checkModelID( $yourContent->getModel() );
927 $format = $this->getDefaultFormat();
929 $old = $this->serializeContent( $oldContent, $format );
930 $mine = $this->serializeContent( $myContent, $format );
931 $yours = $this->serializeContent( $yourContent, $format );
933 $ok = wfMerge( $old, $mine, $yours, $result );
940 return $this->makeEmptyContent();
943 $mergedContent = $this->unserializeContent( $result, $format );
944 return $mergedContent;
952 class WikitextContentHandler
extends TextContentHandler
{
954 public function __construct( $modelId = CONTENT_MODEL_WIKITEXT
) {
955 parent
::__construct( $modelId, array( CONTENT_FORMAT_WIKITEXT
) );
958 public function unserializeContent( $text, $format = null ) {
959 $this->checkFormat( $format );
961 return new WikitextContent( $text );
964 public function makeEmptyContent() {
965 return new WikitextContent( '' );
969 * Returns true because wikitext supports sections.
971 * @return boolean whether sections are supported.
973 public function supportsSections() {
978 # XXX: make ScriptContentHandler base class, do highlighting stuff there?
983 class JavaScriptContentHandler
extends TextContentHandler
{
985 public function __construct( $modelId = CONTENT_MODEL_JAVASCRIPT
) {
986 parent
::__construct( $modelId, array( CONTENT_FORMAT_JAVASCRIPT
) );
989 public function unserializeContent( $text, $format = null ) {
990 $this->checkFormat( $format );
992 return new JavaScriptContent( $text );
995 public function makeEmptyContent() {
996 return new JavaScriptContent( '' );
1000 * Returns the english language, because JS is english, and should be handled as such.
1002 * @return Language wfGetLangObj( 'en' )
1004 * @see ContentHandler::getPageLanguage()
1006 public function getPageLanguage( Title
$title, Content
$content = null ) {
1007 return wfGetLangObj( 'en' );
1014 class CssContentHandler
extends TextContentHandler
{
1016 public function __construct( $modelId = CONTENT_MODEL_CSS
) {
1017 parent
::__construct( $modelId, array( CONTENT_FORMAT_CSS
) );
1020 public function unserializeContent( $text, $format = null ) {
1021 $this->checkFormat( $format );
1023 return new CssContent( $text );
1026 public function makeEmptyContent() {
1027 return new CssContent( '' );
1031 * Returns the english language, because CSS is english, and should be handled as such.
1033 * @return Language wfGetLangObj( 'en' )
1035 * @see ContentHandler::getPageLanguage()
1037 public function getPageLanguage( Title
$title, Content
$content = null ) {
1038 return wfGetLangObj( 'en' );