Index: trunk/extensions/Cite/citeParserTests.txt |
— | — | @@ -149,10 +149,10 @@ |
150 | 150 | |
151 | 151 | <references/> |
152 | 152 | !! result |
153 | | -<p><sup id="cite_ref-blank_0-0" class="reference"><a href="#cite_note-blank-0" title="">[1]</a></sup> |
154 | | -</p><p><sup id="cite_ref-blank_0-1" class="reference"><a href="#cite_note-blank-0" title="">[1]</a></sup> |
| 153 | +<p><sup id="cite_ref-blank_0" class="reference"><a href="#cite_note-blank" title="">[1]</a></sup> |
| 154 | +</p><p><sup id="cite_ref-blank_1" class="reference"><a href="#cite_note-blank" title="">[1]</a></sup> |
155 | 155 | </p> |
156 | | -<ol class="references"><li id="cite_note-blank-0">↑ <sup><a href="#cite_ref-blank_0-0" title="">1.0</a></sup> <sup><a href="#cite_ref-blank_0-1" title="">1.1</a></sup> content</li></ol> |
| 156 | +<ol class="references"><li id="cite_note-blank">↑ <sup><a href="#cite_ref-blank_0" title="">1.0</a></sup> <sup><a href="#cite_ref-blank_1" title="">1.1</a></sup> content</li></ol> |
157 | 157 | |
158 | 158 | !! end |
159 | 159 | |
— | — | @@ -165,10 +165,10 @@ |
166 | 166 | |
167 | 167 | <references/> |
168 | 168 | !! result |
169 | | -<p><sup id="cite_ref-blank_0-0" class="reference"><a href="#cite_note-blank-0" title="">[1]</a></sup> |
170 | | -</p><p><sup id="cite_ref-blank_0-1" class="reference"><a href="#cite_note-blank-0" title="">[1]</a></sup> |
| 169 | +<p><sup id="cite_ref-blank_0" class="reference"><a href="#cite_note-blank" title="">[1]</a></sup> |
| 170 | +</p><p><sup id="cite_ref-blank_1" class="reference"><a href="#cite_note-blank" title="">[1]</a></sup> |
171 | 171 | </p> |
172 | | -<ol class="references"><li id="cite_note-blank-0">↑ <sup><a href="#cite_ref-blank_0-0" title="">1.0</a></sup> <sup><a href="#cite_ref-blank_0-1" title="">1.1</a></sup> 0</li></ol> |
| 172 | +<ol class="references"><li id="cite_note-blank">↑ <sup><a href="#cite_ref-blank_0" title="">1.0</a></sup> <sup><a href="#cite_ref-blank_1" title="">1.1</a></sup> 0</li></ol> |
173 | 173 | |
174 | 174 | !! end |
175 | 175 | |
— | — | @@ -181,10 +181,10 @@ |
182 | 182 | |
183 | 183 | <references/> |
184 | 184 | !! result |
185 | | -<p><sup id="cite_ref-blank_0-0" class="reference"><a href="#cite_note-blank-0" title="">[1]</a></sup> |
186 | | -</p><p><sup id="cite_ref-blank_0-1" class="reference"><a href="#cite_note-blank-0" title="">[1]</a></sup> |
| 185 | +<p><sup id="cite_ref-blank_0" class="reference"><a href="#cite_note-blank" title="">[1]</a></sup> |
| 186 | +</p><p><sup id="cite_ref-blank_1" class="reference"><a href="#cite_note-blank" title="">[1]</a></sup> |
187 | 187 | </p> |
188 | | -<ol class="references"><li id="cite_note-blank-0">↑ <sup><a href="#cite_ref-blank_0-0" title="">1.0</a></sup> <sup><a href="#cite_ref-blank_0-1" title="">1.1</a></sup> 1</li></ol> |
| 188 | +<ol class="references"><li id="cite_note-blank">↑ <sup><a href="#cite_ref-blank_0" title="">1.0</a></sup> <sup><a href="#cite_ref-blank_1" title="">1.1</a></sup> 1</li></ol> |
189 | 189 | |
190 | 190 | !! end |
191 | 191 | |
— | — | @@ -197,13 +197,13 @@ |
198 | 198 | |
199 | 199 | <references /> |
200 | 200 | !! result |
201 | | -<p><sup id="cite_ref-test123test_0-0" class="reference"><a href="#cite_note-test123test-0" title="">[1]</a></sup> |
202 | | -<sup id="cite_ref-123test_1-0" class="reference"><a href="#cite_note-123test-1" title="">[2]</a></sup> |
203 | | -<sup id="cite_ref-test123_2-0" class="reference"><a href="#cite_note-test123-2" title="">[3]</a></sup> |
| 201 | +<p><sup id="cite_ref-test123test_0" class="reference"><a href="#cite_note-test123test" title="">[1]</a></sup> |
| 202 | +<sup id="cite_ref-123test_0" class="reference"><a href="#cite_note-123test" title="">[2]</a></sup> |
| 203 | +<sup id="cite_ref-test123_0" class="reference"><a href="#cite_note-test123" title="">[3]</a></sup> |
204 | 204 | </p> |
205 | | -<ol class="references"><li id="cite_note-test123test-0"><a href="#cite_ref-test123test_0-0" title="">↑</a> One</li> |
206 | | -<li id="cite_note-123test-1"><a href="#cite_ref-123test_1-0" title="">↑</a> Two</li> |
207 | | -<li id="cite_note-test123-2"><a href="#cite_ref-test123_2-0" title="">↑</a> Three</li></ol> |
| 205 | +<ol class="references"><li id="cite_note-test123test"><a href="#cite_ref-test123test_0" title="">↑</a> One</li> |
| 206 | +<li id="cite_note-123test"><a href="#cite_ref-123test_0" title="">↑</a> Two</li> |
| 207 | +<li id="cite_note-test123"><a href="#cite_ref-test123_0" title="">↑</a> Three</li></ol> |
208 | 208 | |
209 | 209 | !! end |
210 | 210 | |
— | — | @@ -229,8 +229,8 @@ |
230 | 230 | <p><strong class="error">Cite error: Invalid <code><ref></code> tag; name cannot be a simple integer, use a descriptive title</strong> |
231 | 231 | </p><p><sup id="cite_ref-0" class="reference"><a href="#cite_note-0" title="">[1]</a></sup> |
232 | 232 | </p><p><strong class="error">Cite error: Invalid <code><ref></code> tag; refs with no content must have a name</strong> |
233 | | -</p><p><sup id="cite_ref-bar_1-0" class="reference"><a href="#cite_note-bar-1" title="">[2]</a></sup> |
234 | | -</p><p><sup id="cite_ref-blankwithnoreference_2-0" class="reference"><a href="#cite_note-blankwithnoreference-2" title="">[3]</a></sup> |
| 233 | +</p><p><sup id="cite_ref-bar_0" class="reference"><a href="#cite_note-bar" title="">[2]</a></sup> |
| 234 | +</p><p><sup id="cite_ref-blankwithnoreference_0" class="reference"><a href="#cite_note-blankwithnoreference" title="">[3]</a></sup> |
235 | 235 | </p><p><strong class="error">Cite error: Invalid <code><references></code> tag; no input is allowed, use |
236 | 236 | <code><references /></code></strong> |
237 | 237 | </p><p><strong class="error">Cite error: Invalid <code><references></code> tag; no parameters are allowed, use <code><references /></code></strong> |
— | — | @@ -242,19 +242,3 @@ |
243 | 243 | !! end |
244 | 244 | |
245 | 245 | |
246 | | -!! test |
247 | | -Simple <ref>, with <references/> in group |
248 | | -!! input |
249 | | -Wikipedia rocks!<ref>Proceeds of Rockology, vol. XXI</ref> |
250 | | -Wikipedia rocks!<ref group=note>Proceeds of Rockology, vol. XXI</ref> |
251 | | - |
252 | | -<references/> |
253 | | -<references group=note/> |
254 | | -!! result |
255 | | -<p>Wikipedia rocks!<sup id="cite_ref-0" class="reference"><a href="#cite_note-0" title="">[1]</a></sup> |
256 | | -Wikipedia rocks!<sup id="cite_ref-1" class="reference"><a href="#cite_note-1" title="">[note 1]</a></sup> |
257 | | -</p> |
258 | | -<ol class="references"><li id="cite_note-0"><a href="#cite_ref-0" title="">↑</a> Proceeds of Rockology, vol. XXI</li></ol> |
259 | | -<ol class="references"><li id="cite_note-1"><a href="#cite_ref-1" title="">↑</a> Proceeds of Rockology, vol. XXI</li></ol> |
260 | | - |
261 | | -!! end |
Index: trunk/extensions/Cite/Cite.php |
— | — | @@ -30,13 +30,6 @@ |
31 | 31 | $wgParserTestFiles[] = dirname( __FILE__ ) . "/citeParserTests.txt"; |
32 | 32 | $wgExtensionMessagesFiles['Cite'] = dirname( __FILE__ ) . "/Cite.i18n.php"; |
33 | 33 | |
34 | | -define( 'CITE_DEFAULT_GROUP', ''); |
35 | | -/** |
36 | | - * The emergency shut-off switch. Override in local settings to disable |
37 | | - * groups; or remove all references from this file to enable unconditionally |
38 | | - */ |
39 | | -$wgAllowCiteGroups = true; |
40 | | - |
41 | 34 | function wfCite() { |
42 | 35 | class Cite { |
43 | 36 | /**#@+ |
— | — | @@ -82,7 +75,6 @@ |
83 | 76 | * @var int |
84 | 77 | */ |
85 | 78 | var $mOutCnt = 0; |
86 | | - var $mGroupCnt = array(); |
87 | 79 | |
88 | 80 | /** |
89 | 81 | * Internal counter for anonymous references, seperate from |
— | — | @@ -145,11 +137,11 @@ |
146 | 138 | } |
147 | 139 | } |
148 | 140 | |
149 | | - function guardedRef( $str, $argv, $parser, $default_group=CITE_DEFAULT_GROUP ) { |
| 141 | + function guardedRef( $str, $argv, $parser ) { |
150 | 142 | $this->mParser = $parser; |
151 | 143 | |
152 | 144 | # The key here is the "name" attribute. |
153 | | - list($key,$group) = $this->refArg( $argv ); |
| 145 | + $key = $this->refArg( $argv ); |
154 | 146 | |
155 | 147 | if( $str === '' ) { |
156 | 148 | # <ref ...></ref>. This construct is always invalid: either |
— | — | @@ -175,11 +167,6 @@ |
176 | 168 | # (and would produce weird id's anyway). |
177 | 169 | return $this->error( 'cite_error_ref_numeric_key' ); |
178 | 170 | } |
179 | | - |
180 | | - #Split these into groups. |
181 | | - if( $group === null ) { |
182 | | - $group = $default_group; |
183 | | - } |
184 | 171 | |
185 | 172 | if( is_string( $key ) or is_string( $str ) ) { |
186 | 173 | # We don't care about the content: if the key exists, the ref |
— | — | @@ -187,7 +174,7 @@ |
188 | 175 | # fers to an existing one. If it refers to a nonexistent ref, |
189 | 176 | # we'll figure that out later. Likewise it's definitely valid |
190 | 177 | # if there's any content, regardless of key. |
191 | | - return $this->stack( $str, $key, $group ); |
| 178 | + return $this->stack( $str, $key ); |
192 | 179 | } |
193 | 180 | |
194 | 181 | # Not clear how we could get here, but something is probably |
— | — | @@ -205,36 +192,21 @@ |
206 | 193 | * input and null on no input |
207 | 194 | */ |
208 | 195 | function refArg( $argv ) { |
209 | | - global $wgAllowCiteGroups; |
210 | 196 | $cnt = count( $argv ); |
211 | 197 | |
212 | | - if ( $cnt > 2 ) |
213 | | - // There should only be one key and one group |
| 198 | + if ( $cnt > 1 ) |
| 199 | + // There should only be one key |
214 | 200 | return false; |
215 | | - else if ( $cnt >= 1 ) { |
216 | | - if ( isset( $argv['name'] ) ) { |
| 201 | + else if ( $cnt == 1 ) |
| 202 | + if ( isset( $argv['name'] ) ) |
217 | 203 | // Key given. |
218 | | - $key = $this->validateName( $argv['name'] ); |
219 | | - unset( $argv['name']); |
220 | | - --$cnt; |
221 | | - } |
222 | | - if ( isset( $argv['group'] ) ){ |
223 | | - if (! $wgAllowCiteGroups ) return array(false); //remove when groups are fully tested. |
224 | | - // Group given. |
225 | | - $group = $this->validateName( $argv['group'] ); |
226 | | - unset( $argv['group']); |
227 | | - --$cnt; |
228 | | - } |
229 | | - |
230 | | - if ( $cnt == 0) |
231 | | - return array ($key,$group); |
| 204 | + return $this->validateName( array_shift( $argv ) ); |
232 | 205 | else |
233 | 206 | // Invalid key |
234 | | - return array(false); |
235 | | - } |
| 207 | + return false; |
236 | 208 | else |
237 | 209 | // No key |
238 | | - return array(null,$group); |
| 210 | + return null; |
239 | 211 | } |
240 | 212 | |
241 | 213 | /** |
— | — | @@ -270,47 +242,38 @@ |
271 | 243 | * @param mixed $key Argument to the <ref> tag as returned by $this->refArg() |
272 | 244 | * @return string |
273 | 245 | */ |
274 | | - function stack( $str, $key = null, $group ) { |
| 246 | + function stack( $str, $key = null ) { |
275 | 247 | if ( $key === null ) { |
276 | 248 | // No key |
277 | | - //$this->mRefs[$group][] = $str; |
278 | | - $this->mRefs[$group][] = array('count'=>-1, 'text'=>$str, 'key'=>++$this->mOutCnt); |
279 | | - |
280 | | - return $this->linkRef( $group, $this->mInCnt++ ); |
281 | | - } else if ( is_string( $key ) ) { |
| 249 | + $this->mRefs[] = $str; |
| 250 | + return $this->linkRef( $this->mInCnt++ ); |
| 251 | + } else if ( is_string( $key ) ) |
282 | 252 | // Valid key |
283 | | - if ( ! isset( $this->mRefs[$group][$key] ) || ! is_array( $this->mRefs[$group][$key] ) ) { |
284 | | - // First occurance |
285 | | - $this->mRefs[$group][$key] = array( |
| 253 | + if ( ! isset( $this->mRefs[$key] ) || ! is_array( $this->mRefs[$key] ) ) { |
| 254 | + // First occourance |
| 255 | + $this->mRefs[$key] = array( |
286 | 256 | 'text' => $str, |
287 | 257 | 'count' => 0, |
288 | | - 'key' => ++$this->mOutCnt, |
289 | | - 'number' => ++$this->mGroupCnt[$group] |
| 258 | + 'number' => ++$this->mOutCnt |
290 | 259 | ); |
291 | 260 | return |
292 | 261 | $this->linkRef( |
293 | | - $group, |
294 | 262 | $key, |
295 | | - $this->mRefs[$group][$key]['key']."-".$this->mRefs[$group][$key]['count'], |
296 | | - $this->mRefs[$group][$key]['number'], |
297 | | - "-".$this->mRefs[$group][$key]['key'] |
| 263 | + $this->mRefs[$key]['count'], |
| 264 | + $this->mRefs[$key]['number'] |
298 | 265 | ); |
299 | 266 | } else { |
300 | 267 | // We've been here before |
301 | | - if ( $this->mRefs[$group][$key]['text'] === null && $str !== '' ) { |
| 268 | + if ( $this->mRefs[$key]['text'] === null && $str !== '' ) { |
302 | 269 | // If no text found before, use this text |
303 | | - $this->mRefs[$group][$key]['text'] = $str; |
| 270 | + $this->mRefs[$key]['text'] = $str; |
304 | 271 | }; |
305 | 272 | return |
306 | 273 | $this->linkRef( |
307 | | - $group, |
308 | 274 | $key, |
309 | | - $this->mRefs[$group][$key]['key']."-".++$this->mRefs[$group][$key]['count'], |
310 | | - $this->mRefs[$group][$key]['number'], |
311 | | - "-".$this->mRefs[$group][$key]['key'] |
| 275 | + ++$this->mRefs[$key]['count'], |
| 276 | + $this->mRefs[$key]['number'] |
312 | 277 | ); } |
313 | | - } |
314 | | - |
315 | 278 | else |
316 | 279 | $this->croak( 'cite_error_stack_invalid_input', serialize( array( $key, $str ) ) ); |
317 | 280 | } |
— | — | @@ -337,26 +300,15 @@ |
338 | 301 | return $ret; |
339 | 302 | } |
340 | 303 | } |
341 | | - |
342 | | - function guardedReferences( $str, $argv, $parser, $group = CITE_DEFAULT_GROUP ) { |
343 | | - global $wgAllowCiteGroups; |
344 | | - |
| 304 | + |
| 305 | + function guardedReferences( $str, $argv, $parser ) { |
345 | 306 | $this->mParser = $parser; |
346 | | - |
347 | 307 | if ( $str !== null ) |
348 | 308 | return $this->error( 'cite_error_references_invalid_input' ); |
349 | | - |
350 | | - |
351 | | - if ( isset( $argv['group'] ) and $wgAllowCiteGroups) { |
352 | | - $group = $argv['group']; |
353 | | - unset ($argv['group']); |
354 | | - |
355 | | - } |
356 | | - |
357 | | - if ( count( $argv ) ) |
| 309 | + else if ( count( $argv ) ) |
358 | 310 | return $this->error( 'cite_error_references_invalid_parameters' ); |
359 | 311 | else |
360 | | - return $this->referencesFormat($group); |
| 312 | + return $this->referencesFormat(); |
361 | 313 | } |
362 | 314 | |
363 | 315 | /** |
— | — | @@ -364,14 +316,14 @@ |
365 | 317 | * |
366 | 318 | * @return string XHTML ready for output |
367 | 319 | */ |
368 | | - function referencesFormat($group) { |
369 | | - if (( count( $this->mRefs ) == 0 ) or (count( $this->mRefs[$group] ) == 0 )) |
| 320 | + function referencesFormat() { |
| 321 | + if ( count( $this->mRefs ) == 0 ) |
370 | 322 | return ''; |
371 | 323 | |
372 | 324 | wfProfileIn( __METHOD__ ); |
373 | 325 | wfProfileIn( __METHOD__ .'-entries' ); |
374 | 326 | $ent = array(); |
375 | | - foreach ( $this->mRefs[$group] as $k => $v ) |
| 327 | + foreach ( $this->mRefs as $k => $v ) |
376 | 328 | $ent[] = $this->referencesFormatEntry( $k, $v ); |
377 | 329 | |
378 | 330 | $prefix = wfMsgForContentNoTrans( 'cite_references_prefix' ); |
— | — | @@ -413,16 +365,6 @@ |
414 | 366 | $this->refKey( $key, $val['count'] ), |
415 | 367 | $this->error( 'cite_error_references_no_text', $key ) |
416 | 368 | ); |
417 | | - if ( $val['count'] < 0 ) |
418 | | - return |
419 | | - wfMsgForContentNoTrans( |
420 | | - 'cite_references_link_one', |
421 | | - $this->referencesKey( $val['key'] ), |
422 | | - #$this->refKey( $val['key'], $val['count'] ), |
423 | | - $this->refKey( $val['key'] ), |
424 | | - |
425 | | - ( $val['text'] != '' ? $val['text'] : $this->error( 'cite_error_references_no_text', $key ) ) |
426 | | - ); |
427 | 369 | // Standalone named reference, I want to format this like an |
428 | 370 | // anonymous reference because displaying "1. 1.1 Ref text" is |
429 | 371 | // overkill and users frequently use named references when they |
— | — | @@ -431,19 +373,18 @@ |
432 | 374 | return |
433 | 375 | wfMsgForContentNoTrans( |
434 | 376 | 'cite_references_link_one', |
435 | | - $this->referencesKey( $key ."-" . $val['key'] ), |
436 | | - #$this->refKey( $key, $val['count'] ), |
437 | | - $this->refKey( $key, $val['key']."-".$val['count'] ), |
| 377 | + $this->referencesKey( $key ), |
| 378 | + $this->refKey( $key, $val['count'] ), |
438 | 379 | ( $val['text'] != '' ? $val['text'] : $this->error( 'cite_error_references_no_text', $key ) ) |
439 | 380 | ); |
440 | 381 | // Named references with >1 occurrences |
441 | 382 | else { |
442 | 383 | $links = array(); |
443 | | -//for group handling, we have an extra key here. |
| 384 | + |
444 | 385 | for ( $i = 0; $i <= $val['count']; ++$i ) { |
445 | 386 | $links[] = wfMsgForContentNoTrans( |
446 | 387 | 'cite_references_link_many_format', |
447 | | - $this->refKey( $key, $val['key']."-$i" ), |
| 388 | + $this->refKey( $key, $i ), |
448 | 389 | $this->referencesFormatEntryNumericBacklinkLabel( $val['number'], $i, $val['count'] ), |
449 | 390 | $this->referencesFormatEntryAlternateBacklinkLabel( $i ) |
450 | 391 | ); |
— | — | @@ -453,7 +394,7 @@ |
454 | 395 | |
455 | 396 | return |
456 | 397 | wfMsgForContentNoTrans( 'cite_references_link_many', |
457 | | - $this->referencesKey( $key ."-" . $val['key'] ), |
| 398 | + $this->referencesKey( $key ), |
458 | 399 | $list, |
459 | 400 | ( $val['text'] != '' ? $val['text'] : $this->error( 'cite_error_references_no_text', $key ) ) |
460 | 401 | ); |
— | — | @@ -505,7 +446,7 @@ |
506 | 447 | |
507 | 448 | /** |
508 | 449 | * Return an id for use in wikitext output based on a key and |
509 | | - * optionally the number of it, used in <references>, not <ref> |
| 450 | + * optionally the # of it, used in <references>, not <ref> |
510 | 451 | * (since otherwise it would link to itself) |
511 | 452 | * |
512 | 453 | * @static |
— | — | @@ -525,7 +466,7 @@ |
526 | 467 | |
527 | 468 | /** |
528 | 469 | * Return an id for use in wikitext output based on a key and |
529 | | - * optionally the number of it, used in <ref>, not <references> |
| 470 | + * optionally the # of it, used in <ref>, not <references> |
530 | 471 | * (since otherwise it would link to itself) |
531 | 472 | * |
532 | 473 | * @static |
— | — | @@ -548,22 +489,23 @@ |
549 | 490 | * and return XHTML ready for output |
550 | 491 | * |
551 | 492 | * @param string $key The key for the link |
552 | | - * @param int $count The index of the key, used for distinguishing |
553 | | - * multiple occurances of the same key |
| 493 | + * @param int $count The # of the key, used for distinguishing |
| 494 | + * multiple occourances of the same key |
554 | 495 | * @param int $label The label to use for the link, I want to |
555 | 496 | * use the same label for all occourances of |
556 | 497 | * the same named reference. |
557 | 498 | * @return string |
558 | 499 | */ |
559 | | - function linkRef( $group, $key, $count = null, $label = null, $subkey = '' ) { |
| 500 | + function linkRef( $key, $count = null, $label = null ) { |
560 | 501 | global $wgContLang; |
| 502 | + |
561 | 503 | return |
562 | 504 | $this->parse( |
563 | 505 | wfMsgForContentNoTrans( |
564 | 506 | 'cite_reference_link', |
565 | 507 | $this->refKey( $key, $count ), |
566 | | - $this->referencesKey( $key . $subkey ), |
567 | | - (($group == CITE_DEFAULT_GROUP)?'':"$group ").$wgContLang->formatNum( is_null( $label ) ? ++$this->mGroupCnt[$group] : $label ) |
| 508 | + $this->referencesKey( $key ), |
| 509 | + $wgContLang->formatNum( is_null( $label ) ? ++$this->mOutCnt : $label ) |
568 | 510 | ) |
569 | 511 | ); |
570 | 512 | } |
— | — | @@ -666,9 +608,7 @@ |
667 | 609 | * want the counts to transcend pages and other instances |
668 | 610 | */ |
669 | 611 | function clearState() { |
670 | | - $this->mGroupCnt = array(); |
671 | | - $this->mOutCnt = -1; |
672 | | - $this->mInCnt = 0; |
| 612 | + $this->mOutCnt = $this->mInCnt = 0; |
673 | 613 | $this->mRefs = array(); |
674 | 614 | |
675 | 615 | return true; |