Index: trunk/extensions/HtmlUi/HtmlUi.i18n.php |
— | — | @@ -0,0 +1,25 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Internationalisation for HtmlUi extension |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + */ |
| 9 | + |
| 10 | +$messages = array(); |
| 11 | + |
| 12 | +/** English |
| 13 | + * @author Trevor Parscal |
| 14 | + */ |
| 15 | +$messages['en'] = array( |
| 16 | + 'htmlui' => 'HTML User Interface Library', |
| 17 | + 'htmlui-desc' => 'Toolkit for rendering HTML user interfaces.', |
| 18 | +); |
| 19 | + |
| 20 | +/** Message documentation (Message documentation) |
| 21 | + * @author Trevor Parscal |
| 22 | + */ |
| 23 | +$messages['qqq'] = array( |
| 24 | + 'htmlui' => 'HTML means Hyper-Text Markup Language. UI means User Interface. HtmlUI is the name of a user interface library.', |
| 25 | + 'htmlui-desc' => '{{desc}}', |
| 26 | +); |
Property changes on: trunk/extensions/HtmlUi/HtmlUi.i18n.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 27 | + native |
Index: trunk/extensions/HtmlUi/HtmlUi.php |
— | — | @@ -0,0 +1,33 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * HtmlUi extension |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + * |
| 9 | + * @author Trevor Parscal <trevor@wikimedia.org> |
| 10 | + * @license Apache 2.0 |
| 11 | + * @version 0.1.0 |
| 12 | + */ |
| 13 | + |
| 14 | +/* Setup */ |
| 15 | + |
| 16 | +$wgExtensionCredits['other'][] = array( |
| 17 | + 'path' => __FILE__, |
| 18 | + 'name' => 'HtmlUi', |
| 19 | + 'author' => array( 'Trevor Parscal' ), |
| 20 | + 'version' => '0.1.0', |
| 21 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:HtmlUi', |
| 22 | + 'descriptionmsg' => 'htmlui-desc', |
| 23 | +); |
| 24 | +$dir = dirname( __FILE__ ); |
| 25 | +$wgAutoloadClasses['HtmlUi'] = "$dir/classes/HtmlUi.php"; |
| 26 | +$wgAutoloadClasses['HtmlUiField'] = "$dir/classes/HtmlUiField.php"; |
| 27 | +$wgAutoloadClasses['HtmlUiFieldset'] = "$dir/classes/HtmlUiFieldset.php"; |
| 28 | +$wgAutoloadClasses['HtmlUiForm'] = "$dir/classes/HtmlUiForm.php"; |
| 29 | +$wgAutoloadClasses['HtmlUiFormElement'] = "$dir/classes/HtmlUiFormElement.php"; |
| 30 | +$wgAutoloadClasses['HtmlUiFormElementCollection'] = "$dir/classes/HtmlUiFormElementCollection.php"; |
| 31 | +$wgAutoloadClasses['HtmlUiTemplate'] = "$dir/classes/HtmlUiTemplate.php"; |
| 32 | +$wgAutoloadClasses['HtmlUiHooks'] = "$dir/HtmlUi.hooks.php"; |
| 33 | +$wgExtensionMessagesFiles['HtmlUi'] = "$dir/HtmlUi.i18n.php"; |
| 34 | +$wgHooks['ResourceLoaderRegisterModules'][] = 'HtmlUiHooks::resourceLoaderRegisterModules'; |
Property changes on: trunk/extensions/HtmlUi/HtmlUi.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 35 | + native |
Index: trunk/extensions/HtmlUi/modules/ext.htmlUi.css |
— | — | @@ -0,0 +1,3 @@ |
| 2 | +/** |
| 3 | + * CSS for HtmlUi |
| 4 | + */ |
Property changes on: trunk/extensions/HtmlUi/modules/ext.htmlUi.css |
___________________________________________________________________ |
Added: svn:mime-type |
1 | 5 | + text/plain |
Added: svn:eol-style |
2 | 6 | + native |
Index: trunk/extensions/HtmlUi/modules/ext.htmlUi.js |
— | — | @@ -0,0 +1,3 @@ |
| 2 | +/** |
| 3 | + * JavaScript for HtmlUi |
| 4 | + */ |
Property changes on: trunk/extensions/HtmlUi/modules/ext.htmlUi.js |
___________________________________________________________________ |
Added: svn:mime-type |
1 | 5 | + text/plain |
Added: svn:eol-style |
2 | 6 | + native |
Index: trunk/extensions/HtmlUi/HtmlUi.hooks.php |
— | — | @@ -0,0 +1,39 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Hooks for HtmlUi extension |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + */ |
| 9 | + |
| 10 | +class HtmlUiHooks { |
| 11 | + |
| 12 | + /* Protected Static Members */ |
| 13 | + |
| 14 | + protected static $modules = array( |
| 15 | + 'ext.htmlUi' => array( |
| 16 | + 'scripts' => 'ext.htmlUi.js', |
| 17 | + 'styles' => 'ext.htmlUi.css', |
| 18 | + 'group' => 'ext.htmlUi', |
| 19 | + ), |
| 20 | + ); |
| 21 | + |
| 22 | + /* Static Methods */ |
| 23 | + |
| 24 | + /** |
| 25 | + * ResourceLoaderRegisterModules hook. |
| 26 | + * |
| 27 | + * Adds modules to ResourceLoader. |
| 28 | + */ |
| 29 | + public static function resourceLoaderRegisterModules( &$resourceLoader ) { |
| 30 | + global $wgExtensionAssetsPath; |
| 31 | + $localpath = dirname( __FILE__ ) . '/modules'; |
| 32 | + $remotepath = "$wgExtensionAssetsPath/HtmlUi/modules"; |
| 33 | + foreach ( self::$modules as $name => $resources ) { |
| 34 | + $resourceLoader->register( |
| 35 | + $name, new ResourceLoaderFileModule( $resources, $localpath, $remotepath ) |
| 36 | + ); |
| 37 | + } |
| 38 | + return true; |
| 39 | + } |
| 40 | +} |
Property changes on: trunk/extensions/HtmlUi/HtmlUi.hooks.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 41 | + native |
Index: trunk/extensions/HtmlUi/README |
— | — | @@ -0,0 +1,24 @@ |
| 2 | +== General Objective == |
| 3 | + |
| 4 | +Provide a managed way to generate HTML user interface components. |
| 5 | + |
| 6 | +== Outline of Proposed Functionality == |
| 7 | + |
| 8 | +Filters (Validation) |
| 9 | + |
| 10 | +* Minimum length |
| 11 | +* Maximum length |
| 12 | +* Pattern (regex) |
| 13 | +* Compare (a [operation] [value|b]) |
| 14 | + |
| 15 | +Workflows |
| 16 | + |
| 17 | +* a requires [b, c, d, …] |
| 18 | +* a confirms b |
| 19 | + |
| 20 | +Fields |
| 21 | + |
| 22 | +* Text (single-line, multi-line - options/suggestions, auto-grow) |
| 23 | +* MultiText (multiple texts with options) |
| 24 | +* Opton (radio buttons, dropdown list, slider, knob, etc.) |
| 25 | +* MultiOption (multiple checkboxes, multi-select list) |
Index: trunk/extensions/HtmlUi/classes/HtmlUiFormElementCollection.php |
— | — | @@ -0,0 +1,47 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class HtmlUiFormElementCollection { |
| 5 | + |
| 6 | + /* Abstract Protected Methods */ |
| 7 | + |
| 8 | + abstract protected function getDefaultOptions() { |
| 9 | + return array(); |
| 10 | + } |
| 11 | + |
| 12 | + /* Protected Members */ |
| 13 | + |
| 14 | + protected $options; |
| 15 | + protected $elements; |
| 16 | + |
| 17 | + /* Methods */ |
| 18 | + |
| 19 | + public function __construct( array $elements = array(), $options = array() ) { |
| 20 | + $this->addElements( $elements ); |
| 21 | + $this->options = array_merge( $this->getDefaultOptions(), $options ); |
| 22 | + } |
| 23 | + |
| 24 | + public function addElement( HtmlUiFormElement $element ) { |
| 25 | + $this->elements[] = $element; |
| 26 | + } |
| 27 | + |
| 28 | + public function addElements( array $elements ) { |
| 29 | + foreach ( $elements as $element ) { |
| 30 | + $this->addElement( $element ); |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + public function removeElement( HtmlUiFormElement $element ) { |
| 35 | + $index = array_search( $element, $this->elements, true ); |
| 36 | + if ( $index !== false ) { |
| 37 | + array_splice( $this->elements, $index, 1 ); |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + public function getOption( $option ) { |
| 42 | + return isset( $this->options[$option] ) ? $this->options[$option] : null; |
| 43 | + } |
| 44 | + |
| 45 | + public function setOption( $option, $value ) { |
| 46 | + return isset( $this->options[$option] ) ? $this->options[$option] = $value : null; |
| 47 | + } |
| 48 | +} |
Property changes on: trunk/extensions/HtmlUi/classes/HtmlUiFormElementCollection.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 49 | + native |
Index: trunk/extensions/HtmlUi/classes/HtmlUiTemplate.php |
— | — | @@ -0,0 +1,66 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class HtmlUiTemplate { |
| 5 | + |
| 6 | + /* Protected Members */ |
| 7 | + |
| 8 | + protected $filePath; |
| 9 | + |
| 10 | + /* Methods */ |
| 11 | + |
| 12 | + /** |
| 13 | + * @param {string} $file path to template |
| 14 | + * @param {array} $data list of properties to initially set |
| 15 | + */ |
| 16 | + public function __construct( $filePath ) { |
| 17 | + if ( !file_exists( $filePath ) ) { |
| 18 | + throw new \MWException( sprintf( |
| 19 | + 'Bad template file path error. "%s" is not a path to an existing file', $filePath |
| 20 | + ) ); |
| 21 | + } |
| 22 | + $this->filePath = $filePath; |
| 23 | + } |
| 24 | + |
| 25 | + /** |
| 26 | + * Renders the template using an output-buffer. |
| 27 | + * |
| 28 | + * @param {array} $data List of key/value pairs to expand into variables while rendering |
| 29 | + * @return {string} Rendered template |
| 30 | + */ |
| 31 | + public function render( array $data = array() ) { |
| 32 | + // Expand bindings to vars, just for this scope |
| 33 | + extract( $data ); |
| 34 | + ob_start(); |
| 35 | + require( $this->filePath ); |
| 36 | + return ob_get_clean(); |
| 37 | + } |
| 38 | + |
| 39 | + /* Static Methods */ |
| 40 | + |
| 41 | + /** |
| 42 | + * Escapes a string to be safely rendered in an HTML document. |
| 43 | + */ |
| 44 | + public static function escape( $value ) { |
| 45 | + // More escaping here may be needed |
| 46 | + return htmlspecialchars( $value ); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Renders XML attributes from an array of key and value pairs. If a value is an array, it's |
| 51 | + * imploded using a space as a delimiter. If any attributes are rendered, the result is preceded |
| 52 | + * with a single space, otherwise the result is an empty string. |
| 53 | + */ |
| 54 | + public static function attributes( $attributes ) { |
| 55 | + $result = array(); |
| 56 | + if ( is_array( $attributes ) ) { |
| 57 | + foreach ( $attributes as $key => $value ) { |
| 58 | + if ( is_array( $value ) ) { |
| 59 | + $result[] = $key . '="' . implode( ' ', self::escape( $value ) ) . '"'; |
| 60 | + } else { |
| 61 | + $result[] = $key . '="' . self::escape( $value ) . '"'; |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | + return count( $result ) ? ( ' ' . implode( ' ', $result ) ) : ''; |
| 66 | + } |
| 67 | +} |
Property changes on: trunk/extensions/HtmlUi/classes/HtmlUiTemplate.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 68 | + native |
Index: trunk/extensions/HtmlUi/classes/HtmlUiFormElement.php |
— | — | @@ -0,0 +1,10 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +interface HtmlUiFormElement { |
| 5 | + |
| 6 | + /* Methods */ |
| 7 | + |
| 8 | + public function getId(); |
| 9 | + public function setId( $id ); |
| 10 | + public function render(); |
| 11 | +} |
Property changes on: trunk/extensions/HtmlUi/classes/HtmlUiFormElement.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 12 | + native |
Index: trunk/extensions/HtmlUi/classes/HtmlUi.php |
— | — | @@ -0,0 +1,13 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +abstract class HtmlUi { |
| 5 | + |
| 6 | + /* Static Methods */ |
| 7 | + |
| 8 | + public static function createForm( array $elements = array() ) { |
| 9 | + foreach ( $elements as $path => $options ) { |
| 10 | + $id = end( explode( '/', $path ) ); |
| 11 | + // Build out a structured form from a flat list of elements |
| 12 | + } |
| 13 | + } |
| 14 | +} |
Property changes on: trunk/extensions/HtmlUi/classes/HtmlUi.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 15 | + native |
Index: trunk/extensions/HtmlUi/classes/HtmlUiFieldset.php |
— | — | @@ -0,0 +1,29 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class HtmlUiFieldset extends HtmlUiFormElementCollection implements HtmlUiFormElement { |
| 5 | + |
| 6 | + /* Protected Members */ |
| 7 | + |
| 8 | + protected $id; |
| 9 | + |
| 10 | + /* Protected Methods */ |
| 11 | + |
| 12 | + protected function getDefaultOptions() { |
| 13 | + return array(); |
| 14 | + } |
| 15 | + |
| 16 | + /* Methods */ |
| 17 | + |
| 18 | + public function getId() { |
| 19 | + return $this->id; |
| 20 | + } |
| 21 | + |
| 22 | + public function setId( $id ) { |
| 23 | + return $this->id = $id; |
| 24 | + } |
| 25 | + |
| 26 | + public function render() { |
| 27 | + $template = new HtmlUiTemplate( 'extensions/HtmlUi/templates/HtmlUiFieldset.php' ); |
| 28 | + return $template->render( array_merge( array( 'id' => $this->id ), $this->elements ) ); |
| 29 | + } |
| 30 | +} |
Property changes on: trunk/extensions/HtmlUi/classes/HtmlUiFieldset.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 31 | + native |
Index: trunk/extensions/HtmlUi/classes/HtmlUiField.php |
— | — | @@ -0,0 +1,28 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +abstract class HtmlUiField implements HtmlUiFormElement { |
| 5 | + |
| 6 | + /* Protected Members */ |
| 7 | + |
| 8 | + protected $id; |
| 9 | + |
| 10 | + /* Protected Methods */ |
| 11 | + |
| 12 | + protected function getDefaultOptions() { |
| 13 | + return array(); |
| 14 | + } |
| 15 | + |
| 16 | + /* Methods */ |
| 17 | + |
| 18 | + public function getId() { |
| 19 | + return $this->id; |
| 20 | + } |
| 21 | + |
| 22 | + public function setId( $id ) { |
| 23 | + return $this->id = $id; |
| 24 | + } |
| 25 | + |
| 26 | + abstract public function render(); |
| 27 | + abstract public function getValue(); |
| 28 | + abstract public function setValue( $value ); |
| 29 | +} |
Property changes on: trunk/extensions/HtmlUi/classes/HtmlUiField.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 30 | + native |
Index: trunk/extensions/HtmlUi/classes/HtmlUiForm.php |
— | — | @@ -0,0 +1,30 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class HtmlUiForm extends HtmlUiFormElementCollection { |
| 5 | + |
| 6 | + /* Protected Methods */ |
| 7 | + |
| 8 | + protected function getDefaultOptions() { |
| 9 | + return array( |
| 10 | + 'action' => './', |
| 11 | + 'method' => 'post', |
| 12 | + ); |
| 13 | + } |
| 14 | + |
| 15 | + /* Method */ |
| 16 | + |
| 17 | + public function render() { |
| 18 | + $template = new HtmlUiTemplate( 'extensions/HtmlUi/templates/HtmlUiForm.php' ); |
| 19 | + return $template->render( array_merge( |
| 20 | + array( 'attributes' => array( |
| 21 | + 'action' => $this->options['action'], |
| 22 | + 'method' => $this->options['method'], |
| 23 | + ), |
| 24 | + $this->elements |
| 25 | + ) ); |
| 26 | + } |
| 27 | + |
| 28 | + public function validate() { |
| 29 | + // |
| 30 | + } |
| 31 | +} |
Property changes on: trunk/extensions/HtmlUi/classes/HtmlUiForm.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 32 | + native |
Index: trunk/extensions/HtmlUi/templates/HtmlUiFieldset.php |
— | — | @@ -0,0 +1,5 @@ |
| 2 | +<fieldset class="htmlUiFieldset" rel="<?php echo self::escape( $id ) ?>"> |
| 3 | + <?php foreach( $elements as $element ): ?> |
| 4 | + <?php echo $element->render(); ?> |
| 5 | + <?php endforeach; ?> |
| 6 | +</fieldset> |
Property changes on: trunk/extensions/HtmlUi/templates/HtmlUiFieldset.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 7 | + native |
Index: trunk/extensions/HtmlUi/templates/HtmlUiForm.php |
— | — | @@ -0,0 +1,5 @@ |
| 2 | +<form class="htmlUiForm"<?php echo self::attributes( $attributes ) ?>> |
| 3 | + <?php foreach( $elements as $element ): ?> |
| 4 | + <?php echo $element->render(); ?> |
| 5 | + <?php endforeach; ?> |
| 6 | +</form> |
Property changes on: trunk/extensions/HtmlUi/templates/HtmlUiForm.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 7 | + native |