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