r32273 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r32272‎ | r32273 | r32274 >
Date:00:19, 21 March 2008
Author:brion
Status:old
Tags:
Comment:
Revert r32256 -- lots of notice errors about undefined index & such seen while running tests
Modified paths:
  • /trunk/extensions/Cite/Cite.php (modified) (history)
  • /trunk/extensions/Cite/citeParserTests.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/Cite/citeParserTests.txt
@@ -149,10 +149,10 @@
150150
151151 <references/>
152152 !! 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>
155155 </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>
157157
158158 !! end
159159
@@ -165,10 +165,10 @@
166166
167167 <references/>
168168 !! 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>
171171 </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>
173173
174174 !! end
175175
@@ -181,10 +181,10 @@
182182
183183 <references/>
184184 !! 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>
187187 </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>
189189
190190 !! end
191191
@@ -197,13 +197,13 @@
198198
199199 <references />
200200 !! 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>
204204 </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>
208208
209209 !! end
210210
@@ -229,8 +229,8 @@
230230 <p><strong class="error">Cite error: Invalid <code>&lt;ref&gt;</code> tag; name cannot be a simple integer, use a descriptive title</strong>
231231 </p><p><sup id="cite_ref-0" class="reference"><a href="#cite_note-0" title="">[1]</a></sup>
232232 </p><p><strong class="error">Cite error: Invalid <code>&lt;ref&gt;</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>
235235 </p><p><strong class="error">Cite error: Invalid <code>&lt;references&gt;</code> tag; no input is allowed, use
236236 <code>&lt;references /&gt;</code></strong>
237237 </p><p><strong class="error">Cite error: Invalid <code>&lt;references&gt;</code> tag; no parameters are allowed, use <code>&lt;references /&gt;</code></strong>
@@ -242,19 +242,3 @@
243243 !! end
244244
245245
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 @@
3131 $wgParserTestFiles[] = dirname( __FILE__ ) . "/citeParserTests.txt";
3232 $wgExtensionMessagesFiles['Cite'] = dirname( __FILE__ ) . "/Cite.i18n.php";
3333
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 -
4134 function wfCite() {
4235 class Cite {
4336 /**#@+
@@ -82,7 +75,6 @@
8376 * @var int
8477 */
8578 var $mOutCnt = 0;
86 - var $mGroupCnt = array();
8779
8880 /**
8981 * Internal counter for anonymous references, seperate from
@@ -145,11 +137,11 @@
146138 }
147139 }
148140
149 - function guardedRef( $str, $argv, $parser, $default_group=CITE_DEFAULT_GROUP ) {
 141+ function guardedRef( $str, $argv, $parser ) {
150142 $this->mParser = $parser;
151143
152144 # The key here is the "name" attribute.
153 - list($key,$group) = $this->refArg( $argv );
 145+ $key = $this->refArg( $argv );
154146
155147 if( $str === '' ) {
156148 # <ref ...></ref>. This construct is always invalid: either
@@ -175,11 +167,6 @@
176168 # (and would produce weird id's anyway).
177169 return $this->error( 'cite_error_ref_numeric_key' );
178170 }
179 -
180 - #Split these into groups.
181 - if( $group === null ) {
182 - $group = $default_group;
183 - }
184171
185172 if( is_string( $key ) or is_string( $str ) ) {
186173 # We don't care about the content: if the key exists, the ref
@@ -187,7 +174,7 @@
188175 # fers to an existing one. If it refers to a nonexistent ref,
189176 # we'll figure that out later. Likewise it's definitely valid
190177 # if there's any content, regardless of key.
191 - return $this->stack( $str, $key, $group );
 178+ return $this->stack( $str, $key );
192179 }
193180
194181 # Not clear how we could get here, but something is probably
@@ -205,36 +192,21 @@
206193 * input and null on no input
207194 */
208195 function refArg( $argv ) {
209 - global $wgAllowCiteGroups;
210196 $cnt = count( $argv );
211197
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
214200 return false;
215 - else if ( $cnt >= 1 ) {
216 - if ( isset( $argv['name'] ) ) {
 201+ else if ( $cnt == 1 )
 202+ if ( isset( $argv['name'] ) )
217203 // 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 ) );
232205 else
233206 // Invalid key
234 - return array(false);
235 - }
 207+ return false;
236208 else
237209 // No key
238 - return array(null,$group);
 210+ return null;
239211 }
240212
241213 /**
@@ -270,47 +242,38 @@
271243 * @param mixed $key Argument to the <ref> tag as returned by $this->refArg()
272244 * @return string
273245 */
274 - function stack( $str, $key = null, $group ) {
 246+ function stack( $str, $key = null ) {
275247 if ( $key === null ) {
276248 // 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 ) )
282252 // 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(
286256 'text' => $str,
287257 'count' => 0,
288 - 'key' => ++$this->mOutCnt,
289 - 'number' => ++$this->mGroupCnt[$group]
 258+ 'number' => ++$this->mOutCnt
290259 );
291260 return
292261 $this->linkRef(
293 - $group,
294262 $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']
298265 );
299266 } else {
300267 // We've been here before
301 - if ( $this->mRefs[$group][$key]['text'] === null && $str !== '' ) {
 268+ if ( $this->mRefs[$key]['text'] === null && $str !== '' ) {
302269 // If no text found before, use this text
303 - $this->mRefs[$group][$key]['text'] = $str;
 270+ $this->mRefs[$key]['text'] = $str;
304271 };
305272 return
306273 $this->linkRef(
307 - $group,
308274 $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']
312277 ); }
313 - }
314 -
315278 else
316279 $this->croak( 'cite_error_stack_invalid_input', serialize( array( $key, $str ) ) );
317280 }
@@ -337,26 +300,15 @@
338301 return $ret;
339302 }
340303 }
341 -
342 - function guardedReferences( $str, $argv, $parser, $group = CITE_DEFAULT_GROUP ) {
343 - global $wgAllowCiteGroups;
344 -
 304+
 305+ function guardedReferences( $str, $argv, $parser ) {
345306 $this->mParser = $parser;
346 -
347307 if ( $str !== null )
348308 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 ) )
358310 return $this->error( 'cite_error_references_invalid_parameters' );
359311 else
360 - return $this->referencesFormat($group);
 312+ return $this->referencesFormat();
361313 }
362314
363315 /**
@@ -364,14 +316,14 @@
365317 *
366318 * @return string XHTML ready for output
367319 */
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 )
370322 return '';
371323
372324 wfProfileIn( __METHOD__ );
373325 wfProfileIn( __METHOD__ .'-entries' );
374326 $ent = array();
375 - foreach ( $this->mRefs[$group] as $k => $v )
 327+ foreach ( $this->mRefs as $k => $v )
