Index: trunk/extensions/SemanticForms/specials/SF_UploadWindow.php |
— | — | @@ -5,10 +5,12 @@ |
6 | 6 | * a few changes to remove skin CSS and HTML, and to populate the relevant |
7 | 7 | * field in the form with the name of the uploaded form. |
8 | 8 | * |
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. |
11 | 11 | * |
12 | 12 | * @addtogroup SpecialPage |
| 13 | + * |
| 14 | + * @author Yaron Koren |
13 | 15 | */ |
14 | 16 | if (!defined('MEDIAWIKI')) die(); |
15 | 17 | |
— | — | @@ -21,8 +23,8 @@ |
22 | 24 | * Entry point |
23 | 25 | */ |
24 | 26 | 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; |
27 | 29 | |
28 | 30 | // disable $wgOut - we'll print out the page manually, taking the |
29 | 31 | // body created by the form, plus the necessary Javascript files, |
— | — | @@ -74,6 +76,7 @@ |
75 | 77 | |
76 | 78 | # used by Semantic Forms |
77 | 79 | var $mInputID; |
| 80 | + var $mDelimiter; |
78 | 81 | |
79 | 82 | const SESSION_VERSION = 1; |
80 | 83 | /**#@-*/ |
— | — | @@ -88,7 +91,8 @@ |
89 | 92 | $this->mDesiredDestName = $request->getText( 'wpDestFile' ); |
90 | 93 | $this->mIgnoreWarning = $request->getCheck( 'wpIgnoreWarning' ); |
91 | 94 | $this->mComment = $request->getText( 'wpUploadDescription' ); |
92 | | - $this->mInputID = $request->getText( 'wpInputID' ); |
| 95 | + $this->mInputID = $request->getText( 'sfInputID' ); |
| 96 | + $this->mDelimiter = $request->getText( 'sfDelimiter' ); |
93 | 97 | |
94 | 98 | if( !$request->wasPosted() ) { |
95 | 99 | # GET requests just give the main form; no data except destination |
— | — | @@ -154,7 +158,8 @@ |
155 | 159 | $this->mSessionKey = false; |
156 | 160 | $this->mStashed = false; |
157 | 161 | $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' ); |
159 | 164 | } |
160 | 165 | |
161 | 166 | /** |
— | — | @@ -175,8 +180,6 @@ |
176 | 181 | |
177 | 182 | // PHP won't auto-cleanup the file |
178 | 183 | $this->mRemoveTempFile = file_exists( $local_file ); |
179 | | - // this might not be necessary |
180 | | - $this->mInputID = $request->getText( 'wpInputID' ); |
181 | 184 | } |
182 | 185 | |
183 | 186 | /** |
— | — | @@ -490,11 +493,38 @@ |
491 | 494 | // Success, redirect to description page |
492 | 495 | //$wgOut->redirect( $this->mLocalFile->getTitle()->getFullURL() ); |
493 | 496 | |
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 |
498 | 504 | 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 |
499 | 529 | parent.fb.end(); |
500 | 530 | </script> |
501 | 531 | |
— | — | @@ -775,7 +805,8 @@ |
776 | 806 | <input type='hidden' name='wpLicense' value=\"" . htmlspecialchars( $this->mLicense ) . "\" /> |
777 | 807 | <input type='hidden' name='wpDestFile' value=\"" . htmlspecialchars( $this->mDesiredDestName ) . "\" /> |
778 | 808 | <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 ) . "\" /> |
780 | 811 | {$copyright} |
781 | 812 | <table border='0'> |
782 | 813 | <tr> |
— | — | @@ -1015,7 +1046,8 @@ |
1016 | 1047 | |
1017 | 1048 | </table> |
1018 | 1049 | <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 ) . "\" /> |
1020 | 1052 | </form>" ); |
1021 | 1053 | } |
1022 | 1054 | |