Index: trunk/extensions/FileAttach/FileAttach.php |
— | — | @@ -86,7 +86,7 @@ |
87 | 87 | } |
88 | 88 | |
89 | 89 | /* |
90 | | - * Note if this is the upload form so that we can modify it before page display |
| 90 | + * Note if this is the upload form or warning form so that we can modify it before page display |
91 | 91 | */ |
92 | 92 | function onUploadFormInitial( $form ) { |
93 | 93 | $this->uploadForm = true; |
— | — | @@ -97,26 +97,28 @@ |
98 | 98 | * Check if the upload should attach to an article |
99 | 99 | */ |
100 | 100 | function onUploadFormBeforeProcessing( $form ) { |
101 | | - global $wgRequest, $wgAttachmentHeading, $wgHooks; |
| 101 | + global $wgRequest, $wgHooks; |
102 | 102 | if( $attachto = $wgRequest->getText( 'attachto', '' ) ) { |
103 | | - $filename = $wgRequest->getText( 'wpDestFile' ); |
| 103 | + $this->uploadForm = true; |
104 | 104 | $title = Title::newFromText( $attachto ); |
105 | | - $this->attachto = $article = new Article( $title ); |
106 | | - $text = preg_replace( "|(\s+==\s*$wgAttachmentHeading\s*==)\s+|s", "$1\n*[[:File:$filename]]\n", $article->getContent(), 1, $count ); |
107 | | - if( $count == 0 ) $text .= "\n\n== $wgAttachmentHeading ==\n*[[:File:$filename]]\n"; |
108 | | - $article->doEdit( $text, wfMsg( 'fileattach-editcomment', $filename ), EDIT_UPDATE ); |
| 105 | + $this->attachto = new Article( $title ); |
109 | 106 | $wgHooks['SpecialUploadComplete'][] = $this; |
110 | 107 | } |
111 | 108 | return true; |
112 | 109 | } |
113 | 110 | |
114 | 111 | /* |
115 | | - * Change the redirection after upload to the page the file attached to |
| 112 | + * Change the redirection after upload to the page the file attached to, |
| 113 | + * and attach the file to the article |
116 | 114 | */ |
117 | 115 | function onSpecialUploadComplete( $upload ) { |
118 | | - global $wgOut; |
| 116 | + global $wgOut, $wgRequest, $wgAttachmentHeading; |
119 | 117 | $this->wgOut = $wgOut; |
120 | 118 | $wgOut = new FileAttachDummyOutput; |
| 119 | + $filename = $wgRequest->getText( 'wpDestFile' ); |
| 120 | + $text = preg_replace( "|(\s+==\s*$wgAttachmentHeading\s*==)\s+|s", "$1\n*[[:File:$filename]]\n", $this->attachto->getContent(), 1, $count ); |
| 121 | + if( $count == 0 ) $text .= "\n\n== $wgAttachmentHeading ==\n*[[:File:$filename]]\n"; |
| 122 | + $this->attachto->doEdit( $text, wfMsg( 'fileattach-editcomment', $filename ), EDIT_UPDATE ); |
121 | 123 | return true; |
122 | 124 | } |
123 | 125 | |