r36261 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r36260‎ | r36261 | r36262 >
Date:15:33, 13 June 2008
Author:yaron
Status:old
Tags:
Comment:
Added handling for fields that contain a list of files, instead of just one
Modified paths:
  • /trunk/extensions/SemanticForms/specials/SF_UploadWindow.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/specials/SF_UploadWindow.php
@@ -5,10 +5,12 @@
66 * a few changes to remove skin CSS and HTML, and to populate the relevant
77 * field in the form with the name of the uploaded form.
88 *
9 - * This class was created by Yaron Koren, and based almost entirely on the
10 - * upload functionality developed by the Chickipedia.com team.
 9+ * This class is based almost entirely on the upload functionality
 10+ * developed by the Chickipedia.com team.
1111 *
1212 * @addtogroup SpecialPage
 13+ *
 14+ * @author Yaron Koren
1315 */
1416 if (!defined('MEDIAWIKI')) die();
1517
@@ -21,8 +23,8 @@
2224 * Entry point
2325 */
2426 function doSpecialUploadWindow() {
25 - global $wgRequest, $wgOut;
26 - global $wgUser, $wgServer, $wgJsMimeType, $wgStylePath, $wgStyleVersion;
 27+ global $wgRequest, $wgOut, $wgUser, $wgServer;
 28+ global $wgScript, $wgJsMimeType, $wgStylePath, $wgStyleVersion;
2729
2830 // disable $wgOut - we'll print out the page manually, taking the
2931 // body created by the form, plus the necessary Javascript files,
@@ -74,6 +76,7 @@
7577
7678 # used by Semantic Forms
7779 var $mInputID;
 80+ var $mDelimiter;
7881
7982 const SESSION_VERSION = 1;
8083 /**#@-*/
@@ -88,7 +91,8 @@
8992 $this->mDesiredDestName = $request->getText( 'wpDestFile' );
9093 $this->mIgnoreWarning = $request->getCheck( 'wpIgnoreWarning' );
9194 $this->mComment = $request->getText( 'wpUploadDescription' );
92 - $this->mInputID = $request->getText( 'wpInputID' );
 95+ $this->mInputID = $request->getText( 'sfInputID' );
 96+ $this->mDelimiter = $request->getText( 'sfDelimiter' );
9397
9498 if( !$request->wasPosted() ) {
9599 # GET requests just give the main form; no data except destination
@@ -154,7 +158,8 @@
155159 $this->mSessionKey = false;
156160 $this->mStashed = false;
157161 $this->mRemoveTempFile = false; // PHP will handle this
158 - $this->mInputID = $request->getText( 'wpInputID' );
 162+ $this->mInputID = $request->getText( 'sfInputID' );
 163+ $this->mDelimiter = $request->getText( 'sfDelimiter' );
159164 }
160165
161166 /**
@@ -175,8 +180,6 @@
176181
177182 // PHP won't auto-cleanup the file
178183 $this->mRemoveTempFile = file_exists( $local_file );
179 - // this might not be necessary
180 - $this->mInputID = $request->getText( 'wpInputID' );
181184 }
182185
183186 /**
@@ -490,11 +493,38 @@
491494 // Success, redirect to description page
492495 //$wgOut->redirect( $this->mLocalFile->getTitle()->getFullURL() );
493496
494 - // Semantic Forms change - output Javascript to fill
495 - // in field in original form, and close the Floatbox
496 - $output =<<<END
497 - <script type="text/javascript">
 497+ // Semantic Forms change - output Javascript to either
 498+ // fill in or append to the field in original form, and
 499+ // close the window
 500+ $basename = str_replace('_', ' ', $basename);
 501+ $output = ' <script type="text/javascript">' . "\n";
 502+ if ($this->mDelimiter == null) {
 503+ $output .=<<<END
498504 parent.document.getElementById("{$this->mInputID}").value = '$basename';
 505+
 506+END;
 507+ } else {
 508+ $output .=<<<END
 509+ // if the current value is blank, set it to this file name;
 510+ // if it's not blank and ends in a space or delimiter, append
 511+ // the file name; if it ends with a normal character, append
 512+ // both a delimiter and a file name; and add on a delimiter
 513+ // at the end in any case
 514+ var cur_value = parent.document.getElementById("{$this->mInputID}").value;
 515+ if (cur_value == '') {
 516+ parent.document.getElementById("{$this->mInputID}").value = '$basename' + '{$this->mDelimiter} ';
 517+ } else {
 518+ var last_char = cur_value.charAt(cur_value.length - 1);
 519+ if (last_char == '{$this->mDelimiter}' || last_char == ' ') {
 520+ parent.document.getElementById("{$this->mInputID}").value += '$basename' + '{$this->mDelimiter} ';
 521+ } else {
 522+ parent.document.getElementById("{$this->mInputID}").value += '{$this->mDelimiter} $basename{$this->mDelimiter} ';
 523+ }
 524+ }
 525+
 526+END;
 527+ }
 528+ $output .=<<<END
499529 parent.fb.end();
500530 </script>
501531
@@ -775,7 +805,8 @@
776806 <input type='hidden' name='wpLicense' value=\"" . htmlspecialchars( $this->mLicense ) . "\" />
777807 <input type='hidden' name='wpDestFile' value=\"" . htmlspecialchars( $this->mDesiredDestName ) . "\" />
778808 <input type='hidden' name='wpWatchthis' value=\"" . htmlspecialchars( intval( $this->mWatchthis ) ) . "\" />
779 - <input type='hidden' name='wpInputID' value=\"" . htmlspecialchars( $this->mInputID ) . "\" />
 809+ <input type='hidden' name='sfInputID' value=\"" . htmlspecialchars( $this->mInputID ) . "\" />
 810+ <input type='hidden' name='sfDelimiter' value=\"" . htmlspecialchars( $this->mInputID ) . "\" />
780811 {$copyright}
781812 <table border='0'>
782813 <tr>
@@ -1015,7 +1046,8 @@
10161047
10171048 </table>
10181049 <input type='hidden' name='wpDestFileWarningAck' id='wpDestFileWarningAck' value=''/>
1019 - <input type='hidden' name='wpInputID' value=\"" . htmlspecialchars( $this->mInputID ) . "\" />
 1050+ <input type='hidden' name='sfInputID' value=\"" . htmlspecialchars( $this->mInputID ) . "\" />
 1051+ <input type='hidden' name='sfDelimiter' value=\"" . htmlspecialchars( $this->mDelimiter ) . "\" />
10201052 </form>" );
10211053 }
10221054

Status & tagging log