r51658 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51657‎ | r51658 | r51659 >
Date:19:10, 9 June 2009
Author:catrope
Status:deferred
Tags:
Comment:
UsabilityInitiative: Add EditWarning extension that warns users when they try to navigate away from the edit form without saving their changes
Modified paths:
  • /trunk/extensions/UsabilityInitiative/EditWarning (added) (history)
  • /trunk/extensions/UsabilityInitiative/EditWarning/EditWarning.hooks.php (added) (history)
  • /trunk/extensions/UsabilityInitiative/EditWarning/EditWarning.i18n.php (added) (history)
  • /trunk/extensions/UsabilityInitiative/EditWarning/EditWarning.js (added) (history)
  • /trunk/extensions/UsabilityInitiative/EditWarning/EditWarning.php (added) (history)
  • /trunk/extensions/UsabilityInitiative/UsabilityInitiative.php (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.php
@@ -28,16 +28,14 @@
2929 'descriptionmsg' => 'usabilityinitiative-desc',
3030 );
3131
32 -// Shortcut to this extension directory
33 -$dir = dirname( __FILE__ );
34 -
3532 // 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";
3835
3936 // Register ajax add script hook
4037 $wgHooks['AjaxAddScript'][] = 'UsabilityInitiativeHooks::addJS';
4138
4239 /* Components */
4340
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
120 + 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
143 + 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
140 + 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
159 + native

Status & tagging log