r82196 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82195‎ | r82196 | r82197 >
Date:21:52, 15 February 2011
Author:reedy
Status:ok
Tags:
Comment:
Stylize double wiki. My OCD is annoying me
Modified paths:
  • /trunk/extensions/DoubleWiki/DoubleWiki_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DoubleWiki/DoubleWiki_body.php
@@ -27,18 +27,18 @@
2828 /*
2929 * Read the list of matched phrases and add tags to the html output.
3030 */
31 - function addMatchingTags ( &$text, $lang ) {
 31+ function addMatchingTags ( &$text, $lang ) {
3232 $pattern = "/<div id=\"align-$lang\" style=\"display:none;\">\n<p>([^<]*?)<\/p>\n<\/div>/is";
3333 $m = array();
34 - if( ! preg_match( $pattern, $text, $m ) ) {
 34+ if ( ! preg_match( $pattern, $text, $m ) ) {
3535 return;
3636 }
3737 $text = str_replace( $m[1], '', $text );
3838 $line_pattern = "/\s*([^:\n]*?)\s*:\s*([^:\n]*?)\s*\n/i";
3939 $items = array();
4040 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 );
4343 }
4444 }
4545
@@ -58,51 +58,51 @@
5959 global $wgContLang, $wgRequest, $wgLang, $wgContLanguageCode;
6060
6161 $match_request = $wgRequest->getText( 'match' );
62 - if ( $match_request === '' ) {
 62+ if ( $match_request === '' ) {
6363 return true;
6464 }
6565 $this->addMatchingTags ( $text, $match_request );
6666
67 - foreach( $out->mLanguageLinks as $l ) {
 67+ foreach ( $out->mLanguageLinks as $l ) {
6868 $nt = Title::newFromText( $l );
6969 $iw = $nt->getInterwiki();
70 - if ( $iw === $match_request ){
71 - $url = $nt->getFullURL();
 70+ if ( $iw === $match_request ) {
 71+ $url = $nt->getFullURL();
7272 $myURL = $out->getTitle()->getLocalURL();
7373 $languageName = $wgContLang->getLanguageName( $nt->getInterwiki() );
7474 $myLanguage = $wgLang->getLanguageName( $wgContLanguageCode );
7575
7676 $translation = Http::get( wfAppendQuery( $url, array( 'action' => 'render' ) ) );
7777 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(
8282 "/<a href=\"http:\/\/([^\"\?]*)\"(([\s]+)(c(?!lass=)|[^c\>\s])([^\>\s]*))*\>/i",
8383 "<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(
8686 "/<a href=\"http:\/\/([^\"]*)\"(([\s]+)(c(?!lass=)|[^c\>\s])([^\>\s]*))*\>/i",
8787 "<a href=\"http://\\1\" class=\"extiw\"\\3>", $translation );
88 - #use class='extiw' for images too
 88+ # use class='extiw' for images too
8989 $translation = preg_replace(
9090 "/<a href=\"http:\/\/([^\"]*)\"([^\>]*)class=\"image\"([^\>]*)\>/i",
9191 "<a href=\"http://\\1\"\\2class=\"extiw\"\\3>", $translation );
9292
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\"",
9595 $translation );
96 - $translation = preg_replace("/<li id=\"(.*?)\"/i","<li id=\"l_\\1\"",
 96+ $translation = preg_replace( "/<li id=\"(.*?)\"/i", "<li id=\"l_\\1\"",
9797 $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 );
100100
101 - #add ?match= to local links of the local wiki
 101+ # add ?match= to local links of the local wiki
102102 $text = preg_replace( "/<a href=\"\/([^\"\?]*)\"/i",
103103 "<a href=\"/\\1?match={$match_request}\"", $text );
104104
105 - #do the job
106 - $text = $this->matchColumns ( $text, $myLanguage, $myURL, $wgContLanguageCode,
 105+ # do the job
 106+ $text = $this->matchColumns ( $text, $myLanguage, $myURL, $wgContLanguageCode,
107107 $translation, $languageName, $url, $match_request );
108108 }
109109 }
@@ -120,14 +120,14 @@
121121
122122 $body = '';
123123 $left_chunk = '';
124 - $right_chunk = '';
 124+ $right_chunk = '';
125125
126126 $leftSliceCount = count( $left_slices );
127 - for ( $i=0 ; $i < $leftSliceCount; $i++ ) {
 127+ for ( $i = 0 ; $i < $leftSliceCount; $i++ ) {
128128
129129 // some slices might be empty
130 - if( $left_slices[$i] == '' ) {
131 - continue;
 130+ if ( $left_slices[$i] == '' ) {
 131+ continue;
132132 }
133133
134134 $found = false;
@@ -135,28 +135,28 @@
136136 $left_chunk .= $left_slices[$i];
137137
138138 # 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 ) {
140140 $right_chunk .= $right_text;
141141 $found = true;
142142 } else {
143 - #look for requested tag in the text
 143+ # look for requested tag in the text
144144 $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 );
148148 // detect the end of previous paragraph
149149 // regexp matches the rightmost delimiter
150150 $m = array();
151 - if ( preg_match("/(.*)<\/(p|dl)>/is", $sub, $m ) ) {
 151+ if ( preg_match( "/(.*)<\/(p|dl)>/is", $sub, $m ) ) {
152152 $right_chunk .= $m[0];
153 - $right_text = substr( $right_text, strlen($m[0]) );
 153+ $right_text = substr( $right_text, strlen( $m[0] ) );
154154 }
155 - #} else {
 155+ # } else {
156156 # print "<br/>tag not found ".$tag;
157157 }
158158 }
159159
160 - if( $found && $right_chunk ) {
 160+ if ( $found && $right_chunk ) {
161161 // Detect paragraphs
162162 $left_bits = $this->find_paragraphs( $left_chunk );
163163 $right_bits = $this->find_paragraphs( $right_chunk );
@@ -171,13 +171,13 @@
172172 $left_chunk = '';
173173 $right_chunk = '';
174174 $leftBitCount = count( $left_bits );
175 - for($l=0; $l < $leftBitCount ; $l++ ) {
176 - $body .=
 175+ for ( $l = 0; $l < $leftBitCount ; $l++ ) {
 176+ $body .=
177177 "<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";
182182 }
183183 }
184184 }
@@ -185,7 +185,7 @@
186186 // format table head and return results
187187 $left_url = htmlspecialchars( $left_url );
188188 $right_url = htmlspecialchars( $right_url );
189 - $head =
 189+ $head =
190190 "<table id=\"doubleWikiTable\" width=\"100%\" border=\"0\" bgcolor=\"white\" rules=\"cols\" cellpadding=\"0\">
191191 <colgroup><col width=\"50%\"/><col width=\"50%\"/></colgroup><thead>
192192 <tr><td bgcolor=\"#cfcfff\" align=\"center\" lang=\"{$left_lang}\">
@@ -207,23 +207,23 @@
208208 $counter = 0;
209209 $out = '';
210210 $matchCount = count( $m );
211 - for( $i = 0; $i < $matchCount; $i++ ){
 211+ for ( $i = 0; $i < $matchCount; $i++ ) {
212212 $t = $m[$i][0];
213 - if( substr( $t, 0, 2) != "</" ) {
 213+ if ( substr( $t, 0, 2 ) != "</" ) {
214214 $counter++;
215215 } else {
216216 $counter--;
217217 }
218218 $out .= $bits[$i] . $t;
219 - if( ( $t == "</p>" || $t == "</dl>" ) && $counter == 0 ) {
 219+ if ( ( $t == "</p>" || $t == "</dl>" ) && $counter == 0 ) {
220220 $result[] = $out;
221221 $out = '';
222222 }
223223 }
224 - if( $out ) {
 224+ if ( $out ) {
225225 $result[] = $out;
226226 }
227 - return $result;
 227+ return $result;
228228 }
229229
230230 /*
@@ -235,22 +235,22 @@
236236 $left_slices = preg_split( $tag_pattern, $left_text );
237237 $left_tags = array();
238238 preg_match_all( $tag_pattern, $left_text, $left_tags, PREG_PATTERN_ORDER );
239 - $n = count( $left_slices);
 239+ $n = count( $left_slices );
240240
241 - /*
 241+ /*
242242 * Make slices that are full paragraphs
243243 * If two slices correspond to the same paragraph, the second one will be empty
244244 */
245 - for ( $i=0; $i < $n - 1; $i++ ) {
 245+ for ( $i = 0; $i < $n - 1; $i++ ) {
246246 $str = $left_slices[$i];
247247 $m = array();
248 - if ( preg_match("/(.*)<(p|dl)>/is", $str, $m ) ) {
 248+ if ( preg_match( "/(.*)<(p|dl)>/is", $str, $m ) ) {
249249 $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];
251251 }
252252 }
253253
254 - /*
 254+ /*
255255 * Keep only slices that contain balanced html
256256 * If a slice is unbalanced, we merge it with the next one.
257257 * The first and last slices are compensated.
@@ -258,36 +258,36 @@
259259 $stack = array();
260260 $opening = '';
261261
262 - for( $i = 0; $i < $n; $i++ ) {
 262+ for ( $i = 0; $i < $n; $i++ ) {
263263 $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 );
265265 $counter = 0;
266266 $matchCount = count( $m );
267 - for($k=0 ; $k < $matchCount ; $k++) {
 267+ for ( $k = 0 ; $k < $matchCount ; $k++ ) {
268268 $t = $m[$k];
269 - if( substr( $t[0], 0, 2) != "</" ) {
 269+ if ( substr( $t[0], 0, 2 ) != "</" ) {
270270 $counter++;
271 - array_push($stack, $t);
 271+ array_push( $stack, $t );
272272 } else {
273 - array_pop($stack);
 273+ array_pop( $stack );
274274 $counter--;
275275 }
276276 }
277 - if( $i == 0 ) {
 277+ if ( $i == 0 ) {
278278 $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;
282282 }
283283 $left_slices[$i] = $left_slices[$i] . $closure;
284 - } else if( $i == $n - 1 ) {
 284+ } else if ( $i == $n - 1 ) {
285285 $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];
288288 $left_slices[$i] = '';
289289 }
290290 }
291 - return array($left_slices, $left_tags);
 291+ return array( $left_slices, $left_tags );
292292 }
293293
294294 }

Status & tagging log