r34398 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r34397‎ | r34398 | r34399 >
Date:20:57, 7 May 2008
Author:sanbeg
Status:old
Tags:
Comment:
add parallel note/footnotes tags for alphabetic footnotes, which incidently allow 1 level of nesting
Modified paths:
  • /trunk/extensions/Cite/Cite.i18n.php (modified) (history)
  • /trunk/extensions/Cite/Cite.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Cite/Cite.i18n.php
@@ -67,6 +67,7 @@
6868 # Although I could just use # instead of <li> above and nothing here that
6969 # will break on input that contains linebreaks
7070 'cite_references_prefix' => '<ol class="references">',
 71+ 'cite_references_prefix_a' => '<ol type="a" class="references">',
7172 'cite_references_suffix' => '</ol>',
7273 );
7374
Index: trunk/extensions/Cite/Cite.php
@@ -67,7 +67,7 @@
6868 * </code>
6969 *
7070 * This works because:
71 - * * PHP's datastructures are guarenteed to be returned in the
 71+ * * PHP's datastructures are guaranteed to be returned in the
7272 * order that things are inserted into them (unless you mess
7373 * with that)
7474 * * User supplied keys can't be integers, therefore avoiding
@@ -82,7 +82,7 @@
8383 *
8484 * @var int
8585 */
86 - var $mOutCnt = 0;
 86+ static $mOutCnt = 0;
8787 var $mGroupCnt = array();
8888
8989 /**
@@ -92,7 +92,7 @@
9393 *
9494 * @var int
9595 */
96 - var $mInCnt = 0;
 96+ static $mInCnt = 0;
9797
9898 /**
9999 * The backlinks, in order, to pass as $3 to
@@ -282,9 +282,9 @@
283283 if ( $key === null ) {
284284 // No key
285285 //$this->mRefs[$group][] = $str;
286 - $this->mRefs[$group][] = array('count'=>-1, 'text'=>$str, 'key'=>++$this->mOutCnt);
 286+ $this->mRefs[$group][] = array('count'=>-1, 'text'=>$str, 'key'=>++self::$mOutCnt);
287287
288 - return $this->linkRef( $group, $this->mInCnt++ );
 288+ return $this->linkRef( $group, self::$mInCnt++ );
289289 } else if ( is_string( $key ) ) {
290290 // Valid key
291291 if ( ! isset( $this->mRefs[$group][$key] ) || ! is_array( $this->mRefs[$group][$key] ) ) {
@@ -292,10 +292,10 @@
293293 $this->mRefs[$group][$key] = array(
294294 'text' => $str,
295295 'count' => 0,
296 - 'key' => ++$this->mOutCnt,
 296+ 'key' => ++self::$mOutCnt,
297297 'number' => ++$this->mGroupCnt[$group]
298298 );
299 - $this->mInCnt++;
 299+ self::$mInCnt++;
300300 return
301301 $this->linkRef(
302302 $group,
@@ -373,7 +373,7 @@
374374 *
375375 * @return string XHTML ready for output
376376 */
377 - function referencesFormat($group) {
 377+ function referencesFormat($group, $prefix='cite_references_prefix') {
378378 if (( count( $this->mRefs ) == 0 ) or (empty( $this->mRefs[$group] ) ))
379379 return '';
380380
@@ -383,7 +383,7 @@
384384 foreach ( $this->mRefs[$group] as $k => $v )
385385 $ent[] = $this->referencesFormatEntry( $k, $v );
386386
387 - $prefix = wfMsgForContentNoTrans( 'cite_references_prefix' );
 387+ $prefix = wfMsgForContentNoTrans( $prefix );
388388 $suffix = wfMsgForContentNoTrans( 'cite_references_suffix' );
389389 $content = implode( "\n", $ent );
390390
@@ -516,6 +516,12 @@
517517 }
518518 }
519519
 520+ function refCounterString($counter) {
 521+ global $wgContLang;
 522+ return $wgContLang->formatNum($counter);
 523+ }
 524+
 525+
520526 /**
521527 * Return an id for use in wikitext output based on a key and
522528 * optionally the number of it, used in <references>, not <ref>
@@ -564,19 +570,18 @@
565571 * @param int $count The index of the key, used for distinguishing
566572 * multiple occurances of the same key
567573 * @param int $label The label to use for the link, I want to
568 - * use the same label for all occourances of
 574+ * use the same label for all occurances of
569575 * the same named reference.
570576 * @return string
571577 */
572578 function linkRef( $group, $key, $count = null, $label = null, $subkey = '' ) {
573 - global $wgContLang;
574579 return
575580 $this->parse(
576581 wfMsgForContentNoTrans(
577582 'cite_reference_link',
578583 $this->refKey( $key, $count ),
579584 $this->referencesKey( $key . $subkey ),
580 - (($group == CITE_DEFAULT_GROUP)?'':"$group ").$wgContLang->formatNum( is_null( $label ) ? ++$this->mGroupCnt[$group] : $label )
 585+ (($group == CITE_DEFAULT_GROUP)?'':"$group ").$this->refCounterString( is_null( $label ) ? ++$this->mGroupCnt[$group] : $label )
581586 )
582587 );
583588 }
@@ -680,8 +685,8 @@
681686 */
682687 function clearState() {
683688 $this->mGroupCnt = array();
684 - $this->mOutCnt = -1;
685 - $this->mInCnt = 0;
 689+ self::$mOutCnt = -1;
 690+ self::$mInCnt = 0;
686691 $this->mRefs = array();
687692
688693 return true;
@@ -732,7 +737,51 @@
733738 /**#@-*/
734739 }
735740
 741+
 742+
 743+ class Note extends Cite
 744+ {
 745+
 746+ /**
 747+ * Constructor
 748+ */
 749+ function Note() {
 750+ $this->setHooks();
 751+ }
 752+
 753+ /**
 754+ * Initialize the parser hooks
 755+ */
 756+ function setHooks() {
 757+ global $wgParser, $wgHooks;
 758+
 759+ $wgParser->setHook( 'note' , array( &$this, 'ref' ) );
 760+ $wgParser->setHook( 'footnotes' , array( &$this, 'references' ) );
 761+
 762+ $wgHooks['ParserClearState'][] = array( &$this, 'clearState' );
 763+ }
 764+
 765+ function refCounterString($counter) {
 766+ return $this->referencesFormatEntryAlternateBacklinkLabel( $counter-1 );
 767+ }
 768+
 769+
 770+ /**
 771+ * Make output to be returned from the references() function
 772+ *
 773+ * @return string XHTML ready for output
 774+ */
 775+ function referencesFormat($group, $prefix='cite_references_prefix_a') {
 776+ return parent::referencesFormat($group, $prefix);
 777+}
 778+
 779+ }
 780+
 781+
 782+
 783+
736784 new Cite;
 785+ new Note;
737786 }
738787
739788 /**#@-*/

Follow-up revisions

RevisionCommit summaryAuthorDate
r34400Revert r34398 for now; near-duplicate of existing tag seems a bit odd to mebrion21:05, 7 May 2008

Status & tagging log