Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.php |
— | — | @@ -28,16 +28,14 @@ |
29 | 29 | 'descriptionmsg' => 'usabilityinitiative-desc', |
30 | 30 | ); |
31 | 31 | |
32 | | -// Shortcut to this extension directory |
33 | | -$dir = dirname( __FILE__ ); |
34 | | - |
35 | 32 | // Autoload Classes |
36 | | -$wgAutoloadClasses['UsabilityInitiativeHooks'] = "$dir/UsabilityInitiative.hooks.php"; |
37 | | -$wgExtensionMessagesFiles['UsabilityInitiative'] = "$dir/UsabilityInitiative.i18n.php"; |
| 33 | +$wgAutoloadClasses['UsabilityInitiativeHooks'] = dirname(__FILE__) . "/UsabilityInitiative.hooks.php"; |
| 34 | +$wgExtensionMessagesFiles['UsabilityInitiative'] = dirname(__FILE__) . "/UsabilityInitiative.i18n.php"; |
38 | 35 | |
39 | 36 | // Register ajax add script hook |
40 | 37 | $wgHooks['AjaxAddScript'][] = 'UsabilityInitiativeHooks::addJS'; |
41 | 38 | |
42 | 39 | /* Components */ |
43 | 40 | |
44 | | -require_once( "$dir/EditToolbar/EditToolbar.php" ); |
| 41 | +require_once( dirname(__FILE__) . "/EditToolbar/EditToolbar.php" ); |
| 42 | +require_once( dirname(__FILE__) . "/EditWarning/EditWarning.php" ); |
Index: trunk/extensions/UsabilityInitiative/EditWarning/EditWarning.i18n.php |
— | — | @@ -0,0 +1,18 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Internationalisation for Usability Initiative EditWarning extension |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + */ |
| 9 | + |
| 10 | +$messages = array(); |
| 11 | + |
| 12 | +/** English |
| 13 | + * @author Roan Kattouw |
| 14 | + */ |
| 15 | +$messages['en'] = array( |
| 16 | + 'editwarning' => 'Edit warning', |
| 17 | + 'editwarning-desc' => 'Show a warning when a user tries to leave the edit form without saving', |
| 18 | + 'editwarning-warning' => 'You have unsaved changes. Click OK to leave this page and destroy your changes, or Cancel to stay here and keep them.', |
| 19 | +); |
Property changes on: trunk/extensions/UsabilityInitiative/EditWarning/EditWarning.i18n.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 20 | + native |
Index: trunk/extensions/UsabilityInitiative/EditWarning/EditWarning.php |
— | — | @@ -0,0 +1,41 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Usability Initiative EditWarning extension |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + * |
| 9 | + * This file contains the include file for the EditWarning portion of the |
| 10 | + * UsabilityInitiative extension of MediaWiki. |
| 11 | + * |
| 12 | + * Usage: This file is included automatically by ../UsabilityInitiative.php |
| 13 | + * |
| 14 | + * @author Roan Kattouw <roan.kattouw@gmail.com> |
| 15 | + * @license GPL v2 or later |
| 16 | + * @version 0.1.1 |
| 17 | + */ |
| 18 | + |
| 19 | +// Shortcut to this extension directory |
| 20 | +$dir = dirname( __FILE__ ) . '/'; |
| 21 | + |
| 22 | +// Credits |
| 23 | +$wgExtensionCredits['other'][] = array( |
| 24 | + 'path' => __FILE__, |
| 25 | + 'name' => 'EditWarning', |
| 26 | + 'author' => 'Roan Kattouw', |
| 27 | + 'version' => '0.1.1', |
| 28 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:UsabilityInitiative', |
| 29 | + 'descriptionmsg' => 'editwarning-desc', |
| 30 | +); |
| 31 | + |
| 32 | +// Bump the version number every time you change any of the .css/.js files |
| 33 | +$wgEditWarningStyleVersion = 0; |
| 34 | + |
| 35 | +// Autoload Classes |
| 36 | +$wgAutoloadClasses['EditWarningHooks'] = $dir . 'EditWarning.hooks.php'; |
| 37 | + |
| 38 | +// Internationalization |
| 39 | +$wgExtensionMessagesFiles['EditWarning'] = $dir . 'EditWarning.i18n.php'; |
| 40 | + |
| 41 | +// Register ajax add script hook |
| 42 | +$wgHooks['AjaxAddScript'][] = 'EditWarningHooks::addJS'; |
Property changes on: trunk/extensions/UsabilityInitiative/EditWarning/EditWarning.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 43 | + native |
Index: trunk/extensions/UsabilityInitiative/EditWarning/EditWarning.hooks.php |
— | — | @@ -0,0 +1,38 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Hooks for Usability Initiative EditWarning extension |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + */ |
| 9 | + |
| 10 | +class EditWarningHooks { |
| 11 | + /** |
| 12 | + * AjaxAddScript hook |
| 13 | + * Add ajax support script |
| 14 | + */ |
| 15 | + public static function addJS( $out ) { |
| 16 | + global $wgScriptPath, $wgJsMimeType, $wgEditWarningStyleVersion; |
| 17 | + // Add javascript resources to document |
| 18 | + $out->addScript( |
| 19 | + Xml::element( |
| 20 | + 'script', |
| 21 | + array( |
| 22 | + 'type' => $wgJsMimeType, |
| 23 | + 'src' => $wgScriptPath . |
| 24 | + '/extensions/UsabilityInitiative/EditWarning/EditWarning.js?' . |
| 25 | + $wgEditWarningStyleVersion |
| 26 | + ), |
| 27 | + '', |
| 28 | + false |
| 29 | + ) |
| 30 | + ); |
| 31 | + wfLoadExtensionMessages( 'EditWarning' ); |
| 32 | + $key = Xml::escapeJsString( 'editwarning-warning' ); |
| 33 | + $value = Xml::escapeJsString( wfMsg( 'editwarning-warning' ) ); |
| 34 | + $messagesList = "'$key': '$value'"; |
| 35 | + $out->addInlineScript("loadGM({{$messagesList}});"); |
| 36 | + // Continue |
| 37 | + return true; |
| 38 | + } |
| 39 | +} |
Property changes on: trunk/extensions/UsabilityInitiative/EditWarning/EditWarning.hooks.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 40 | + native |
Index: trunk/extensions/UsabilityInitiative/EditWarning/EditWarning.js |
— | — | @@ -0,0 +1,57 @@ |
| 2 | +/* JavaScript for EditToolbar extension */ |
| 3 | + |
| 4 | +/** |
| 5 | + * This is designed to be directly compatible with (and is essentially taken |
| 6 | + * directly from) the mv_embed code for bringing internationalized messages into |
| 7 | + * the JavaScript space. As such, if we get to the point of merging that stuff |
| 8 | + * into the main branch this code will be uneeded and probably cause issues. |
| 9 | + */ |
| 10 | +// Creates global message object if not already in existence |
| 11 | +if ( !gMsg ) var gMsg = {}; |
| 12 | +/** |
| 13 | + * Caches a list of messages for later retrieval |
| 14 | + * @param {Object} msgSet Hash of key:value pairs of messages to cache |
| 15 | + */ |
| 16 | +function loadGM( msgSet ){ |
| 17 | + for ( var i in msgSet ){ |
| 18 | + gMsg[ i ] = msgSet[i]; |
| 19 | + } |
| 20 | +} |
| 21 | +/** |
| 22 | + * Retieves a message from the global message cache, performing on-the-fly |
| 23 | + * replacements using MediaWiki message syntax ($1, $2, etc.) |
| 24 | + * @param {String} key Name of message as it is in MediaWiki |
| 25 | + * @param {Array} args Array of replacement arguments |
| 26 | + */ |
| 27 | +function gM( key, args ) { |
| 28 | + var ms = ''; |
| 29 | + if ( key in gMsg ) { |
| 30 | + ms = gMsg[ key ]; |
| 31 | + if ( typeof args == 'object' || typeof args == 'array' ) { |
| 32 | + for ( var v in args ){ |
| 33 | + var rep = '\$'+ ( parseInt(v) + 1 ); |
| 34 | + ms = ms.replace( rep, args[v]); |
| 35 | + } |
| 36 | + } else if ( typeof args =='string' || typeof args =='number' ) { |
| 37 | + ms = ms.replace( /\$1/, args ); |
| 38 | + } |
| 39 | + return ms; |
| 40 | + } else { |
| 41 | + return '[' + key + ']'; |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +function editWarningSetWarning() { |
| 46 | + $(window).bind('beforeunload', function(event) { |
| 47 | + if(!confirm(gM('editwarning-warning'))) |
| 48 | + event.preventDefault(); |
| 49 | + event.stopImmediatePropagation(); |
| 50 | + }); |
| 51 | +} |
| 52 | + |
| 53 | +$(document).ready(function() { |
| 54 | + $('#wpTextbox1').change(editWarningSetWarning) |
| 55 | + .bind('paste', editWarningSetWarning); |
| 56 | + $('#wpSummary').change(editWarningSetWarning) |
| 57 | + .bind('paste', editWarningSetWarning); |
| 58 | +}); |
Property changes on: trunk/extensions/UsabilityInitiative/EditWarning/EditWarning.js |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 59 | + native |