+ # Handle comments. These won't be generated by mediawiki (they
+ # are stripped in the Sanitizer) but may be generated by extensions.
+ if (
+ $this->allowComments &&
+ preg_match( Balancer::VALID_COMMENT_REGEX, $x, $regs, PREG_OFFSET_CAPTURE ) &&
+ /* verify EOF condition where necessary */
+ ( $regs[4][1] < 0 || !$this->bitsIterator->valid() )
+ ) {
+ $contents = $regs[2][0];
+ $rest = $regs[5][0];
+ $this->insertToken( 'comment', $contents );
+ $this->insertToken( 'text', str_replace( '>', '>', $rest ) );
+ return;
+ }