From fdb8d77b680840866f44bc1515710db60af94fc5 Mon Sep 17 00:00:00 2001 From: Tom N Harris Date: Mon, 30 Jul 2007 23:50:07 +0200 Subject: New structured forms and action events Replaces a number of *FORM_INJECTION events with a more flexible way of modifying forms. Forms are created with a Doku_Form class (inc/form.php) that can be manipulated by plugins prior to output. Plugins register a HTML_{$name}FORM_OUTPUT event which can modify the form object prior to output. Available forms are: LOGIN DRAFT CONFLICT REGISTER UPDATEPROFILE EDIT RESENDPWD Documentation for the Doku_Form class is in inc/form.php. darcs-hash:20070730215007-6942e-a0cf08197f939e224a2b28c40aec5431b118ea94.gz --- inc/html.php | 395 +++++++++++++++++++++++------------------------------------ 1 file changed, 150 insertions(+), 245 deletions(-) (limited to 'inc/html.php') diff --git a/inc/html.php b/inc/html.php index 0c9660fa2..ff2194f2b 100644 --- a/inc/html.php +++ b/inc/html.php @@ -9,6 +9,7 @@ if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); if(!defined('NL')) define('NL',"\n"); require_once(DOKU_INC.'inc/parserutils.php'); +require_once(DOKU_INC.'inc/form.php'); /** * Convenience function to quickly build a wikilink @@ -42,7 +43,6 @@ function html_attbuild($attributes){ * The loginform * * @author Andreas Gohr - * @triggers HTML_LOGINFORM_INJECTION */ function html_login(){ global $lang; @@ -51,59 +51,32 @@ function html_login(){ global $auth; print p_locale_xhtml('login'); - ?> -
-
-
- - - -
-
- - - - - -
-
- canDo('addUser') && actionOK('register')){ - print '

'; - print $lang['reghere']; - print ': '.$lang['register'].''; - print '

'; - } + print '
'.NL; + $form = new Doku_Form('dw__login'); + $form->startFieldset($lang['btn_login']); + $form->addHidden('id', $ID); + $form->addHidden('do', 'login'); + $form->addElement(form_makeTextField('u', $_REQUEST['u'], $lang['user'], 'focus__this', 'block')); + $form->addElement(form_makePasswordField('p', $lang['pass'], '', 'block')); + $form->addElement(form_makeCheckboxField('r', '1', $lang['remember'], 'remember__me', 'simple')); + $form->addElement(form_makeButton('submit', '', $lang['btn_login'])); + $form->endFieldset(); + html_form('login', $form); + + if($auth && $auth->canDo('addUser') && actionOK('register')){ + print '

'; + print $lang['reghere']; + print ': '.$lang['register'].''; + print '

'; + } - if ($auth && $auth->canDo('modPass') && actionOK('resendpwd')) { - print '

'; - print $lang['pwdforget']; - print ': '.$lang['btn_resendpwd'].''; - print '

'; - } - ?> -
- canDo('modPass') && actionOK('resendpwd')) { + print '

'; + print $lang['pwdforget']; + print ': '.$lang['btn_resendpwd'].''; + print '

'; } -*/ + print '
'.NL; } /** @@ -264,21 +237,18 @@ function html_draft(){ $draft = unserialize(io_readFile($INFO['draft'],false)); $text = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true)); - echo p_locale_xhtml('draft'); - ?> -
- -
- - -
- - - - -
- addHidden('id', $ID); + $form->addHidden('date', $draft['date']); + $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly'))); + $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status'))); + $form->addElement($lang['draftdate'].' '. date($conf['dformat'],filemtime($INFO['draft']))); + $form->addElement(form_makeCloseTag('div')); + $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1'))); + $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2'))); + $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3'))); + html_form('draft', $form); } /** @@ -886,19 +856,14 @@ function html_conflict($text,$summary){ global $lang; print p_locale_xhtml('conflict'); - ?> -
-
- - - - - - -
-
-



- addHidden('id', $ID); + $form->addHidden('wikitext', $text); + $form->addHidden('summary', $summary); + $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s'))); + $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel'])); + html_form('conflict', $form); + print '



'.NL; } /** @@ -922,7 +887,6 @@ function html_msgarea(){ * Prints the registration form * * @author Andreas Gohr - * @triggers HTML_REGISTERFORM_INJECTION */ function html_register(){ global $lang; @@ -930,51 +894,23 @@ function html_register(){ global $ID; print p_locale_xhtml('register'); -?> -
-
-
- - - - -
- - -
-
- - -
-
- - -
-
-
-'.NL; + $form = new Doku_Form('dw__register', wl($ID)); + $form->startFieldset($lang['register']); + $form->addHidden('do', 'register'); + $form->addHidden('save', '1'); + $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], null, 'block', array('size'=>'50'))); + if (!$conf['autopasswd']) { + $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50'))); + $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50'))); + } + $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', array('size'=>'50'))); + $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', array('size'=>'50'))); + $form->addElement(form_makeButton('submit', '', $lang['register'])); + $form->endFieldset(); + html_form('register', $form); + + print ''.NL; } /** @@ -994,55 +930,30 @@ function html_updateprofile(){ if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name']; if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail']; -?> -
-
-
- - - - -
-
-

