r86166 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86165‎ | r86166 | r86167 >
Date:01:02, 16 April 2011
Author:nad
Status:resolved (Comments)
Tags:
Comment:
attachment process wasnt working if upload warning happened
Modified paths:
  • /trunk/extensions/FileAttach/FileAttach.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FileAttach/FileAttach.php
@@ -86,7 +86,7 @@
8787 }
8888
8989 /*
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
9191 */
9292 function onUploadFormInitial( $form ) {
9393 $this->uploadForm = true;
@@ -97,26 +97,28 @@
9898 * Check if the upload should attach to an article
9999 */
100100 function onUploadFormBeforeProcessing( $form ) {
101 - global $wgRequest, $wgAttachmentHeading, $wgHooks;
 101+ global $wgRequest, $wgHooks;
102102 if( $attachto = $wgRequest->getText( 'attachto', '' ) ) {
103 - $filename = $wgRequest->getText( 'wpDestFile' );
 103+ $this->uploadForm = true;
104104 $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 );
109106 $wgHooks['SpecialUploadComplete'][] = $this;
110107 }
111108 return true;
112109 }
113110
114111 /*
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
116114 */
117115 function onSpecialUploadComplete( $upload ) {
118 - global $wgOut;
 116+ global $wgOut, $wgRequest, $wgAttachmentHeading;
119117 $this->wgOut = $wgOut;
120118 $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 );
121123 return true;
122124 }
123125

Follow-up revisions

RevisionCommit summaryAuthorDate
r96612Pass second param to article constructor per r86166demon20:12, 8 September 2011

Comments

#Comment by Nikerabbit (talk | contribs)   07:29, 16 April 2011

Always use new Article( $foo, 0 );

+$this->attachto = new Article( $title );

Status & tagging log