some todo comments
[lhc/web/wiklou.git] / includes / ContentHandler.php
1 <?php
2
3 class MWContentSerializationException extends MWException {
4
5 }
6
7
8 /**
9 * A content handler knows how do deal with a specific type of content on a wiki page.
10 * Content is stored in the database in a serialized form (using a serialization format aka mime type)
11 * and is be unserialized into it's native PHP represenation (the content model), which is wrappe in
12 * an instance of the appropriate subclass of Content.
13 *
14 * ContentHandler instances are stateless singletons that serve, among other things, as a factory for
15 * Content objects. Generally, there is one subclass of ContentHandler and one subclass of Content
16 * for every type of content model.
17 *
18 * Some content types have a flat model, that is, their native represenation is the
19 * same as their serialized form. Examples would be JavaScript and CSS code. As of now,
20 * this also applies to wikitext (mediawiki's default content type), but wikitext
21 * content may be represented by a DOM or AST structure in the future.
22 */
23 abstract class ContentHandler {
24
25 /**
26 * Conveniance function for getting flat text from a Content object. This shleould only
27 * be used in the context of backwards compatibility with code that is not yet able
28 * to handle Content objects!
29 *
30 * If $content is equal to null or false, this method returns the empty string.
31 *
32 * If $content is an instance of TextContent, this method returns the flat text as returned by $content->getnativeData().
33 *
34 * If $content is not a TextContent object, the bahaviour of this method depends on the global $wgContentHandlerTextFallback:
35 * If $wgContentHandlerTextFallback is 'fail' and $content is not a TextContent object, an MWException is thrown.
36 * If $wgContentHandlerTextFallback is 'serialize' and $content is not a TextContent object, $content->serialize()
37 * is called to get a string form of the content.
38 * Otherwise, this method returns null.
39 *
40 * @static
41 * @param Content|null $content
42 * @return null|string the textual form of $content, if available
43 * @throws MWException if $content is not an instance of TextContent and $wgContentHandlerTextFallback was set to 'fail'.
44 */
45 public static function getContentText( Content $content = null ) {
46 global $wgContentHandlerTextFallback;
47
48 if ( is_null( $content ) ) {
49 return '';
50 }
51
52 if ( $content instanceof TextContent ) {
53 return $content->getNativeData();
54 }
55
56 if ( $wgContentHandlerTextFallback == 'fail' ) {
57 throw new MWException( "Attempt to get text from Content with model " . $content->getModelName() );
58 }
59
60 if ( $wgContentHandlerTextFallback == 'serialize' ) {
61 return $content->serialize();
62 }
63
64 return null;
65 }
66
67 /**
68 * Conveniance function for creating a Content object from a given textual representation.
69 *
70 * $text will be deserialized into a Content object of the model specified by $modelName (or,
71 * if that is not given, $title->getContentModelName()) using the given format.
72 *
73 * @static
74 * @param $text the textual represenation, will be unserialized to create the Content object
75 * @param Title $title the title of the page this text belongs to, required as a context for deserialization
76 * @param null|String $modelName the model to deserialize to. If not provided, $title->getContentModelName() is used.
77 * @param null|String $format the format to use for deserialization. If not given, the model's default format is used.
78 *
79 * @return Content a Content object representing $text
80 */
81 public static function makeContent( $text, Title $title, $modelName = null, $format = null ) {
82
83 if ( is_null( $modelName ) ) {
84 $modelName = $title->getContentModelName();
85 }
86
87 $handler = ContentHandler::getForModelName( $modelName );
88 return $handler->unserializeContent( $text, $format );
89 }
90
91 /**
92 * Returns the name of the default content model to be used for the page with the given title.
93 *
94 * Note: There should rarely be need to call this method directly.
95 * To determine the actual content model for a given page, use Title::getContentModelName().
96 *
97 * Which model is to be used per default for the page is determined based on several factors:
98 * * The global setting $wgNamespaceContentModels specifies a content model per namespace.
99 * * The hook DefaultModelFor may be used to override the page's default model.
100 * * Pages in NS_MEDIAWIKI and NS_USER default to the CSS or JavaScript model if they end in .js or .css, respectively.
101 * * Pages in NS_MEDIAWIKI default to the wikitext model otherwise.
102 * * The hook TitleIsCssOrJsPage may be used to force a page to use the CSS or JavaScript model if they end in .js or .css, respectively.
103 * * The hook TitleIsWikitextPage may be used to force a page to use the wikitext model.
104 *
105 * If none of the above applies, the wikitext model is used.
106 *
107 * Note: this is used by, and may thus not use, Title::getContentModelName()
108 *
109 * @static
110 * @param Title $title
111 * @return null|string default model name for the page given by $title
112 */
113 public static function getDefaultModelFor( Title $title ) {
114 global $wgNamespaceContentModels;
115
116 // NOTE: this method must not rely on $title->getContentModelName() directly or indirectly,
117 // because it is used to initialized the mContentModelName memebr.
118
119 $ns = $title->getNamespace();
120
121 $ext = false;
122 $m = null;
123 $model = null;
124
125 if ( !empty( $wgNamespaceContentModels[ $ns ] ) ) {
126 $model = $wgNamespaceContentModels[ $ns ];
127 }
128
129 // hook can determin default model
130 if ( !wfRunHooks( 'DefaultModelFor', array( $title, &$model ) ) ) { #FIXME: document new hook!
131 if ( !is_null( $model ) ) {
132 return $model;
133 }
134 }
135
136 // Could this page contain custom CSS or JavaScript, based on the title?
137 $isCssOrJsPage = NS_MEDIAWIKI == $ns && preg_match( '!\.(css|js)$!u', $title->getText(), $m );
138 if ( $isCssOrJsPage ) {
139 $ext = $m[1];
140 }
141
142 // hook can force js/css
143 wfRunHooks( 'TitleIsCssOrJsPage', array( $title, &$isCssOrJsPage ) );
144
145 // Is this a .css subpage of a user page?
146 $isJsCssSubpage = NS_USER == $ns && !$isCssOrJsPage && preg_match( "/\\/.*\\.(js|css)$/", $title->getText(), $m );
147 if ( $isJsCssSubpage ) {
148 $ext = $m[1];
149 }
150
151 // is this wikitext, according to $wgNamespaceContentModels or the DefaultModelFor hook?
152 $isWikitext = is_null( $model ) || $model == CONTENT_MODEL_WIKITEXT;
153 $isWikitext = $isWikitext && !$isCssOrJsPage && !$isJsCssSubpage;
154
155 // hook can override $isWikitext
156 wfRunHooks( 'TitleIsWikitextPage', array( $title, &$isWikitext ) );
157
158 if ( !$isWikitext ) {
159 switch ( $ext ) {
160 case 'js':
161 return CONTENT_MODEL_JAVASCRIPT;
162 case 'css':
163 return CONTENT_MODEL_CSS;
164 default:
165 return is_null( $model ) ? CONTENT_MODEL_TEXT : $model;
166 }
167 }
168
169 // we established that is must be wikitext
170
171 return CONTENT_MODEL_WIKITEXT;
172 }
173
174 /**
175 * returns the appropriate ContentHandler singleton for the given title
176 *
177 * @static
178 * @param Title $title
179 * @return ContentHandler
180 */
181 public static function getForTitle( Title $title ) {
182 $modelName = $title->getContentModelName();
183 return ContentHandler::getForModelName( $modelName );
184 }
185
186 /**
187 * returns the appropriate ContentHandler singleton for the given Content object
188 *
189 * @static
190 * @param Content $content
191 * @return ContentHandler
192 */
193 public static function getForContent( Content $content ) {
194 $modelName = $content->getModelName();
195 return ContentHandler::getForModelName( $modelName );
196 }
197
198 /**
199 * returns the ContentHandler singleton for the given model name. Use the CONTENT_MODEL_XXX constants to
200 * identify the desired content model.
201 *
202 * ContentHandler singletons are take from the global $wgContentHandlers array. Keys in that array are
203 * model names, the values are either ContentHandler singleton objects, or strings specifying the appropriate
204 * subclass of ContentHandler.
205 *
206 * If a class name in encountered when looking up the singleton for a given model name, the class is
207 * instantiated and the class name is replaced by te resulting singleton in $wgContentHandlers.
208 *
209 * If no ContentHandler is defined for the desired $modelName, the ContentHandler may be provided by the
210 * a ContentHandlerForModelName hook. if no Contenthandler can be determined, an MWException is raised.
211 *
212 * @static
213 * @param $modelName String the name of the content model for which to get a handler. Use CONTENT_MODEL_XXX constants.
214 * @return ContentHandler the ContentHandler singleton for handling the model given by $modelName
215 * @throws MWException if no handler is known for $modelName.
216 */
217 public static function getForModelName( $modelName ) {
218 global $wgContentHandlers;
219
220 if ( empty( $wgContentHandlers[$modelName] ) ) {
221 $handler = null;
222
223 // TODO: document new hook
224 wfRunHooks( 'ContentHandlerForModelName', array( $modelName, &$handler ) );
225
226 if ( $handler ) { // NOTE: may be a string or an object, either is fine!
227 $wgContentHandlers[$modelName] = $handler;
228 } else {
229 throw new MWException( "No handler for model $modelName registered in \$wgContentHandlers" );
230 }
231 }
232
233 if ( is_string( $wgContentHandlers[$modelName] ) ) {
234 $class = $wgContentHandlers[$modelName];
235 $wgContentHandlers[$modelName] = new $class( $modelName );
236 }
237
238 return $wgContentHandlers[$modelName];
239 }
240
241 // ----------------------------------------------------------------------------------------------------------
242
243 /**
244 * Constructor, initializing the ContentHandler instance with it's model name and a list of supported formats.
245 * Values for the parameters are typically provided as literals by subclasses' constructors.
246 *
247 * @param String $modelName (use CONTENT_MODEL_XXX constants).
248 * @param array $formats list for supported serialization formats (typically as MIME types)
249 */
250 public function __construct( $modelName, $formats ) {
251 $this->mModelName = $modelName;
252 $this->mSupportedFormats = $formats;
253 }
254
255
256 /**
257 * Serializes Content object of the type supported by this ContentHandler.
258 *
259 * @abstract
260 * @param Content $content the Content object to serialize
261 * @param null $format the desired serialization format
262 * @return String serialized form of the content
263 */
264 public abstract function serializeContent( Content $content, $format = null );
265
266 /**
267 * Unserializes a Content object of the type supported by this ContentHandler.
268 *
269 * @abstract
270 * @param $blob String serialized form of the content
271 * @param null $format the format used for serialization
272 * @return Content the Content object created by deserializing $blob
273 */
274 public abstract function unserializeContent( $blob, $format = null );
275
276 /**
277 * Creates an empty Content object of the type supported by this ContentHandler.
278 *
279 */
280 public abstract function makeEmptyContent();
281
282 /**
283 * Returns the model name that identifies the content model this ContentHandler can handle.
284 * Use with the CONTENT_MODEL_XXX constants.
285 *
286 * @return String the model name
287 */
288 public function getModelName() {
289 return $this->mModelName;
290 }
291
292 /**
293 * Throws an MWException if $modelName is not the content model handeled by this ContentHandler.
294 *
295 * @param $modelName the model name to check
296 */
297 protected function checkModelName( $modelName ) {
298 if ( $modelName !== $this->mModelName ) {
299 throw new MWException( "Bad content model: expected " . $this->mModelName . " but got found " . $modelName );
300 }
301 }
302
303 /**
304 * Returns a list of serialization formats supported by the serializeContent() and unserializeContent() methods of
305 * this ContentHandler.
306 *
307 * @return array of serialization formats as MIME type like strings
308 */
309 public function getSupportedFormats() {
310 return $this->mSupportedFormats;
311 }
312
313 /**
314 * The format used for serialization/deserialization per default by this ContentHandler.
315 *
316 * This default implementation will return the first element of the array of formats
317 * that was passed to the constructor.
318 *
319 * @return String the name of the default serialiozation format as a MIME type
320 */
321 public function getDefaultFormat() {
322 return $this->mSupportedFormats[0];
323 }
324
325 /**
326 * Returns true if $format is a serialization format supported by this ContentHandler,
327 * and false otherwise.
328 *
329 * Note that if $format is null, this method always returns true, because null
330 * means "use the default format".
331 *
332 * @param $format the serialization format to check
333 * @return bool
334 */
335 public function isSupportedFormat( $format ) {
336
337 if ( !$format ) {
338 return true; // this means "use the default"
339 }
340
341 return in_array( $format, $this->mSupportedFormats );
342 }
343
344 /**
345 * Throws an MWException if isSupportedFormat( $format ) is not true. Convenient
346 * for checking whether a format provided as a parameter is actually supported.
347 *
348 * @param $format the serialization format to check
349 */
350 protected function checkFormat( $format ) {
351 if ( !$this->isSupportedFormat( $format ) ) {
352 throw new MWException( "Format $format is not supported for content model " . $this->getModelName() );
353 }
354 }
355
356 /**
357 * Returns overrides for action handlers.
358 * Classes listed here will be used instead of the default one when
359 * (and only when) $wgActions[$action] === true. This allows subclasses
360 * to override the default action handlers.
361 *
362 * @return Array
363 */
364 public function getActionOverrides() {
365 return array();
366 }
367
368 /**
369 * Return an Article object suitable for viewing the given object
370 *
371 * NOTE: does *not* do special handling for Image and Category pages!
372 * Use Article::newFromTitle() for that!
373 *
374 * @param Title $title
375 * @return Article
376 * @todo Article is being refactored into an action class, keep track of that
377 * @todo Article really defines the view of the content... rename this method to createViewPage ?
378 */
379 public function createArticle( Title $title ) {
380 $this->checkModelName( $title->getContentModelName() );
381
382 $article = new Article($title);
383 return $article;
384 }
385
386 /**
387 * Return an EditPage object suitable for editing the given object
388 *
389 * @param Article $article
390 * @return EditPage
391 */
392 public function createEditPage( Article $article ) {
393 $this->checkModelName( $article->getContentModelName() );
394
395 $editPage = new EditPage( $article );
396 return $editPage;
397 }
398
399 /**
400 * Return an ExternalEdit object suitable for editing the given object
401 *
402 * @param IContextSource $context
403 * @return ExternalEdit
404 * @todo does anyone or anythign actually use the external edit facility? Can we just deprecate and ignore it?
405 */
406 public function createExternalEdit( IContextSource $context ) {
407 $this->checkModelName( $context->getTitle()->getModelName() );
408
409 $externalEdit = new ExternalEdit( $context );
410 return $externalEdit;
411 }
412
413 /**
414 * Factory
415 * @param $context IContextSource context to use, anything else will be ignored
416 * @param $old Integer old ID we want to show and diff with.
417 * @param $new String either 'prev' or 'next'.
418 * @param $rcid Integer ??? FIXME (default 0)
419 * @param $refreshCache boolean If set, refreshes the diff cache
420 * @param $unhide boolean If set, allow viewing deleted revs
421 *
422 * @return DifferenceEngine
423 */
424 public function createDifferenceEngine( IContextSource $context, $old = 0, $new = 0, $rcid = 0, #FIMXE: use everywhere!
425 $refreshCache = false, $unhide = false ) {
426
427 $this->checkModelName( $context->getTitle()->getModelName() );
428
429 $diffEngineClass = $this->getDiffEngineClass();
430
431 return new $diffEngineClass( $context, $old, $new, $rcid, $refreshCache, $unhide );
432 }
433
434 /**
435 * Returns the name of the diff engine to use.
436 *
437 * @since 0.1
438 *
439 * @return string
440 */
441 protected function getDiffEngineClass() {
442 return 'DifferenceEngine';
443 }
444
445 /**
446 * attempts to merge differences between three versions.
447 * Returns a new Content object for a clean merge and false for failure or a conflict.
448 *
449 * This default implementation always returns false.
450 *
451 * @param $oldContent String
452 * @param $myContent String
453 * @param $yourContent String
454 * @return Content|Bool
455 */
456 public function merge3( Content $oldContent, Content $myContent, Content $yourContent ) {
457 return false;
458 }
459
460 /**
461 * Return an applicable autosummary if one exists for the given edit.
462 *
463 * @param $oldContent Content|null: the previous text of the page.
464 * @param $newContent Content|null: The submitted text of the page.
465 * @param $flags Int bitmask: a bitmask of flags submitted for the edit.
466 *
467 * @return string An appropriate autosummary, or an empty string.
468 */
469 public function getAutosummary( Content $oldContent = null, Content $newContent = null, $flags ) {
470 global $wgContLang;
471
472 // Decide what kind of autosummary is needed.
473
474 // Redirect autosummaries
475
476 $ot = !empty( $ot ) ? $oldContent->getRedirectTarget() : false;
477 $rt = !empty( $rt ) ? $newContent->getRedirectTarget() : false;
478
479 if ( is_object( $rt ) && ( !is_object( $ot ) || !$rt->equals( $ot ) || $ot->getFragment() != $rt->getFragment() ) ) {
480
481 $truncatedtext = $newContent->getTextForSummary(
482 250
483 - strlen( wfMsgForContent( 'autoredircomment' ) )
484 - strlen( $rt->getFullText() ) );
485
486 return wfMsgForContent( 'autoredircomment', $rt->getFullText(), $truncatedtext );
487 }
488
489 // New page autosummaries
490 if ( $flags & EDIT_NEW && $newContent->getSize() > 0 ) {
491 // If they're making a new article, give its text, truncated, in the summary.
492
493 $truncatedtext = $newContent->getTextForSummary(
494 200 - strlen( wfMsgForContent( 'autosumm-new' ) ) );
495
496 return wfMsgForContent( 'autosumm-new', $truncatedtext );
497 }
498
499 // Blanking autosummaries
500 if ( !empty( $oldContent ) && $oldContent->getSize() > 0 && $newContent->getSize() == 0 ) {
501 return wfMsgForContent( 'autosumm-blank' );
502 } elseif ( !empty( $oldContent ) && $oldContent->getSize() > 10 * $newContent->getSize() && $newContent->getSize() < 500 ) {
503 // Removing more than 90% of the article
504
505 $truncatedtext = $newContent->getTextForSummary(
506 200 - strlen( wfMsgForContent( 'autosumm-replace' ) ) );
507
508 return wfMsgForContent( 'autosumm-replace', $truncatedtext );
509 }
510
511 // If we reach this point, there's no applicable autosummary for our case, so our
512 // autosummary is empty.
513
514 return '';
515 }
516
517 /**
518 * Auto-generates a deletion reason
519 *
520 * @param $title Title: the page's title
521 * @param &$hasHistory Boolean: whether the page has a history
522 * @return mixed String containing deletion reason or empty string, or boolean false
523 * if no revision occurred
524 *
525 * @todo &$hasHistory is extremely ugly, it's here because WikiPage::getAutoDeleteReason() and Article::getReason() have it / want it.
526 */
527 public function getAutoDeleteReason( Title $title, &$hasHistory ) {
528 $dbw = wfGetDB( DB_MASTER );
529
530 // Get the last revision
531 $rev = Revision::newFromTitle( $title );
532
533 if ( is_null( $rev ) ) {
534 return false;
535 }
536
537 // Get the article's contents
538 $content = $rev->getContent();
539 $blank = false;
540
541 // If the page is blank, use the text from the previous revision,
542 // which can only be blank if there's a move/import/protect dummy revision involved
543 if ( $content->getSize() == 0 ) {
544 $prev = $rev->getPrevious();
545
546 if ( $prev ) {
547 $content = $rev->getContent();
548 $blank = true;
549 }
550 }
551
552 // Find out if there was only one contributor
553 // Only scan the last 20 revisions
554 $res = $dbw->select( 'revision', 'rev_user_text',
555 array( 'rev_page' => $title->getArticleID(), $dbw->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0' ),
556 __METHOD__,
557 array( 'LIMIT' => 20 )
558 );
559
560 if ( $res === false ) {
561 // This page has no revisions, which is very weird
562 return false;
563 }
564
565 $hasHistory = ( $res->numRows() > 1 );
566 $row = $dbw->fetchObject( $res );
567
568 if ( $row ) { // $row is false if the only contributor is hidden
569 $onlyAuthor = $row->rev_user_text;
570 // Try to find a second contributor
571 foreach ( $res as $row ) {
572 if ( $row->rev_user_text != $onlyAuthor ) { // Bug 22999
573 $onlyAuthor = false;
574 break;
575 }
576 }
577 } else {
578 $onlyAuthor = false;
579 }
580
581 // Generate the summary with a '$1' placeholder
582 if ( $blank ) {
583 // The current revision is blank and the one before is also
584 // blank. It's just not our lucky day
585 $reason = wfMsgForContent( 'exbeforeblank', '$1' );
586 } else {
587 if ( $onlyAuthor ) {
588 $reason = wfMsgForContent( 'excontentauthor', '$1', $onlyAuthor );
589 } else {
590 $reason = wfMsgForContent( 'excontent', '$1' );
591 }
592 }
593
594 if ( $reason == '-' ) {
595 // Allow these UI messages to be blanked out cleanly
596 return '';
597 }
598
599 // Max content length = max comment length - length of the comment (excl. $1)
600 $text = $content->getTextForSummary( 255 - ( strlen( $reason ) - 2 ) );
601
602 // Now replace the '$1' placeholder
603 $reason = str_replace( '$1', $text, $reason );
604
605 return $reason;
606 }
607
608 #TODO: getSecondaryUpdatesForDeletion( Content ) returns an array of SecondaryDataUpdate objects
609 #... or do that in the Content class?
610
611 /**
612 * Get the Content object that needs to be saved in order to undo all revisions
613 * between $undo and $undoafter. Revisions must belong to the same page,
614 * must exist and must not be deleted
615 * @param $undo Revision
616 * @param $undoafter null|Revision Must be an earlier revision than $undo
617 * @return mixed string on success, false on failure
618 */
619 public function getUndoContent( Revision $current, Revision $undo, Revision $undoafter = null ) {
620 $cur_content = $current->getContent();
621
622 if ( empty( $cur_content ) ) {
623 return false; // no page
624 }
625
626 $undo_content = $undo->getContent();
627 $undoafter_content = $undoafter->getContent();
628
629 if ( $cur_content->equals( $undo_content ) ) {
630 // No use doing a merge if it's just a straight revert.
631 return $undoafter_content;
632 }
633
634 $undone_content = $this->merge3( $undo_content, $undoafter_content, $cur_content );
635
636 return $undone_content;
637 }
638 }
639
640
641 abstract class TextContentHandler extends ContentHandler {
642
643 public function __construct( $modelName, $formats ) {
644 parent::__construct( $modelName, $formats );
645 }
646
647 public function serializeContent( Content $content, $format = null ) {
648 $this->checkFormat( $format );
649 return $content->getNativeData();
650 }
651
652 /**
653 * attempts to merge differences between three versions.
654 * Returns a new Content object for a clean merge and false for failure or a conflict.
655 *
656 * This text-based implementation uses wfMerge().
657 *
658 * @param $oldContent String
659 * @param $myContent String
660 * @param $yourContent String
661 * @return Content|Bool
662 */
663 public function merge3( Content $oldContent, Content $myContent, Content $yourContent ) {
664 $this->checkModelName( $oldContent->getModelName() );
665 #TODO: check that all Content objects have the same content model! #XXX: what to do if they don't?
666
667 $format = $this->getDefaultFormat();
668
669 $old = $this->serializeContent( $oldContent, $format );
670 $mine = $this->serializeContent( $myContent, $format );
671 $yours = $this->serializeContent( $yourContent, $format );
672
673 $ok = wfMerge( $old, $mine, $yours, $result );
674
675 if ( !$ok ) {
676 return false;
677 }
678
679 if ( !$result ) {
680 return $this->makeEmptyContent();
681 }
682
683 $mergedContent = $this->unserializeContent( $result, $format );
684 return $mergedContent;
685 }
686
687
688 }
689 class WikitextContentHandler extends TextContentHandler {
690
691 public function __construct( $modelName = CONTENT_MODEL_WIKITEXT ) {
692 parent::__construct( $modelName, array( 'application/x-wikitext' ) ); #FIXME: mime
693 }
694
695 public function unserializeContent( $text, $format = null ) {
696 $this->checkFormat( $format );
697
698 return new WikitextContent( $text );
699 }
700
701 public function makeEmptyContent() {
702 return new WikitextContent( '' );
703 }
704
705
706 }
707
708 #TODO: make ScriptContentHandler base class with plugin interface for syntax highlighting!
709
710 class JavaScriptContentHandler extends TextContentHandler {
711
712 public function __construct( $modelName = CONTENT_MODEL_WIKITEXT ) {
713 parent::__construct( $modelName, array( 'text/javascript' ) ); #XXX: or use $wgJsMimeType? this is for internal storage, not HTTP...
714 }
715
716 public function unserializeContent( $text, $format = null ) {
717 return new JavaScriptContent( $text );
718 }
719
720 public function makeEmptyContent() {
721 return new JavaScriptContent( '' );
722 }
723 }
724
725 class CssContentHandler extends TextContentHandler {
726
727 public function __construct( $modelName = CONTENT_MODEL_WIKITEXT ) {
728 parent::__construct( $modelName, array( 'text/css' ) );
729 }
730
731 public function unserializeContent( $text, $format = null ) {
732 return new CssContent( $text );
733 }
734
735 public function makeEmptyContent() {
736 return new CssContent( '' );
737 }
738
739 }