diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2013-01-18 16:46:04 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2013-01-18 16:46:04 +0100 |
commit | 63601400e476c6cf43d985f3e7b9864681695ed4 (patch) | |
tree | f7846203a952e38aaf66989d0a4702779f549962 /includes/parser/StripState.php | |
parent | 8ff01378c9e0207f9169b81966a51def645b6a51 (diff) |
Update to MediaWiki 1.20.2
this update includes:
* adjusted Arch Linux skin
* updated FluxBBAuthPlugin
* patch for https://bugzilla.wikimedia.org/show_bug.cgi?id=44024
Diffstat (limited to 'includes/parser/StripState.php')
-rw-r--r-- | includes/parser/StripState.php | 55 |
1 files changed, 48 insertions, 7 deletions
diff --git a/includes/parser/StripState.php b/includes/parser/StripState.php index 7ad80fa1..ad95d5f7 100644 --- a/includes/parser/StripState.php +++ b/includes/parser/StripState.php @@ -1,4 +1,25 @@ <?php +/** + * Holder for stripped items when parsing wiki markup. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + * @ingroup Parser + */ /** * @todo document, briefly. @@ -10,6 +31,10 @@ class StripState { protected $regex; protected $tempType, $tempMergePrefix; + protected $circularRefGuard; + protected $recursionLevel = 0; + + const UNSTRIP_RECURSION_LIMIT = 20; /** * @param $prefix string @@ -21,6 +46,7 @@ class StripState { 'general' => array() ); $this->regex = "/{$this->prefix}([^\x7f]+)" . Parser::MARKER_SUFFIX . '/'; + $this->circularRefGuard = array(); } /** @@ -92,12 +118,10 @@ class StripState { } wfProfileIn( __METHOD__ ); + $oldType = $this->tempType; $this->tempType = $type; - do { - $oldText = $text; - $text = preg_replace_callback( $this->regex, array( $this, 'unstripCallback' ), $text ); - } while ( $text !== $oldText ); - $this->tempType = null; + $text = preg_replace_callback( $this->regex, array( $this, 'unstripCallback' ), $text ); + $this->tempType = $oldType; wfProfileOut( __METHOD__ ); return $text; } @@ -107,8 +131,25 @@ class StripState { * @return array */ protected function unstripCallback( $m ) { - if ( isset( $this->data[$this->tempType][$m[1]] ) ) { - return $this->data[$this->tempType][$m[1]]; + $marker = $m[1]; + if ( isset( $this->data[$this->tempType][$marker] ) ) { + if ( isset( $this->circularRefGuard[$marker] ) ) { + return '<span class="error">' + . wfMessage( 'parser-unstrip-loop-warning' )->inContentLanguage()->text() + . '</span>'; + } + if ( $this->recursionLevel >= self::UNSTRIP_RECURSION_LIMIT ) { + return '<span class="error">' . + wfMessage( 'parser-unstrip-recursion-limit' ) + ->numParams( self::UNSTRIP_RECURSION_LIMIT )->inContentLanguage()->text() . + '</span>'; + } + $this->circularRefGuard[$marker] = true; + $this->recursionLevel++; + $ret = $this->unstripType( $this->tempType, $this->data[$this->tempType][$marker] ); + $this->recursionLevel--; + unset( $this->circularRefGuard[$marker] ); + return $ret; } else { return $m[0]; } |