376328 $ent[] = $this->referencesFormatEntry( $k, $v );
377329
378330 $prefix = wfMsgForContentNoTrans( 'cite_references_prefix' );
@@ -413,16 +365,6 @@
414366 $this->refKey( $key, $val['count'] ),
415367 $this->error( 'cite_error_references_no_text', $key )
416368 );
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 - );
427369 // Standalone named reference, I want to format this like an
428370 // anonymous reference because displaying "1. 1.1 Ref text" is
429371 // overkill and users frequently use named references when they
@@ -431,19 +373,18 @@
432374 return
433375 wfMsgForContentNoTrans(
434376 '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'] ),
438379 ( $val['text'] != '' ? $val['text'] : $this->error( 'cite_error_references_no_text', $key ) )
439380 );
440381 // Named references with >1 occurrences
441382 else {
442383 $links = array();
443 -//for group handling, we have an extra key here.
 384+
444385 for ( $i = 0; $i <= $val['count']; ++$i ) {
445386 $links[] = wfMsgForContentNoTrans(
446387 'cite_references_link_many_format',
447 - $this->refKey( $key, $val['key']."-$i" ),
 388+ $this->refKey( $key, $i ),
448389 $this->referencesFormatEntryNumericBacklinkLabel( $val['number'], $i, $val['count'] ),
449390 $this->referencesFormatEntryAlternateBacklinkLabel( $i )
450391 );
@@ -453,7 +394,7 @@
454395
455396 return
456397 wfMsgForContentNoTrans( 'cite_references_link_many',
457 - $this->referencesKey( $key ."-" . $val['key'] ),
 398+ $this->referencesKey( $key ),
458399 $list,
459400 ( $val['text'] != '' ? $val['text'] : $this->error( 'cite_error_references_no_text', $key ) )
460401 );
@@ -505,7 +446,7 @@
506447
507448 /**
508449 * 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>
510451 * (since otherwise it would link to itself)
511452 *
512453 * @static
@@ -525,7 +466,7 @@
526467
527468 /**
528469 * 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>
530471 * (since otherwise it would link to itself)
531472 *
532473 * @static
@@ -548,22 +489,23 @@
549490 * and return XHTML ready for output
550491 *
551492 * @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
554495 * @param int $label The label to use for the link, I want to
555496 * use the same label for all occourances of
556497 * the same named reference.
557498 * @return string
558499 */
559 - function linkRef( $group, $key, $count = null, $label = null, $subkey = '' ) {
 500+ function linkRef( $key, $count = null, $label = null ) {
560501 global $wgContLang;
 502+
561503 return
562504 $this->parse(
563505 wfMsgForContentNoTrans(
564506 'cite_reference_link',
565507 $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 )
568510 )
569511 );
570512 }
@@ -666,9 +608,7 @@
667609 * want the counts to transcend pages and other instances
668610 */
669611 function clearState() {
670 - $this->mGroupCnt = array();
671 - $this->mOutCnt = -1;
672 - $this->mInCnt = 0;
 612+ $this->mOutCnt = $this->mInCnt = 0;
673613 $this->mRefs = array();
674614
675615 return true;

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r32256add "group" parameter to allow multiple reference/footnote groupssanbeg21:26, 20 March 2008

Status & tagging log