5965753d0c0e0401e5aafcc44fce3dab3285a2a8
3 * A content object represents page content, e.g. the text to show on a page.
4 * Content objects have no knowledge about how they relate to Wiki pages.
13 * @return String a string representing the content in a way useful for building a full text search index.
14 * If no useful representation exists, this method returns an empty string.
16 * @todo: test that this actually works
17 * @todo: make sure this also works with LuceneSearch / WikiSearch
19 public function getTextForSearchIndex( );
24 * @return String the wikitext to include when another page includes this content, or false if the content is not
25 * includable in a wikitext page.
27 * @TODO: allow native handling, bypassing wikitext representation, like for includable special pages.
28 * @TODO: allow transclusion into other content models than Wikitext!
29 * @TODO: used in WikiPage and MessageCache to get message text. Not so nice. What should we use instead?!
31 public function getWikitextForTransclusion( );
34 * Returns a textual representation of the content suitable for use in edit summaries and log messages.
38 * @param int $maxlength maximum length of the summary text
39 * @return String the summary text
41 public function getTextForSummary( $maxlength = 250 );
44 * Returns native representation of the data. Interpretation depends on the data model used,
45 * as given by getDataModel().
49 * @return mixed the native representation of the content. Could be a string, a nested array
50 * structure, an object, a binary blob... anything, really.
52 * @NOTE: review all calls carefully, caller must be aware of content model!
54 public function getNativeData( );
57 * returns the content's nominal size in bogo-bytes.
61 public function getSize( );
64 * Returns the id of the content model used by this content objects.
65 * Corresponds to the CONTENT_MODEL_XXX constants.
69 * @return int the model id
71 public function getModel();
74 * Convenience method that returns the ContentHandler singleton for handling the content
75 * model this Content object uses.
77 * Shorthand for ContentHandler::getForContent( $this )
81 * @return ContentHandler
83 public function getContentHandler();
86 * Convenience method that returns the default serialization format for the content model
87 * model this Content object uses.
89 * Shorthand for $this->getContentHandler()->getDefaultFormat()
93 * @return ContentHandler
95 public function getDefaultFormat();
98 * Convenience method that returns the list of serialization formats supported
99 * for the content model model this Content object uses.
101 * Shorthand for $this->getContentHandler()->getSupportedFormats()
105 * @return array of supported serialization formats
107 public function getSupportedFormats();
110 * Returns true if $format is a supported serialization format for this Content object,
113 * Note that this should always return true if $format is null, because null stands for the
114 * default serialization.
116 * Shorthand for $this->getContentHandler()->isSupportedFormat( $format )
120 * @param String $format the format to check
121 * @return bool whether the format is supported
123 public function isSupportedFormat( $format );
126 * Convenience method for serializing this Content object.
128 * Shorthand for $this->getContentHandler()->serializeContent( $this, $format )
132 * @param null|String $format the desired serialization format (or null for the default format).
133 * @return String serialized form of this Content object
135 public function serialize( $format = null );
138 * Returns true if this Content object represents empty content.
142 * @return bool whether this Content object is empty
144 public function isEmpty();
147 * Returns whether the content is valid. This is intended for local validity checks, not considering global consistency.
148 * Content needs to be valid before it can be saved.
150 * This default implementation always returns true.
156 public function isValid();
159 * Returns true if this Content objects is conceptually equivalent to the given Content object.
162 * * Will return false if $that is null.
163 * * Will return true if $that === $this.
164 * * Will return false if $that->getModelName() != $this->getModel().
165 * * Will return false if $that->getNativeData() is not equal to $this->getNativeData(),
166 * where the meaning of "equal" depends on the actual data model.
168 * Implementations should be careful to make equals() transitive and reflexive:
170 * * $a->equals( $b ) <=> $b->equals( $a )
171 * * $a->equals( $b ) && $b->equals( $c ) ==> $a->equals( $c )
175 * @param Content $that the Content object to compare to
176 * @return bool true if this Content object is equal to $that, false otherwise.
178 public function equals( Content
$that = null );
181 * Return a copy of this Content object. The following must be true for the object returned
182 * if $copy = $original->copy()
184 * * get_class($original) === get_class($copy)
185 * * $original->getModel() === $copy->getModel()
186 * * $original->equals( $copy )
188 * If and only if the Content object is immutable, the copy() method can and should
189 * return $this. That is, $copy === $original may be true, but only for immutable content
194 * @return Content. A copy of this object
196 public function copy( );
199 * Returns true if this content is countable as a "real" wiki page, provided
200 * that it's also in a countable location (e.g. a current revision in the main namespace).
204 * @param $hasLinks Bool: if it is known whether this content contains links, provide this information here,
205 * to avoid redundant parsing to find out.
208 public function isCountable( $hasLinks = null ) ;
211 * Convenience method, shorthand for
212 * $this->getContentHandler()->getParserOutput( $this, $title, $revId, $options, $generateHtml )
214 * @note: subclasses should NOT override this to provide custom rendering.
215 * Override ContentHandler::getParserOutput() instead!
217 * @param Title $title
219 * @param null|ParserOptions $options
220 * @param Boolean $generateHtml whether to generate Html (default: true). If false,
221 * the result of calling getText() on the ParserOutput object returned by
222 * this method is undefined.
226 * @return ParserOutput
228 public function getParserOutput( Title
$title, $revId = null, ParserOptions
$options = null, $generateHtml = true );
231 * Construct the redirect destination from this content and return an
232 * array of Titles, or null if this content doesn't represent a redirect.
233 * The last element in the array is the final destination after all redirects
234 * have been resolved (up to $wgMaxRedirects times).
238 * @return Array of Titles, with the destination last
240 public function getRedirectChain();
243 * Construct the redirect destination from this content and return a Title,
244 * or null if this content doesn't represent a redirect.
245 * This will only return the immediate redirect target, useful for
246 * the redirect table and other checks that don't need full recursion.
250 * @return Title: The corresponding Title
252 public function getRedirectTarget();
255 * Construct the redirect destination from this content and return the
256 * Title, or null if this content doesn't represent a redirect.
257 * This will recurse down $wgMaxRedirects times or until a non-redirect target is hit
258 * in order to provide (hopefully) the Title of the final destination instead of another redirect.
264 public function getUltimateRedirectTarget();
267 * Returns whether this Content represents a redirect.
268 * Shorthand for getRedirectTarget() !== null.
274 public function isRedirect();
277 * Returns the section with the given id.
281 * @param String $sectionId the section's id, given as a numeric string. The id "0" retrieves the section before
282 * the first heading, "1" the text between the first heading (included) and the second heading (excluded), etc.
283 * @return Content|Boolean|null the section, or false if no such section exist, or null if sections are not supported
285 public function getSection( $sectionId );
288 * Replaces a section of the content and returns a Content object with the section replaced.
292 * @param $section empty/null/false or a section number (0, 1, 2, T1, T2...), or "new"
293 * @param $with Content: new content of the section
294 * @param $sectionTitle String: new section's subject, only if $section is 'new'
295 * @return string Complete article text, or null if error
297 public function replaceSection( $section, Content
$with, $sectionTitle = '' );
300 * Returns a Content object with pre-save transformations applied (or this object if no transformations apply).
304 * @param Title $title
306 * @param null|ParserOptions $popts
309 public function preSaveTransform( Title
$title, User
$user, ParserOptions
$popts );
312 * Returns a new WikitextContent object with the given section heading prepended, if supported.
313 * The default implementation just returns this Content object unmodified, ignoring the section header.
317 * @param $header String
320 public function addSectionHeader( $header );
323 * Returns a Content object with preload transformations applied (or this object if no transformations apply).
327 * @param Title $title
328 * @param null|ParserOptions $popts
331 public function preloadTransform( Title
$title, ParserOptions
$popts );
333 # TODO: handle ImagePage and CategoryPage
334 # TODO: make sure we cover lucene search / wikisearch.
335 # TODO: make sure ReplaceTemplates still works
336 # FUTURE: nice&sane integration of GeSHi syntax highlighting
337 # [11:59] <vvv> Hooks are ugly; make CodeHighlighter interface and a config to set the class which handles syntax highlighting
338 # [12:00] <vvv> And default it to a DummyHighlighter
340 # TODO: make sure we cover the external editor interface (does anyone actually use that?!)
342 # TODO: tie into API to provide contentModel for Revisions
343 # TODO: tie into API to provide serialized version and contentFormat for Revisions
344 # TODO: tie into API edit interface
345 # FUTURE: make EditForm plugin for EditPage
347 # FUTURE: special type for redirects?!
348 # FUTURE: MultipartMultipart < WikipageContent (Main + Links + X)
349 # FUTURE: LinksContent < LanguageLinksContent, CategoriesContent
351 // @TODO: add support for ar_content_format, ar_content_model, rev_content_format, rev_content_model to API
356 * A content object represents page content, e.g. the text to show on a page.
357 * Content objects have no knowledge about how they relate to Wiki pages.
361 abstract class AbstractContent
implements Content
{
364 * Name of the content model this Content object represents.
365 * Use with CONTENT_MODEL_XXX constants
367 * @var String $model_id
372 * @param int $model_id
374 public function __construct( $model_id = null ) {
375 $this->model_id
= $model_id;
379 * Returns the id of the content model used by this content objects.
380 * Corresponds to the CONTENT_MODEL_XXX constants.
384 * @return int the model id
386 public function getModel() {
387 return $this->model_id
;
391 * Throws an MWException if $model_id is not the id of the content model
392 * supported by this Content object.
394 * @param int $model_id the model to check
396 * @throws MWException
398 protected function checkModelID( $model_id ) {
399 if ( $model_id !== $this->model_id
) {
400 $model_name = ContentHandler
::getContentModelName( $model_id );
401 $own_model_name = ContentHandler
::getContentModelName( $this->model_id
);
403 throw new MWException( "Bad content model: expected {$this->model_id} ($own_model_name) but got found $model_id ($model_name)." );
408 * Convenience method that returns the ContentHandler singleton for handling the content
409 * model this Content object uses.
411 * Shorthand for ContentHandler::getForContent( $this )
415 * @return ContentHandler
417 public function getContentHandler() {
418 return ContentHandler
::getForContent( $this );
422 * Convenience method that returns the default serialization format for the content model
423 * model this Content object uses.
425 * Shorthand for $this->getContentHandler()->getDefaultFormat()
429 * @return ContentHandler
431 public function getDefaultFormat() {
432 return $this->getContentHandler()->getDefaultFormat();
436 * Convenience method that returns the list of serialization formats supported
437 * for the content model model this Content object uses.
439 * Shorthand for $this->getContentHandler()->getSupportedFormats()
443 * @return array of supported serialization formats
445 public function getSupportedFormats() {
446 return $this->getContentHandler()->getSupportedFormats();
450 * Returns true if $format is a supported serialization format for this Content object,
453 * Note that this will always return true if $format is null, because null stands for the
454 * default serialization.
456 * Shorthand for $this->getContentHandler()->isSupportedFormat( $format )
460 * @param String $format the format to check
461 * @return bool whether the format is supported
463 public function isSupportedFormat( $format ) {
465 return true; // this means "use the default"
468 return $this->getContentHandler()->isSupportedFormat( $format );
472 * Throws an MWException if $this->isSupportedFormat( $format ) doesn't return true.
475 * @throws MWException
477 protected function checkFormat( $format ) {
478 if ( !$this->isSupportedFormat( $format ) ) {
479 throw new MWException( "Format $format is not supported for content model " . $this->getModel() );
484 * Convenience method for serializing this Content object.
486 * Shorthand for $this->getContentHandler()->serializeContent( $this, $format )
490 * @param null|String $format the desired serialization format (or null for the default format).
491 * @return String serialized form of this Content object
493 public function serialize( $format = null ) {
494 return $this->getContentHandler()->serializeContent( $this, $format );
498 * Returns true if this Content object represents empty content.
502 * @return bool whether this Content object is empty
504 public function isEmpty() {
505 return $this->getSize() == 0;
509 * Returns if the content is valid. This is intended for local validity checks, not considering global consistency.
510 * It needs to be valid before it can be saved.
512 * This default implementation always returns true.
518 public function isValid() {
523 * Returns true if this Content objects is conceptually equivalent to the given Content object.
525 * Will returns false if $that is null.
526 * Will return true if $that === $this.
527 * Will return false if $that->getModelName() != $this->getModel().
528 * Will return false if $that->getNativeData() is not equal to $this->getNativeData(),
529 * where the meaning of "equal" depends on the actual data model.
531 * Implementations should be careful to make equals() transitive and reflexive:
533 * * $a->equals( $b ) <=> $b->equals( $a )
534 * * $a->equals( $b ) && $b->equals( $c ) ==> $a->equals( $c )
538 * @param Content $that the Content object to compare to
539 * @return bool true if this Content object is euqual to $that, false otherwise.
541 public function equals( Content
$that = null ) {
542 if ( is_null( $that ) ){
546 if ( $that === $this ) {
550 if ( $that->getModel() !== $this->getModel() ) {
554 return $this->getNativeData() === $that->getNativeData();
558 * Convenience method, shorthand for
559 * $this->getContentHandler()->getParserOutput( $this, $title, $revId, $options, $generateHtml )
561 * @note: subclasses should NOT override this to provide custom rendering.
562 * Override ContentHandler::getParserOutput() instead!
564 * @param Title $title
566 * @param null|ParserOptions $options
567 * @param Boolean $generateHtml whether to generate Html (default: true). If false,
568 * the result of calling getText() on the ParserOutput object returned by
569 * this method is undefined.
573 * @return ParserOutput
575 public function getParserOutput( Title
$title, $revId = null, ParserOptions
$options = null, $generateHtml = true ) {
576 return $this->getContentHandler()->getParserOutput( $this, $title, $revId, $options, $generateHtml );
580 * Construct the redirect destination from this content and return an
581 * array of Titles, or null if this content doesn't represent a redirect.
582 * The last element in the array is the final destination after all redirects
583 * have been resolved (up to $wgMaxRedirects times).
585 * There is usually no need to override the default behaviour, subclasses that
586 * want to implement redirects should override getRedirectTarget().
590 * @return Array of Titles, with the destination last
591 * @note: migrated here from Title::newFromRedirectArray
593 public function getRedirectChain() {
594 global $wgMaxRedirects;
595 $title = $this->getRedirectTarget();
596 if ( is_null( $title ) ) {
599 // recursive check to follow double redirects
600 $recurse = $wgMaxRedirects;
601 $titles = array( $title );
602 while ( --$recurse > 0 ) {
603 if ( $title->isRedirect() ) {
604 $page = WikiPage
::factory( $title );
605 $newtitle = $page->getRedirectTarget();
609 // Redirects to some special pages are not permitted
610 if ( $newtitle instanceOf Title
&& $newtitle->isValidRedirectTarget() ) {
611 // the new title passes the checks, so make that our current title so that further recursion can be checked
613 $titles[] = $newtitle;
622 * Construct the redirect destination from this content and return a Title,
623 * or null if this content doesn't represent a redirect.
625 * This shall only return the immediate redirect target, useful for
626 * the redirect table and other checks that don't need full recursion.
628 * This implementation always returns null, subclasses should implement it
629 * according to their data model.
633 * @return Title: The corresponding Title
635 public function getRedirectTarget() {
640 * Construct the redirect destination from this content and return the
641 * Title, or null if this content doesn't represent a redirect.
642 * This will recurse down $wgMaxRedirects times or until a non-redirect target is hit
643 * in order to provide (hopefully) the Title of the final destination instead of another redirect.
645 * There is usually no need to override the default behaviour, subclasses that
646 * want to implement redirects should override getRedirectTarget().
651 * @note: migrated here from Title::newFromRedirectRecurse
653 public function getUltimateRedirectTarget() {
654 $titles = $this->getRedirectChain();
655 return $titles ?
array_pop( $titles ) : null;
663 public function isRedirect() {
664 return $this->getRedirectTarget() !== null;
668 * Returns the section with the given id.
670 * The default implementation returns null.
674 * @param String $sectionId the section's id, given as a numeric string. The id "0" retrieves the section before
675 * the first heading, "1" the text between the first heading (included) and the second heading (excluded), etc.
676 * @return Content|Boolean|null the section, or false if no such section exist, or null if sections are not supported
678 public function getSection( $sectionId ) {
683 * Replaces a section of the content and returns a Content object with the section replaced.
687 * @param $section empty/null/false or a section number (0, 1, 2, T1, T2...), or "new"
688 * @param $with Content: new content of the section
689 * @param $sectionTitle String: new section's subject, only if $section is 'new'
690 * @return string Complete article text, or null if error
692 public function replaceSection( $section, Content
$with, $sectionTitle = '' ) {
697 * Returns a Content object with pre-save transformations applied (or this object if no transformations apply).
701 * @param Title $title
703 * @param null|ParserOptions $popts
706 public function preSaveTransform( Title
$title, User
$user, ParserOptions
$popts ) {
711 * Returns a new WikitextContent object with the given section heading prepended, if supported.
712 * The default implementation just returns this Content object unmodified, ignoring the section header.
716 * @param $header String
719 public function addSectionHeader( $header ) {
724 * Returns a Content object with preload transformations applied (or this object if no transformations apply).
728 * @param Title $title
729 * @param null|ParserOptions $popts
732 public function preloadTransform( Title
$title, ParserOptions
$popts ) {
738 * Content object implementation for representing flat text.
740 * TextContent instances are immutable
744 abstract class TextContent
extends AbstractContent
{
746 public function __construct( $text, $model_id = null ) {
747 parent
::__construct( $model_id );
749 $this->mText
= $text;
752 public function copy() {
753 return $this; #NOTE: this is ok since TextContent are immutable.
756 public function getTextForSummary( $maxlength = 250 ) {
759 $text = $this->getNativeData();
761 $truncatedtext = $wgContLang->truncate(
762 preg_replace( "/[\n\r]/", ' ', $text ),
763 max( 0, $maxlength ) );
765 return $truncatedtext;
769 * returns the text's size in bytes.
771 * @return int the size
773 public function getSize( ) {
774 $text = $this->getNativeData( );
775 return strlen( $text );
779 * Returns true if this content is not a redirect, and $wgArticleCountMethod is "any".
781 * @param $hasLinks Bool: if it is known whether this content contains links, provide this information here,
782 * to avoid redundant parsing to find out.
784 * @return bool true if the content is countable
786 public function isCountable( $hasLinks = null ) {
787 global $wgArticleCountMethod;
789 if ( $this->isRedirect( ) ) {
793 if ( $wgArticleCountMethod === 'any' ) {
801 * Returns the text represented by this Content object, as a string.
803 * @return String the raw text
805 public function getNativeData( ) {
806 $text = $this->mText
;
811 * Returns the text represented by this Content object, as a string.
813 * @return String the raw text
815 public function getTextForSearchIndex( ) {
816 return $this->getNativeData();
820 * Returns the text represented by this Content object, as a string.
822 * @return String the raw text
824 public function getWikitextForTransclusion( ) {
825 return $this->getNativeData();
829 * Diff this content object with another content object..
833 * @param Content $that the other content object to compare this content object to
834 * @param Language $lang the language object to use for text segmentation. If not given, $wgContentLang is used.
836 * @return DiffResult a diff representing the changes that would have to be made to this content object
837 * to make it equal to $that.
839 public function diff( Content
$that, Language
$lang = null ) {
842 $this->checkModelID( $that->getModel() );
844 #@todo: could implement this in DifferenceEngine and just delegate here?
846 if ( !$lang ) $lang = $wgContLang;
848 $otext = $this->getNativeData();
849 $ntext = $this->getNativeData();
851 # Note: Use native PHP diff, external engines don't give us abstract output
852 $ota = explode( "\n", $wgContLang->segmentForDiff( $otext ) );
853 $nta = explode( "\n", $wgContLang->segmentForDiff( $ntext ) );
855 $diff = new Diff( $ota, $nta );
865 class WikitextContent
extends TextContent
{
867 public function __construct( $text ) {
868 parent
::__construct($text, CONTENT_MODEL_WIKITEXT
);
872 * Returns the section with the given id.
874 * @param String $section
876 * @internal param String $sectionId the section's id
877 * @return Content|false|null the section, or false if no such section exist, or null if sections are not supported
879 public function getSection( $section ) {
882 $text = $this->getNativeData();
883 $sect = $wgParser->getSection( $text, $section, false );
885 return new WikitextContent( $sect );
889 * Replaces a section in the wikitext
891 * @param $section empty/null/false or a section number (0, 1, 2, T1, T2...), or "new"
892 * @param $with Content: new content of the section
893 * @param $sectionTitle String: new section's subject, only if $section is 'new'
895 * @throws MWException
896 * @return Content Complete article content, or null if error
898 public function replaceSection( $section, Content
$with, $sectionTitle = '' ) {
899 wfProfileIn( __METHOD__
);
901 $myModelId = $this->getModel();
902 $sectionModelId = $with->getModel();
904 if ( $sectionModelId != $myModelId ) {
905 $myModelName = ContentHandler
::getContentModelName( $myModelId );
906 $sectionModelName = ContentHandler
::getContentModelName( $sectionModelId );
908 throw new MWException( "Incompatible content model for section: document uses $myModelId ($myModelName), "
909 . "section uses $sectionModelId ($sectionModelName)." );
912 $oldtext = $this->getNativeData();
913 $text = $with->getNativeData();
915 if ( $section === '' ) {
916 return $with; #XXX: copy first?
917 } if ( $section == 'new' ) {
918 # Inserting a new section
919 $subject = $sectionTitle ?
wfMsgForContent( 'newsectionheaderdefaultlevel', $sectionTitle ) . "\n\n" : '';
920 if ( wfRunHooks( 'PlaceNewSection', array( $this, $oldtext, $subject, &$text ) ) ) {
921 $text = strlen( trim( $oldtext ) ) > 0
922 ?
"{$oldtext}\n\n{$subject}{$text}"
923 : "{$subject}{$text}";
926 # Replacing an existing section; roll out the big guns
929 $text = $wgParser->replaceSection( $oldtext, $section, $text );
932 $newContent = new WikitextContent( $text );
934 wfProfileOut( __METHOD__
);
939 * Returns a new WikitextContent object with the given section heading prepended.
941 * @param $header String
944 public function addSectionHeader( $header ) {
945 $text = wfMsgForContent( 'newsectionheaderdefaultlevel', $header ) . "\n\n" . $this->getNativeData();
947 return new WikitextContent( $text );
951 * Returns a Content object with pre-save transformations applied (or this object if no transformations apply).
953 * @param Title $title
955 * @param ParserOptions $popts
958 public function preSaveTransform( Title
$title, User
$user, ParserOptions
$popts ) { #FIXME: also needed for JS/CSS!
959 global $wgParser, $wgConteLang;
961 $text = $this->getNativeData();
962 $pst = $wgParser->preSaveTransform( $text, $title, $user, $popts );
964 return new WikitextContent( $pst );
968 * Returns a Content object with preload transformations applied (or this object if no transformations apply).
970 * @param Title $title
971 * @param ParserOptions $popts
974 public function preloadTransform( Title
$title, ParserOptions
$popts ) {
975 global $wgParser, $wgConteLang;
977 $text = $this->getNativeData();
978 $plt = $wgParser->getPreloadText( $text, $title, $popts );
980 return new WikitextContent( $plt );
984 * Implement redirect extraction for wikitext.
988 * @note: migrated here from Title::newFromRedirectInternal()
990 * @see Content::getRedirectTarget
991 * @see AbstractContent::getRedirectTarget
993 public function getRedirectTarget() {
994 global $wgMaxRedirects;
995 if ( $wgMaxRedirects < 1 ) {
996 //redirects are disabled, so quit early
999 $redir = MagicWord
::get( 'redirect' );
1000 $text = trim( $this->getNativeData() );
1001 if ( $redir->matchStartAndRemove( $text ) ) {
1002 // Extract the first link and see if it's usable
1003 // Ensure that it really does come directly after #REDIRECT
1004 // Some older redirects included a colon, so don't freak about that!
1006 if ( preg_match( '!^\s*:?\s*\[{2}(.*?)(?:\|.*?)?\]{2}!', $text, $m ) ) {
1007 // Strip preceding colon used to "escape" categories, etc.
1008 // and URL-decode links
1009 if ( strpos( $m[1], '%' ) !== false ) {
1010 // Match behavior of inline link parsing here;
1011 $m[1] = rawurldecode( ltrim( $m[1], ':' ) );
1013 $title = Title
::newFromText( $m[1] );
1014 // If the title is a redirect to bad special pages or is invalid, return null
1015 if ( !$title instanceof Title ||
!$title->isValidRedirectTarget() ) {
1025 * Returns true if this content is not a redirect, and this content's text is countable according to
1026 * the criteria defined by $wgArticleCountMethod.
1028 * @param Bool $hasLinks if it is known whether this content contains links, provide this information here,
1029 * to avoid redundant parsing to find out.
1030 * @param null|\Title $title
1032 * @internal param \IContextSource $context context for parsing if necessary
1034 * @return bool true if the content is countable
1036 public function isCountable( $hasLinks = null, Title
$title = null ) {
1037 global $wgArticleCountMethod;
1039 if ( $this->isRedirect( ) ) {
1043 $text = $this->getNativeData();
1045 switch ( $wgArticleCountMethod ) {
1049 return strpos( $text, ',' ) !== false;
1051 if ( $hasLinks === null ) { # not known, find out
1053 $context = RequestContext
::getMain();
1054 $title = $context->getTitle();
1057 $po = $this->getParserOutput( $title, null, null, false );
1058 $links = $po->getLinks();
1059 $hasLinks = !empty( $links );
1068 public function getTextForSummary( $maxlength = 250 ) {
1069 $truncatedtext = parent
::getTextForSummary( $maxlength );
1071 #clean up unfinished links
1072 #XXX: make this optional? wasn't there in autosummary, but required for deletion summary.
1073 $truncatedtext = preg_replace( '/\[\[([^\]]*)\]?$/', '$1', $truncatedtext );
1075 return $truncatedtext;
1083 class MessageContent
extends TextContent
{
1084 public function __construct( $msg_key, $params = null, $options = null ) {
1085 parent
::__construct(null, CONTENT_MODEL_WIKITEXT
); #XXX: messages may be wikitext, html or plain text! and maybe even something else entirely.
1087 $this->mMessageKey
= $msg_key;
1089 $this->mParameters
= $params;
1091 if ( is_null( $options ) ) {
1094 elseif ( is_string( $options ) ) {
1095 $options = array( $options );
1098 $this->mOptions
= $options;
1102 * Returns the message as rendered HTML, using the options supplied to the constructor plus "parse".
1103 * @return String the message text, parsed
1105 public function getHtml( ) {
1106 $opt = array_merge( $this->mOptions
, array('parse') );
1108 return wfMsgExt( $this->mMessageKey
, $this->mParameters
, $opt );
1113 * Returns the message as raw text, using the options supplied to the constructor minus "parse" and "parseinline".
1115 * @return String the message text, unparsed.
1117 public function getNativeData( ) {
1118 $opt = array_diff( $this->mOptions
, array('parse', 'parseinline') );
1120 return wfMsgExt( $this->mMessageKey
, $this->mParameters
, $opt );
1128 class JavaScriptContent
extends TextContent
{
1129 public function __construct( $text ) {
1130 parent
::__construct($text, CONTENT_MODEL_JAVASCRIPT
);
1138 class CssContent
extends TextContent
{
1139 public function __construct( $text ) {
1140 parent
::__construct($text, CONTENT_MODEL_CSS
);