r51049 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51048‎ | r51049 | r51050 >
Date:06:51, 27 May 2009
Author:tstarling
Status:deferred
Tags:
Comment:
Style changes only, no functional changes.
* Ran stylize.php
* Added more braces, moved "else" keywords to the same line as the previous closing brace
* Reduced vertical whitespace
Modified paths:
  • /trunk/extensions/ProofreadPage/ProofreadPage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ProofreadPage/ProofreadPage.php
@@ -4,9 +4,9 @@
55 die( "ProofreadPage extension\n" );
66 }
77
8 -$dir = dirname(__FILE__) . '/';
 8+$dir = dirname( __FILE__ ) . '/';
99
10 -$wgExtensionMessagesFiles['ProofreadPage'] = dirname(__FILE__) . '/ProofreadPage.i18n.php';
 10+$wgExtensionMessagesFiles['ProofreadPage'] = dirname( __FILE__ ) . '/ProofreadPage.i18n.php';
1111
1212 $wgHooks['BeforePageDisplay'][] = 'pr_beforePageDisplay';
1313 $wgHooks['GetLinkColours'][] = 'pr_getLinkColours';
@@ -38,18 +38,15 @@
3939 }
4040
4141
42 -
4342 /**
44 - *
4543 * Query the database to find if the current page is referred in an Index page.
46 - *
4744 */
48 -function pr_load_index($title){
 45+function pr_load_index( $title ) {
4946
5047 $page_namespace = preg_quote( wfMsgForContent( 'proofreadpage_namespace' ), '/' );
5148 $index_namespace = preg_quote( wfMsgForContent( 'proofreadpage_index_namespace' ), '/' );
5249
53 - $title->pr_index_title=NULL;
 50+ $title->pr_index_title = NULL;
5451
5552 $dbr = wfGetDB( DB_SLAVE );
5653 $result = $dbr->select(
@@ -60,18 +57,18 @@
6158 'pl_title' => $title->getDBkey(),
6259 'pl_from=page_id'
6360 ),
64 - __METHOD__);
 61+ __METHOD__ );
