Index: trunk/extensions/SemanticGlossary/SemanticGlossaryParser.php |
— | — | @@ -28,7 +28,7 @@ |
29 | 29 | * @param $text |
30 | 30 | * @return Boolean |
31 | 31 | */ |
32 | | - static function parse( &$parser, &$text ) { |
| 32 | + static function parse ( &$parser, &$text ) { |
33 | 33 | |
34 | 34 | wfProfileIn( __METHOD__ ); |
35 | 35 | |
— | — | @@ -38,7 +38,6 @@ |
39 | 39 | wfProfileOut( __METHOD__ ); |
40 | 40 | |
41 | 41 | return true; |
42 | | - |
43 | 42 | } |
44 | 43 | |
45 | 44 | /** |
— | — | @@ -46,19 +45,18 @@ |
47 | 46 | * |
48 | 47 | * @return Array an array mapping terms (keys) to descriptions (values) |
49 | 48 | */ |
50 | | - function getGlossaryArray( SemanticGlossaryMessageLog &$messages = null ) { |
| 49 | + function getGlossaryArray ( SemanticGlossaryMessageLog &$messages = null ) { |
51 | 50 | |
52 | 51 | global $smwgQDefaultNamespaces; |
53 | 52 | |
54 | 53 | wfProfileIn( __METHOD__ ); |
55 | 54 | |
56 | 55 | $store = smwfGetStore(); // default store |
57 | | - |
58 | 56 | // Create query |
59 | | - $desc = new SMWSomeProperty(new SMWDIProperty( '___glt' ), new SMWThingDescription()); |
60 | | - $desc -> addPrintRequest(new SMWPrintRequest( SMWPrintRequest::PRINT_PROP, null, SMWPropertyValue::makeProperty( '___glt' ) )); |
61 | | - $desc -> addPrintRequest(new SMWPrintRequest( SMWPrintRequest::PRINT_PROP, null, SMWPropertyValue::makeProperty( '___gld' ) )); |
62 | | - $desc -> addPrintRequest(new SMWPrintRequest( SMWPrintRequest::PRINT_PROP, null, SMWPropertyValue::makeProperty( '___gll' ) )); |
| 57 | + $desc = new SMWSomeProperty( new SMWDIProperty( '___glt' ), new SMWThingDescription() ); |
| 58 | + $desc -> addPrintRequest( new SMWPrintRequest( SMWPrintRequest::PRINT_PROP, null, SMWPropertyValue::makeProperty( '___glt' ) ) ); |
| 59 | + $desc -> addPrintRequest( new SMWPrintRequest( SMWPrintRequest::PRINT_PROP, null, SMWPropertyValue::makeProperty( '___gld' ) ) ); |
| 60 | + $desc -> addPrintRequest( new SMWPrintRequest( SMWPrintRequest::PRINT_PROP, null, SMWPropertyValue::makeProperty( '___gll' ) ) ); |
63 | 61 | |
64 | 62 | $query = new SMWQuery( $desc, true, false ); |
65 | 63 | $query -> querymode = SMWQuery::MODE_INSTANCES; |
— | — | @@ -93,14 +91,14 @@ |
94 | 92 | |
95 | 93 | if ( $messages ) { |
96 | 94 | $messages -> addMessage( |
97 | | - wfMsg('semanticglossary-termdefinedtwice', array($subject -> getPrefixedText())), |
| 95 | + wfMsg( 'semanticglossary-termdefinedtwice', array( $subject -> getPrefixedText() ) ), |
98 | 96 | SemanticGlossaryMessageLog::SG_WARNING ); |
99 | 97 | } |
100 | 98 | |
101 | 99 | continue; |
102 | 100 | } |
103 | 101 | |
104 | | - $source = array( $subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subject->getDBkey() ); |
| 102 | + $source = array( $subject -> getDBkey(), $subject -> getNamespace(), $subject -> getInterwiki(), $subject -> getDBkey() ); |
105 | 103 | |
106 | 104 | if ( array_key_exists( $term, $result ) ) { |
107 | 105 | $result[ $term ] -> addDefinition( $definition, $link, $source ); |
— | — | @@ -123,7 +121,7 @@ |
124 | 122 | * @param $text |
125 | 123 | * @return Boolean |
126 | 124 | */ |
127 | | - protected function realParse( &$parser, &$text ) { |
| 125 | + protected function realParse ( &$parser, &$text ) { |
128 | 126 | |
129 | 127 | global $wgRequest, $sggSettings; |
130 | 128 | |
— | — | @@ -144,12 +142,11 @@ |
145 | 143 | // var_export($text); |
146 | 144 | //Parse HTML from page |
147 | 145 | // $doc = new DOMDocument(); |
148 | | -//// @$doc -> loadHTML( '<html><meta http-equiv="content-type" content="charset=utf-8"/>' . $text . '</html>' ); |
| 146 | +// @$doc -> loadHTML( '<html><meta http-equiv="content-type" content="charset=utf-8"/>' . $text . '</html>' ); |
149 | 147 | // $doc -> loadHTML( $text ); |
| 148 | + // FIXME: this works in PHP 5.3.3. What about 5.1? |
| 149 | + $doc = @DOMDocument::loadHTML( $text ); |
150 | 150 | |
151 | | - // this works in PHP 5.3.3. What about 5.1? |
152 | | - $doc = @DOMDocument::loadHTML($text); |
153 | | - |
154 | 151 | //Find all text in HTML. |
155 | 152 | $xpath = new DOMXpath( $doc ); |
156 | 153 | $elements = $xpath -> query( "//*[not(ancestor-or-self::*[@class='noglossary'] or ancestor-or-self::a)][text()!=' ']/text()" ); |
— | — | @@ -167,7 +164,7 @@ |
168 | 165 | |
169 | 166 | //Split node text into words, putting offset and text into $offsets[0] array |
170 | 167 | // preg_match_all( "/\b[^\b\s\.,;:]+/", $el -> nodeValue, $offsets, PREG_OFFSET_CAPTURE ); |
171 | | - preg_match_all( "/[^\s$sggSettings->punctuationCharacters]+/", $el -> nodeValue, $offsets, PREG_OFFSET_CAPTURE ); |
| 168 | + preg_match_all( "/[^\s{$sggSettings -> punctuationCharacters}]+/", $el -> nodeValue, $offsets, PREG_OFFSET_CAPTURE ); |
172 | 169 | |
173 | 170 | //Search and replace words in reverse order (from end of string backwards), |
174 | 171 | //This way we don't mess up the offsets of the words as we iterate |
— | — | @@ -209,7 +206,13 @@ |
210 | 207 | |
211 | 208 | if ( $changed ) { |
212 | 209 | $body = $xpath -> query( '/html/body' ); |
213 | | - $text = $doc -> saveHTML(); |
| 210 | +// $text = $doc -> saveXML( $body -> item( 0 ) ); |
| 211 | + |
| 212 | + $text = ''; |
| 213 | + foreach ( $body -> item( 0 ) -> childNodes as $child ) { |
| 214 | + $text .= $doc -> saveXML( $child ); |
| 215 | + } |
| 216 | + |
214 | 217 | $this -> loadModules( $parser ); |
215 | 218 | } |
216 | 219 | |
— | — | @@ -218,7 +221,7 @@ |
219 | 222 | return true; |
220 | 223 | } |
221 | 224 | |
222 | | - protected function loadModules( &$parser ) { |
| 225 | + protected function loadModules ( &$parser ) { |
223 | 226 | |
224 | 227 | global $wgOut, $wgScriptPath; |
225 | 228 | |