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 substr( $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 }
MessageContent\getTextForSearchIndex
getTextForSearchIndex()
Definition: MessageContent.php:101
MessageContent\$mMessage
Message $mMessage
Definition: MessageContent.php:42
MessageContent\getNativeData
getNativeData()
Returns the message object, with any parameters already substituted.
Definition: MessageContent.php:80
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1175
MessageContent\__construct
__construct( $msg, $params=null)
Definition: MessageContent.php:48
MessageContent\getSize
getSize()
Definition: MessageContent.php:130
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
Definition: GlobalFunctions.php:989
MessageContent\getWikitextForTransclusion
getWikitextForTransclusion()
Definition: MessageContent.php:110
AbstractContent
Base implementation for content objects.
Definition: AbstractContent.php:42
MessageContent\getWikitext
getWikitext()
Returns the message text.
Definition: MessageContent.php:69
CONTENT_MODEL_WIKITEXT
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:208
MessageContent
Wrapper allowing us to handle a system message as a Content object.
Definition: MessageContent.php:37
Message
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition: Message.php:138
MessageContent\copy
copy()
Definition: MessageContent.php:139
MessageContent\getMessage
getMessage()
Returns the message object, with any parameters already substituted.
Definition: MessageContent.php:91
MessageContent\getTextForSummary
getTextForSummary( $maxlength=250)
Definition: MessageContent.php:121
MessageContent\isCountable
isCountable( $hasLinks=null)
Definition: MessageContent.php:152