6562
66 - while( $x = $dbr->fetchObject( $result ) ) {
 63+ while ( $x = $dbr->fetchObject( $result ) ) {
6764 $ref_title = Title::makeTitle( $x->page_namespace, $x->page_title );
68 - if( preg_match( "/^$index_namespace:(.*)$/", $ref_title->getPrefixedText() ) ) {
 65+ if ( preg_match( "/^$index_namespace:(.*)$/", $ref_title->getPrefixedText() ) ) {
6966 $title->pr_index_title = $ref_title->getPrefixedText();
7067 break;
7168 }
7269 }
7370 $dbr->freeResult( $result ) ;
7471
75 - if($title->pr_index_title) return;
 72+ if ( $title->pr_index_title ) return;
7673
7774 /*check if we are a page of a multipage file*/
7875
@@ -82,16 +79,16 @@
8380
8481 $image = wfFindFile( $imageTitle );
8582
86 - //if it is multipage, we use the page order of the file
87 - if( $image && $image->exists() && $image->isMultiPage() ) {
 83+ // if it is multipage, we use the page order of the file
 84+ if ( $image && $image->exists() && $image->isMultiPage() ) {
8885
8986 $pagenr = 1;
9087 $parts = explode( '/', $title->getText() );
91 - if( count( $parts ) > 1 ) {
 88+ if ( count( $parts ) > 1 ) {
9289 $pagenr = intval( array_pop( $parts ) );
9390 }
9491 $count = $image->pageCount();
95 - if( $pagenr < 1 || $pagenr > $count || $count == 1 )
 92+ if ( $pagenr < 1 || $pagenr > $count || $count == 1 )
9693 return $err;
9794 $name = $image->getTitle()->getText();
9895 $index_name = "$index_namespace:$name";
@@ -102,24 +99,19 @@
103100
104101 $title->pr_page_num = "$pagenr";
105102
106 - if( !$title->pr_index_title ) {
107 - //there is no index, or the page is not listed in the index : use canonical index
 103+ if ( !$title->pr_index_title ) {
 104+ // there is no index, or the page is not listed in the index : use canonical index
108105 $title->pr_index_title = $index_name;
109106 }
110 - }
 107+ }
111108
112109
113110 }
114111
115112
116 -
117113 /**
118 - *
119114 * return the URLs of the index, previous and next pages.
120 - *
121115 */
122 -
123 -
124116 function pr_navigation( $image ) {
125117 global $wgTitle;
126118 $index_title = Title::newFromText( $wgTitle->pr_index_title );
@@ -128,17 +120,17 @@
129121 $index_namespace = preg_quote( wfMsgForContent( 'proofreadpage_index_namespace' ), '/' );
130122 $err = array( '', '', '', array() );
131123
132 - //if multipage, we use the page order, but we should read pagenum from the index
133 - if( $image && $image->exists() && $image->isMultiPage() ) {
134 -
 124+ // if multipage, we use the page order, but we should read pagenum from the index
 125+ if ( $image && $image->exists() && $image->isMultiPage() ) {
135126 $pagenr = 1;
136127 $parts = explode( '/', $wgTitle->getText() );
137 - if( count( $parts ) > 1 ) {
 128+ if ( count( $parts ) > 1 ) {
138129 $pagenr = intval( array_pop( $parts ) );
139130 }
140131 $count = $image->pageCount();
141 - if( $pagenr < 1 || $pagenr > $count || $count == 1 )
 132+ if ( $pagenr < 1 || $pagenr > $count || $count == 1 ) {
142133 return $err;
 134+ }
143135 $name = $image->getTitle()->getText();
144136 $index_name = "$index_namespace:$name";
145137 $prev_name = "$page_namespace:$name/" . ( $pagenr - 1 );
@@ -146,27 +138,30 @@
147139 $prev_url = ( $pagenr == 1 ) ? '' : Title::newFromText( $prev_name )->getFullURL();
148140 $next_url = ( $pagenr == $count ) ? '' : Title::newFromText( $next_name )->getFullURL();
149141
150 - if( !$index_title ) {
151 - //there is no index, or the page is not listed in the index : use canonical index
 142+ if ( !$index_title ) {
 143+ // there is no index, or the page is not listed in the index : use canonical index
152144 $index_title = Title::newFromText( $index_name );
153145 }
154 - }
155 - else {
 146+ } else {
156147 $prev_url = '';
157148 $next_url = '';
158149 }
159150
160 - if( !$index_title ) return array( '', $prev_url, $next_url, array() ) ;
 151+ if ( !$index_title ) {
 152+ return array( '', $prev_url, $next_url, array() ) ;
 153+ }
161154
162155 $index_url = $index_title->getFullURL();
163156
164 - if( !$index_title->exists()) return array( $index_url, $prev_url, $next_url, array() );
 157+ if ( !$index_title->exists() ) {
 158+ return array( $index_url, $prev_url, $next_url, array() );
 159+ }
165160
166 - //if the index page exists, read metadata
167 - list( $prev_title, $next_title, $attributes ) = pr_parse_index($index_title,$wgTitle);
 161+ // if the index page exists, read metadata
 162+ list( $prev_title, $next_title, $attributes ) = pr_parse_index( $index_title, $wgTitle );
168163
169 - if($prev_title) $prev_url = $prev_title->getFullURL();
170 - if($next_title) $next_url = $next_title->getFullURL();
 164+ if ( $prev_title ) $prev_url = $prev_title->getFullURL();
 165+ if ( $next_title ) $next_url = $next_title->getFullURL();
171166
172167 return array( $index_url, $prev_url, $next_url, $attributes );
173168
@@ -177,68 +172,68 @@
178173 read metadata from the index page
179174 if page_title is provided, return page number, previous and next pages
180175 */
 176+function pr_parse_index( $index_title, $page_title ) {
181177
182 -function pr_parse_index($index_title, $page_title){
183 -
184178 $err = array( '', '', array() );
185179
186180 $page_namespace = preg_quote( wfMsgForContent( 'proofreadpage_namespace' ), '/' );
187181 $index_namespace = preg_quote( wfMsgForContent( 'proofreadpage_index_namespace' ), '/' );
188182
189 - if( !$index_title ) return $err;
190 - if( !$index_title->exists() ) return $err;
 183+ if ( !$index_title ) return $err;
 184+ if ( !$index_title->exists() ) return $err;
191185
192186 $rev = Revision::newFromTitle( $index_title );
193187 $text = $rev->getText();
194188
195189 $attributes = array();
196190
197 - if($page_title){
198 - //find page number, previous and next pages
 191+ if ( $page_title ) {
 192+ // find page number, previous and next pages
199193
200 - //default pagenum was set during load()
201 - if($page_title->pr_page_num) $attributes["pagenum"] = $page_title->pr_page_num;
 194+ // default pagenum was set during load()
 195+ if ( $page_title->pr_page_num ) $attributes["pagenum"] = $page_title->pr_page_num;
202196
203 - //check if it is using pagelist
 197+ // check if it is using pagelist
204198 preg_match( "/<pagelist(.*?)\/>/i", $text, $m );
205 - if($m){
206 - preg_match_all( "/([0-9a-z]*?)\=(.*?)\s/", $m[1]." ", $m2, PREG_PATTERN_ORDER );
 199+ if ( $m ) {
 200+ preg_match_all( "/([0-9a-z]*?)\=(.*?)\s/", $m[1] . " ", $m2, PREG_PATTERN_ORDER );
207201 $params = array();
208 - for( $i=0; $i<count( $m2[1] ); $i++) {
 202+ for ( $i = 0; $i < count( $m2[1] ); $i++ ) {
209203 $params[ $m2[1][$i] ] = $m2[2][$i];
210204 }
211 - list($view, $links, $mode) = pr_pageNumber($page_title->pr_page_num,$params);
 205+ list( $view, $links, $mode ) = pr_pageNumber( $page_title->pr_page_num, $params );
212206 $attributes["pagenum"] = $view;
213 - }
214 - else{
215 -
 207+ } else {
216208 $tag_pattern = "/\[\[($page_namespace:.*?)(\|(.*?)|)\]\]/i";
217209 preg_match_all( $tag_pattern, $text, $links, PREG_PATTERN_ORDER );
218210
219 - for( $i=0; $i<count( $links[1] ); $i++) {
 211+ for ( $i = 0; $i < count( $links[1] ); $i++ ) {
220212 $a_title = Title::newFromText( $links[1][$i] );
221 - if(!$a_title) continue;
222 - if( $a_title->getPrefixedText() == $page_title->getPrefixedText() ) {
 213+ if ( !$a_title ) continue;
 214+ if ( $a_title->getPrefixedText() == $page_title->getPrefixedText() ) {
223215 $attributes["pagenum"] = $links[3][$i];
224216 break;
225217 }
226218 }
227 - if( ($i>0) && ($i<count($links[1])) ){
228 - $prev_title = Title::newFromText( $links[1][$i-1] );
 219+ if ( ( $i > 0 ) && ( $i < count( $links[1] ) ) ) {
 220+ $prev_title = Title::newFromText( $links[1][$i - 1] );
229221 }
230 - if( ($i>=0) && ($i+1<count($links[1])) ){
231 - $next_title = Title::newFromText( $links[1][$i+1] );
 222+ if ( ( $i >= 0 ) && ( $i + 1 < count( $links[1] ) ) ) {
 223+ $next_title = Title::newFromText( $links[1][$i + 1] );
232224 }
233225 }
234226 }
235227
236 - $var_names = explode(" ", wfMsgForContent('proofreadpage_js_attributes') );
237 - for($i=0; $i< count($var_names);$i++){
238 - $tag_pattern = "/\n\|".$var_names[$i]."=(.*?)\n/i";
239 - //$var = 'proofreadPage'.$var_names[$i];
240 - $var = strtolower($var_names[$i]);
241 - if( preg_match( $tag_pattern, $text, $matches ) ) $attributes[$var] = $matches[1];
242 - else $attributes[$var] = '';
 228+ $var_names = explode( " ", wfMsgForContent( 'proofreadpage_js_attributes' ) );
 229+ for ( $i = 0; $i < count( $var_names ); $i++ ) {
 230+ $tag_pattern = "/\n\|" . $var_names[$i] . "=(.*?)\n/i";
 231+ // $var = 'proofreadPage'.$var_names[$i];
 232+ $var = strtolower( $var_names[$i] );
 233+ if ( preg_match( $tag_pattern, $text, $matches ) ) {
 234+ $attributes[$var] = $matches[1];
 235+ } else {
 236+ $attributes[$var] = '';
 237+ }
243238 }
244239 return array( $prev_title, $next_title, $attributes );
245240
@@ -246,16 +241,13 @@
247242
248243
249244 /**
250 - *
251245 * Append javascript variables and code to the page.
252 - *
253246 */
254 -
255247 function pr_beforePageDisplay( &$out ) {
256248 global $wgTitle, $wgJsMimeType, $wgScriptPath, $wgRequest, $wgProofreadPageVersion;
257249
258250 wfLoadExtensionMessages( 'ProofreadPage' );
259 - $action = $wgRequest->getVal('action');
 251+ $action = $wgRequest->getVal( 'action' );
260252 $isEdit = ( $action == 'submit' || $action == 'edit' ) ? 1 : 0;
261253 if ( !isset( $wgTitle ) || ( !$out->isArticle() && !$isEdit ) || isset( $out->proofreadPageDone ) ) {
262254 return true;
@@ -264,13 +256,15 @@
265257
266258 $page_namespace = preg_quote( wfMsgForContent( 'proofreadpage_namespace' ), '/' );
267259 if ( preg_match( "/^$page_namespace:(.*?)(\/([0-9]*)|)$/", $wgTitle->getPrefixedText(), $m ) ) {
268 - if( !isset($wgTitle->pr_index_title) ) pr_load_index($wgTitle);
 260+ if ( !isset( $wgTitle->pr_index_title ) ) {
 261+ pr_load_index( $wgTitle );
 262+ }
269263 pr_preparePage( $out, $m, $isEdit );
270264 return true;
271265 }
272266
273267 $index_namespace = preg_quote( wfMsgForContent( 'proofreadpage_index_namespace' ), '/' );
274 - if ( $isEdit && (preg_match( "/^$index_namespace:(.*?)(\/([0-9]*)|)$/", $wgTitle->getPrefixedText(), $m ) ) ) {
 268+ if ( $isEdit && ( preg_match( "/^$index_namespace:(.*?)(\/([0-9]*)|)$/", $wgTitle->getPrefixedText(), $m ) ) ) {
275269 pr_prepareIndex( $out );
276270 return true;
277271 }
@@ -289,17 +283,13 @@
290284 EOT
291285 );
292286 $out->addScript( "<script type=\"{$wgJsMimeType}\">
293 -var prp_index_attributes = \"" . Xml::escapeJsString(wfMsgForContent('proofreadpage_index_attributes')) . "\";
 287+var prp_index_attributes = \"" . Xml::escapeJsString( wfMsgForContent( 'proofreadpage_index_attributes' ) ) . "\";
294288 </script>\n"
295289 );
296290
297291 }
298292
299293
300 -
301 -
302 -
303 -
304294 function pr_preparePage( $out, $m, $isEdit ) {
305295 global $wgJsMimeType, $wgScriptPath, $wgRequest, $wgProofreadPageVersion;
306296
@@ -312,21 +302,19 @@
313303 if ( $image && $image->exists() ) {
314304 $width = $image->getWidth();
315305 $height = $image->getHeight();
316 - if($m[2]) {
 306+ if ( $m[2] ) {
317307 $viewName = $image->thumbName( array( 'width' => $width, 'page' => $m[3] ) );
318308 $viewURL = $image->getThumbUrl( $viewName );
319309
320310 $thumbName = $image->thumbName( array( 'width' => '##WIDTH##', 'page' => $m[3] ) );
321311 $thumbURL = $image->getThumbUrl( $thumbName );
322 - }
323 - else {
 312+ } else {
324313 $viewURL = $image->getViewURL();
325314 $thumbName = $image->thumbName( array( 'width' => '##WIDTH##' ) );
326315 $thumbURL = $image->getThumbUrl( $thumbName );
327316 }
328317 $thumbURL = str_replace( '%23', '#', $thumbURL );
329 - }
330 - else {
 318+ } else {
331319 $width = 0;
332320 $height = 0;
333321 $viewURL = '';
@@ -348,10 +336,10 @@
349337 'proofreadPageNextURL' => $next_url,
350338 ) + $attributes;
351339
352 - //Header and Footer
353 - $header = $attributes['header'] ? $attributes['header'] : wfMsgGetKey('proofreadpage_default_header',true,false,false);
354 - $footer = $attributes['footer'] ? $attributes['footer'] : wfMsgGetKey('proofreadpage_default_footer',true,false,false);
355 - foreach($attributes as $key=>$val){
 340+ // Header and Footer
 341+ $header = $attributes['header'] ? $attributes['header'] : wfMsgGetKey( 'proofreadpage_default_header', true, false, false );
 342+ $footer = $attributes['footer'] ? $attributes['footer'] : wfMsgGetKey( 'proofreadpage_default_footer', true, false, false );
 343+ foreach ( $attributes as $key => $val ) {
356344 $header = str_replace( "{{{{$key}}}}", $val, $header );
357345 $footer = str_replace( "{{{{$key}}}}", $val, $footer );
358346 }
@@ -369,21 +357,21 @@
370358
371359 # Add messages from i18n
372360 $out->addScript( "<script type=\"{$wgJsMimeType}\">
373 -var proofreadPageMessageIndex = \"" . Xml::escapeJsString(wfMsg('proofreadpage_index')) . "\";
374 -var proofreadPageMessageNextPage = \"" . Xml::escapeJsString(wfMsg('proofreadpage_nextpage')) . "\";
375 -var proofreadPageMessagePrevPage = \"" . Xml::escapeJsString(wfMsg('proofreadpage_prevpage')) . "\";
376 -var proofreadPageMessageImage = \"" . Xml::escapeJsString(wfMsg('proofreadpage_image')) . "\";
377 -var proofreadPageMessageHeader = \"" . Xml::escapeJsString(wfMsg('proofreadpage_header')) . "\";
378 -var proofreadPageMessagePageBody = \"" . Xml::escapeJsString(wfMsg('proofreadpage_body')) . "\";
379 -var proofreadPageMessageFooter = \"" . Xml::escapeJsString(wfMsg('proofreadpage_footer')) . "\";
380 -var proofreadPageMessageToggleHeaders = \"" . Xml::escapeJsString(wfMsg('proofreadpage_toggleheaders')) . "\";
381 -var proofreadPageMessageStatus = \"" . Xml::escapeJsString(wfMsg('proofreadpage_page_status')) . "\";
382 -var proofreadPageMessageQuality0 = \"" . Xml::escapeJsString(wfMsgForContent('proofreadpage_quality0_category')) . "\";
383 -var proofreadPageMessageQuality1 = \"" . Xml::escapeJsString(wfMsgForContent('proofreadpage_quality1_category')) . "\";
384 -var proofreadPageMessageQuality2 = \"" . Xml::escapeJsString(wfMsgForContent('proofreadpage_quality2_category')) . "\";
385 -var proofreadPageMessageQuality3 = \"" . Xml::escapeJsString(wfMsgForContent('proofreadpage_quality3_category')) . "\";
386 -var proofreadPageMessageQuality4 = \"" . Xml::escapeJsString(wfMsgForContent('proofreadpage_quality4_category')) . "\";
387 -</script>\n"
 361+var proofreadPageMessageIndex = \"" . Xml::escapeJsString( wfMsg( 'proofreadpage_index' ) ) . "\";
 362+var proofreadPageMessageNextPage = \"" . Xml::escapeJsString( wfMsg( 'proofreadpage_nextpage' ) ) . "\";
 363+var proofreadPageMessagePrevPage = \"" . Xml::escapeJsString( wfMsg( 'proofreadpage_prevpage' ) ) . "\";
 364+var proofreadPageMessageImage = \"" . Xml::escapeJsString( wfMsg( 'proofreadpage_image' ) ) . "\";
 365+var proofreadPageMessageHeader = \"" . Xml::escapeJsString( wfMsg( 'proofreadpage_header' ) ) . "\";
 366+var proofreadPageMessagePageBody = \"" . Xml::escapeJsString( wfMsg( 'proofreadpage_body' ) ) . "\";
 367+var proofreadPageMessageFooter = \"" . Xml::escapeJsString( wfMsg( 'proofreadpage_footer' ) ) . "\";
 368+var proofreadPageMessageToggleHeaders = \"" . Xml::escapeJsString( wfMsg( 'proofreadpage_toggleheaders' ) ) . "\";
 369+var proofreadPageMessageStatus = \"" . Xml::escapeJsString( wfMsg( 'proofreadpage_page_status' ) ) . "\";
 370+var proofreadPageMessageQuality0 = \"" . Xml::escapeJsString( wfMsgForContent( 'proofreadpage_quality0_category' ) ) . "\";
 371+var proofreadPageMessageQuality1 = \"" . Xml::escapeJsString( wfMsgForContent( 'proofreadpage_quality1_category' ) ) . "\";
 372+var proofreadPageMessageQuality2 = \"" . Xml::escapeJsString( wfMsgForContent( 'proofreadpage_quality2_category' ) ) . "\";
 373+var proofreadPageMessageQuality3 = \"" . Xml::escapeJsString( wfMsgForContent( 'proofreadpage_quality3_category' ) ) . "\";
 374+var proofreadPageMessageQuality4 = \"" . Xml::escapeJsString( wfMsgForContent( 'proofreadpage_quality4_category' ) ) . "\";
 375+</script>\n"
388376 );
389377 return true;
390378 }
@@ -407,17 +395,15 @@
408396 return true;
409397 }
410398
411 - //counters
 399+ // counters
412400 $n = $n1 = $n2 = $n3 = $n4 = 0;
413401
414402 $dbr = wfGetDB( DB_SLAVE );
415403 $catlinks = $dbr->tableName( 'categorylinks' );
416404 foreach ( $page_ids as $id => $pdbk ) {
417 -
418405 // consider only link in page namespace
419406 $page_namespace = preg_quote( wfMsgForContent( 'proofreadpage_namespace' ), '/' );
420407 if ( preg_match( "/^$page_namespace:(.*?)$/", $pdbk ) ) {
421 -
422408 $colours[$pdbk] = 'quality1';
423409 $n++;
424410
@@ -434,24 +420,22 @@
435421 $query .= ')';
436422 $res = $dbr->query( $query, __METHOD__ );
437423
438 - while ( $x = $dbr->fetchObject($res) ) {
439 -
 424+ while ( $x = $dbr->fetchObject( $res ) ) {
440425 $pdbk = $page_ids[$x->cl_from];
441 -
442 - switch($x->cl_to){
443 - case str_replace( ' ' , '_' , wfMsgForContent('proofreadpage_quality1_category')):
 426+ switch( $x->cl_to ) {
 427+ case str_replace( ' ' , '_' , wfMsgForContent( 'proofreadpage_quality1_category' ) ):
444428 $colours[$pdbk] = 'quality1';
445429 $n1++;
446430 break;
447 - case str_replace( ' ' , '_' , wfMsgForContent('proofreadpage_quality2_category')):
 431+ case str_replace( ' ' , '_' , wfMsgForContent( 'proofreadpage_quality2_category' ) ):
448432 $colours[$pdbk] = 'quality2';
449433 $n2++;
450434 break;
451 - case str_replace( ' ' , '_' , wfMsgForContent('proofreadpage_quality3_category')):
 435+ case str_replace( ' ' , '_' , wfMsgForContent( 'proofreadpage_quality3_category' ) ):
452436 $colours[$pdbk] = 'quality3';
453437 $n3++;
454438 break;
455 - case str_replace( ' ' , '_' , wfMsgForContent('proofreadpage_quality4_category')):
 439+ case str_replace( ' ' , '_' , wfMsgForContent( 'proofreadpage_quality4_category' ) ):
456440 $colours[$pdbk] = 'quality4';
457441 $n4++;
458442 break;
@@ -463,7 +447,6 @@
464448 }
465449
466450 function pr_imageMessage( &$imgpage , &$wgOut ) {
467 -
468451 global $wgUser;
469452 $sk = $wgUser->getSkin();
470453
@@ -476,135 +459,136 @@
477460 $index_namespace = preg_quote( wfMsgForContent( 'proofreadpage_index_namespace' ), '/' );
478461 $name = $image->getTitle()->getText();
479462
480 - $link = $sk->makeKnownLink( "$index_namespace:$name", wfMsg('proofreadpage_image_message') );
 463+ $link = $sk->makeKnownLink( "$index_namespace:$name", wfMsg( 'proofreadpage_image_message' ) );
481464 $wgOut->addHTML( "{$link}" );
482465
483466 return true;
484467 }
485468
486469
487 -
488 -//credit : http://www.mediawiki.org/wiki/Extension:RomanNumbers
489 -function toRoman($num) {
490 -if ($num < 0 || $num > 9999) return -1;
 470+// credit : http://www.mediawiki.org/wiki/Extension:RomanNumbers
 471+function toRoman( $num ) {
 472+ if ( $num < 0 || $num > 9999 ) {
 473+ return - 1;
 474+ }
491475
492 - $romanOnes = array(1=> "I",2=>"II",3=>"III",4=>"IV", 5=>"V", 6=>"VI", 7=>"VII", 8=>"VIII", 9=>"IX" );
493 - $romanTens = array(1=> "X", 2=>"XX", 3=>"XXX", 4=>"XL", 5=>"L", 6=>"LX", 7=>"LXX",8=>"LXXX", 9=>"XC");
494 - $romanHund = array(1=> "C", 2=>"CC", 3=>"CCC", 4=>"CD", 5=>"D", 6=>"DC", 7=>"DCC",8=>"DCCC", 9=>"CM");
495 - $romanThou = array(1=> "M", 2=>"MM", 3=>"MMM", 4=>"MMMM", 5=>"MMMMM", 6=>"MMMMMM",7=>"MMMMMMM", 8=>"MMMMMMMM", 9=>"MMMMMMMMM");
 476+ $romanOnes = array( 1 => "I", 2 => "II", 3 => "III", 4 => "IV", 5 => "V", 6 => "VI", 7 => "VII", 8 => "VIII", 9 => "IX" );
 477+ $romanTens = array( 1 => "X", 2 => "XX", 3 => "XXX", 4 => "XL", 5 => "L", 6 => "LX", 7 => "LXX", 8 => "LXXX", 9 => "XC" );
 478+ $romanHund = array( 1 => "C", 2 => "CC", 3 => "CCC", 4 => "CD", 5 => "D", 6 => "DC", 7 => "DCC", 8 => "DCCC", 9 => "CM" );
 479+ $romanThou = array( 1 => "M", 2 => "MM", 3 => "MMM", 4 => "MMMM", 5 => "MMMMM", 6 => "MMMMMM", 7 => "MMMMMMM", 8 => "MMMMMMMM", 9 => "MMMMMMMMM" );
496480
497481 $ones = $num % 10;
498 - $tens = ($num - $ones) % 100;
499 - $hund = ($num - $tens - $ones) % 1000;
500 - $thou = ($num - $hund - $tens - $ones) % 10000;
 482+ $tens = ( $num - $ones ) % 100;
 483+ $hund = ( $num - $tens - $ones ) % 1000;
 484+ $thou = ( $num - $hund - $tens - $ones ) % 10000;
501485
502486 $tens = $tens / 10;
503487 $hund = $hund / 100;
504488 $thou = $thou / 1000;
505489
506 - if ($thou) $romanNum .= $romanThou[$thou];
507 - if ($hund) $romanNum .= $romanHund[$hund];
508 - if ($tens) $romanNum .= $romanTens[$tens];
509 - if ($ones) $romanNum .= $romanOnes[$ones];
 490+ if ( $thou ) $romanNum .= $romanThou[$thou];
 491+ if ( $hund ) $romanNum .= $romanHund[$hund];
 492+ if ( $tens ) $romanNum .= $romanTens[$tens];
 493+ if ( $ones ) $romanNum .= $romanOnes[$ones];
510494
511 - return $romanNum;
 495+ return $romanNum;
512496 }
513497
514498
515 -
516499 function pr_renderIndexTag( $input, $args ) {
517500 global $wgParser, $wgTitle;
518501
519 - if( !isset($wgTitle->pr_index_title) ) pr_load_index($wgTitle);
 502+ if ( !isset( $wgTitle->pr_index_title ) ) {
 503+ pr_load_index( $wgTitle );
 504+ }
520505
521506 $index_namespace = preg_quote( wfMsgForContent( 'proofreadpage_index_namespace' ), '/' );
522507
523508 $name = $args['src'];
524 - if( $name )
 509+ if ( $name ) {
525510 $index_title = Title::newFromText( "$index_namespace:$name" );
526 - else
 511+ } else {
527512 $index_title = Title::newFromText( $wgTitle->pr_index_title );
 513+ }
528514
529 - if( ! $index_title || ! $index_title->exists() ) return "error: no such index: $index_namespace:$name";
 515+ if ( ! $index_title || ! $index_title->exists() ) {
 516+ return "error: no such index: $index_namespace:$name";
 517+ }
530518
531 - if($wgTitle->pr_index_title) $page_index = $wgTitle; else $page_index=NULL;
 519+ if ( $wgTitle->pr_index_title ) {
 520+ $page_index = $wgTitle;
 521+ } else {
 522+ $page_index = NULL;
 523+ }
532524
533 - //here we must parse the index everytime we render the tag:
534 - //it would be better to store the attributes in a table
535 - //especially in the case of a 'special' page
 525+ // here we must parse the index everytime we render the tag:
 526+ // it would be better to store the attributes in a table
 527+ // especially in the case of a 'special' page
536528 list( $prev_title, $next_title, $attributes ) = pr_parse_index( $index_title, $page_index );
537529
538 - //first parse
539 - $input = $wgParser->recursiveTagParse($input);
540 -
541 - foreach($attributes as $key=>$val){
 530+ // first parse
 531+ $input = $wgParser->recursiveTagParse( $input );
 532+ foreach ( $attributes as $key => $val ) {
542533 $input = str_replace( "{{{{$key}}}}", $val, $input );
543534 }
544535
545 -
546 - $out = $wgParser->recursiveTagParse($input);
547 -
 536+ $out = $wgParser->recursiveTagParse( $input );
548537 return $out;
549 -
550538 }
551539
552540
553 -
554 -function pr_pageNumber($i,$args){
555 - $mode = 'normal'; //default
 541+function pr_pageNumber( $i, $args ) {
 542+ $mode = 'normal'; // default
556543 $offset = 0;
557544 $links = true;
558545 foreach ( $args as $num => $param ) {
559 -
560 - if( ( preg_match( "/^([0-9]*)to([0-9]*)$/", $num, $m ) && ( $i>=$m[1] && $i<=$m[2] ) )
561 - || ( is_numeric($num) && ($i == $num) ) ) {
562 - $params = explode(";",$param);
 546+ if ( ( preg_match( "/^([0-9]*)to([0-9]*)$/", $num, $m ) && ( $i >= $m[1] && $i <= $m[2] ) )
 547+ || ( is_numeric( $num ) && ( $i == $num ) ) ) {
 548+ $params = explode( ";", $param );
563549 foreach ( $params as $iparam ) {
564 - switch($iparam){
565 - case 'roman':
 550+ switch( $iparam ) {
 551+ case 'roman':
566552 $mode = 'roman';
567553 break;
568 - case 'highroman':
 554+ case 'highroman':
569555 $mode = 'highroman';
570556 break;
571 - case 'empty':
 557+ case 'empty':
572558 $links = false;
573559 break;
574560 default:
575 - if(!is_numeric($iparam))
 561+ if ( !is_numeric( $iparam ) )
576562 $mode = $iparam;
577563 }
578564 }
579565 }
580566
581 - if( is_numeric($num) && ($i >= $num) ) {
582 - $params = explode(";",$param);
583 - foreach ( $params as $iparam )
584 - if(is_numeric($iparam))
 567+ if ( is_numeric( $num ) && ( $i >= $num ) ) {
 568+ $params = explode( ";", $param );
 569+ foreach ( $params as $iparam )
 570+ if ( is_numeric( $iparam ) )
585571 $offset = $num - $iparam;
586572 }
587573
588574 }
589 - $view = ($i - $offset);
590 - switch($mode) {
591 - case 'highroman':
592 - $view = toRoman($view); break;
593 - case 'roman':
594 - $view = strtolower(toRoman($view)); break;
595 - case 'normal':
596 - $view = ''.$view; break;
597 - case 'empty':
598 - $view = ''.$view; break;
599 - default:
 575+ $view = ( $i - $offset );
 576+ switch( $mode ) {
 577+ case 'highroman':
 578+ $view = toRoman( $view ); break;
 579+ case 'roman':
 580+ $view = strtolower( toRoman( $view ) ); break;
 581+ case 'normal':
 582+ $view = '' . $view; break;
 583+ case 'empty':
 584+ $view = '' . $view; break;
 585+ default:
600586 $view = $mode;
601587 }
602 - return array($view,$links,$mode);
 588+ return array( $view, $links, $mode );
603589 }
604 -
605590
606591
607592 function pr_renderPageList( $input, $args ) {
608 -
609593 global $wgUser, $wgTitle;
610594 wfLoadExtensionMessages( 'ProofreadPage' );
611595 $index_namespace = preg_quote( wfMsgForContent( 'proofreadpage_index_namespace' ), '/' );
@@ -617,10 +601,9 @@
618602 return true;
619603 }
620604 $image = wfFindFile( $imageTitle );
621 - $return="";
 605+ $return = "";
622606
623607 if ( $image && $image->isMultipage() ) {
624 -
625608 $name = $imageTitle->getDBkey();
626609 $count = $image->pageCount();
627610 $dbr = wfGetDB( DB_SLAVE );
@@ -628,19 +611,18 @@
629612
630613 $page_namespace = preg_quote( wfMsgForContent( 'proofreadpage_namespace' ), '/' );
631614 $page_ns_index = MWNamespace::getCanonicalIndex( strtolower( $page_namespace ) );
632 - if( $page_ns_index == NULL ) {
 615+ if ( $page_ns_index == NULL ) {
633616 $page_ns_index = NS_MAIN;
634617 }
635618
636 - for( $i=0; $i<$count ; $i++) {
637 -
 619+ for ( $i = 0; $i < $count ; $i++ ) {
638620 if ( !isset( $query ) ) {
639621 $query = "SELECT page_id, page_title, page_namespace";
640622 $query .= " FROM $pagetable WHERE (page_namespace=$page_ns_index AND page_title IN(";
641623 } else {
642624 $query .= ', ';
643625 }
644 - $link_name = "$name" . '/'. ($i+1) ;
 626+ $link_name = "$name" . '/' . ( $i + 1 ) ;
645627 $query .= $dbr->addQuotes( $link_name );
646628 }
647629 $query .= '))';
@@ -648,7 +630,7 @@
649631
650632 $colours = array();
651633 $linkcolour_ids = array();
652 - while ( $s = $dbr->fetchObject($res) ) {
 634+ while ( $s = $dbr->fetchObject( $res ) ) {
653635 $title = Title::makeTitle( $s->page_namespace, $s->page_title );
654636 $pdbk = $title->getPrefixedDBkey();
655637 $colours[$pdbk] = 'known';
@@ -658,27 +640,28 @@
659641
660642 $sk = $wgUser->getSkin();
661643
662 - for( $i=1; $i<$count+1 ; $i++) {
 644+ for ( $i = 1; $i < $count + 1 ; $i++ ) {
 645+ $pdbk = "$page_namespace:$name" . '/' . $i ;
 646+ list( $view, $links, $mode ) = pr_pageNumber( $i, $args );
663647
664 - $pdbk = "$page_namespace:$name" . '/'. $i ;
665 - list( $view, $links, $mode ) = pr_pageNumber($i,$args);
 648+ if ( $mode == 'highroman' || $mode == 'roman' ) $view = '&nbsp;' . $view;
666649
667 - if($mode == 'highroman' || $mode == 'roman') $view = '&nbsp;'.$view;
668 -
669 - $n = strlen($count) - strlen($view);
670 - if( $n && ($mode == 'normal' || $mode == 'empty') ){
 650+ $n = strlen( $count ) - strlen( $view );
 651+ if ( $n && ( $mode == 'normal' || $mode == 'empty' ) ) {
671652 $txt = '<span style="visibility:hidden;">';
672 - for( $j=0; $j<$n; $j++) $txt = $txt.'0';
673 - $view = $txt.'</span>'.$view;
 653+ for ( $j = 0; $j < $n; $j++ ) {
 654+ $txt = $txt . '0';
 655+ }
 656+ $view = $txt . '</span>' . $view;
674657 }
675658 $title = Title::newFromText( $pdbk );
676659
677 - if($links==false) $return.= $view." ";
678 - else{
 660+ if ( $links == false ) {
 661+ $return .= $view . " ";
 662+ } else {
679663 if ( !isset( $colours[$pdbk] ) ) {
680664 $link = $sk->makeBrokenLinkObj( $title, $view );
681 - }
682 - else {
 665+ } else {
683666 $link = $sk->makeColouredLinkObj( $title, $colours[$pdbk], $view );
684667 }
685668 $return .= "{$link} ";
@@ -698,10 +681,11 @@
699682
700683 $title = $article->mTitle;
701684
702 - if( preg_match( "/^$page_namespace:(.*)$/", $title->getPrefixedText() ) ) {
703 -
704 - if( !isset($title->pr_index_title) ) pr_load_index($title);
705 - if( $title->pr_index_title) {
 685+ if ( preg_match( "/^$page_namespace:(.*)$/", $title->getPrefixedText() ) ) {
 686+ if ( !isset( $title->pr_index_title ) ) {
 687+ pr_load_index( $title );
 688+ }
 689+ if ( $title->pr_index_title ) {
706690 $index_title = Title::makeTitleSafe( $index_namespace, $title->pr_index_title );
707691 $index_title->invalidateCache();
708692 }
@@ -712,14 +696,12 @@
713697 }
714698
715699
716 -
717700 function pr_preloadText( $textbox1, $mTitle ) {
718701 global $wgDjvuTxt;
719702
720703 $page_namespace = preg_quote( wfMsgForContent( 'proofreadpage_namespace' ), '/' );
721704
722705 if ( $wgDjvuTxt && preg_match( "/^$page_namespace:(.*?)\/([0-9]*)$/", $mTitle->getPrefixedText(), $m ) ) {
723 -
724706 $imageTitle = Title::makeTitleSafe( NS_IMAGE, $m[1] );
725707 if ( !$imageTitle ) {
726708 return true;
@@ -727,15 +709,14 @@
728710
729711 $image = wfFindFile( $imageTitle );
730712 if ( $image && $image->exists() && $image->getMimeType() == 'image/vnd.djvu' ) {
731 -
732713 $name = $image->thumbName( array( 'width' => '##WIDTH##', 'page' => $m[2] ) );
733714 $name = str_replace( '##WIDTH##px', 'djvutxt', $name );
734715 $name = str_replace( '.jpg', '.txt', $name );
735716 $url = $image->getThumbUrl( $name );
736717
737 - if($url[0]=='/') $url = "http://localhost" . $url;
738 - $text = Http::get($url);
739 - if($text) $textbox1 = $text;
 718+ if ( $url[0] == '/' ) $url = "http://localhost" . $url;
 719+ $text = Http::get( $url );
 720+ if ( $text ) $textbox1 = $text;
740721 }
741722 }
742723 return true;

Status & tagging log