Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.php |
— | — | @@ -40,4 +40,4 @@ |
41 | 41 | |
42 | 42 | /* Components */ |
43 | 43 | |
44 | | -require_once( "$dir/Toolbar/Toolbar.php" ); |
| 44 | +require_once( "$dir/EditToolbar/EditToolbar.php" ); |
Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.css |
— | — | @@ -0,0 +1,27 @@ |
| 2 | +/* CSS StyleSheet for Toolbar extensions */ |
| 3 | + |
| 4 | +div#edittoolbar { |
| 5 | + width: 100%; |
| 6 | + height: 32px; |
| 7 | + background-color: #EEEEEE; |
| 8 | +} |
| 9 | + |
| 10 | +div#edittoolbar > div.group { |
| 11 | + float: left; |
| 12 | + height: 26px; |
| 13 | + margin: 3px; |
| 14 | + padding-left: 3px; |
| 15 | + border-left: solid 1px #DDDDDD; |
| 16 | +} |
| 17 | +div#edittoolbar > div.group:first-child { |
| 18 | + border-left: none; |
| 19 | +} |
| 20 | + |
| 21 | +div#edittoolbar > div.group > img { |
| 22 | + float: left; |
| 23 | + border: 0px; |
| 24 | + height: 22px; |
| 25 | + width: 22px; |
| 26 | + margin: 2px; |
| 27 | + cursor: pointer; |
| 28 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.css |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 29 | + native |
Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.hooks.php |
— | — | @@ -0,0 +1,126 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Hooks for Usability Initiative Toolbar extension |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + */ |
| 9 | + |
| 10 | +class EditToolbarHooks { |
| 11 | + |
| 12 | + /* Static Functions */ |
| 13 | + |
| 14 | + /** |
| 15 | + * EditPageBeforeEditToolbar hook |
| 16 | + * Intercept the display of the toolbar, replacing the content of $toolbar |
| 17 | + */ |
| 18 | + public static function intercept( &$toolbar ) { |
| 19 | + global $wgUser, $wgOut, $wgJsMimeType; |
| 20 | + |
| 21 | + // Internationalization |
| 22 | + wfLoadExtensionMessages( 'EditToolbar' ); |
| 23 | + |
| 24 | + // Replaces toolbar with new toolbar container |
| 25 | + if ( $wgUser->getOption( 'usebetatoolbar' ) ) { |
| 26 | + $toolbar = '<div id="edittoolbar"></div>'; |
| 27 | + } |
| 28 | + // List of messages to be sent to the client for use in the toolbar |
| 29 | + // all of which will get a prefix of "toolbar" |
| 30 | + $messages = array( |
| 31 | + 'format-bold', |
| 32 | + 'format-bold-example', |
| 33 | + 'format-italic', |
| 34 | + 'format-italic-example', |
| 35 | + 'insert-ilink', |
| 36 | + 'insert-ilink-example', |
| 37 | + 'insert-xlink', |
| 38 | + 'insert-xlink-example', |
| 39 | + 'insert-image', |
| 40 | + 'insert-image-example', |
| 41 | + 'insert-reference', |
| 42 | + 'insert-reference-example', |
| 43 | + ); |
| 44 | + // Transforms messages into javascript object members |
| 45 | + foreach ( $messages as $i => $message ) { |
| 46 | + $escapedMessageValue = Xml::escapeJsString( |
| 47 | + wfMsg( 'edittoolbar-' . $message ) |
| 48 | + ); |
| 49 | + $escapedMessageKey = Xml::escapeJsString( $message ); |
| 50 | + $messages[$i] = "'{$escapedMessageKey}':'{$escapedMessageValue}'"; |
| 51 | + } |
| 52 | + // Converts array of object members to a comma delimited list |
| 53 | + $messagesList = implode( ',', $messages ); |
| 54 | + // Encapsulates list in javascript code to set them durring load |
| 55 | + $messagesJs = "editToolbar.setMessages({{$messagesList}});"; |
| 56 | + // Appends javascript message setting code |
| 57 | + $toolbar .= Xml::element( |
| 58 | + 'script', array( 'type' => $wgJsMimeType ), $messagesJs |
| 59 | + ); |
| 60 | + |
| 61 | + // Continue |
| 62 | + return true; |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * GetPreferences hook |
| 67 | + * Add toolbar related items to the preferences |
| 68 | + */ |
| 69 | + public static function addPreferences( $user, $defaultPreferences ) { |
| 70 | + wfLoadExtensionMessages( 'EditToolbar' ); |
| 71 | + $defaultPreferences['usebetatoolbar'] = |
| 72 | + array( |
| 73 | + 'type' => 'toggle', |
| 74 | + 'label-message' => 'edittoolbar-preference', |
| 75 | + 'section' => 'editing/advancedediting', |
| 76 | + ); |
| 77 | + return true; |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * AjaxAddScript hook |
| 82 | + * Add ajax support script |
| 83 | + */ |
| 84 | + public static function addJS( $out ) { |
| 85 | + global $wgScriptPath, $wgJsMimeType, $wgEditToolbarStyleVersion; |
| 86 | + // Add javascript version variable |
| 87 | + $out->addInlineScript( |
| 88 | + "var wgEditToolbarStyleVersion = \"$wgEditToolbarStyleVersion\";\n" |
| 89 | + ); |
| 90 | + // Add javascript resources to document |
| 91 | + $out->addScript( |
| 92 | + Xml::element( |
| 93 | + 'script', |
| 94 | + array( |
| 95 | + 'type' => $wgJsMimeType, |
| 96 | + 'src' => $wgScriptPath . |
| 97 | + '/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js?' . |
| 98 | + $wgToolbarStyleVersion |
| 99 | + ), |
| 100 | + '', |
| 101 | + false |
| 102 | + ) |
| 103 | + ); |
| 104 | + // Continue |
| 105 | + return true; |
| 106 | + } |
| 107 | + |
| 108 | + /** |
| 109 | + * BeforePageDisplay hook |
| 110 | + * Add css style sheet |
| 111 | + */ |
| 112 | + public static function addCSS( $out ) { |
| 113 | + global $wgScriptPath, $wgEditToolbarStyleVersion; |
| 114 | + // Add css for various styles |
| 115 | + $out->addLink( |
| 116 | + array( |
| 117 | + 'rel' => 'stylesheet', |
| 118 | + 'type' => 'text/css', |
| 119 | + 'href' => $wgScriptPath . |
| 120 | + '/extensions/UsabilityInitiative/EditToolbar/EditToolbar.css?' . |
| 121 | + $wgEditToolbarStyleVersion, |
| 122 | + ) |
| 123 | + ); |
| 124 | + // Continue |
| 125 | + return true; |
| 126 | + } |
| 127 | +} |
Property changes on: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.hooks.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 128 | + native |
Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js |
— | — | @@ -0,0 +1,210 @@ |
| 2 | +/* JavaScript for EditToolbar extension */ |
| 3 | + |
| 4 | +/** |
| 5 | + * Prototype for global editToolbar object |
| 6 | + * @param {String} toolbarSelector jQuery compatible selector of toolbar div |
| 7 | + */ |
| 8 | +function EditToolbar( toolbarSelector ) { |
| 9 | + |
| 10 | + /* Private Members */ |
| 11 | + |
| 12 | + // Reference to object's self |
| 13 | + var self = this; |
| 14 | + // Reference to DIV container object (set on initialize) |
| 15 | + var toolbarDiv = null; |
| 16 | + // Sections (main and subs), groups and buttons |
| 17 | + var tools = { main: {}, subs: {} }; |
| 18 | + // Internationalized user interface messages |
| 19 | + var messages = {}; |
| 20 | + |
| 21 | + /* Functions */ |
| 22 | + |
| 23 | + /** |
| 24 | + * Initializes the toolbar user interface |
| 25 | + */ |
| 26 | + this.initialize = function() { |
| 27 | + // Path to images (THIS WILL HAVE TO CHANGE IF YOU MOVE THIS INTO CORE) |
| 28 | + var imagePath = wgScriptPath + |
| 29 | + '/extensions/UsabilityInitiative/EditToolbar/images/'; |
| 30 | + // Gets object handle for container |
| 31 | + toolbarDiv = $( toolbarSelector ); |
| 32 | + // Checks if the toolbar div existed |
| 33 | + if ( toolbarDiv ) { |
| 34 | + // Loops over each main group |
| 35 | + for ( group in tools.main ) { |
| 36 | + // Creates tool group |
| 37 | + var groupDiv = $( '<div class="group"></div>' ); |
| 38 | + // Appends group to toolbar |
| 39 | + groupDiv.appendTo( toolbarDiv ); |
| 40 | + for ( tool in tools.main[group] ) { |
| 41 | + // Creates tool |
| 42 | + var toolImg = $( '<img />' ); |
| 43 | + // Appends tool to group |
| 44 | + toolImg.appendTo( groupDiv ); |
| 45 | + // Customizes the tool |
| 46 | + toolImg.attr({ |
| 47 | + src: imagePath + tools.main[group][tool].icon, |
| 48 | + alt: messages[group + '-' + tool], |
| 49 | + title: messages[group + '-' + tool] |
| 50 | + }); |
| 51 | + // Sets button action |
| 52 | + toolImg.click( tools.main[group][tool].action ); |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * Adds a tool to the toolbar |
| 60 | + * @param {String} section ID of section to add tool to |
| 61 | + * @param {String} group ID of group to add tool to |
| 62 | + * @param {String} tool ID of tool to add |
| 63 | + * @param {Object} configuration Object of configuration for tool |
| 64 | + */ |
| 65 | + this.addTool = function( section, group, tool, configuration ) { |
| 66 | + // Checks if the section is valid |
| 67 | + if ( section in tools ) { |
| 68 | + // Checks if the group doesn't exist in the section |
| 69 | + if ( !( group in tools[section] ) ) { |
| 70 | + // Adds the group to the section |
| 71 | + tools[section][group] = {}; |
| 72 | + } |
| 73 | + // Checks if the tool doesn't exist in the group |
| 74 | + if ( !( tool in tools[section][group] ) ) { |
| 75 | + // Adds tool and configuration to group |
| 76 | + tools[section][group][tool] = configuration; |
| 77 | + } |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * Sets several user interface messages |
| 83 | + * @param {Object} messageList List of key/value pairs of messages |
| 84 | + */ |
| 85 | + this.setMessages = function( messageList ) { |
| 86 | + for ( messageItem in messageList ) { |
| 87 | + messages[messageItem] = messageList[messageItem]; |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * Sets a user interface message |
| 93 | + * @param {String} key Key of message |
| 94 | + * @param {String} value Value of message |
| 95 | + */ |
| 96 | + this.setMessage = function( key, value ) { |
| 97 | + messages[key] = value; |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * Gets a user interface message |
| 102 | + * @param {String} key Key of message |
| 103 | + */ |
| 104 | + this.getMessage = function( key ) { |
| 105 | + if ( key in messages ) { |
| 106 | + return messages[key]; |
| 107 | + } else { |
| 108 | + return key; |
| 109 | + } |
| 110 | + } |
| 111 | + |
| 112 | + /** |
| 113 | + * Performs the action associated with a tool |
| 114 | + * @param {String} section ID of section of tool to use |
| 115 | + * @param {String} group ID of group of tool to use |
| 116 | + * @param {String} tool ID of tool to use |
| 117 | + */ |
| 118 | + this.useTool = function( section, group, tool ) { |
| 119 | + // Checks if the tool exists |
| 120 | + if ( tool in tools[section][group] ) { |
| 121 | + // Adds tool and configuration to group |
| 122 | + tools[section][group][tool].action(); |
| 123 | + } |
| 124 | + } |
| 125 | +} |
| 126 | + |
| 127 | +// Creates global toolbar object |
| 128 | +var editToolbar = new EditToolbar( '#edittoolbar' ); |
| 129 | +// Executes function when document is ready |
| 130 | +$( document ).ready( function() { |
| 131 | + // Initializes edit toolbar |
| 132 | + editToolbar.initialize(); |
| 133 | +}); |
| 134 | + |
| 135 | +/** |
| 136 | + * This is a problem for internationalization - so clearly this will be moved |
| 137 | + * or restructured at some point. |
| 138 | + */ |
| 139 | +// Adds tools to toolbar |
| 140 | +editToolbar.addTool( |
| 141 | + 'main', 'format', 'bold', |
| 142 | + { |
| 143 | + icon: 'format-bold.png', |
| 144 | + action: function() { |
| 145 | + $( '#wpTextbox1' ).encapsulateSelection( |
| 146 | + "'''", null, editToolbar.getMessage( 'format-bold-example' ) |
| 147 | + ); |
| 148 | + return false; |
| 149 | + } |
| 150 | + } |
| 151 | +); |
| 152 | +editToolbar.addTool( |
| 153 | + 'main', 'format', 'italic', |
| 154 | + { |
| 155 | + icon: 'format-italic.png', |
| 156 | + action: function() { |
| 157 | + $( '#wpTextbox1' ).encapsulateSelection( |
| 158 | + "''", null, editToolbar.getMessage( 'format-italic-example' ) |
| 159 | + ); |
| 160 | + return false; |
| 161 | + } |
| 162 | + } |
| 163 | +); |
| 164 | +editToolbar.addTool( |
| 165 | + 'main', 'insert', 'ilink', |
| 166 | + { |
| 167 | + icon: 'insert-ilink.png', |
| 168 | + action: function() { |
| 169 | + $( '#wpTextbox1' ).encapsulateSelection( |
| 170 | + '[[', ']]', editToolbar.getMessage( 'insert-ilink-example' ) |
| 171 | + ); |
| 172 | + return false; |
| 173 | + } |
| 174 | + } |
| 175 | +); |
| 176 | +editToolbar.addTool( |
| 177 | + 'main', 'insert', 'xlink', |
| 178 | + { |
| 179 | + icon: 'insert-xlink.png', |
| 180 | + action: function() { |
| 181 | + $( '#wpTextbox1' ).encapsulateSelection( |
| 182 | + '[', ']', editToolbar.getMessage( 'insert-xlink-example' ) |
| 183 | + ); |
| 184 | + return false; |
| 185 | + } |
| 186 | + } |
| 187 | +); |
| 188 | +editToolbar.addTool( |
| 189 | + 'main', 'insert', 'image', |
| 190 | + { |
| 191 | + icon: 'insert-image.png', |
| 192 | + action: function() { |
| 193 | + $( '#wpTextbox1' ).encapsulateSelection( |
| 194 | + '[[File:', ']]', editToolbar.getMessage( 'insert-image-example' ) |
| 195 | + ); |
| 196 | + return false; |
| 197 | + } |
| 198 | + } |
| 199 | +); |
| 200 | +editToolbar.addTool( |
| 201 | + 'main', 'insert', 'reference', |
| 202 | + { |
| 203 | + icon: 'insert-reference.png', |
| 204 | + action: function() { |
| 205 | + $( '#wpTextbox1' ).encapsulateSelection( |
| 206 | + '<ref>', '</ref>', editToolbar.getMessage( 'insert-reference-example' ) |
| 207 | + ); |
| 208 | + return false; |
| 209 | + } |
| 210 | + } |
| 211 | +); |
\ No newline at end of file |
Property changes on: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 212 | + native |
Index: trunk/extensions/UsabilityInitiative/EditToolbar/images/insert-reference.png |
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes on: trunk/extensions/UsabilityInitiative/EditToolbar/images/insert-reference.png |
___________________________________________________________________ |
Added: svn:mime-type |
2 | 213 | + application/octet-stream |
Index: trunk/extensions/UsabilityInitiative/EditToolbar/images/insert-image.png |
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes on: trunk/extensions/UsabilityInitiative/EditToolbar/images/insert-image.png |
___________________________________________________________________ |
Added: svn:mime-type |
3 | 214 | + application/octet-stream |
Index: trunk/extensions/UsabilityInitiative/EditToolbar/images/format-bold.png |
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes on: trunk/extensions/UsabilityInitiative/EditToolbar/images/format-bold.png |
___________________________________________________________________ |
Added: svn:mime-type |
4 | 215 | + application/octet-stream |
Index: trunk/extensions/UsabilityInitiative/EditToolbar/images/insert-xlink.png |
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes on: trunk/extensions/UsabilityInitiative/EditToolbar/images/insert-xlink.png |
___________________________________________________________________ |
Added: svn:mime-type |
5 | 216 | + application/octet-stream |
Index: trunk/extensions/UsabilityInitiative/EditToolbar/images/insert-ilink.png |
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes on: trunk/extensions/UsabilityInitiative/EditToolbar/images/insert-ilink.png |
___________________________________________________________________ |
Added: svn:mime-type |
6 | 217 | + application/octet-stream |
Index: trunk/extensions/UsabilityInitiative/EditToolbar/images/format-italic.png |
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes on: trunk/extensions/UsabilityInitiative/EditToolbar/images/format-italic.png |
___________________________________________________________________ |
Added: svn:mime-type |
7 | 218 | + application/octet-stream |
Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.i18n.php |
— | — | @@ -0,0 +1,30 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Internationalisation for Usability Initiative Editing Toolbar 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 | + 'edittoolbar' => 'Editing Toolbar', |
| 17 | + 'edittoolbar-desc' => 'Edit page toolbar with enhanced usability', |
| 18 | + 'edittoolbar-preference' => 'Enable enhanced editing toolbar', |
| 19 | + 'edittoolbar-format-bold' => 'Bold', |
| 20 | + 'edittoolbar-format-bold-example' => 'Bold text', |
| 21 | + 'edittoolbar-format-italic' => 'Italic', |
| 22 | + 'edittoolbar-format-italic-example' => 'Italic text', |
| 23 | + 'edittoolbar-insert-ilink' => 'Internal link', |
| 24 | + 'edittoolbar-insert-ilink-example' => 'Link title', |
| 25 | + 'edittoolbar-insert-xlink' => 'External link (remember http:// prefix)', |
| 26 | + 'edittoolbar-insert-xlink-example' => 'http://www.example.com link title', |
| 27 | + 'edittoolbar-insert-image' => 'Embedded file', |
| 28 | + 'edittoolbar-insert-image-example' => 'File:Example.jpg', |
| 29 | + 'edittoolbar-insert-reference' => 'Insert a reference', |
| 30 | + 'edittoolbar-insert-reference-example' => 'Insert footnote text here', |
| 31 | +); |
Property changes on: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.i18n.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 32 | + native |
Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.php |
— | — | @@ -0,0 +1,51 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Usability Initiative EditToolbar extension |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + * |
| 9 | + * This file contains the include file for the EditToolbar portion of the |
| 10 | + * UsabilityInitiative extension of MediaWiki. |
| 11 | + * |
| 12 | + * Usage: This file is included automatically by ../UsabilityInitiative.php |
| 13 | + * |
| 14 | + * @author Trevor Parscal <tparscal@wikimedia.org> |
| 15 | + * Allow "or a later version" here? |
| 16 | + * @license GPL v2 |
| 17 | + * @version 0.1.1 |
| 18 | + */ |
| 19 | + |
| 20 | +// Shortcut to this extension directory |
| 21 | +$dir = dirname( __FILE__ ) . '/'; |
| 22 | + |
| 23 | +// Credits |
| 24 | +$wgExtensionCredits['other'][] = array( |
| 25 | + 'path' => __FILE__, |
| 26 | + 'name' => 'EditToolbar', |
| 27 | + 'author' => 'Trevor Parscal', |
| 28 | + 'version' => '0.1.1', |
| 29 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:UsabilityInitiative', |
| 30 | + 'descriptionmsg' => 'toolbar-desc', |
| 31 | +); |
| 32 | + |
| 33 | +// Bump the version number every time you change any of the .css/.js files |
| 34 | +$wgEditToolbarStyleVersion = 0; |
| 35 | + |
| 36 | +// Autoload Classes |
| 37 | +$wgAutoloadClasses['EditToolbarHooks'] = $dir . 'EditToolbar.hooks.php'; |
| 38 | + |
| 39 | +// Internationalization |
| 40 | +$wgExtensionMessagesFiles['EditToolbar'] = $dir . 'EditToolbar.i18n.php'; |
| 41 | + |
| 42 | +// Register toolbar interception |
| 43 | +$wgHooks['EditPageBeforeEditToolbar'][] = 'EditToolbarHooks::intercept'; |
| 44 | + |
| 45 | +// Register preferences customization |
| 46 | +$wgHooks['GetPreferences'][] = 'EditToolbarHooks::addPreferences'; |
| 47 | + |
| 48 | +// Register ajax add script hook |
| 49 | +$wgHooks['AjaxAddScript'][] = 'EditToolbarHooks::addJS'; |
| 50 | + |
| 51 | +// Register css add script hook |
| 52 | +$wgHooks['BeforePageDisplay'][] = 'EditToolbarHooks::addCSS'; |
Property changes on: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 53 | + native |