Index: trunk/extensions/ProofreadPage/ProofreadPage.php |
— | — | @@ -4,9 +4,9 @@ |
5 | 5 | die( "ProofreadPage extension\n" ); |
6 | 6 | } |
7 | 7 | |
8 | | -$dir = dirname(__FILE__) . '/'; |
| 8 | +$dir = dirname( __FILE__ ) . '/'; |
9 | 9 | |
10 | | -$wgExtensionMessagesFiles['ProofreadPage'] = dirname(__FILE__) . '/ProofreadPage.i18n.php'; |
| 10 | +$wgExtensionMessagesFiles['ProofreadPage'] = dirname( __FILE__ ) . '/ProofreadPage.i18n.php'; |
11 | 11 | |
12 | 12 | $wgHooks['BeforePageDisplay'][] = 'pr_beforePageDisplay'; |
13 | 13 | $wgHooks['GetLinkColours'][] = 'pr_getLinkColours'; |
— | — | @@ -38,18 +38,15 @@ |
39 | 39 | } |
40 | 40 | |
41 | 41 | |
42 | | - |
43 | 42 | /** |
44 | | - * |
45 | 43 | * Query the database to find if the current page is referred in an Index page. |
46 | | - * |
47 | 44 | */ |
48 | | -function pr_load_index($title){ |
| 45 | +function pr_load_index( $title ) { |
49 | 46 | |
50 | 47 | $page_namespace = preg_quote( wfMsgForContent( 'proofreadpage_namespace' ), '/' ); |
51 | 48 | $index_namespace = preg_quote( wfMsgForContent( 'proofreadpage_index_namespace' ), '/' ); |
52 | 49 | |
53 | | - $title->pr_index_title=NULL; |
| 50 | + $title->pr_index_title = NULL; |
54 | 51 | |
55 | 52 | $dbr = wfGetDB( DB_SLAVE ); |
56 | 53 | $result = $dbr->select( |
— | — | @@ -60,18 +57,18 @@ |
61 | 58 | 'pl_title' => $title->getDBkey(), |
62 | 59 | 'pl_from=page_id' |
63 | 60 | ), |
64 | | - __METHOD__); |
| 61 | + __METHOD__ ); |
65 | 62 | |
66 | | - while( $x = $dbr->fetchObject( $result ) ) { |
| 63 | + while ( $x = $dbr->fetchObject( $result ) ) { |
67 | 64 | $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() ) ) { |
69 | 66 | $title->pr_index_title = $ref_title->getPrefixedText(); |
70 | 67 | break; |
71 | 68 | } |
72 | 69 | } |
73 | 70 | $dbr->freeResult( $result ) ; |
74 | 71 | |
75 | | - if($title->pr_index_title) return; |
| 72 | + if ( $title->pr_index_title ) return; |
76 | 73 | |
77 | 74 | /*check if we are a page of a multipage file*/ |
78 | 75 | |
— | — | @@ -82,16 +79,16 @@ |
83 | 80 | |
84 | 81 | $image = wfFindFile( $imageTitle ); |
85 | 82 | |
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() ) { |
88 | 85 | |
89 | 86 | $pagenr = 1; |
90 | 87 | $parts = explode( '/', $title->getText() ); |
91 | | - if( count( $parts ) > 1 ) { |
| 88 | + if ( count( $parts ) > 1 ) { |
92 | 89 | $pagenr = intval( array_pop( $parts ) ); |
93 | 90 | } |
94 | 91 | $count = $image->pageCount(); |
95 | | - if( $pagenr < 1 || $pagenr > $count || $count == 1 ) |
| 92 | + if ( $pagenr < 1 || $pagenr > $count || $count == 1 ) |
96 | 93 | return $err; |
97 | 94 | $name = $image->getTitle()->getText(); |
98 | 95 | $index_name = "$index_namespace:$name"; |
— | — | @@ -102,24 +99,19 @@ |
103 | 100 | |
104 | 101 | $title->pr_page_num = "$pagenr"; |
105 | 102 | |
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 |
108 | 105 | $title->pr_index_title = $index_name; |
109 | 106 | } |
110 | | - } |
| 107 | + } |
111 | 108 | |
112 | 109 | |
113 | 110 | } |
114 | 111 | |
115 | 112 | |
116 | | - |
117 | 113 | /** |
118 | | - * |
119 | 114 | * return the URLs of the index, previous and next pages. |
120 | | - * |
121 | 115 | */ |
122 | | - |
123 | | - |
124 | 116 | function pr_navigation( $image ) { |
125 | 117 | global $wgTitle; |
126 | 118 | $index_title = Title::newFromText( $wgTitle->pr_index_title ); |
— | — | @@ -128,17 +120,17 @@ |
129 | 121 | $index_namespace = preg_quote( wfMsgForContent( 'proofreadpage_index_namespace' ), '/' ); |
130 | 122 | $err = array( '', '', '', array() ); |
131 | 123 | |
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() ) { |
135 | 126 | $pagenr = 1; |
136 | 127 | $parts = explode( '/', $wgTitle->getText() ); |
137 | | - if( count( $parts ) > 1 ) { |
| 128 | + if ( count( $parts ) > 1 ) { |
138 | 129 | $pagenr = intval( array_pop( $parts ) ); |
139 | 130 | } |
140 | 131 | $count = $image->pageCount(); |
141 | | - if( $pagenr < 1 || $pagenr > $count || $count == 1 ) |
| 132 | + if ( $pagenr < 1 || $pagenr > $count || $count == 1 ) { |
142 | 133 | return $err; |
| 134 | + } |
143 | 135 | $name = $image->getTitle()->getText(); |
144 | 136 | $index_name = "$index_namespace:$name"; |
145 | 137 | $prev_name = "$page_namespace:$name/" . ( $pagenr - 1 ); |
— | — | @@ -146,27 +138,30 @@ |
147 | 139 | $prev_url = ( $pagenr == 1 ) ? '' : Title::newFromText( $prev_name )->getFullURL(); |
148 | 140 | $next_url = ( $pagenr == $count ) ? '' : Title::newFromText( $next_name )->getFullURL(); |
149 | 141 | |
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 |
152 | 144 | $index_title = Title::newFromText( $index_name ); |
153 | 145 | } |
154 | | - } |
155 | | - else { |
| 146 | + } else { |
156 | 147 | $prev_url = ''; |
157 | 148 | $next_url = ''; |
158 | 149 | } |
159 | 150 | |
160 | | - if( !$index_title ) return array( '', $prev_url, $next_url, array() ) ; |
| 151 | + if ( !$index_title ) { |
| 152 | + return array( '', $prev_url, $next_url, array() ) ; |
| 153 | + } |
161 | 154 | |
162 | 155 | $index_url = $index_title->getFullURL(); |
163 | 156 | |
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 | + } |
165 | 160 | |
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 ); |
168 | 163 | |
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(); |
171 | 166 | |
172 | 167 | return array( $index_url, $prev_url, $next_url, $attributes ); |
173 | 168 | |
— | — | @@ -177,68 +172,68 @@ |
178 | 173 | read metadata from the index page |
179 | 174 | if page_title is provided, return page number, previous and next pages |
180 | 175 | */ |
| 176 | +function pr_parse_index( $index_title, $page_title ) { |
181 | 177 | |
182 | | -function pr_parse_index($index_title, $page_title){ |
183 | | - |
184 | 178 | $err = array( '', '', array() ); |
185 | 179 | |
186 | 180 | $page_namespace = preg_quote( wfMsgForContent( 'proofreadpage_namespace' ), '/' ); |
187 | 181 | $index_namespace = preg_quote( wfMsgForContent( 'proofreadpage_index_namespace' ), '/' ); |
188 | 182 | |
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; |
191 | 185 | |
192 | 186 | $rev = Revision::newFromTitle( $index_title ); |
193 | 187 | $text = $rev->getText(); |
194 | 188 | |
195 | 189 | $attributes = array(); |
196 | 190 | |
197 | | - if($page_title){ |
198 | | - //find page number, previous and next pages |
| 191 | + if ( $page_title ) { |
| 192 | + // find page number, previous and next pages |
199 | 193 | |
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; |
202 | 196 | |
203 | | - //check if it is using pagelist |
| 197 | + // check if it is using pagelist |
204 | 198 | 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 ); |
207 | 201 | $params = array(); |
208 | | - for( $i=0; $i<count( $m2[1] ); $i++) { |
| 202 | + for ( $i = 0; $i < count( $m2[1] ); $i++ ) { |
209 | 203 | $params[ $m2[1][$i] ] = $m2[2][$i]; |
210 | 204 | } |
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 ); |
212 | 206 | $attributes["pagenum"] = $view; |
213 | | - } |
214 | | - else{ |
215 | | - |
| 207 | + } else { |
216 | 208 | $tag_pattern = "/\[\[($page_namespace:.*?)(\|(.*?)|)\]\]/i"; |
217 | 209 | preg_match_all( $tag_pattern, $text, $links, PREG_PATTERN_ORDER ); |
218 | 210 | |
219 | | - for( $i=0; $i<count( $links[1] ); $i++) { |
| 211 | + for ( $i = 0; $i < count( $links[1] ); $i++ ) { |
220 | 212 | $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() ) { |
223 | 215 | $attributes["pagenum"] = $links[3][$i]; |
224 | 216 | break; |
225 | 217 | } |
226 | 218 | } |
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] ); |
229 | 221 | } |
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] ); |
232 | 224 | } |
233 | 225 | } |
234 | 226 | } |
235 | 227 | |
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 | + } |
243 | 238 | } |
244 | 239 | return array( $prev_title, $next_title, $attributes ); |
245 | 240 | |
— | — | @@ -246,16 +241,13 @@ |
247 | 242 | |
248 | 243 | |
249 | 244 | /** |
250 | | - * |
251 | 245 | * Append javascript variables and code to the page. |
252 | | - * |
253 | 246 | */ |
254 | | - |
255 | 247 | function pr_beforePageDisplay( &$out ) { |
256 | 248 | global $wgTitle, $wgJsMimeType, $wgScriptPath, $wgRequest, $wgProofreadPageVersion; |
257 | 249 | |
258 | 250 | wfLoadExtensionMessages( 'ProofreadPage' ); |
259 | | - $action = $wgRequest->getVal('action'); |
| 251 | + $action = $wgRequest->getVal( 'action' ); |
260 | 252 | $isEdit = ( $action == 'submit' || $action == 'edit' ) ? 1 : 0; |
261 | 253 | if ( !isset( $wgTitle ) || ( !$out->isArticle() && !$isEdit ) || isset( $out->proofreadPageDone ) ) { |
262 | 254 | return true; |
— | — | @@ -264,13 +256,15 @@ |
265 | 257 | |
266 | 258 | $page_namespace = preg_quote( wfMsgForContent( 'proofreadpage_namespace' ), '/' ); |
267 | 259 | 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 | + } |
269 | 263 | pr_preparePage( $out, $m, $isEdit ); |
270 | 264 | return true; |
271 | 265 | } |
272 | 266 | |
273 | 267 | $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 ) ) ) { |
275 | 269 | pr_prepareIndex( $out ); |
276 | 270 | return true; |
277 | 271 | } |
— | — | @@ -289,17 +283,13 @@ |
290 | 284 | EOT |
291 | 285 | ); |
292 | 286 | $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' ) ) . "\"; |
294 | 288 | </script>\n" |
295 | 289 | ); |
296 | 290 | |
297 | 291 | } |
298 | 292 | |
299 | 293 | |
300 | | - |
301 | | - |
302 | | - |
303 | | - |
304 | 294 | function pr_preparePage( $out, $m, $isEdit ) { |
305 | 295 | global $wgJsMimeType, $wgScriptPath, $wgRequest, $wgProofreadPageVersion; |
306 | 296 | |
— | — | @@ -312,21 +302,19 @@ |
313 | 303 | if ( $image && $image->exists() ) { |
314 | 304 | $width = $image->getWidth(); |
315 | 305 | $height = $image->getHeight(); |
316 | | - if($m[2]) { |
| 306 | + if ( $m[2] ) { |
317 | 307 | $viewName = $image->thumbName( array( 'width' => $width, 'page' => $m[3] ) ); |
318 | 308 | $viewURL = $image->getThumbUrl( $viewName ); |
319 | 309 | |
320 | 310 | $thumbName = $image->thumbName( array( 'width' => '##WIDTH##', 'page' => $m[3] ) ); |
321 | 311 | $thumbURL = $image->getThumbUrl( $thumbName ); |
322 | | - } |
323 | | - else { |
| 312 | + } else { |
324 | 313 | $viewURL = $image->getViewURL(); |
325 | 314 | $thumbName = $image->thumbName( array( 'width' => '##WIDTH##' ) ); |
326 | 315 | $thumbURL = $image->getThumbUrl( $thumbName ); |
327 | 316 | } |
328 | 317 | $thumbURL = str_replace( '%23', '#', $thumbURL ); |
329 | | - } |
330 | | - else { |
| 318 | + } else { |
331 | 319 | $width = 0; |
332 | 320 | $height = 0; |
333 | 321 | $viewURL = ''; |
— | — | @@ -348,10 +336,10 @@ |
349 | 337 | 'proofreadPageNextURL' => $next_url, |
350 | 338 | ) + $attributes; |
351 | 339 | |
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 ) { |
356 | 344 | $header = str_replace( "{{{{$key}}}}", $val, $header ); |
357 | 345 | $footer = str_replace( "{{{{$key}}}}", $val, $footer ); |
358 | 346 | } |
— | — | @@ -369,21 +357,21 @@ |
370 | 358 | |
371 | 359 | # Add messages from i18n |
372 | 360 | $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" |
388 | 376 | ); |
389 | 377 | return true; |
390 | 378 | } |
— | — | @@ -407,17 +395,15 @@ |
408 | 396 | return true; |
409 | 397 | } |
410 | 398 | |
411 | | - //counters |
| 399 | + // counters |
412 | 400 | $n = $n1 = $n2 = $n3 = $n4 = 0; |
413 | 401 | |
414 | 402 | $dbr = wfGetDB( DB_SLAVE ); |
415 | 403 | $catlinks = $dbr->tableName( 'categorylinks' ); |
416 | 404 | foreach ( $page_ids as $id => $pdbk ) { |
417 | | - |
418 | 405 | // consider only link in page namespace |
419 | 406 | $page_namespace = preg_quote( wfMsgForContent( 'proofreadpage_namespace' ), '/' ); |
420 | 407 | if ( preg_match( "/^$page_namespace:(.*?)$/", $pdbk ) ) { |
421 | | - |
422 | 408 | $colours[$pdbk] = 'quality1'; |
423 | 409 | $n++; |
424 | 410 | |
— | — | @@ -434,24 +420,22 @@ |
435 | 421 | $query .= ')'; |
436 | 422 | $res = $dbr->query( $query, __METHOD__ ); |
437 | 423 | |
438 | | - while ( $x = $dbr->fetchObject($res) ) { |
439 | | - |
| 424 | + while ( $x = $dbr->fetchObject( $res ) ) { |
440 | 425 | $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' ) ): |
444 | 428 | $colours[$pdbk] = 'quality1'; |
445 | 429 | $n1++; |
446 | 430 | break; |
447 | | - case str_replace( ' ' , '_' , wfMsgForContent('proofreadpage_quality2_category')): |
| 431 | + case str_replace( ' ' , '_' , wfMsgForContent( 'proofreadpage_quality2_category' ) ): |
448 | 432 | $colours[$pdbk] = 'quality2'; |
449 | 433 | $n2++; |
450 | 434 | break; |
451 | | - case str_replace( ' ' , '_' , wfMsgForContent('proofreadpage_quality3_category')): |
| 435 | + case str_replace( ' ' , '_' , wfMsgForContent( 'proofreadpage_quality3_category' ) ): |
452 | 436 | $colours[$pdbk] = 'quality3'; |
453 | 437 | $n3++; |
454 | 438 | break; |
455 | | - case str_replace( ' ' , '_' , wfMsgForContent('proofreadpage_quality4_category')): |
| 439 | + case str_replace( ' ' , '_' , wfMsgForContent( 'proofreadpage_quality4_category' ) ): |
456 | 440 | $colours[$pdbk] = 'quality4'; |
457 | 441 | $n4++; |
458 | 442 | break; |
— | — | @@ -463,7 +447,6 @@ |
464 | 448 | } |
465 | 449 | |
466 | 450 | function pr_imageMessage( &$imgpage , &$wgOut ) { |
467 | | - |
468 | 451 | global $wgUser; |
469 | 452 | $sk = $wgUser->getSkin(); |
470 | 453 | |
— | — | @@ -476,135 +459,136 @@ |
477 | 460 | $index_namespace = preg_quote( wfMsgForContent( 'proofreadpage_index_namespace' ), '/' ); |
478 | 461 | $name = $image->getTitle()->getText(); |
479 | 462 | |
480 | | - $link = $sk->makeKnownLink( "$index_namespace:$name", wfMsg('proofreadpage_image_message') ); |
| 463 | + $link = $sk->makeKnownLink( "$index_namespace:$name", wfMsg( 'proofreadpage_image_message' ) ); |
481 | 464 | $wgOut->addHTML( "{$link}" ); |
482 | 465 | |
483 | 466 | return true; |
484 | 467 | } |
485 | 468 | |
486 | 469 | |
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 | + } |
491 | 475 | |
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" ); |
496 | 480 | |
497 | 481 | $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; |
501 | 485 | |
502 | 486 | $tens = $tens / 10; |
503 | 487 | $hund = $hund / 100; |
504 | 488 | $thou = $thou / 1000; |
505 | 489 | |
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]; |
510 | 494 | |
511 | | - return $romanNum; |
| 495 | + return $romanNum; |
512 | 496 | } |
513 | 497 | |
514 | 498 | |
515 | | - |
516 | 499 | function pr_renderIndexTag( $input, $args ) { |
517 | 500 | global $wgParser, $wgTitle; |
518 | 501 | |
519 | | - if( !isset($wgTitle->pr_index_title) ) pr_load_index($wgTitle); |
| 502 | + if ( !isset( $wgTitle->pr_index_title ) ) { |
| 503 | + pr_load_index( $wgTitle ); |
| 504 | + } |
520 | 505 | |
521 | 506 | $index_namespace = preg_quote( wfMsgForContent( 'proofreadpage_index_namespace' ), '/' ); |
522 | 507 | |
523 | 508 | $name = $args['src']; |
524 | | - if( $name ) |
| 509 | + if ( $name ) { |
525 | 510 | $index_title = Title::newFromText( "$index_namespace:$name" ); |
526 | | - else |
| 511 | + } else { |
527 | 512 | $index_title = Title::newFromText( $wgTitle->pr_index_title ); |
| 513 | + } |
528 | 514 | |
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 | + } |
530 | 518 | |
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 | + } |
532 | 524 | |
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 |
536 | 528 | list( $prev_title, $next_title, $attributes ) = pr_parse_index( $index_title, $page_index ); |
537 | 529 | |
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 ) { |
542 | 533 | $input = str_replace( "{{{{$key}}}}", $val, $input ); |
543 | 534 | } |
544 | 535 | |
545 | | - |
546 | | - $out = $wgParser->recursiveTagParse($input); |
547 | | - |
| 536 | + $out = $wgParser->recursiveTagParse( $input ); |
548 | 537 | return $out; |
549 | | - |
550 | 538 | } |
551 | 539 | |
552 | 540 | |
553 | | - |
554 | | -function pr_pageNumber($i,$args){ |
555 | | - $mode = 'normal'; //default |
| 541 | +function pr_pageNumber( $i, $args ) { |
| 542 | + $mode = 'normal'; // default |
556 | 543 | $offset = 0; |
557 | 544 | $links = true; |
558 | 545 | 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 ); |
563 | 549 | foreach ( $params as $iparam ) { |
564 | | - switch($iparam){ |
565 | | - case 'roman': |
| 550 | + switch( $iparam ) { |
| 551 | + case 'roman': |
566 | 552 | $mode = 'roman'; |
567 | 553 | break; |
568 | | - case 'highroman': |
| 554 | + case 'highroman': |
569 | 555 | $mode = 'highroman'; |
570 | 556 | break; |
571 | | - case 'empty': |
| 557 | + case 'empty': |
572 | 558 | $links = false; |
573 | 559 | break; |
574 | 560 | default: |
575 | | - if(!is_numeric($iparam)) |
| 561 | + if ( !is_numeric( $iparam ) ) |
576 | 562 | $mode = $iparam; |
577 | 563 | } |
578 | 564 | } |
579 | 565 | } |
580 | 566 | |
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 ) ) |
585 | 571 | $offset = $num - $iparam; |
586 | 572 | } |
587 | 573 | |
588 | 574 | } |
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: |
600 | 586 | $view = $mode; |
601 | 587 | } |
602 | | - return array($view,$links,$mode); |
| 588 | + return array( $view, $links, $mode ); |
603 | 589 | } |
604 | | - |
605 | 590 | |
606 | 591 | |
607 | 592 | function pr_renderPageList( $input, $args ) { |
608 | | - |
609 | 593 | global $wgUser, $wgTitle; |
610 | 594 | wfLoadExtensionMessages( 'ProofreadPage' ); |
611 | 595 | $index_namespace = preg_quote( wfMsgForContent( 'proofreadpage_index_namespace' ), '/' ); |
— | — | @@ -617,10 +601,9 @@ |
618 | 602 | return true; |
619 | 603 | } |
620 | 604 | $image = wfFindFile( $imageTitle ); |
621 | | - $return=""; |
| 605 | + $return = ""; |
622 | 606 | |
623 | 607 | if ( $image && $image->isMultipage() ) { |
624 | | - |
625 | 608 | $name = $imageTitle->getDBkey(); |
626 | 609 | $count = $image->pageCount(); |
627 | 610 | $dbr = wfGetDB( DB_SLAVE ); |
— | — | @@ -628,19 +611,18 @@ |
629 | 612 | |
630 | 613 | $page_namespace = preg_quote( wfMsgForContent( 'proofreadpage_namespace' ), '/' ); |
631 | 614 | $page_ns_index = MWNamespace::getCanonicalIndex( strtolower( $page_namespace ) ); |
632 | | - if( $page_ns_index == NULL ) { |
| 615 | + if ( $page_ns_index == NULL ) { |
633 | 616 | $page_ns_index = NS_MAIN; |
634 | 617 | } |
635 | 618 | |
636 | | - for( $i=0; $i<$count ; $i++) { |
637 | | - |
| 619 | + for ( $i = 0; $i < $count ; $i++ ) { |
638 | 620 | if ( !isset( $query ) ) { |
639 | 621 | $query = "SELECT page_id, page_title, page_namespace"; |
640 | 622 | $query .= " FROM $pagetable WHERE (page_namespace=$page_ns_index AND page_title IN("; |
641 | 623 | } else { |
642 | 624 | $query .= ', '; |
643 | 625 | } |
644 | | - $link_name = "$name" . '/'. ($i+1) ; |
| 626 | + $link_name = "$name" . '/' . ( $i + 1 ) ; |
645 | 627 | $query .= $dbr->addQuotes( $link_name ); |
646 | 628 | } |
647 | 629 | $query .= '))'; |
— | — | @@ -648,7 +630,7 @@ |
649 | 631 | |
650 | 632 | $colours = array(); |
651 | 633 | $linkcolour_ids = array(); |
652 | | - while ( $s = $dbr->fetchObject($res) ) { |
| 634 | + while ( $s = $dbr->fetchObject( $res ) ) { |
653 | 635 | $title = Title::makeTitle( $s->page_namespace, $s->page_title ); |
654 | 636 | $pdbk = $title->getPrefixedDBkey(); |
655 | 637 | $colours[$pdbk] = 'known'; |
— | — | @@ -658,27 +640,28 @@ |
659 | 641 | |
660 | 642 | $sk = $wgUser->getSkin(); |
661 | 643 | |
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 ); |
663 | 647 | |
664 | | - $pdbk = "$page_namespace:$name" . '/'. $i ; |
665 | | - list( $view, $links, $mode ) = pr_pageNumber($i,$args); |
| 648 | + if ( $mode == 'highroman' || $mode == 'roman' ) $view = ' ' . $view; |
666 | 649 | |
667 | | - if($mode == 'highroman' || $mode == 'roman') $view = ' '.$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' ) ) { |
671 | 652 | $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; |
674 | 657 | } |
675 | 658 | $title = Title::newFromText( $pdbk ); |
676 | 659 | |
677 | | - if($links==false) $return.= $view." "; |
678 | | - else{ |
| 660 | + if ( $links == false ) { |
| 661 | + $return .= $view . " "; |
| 662 | + } else { |
679 | 663 | if ( !isset( $colours[$pdbk] ) ) { |
680 | 664 | $link = $sk->makeBrokenLinkObj( $title, $view ); |
681 | | - } |
682 | | - else { |
| 665 | + } else { |
683 | 666 | $link = $sk->makeColouredLinkObj( $title, $colours[$pdbk], $view ); |
684 | 667 | } |
685 | 668 | $return .= "{$link} "; |
— | — | @@ -698,10 +681,11 @@ |
699 | 682 | |
700 | 683 | $title = $article->mTitle; |
701 | 684 | |
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 ) { |
706 | 690 | $index_title = Title::makeTitleSafe( $index_namespace, $title->pr_index_title ); |
707 | 691 | $index_title->invalidateCache(); |
708 | 692 | } |
— | — | @@ -712,14 +696,12 @@ |
713 | 697 | } |
714 | 698 | |
715 | 699 | |
716 | | - |
717 | 700 | function pr_preloadText( $textbox1, $mTitle ) { |
718 | 701 | global $wgDjvuTxt; |
719 | 702 | |
720 | 703 | $page_namespace = preg_quote( wfMsgForContent( 'proofreadpage_namespace' ), '/' ); |
721 | 704 | |
722 | 705 | if ( $wgDjvuTxt && preg_match( "/^$page_namespace:(.*?)\/([0-9]*)$/", $mTitle->getPrefixedText(), $m ) ) { |
723 | | - |
724 | 706 | $imageTitle = Title::makeTitleSafe( NS_IMAGE, $m[1] ); |
725 | 707 | if ( !$imageTitle ) { |
726 | 708 | return true; |
— | — | @@ -727,15 +709,14 @@ |
728 | 710 | |
729 | 711 | $image = wfFindFile( $imageTitle ); |
730 | 712 | if ( $image && $image->exists() && $image->getMimeType() == 'image/vnd.djvu' ) { |
731 | | - |
732 | 713 | $name = $image->thumbName( array( 'width' => '##WIDTH##', 'page' => $m[2] ) ); |
733 | 714 | $name = str_replace( '##WIDTH##px', 'djvutxt', $name ); |
734 | 715 | $name = str_replace( '.jpg', '.txt', $name ); |
735 | 716 | $url = $image->getThumbUrl( $name ); |
736 | 717 | |
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; |
740 | 721 | } |
741 | 722 | } |
742 | 723 | return true; |