* (bug 13725) Upload form watch checkbox state set correctly with wpDestFile
authorBrion Vibber <brion@users.mediawiki.org>
Tue, 15 Apr 2008 19:02:12 +0000 (19:02 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Tue, 15 Apr 2008 19:02:12 +0000 (19:02 +0000)
r33330 just disabled the check for wpDestFile, so that the 'watch pages i create'
setting would watch *all* uploads. The system now checks the actual value, so
it sets the watch checkbox if the requested file doesn't exist locally and you
have it set for creations, or if you've already got the file watched.

There are still some minor issues:
* Since you have the chance to change the target filename on the form, the
  initial checkbox state can get out of sync if you switch from an empty file
  to an existing file or vice-versa.
* Unlike the edit form, the upload form doesn't _unwatch_ a previously-watched
  page when the box is unchecked.

RELEASE-NOTES
includes/SpecialUpload.php

index 1fbc6c4..381ef63 100644 (file)
@@ -184,6 +184,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 13728) Don't trim initial whitespace during section edits
 * (bug 13727) Don't delete log entries from recentchanges on page deletion
 * (bug 13752) Section redirects now works again
+* (bug 13725) Upload form watch checkbox state set correctly with wpDestFile
+
 
 === API changes in 1.13 ===
 
index 5e79e63..f0a36d6 100644 (file)
@@ -1016,8 +1016,7 @@ wgUploadAutoFill = {$autofill};
 
                $encDestName = htmlspecialchars( $this->mDesiredDestName );
 
-               $watchChecked =
-                       ( $wgUser->getOption( 'watchdefault' ) || $wgUser->getOption( 'watchcreations' ) )
+               $watchChecked = $this->watchCheck()
                        ? 'checked="checked"'
                        : '';
                $warningChecked = $this->mIgnoreWarning ? 'checked' : '';
@@ -1192,6 +1191,35 @@ wgUploadAutoFill = {$autofill};
        }
 
        /* -------------------------------------------------------------- */
+       
+       /**
+        * See if we should check the 'watch this page' checkbox on the form
+        * based on the user's preferences and whether we're being asked
+        * to create a new file or update an existing one.
+        *
+        * In the case where 'watch edits' is off but 'watch creations' is on,
+        * we'll leave the box unchecked.
+        *
+        * Note that the page target can be changed *on the form*, so our check
+        * state can get out of sync.
+        */
+       function watchCheck() {
+               global $wgUser;
+               if( $wgUser->getOption( 'watchdefault' ) ) {
+                       // Watch all edits!
+                       return true;
+               }
+               
+               $local = wfLocalFile( $this->mDesiredDestName );
+               if( $local && $local->exists() ) {
+                       // We're uploading a new version of an existing file.
+                       // No creation, so don't watch it if we're not already.
+                       return $local->getTitle()->userIsWatching();
+               } else {
+                       // New page should get watched if that's our option.
+                       return $wgUser->getOption( 'watchcreations' );
+               }
+       }
 
        /**
         * Split a file into a base name and all dot-delimited 'extensions'