- - canDo('modPass')) { ?> -
-
- - - -
-
- - - - -
-
-
-'.NL; + $form = new Doku_Form('dw__register', wl($ID)); + $form->startFieldset($lang['profile']); + $form->addHidden('do', 'profile'); + $form->addHidden('save', '1'); + $form->addElement(form_makeTextField('fullname', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled'))); + $attr = array('size'=>'50'); + if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled'; + $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', $attr)); + $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', $attr)); + $form->addElement(form_makeTag('br')); + if ($auth->canDo('modPass')) { + $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50'))); + $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50'))); + } + if ($conf['profileconfirm']) { + $form->addElement(form_makeTag('br')); + $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50'))); + } + $form->addElement(form_makeButton('submit', '', $lang['btn_save'])); + $form->addElement(form_makeButton('reset', '', $lang['btn_reset'])); + $form->endFieldset(); + html_form('updateprofile', $form); + print ''.NL; } /** @@ -1108,7 +1019,6 @@ function html_edit($text=null,$include='edit'){ //FIXME: include needed? if($wr){ if ($REV) print p_locale_xhtml('editrev'); print p_locale_xhtml($include); - $ro=false; }else{ // check pseudo action 'source' if(!actionOK('source')){ @@ -1116,7 +1026,6 @@ function html_edit($text=null,$include='edit'){ //FIXME: include needed? return; } print p_locale_xhtml('read'); - $ro='readonly="readonly"'; } if(!$DATE) $DATE = $INFO['lastmod']; @@ -1126,7 +1035,7 @@ function html_edit($text=null,$include='edit'){ //FIXME: include needed?
-
@@ -1139,44 +1048,35 @@ function html_edit($text=null,$include='edit'){ //FIXME: include needed?
- - -
- - - - - - -
- - - - $wr); - trigger_event('HTML_EDITFORM_INJECTION', $evdata); - ?> - -
-
- -
- - - -
- - -
- - - -
- -
-
- addHidden('id', $ID); + $form->addHidden('rev', $REV); + $form->addHidden('date', $DATE); + $form->addHidden('prefix', $PRE); + $form->addHidden('suffix', $SUF); + $form->addHidden('changecheck', $check); + $attr = array('tabindex'=>'1'); + if (!$wr) $attr['readonly'] = 'readonly'; + $form->addElement(form_makeWikiText($text, $attr)); + $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar'))); + $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl'))); + $form->addElement(form_makeCloseTag('div')); + if ($wr) { + $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons'))); + $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4'))); + $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5'))); + $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6'))); + $form->addElement(form_makeCloseTag('div')); + $form->addElement(form_makeOpenTag('div', array('class'=>'summary'))); + $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2'))); + $elem = html_minoredit(); + if ($elem) $form->addElement($elem); + $form->addElement(form_makeCloseTag('div')); + } + $form->addElement(form_makeCloseTag('div')); + html_form('edit', $form); + print ''.NL; } /** @@ -1189,24 +1089,13 @@ function html_minoredit(){ global $lang; // minor edits are for logged in users only if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){ - return; + return false; } $p = array(); - $p['name'] = 'minor'; - $p['type'] = 'checkbox'; - $p['id'] = 'minoredit'; $p['tabindex'] = 3; - $p['value'] = '1'; if(!empty($_REQUEST['minor'])) $p['checked']='checked'; - $att = buildAttributes($p); - - print ''; - print ""; - print ''; - print ''; + return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p); } /** @@ -1341,23 +1230,39 @@ function html_resendpwd() { global $ID; print p_locale_xhtml('resendpwd'); -?> -
-
-
-
- - - -
- -
-
-
-'.NL; + $form = new Doku_Form('dw__resendpwd', wl($ID)); + $form->startFieldset($lang['resendpwd']); + $form->addHidden('do', 'resendpwd'); + $form->addHidden('save', '1'); + $form->addElement(form_makeTag('br')); + $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], '', 'block')); + $form->addElement(form_makeTag('br')); + $form->addElement(form_makeTag('br')); + $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd'])); + $form->endFieldset(); + html_form('resendpwd', $form); + print ''.NL; +} + +/** + * Output a Doku_Form object. + * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT + * + * @author Tom N Harris + */ +function html_form($name, &$form) { + // Safety check in case the caller forgets. + $form->endFieldset(); + trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false); +} + +/** + * Form print function. + * Just calls printForm() on the data object. + */ +function html_form_output($data) { + $data->printForm(); } //Setup VIM: ex: et ts=2 enc=utf-8 : -- cgit v1.2.3