Merge branch 'Wikidata' of ssh://review/mediawiki/core into Wikidata
[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->unserialize( $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 * @FIXME: bad method name: suggests it serializes a ContentHandler, while in fact it serializes a Content object
260 *
261 * @abstract
262 * @param Content $content the Content object to serialize
263 * @param null $format the desired serialization format
264 * @return String serialized form of the content
265 */
266 public abstract function serialize( Content $content, $format = null );
267
268 /**
269 * Unserializes a Content object of the type supported by this ContentHandler.
270 *
271 * @FIXME: bad method name: suggests it unserializes a ContentHandler, while in fact it unserializes a Content object
272 *
273 * @abstract
274 * @param $blob String serialized form of the content
275 * @param null $format the format used for serialization
276 * @return Content the Content object created by deserializing $blob
277 */
278 public abstract function unserialize( $blob, $format = null );
279
280 /**
281 * Creates an empty Content object of the type supported by this ContentHandler.
282 *
283 * @FIXME: bad method name: suggests it empties the content of an instance rather then creating a new empty one
284 */
285 public abstract function emptyContent();
286
287 /**
288 * Returns the model name that identifies the content model this ContentHandler can handle.
289 * Use with the CONTENT_MODEL_XXX constants.
290 *
291 * @return String the model name
292 */
293 public function getModelName() {
294 return $this->mModelName;
295 }
296
297 /**
298 * Throws an MWException if $modelName is not the content model handeled by this ContentHandler.
299 *
300 * @param $modelName the model name to check
301 */
302 protected function checkModelName( $modelName ) {
303 if ( $modelName !== $this->mModelName ) {
304 throw new MWException( "Bad content model: expected " . $this->mModelName . " but got found " . $modelName );
305 }
306 }
307
308 /**
309 * Returns a list of serialization formats supported by the serialize() and unserialize() methods of
310 * this ContentHandler.
311 *
312 * @return array of serialization formats as MIME type like strings
313 */
314 public function getSupportedFormats() {
315 return $this->mSupportedFormats;
316 }
317
318 /**
319 * The format used for serialization/deserialization per default by this ContentHandler.
320 *
321 * This default implementation will return the first element of the array of formats
322 * that was passed to the constructor.
323 *
324 * @return String the name of the default serialiozation format as a MIME type
325 */
326 public function getDefaultFormat() {
327 return $this->mSupportedFormats[0];
328 }
329
330 /**
331 * Returns true if $format is a serialization format supported by this ContentHandler,
332 * and false otherwise.
333 *
334 * Note that if $format is null, this method always returns true, because null
335 * means "use the default format".
336 *
337 * @param $format the serialization format to check
338 * @return bool
339 */
340 public function isSupportedFormat( $format ) {
341
342 if ( !$format ) {
343 return true; // this means "use the default"
344 }
345
346 return in_array( $format, $this->mSupportedFormats );
347 }
348
349 /**
350 * Throws an MWException if isSupportedFormat( $format ) is not true. Convenient
351 * for checking whether a format provided as a parameter is actually supported.
352 *
353 * @param $format the serialization format to check
354 */
355 protected function checkFormat( $format ) {
356 if ( !$this->isSupportedFormat( $format ) ) {
357 throw new MWException( "Format $format is not supported for content model " . $this->getModelName() );
358 }
359 }
360
361 /**
362 * Returns overrides for action handlers.
363 * Classes listed here will be used instead of the default one when
364 * (and only when) $wgActions[$action] === true. This allows subclasses
365 * to override the default actiuon handlers.
366 *
367 * @return Array
368 */
369 public function getActionOverrides() {
370 return array();
371 }
372
373 /**
374 * Return an Article object suitable for viewing the given object
375 *
376 * NOTE: does *not* do special handling for Image and Category pages!
377 * Use Article::newFromTitle() for that!
378 *
379 * @param Title $title
380 * @return Article
381 * @todo Article is being refactored into an action class, keep track of that
382 * @todo Article really defines the view of the content... rename this method to createViewPage ?
383 */
384 public function createArticle( Title $title ) {
385 $this->checkModelName( $title->getContentModelName() );
386
387 $article = new Article($title);
388 return $article;
389 }
390
391 /**
392 * Return an EditPage object suitable for editing the given object
393 *
394 * @param Article $article
395 * @return EditPage
396 */
397 public function createEditPage( Article $article ) {
398 $this->checkModelName( $article->getContentModelName() );
399
400 $editPage = new EditPage( $article );
401 return $editPage;
402 }
403
404 /**
405 * Return an ExternalEdit object suitable for editing the given object
406 *
407 * @param IContextSource $context
408 * @return ExternalEdit
409 * @todo does anyone or anythign actually use the external edit facility? Can we just deprecate and ignore it?
410 */
411 public function createExternalEdit( IContextSource $context ) {
412 $this->checkModelName( $context->getTitle()->getModelName() );
413
414 $externalEdit = new ExternalEdit( $context );
415 return $externalEdit;
416 }
417
418 /**
419 * Factory
420 * @param $context IContextSource context to use, anything else will be ignored
421 * @param $old Integer old ID we want to show and diff with.
422 * @param $new String either 'prev' or 'next'.
423 * @param $rcid Integer ??? FIXME (default 0)
424 * @param $refreshCache boolean If set, refreshes the diff cache
425 * @param $unhide boolean If set, allow viewing deleted revs
426 *
427 * @return DifferenceEngine
428 * @todo rename to createDifferenceEngine for consistency.
429 */
430 public function getDifferenceEngine( IContextSource $context, $old = 0, $new = 0, $rcid = 0, #FIMXE: use everywhere!
431 $refreshCache = false, $unhide = false ) {
432
433 $this->checkModelName( $context->getTitle()->getModelName() );
434
435 $diffEngineClass = $this->getDiffEngineClass();
436
437 return new $diffEngineClass( $context, $old, $new, $rcid, $refreshCache, $unhide );
438 }
439
440 /**
441 * Returns the name of the diff engine to use.
442 *
443 * @since 0.1
444 *
445 * @return string
446 */
447 protected function getDiffEngineClass() {
448 return 'DifferenceEngine';
449 }
450
451 /**
452 * attempts to merge differences between three versions.
453 * Returns a new Content object for a clean merge and false for failure or a conflict.
454 *
455 * This default implementation always returns false.
456 *
457 * @param $oldContent String
458 * @param $myContent String
459 * @param $yourContent String
460 * @return Content|Bool
461 */
462 public function merge3( Content $oldContent, Content $myContent, Content $yourContent ) {
463 return false;
464 }
465
466 /**
467 * Return an applicable autosummary if one exists for the given edit.
468 *
469 * @param $oldContent Content|null: the previous text of the page.
470 * @param $newContent Content|null: The submitted text of the page.
471 * @param $flags Int bitmask: a bitmask of flags submitted for the edit.
472 *
473 * @return string An appropriate autosummary, or an empty string.
474 */
475 public function getAutosummary( Content $oldContent = null, Content $newContent = null, $flags ) {
476 global $wgContLang;
477
478 // Decide what kind of autosummary is needed.
479
480 // Redirect autosummaries
481
482 $ot = !empty( $ot ) ? $oldContent->getRedirectTarget() : false;
483 $rt = !empty( $rt ) ? $newContent->getRedirectTarget() : false;
484
485 if ( is_object( $rt ) && ( !is_object( $ot ) || !$rt->equals( $ot ) || $ot->getFragment() != $rt->getFragment() ) ) {
486
487 $truncatedtext = $newContent->getTextForSummary(
488 250
489 - strlen( wfMsgForContent( 'autoredircomment' ) )
490 - strlen( $rt->getFullText() ) );
491
492 return wfMsgForContent( 'autoredircomment', $rt->getFullText(), $truncatedtext );
493 }
494
495 // New page autosummaries
496 if ( $flags & EDIT_NEW && $newContent->getSize() > 0 ) {
497 // If they're making a new article, give its text, truncated, in the summary.
498
499 $truncatedtext = $newContent->getTextForSummary(
500 200 - strlen( wfMsgForContent( 'autosumm-new' ) ) );
501
502 return wfMsgForContent( 'autosumm-new', $truncatedtext );
503 }
504
505 // Blanking autosummaries
506 if ( $oldContent->getSize() > 0 && $newContent->getSize() == 0 ) {
507 return wfMsgForContent( 'autosumm-blank' );
508 } elseif ( $oldContent->getSize() > 10 * $newContent->getSize() && $newContent->getSize() < 500 ) {
509 // Removing more than 90% of the article
510
511 $truncatedtext = $newContent->getTextForSummary(
512 200 - strlen( wfMsgForContent( 'autosumm-replace' ) ) );
513
514 return wfMsgForContent( 'autosumm-replace', $truncatedtext );
515 }
516
517 // If we reach this point, there's no applicable autosummary for our case, so our
518 // autosummary is empty.
519
520 return '';
521 }
522
523 /**
524 * Auto-generates a deletion reason
525 *
526 * @param $title Title: the page's title
527 * @param &$hasHistory Boolean: whether the page has a history
528 * @return mixed String containing deletion reason or empty string, or boolean false
529 * if no revision occurred
530 *
531 * @todo &$hasHistory is extremely ugly, it's here because WikiPage::getAutoDeleteReason() and Article::getReason() have it / want it.
532 */
533 public function getAutoDeleteReason( Title $title, &$hasHistory ) {
534 $dbw = wfGetDB( DB_MASTER );
535
536 // Get the last revision
537 $rev = Revision::newFromTitle( $title );
538
539 if ( is_null( $rev ) ) {
540 return false;
541 }
542
543 // Get the article's contents
544 $content = $rev->getContent();
545 $blank = false;
546
547 // If the page is blank, use the text from the previous revision,
548 // which can only be blank if there's a move/import/protect dummy revision involved
549 if ( $content->getSize() == 0 ) {
550 $prev = $rev->getPrevious();
551
552 if ( $prev ) {
553 $content = $rev->getContent();
554 $blank = true;
555 }
556 }
557
558 // Find out if there was only one contributor
559 // Only scan the last 20 revisions
560 $res = $dbw->select( 'revision', 'rev_user_text',
561 array( 'rev_page' => $title->getArticleID(), $dbw->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0' ),
562 __METHOD__,
563 array( 'LIMIT' => 20 )
564 );
565
566 if ( $res === false ) {
567 // This page has no revisions, which is very weird
568 return false;
569 }
570
571 $hasHistory = ( $res->numRows() > 1 );
572 $row = $dbw->fetchObject( $res );
573
574 if ( $row ) { // $row is false if the only contributor is hidden
575 $onlyAuthor = $row->rev_user_text;
576 // Try to find a second contributor
577 foreach ( $res as $row ) {
578 if ( $row->rev_user_text != $onlyAuthor ) { // Bug 22999
579 $onlyAuthor = false;
580 break;
581 }
582 }
583 } else {
584 $onlyAuthor = false;
585 }
586
587 // Generate the summary with a '$1' placeholder
588 if ( $blank ) {
589 // The current revision is blank and the one before is also
590 // blank. It's just not our lucky day
591 $reason = wfMsgForContent( 'exbeforeblank', '$1' );
592 } else {
593 if ( $onlyAuthor ) {
594 $reason = wfMsgForContent( 'excontentauthor', '$1', $onlyAuthor );
595 } else {
596 $reason = wfMsgForContent( 'excontent', '$1' );
597 }
598 }
599
600 if ( $reason == '-' ) {
601 // Allow these UI messages to be blanked out cleanly
602 return '';
603 }
604
605 // Max content length = max comment length - length of the comment (excl. $1)
606 $text = $content->getTextForSummary( 255 - ( strlen( $reason ) - 2 ) );
607
608 // Now replace the '$1' placeholder
609 $reason = str_replace( '$1', $text, $reason );
610
611 return $reason;
612 }
613
614 /**
615 * Get the Content object that needs to be saved in order to undo all revisions
616 * between $undo and $undoafter. Revisions must belong to the same page,
617 * must exist and must not be deleted
618 * @param $undo Revision
619 * @param $undoafter null|Revision Must be an earlier revision than $undo
620 * @return mixed string on success, false on failure
621 */
622 public function getUndoContent( Revision $current, Revision $undo, Revision $undoafter = null ) {
623 $cur_content = $current->getContent();
624
625 if ( empty( $cur_content ) ) {
626 return false; // no page
627 }
628
629 $undo_content = $undo->getContent();
630 $undoafter_content = $undoafter->getContent();
631
632 if ( $cur_content->equals( $undo_content ) ) {
633 // No use doing a merge if it's just a straight revert.
634 return $undoafter_content;
635 }
636
637 $undone_content = $this->merge3( $undo_content, $undoafter_content, $cur_content );
638
639 return $undone_content;
640 }
641 }
642
643
644 abstract class TextContentHandler extends ContentHandler {
645
646 public function __construct( $modelName, $formats ) {
647 parent::__construct( $modelName, $formats );
648 }
649
650 public function serialize( Content $content, $format = null ) {
651 $this->checkFormat( $format );
652 return $content->getNativeData();
653 }
654
655 /**
656 * attempts to merge differences between three versions.
657 * Returns a new Content object for a clean merge and false for failure or a conflict.
658 *
659 * This text-based implementation uses wfMerge().
660 *
661 * @param $oldContent String
662 * @param $myContent String
663 * @param $yourContent String
664 * @return Content|Bool
665 */
666 public function merge3( Content $oldContent, Content $myContent, Content $yourContent ) {
667 $this->checkModelName( $oldContent->getModelName() );
668 #TODO: check that all Content objects have the same content model! #XXX: what to do if they don't?
669
670 $format = $this->getDefaultFormat();
671
672 $old = $this->serialize( $oldContent, $format );
673 $mine = $this->serialize( $myContent, $format );
674 $yours = $this->serialize( $yourContent, $format );
675
676 $ok = wfMerge( $old, $mine, $yours, $result );
677
678 if ( !$ok ) {
679 return false;
680 }
681
682 if ( !$result ) {
683 return $this->emptyContent();
684 }
685
686 $mergedContent = $this->unserialize( $result, $format );
687 return $mergedContent;
688 }
689
690
691 }
692 class WikitextContentHandler extends TextContentHandler {
693
694 public function __construct( $modelName = CONTENT_MODEL_WIKITEXT ) {
695 parent::__construct( $modelName, array( 'application/x-wikitext' ) ); #FIXME: mime
696 }
697
698 public function unserialize( $text, $format = null ) {
699 $this->checkFormat( $format );
700
701 return new WikitextContent( $text );
702 }
703
704 public function emptyContent() {
705 return new WikitextContent( '' );
706 }
707
708
709 }
710
711 #TODO: make ScriptContentHandler base class with plugin interface for syntax highlighting!
712
713 class JavaScriptContentHandler extends TextContentHandler {
714
715 public function __construct( $modelName = CONTENT_MODEL_WIKITEXT ) {
716 parent::__construct( $modelName, array( 'text/javascript' ) ); #XXX: or use $wgJsMimeType? this is for internal storage, not HTTP...
717 }
718
719 public function unserialize( $text, $format = null ) {
720 return new JavaScriptContent( $text );
721 }
722
723 public function emptyContent() {
724 return new JavaScriptContent( '' );
725 }
726 }
727
728 class CssContentHandler extends TextContentHandler {
729
730 public function __construct( $modelName = CONTENT_MODEL_WIKITEXT ) {
731 parent::__construct( $modelName, array( 'text/css' ) );
732 }
733
734 public function unserialize( $text, $format = null ) {
735 return new CssContent( $text );
736 }
737
738 public function emptyContent() {
739 return new CssContent( '' );
740 }
741
742 }