Index: trunk/extensions/DoubleWiki/DoubleWiki_body.php |
— | — | @@ -27,18 +27,18 @@ |
28 | 28 | /* |
29 | 29 | * Read the list of matched phrases and add tags to the html output. |
30 | 30 | */ |
31 | | - function addMatchingTags ( &$text, $lang ) { |
| 31 | + function addMatchingTags ( &$text, $lang ) { |
32 | 32 | $pattern = "/<div id=\"align-$lang\" style=\"display:none;\">\n<p>([^<]*?)<\/p>\n<\/div>/is"; |
33 | 33 | $m = array(); |
34 | | - if( ! preg_match( $pattern, $text, $m ) ) { |
| 34 | + if ( ! preg_match( $pattern, $text, $m ) ) { |
35 | 35 | return; |
36 | 36 | } |
37 | 37 | $text = str_replace( $m[1], '', $text ); |
38 | 38 | $line_pattern = "/\s*([^:\n]*?)\s*:\s*([^:\n]*?)\s*\n/i"; |
39 | 39 | $items = array(); |
40 | 40 | preg_match_all( $line_pattern, $m[1], $items, PREG_SET_ORDER ); |
41 | | - foreach( $items as $n => $i ) { |
42 | | - $text = str_replace( $i[1], "<span id=\"dw-$n\" title=\"{$i[2]}\"/>".$i[1], $text ); |
| 41 | + foreach ( $items as $n => $i ) { |
| 42 | + $text = str_replace( $i[1], "<span id=\"dw-$n\" title=\"{$i[2]}\"/>" . $i[1], $text ); |
43 | 43 | } |
44 | 44 | } |
45 | 45 | |
— | — | @@ -58,51 +58,51 @@ |
59 | 59 | global $wgContLang, $wgRequest, $wgLang, $wgContLanguageCode; |
60 | 60 | |
61 | 61 | $match_request = $wgRequest->getText( 'match' ); |
62 | | - if ( $match_request === '' ) { |
| 62 | + if ( $match_request === '' ) { |
63 | 63 | return true; |
64 | 64 | } |
65 | 65 | $this->addMatchingTags ( $text, $match_request ); |
66 | 66 | |
67 | | - foreach( $out->mLanguageLinks as $l ) { |
| 67 | + foreach ( $out->mLanguageLinks as $l ) { |
68 | 68 | $nt = Title::newFromText( $l ); |
69 | 69 | $iw = $nt->getInterwiki(); |
70 | | - if ( $iw === $match_request ){ |
71 | | - $url = $nt->getFullURL(); |
| 70 | + if ( $iw === $match_request ) { |
| 71 | + $url = $nt->getFullURL(); |
72 | 72 | $myURL = $out->getTitle()->getLocalURL(); |
73 | 73 | $languageName = $wgContLang->getLanguageName( $nt->getInterwiki() ); |
74 | 74 | $myLanguage = $wgLang->getLanguageName( $wgContLanguageCode ); |
75 | 75 | |
76 | 76 | $translation = Http::get( wfAppendQuery( $url, array( 'action' => 'render' ) ) ); |
77 | 77 | if ( $translation !== null ) { |
78 | | - #first find all links that have no 'class' parameter. |
79 | | - #these links are local so we add '?match=xx' to their url, |
80 | | - #unless it already contains a '?' |
81 | | - $translation = preg_replace( |
| 78 | + # first find all links that have no 'class' parameter. |
| 79 | + # these links are local so we add '?match=xx' to their url, |
| 80 | + # unless it already contains a '?' |
| 81 | + $translation = preg_replace( |
82 | 82 | "/<a href=\"http:\/\/([^\"\?]*)\"(([\s]+)(c(?!lass=)|[^c\>\s])([^\>\s]*))*\>/i", |
83 | 83 | "<a href=\"http://\\1?match={$wgContLanguageCode}\"\\2>", $translation ); |
84 | | - #now add class='extiw' to these links |
85 | | - $translation = preg_replace( |
| 84 | + # now add class='extiw' to these links |
| 85 | + $translation = preg_replace( |
86 | 86 | "/<a href=\"http:\/\/([^\"]*)\"(([\s]+)(c(?!lass=)|[^c\>\s])([^\>\s]*))*\>/i", |
87 | 87 | "<a href=\"http://\\1\" class=\"extiw\"\\3>", $translation ); |
88 | | - #use class='extiw' for images too |
| 88 | + # use class='extiw' for images too |
89 | 89 | $translation = preg_replace( |
90 | 90 | "/<a href=\"http:\/\/([^\"]*)\"([^\>]*)class=\"image\"([^\>]*)\>/i", |
91 | 91 | "<a href=\"http://\\1\"\\2class=\"extiw\"\\3>", $translation ); |
92 | 92 | |
93 | | - #add prefixes to internal links, in order to prevent duplicates |
94 | | - $translation = preg_replace("/<a href=\"#(.*?)\"/i","<a href=\"#l_\\1\"", |
| 93 | + # add prefixes to internal links, in order to prevent duplicates |
| 94 | + $translation = preg_replace( "/<a href=\"#(.*?)\"/i", "<a href=\"#l_\\1\"", |
95 | 95 | $translation ); |
96 | | - $translation = preg_replace("/<li id=\"(.*?)\"/i","<li id=\"l_\\1\"", |
| 96 | + $translation = preg_replace( "/<li id=\"(.*?)\"/i", "<li id=\"l_\\1\"", |
97 | 97 | $translation ); |
98 | | - $text = preg_replace("/<a href=\"#(.*?)\"/i","<a href=\"#r_\\1\"", $text ); |
99 | | - $text = preg_replace("/<li id=\"(.*?)\"/i","<li id=\"r_\\1\"", $text ); |
| 98 | + $text = preg_replace( "/<a href=\"#(.*?)\"/i", "<a href=\"#r_\\1\"", $text ); |
| 99 | + $text = preg_replace( "/<li id=\"(.*?)\"/i", "<li id=\"r_\\1\"", $text ); |
100 | 100 | |
101 | | - #add ?match= to local links of the local wiki |
| 101 | + # add ?match= to local links of the local wiki |
102 | 102 | $text = preg_replace( "/<a href=\"\/([^\"\?]*)\"/i", |
103 | 103 | "<a href=\"/\\1?match={$match_request}\"", $text ); |
104 | 104 | |
105 | | - #do the job |
106 | | - $text = $this->matchColumns ( $text, $myLanguage, $myURL, $wgContLanguageCode, |
| 105 | + # do the job |
| 106 | + $text = $this->matchColumns ( $text, $myLanguage, $myURL, $wgContLanguageCode, |
107 | 107 | $translation, $languageName, $url, $match_request ); |
108 | 108 | } |
109 | 109 | } |
— | — | @@ -120,14 +120,14 @@ |
121 | 121 | |
122 | 122 | $body = ''; |
123 | 123 | $left_chunk = ''; |
124 | | - $right_chunk = ''; |
| 124 | + $right_chunk = ''; |
125 | 125 | |
126 | 126 | $leftSliceCount = count( $left_slices ); |
127 | | - for ( $i=0 ; $i < $leftSliceCount; $i++ ) { |
| 127 | + for ( $i = 0 ; $i < $leftSliceCount; $i++ ) { |
128 | 128 | |
129 | 129 | // some slices might be empty |
130 | | - if( $left_slices[$i] == '' ) { |
131 | | - continue; |
| 130 | + if ( $left_slices[$i] == '' ) { |
| 131 | + continue; |
132 | 132 | } |
133 | 133 | |
134 | 134 | $found = false; |
— | — | @@ -135,28 +135,28 @@ |
136 | 136 | $left_chunk .= $left_slices[$i]; |
137 | 137 | |
138 | 138 | # if we are at the end of the loop, finish quickly |
139 | | - if ( $i== count( $left_slices ) - 1 ) { |
| 139 | + if ( $i == count( $left_slices ) - 1 ) { |
140 | 140 | $right_chunk .= $right_text; |
141 | 141 | $found = true; |
142 | 142 | } else { |
143 | | - #look for requested tag in the text |
| 143 | + # look for requested tag in the text |
144 | 144 | $a = strpos ( $right_text, $tag ); |
145 | | - if( $a ) { |
146 | | - $found = true; |
147 | | - $sub = substr( $right_text, 0, $a); |
| 145 | + if ( $a ) { |
| 146 | + $found = true; |
| 147 | + $sub = substr( $right_text, 0, $a ); |
148 | 148 | // detect the end of previous paragraph |
149 | 149 | // regexp matches the rightmost delimiter |
150 | 150 | $m = array(); |
151 | | - if ( preg_match("/(.*)<\/(p|dl)>/is", $sub, $m ) ) { |
| 151 | + if ( preg_match( "/(.*)<\/(p|dl)>/is", $sub, $m ) ) { |
152 | 152 | $right_chunk .= $m[0]; |
153 | | - $right_text = substr( $right_text, strlen($m[0]) ); |
| 153 | + $right_text = substr( $right_text, strlen( $m[0] ) ); |
154 | 154 | } |
155 | | - #} else { |
| 155 | + # } else { |
156 | 156 | # print "<br/>tag not found ".$tag; |
157 | 157 | } |
158 | 158 | } |
159 | 159 | |
160 | | - if( $found && $right_chunk ) { |
| 160 | + if ( $found && $right_chunk ) { |
161 | 161 | // Detect paragraphs |
162 | 162 | $left_bits = $this->find_paragraphs( $left_chunk ); |
163 | 163 | $right_bits = $this->find_paragraphs( $right_chunk ); |
— | — | @@ -171,13 +171,13 @@ |
172 | 172 | $left_chunk = ''; |
173 | 173 | $right_chunk = ''; |
174 | 174 | $leftBitCount = count( $left_bits ); |
175 | | - for($l=0; $l < $leftBitCount ; $l++ ) { |
176 | | - $body .= |
| 175 | + for ( $l = 0; $l < $leftBitCount ; $l++ ) { |
| 176 | + $body .= |
177 | 177 | "<tr><td valign=\"top\" style=\"vertical-align:100%;padding-right: 0.5em\" lang=\"{$left_lang}\">" |
178 | | - ."<div style=\"width:35em; margin:0px auto\">\n".$left_bits[$l]."</div>" |
179 | | - ."</td>\n<td valign=\"top\" style=\"padding-left: 0.5em\" lang=\"{$right_lang}\">" |
180 | | - ."<div style=\"width:35em; margin:0px auto\">\n".$right_bits[$l]."</div>" |
181 | | - ."</td></tr>\n"; |
| 178 | + . "<div style=\"width:35em; margin:0px auto\">\n" . $left_bits[$l] . "</div>" |
| 179 | + . "</td>\n<td valign=\"top\" style=\"padding-left: 0.5em\" lang=\"{$right_lang}\">" |
| 180 | + . "<div style=\"width:35em; margin:0px auto\">\n" . $right_bits[$l] . "</div>" |
| 181 | + . "</td></tr>\n"; |
182 | 182 | } |
183 | 183 | } |
184 | 184 | } |
— | — | @@ -185,7 +185,7 @@ |
186 | 186 | // format table head and return results |
187 | 187 | $left_url = htmlspecialchars( $left_url ); |
188 | 188 | $right_url = htmlspecialchars( $right_url ); |
189 | | - $head = |
| 189 | + $head = |
190 | 190 | "<table id=\"doubleWikiTable\" width=\"100%\" border=\"0\" bgcolor=\"white\" rules=\"cols\" cellpadding=\"0\"> |
191 | 191 | <colgroup><col width=\"50%\"/><col width=\"50%\"/></colgroup><thead> |
192 | 192 | <tr><td bgcolor=\"#cfcfff\" align=\"center\" lang=\"{$left_lang}\"> |
— | — | @@ -207,23 +207,23 @@ |
208 | 208 | $counter = 0; |
209 | 209 | $out = ''; |
210 | 210 | $matchCount = count( $m ); |
211 | | - for( $i = 0; $i < $matchCount; $i++ ){ |
| 211 | + for ( $i = 0; $i < $matchCount; $i++ ) { |
212 | 212 | $t = $m[$i][0]; |
213 | | - if( substr( $t, 0, 2) != "</" ) { |
| 213 | + if ( substr( $t, 0, 2 ) != "</" ) { |
214 | 214 | $counter++; |
215 | 215 | } else { |
216 | 216 | $counter--; |
217 | 217 | } |
218 | 218 | $out .= $bits[$i] . $t; |
219 | | - if( ( $t == "</p>" || $t == "</dl>" ) && $counter == 0 ) { |
| 219 | + if ( ( $t == "</p>" || $t == "</dl>" ) && $counter == 0 ) { |
220 | 220 | $result[] = $out; |
221 | 221 | $out = ''; |
222 | 222 | } |
223 | 223 | } |
224 | | - if( $out ) { |
| 224 | + if ( $out ) { |
225 | 225 | $result[] = $out; |
226 | 226 | } |
227 | | - return $result; |
| 227 | + return $result; |
228 | 228 | } |
229 | 229 | |
230 | 230 | /* |
— | — | @@ -235,22 +235,22 @@ |
236 | 236 | $left_slices = preg_split( $tag_pattern, $left_text ); |
237 | 237 | $left_tags = array(); |
238 | 238 | preg_match_all( $tag_pattern, $left_text, $left_tags, PREG_PATTERN_ORDER ); |
239 | | - $n = count( $left_slices); |
| 239 | + $n = count( $left_slices ); |
240 | 240 | |
241 | | - /* |
| 241 | + /* |
242 | 242 | * Make slices that are full paragraphs |
243 | 243 | * If two slices correspond to the same paragraph, the second one will be empty |
244 | 244 | */ |
245 | | - for ( $i=0; $i < $n - 1; $i++ ) { |
| 245 | + for ( $i = 0; $i < $n - 1; $i++ ) { |
246 | 246 | $str = $left_slices[$i]; |
247 | 247 | $m = array(); |
248 | | - if ( preg_match("/(.*)<(p|dl)>/is", $str, $m ) ) { |
| 248 | + if ( preg_match( "/(.*)<(p|dl)>/is", $str, $m ) ) { |
249 | 249 | $left_slices[$i] = $m[1]; |
250 | | - $left_slices[$i+1] = substr( $str, strlen($m[1]) ) . $left_slices[$i+1]; |
| 250 | + $left_slices[$i + 1] = substr( $str, strlen( $m[1] ) ) . $left_slices[$i + 1]; |
251 | 251 | } |
252 | 252 | } |
253 | 253 | |
254 | | - /* |
| 254 | + /* |
255 | 255 | * Keep only slices that contain balanced html |
256 | 256 | * If a slice is unbalanced, we merge it with the next one. |
257 | 257 | * The first and last slices are compensated. |
— | — | @@ -258,36 +258,36 @@ |
259 | 259 | $stack = array(); |
260 | 260 | $opening = ''; |
261 | 261 | |
262 | | - for( $i = 0; $i < $n; $i++ ) { |
| 262 | + for ( $i = 0; $i < $n; $i++ ) { |
263 | 263 | $m = array(); |
264 | | - preg_match_all( $this->tags, $left_slices[$i], $m, PREG_SET_ORDER); |
| 264 | + preg_match_all( $this->tags, $left_slices[$i], $m, PREG_SET_ORDER ); |
265 | 265 | $counter = 0; |
266 | 266 | $matchCount = count( $m ); |
267 | | - for($k=0 ; $k < $matchCount ; $k++) { |
| 267 | + for ( $k = 0 ; $k < $matchCount ; $k++ ) { |
268 | 268 | $t = $m[$k]; |
269 | | - if( substr( $t[0], 0, 2) != "</" ) { |
| 269 | + if ( substr( $t[0], 0, 2 ) != "</" ) { |
270 | 270 | $counter++; |
271 | | - array_push($stack, $t); |
| 271 | + array_push( $stack, $t ); |
272 | 272 | } else { |
273 | | - array_pop($stack); |
| 273 | + array_pop( $stack ); |
274 | 274 | $counter--; |
275 | 275 | } |
276 | 276 | } |
277 | | - if( $i == 0 ) { |
| 277 | + if ( $i == 0 ) { |
278 | 278 | $closure = ''; |
279 | | - for( $k=0; $k < $counter ; $k++ ) { |
280 | | - $opening .= "<".$stack[$k][1].">"; |
281 | | - $closure = "</".$stack[$k][1].">" . $closure; |
| 279 | + for ( $k = 0; $k < $counter ; $k++ ) { |
| 280 | + $opening .= "<" . $stack[$k][1] . ">"; |
| 281 | + $closure = "</" . $stack[$k][1] . ">" . $closure; |
282 | 282 | } |
283 | 283 | $left_slices[$i] = $left_slices[$i] . $closure; |
284 | | - } else if( $i == $n - 1 ) { |
| 284 | + } else if ( $i == $n - 1 ) { |
285 | 285 | $left_slices[$i] = $opening . $left_slices[$i]; |
286 | | - } else if( $counter != 0 ) { |
287 | | - $left_slices[$i + 1] = $left_slices[$i] . $left_slices[$i+1]; |
| 286 | + } else if ( $counter != 0 ) { |
| 287 | + $left_slices[$i + 1] = $left_slices[$i] . $left_slices[$i + 1]; |
288 | 288 | $left_slices[$i] = ''; |
289 | 289 | } |
290 | 290 | } |
291 | | - return array($left_slices, $left_tags); |
| 291 | + return array( $left_slices, $left_tags ); |
292 | 292 | } |
293 | 293 | |
294 | 294 | } |