MediaWiki  1.23.13
StripState.php
Go to the documentation of this file.
1 <?php
28 class StripState {
29  protected $prefix;
30  protected $data;
31  protected $regex;
32 
34  protected $circularRefGuard;
35  protected $recursionLevel = 0;
36 
38 
42  function __construct( $prefix ) {
43  $this->prefix = $prefix;
44  $this->data = array(
45  'nowiki' => array(),
46  'general' => array()
47  );
48  $this->regex = "/{$this->prefix}([^\x7f]+)" . Parser::MARKER_SUFFIX . '/';
49  $this->circularRefGuard = array();
50  }
51 
57  function addNoWiki( $marker, $value ) {
58  $this->addItem( 'nowiki', $marker, $value );
59  }
60 
65  function addGeneral( $marker, $value ) {
66  $this->addItem( 'general', $marker, $value );
67  }
68 
75  protected function addItem( $type, $marker, $value ) {
76  if ( !preg_match( $this->regex, $marker, $m ) ) {
77  throw new MWException( "Invalid marker: $marker" );
78  }
79 
80  $this->data[$type][$m[1]] = $value;
81  }
82 
87  function unstripGeneral( $text ) {
88  return $this->unstripType( 'general', $text );
89  }
90 
95  function unstripNoWiki( $text ) {
96  return $this->unstripType( 'nowiki', $text );
97  }
98 
103  function unstripBoth( $text ) {
104  $text = $this->unstripType( 'general', $text );
105  $text = $this->unstripType( 'nowiki', $text );
106  return $text;
107  }
108 
114  protected function unstripType( $type, $text ) {
115  // Shortcut
116  if ( !count( $this->data[$type] ) ) {
117  return $text;
118  }
119 
120  wfProfileIn( __METHOD__ );
121  $oldType = $this->tempType;
122  $this->tempType = $type;
123  $text = preg_replace_callback( $this->regex, array( $this, 'unstripCallback' ), $text );
124  $this->tempType = $oldType;
125  wfProfileOut( __METHOD__ );
126  return $text;
127  }
128 
133  protected function unstripCallback( $m ) {
134  $marker = $m[1];
135  if ( isset( $this->data[$this->tempType][$marker] ) ) {
136  if ( isset( $this->circularRefGuard[$marker] ) ) {
137  return '<span class="error">'
138  . wfMessage( 'parser-unstrip-loop-warning' )->inContentLanguage()->text()
139  . '</span>';
140  }
141  if ( $this->recursionLevel >= self::UNSTRIP_RECURSION_LIMIT ) {
142  return '<span class="error">' .
143  wfMessage( 'parser-unstrip-recursion-limit' )
144  ->numParams( self::UNSTRIP_RECURSION_LIMIT )->inContentLanguage()->text() .
145  '</span>';
146  }
147  $this->circularRefGuard[$marker] = true;
148  $this->recursionLevel++;
149  $ret = $this->unstripType( $this->tempType, $this->data[$this->tempType][$marker] );
150  $this->recursionLevel--;
151  unset( $this->circularRefGuard[$marker] );
152  return $ret;
153  } else {
154  return $m[0];
155  }
156  }
157 
166  function getSubState( $text ) {
167  $subState = new StripState( $this->prefix );
168  $pos = 0;
169  while ( true ) {
170  $startPos = strpos( $text, $this->prefix, $pos );
171  $endPos = strpos( $text, Parser::MARKER_SUFFIX, $pos );
172  if ( $startPos === false || $endPos === false ) {
173  break;
174  }
175 
176  $endPos += strlen( Parser::MARKER_SUFFIX );
177  $marker = substr( $text, $startPos, $endPos - $startPos );
178  if ( !preg_match( $this->regex, $marker, $m ) ) {
179  continue;
180  }
181 
182  $key = $m[1];
183  if ( isset( $this->data['nowiki'][$key] ) ) {
184  $subState->data['nowiki'][$key] = $this->data['nowiki'][$key];
185  } elseif ( isset( $this->data['general'][$key] ) ) {
186  $subState->data['general'][$key] = $this->data['general'][$key];
187  }
188  $pos = $endPos;
189  }
190  return $subState;
191  }
192 
202  function merge( $otherState, $texts ) {
203  $mergePrefix = Parser::getRandomString();
204 
205  foreach ( $otherState->data as $type => $items ) {
206  foreach ( $items as $key => $value ) {
207  $this->data[$type]["$mergePrefix-$key"] = $value;
208  }
209  }
210 
211  $this->tempMergePrefix = $mergePrefix;
212  $texts = preg_replace_callback( $otherState->regex, array( $this, 'mergeCallback' ), $texts );
213  $this->tempMergePrefix = null;
214  return $texts;
215  }
216 
221  protected function mergeCallback( $m ) {
222  $key = $m[1];
223  return "{$this->prefix}{$this->tempMergePrefix}-$key" . Parser::MARKER_SUFFIX;
224  }
225 
232  function killMarkers( $text ) {
233  return preg_replace( $this->regex, '', $text );
234  }
235 }
StripState\merge
merge( $otherState, $texts)
Merge another StripState object into this one.
Definition: StripState.php:202
StripState\getSubState
getSubState( $text)
Get a StripState object which is sufficient to unstrip the given text.
Definition: StripState.php:166
data
and how to run hooks for an and one after Each event has a preferably in CamelCase For ArticleDelete hook A clump of code and data that should be run when an event happens This can be either a function and a chunk of data
Definition: hooks.txt:6
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
StripState\unstripNoWiki
unstripNoWiki( $text)
Definition: StripState.php:95
StripState\UNSTRIP_RECURSION_LIMIT
const UNSTRIP_RECURSION_LIMIT
Definition: StripState.php:37
StripState\unstripGeneral
unstripGeneral( $text)
Definition: StripState.php:87
wfProfileIn
wfProfileIn( $functionname)
Begin profiling of a function.
Definition: Profiler.php:33
$ret
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition: hooks.txt:1530
StripState\$data
$data
Definition: StripState.php:30
StripState\$tempType
$tempType
Definition: StripState.php:33
StripState\addNoWiki
addNoWiki( $marker, $value)
Add a nowiki strip item.
Definition: StripState.php:57
StripState
Definition: StripState.php:28
StripState\$recursionLevel
$recursionLevel
Definition: StripState.php:35
MWException
MediaWiki exception.
Definition: MWException.php:26
StripState\$circularRefGuard
$circularRefGuard
Definition: StripState.php:34
wfProfileOut
wfProfileOut( $functionname='missing')
Stop profiling of a function.
Definition: Profiler.php:46
wfMessage
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form externallinks including delete and has completed for all link tables default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
StripState\addGeneral
addGeneral( $marker, $value)
Definition: StripState.php:65
StripState\$prefix
$prefix
Definition: StripState.php:29
$value
$value
Definition: styleTest.css.php:45
StripState\__construct
__construct( $prefix)
Definition: StripState.php:42
StripState\unstripCallback
unstripCallback( $m)
Definition: StripState.php:133
StripState\$tempMergePrefix
$tempMergePrefix
Definition: StripState.php:33
StripState\addItem
addItem( $type, $marker, $value)
Definition: StripState.php:75
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
StripState\unstripType
unstripType( $type, $text)
Definition: StripState.php:114
StripState\$regex
$regex
Definition: StripState.php:31
StripState\unstripBoth
unstripBoth( $text)
Definition: StripState.php:103
StripState\mergeCallback
mergeCallback( $m)
Definition: StripState.php:221
StripState\killMarkers
killMarkers( $text)
Remove any strip markers found in the given text.
Definition: StripState.php:232
$type
$type
Definition: testCompression.php:46