55 $this->circularRefGuard = [];
58 if ( isset( $options[
'depthLimit'] ) ) {
59 $this->depthLimit = $options[
'depthLimit'];
61 if ( isset( $options[
'sizeLimit'] ) ) {
62 $this->sizeLimit = $options[
'sizeLimit'];
72 $this->
addItem(
'nowiki', $marker, $value );
80 $this->
addItem(
'general', $marker, $value );
90 if ( !preg_match( $this->regex, $marker, $m ) ) {
94 $this->data[
$type][$m[1]] = $value;
120 if ( !count( $this->data[
'nowiki'] ) ) {
124 $callback =
function ( $m ) use ( $callback ) {
126 if ( isset( $this->data[
'nowiki'][$marker] ) ) {
127 $value = $this->data[
'nowiki'][$marker];
128 if ( $value instanceof Closure ) {
132 $this->expandSize += strlen( $value );
133 if ( $this->expandSize > $this->sizeLimit ) {
134 return $this->getLimitationWarning(
'unstrip-size', $this->sizeLimit );
137 return call_user_func( $callback, $value );
143 return preg_replace_callback( $this->regex, $callback, $text );
151 $text = $this->unstripType(
'general', $text );
152 $text = $this->unstripType(
'nowiki', $text );
163 if ( !count( $this->data[
$type] ) ) {
167 $callback =
function ( $m ) use (
$type ) {
169 if ( isset( $this->data[
$type][$marker] ) ) {
170 if ( isset( $this->circularRefGuard[$marker] ) ) {
171 return $this->getWarning(
'parser-unstrip-loop-warning' );
174 if ( $this->depth > $this->highestDepth ) {
175 $this->highestDepth = $this->depth;
177 if ( $this->depth >= $this->depthLimit ) {
178 return $this->getLimitationWarning(
'unstrip-depth', $this->depthLimit );
181 $value = $this->data[
$type][$marker];
182 if ( $value instanceof Closure ) {
186 $this->expandSize += strlen( $value );
187 if ( $this->expandSize > $this->sizeLimit ) {
188 return $this->getLimitationWarning(
'unstrip-size', $this->sizeLimit );
191 $this->circularRefGuard[$marker] =
true;
193 $ret = $this->unstripType(
$type, $value );
195 unset( $this->circularRefGuard[$marker] );
203 $text = preg_replace_callback( $this->regex, $callback, $text );
214 private function getLimitationWarning(
$type, $max =
'' ) {
215 if ( $this->parser ) {
216 $this->parser->limitationWarn(
$type, $max );
218 return $this->getWarning(
"$type-warning", $max );
228 private function getWarning( $message, $max =
'' ) {
229 return '<span class="error">' .
231 ->numParams( $max )->inContentLanguage()->text() .
243 [
'limitreport-unstrip-depth',
249 [
'limitreport-unstrip-size',
265 return preg_replace( $this->regex,
'', $text );
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
if(!defined('MW_SETUP_CALLBACK'))
PHP Parser - Processes wiki markup (which uses a more user-friendly syntax, such as "[[link]]" for ma...
addNoWiki( $marker, $value)
Add a nowiki strip item.
getLimitReport()
Get an array of parameters to pass to ParserOutput::setLimitReportData()
unstripType( $type, $text)
replaceNoWikis(string $text, callable $callback)
addGeneral( $marker, $value)
killMarkers( $text)
Remove any strip markers found in the given text.
addItem( $type, $marker, $value)
__construct(Parser $parser=null, $options=[])