]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - vendor/wikimedia/remex-html/RemexHtml/TreeBuilder/InHeadNoscript.php
MediaWiki 1.30.2-scripts
[autoinstalls/mediawiki.git] / vendor / wikimedia / remex-html / RemexHtml / TreeBuilder / InHeadNoscript.php
1 <?php
2
3 namespace RemexHtml\TreeBuilder;
4 use RemexHtml\Tokenizer\Attributes;
5
6 /**
7  * The "in head noscript" insertion mode
8  */
9 class InHeadNoscript extends InsertionMode {
10         public function characters( $text, $start, $length, $sourceStart, $sourceLength ) {
11                 $builder = $this->builder;
12                 $dispatcher = $this->dispatcher;
13
14                 // Insert whitespace
15                 list( $part1, $part2 ) = $this->splitInitialMatch( true, "\t\n\f\r ",
16                         $text, $start, $length, $sourceStart, $sourceLength );
17                 list( $start, $length, $sourceStart, $sourceLength ) = $part1;
18                 if ( $length ) {
19                         $dispatcher->inHead->characters(
20                                 $text, $start, $length, $sourceStart, $sourceLength );
21                 }
22
23                 // Switch mode on non-whitespace
24                 list( $start, $length, $sourceStart, $sourceLength ) = $part2;
25                 if ( $length ) {
26                         $builder->error( "unexpected non-whitespace character in head in noscript, " .
27                                 "closing noscript",  $sourceStart );
28                         $builder->pop( $sourceStart, 0 );
29                         $dispatcher->switchMode( Dispatcher::IN_HEAD )
30                                 ->characters( $text, $start, $length, $sourceStart, $sourceLength );
31                 }
32         }
33
34         public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) {
35                 $builder = $this->builder;
36                 $dispatcher = $this->dispatcher;
37
38                 switch ( $name ) {
39                 case 'html':
40                         $dispatcher->inBody->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength );
41                         break;
42
43                 case 'basefont':
44                 case 'bgsound':
45                 case 'link':
46                 case 'meta':
47                 case 'noframes':
48                 case 'style':
49                         $dispatcher->inHead->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength );
50                         break;
51
52                 case 'head':
53                 case 'noscript':
54                         $builder->error( "unexpected <$name> in head in noscript, ignoring", $sourceStart );
55                         return;
56
57                 default:
58                         $builder->error( "unexpected <$name> in head in noscript, closing noscript",
59                                 $sourceStart );
60                         $builder->pop( $sourceStart, 0 );
61                         $dispatcher->switchMode( Dispatcher::IN_HEAD )
62                                 ->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength );
63                 }
64         }
65
66         public function endTag( $name, $sourceStart, $sourceLength ) {
67                 $builder = $this->builder;
68                 $dispatcher = $this->dispatcher;
69
70                 switch ( $name ) {
71                 case 'noscript':
72                         $builder->pop( $sourceStart, $sourceLength );
73                         $dispatcher->switchMode( Dispatcher::IN_HEAD );
74                         break;
75
76                 case 'br':
77                         $builder->error( "unexpected </br> in head in noscript, closing noscript",
78                                 $sourceStart );
79                         $builder->pop( $sourceStart, 0 );
80                         $dispatcher->switchMode( Dispatcher::IN_HEAD )
81                                 ->endTag( $name, $sourceStart, $sourceLength );
82                         break;
83
84                 default:
85                         $builder->error( "unexpected </$name> in head in noscript, ignoring",
86                                 $sourceStart );
87                         return;
88                 }
89         }
90
91         public function endDocument( $pos ) {
92                 $this->builder->error( "unexpected end-of-file in head in noscript", $pos );
93                 $this->builder->pop( $pos, 0 );
94                 $this->dispatcher->switchMode( Dispatcher::IN_HEAD )
95                         ->endDocument( $pos );
96         }
97 }