diff --git a/NEWS b/NEWS index 644988e8..87ea7dfe 100644 --- a/NEWS +++ b/NEWS @@ -25,6 +25,8 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier longer strings that would be more appropriately edited with a textarea . Allow newlines to act as separators for lists, hashes, lookups and %HTML.Allowed +. ConfigForm generates textareas instead of text inputs for lists, hashes, + lookups, text and itext fields 2.0.2, unknown release date (none) diff --git a/library/HTMLPurifier/Printer/ConfigForm.php b/library/HTMLPurifier/Printer/ConfigForm.php index 7dda9197..4305ea86 100644 --- a/library/HTMLPurifier/Printer/ConfigForm.php +++ b/library/HTMLPurifier/Printer/ConfigForm.php @@ -34,7 +34,9 @@ class HTMLPurifier_Printer_ConfigForm extends HTMLPurifier_Printer * @param $doc_url String documentation URL, will have fragment tagged on * @param $compress Integer max length before compressing a directive name, set to false to turn off */ - function HTMLPurifier_Printer_ConfigForm($name, $doc_url = null, $compress = false) { + function HTMLPurifier_Printer_ConfigForm( + $name, $doc_url = null, $compress = false + ) { parent::HTMLPurifier_Printer(); $this->docURL = $doc_url; $this->name = $name; @@ -43,6 +45,15 @@ class HTMLPurifier_Printer_ConfigForm extends HTMLPurifier_Printer $this->fields['bool'] = new HTMLPurifier_Printer_ConfigForm_bool(); } + /** + * @param $cols Integer columns of textarea, null to use default + * @param $rows Integer rows of textarea, null to use default + */ + function setTextareaDimensions($cols = null, $rows = null) { + if ($cols) $this->fields['default']->cols = $cols; + if ($rows) $this->fields['default']->rows = $rows; + } + /** * Retrieves styling, in case the directory it's in is not publically * available @@ -200,6 +211,8 @@ class HTMLPurifier_Printer_ConfigForm_NullDecorator extends HTMLPurifier_Printer * Swiss-army knife configuration form field printer */ class HTMLPurifier_Printer_ConfigForm_default extends HTMLPurifier_Printer { + var $cols = 18; + var $rows = 5; function render($ns, $directive, $value, $name, $config) { $this->prepareGenerator($config); // this should probably be split up a little @@ -214,12 +227,12 @@ class HTMLPurifier_Printer_ConfigForm_default extends HTMLPurifier_Printer { $value[] = $val; } case 'list': - $value = implode(',', $value); + $value = implode(PHP_EOL, $value); break; case 'hash': $nvalue = ''; foreach ($value as $i => $v) { - $nvalue .= "$i:$v,"; + $nvalue .= "$i:$v" . PHP_EOL; } $value = $nvalue; break; @@ -244,6 +257,15 @@ class HTMLPurifier_Printer_ConfigForm_default extends HTMLPurifier_Printer { $ret .= $this->element('option', $val, $attr); } $ret .= $this->end('select'); + } elseif ( + $def->type == 'text' || $def->type == 'itext' || + $def->type == 'list' || $def->type == 'hash' || $def->type == 'lookup' + ) { + $attr['cols'] = $this->cols; + $attr['rows'] = $this->rows; + $ret .= $this->start('textarea', $attr); + $ret .= $this->text($value); + $ret .= $this->end('textarea'); } else { $attr['value'] = $value; $attr['type'] = 'text'; diff --git a/smoketests/testSchema.php b/smoketests/testSchema.php index 6e8bc74b..e6b721dc 100644 --- a/smoketests/testSchema.php +++ b/smoketests/testSchema.php @@ -37,3 +37,7 @@ HTMLPurifier_ConfigSchema::defineNamespace('ReportCard', 'It is for grades.'); HTMLPurifier_ConfigSchema::define('ReportCard', 'English', null, 'string/null', 'Grade from English class.'); HTMLPurifier_ConfigSchema::define('ReportCard', 'Absences', 0, 'int', 'How many times missing from school?'); +HTMLPurifier_ConfigSchema::defineNamespace('Text', 'This stuff is long, boring, and English.'); +HTMLPurifier_ConfigSchema::define('Text', 'AboutUs', 'Nothing much, but this should be decently long so that a textarea would be better', 'text', 'Who are we? What are we up to?'); +HTMLPurifier_ConfigSchema::define('Text', 'Hash', "not-case-sensitive\nstill-not-case-sensitive\nsuper-not-case-sensitive", 'itext', 'This is of limited utility, but of course it ends up being used.'); +