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