https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114865

Revision: 114865
Author:   petrb
Date:     2012-04-12 12:35:05 +0000 (Thu, 12 Apr 2012)
Log Message:
-----------
- New option to allow bypass check for user input and save the backup even if 
user is changing text
- Adjusted the timeout for slow connections, previous value was too low

Modified Paths:
--------------
    trunk/extensions/Drafts/Drafts.hooks.php
    trunk/extensions/Drafts/Drafts.js
    trunk/extensions/Drafts/Drafts.php

Modified: trunk/extensions/Drafts/Drafts.hooks.php
===================================================================
--- trunk/extensions/Drafts/Drafts.hooks.php    2012-04-12 09:48:42 UTC (rev 
114864)
+++ trunk/extensions/Drafts/Drafts.hooks.php    2012-04-12 12:35:05 UTC (rev 
114865)
@@ -170,7 +170,7 @@
         */
        public static function controls( $editpage, $buttons ) {
                global $wgUser, $wgTitle, $wgRequest;
-               global $egDraftsAutoSaveWait, $egDraftsAutoSaveTimeout;
+               global $egDraftsAutoSaveWait, $egDraftsAutoSaveTimeout, 
$egDraftsAutoSaveInputBased;
                // Check permissions
                if ( $wgUser->isAllowed( 'edit' ) && $wgUser->isLoggedIn() ) {
                        // Internationalization
@@ -224,6 +224,13 @@
                        $buttons['savedraft'] .= Xml::element( 'input',
                                array(
                                        'type' => 'hidden',
+                                       'name' => 'wpDraftAutoSaveInputBased',
+                                       'value' => $egDraftsAutoSaveInputBased
+                               )
+                       );
+                       $buttons['savedraft'] .= Xml::element( 'input',
+                               array(
+                                       'type' => 'hidden',
                                        'name' => 'wpDraftAutoSaveTimeout',
                                        'value' => $egDraftsAutoSaveTimeout
                                )

Modified: trunk/extensions/Drafts/Drafts.js
===================================================================
--- trunk/extensions/Drafts/Drafts.js   2012-04-12 09:48:42 UTC (rev 114864)
+++ trunk/extensions/Drafts/Drafts.js   2012-04-12 12:35:05 UTC (rev 114865)
@@ -110,7 +110,20 @@
        this.change = function() {
                // Sets state to changed
                self.setState( 'changed' );
-               // Checks if timer is pending
+               // Checks if timer is pending and if we want to wait for user 
input
+               if ( !configuration.autoSaveBasedOnInput ) {
+                       if ( timer ) {
+                               return;
+                       }
+                       if ( configuration.autoSaveWait && 
configuration.autoSaveWait > 0 ) {
+                               // Sets timer to save automatically after a 
period of time
+                               timer = setTimeout(
+                                       'wgDraft.save()', 
configuration.autoSaveWait * 1000
+                               );
+                       }
+                       return;
+               }
+
                if ( timer ) {
                        // Clears pending timer
                        clearTimeout( timer );
@@ -149,7 +162,8 @@
                        // Gets configured specific values
                        configuration = {
                                autoSaveWait: form.wpDraftAutoSaveWait.value,
-                               autoSaveTimeout: 
form.wpDraftAutoSaveTimeout.value
+                               autoSaveTimeout: 
form.wpDraftAutoSaveTimeout.value,
+                               autoSaveBasedOnInput: 
form.wpDraftAutoSaveInputBased.value
                        };
                        // Gets language-specific messages
                        messages = {

Modified: trunk/extensions/Drafts/Drafts.php
===================================================================
--- trunk/extensions/Drafts/Drafts.php  2012-04-12 09:48:42 UTC (rev 114864)
+++ trunk/extensions/Drafts/Drafts.php  2012-04-12 12:35:05 UTC (rev 114865)
@@ -12,6 +12,7 @@
  * require_once( "$IP/extensions/Drafts/Drafts.php" );
  *
  * @author Trevor Parscal <[email protected]>
+ * @author enhanced by Petr Bena <[email protected]>
  * @license GPL v2
  * @version 0.1.0
  */
@@ -28,7 +29,7 @@
 $wgExtensionCredits['other'][] = array(
        'path' => __FILE__,
        'name' => 'Drafts',
-       'version' => '0.1.0',
+       'version' => '0.1.1',
        'author' => 'Trevor Parscal',
        'url' => 'https://www.mediawiki.org/wiki/Extension:Drafts',
        'descriptionmsg' => 'drafts-desc',
@@ -44,9 +45,12 @@
 // Use the value 0 to disable autosave
 $egDraftsAutoSaveWait = 120;
 
+// Enable auto save only if user stop typing (less auto saves, but much worse 
recovery ability)
+$egDraftsAutoSaveInputBased = false;
+
 // Seconds to wait until giving up on a response from the server
 // Use the value 0 to disable autosave
-$egDraftsAutoSaveTimeout = 10;
+$egDraftsAutoSaveTimeout = 20;
 
 // Days to keep drafts around before automatic deletion. Set to 0 to keep 
forever.
 $egDraftsLifeSpan = 30;


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to