Commit 401fdc79 authored by Jyhem's avatar Jyhem

[FIX][bp/r66043] Emergency fix of huge functional regressions of footnotes wrt Tiki17

parent c57f99d2
......@@ -17,8 +17,35 @@ function wikiplugin_footnote_info()
'filter' => 'wikicontent',
'format' => 'html',
'introduced' => 3,
'params' => [
'class' => [
'params' => array(
'tag' => array(
'required' => false,
'name' => tra('Tag'),
'description' => tra('Tag footnote with unique identifier'),
'since' => '15.0',
'default' => '',
'filter' => 'alnum',
'accepted' => tra('One word made of alphanumeric characters'),
),
'sameastag' => array(
'required' => false,
'name' => tra('Same as Tag'),
'description' => tra('Tag to existing footnote by its Tag'),
'since' => '15.0',
'default' => '',
'filter' => 'alnum',
'accepted' => tra('One word made of alphanumeric characters'),
),
'sameas' => array(
'required' => false,
'name' => tra('Same as'),
'description' => tra('Tag to existing footnote number'),
'since' => '5.0',
'default' => '',
'filter' => 'alnum',
'accepted' => tra('tag name (since 17) or footnote number'),
),
'class' => array(
'required' => false,
'name' => tra('Class'),
'description' => tra('Add class to footnotearea'),
......@@ -26,8 +53,17 @@ function wikiplugin_footnote_info()
'default' => '',
'filter' => 'alnumspace',
'accepted' => tra('Valid CSS class'),
],
]
),
'scheme' => array(
'required' => false,
'name' => tra('Scheme'),
'description' => tra('Segregate footnotes by class in footnotearea. Apply different numbering style (optional)'),
'since' => '17.0',
'default' => '',
'filter' => 'text',
'accepted' => tra('Scheme strings (ClassName:((Number Style|numStyle))). Multiples may be separated by | (roman-upper:className|decimal)'),
),
)
];
}
......@@ -39,48 +75,107 @@ function wikiplugin_footnote($data, $params)
if (! isset($footnotes['lists'])) { // if this is the first time the script has run, initialise
$footnotes['count'] = 0;
$footnotes['nest'] = 0;
$footnotes['lists'] = []; // data for general footnotes
$footnotes['tag'] = array(); // record of tags and associated footnote numbers
$footnotes['lists'] = array(); // data for general footnotes
$footnotes['lists']['.def.']['listType'] = 'decimal'; // set the default display type for lists
}
if (isset($params['scheme']))
setScheme($params['scheme']);
$data = trim($data);
if (empty($data)) {
return '<sup>' . tra('Error: Empty footnote') . '</sup>';
}
if (! empty($data)) {
$footnotes['count']++; // keep a record of how many times footones is called to generate unique id's
$footnotes['count']++; // keep a record of how many times footones is called to generate unique id's
// Create an array of classes to be applied
$classes = (isset($params['class'])) ? explode(' ',trim($params["class"])) : array();
if ($footnotes['nest'] > 0) // if we are in a nested footnote, add a nested class
$classes[] ='footnest'.$footnotes['nest'];
// Create an array of classes to be applied
$classes = (isset($params['class'])) ? explode(' ', trim($params["class"])) : [];
if ($footnotes['nest'] > 0) { // if we are in a nested footnote, add a nested class
$classes[] = 'footnest' . $footnotes['nest'];
}
//set the current list to create
$list = '.def.'; // Set the default to illegal class name to prevent conflicts
foreach ($classes as $class) {
if (isset($footnotes['lists'][$class])) {
$list = $class; // set list the the first occurrence, if there happens to be multiplies.
break;
//set the current list to create
$list = '.def.'; // Set the default to illegal class name to prevent conflicts
foreach ($classes as $class) {
if (isset($footnotes['lists'][$class])) {
$list = $class; // set list the the first occurrence, if there happens to be multiplies.
break;
}
}
}
// wow, thats a mouth full, lets make it a little more pleasing to the eyes.
$footnote = &$footnotes['lists'][$list]['entry'];
// wow, thats a mouth full, lets make it a little more pleasing to the eyes.
$footnote = &$footnotes['lists'][$list]['entry'];
// set the current number of list entries
$listNum = count($footnote)+1;
if (isset($params["tag"]) && !isset($footnotes['tag'][$params["tag"]])) { // do nothing if duplicate tag
// Keep track of where data can be found for this Tag
$footnotes['tag'][$params["tag"]]['class'] = $list;
$footnotes['tag'][$params["tag"]]['num'] = $listNum;
$footnote[$listNum]['unique'] = $params["tag"];
}else
$footnote[$listNum]['unique'] = $footnotes['count'];
// set the current number of list entries
$listNum = count($footnote) + 1;
$footnote[$listNum]['class'] = implode(' ',$classes);
$footnote[$listNum]['unique'] = $footnotes['count'];
$footnote[$listNum]['class'] = implode(' ', $classes);
$footnotes['nest']++;
$footnote[$listNum]['data'] = TikiLib::lib('parser')->parse_data_plugin($data,true);
$footnotes['nest']--;
$footnotes['nest']++;
$footnote[$listNum]['data'] = TikiLib::lib('parser')->parse_data_plugin($data, true);
$footnotes['nest']--;
$smarty->assign('uniqueId',$footnote[$listNum]['unique']);
$smarty->assign('unique',$footnote[$listNum]['unique']);
$smarty->assign('listNum',$listNum);
$smarty->assign('class',$footnote[$listNum]['class']);
$smarty->assign('listType',$footnotes['lists'][$list]['listType']);
return $smarty->fetch('templates/wiki-plugins/wikiplugin_footnote.tpl');
} else { // if there is no data
if (isset($params['sameastag']))
$sameas = $params['sameastag'];
elseif (isset($params['sameas']))
$sameas = $params['sameas'];
if (isset($sameas)) {
if (isset($footnotes['tag'][$sameas])) {
$listNum =$footnotes['tag'][$sameas]['num'];
$uniqueId = $sameas . '-' .(@count($footnotes['lists'][ $footnotes['tag'][$sameas]['class'] ]['entry'][$listNum]['sameas'])+1);
$footnotes['lists'][$footnotes['tag'][$sameas]['class']]['entry'][$listNum]['sameas'][] = $uniqueId;
$smarty->assign('listNum',$listNum);
$smarty->assign('uniqueId', $uniqueId);
$smarty->assign('unique',$sameas);
$smarty->assign('listType',$footnotes['lists'][$footnotes['tag'][$sameas]['class']]['listType']);
$smarty->assign('class',$footnotes['lists'][$footnotes['tag'][$sameas]['class']]['entry'][$listNum]['class']);
} elseif ((string)(int)$sameas === (string)$sameas) { // else if the value is a integer
$smarty->assign('listNum',$sameas);// legacy support for number pointing.
$smarty->assign('listType',$footnotes['lists']['.def.']['listType']);
if (isset($footnotes['lists']['.def.']['entry'][$sameas])) { // if the entry already exists
$uniqueId = $sameas . '-' . (count($footnotes['lists']['.def.']['entry'][$sameas]['sameas'])+ 1);
$footnotes['lists']['.def.']['entry'][$sameas]['sameas'][] = $uniqueId;
$smarty->assign('uniqueId',$uniqueId);
$smarty->assign('unique', $footnotes['lists']['.def.']['entry'][$sameas]['unique']);
$smarty->assign('class', $footnotes['lists']['.def.']['entry'][$sameas]['class']);
}else{ // legacy support. These values use to be static
$smarty->assign('unique', $sameas);
$smarty->assign('uniqueId', '');
$smarty->assign('class', '');
}
} else {
// The tag does not exist (yet) !!!!
return '<sup>' . tra('Error: Tag not found in any previous footnote') . '</sup>';
}
return $smarty->fetch('templates/wiki-plugins/wikiplugin_footnote.tpl');
}
}
$smarty->assign('uniqueId', $footnote[$listNum]['unique']);
$smarty->assign('unique', $footnote[$listNum]['unique']);
$smarty->assign('listNum', $listNum);
$smarty->assign('class', $footnote[$listNum]['class']);
return $smarty->fetch('templates/wiki-plugins/wikiplugin_footnote.tpl');
return '';
}
function setScheme($rawScheme)
{
global $footnotes;
$classes = explode('|', $rawScheme);
foreach ($classes as $class) {
$scheme = explode(':', $class);
if (!isset($scheme[1]))
$scheme[1] = '.def.'; // if no class specified, use the default list
$footnotes['lists'][$scheme[1]]['listType'] = $scheme[0];
}
}
......@@ -25,6 +25,15 @@ function wikiplugin_footnotearea_info()
'filter' => 'alnum',
'accepted' => tra('Valid CSS class'),
],
'sameasstyle' => array(
'required' => false,
'name' => tra('SameAs Style'),
'description' => tra('Numbering style for sameas referencing.'),
'since' => '17.0',
'default' => 'disc',
'filter' => 'text',
'accepted' => tra('Valid Tiki ((Number Style))'),
),
],
];
}
......@@ -34,6 +43,10 @@ function wikiplugin_footnotearea($data, $params)
global $footnotes;
$smarty = TikiLib::lib('smarty');
if (isset($params['sameasstyle']))
$smarty->assign('sameType',$params['sameasstyle']);
else
$smarty->assign('sameType','disc');
$html = '';
if (isset($params['class'])) { // if class was given
if (isset($footnotes['lists'][$params['class']])) { // if the class exists
......@@ -70,6 +83,7 @@ function genFootnoteArea($listName, $list)
$smarty->assign('listName', ' ' . $listName); // if we are in a list, fix spacing up nice
}
$smarty->assign('footnotes', $list['entry']);
$smarty->assign('listType',$list['listType']);
return $smarty->fetch('templates/wiki-plugins/wikiplugin_footnotearea.tpl');
}
<a {if $uniqueId}id="ref_footnote{$uniqueId}" {/if}href="#footnote{$unique}" class="footlink {$class}">{$listNum|numStyle:"decimal"}</a>
<a {if $uniqueId}id="ref_footnote{$uniqueId}" {/if}href="#footnote{$unique}" class="footlink {$class}">{$listNum|numStyle:$listType}</a>
......@@ -2,10 +2,10 @@
{foreach $footnotes as $number => $footnote}
<div {if $footnote['class']}class="{$footnote['class']}" {/if}id="footnote{$footnote['unique']}">
<span>
<a href="#ref_footnote{$footnote['unique']}">{$number|numStyle:"decimal"}</a>
<a href="#ref_footnote{$footnote['unique']}">{$number|numStyle:$listType}</a>
{if isset($footnote['sameas'])}
{foreach $footnote['sameas'] as $num => $unique}
<a href="#ref_footnote{$unique}" class="sameas"> {($num+1)|numStyle:"disc"}</a>
<a href="#ref_footnote{$unique}" class="sameas"> {($num+1)|numStyle:$sameType}</a>
{/foreach}
{/if}
</span>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment