Revision: 46292
Author:   werdna
Date:     2009-01-26 22:30:42 +0000 (Mon, 26 Jan 2009)

Log Message:
-----------
Don't save duplicate revisions...

Modified Paths:
--------------
    trunk/extensions/AbuseFilter/Views/AbuseFilterViewEdit.php

Modified: trunk/extensions/AbuseFilter/Views/AbuseFilterViewEdit.php
===================================================================
--- trunk/extensions/AbuseFilter/Views/AbuseFilterViewEdit.php  2009-01-26 
21:56:05 UTC (rev 46291)
+++ trunk/extensions/AbuseFilter/Views/AbuseFilterViewEdit.php  2009-01-26 
22:30:42 UTC (rev 46292)
@@ -34,6 +34,13 @@
 
                        list ($newRow, $actions) = $this->loadRequest($filter);
 
+                       $differences = $this->compareVersions( array($newRow, 
$actions), array( $newRow->mOriginalRow, $newRow->mOriginalActions ) );
+
+                       if (!count($differences)) {
+                               $wgOut->redirect( 
$this->getTitle()->getLocalURL() );
+                               return;
+                       }
+
                        $newRow = get_object_vars($newRow); // Convert from 
object to array
 
                        // Set last modifier.
@@ -360,6 +367,40 @@
                return array( $row, $actions );
        }
 
+       /** Each version is expected to be an array( $row, $actions )
+           Returns an array of fields that are different.*/
+       function compareVersions( $version_1, $version_2 ) {
+               $compareFields = array( 'af_public_comments', 'af_pattern', 
'af_comments', 'af_deleted', 'af_enabled', 'af_hidden' );
+               $differences = array();
+
+               list($row1, $actions1) = $version_1;
+               list($row2, $actions2) = $version_2;
+
+               foreach( $compareFields as $field ) {
+                       if ($row1->$field != $row2->$field) {
+                               $differences[] = $field;
+                       }
+               }
+
+               global $wgAbuseFilterAvailableActions;
+               foreach( $wgAbuseFilterAvailableActions as $action ) {
+                       if ( !isset($actions1[$action]) && !isset( 
$actions2[$action] ) ) {
+                               // They're both unset
+                       } elseif ( isset($actions1[$action]) && isset( 
$actions2[$action] ) ) {
+                               // They're both set.
+                               if ( array_diff( 
$actions1[$action]['parameters'], $actions2[$action]['parameters'] ) ) {
+                                       // Different parameters
+                                       $differences[] = 'actions';
+                               }
+                       } else {
+                               // One's unset, one's set.
+                               $differences[] = 'actions';
+                       }
+               }
+
+               return array_unique( $differences );
+       }
+
        function loadRequest( $filter, $history_id = null ) {
                static $row = null;
                static $actions = null;
@@ -376,8 +417,11 @@
                }
 
                // We need some details like last editor
-               list($row) = $this->loadFilterData( $filter );
+               list($row,$origActions) = $this->loadFilterData( $filter );
 
+               $row->mOriginalRow = clone $row;
+               $row->mOriginalActions = $origActions;
+
                $textLoads = array( 'af_public_comments' => 
'wpFilterDescription', 'af_pattern' => 'wpFilterRules', 'af_comments' => 
'wpFilterNotes' );
 
                foreach( $textLoads as $col => $field ) {



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

Reply via email to