Spage has uploaded a new change for review. https://gerrit.wikimedia.org/r/87038
Change subject: Add a Special:Agora page with sample form. ...................................................................... Add a Special:Agora page with sample form. Shows sample Agora controls, with a control panel that affects HTMLForm. TODO: * add run-time CSS switching as in http://pauginer.github.io/agora/ * add tabs to show other kinds of CSS rendering This uses FormSpecialPage and thus HTMLForm, so it requires the core patch "Add vform format to HTMLForm" gerrit 65346 , change Id03d185bbee990595bfc469a61163cc598fc3441 in core, otherwise you don't see Agora buttons. It uses core's mediawiki.ui, so the appearance varies with the state of Agora on the wiki. Change-Id: Ic9c1583b770768ddc5a8c8b54e64cb5d2898ac6b --- M Agora.i18n.php M Agora.php A SpecialAgora.php 3 files changed, 165 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Agora refs/changes/38/87038/1 diff --git a/Agora.i18n.php b/Agora.i18n.php index b0ae99d..4d7e96c 100644 --- a/Agora.i18n.php +++ b/Agora.i18n.php @@ -12,15 +12,17 @@ * @author Rob Moen */ $messages['en'] = array( + 'agora' => 'Agora design sample', 'agora-desc' => 'Skin agnostic Agora theming for MediaWiki', + 'agora-demo-controls' => 'Controls for this design sample/demo', ); /** Message documentation (Message documentation) - * @author Beta16 - * @author Shirayuki */ $messages['qqq'] = array( - 'agora-desc' => '{{desc|name=Agora|url=http://www.mediawiki.org/wiki/Skin:Agora}}', + 'agora' => '{{doc-special|Agora}}', + 'agora-desc' => '{{desc|name=Agora|url=http://www.mediawiki.org/wiki/Agora}}', + 'agora-demo-controls' => 'Form legend for the controls for the design sample', ); /** Asturian (asturianu) diff --git a/Agora.php b/Agora.php index a5b7262..021a643 100644 --- a/Agora.php +++ b/Agora.php @@ -1,23 +1,28 @@ <?php -$wgExtensionCredits['other'][] = array( +$wgExtensionCredits['specialpage'][] = array( 'path' => __FILE__, 'name' => 'Agora', - 'version' => '0.0.2', + 'version' => '0.0.3', 'url' => 'https://www.mediawiki.org/wiki/Extension:Agora', - 'author' => array( 'Rob Moen', 'Trevor Parscal', 'Munaf Assaf' ), + 'author' => array( 'Rob Moen', 'Trevor Parscal', 'Munaf Assaf', 'S Page' ), 'descriptionmsg' => 'agora-desc' ); // Hooks $wgAutoloadClasses['AgoraHooks'] = __DIR__ . '/Agora.hooks.php'; +$wgAutoloadClasses['SpecialAgora'] = __DIR__ . '/SpecialAgora.php'; // Not needed if we do it in the function. $wgExtensionFunctions[] = 'AgoraHooks::doSetup'; $wgHooks['BeforePageDisplay'][] = 'AgoraHooks::onBeforePageDisplay'; -//i18n +// i18n $wgExtensionMessagesFiles['Agora'] = __DIR__ . '/Agora.i18n.php'; + +// The special page +$wgSpecialPages['Agora'] = 'SpecialAgora'; +// XXX Needed? $wgSpecialPageGroups['Agora'] = 'users'; // Resource Template $wgAgoraResourceTemplate = array( @@ -28,7 +33,7 @@ $wgResourceModules += array( 'ext.agora' => $wgAgoraResourceTemplate + array( 'scripts' => array( - 'js/ext.agora', + 'js/ext.agora.js', ), 'position' => 'top', ), diff --git a/SpecialAgora.php b/SpecialAgora.php new file mode 100644 index 0000000..c0d9f8d --- /dev/null +++ b/SpecialAgora.php @@ -0,0 +1,150 @@ +<?php +// TODO (spage, 2013-09-20) Want to have a set of tabs showing different +// things: as well as HTMLForm sample forms, show raw CSS styling like +// http://pauginer.github.io/agora/, jQuery UI, etc. + + +// In trying to figure out where to grab the values for the form controls to +// affect the form itself, here's the flow of code in FormSpecialPage and +// HTMLForm that I worked out. +// +// page loads +// execute() runs, +// calls FormSpecialPage->getForm() +// calls $this->getFormFields() +// where you can supply default values for fields +// creates new HTMLForm (you can't override or subclass this :-( ) +// this setWrapperLegendMsg(), headertext, Pre/Post text, etc. +// adds Query Params as hidden field +// calls alterForm() +// HERE is where I can change the form appearance, +// but I have to get the values of the form controls myself. +// calls form->show() +// form->prepareForm() +// this loadData() from the request +// then looks at submitted data +// if not authorized, returns early +// validates each field +// calling any field validation callbacks +// Here is where I could check the values of my form controls, +// If all validated OK then calls onSubmit() callback +// Continues to form->displayForm() +// If I could subclass the form and intercept displayForm() life would be great, +// I'd tweak the form based on the control values here. But I can't $#@! do it, +// Anyway, form->displayForm() +// calls form->getHTML passing it any errors from submit() +// assembles form modules, styles, errors, header, body... +// getBody() eventually asks each form field for its HTML, passing it either the field's data (what the user did) or its default. +// adds the form HTML to the page. + +class SpecialAgoraControls { + // initial values + public $mHTMLFormType = 'vform'; + public $mHTMLFormShowLegend = false; +} +class SpecialAgora extends FormSpecialPage { + + private $controls; + + public function __construct() { + parent::__construct( 'Agora' ); + $this->controls = new SpecialAgoraControls; + } + + // Affect the appearance of the form according to control form fields. + public function affectTheForm( $form ) { + // We have to load the values of the fields ourselves because we're doing + // this in alterForm() before HTMLForm processes any submit operation. + // And we have to do it for the whole form because the individual + // mFlatFields objects are private. Inflexibility, thy name is HTMLForm. + $form->loadData(); + $this->controls->mHTMLFormType = $form->mFieldData['displayFormat']; + $this->controls->mHTMLFormShowLegend = $form->mFieldData['showWrapperLegend']; + + + $form->setDisplayFormat( $this->controls->mHTMLFormType ); + // Maybe turn the old-school line around the form off. + // XXX This wouldn't be necessary here if we could set the format of + // the HTMLForm to 'vform' at its creation, but there's no way to do so + // from a FormSpecialPage class. + $form->setWrapperLegend( $this->controls->mHTMLFormShowLegend ); + } + + // Copy-paste from https://www.mediawiki.org/wiki/HTMLForm/tutorial2 + static function validateSimpleTextField($simpleTextField, $allData) { + if ($simpleTextField != 'hello') { + return 'You must enter "hello"'; + } + return true; + } + + protected function getFormFields() { + $a = array(); + + // A section with some controls that affect the form. + $a['displayFormat'] = array( + 'section' => 'demo-controls', // the labels {specialpagename}-controls + 'type' => 'select', + 'label' => 'Choose a layout', + 'options' => array( + 'table' => 'table', + 'div' => 'div', + 'raw' => 'raw', + 'vform' => 'vform', + ), + 'default' => $this->controls->mHTMLFormType, + ); + $a['showWrapperLegend'] = array( + 'section' => 'demo-controls', + 'type' => 'check', + 'label' => 'Show wrapper legend', + 'default' => $this->controls->mHTMLFormShowLegend, + ); + + // TODO: skin chooser here (workaround is to add ?useskin=monobook to + // the query string). + + // Now some sample form bits and pieces. + + // These form fields from SpecialPasswordReset.php + $a['Username'] = array( + 'type' => 'text', + 'label-message' => 'passwordreset-username', + ); + + $a['Username']['default'] = $this->getUser()->getName(); + + $a['Email'] = array( + 'type' => 'email', + 'label-message' => 'passwordreset-email', + ); + + // Adapted from https://www.mediawiki.org/wiki/HTMLForm/tutorial2. + $a['simpletextfield'] = array( + 'label' => 'Simple validating Text Field', + 'class' => 'HTMLTextField', + 'validation-callback' => array('SpecialAgora', 'validateSimpleTextField'), #Calling validateSimpteTextField() within SpecialMyForm + ); + + return $a; + } + + public function alterForm( HTMLForm $form ) { + + // We want to configure the form according to the values of its control fields. + // But this runs before the form calls onSubmit() with what the user chose! + $this->affectTheForm( $form ); + + $form->setSubmitTextMsg( 'mailmypassword' ); + } + + /** + * Process the form on POST submission. + * @param $data Array + * @return Bool|Array true for success, false for didn't-try, array of errors on failure + */ + public function onSubmit( array $data ) { + // Return false so the form remains displayed. + return false; + } +} -- To view, visit https://gerrit.wikimedia.org/r/87038 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic9c1583b770768ddc5a8c8b54e64cb5d2898ac6b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Agora Gerrit-Branch: master Gerrit-Owner: Spage <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
