--- Cite_body.php 2009-06-03 18:59:50.000000000 -0600 +++ Cite_body-def-2009-06-04.php 2009-06-03 21:50:48.000000000 -0600 @@ -1,4 +1,34 @@ tag which would expand the references. +** +** If the block is located at the head of the article (ahead of any tags), +** the Refs declared therein will be expanded in the order of declaration. +** +** A Ref declaration block would look something like the following: +** +** +** This is a comment which should be placed in the References section +** +** This is another comment which should be placed in the References section +** +** This is a citation of [http://something.somewhere.com a supporting source] +** +** +** Note that that the Ref tag arrangement above places all newlines inside Ref tag bodies +** This is done to avoid introducing newlines into the article text between Ref tags. +** +**/ /**#@+ * A parser extension that adds two tags, and for adding @@ -12,8 +42,8 @@ * * @bug 4579 * - * @author Ævar Arnfjörð Bjarmason - * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason + * @author Ævar Arnfjörð Bjarmason + * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later */ @@ -126,10 +156,14 @@ function guardedRef( $str, $argv, $parser, $default_group=CITE_DEFAULT_GROUP ) { $this->mParser = $parser; - # The key here is the "name" attribute. - list($key,$group) = $this->refArg( $argv ); - + $temp = $this->refArg ( $argv ); + if ( is_string( $temp ) ) { + // Cite.i18n.php needs an error in many languages for this + return $this->error ( 'cite_error_ref_unk_elements', $temp); + } else { + list($key,$group,$def) = $temp; + } if( $str === '' ) { # . This construct is invalid if # it's a contentful ref, but OK if it's a named duplicate and should @@ -186,7 +220,7 @@ # fers to an existing one. If it refers to a nonexistent ref, # we'll figure that out later. Likewise it's definitely valid # if there's any content, regardless of key. - return $this->stack( $str, $key, $group ); + return $this->stack( $str, $key, $group , $def); } # Not clear how we could get here, but something is probably @@ -205,37 +239,30 @@ */ function refArg( $argv ) { global $wgAllowCiteGroups; - $cnt = count( $argv ); $group = null; $key = null; + $def = false; - if ( $cnt > 2 ) - // There should only be one key and one group - return false; - else if ( $cnt >= 1 ) { if ( isset( $argv['name'] ) ) { // Key given. $key = Sanitizer::escapeId( $argv['name'], 'noninitial' ); unset( $argv['name']); - --$cnt; + } + if ( isset( $argv['def'] ) ) { + // def given. + $def = true; + unset( $argv['def']); } if ( isset( $argv['group'] ) ){ if (! $wgAllowCiteGroups ) return array(false); //remove when groups are fully tested. // Group given. $group = $argv['group']; unset( $argv['group']); - --$cnt; } - - if ( $cnt == 0) - return array ($key,$group); + if ( count($argv) > 0 ) + return ( implode(", ", array_keys($argv)) ); else - // Invalid key - return array(false,false); - } - else - // No key - return array(null,$group); + return array ($key,$group,$def); } /** @@ -245,7 +272,7 @@ * @param mixed $key Argument to the tag as returned by $this->refArg() * @return string */ - function stack( $str, $key = null, $group ) { + function stack( $str, $key = null, $group, $def ) { if (! isset($this->mRefs[$group])) $this->mRefs[$group]=array(); if (! isset($this->mGroupCnt[$group])) @@ -264,10 +291,12 @@ $this->mRefs[$group][$key] = array( 'text' => $str, 'count' => 0, + 'def' => array(), 'key' => ++$this->mOutCnt, 'number' => ++$this->mGroupCnt[$group] ); $this->mInCnt++; + if ( ! $def ) { return $this->linkRef( $group, @@ -276,12 +305,18 @@ $this->mRefs[$group][$key]['number'], "-".$this->mRefs[$group][$key]['key'] ); + } + else { + $this->mRefs[$group][$key]['def'][0] = true; + return ""; + } } else { // We've been here before if ( $this->mRefs[$group][$key]['text'] === null && $str !== '' ) { // If no text found before, use this text $this->mRefs[$group][$key]['text'] = $str; }; + if ( ! $def ) { return $this->linkRef( $group, @@ -289,7 +324,13 @@ $this->mRefs[$group][$key]['key']."-".++$this->mRefs[$group][$key]['count'], $this->mRefs[$group][$key]['number'], "-".$this->mRefs[$group][$key]['key'] - ); } + ); + } + else { + $this->mRefs[$group][$key]['def'][++$this->mRefs[$group][$key]['count']] = true; + return ""; + } + } } else @@ -363,7 +404,7 @@ wfProfileOut( __METHOD__ .'-entries' ); wfProfileIn( __METHOD__ .'-parse' ); - // Live hack: parse() adds two newlines on WM, can't reproduce it locally -ævar + // Live hack: parse() adds two newlines on WM, can't reproduce it locally -ævar $ret = rtrim( $this->parse( $prefix . $content . $suffix ), "\n" ); wfProfileOut( __METHOD__ .'-parse' ); wfProfileOut( __METHOD__ ); @@ -384,6 +425,7 @@ * @return string Wikitext */ function referencesFormatEntry( $key, $val ) { + // Anonymous reference if ( ! is_array( $val ) ) return @@ -414,30 +456,36 @@ // anonymous reference because displaying "1. 1.1 Ref text" is // overkill and users frequently use named references when they // don't need them for convenience - else if ( $val['count'] === 0 ) + else if ( $val['count'] === 0 ) { + if ( $val['def'] ) + $ret = $this->error( 'cite_error_orphan_ref', $key ); + else + $ret = ( $val['text'] != '' ? $val['text'] : $this->error( 'cite_error_references_no_text', $key ) ); return wfMsgForContentNoTrans( 'cite_references_link_one', $this->referencesKey( $key ."-" . $val['key'] ), #$this->refKey( $key, $val['count'] ), $this->refKey( $key, $val['key']."-".$val['count'] ), - ( $val['text'] != '' ? $val['text'] : $this->error( 'cite_error_references_no_text', $key ) ) + $ret ); + } // Named references with >1 occurrences else { $links = array(); //for group handling, we have an extra key here. - for ( $i = 0; $i <= $val['count']; ++$i ) { + for ( $i = 0, $j = 0; $i <= $val['count']; ++$i ) { + if ( ! $val['def'][$i] ) { $links[] = wfMsgForContentNoTrans( 'cite_references_link_many_format', $this->refKey( $key, $val['key']."-$i" ), - $this->referencesFormatEntryNumericBacklinkLabel( $val['number'], $i, $val['count'] ), - $this->referencesFormatEntryAlternateBacklinkLabel( $i ) + $this->referencesFormatEntryNumericBacklinkLabel( $val['number'], $j, $i ), + $this->referencesFormatEntryAlternateBacklinkLabel( $j ) ); + $j++; + } } - $list = $this->listToText( $links ); - return wfMsgForContentNoTrans( 'cite_references_link_many', $this->referencesKey( $key ."-" . $val['key'] ),