Page MenuHomePhabricator
Authored By
bzimport
Nov 21 2014, 10:55 PM
Size
6 KB
Referenced Files
None
Subscribers
None

diff.txt

diff --git a/Cite.i18n.php b/Cite.i18n.php
index 3d3e82c..44763d7 100644
--- a/Cite.i18n.php
+++ b/Cite.i18n.php
@@ -76,7 +76,7 @@ no text was provided for refs named <code>$1</code>',
# Although I could just use # instead of <li> above and nothing here that
# will break on input that contains linebreaks
- 'cite_references_prefix' => '<ol class="references">',
+ 'cite_references_prefix' => '<ol class="references $1" $2>',
'cite_references_suffix' => '</ol>',
);
diff --git a/Cite.php b/Cite.php
index e4d7e92..2637b15 100644
--- a/Cite.php
+++ b/Cite.php
@@ -34,7 +34,7 @@ $wgExtensionMessagesFiles['Cite'] = dirname( __FILE__ ) . "/Cite.i18n.php";
$wgAutoloadClasses['Cite'] = dirname( __FILE__ ) . "/Cite_body.php";
$wgSpecialPageGroups['Cite'] = 'pagetools';
-define( 'CITE_DEFAULT_GROUP', '' );
+define( 'CITE_DEFAULT_GROUP', 'decimal' );
/**
* The emergency shut-off switch. Override in local settings to disable
* groups; or remove all references from this file to enable unconditionally
diff --git a/Cite_body.php b/Cite_body.php
index 62fb086..98c0896 100644
--- a/Cite_body.php
+++ b/Cite_body.php
@@ -139,6 +139,36 @@ class Cite {
var $mRefCallStack = array();
/**
+ * An array of call-back functions for hardcoded ref groups
+ * keys are group names
+ * first column is name of call back function
+ * second column is secodn parameter of call back func
+ *
+ * 'css-value' => array('nameOfCallbackFunc', <variable to be passed to func, varies by
+ * the function being invoked>),
+ *
+ * @var Array
+ */
+ private $mGroupCallbacks = array(
+ 'lower-alpha' => array('formatAlphabet', 'abcdefghijklmnopqrstuvwxyz'),
+ 'upper-alpha' => array('formatAlphabet', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'),
+ 'lower-greek' => array('formatAlphabet', 'αβγδεζηθικλμνξοπρστυφχψω'),
+ 'lower-roman' => array('formatRoman', 0),
+ 'upper-roman' => array('formatRoman', 1),
+ );
+
+ /**
+ * An array for roman numerals
+ * @var Array
+ */
+ private $mRomans = array(
+ 'base' => array('', 'i', 'ii', 'iii', 'iv', 'v', 'vi', 'vii', 'viii', 'ix'),
+ 'tens' => array('', 'x', 'xx', 'xxx', 'xl', 'l', 'lx', 'lxx', 'lxxx', 'xc'),
+ 'hundreds' => array('', 'c', 'cc', 'ccc', 'cd', 'd', 'dc', 'dcc', 'dccc', 'cm'),
+ 'thousand' => 'm',
+ );
+
+ /**
* Did we install us into $wgHooks yet?
* @var Boolean
*/
@@ -634,7 +664,20 @@ class Cite {
$ent[] = $this->referencesFormatEntry( $k, $v );
}
- $prefix = wfMsgForContentNoTrans( 'cite_references_prefix' );
+ // These variables allow for the insertion extra classes
+ // and styles into cite_references_prefix
+ $extraAttributes = '';
+ $extraClasses = '';
+ $extraStyles = '';
+
+ // add css class and css style list type for hard coded group types
+ if ( in_array ( $group, array_keys($this->mGroupCallbacks))) {
+ $extraClasses .= ' ' . $group;
+ $extraStyles .= ' list-style-type: ' . $group . ';';
+ }
+
+ $extraAttributes .= empty($extraStyles) ? '' : ' style="' . $extraStyles . '"';
+ $prefix = wfMsgForContentNoTrans( 'cite_references_prefix', $extraClasses, $extraAttributes);
$suffix = wfMsgForContentNoTrans( 'cite_references_suffix' );
$content = implode( "\n", $ent );
@@ -825,11 +868,28 @@ class Cite {
*/
function getLinkLabel( $offset, $group, $label ) {
$message = "cite_link_label_group-$group";
+
+ // No need to mess around with decimal group
+ if ( $group === CITE_DEFAULT_GROUP ) {
+ return $label;
+ }
+
+ // If this group is hardcoded, call the callback function
+ if ( in_array ( $group, array_keys($this->mGroupCallbacks))) {
+ // name of callback unction to call
+ $method = $this->mGroupCallbacks[$group][0];
+
+ // call the function and return
+ return $this->$method($offset, $this->mGroupCallbacks[$group][1]);
+ }
+
+ // Lets's see if there customs labels
if ( !isset( $this->mLinkLabels[$group] ) ) {
$this->genLinkLabels( $group, $message );
}
- if ( $this->mLinkLabels[$group] === false ) {
- // Use normal representation, ie. "$group 1", "$group 2"...
+
+ // Use normal representation, ie. "$group 1", "$group 2"...
+ if ( $this->mLinkLabels[$group] === false ) {
return $label;
}
@@ -842,6 +902,55 @@ class Cite {
}
/**
+ * Convert a arabic numeral into a roman numeral
+ *
+ * @private
+ *
+ * @param int $offset the number to be converted in roman numerial
+ * @return string $upper Whether upper case
+ */
+ private function formatRoman($offset, $upper) {
+ # No major browser supports roman numerials above 3999, so why should we?
+ if( $offset > 3999 ) return $offset;
+
+ $thousands = intval ( $offset / 1000 );
+ $offset %= 1000;
+
+ $hundreds = intval ( $offset / 100 );
+ $offset %= 100;
+
+ $tens = intval ( $offset / 10 );
+ $offset %= 10;
+
+ $lower = str_repeat ( $this->mRomans['thousand'], $thousands ) . $this->mRomans['hundreds'][$hundreds] . $this->mRomans['tens'][$tens] . $this->mRomans['base'][$offset];
+
+ return ($upper ? strtoupper ( $lower ) : $lower);
+ }
+
+ /**
+ * Convert a decimal numeral into one based on a given alphabet
+ * ie 27 into aa and 2 into b
+ *
+ * @private
+ *
+ * @param int $offset the number to be converted in roman numerial
+ * @return array $upper an array of the alphabet
+ */
+ private function formatAlphabet($offset, $alphabet) {
+ $result = '';
+
+ $offset--;
+ $len = mb_strlen($alphabet);
+
+ while($offset >= 0) {
+ $result = mb_substr( $alphabet, $offset % $len, 1 ) . $result;
+ $offset = intval($offset / $len) - 1;
+ }
+
+ return $result;
+ }
+
+ /**
* Return an id for use in wikitext output based on a key and
* optionally the number of it, used in <references>, not <ref>
* (since otherwise it would link to itself)
diff --git a/citeParserTests.txt b/citeParserTests.txt
index 738dc50..28d549f 100644
--- a/citeParserTests.txt
+++ b/citeParserTests.txt
@@ -389,3 +389,31 @@ Bug 31374 regression check: nested strip items
</li></ol>
!! end
+
+!! test
+<ref> with normal group
+!! input
+Wikipedia normal.<ref group="Note">blah blah</ref>
+
+<references group="Note"/>
+!! result
+<p>Wikipedia normal.<sup id="cite_ref-0" class="reference"><a href="#cite_note-0">[Note 1]</a></sup>
+</p>
+<ol class="references"><li id="cite_note-0"><span class="mw-cite-backlink"><a href="#cite_ref-0">↑</a></span> <span class="reference-text">blah blah</span>
+</li></ol>
+
+!! end
+
+!! test
+<ref> with hard coded roman numeral group
+!! input
+Wikipedia classical.<ref group="lower-roman">Cato the even younger</ref>
+
+<references group="lower-roman"/>
+!! result
+<p>Wikipedia classical.<sup id="cite_ref-0" class="reference"><a href="#cite_note-0">[i]</a></sup>
+</p>
+<ol class="references lower-roman" style="list-style-type: lower-roman;"><li id="cite_note-0"><span class="mw-cite-backlink"><a href="#cite_ref-0">↑</a></span> <span class="reference-text">Cato the even younger</span>
+</li></ol>
+
+!! end

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5893
Default Alt Text
diff.txt (6 KB)

Event Timeline