MediaWiki  master
MessageContent.php
Go to the documentation of this file.
1 <?php
38 
42  protected $mMessage;
43 
48  public function __construct( $msg, $params = null ) {
49  wfDeprecated( __CLASS__, '1.38' );
50  # XXX: messages may be wikitext, html or plain text! and maybe even something else entirely.
51  parent::__construct( CONTENT_MODEL_WIKITEXT );
52 
53  if ( is_string( $msg ) ) {
54  $this->mMessage = wfMessage( $msg );
55  } else {
56  $this->mMessage = clone $msg;
57  }
58 
59  if ( $params ) {
60  $this->mMessage = $this->mMessage->params( $params );
61  }
62  }
63 
69  public function getWikitext() {
70  return $this->mMessage->text();
71  }
72 
80  public function getNativeData() {
81  return $this->getMessage();
82  }
83 
91  public function getMessage() {
92  // NOTE: Message objects are mutable. Cloning here makes MessageContent immutable.
93  return clone $this->mMessage;
94  }
95 
101  public function getTextForSearchIndex() {
102  return $this->mMessage->plain();
103  }
104 
110  public function getWikitextForTransclusion() {
111  return $this->getWikitext();
112  }
113 
121  public function getTextForSummary( $maxlength = 250 ) {
122  return mb_strcut( $this->mMessage->plain(), 0, $maxlength );
123  }
124 
130  public function getSize() {
131  return strlen( $this->mMessage->plain() );
132  }
133 
139  public function copy() {
140  // MessageContent is immutable (because getNativeData() and getMessage()
141  // returns a clone of the Message object)
142  return $this;
143  }
144 
152  public function isCountable( $hasLinks = null ) {
153  return false;
154  }
155 }
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:209
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
Base implementation for content objects.
Wrapper allowing us to handle a system message as a Content object.
getMessage()
Returns the message object, with any parameters already substituted.
getNativeData()
Returns the message object, with any parameters already substituted.
isCountable( $hasLinks=null)
getWikitext()
Returns the message text.
getTextForSummary( $maxlength=250)
__construct( $msg, $params=null)