Use Title, not IContextSource; remove createArticle, etc.
[lhc/web/wiklou.git] / includes / Content.php
1 <?php
2
3 /**
4 * A content object represents page content, e.g. the text to show on a page.
5 * Content objects have no knowledge about how they relate to Wiki pages.
6 *
7 * @since 1.WD
8 */
9 abstract class Content {
10
11 /**
12 * Name of the content model this Content object represents.
13 * Use with CONTENT_MODEL_XXX constants
14 *
15 * @var String $model_id
16 */
17 protected $model_id;
18
19 /**
20 * @since WD.1
21 *
22 * @return String a string representing the content in a way useful for building a full text search index.
23 * If no useful representation exists, this method returns an empty string.
24 */
25 public abstract function getTextForSearchIndex( );
26
27 /**
28 * @since WD.1
29 *
30 * @return String the wikitext to include when another page includes this content, or false if the content is not
31 * includable in a wikitext page.
32 *
33 * @TODO: allow native handling, bypassing wikitext representation, like for includable special pages.
34 * @TODO: use in parser, etc!
35 */
36 public abstract function getWikitextForTransclusion( );
37
38 /**
39 * Returns a textual representation of the content suitable for use in edit summaries and log messages.
40 *
41 * @since WD.1
42 *
43 * @param int $maxlength maximum length of the summary text
44 * @return String the summary text
45 */
46 public abstract function getTextForSummary( $maxlength = 250 );
47
48 /**
49 * Returns native represenation of the data. Interpretation depends on the data model used,
50 * as given by getDataModel().
51 *
52 * @since WD.1
53 *
54 * @return mixed the native representation of the content. Could be a string, a nested array
55 * structure, an object, a binary blob... anything, really.
56 *
57 * @NOTE: review all calls carefully, caller must be aware of content model!
58 */
59 public abstract function getNativeData( );
60
61 /**
62 * returns the content's nominal size in bogo-bytes.
63 *
64 * @return int
65 */
66 public abstract function getSize( );
67
68 /**
69 * @param int $model_id
70 */
71 public function __construct( $model_id = null ) {
72 $this->model_id = $model_id;
73 }
74
75 /**
76 * Returns the id of the content model used by this content objects.
77 * Corresponds to the CONTENT_MODEL_XXX constants.
78 *
79 * @since WD.1
80 *
81 * @return int the model id
82 */
83 public function getModel() {
84 return $this->model_id;
85 }
86
87 /**
88 * Throws an MWException if $model_id is not the id of the content model
89 * supported by this Content object.
90 *
91 * @param int $model_id the model to check
92 */
93 protected function checkModelID( $model_id ) {
94 if ( $model_id !== $this->model_id ) {
95 $model_name = ContentHandler::getContentModelName( $model_id );
96 $own_model_name = ContentHandler::getContentModelName( $this->model_id );
97
98 throw new MWException( "Bad content model: expected {$this->model_id} ($own_model_name) but got found $model_id ($model_name)." );
99 }
100 }
101
102 /**
103 * Conveniance method that returns the ContentHandler singleton for handling the content
104 * model this Content object uses.
105 *
106 * Shorthand for ContentHandler::getForContent( $this )
107 *
108 * @since WD.1
109 *
110 * @return ContentHandler
111 */
112 public function getContentHandler() {
113 return ContentHandler::getForContent( $this );
114 }
115
116 /**
117 * Conveniance method that returns the default serialization format for the content model
118 * model this Content object uses.
119 *
120 * Shorthand for $this->getContentHandler()->getDefaultFormat()
121 *
122 * @since WD.1
123 *
124 * @return ContentHandler
125 */
126 public function getDefaultFormat() {
127 return $this->getContentHandler()->getDefaultFormat();
128 }
129
130 /**
131 * Conveniance method that returns the list of serialization formats supported
132 * for the content model model this Content object uses.
133 *
134 * Shorthand for $this->getContentHandler()->getSupportedFormats()
135 *
136 * @since WD.1
137 *
138 * @return array of supported serialization formats
139 */
140 public function getSupportedFormats() {
141 return $this->getContentHandler()->getSupportedFormats();
142 }
143
144 /**
145 * Returns true if $format is a supported serialization format for this Content object,
146 * false if it isn't.
147 *
148 * Note that this will always return true if $format is null, because null stands for the
149 * default serialization.
150 *
151 * Shorthand for $this->getContentHandler()->isSupportedFormat( $format )
152 *
153 * @since WD.1
154 *
155 * @param String $format the format to check
156 * @return bool whether the format is supported
157 */
158 public function isSupportedFormat( $format ) {
159 if ( !$format ) {
160 return true; // this means "use the default"
161 }
162
163 return $this->getContentHandler()->isSupportedFormat( $format );
164 }
165
166 /**
167 * Throws an MWException if $this->isSupportedFormat( $format ) doesn't return true.
168 *
169 * @param $format
170 * @throws MWException
171 */
172 protected function checkFormat( $format ) {
173 if ( !$this->isSupportedFormat( $format ) ) {
174 throw new MWException( "Format $format is not supported for content model " . $this->getModel() );
175 }
176 }
177
178 /**
179 * Conveniance method for serializing this Content object.
180 *
181 * Shorthand for $this->getContentHandler()->serializeContent( $this, $format )
182 *
183 * @since WD.1
184 *
185 * @param null|String $format the desired serialization format (or null for the default format).
186 * @return String serialized form of this Content object
187 */
188 public function serialize( $format = null ) {
189 return $this->getContentHandler()->serializeContent( $this, $format );
190 }
191
192 /**
193 * Returns true if this Content object represents empty content.
194 *
195 * @since WD.1
196 *
197 * @return bool whether this Content object is empty
198 */
199 public function isEmpty() {
200 return $this->getSize() == 0;
201 }
202
203 /**
204 * Returns if the content is valid.
205 * It needs to be valid before it can be saved.
206 *
207 * @since WD.1
208 *
209 * @return boolean
210 */
211 public function isValid() {
212 // TODO
213 return true;
214 }
215
216 /**
217 * Diff the content object with what is currently stored in the database.
218 * If it is not currently stored, it will be diffed with an empty object.
219 *
220 * @since WD.diff
221 *
222 * @return ContentDiff
223 */
224 public function diffToDatabase() {
225 // TODO
226 }
227
228 /**
229 * Returns true if this Content objects is conceptually equivalent to the given Content object.
230 *
231 * Will returns false if $that is null.
232 * Will return true if $that === $this.
233 * Will return false if $that->getModleName() != $this->getModel().
234 * Will return false if $that->getNativeData() is not equal to $this->getNativeData(),
235 * where the meaning of "equal" depends on the actual data model.
236 *
237 * Implementations should be careful to make equals() transitive and reflexive:
238 *
239 * * $a->equals( $b ) <=> $b->equals( $b )
240 * * $a->equals( $b ) && $b->equals( $c ) ==> $a->equals( $c )
241 *
242 * @since WD.1
243 *
244 * @param Content $that the Content object to compare to
245 * @return bool true if this Content object is euqual to $that, false otherwise.
246 */
247 public function equals( Content $that = null ) {
248 if ( is_null( $that ) ){
249 return false;
250 }
251
252 if ( $that === $this ) {
253 return true;
254 }
255
256 if ( $that->getModel() !== $this->getModel() ) {
257 return false;
258 }
259
260 return $this->getNativeData() === $that->getNativeData();
261 }
262
263 /**
264 * Return a copy of this Content object. The following must be true for the object returned
265 * if $copy = $original->copy()
266 *
267 * * get_class($original) === get_class($copy)
268 * * $original->getModel() === $copy->getModel()
269 * * $original->equals( $copy )
270 *
271 * If and only if the Content object is imutable, the copy() method can and should
272 * return $this. That is, $copy === $original may be true, but only for imutable content
273 * objects.
274 *
275 * @since WD.1
276 *
277 * @return Content. A copy of this object
278 */
279 public abstract function copy( );
280
281 /**
282 * Returns true if this content is countable as a "real" wiki page, provided
283 * that it's also in a countable location (e.g. a current revision in the main namespace).
284 *
285 * @since WD.1
286 *
287 * @param $hasLinks Bool: if it is known whether this content contains links, provide this information here,
288 * to avoid redundant parsing to find out.
289 * @return boolean
290 */
291 public abstract function isCountable( $hasLinks = null ) ;
292
293 /**
294 * @param Title $title
295 * @param null $revId
296 * @param null|ParserOptions $options
297 * @param Boolean $generateHtml whether to generate Html (default: true). If false,
298 * the result of calling getText() on the ParserOutput object returned by
299 * this method is undefined.
300 *
301 * @since WD.1
302 *
303 * @return ParserOutput
304 */
305 public abstract function getParserOutput( Title $title, $revId = null, ParserOptions $options = null, $generateHtml = true );
306
307 /**
308 * Returns a list of DataUpdate objects for recording information about this Content in some secondary
309 * data store. If the optional second argument, $old, is given, the updates may model only the changes that
310 * need to be made to replace information about the old content with infomration about the new content.
311 *
312 * This default implementation calls $this->getParserOutput( $title, null, null, false ), and then
313 * calls getSecondaryDataUpdates( $title, $recursive ) on the resulting ParserOutput object.
314 *
315 * Subclasses may implement this to determine the necessary updates more efficiently, or make use of information
316 * about the old content.
317 *
318 * @param Title $title the context for determining the necessary updates
319 * @param Content|null $old a Content object representing the previous content, i.e. the content being
320 * replaced by this Content object.
321 * @param bool $recursive whether to include recursive updates (default: false).
322 *
323 * @return Array. A list of DataUpdate objects for putting information about this content object somewhere.
324 *
325 * @since WD.1
326 */
327 public function getSecondaryDataUpdates( Title $title, Content $old = null, $recursive = false ) {
328 $po = $this->getParserOutput( $title, null, null, false );
329 return $po->getSecondaryDataUpdates( $title, $recursive );
330 }
331
332 /**
333 * Construct the redirect destination from this content and return an
334 * array of Titles, or null if this content doesn't represent a redirect.
335 * The last element in the array is the final destination after all redirects
336 * have been resolved (up to $wgMaxRedirects times).
337 *
338 * @since WD.1
339 *
340 * @return Array of Titles, with the destination last
341 */
342 public function getRedirectChain() {
343 return null;
344 }
345
346 /**
347 * Construct the redirect destination from this content and return an
348 * array of Titles, or null if this content doesn't represent a redirect.
349 * This will only return the immediate redirect target, useful for
350 * the redirect table and other checks that don't need full recursion.
351 *
352 * @since WD.1
353 *
354 * @return Title: The corresponding Title
355 */
356 public function getRedirectTarget() {
357 return null;
358 }
359
360 /**
361 * Construct the redirect destination from this content and return the
362 * Title, or null if this content doesn't represent a redirect.
363 * This will recurse down $wgMaxRedirects times or until a non-redirect target is hit
364 * in order to provide (hopefully) the Title of the final destination instead of another redirect.
365 *
366 * @since WD.1
367 *
368 * @return Title
369 */
370 public function getUltimateRedirectTarget() {
371 return null;
372 }
373
374 /**
375 * @since WD.1
376 *
377 * @return bool
378 */
379 public function isRedirect() {
380 return $this->getRedirectTarget() !== null;
381 }
382
383 /**
384 * Returns the section with the given id.
385 *
386 * The default implementation returns null.
387 *
388 * @since WD.1
389 *
390 * @param String $sectionId the section's id, given as a numeric string. The id "0" retrieves the section before
391 * the first heading, "1" the text between the first heading (inluded) and the second heading (excluded), etc.
392 * @return Content|Boolean|null the section, or false if no such section exist, or null if sections are not supported
393 */
394 public function getSection( $sectionId ) {
395 return null;
396 }
397
398 /**
399 * Replaces a section of the content and returns a Content object with the section replaced.
400 *
401 * @since WD.1
402 *
403 * @param $section empty/null/false or a section number (0, 1, 2, T1, T2...), or "new"
404 * @param $with Content: new content of the section
405 * @param $sectionTitle String: new section's subject, only if $section is 'new'
406 * @return string Complete article text, or null if error
407 */
408 public function replaceSection( $section, Content $with, $sectionTitle = '' ) {
409 return null;
410 }
411
412 /**
413 * Returns a Content object with pre-save transformations applied (or this object if no transformations apply).
414 *
415 * @since WD.1
416 *
417 * @param Title $title
418 * @param User $user
419 * @param null|ParserOptions $popts
420 * @return Content
421 */
422 public function preSaveTransform( Title $title, User $user, ParserOptions $popts ) {
423 return $this;
424 }
425
426 /**
427 * Returns a new WikitextContent object with the given section heading prepended, if supported.
428 * The default implementation just returns this Content object unmodified, ignoring the section header.
429 *
430 * @since WD.1
431 *
432 * @param $header String
433 * @return Content
434 */
435 public function addSectionHeader( $header ) {
436 return $this;
437 }
438
439 /**
440 * Returns a Content object with preload transformations applied (or this object if no transformations apply).
441 *
442 * @since WD.1
443 *
444 * @param Title $title
445 * @param null|ParserOptions $popts
446 * @return Content
447 */
448 public function preloadTransform( Title $title, ParserOptions $popts ) {
449 return $this;
450 }
451
452 # TODO: handle ImagePage and CategoryPage
453 # TODO: make sure we cover lucene search / wikisearch.
454 # TODO: make sure ReplaceTemplates still works
455 # FUTURE: nice&sane integration of GeSHi syntax highlighting
456 # [11:59] <vvv> Hooks are ugly; make CodeHighlighter interface and a config to set the class which handles syntax highlighting
457 # [12:00] <vvv> And default it to a DummyHighlighter
458
459 # TODO: make sure we cover the external editor interface (does anyone actually use that?!)
460
461 # TODO: tie into API to provide contentModel for Revisions
462 # TODO: tie into API to provide serialized version and contentFormat for Revisions
463 # TODO: tie into API edit interface
464 # FUTURE: make EditForm plugin for EditPage
465 }
466 # FUTURE: special type for redirects?!
467 # FUTURE: MultipartMultipart < WikipageContent (Main + Links + X)
468 # FUTURE: LinksContent < LanguageLinksContent, CategoriesContent
469
470 /**
471 * Content object implementation for representing flat text.
472 *
473 * TextContent instances are imutable
474 *
475 * @since WD.1
476 */
477 abstract class TextContent extends Content {
478
479 public function __construct( $text, $model_id = null ) {
480 parent::__construct( $model_id );
481
482 $this->mText = $text;
483 }
484
485 public function copy() {
486 return $this; #NOTE: this is ok since TextContent are imutable.
487 }
488
489 public function getTextForSummary( $maxlength = 250 ) {
490 global $wgContLang;
491
492 $text = $this->getNativeData();
493
494 $truncatedtext = $wgContLang->truncate(
495 preg_replace( "/[\n\r]/", ' ', $text ),
496 max( 0, $maxlength ) );
497
498 return $truncatedtext;
499 }
500
501 /**
502 * returns the text's size in bytes.
503 *
504 * @return int the size
505 */
506 public function getSize( ) {
507 $text = $this->getNativeData( );
508 return strlen( $text );
509 }
510
511 /**
512 * Returns true if this content is not a redirect, and $wgArticleCountMethod is "any".
513 *
514 * @param $hasLinks Bool: if it is known whether this content contains links, provide this information here,
515 * to avoid redundant parsing to find out.
516 *
517 * @return bool true if the content is countable
518 */
519 public function isCountable( $hasLinks = null ) {
520 global $wgArticleCountMethod;
521
522 if ( $this->isRedirect( ) ) {
523 return false;
524 }
525
526 if ( $wgArticleCountMethod === 'any' ) {
527 return true;
528 }
529
530 return false;
531 }
532
533 /**
534 * Returns the text represented by this Content object, as a string.
535 *
536 * @return String the raw text
537 */
538 public function getNativeData( ) {
539 $text = $this->mText;
540 return $text;
541 }
542
543 /**
544 * Returns the text represented by this Content object, as a string.
545 *
546 * @return String the raw text
547 */
548 public function getTextForSearchIndex( ) {
549 return $this->getNativeData();
550 }
551
552 /**
553 * Returns the text represented by this Content object, as a string.
554 *
555 * @return String the raw text
556 */
557 public function getWikitextForTransclusion( ) {
558 return $this->getNativeData();
559 }
560
561 /**
562 * Returns a generic ParserOutput object, wrapping the HTML returned by getHtml().
563 *
564 * @return ParserOutput representing the HTML form of the text
565 */
566 public function getParserOutput( Title $title, $revId = null, ParserOptions $options = null, $generateHtml = true ) {
567 # generic implementation, relying on $this->getHtml()
568
569 if ( $generateHtml ) $html = $this->getHtml( $options );
570 else $html = '';
571
572 $po = new ParserOutput( $html );
573
574 return $po;
575 }
576
577 protected abstract function getHtml( );
578
579 }
580
581 /**
582 * @since WD.1
583 */
584 class WikitextContent extends TextContent {
585
586 public function __construct( $text ) {
587 parent::__construct($text, CONTENT_MODEL_WIKITEXT);
588 }
589
590 protected function getHtml( ) {
591 throw new MWException( "getHtml() not implemented for wikitext. Use getParserOutput()->getText()." );
592 }
593
594 /**
595 * Returns a ParserOutput object resulting from parsing the content's text using $wgParser.
596 *
597 * @since WikiData1
598 *
599 * @param IContextSource|null $context
600 * @param null $revId
601 * @param null|ParserOptions $options
602 * @param bool $generateHtml
603 *
604 * @return ParserOutput representing the HTML form of the text
605 */
606 public function getParserOutput( Title $title, $revId = null, ParserOptions $options = null, $generateHtml = true ) {
607 global $wgParser;
608
609 if ( !$options ) {
610 $options = new ParserOptions();
611 }
612
613 $po = $wgParser->parse( $this->mText, $title, $options, true, true, $revId );
614
615 return $po;
616 }
617
618 /**
619 * Returns the section with the given id.
620 *
621 * @param String $sectionId the section's id
622 * @return Content|false|null the section, or false if no such section exist, or null if sections are not supported
623 */
624 public function getSection( $section ) {
625 global $wgParser;
626
627 $text = $this->getNativeData();
628 $sect = $wgParser->getSection( $text, $section, false );
629
630 return new WikitextContent( $sect );
631 }
632
633 /**
634 * Replaces a section in the wikitext
635 *
636 * @param $section empty/null/false or a section number (0, 1, 2, T1, T2...), or "new"
637 * @param $with Content: new content of the section
638 * @param $sectionTitle String: new section's subject, only if $section is 'new'
639 * @return Content Complete article content, or null if error
640 */
641 public function replaceSection( $section, Content $with, $sectionTitle = '' ) {
642 wfProfileIn( __METHOD__ );
643
644 $myModelId = $this->getModel();
645 $sectionModelId = $with->getModel();
646
647 if ( $sectionModelId != $myModelId ) {
648 $myModelName = ContentHandler::getContentModelName( $myModelId );
649 $sectionModelName = ContentHandler::getContentModelName( $sectionModelId );
650
651 throw new MWException( "Incompatible content model for section: document uses $myModelId ($myModelName), "
652 . "section uses $sectionModelId ($sectionModelName)." );
653 }
654
655 $oldtext = $this->getNativeData();
656 $text = $with->getNativeData();
657
658 if ( $section === '' ) {
659 return $with; #XXX: copy first?
660 } if ( $section == 'new' ) {
661 # Inserting a new section
662 $subject = $sectionTitle ? wfMsgForContent( 'newsectionheaderdefaultlevel', $sectionTitle ) . "\n\n" : '';
663 if ( wfRunHooks( 'PlaceNewSection', array( $this, $oldtext, $subject, &$text ) ) ) {
664 $text = strlen( trim( $oldtext ) ) > 0
665 ? "{$oldtext}\n\n{$subject}{$text}"
666 : "{$subject}{$text}";
667 }
668 } else {
669 # Replacing an existing section; roll out the big guns
670 global $wgParser;
671
672 $text = $wgParser->replaceSection( $oldtext, $section, $text );
673 }
674
675 $newContent = new WikitextContent( $text );
676
677 wfProfileOut( __METHOD__ );
678 return $newContent;
679 }
680
681 /**
682 * Returns a new WikitextContent object with the given section heading prepended.
683 *
684 * @param $header String
685 * @return Content
686 */
687 public function addSectionHeader( $header ) {
688 $text = wfMsgForContent( 'newsectionheaderdefaultlevel', $header ) . "\n\n" . $this->getNativeData();
689
690 return new WikitextContent( $text );
691 }
692
693 /**
694 * Returns a Content object with pre-save transformations applied (or this object if no transformations apply).
695 *
696 * @param Title $title
697 * @param User $user
698 * @param ParserOptions $popts
699 * @return Content
700 */
701 public function preSaveTransform( Title $title, User $user, ParserOptions $popts ) {
702 global $wgParser, $wgConteLang;
703
704 $text = $this->getNativeData();
705 $pst = $wgParser->preSaveTransform( $text, $title, $user, $popts );
706
707 return new WikitextContent( $pst );
708 }
709
710 /**
711 * Returns a Content object with preload transformations applied (or this object if no transformations apply).
712 *
713 * @param Title $title
714 * @param ParserOptions $popts
715 * @return Content
716 */
717 public function preloadTransform( Title $title, ParserOptions $popts ) {
718 global $wgParser, $wgConteLang;
719
720 $text = $this->getNativeData();
721 $plt = $wgParser->getPreloadText( $text, $title, $popts );
722
723 return new WikitextContent( $plt );
724 }
725
726 public function getRedirectChain() {
727 $text = $this->getNativeData();
728 return Title::newFromRedirectArray( $text );
729 }
730
731 public function getRedirectTarget() {
732 $text = $this->getNativeData();
733 return Title::newFromRedirect( $text );
734 }
735
736 public function getUltimateRedirectTarget() {
737 $text = $this->getNativeData();
738 return Title::newFromRedirectRecurse( $text );
739 }
740
741 /**
742 * Returns true if this content is not a redirect, and this content's text is countable according to
743 * the criteria defiend by $wgArticleCountMethod.
744 *
745 * @param Bool $hasLinks if it is known whether this content contains links, provide this information here,
746 * to avoid redundant parsing to find out.
747 * @param IContextSource $context context for parsing if necessary
748 *
749 * @return bool true if the content is countable
750 */
751 public function isCountable( $hasLinks = null, Title $title = null ) {
752 global $wgArticleCountMethod, $wgRequest;
753
754 if ( $this->isRedirect( ) ) {
755 return false;
756 }
757
758 $text = $this->getNativeData();
759
760 switch ( $wgArticleCountMethod ) {
761 case 'any':
762 return true;
763 case 'comma':
764 return strpos( $text, ',' ) !== false;
765 case 'link':
766 if ( $hasLinks === null ) { # not known, find out
767 if ( !$title ) {
768 $context = RequestContext::getMain();
769 $title = $context->getTitle();
770 }
771
772 $po = $this->getParserOutput( $title, null, null, false );
773 $links = $po->getLinks();
774 $hasLinks = !empty( $links );
775 }
776
777 return $hasLinks;
778 }
779 }
780
781 public function getTextForSummary( $maxlength = 250 ) {
782 $truncatedtext = parent::getTextForSummary( $maxlength );
783
784 #clean up unfinished links
785 #XXX: make this optional? wasn't there in autosummary, but required for deletion summary.
786 $truncatedtext = preg_replace( '/\[\[([^\]]*)\]?$/', '$1', $truncatedtext );
787
788 return $truncatedtext;
789 }
790
791 }
792
793 /**
794 * @since WD.1
795 */
796 class MessageContent extends TextContent {
797 public function __construct( $msg_key, $params = null, $options = null ) {
798 parent::__construct(null, CONTENT_MODEL_WIKITEXT); #XXX: messages may be wikitext, html or plain text! and maybe even something else entirely.
799
800 $this->mMessageKey = $msg_key;
801
802 $this->mParameters = $params;
803
804 if ( is_null( $options ) ) {
805 $options = array();
806 }
807 elseif ( is_string( $options ) ) {
808 $options = array( $options );
809 }
810
811 $this->mOptions = $options;
812
813 $this->mHtmlOptions = null;
814 }
815
816 /**
817 * Returns the message as rendered HTML, using the options supplied to the constructor plus "parse".
818 */
819 protected function getHtml( ) {
820 $opt = array_merge( $this->mOptions, array('parse') );
821
822 return wfMsgExt( $this->mMessageKey, $this->mParameters, $opt );
823 }
824
825
826 /**
827 * Returns the message as raw text, using the options supplied to the constructor minus "parse" and "parseinline".
828 */
829 public function getNativeData( ) {
830 $opt = array_diff( $this->mOptions, array('parse', 'parseinline') );
831
832 return wfMsgExt( $this->mMessageKey, $this->mParameters, $opt );
833 }
834
835 }
836
837 /**
838 * @since WD.1
839 */
840 class JavaScriptContent extends TextContent {
841 public function __construct( $text ) {
842 parent::__construct($text, CONTENT_MODEL_JAVASCRIPT);
843 }
844
845 protected function getHtml( ) {
846 $html = "";
847 $html .= "<pre class=\"mw-code mw-js\" dir=\"ltr\">\n";
848 $html .= htmlspecialchars( $this->getNativeData() );
849 $html .= "\n</pre>\n";
850
851 return $html;
852 }
853
854 }
855
856 /**
857 * @since WD.1
858 */
859 class CssContent extends TextContent {
860 public function __construct( $text ) {
861 parent::__construct($text, CONTENT_MODEL_CSS);
862 }
863
864 protected function getHtml( ) {
865 $html = "";
866 $html .= "<pre class=\"mw-code mw-css\" dir=\"ltr\">\n";
867 $html .= htmlspecialchars( $this->getNativeData() );
868 $html .= "\n</pre>\n";
869
870 return $html;
871 }
872 }