r5329 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r5328‎ | r5329 | r5330 >
Date:16:10, 20 September 2004
Author:hashar
Status:old
Tags:
Comment:
comments / single quotes.
Modified paths:
  • /trunk/phase3/includes/SpecialUpload.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SpecialUpload.php
@@ -8,10 +8,10 @@
99 /**
1010 *
1111 */
12 -require_once( "Image.php" );
 12+require_once( 'Image.php' );
1313
1414 /**
15 - * Constructor
 15+ * Entry point
1616 */
1717 function wfSpecialUpload() {
1818 global $wgRequest;
@@ -30,6 +30,11 @@
3131 var $mUploadCopyStatus, $mUploadSource, $mReUpload, $mAction, $mUpload;
3232 var $mOname, $mSessionKey;
3333
 34+ /**
 35+ * Constructor : initialise object
 36+ * Get data POSTed through the form and assign them to the object
 37+ * @param $request Data posted.
 38+ */
3439 function UploadForm( &$request ) {
3540 $this->mUploadAffirm = $request->getVal( 'wpUploadAffirm' );
3641 $this->mUploadFile = $request->getVal( 'wpUploadFile' );
@@ -47,44 +52,58 @@
4853 $this->mUpload = $request->getCheck( 'wpUpload' );
4954 $this->mSessionKey = $request->getVal( 'wpSessionKey' );
5055
 56+ /** Generate a temporary name if we don't have one yet */
5157 if ( ! $this->mUploadTempName ) {
5258 $this->mUploadTempName = $request->getFileTempName( 'wpUploadFile' );
5359 }
 60+
 61+ /** Get size of file */
5462 if ( ! $this->mUploadSize ) {
5563 $this->mUploadSize = $request->getFileSize( 'wpUploadFile' );
5664 }
5765 $this->mOname = $request->getFileName( 'wpUploadFile' );
58 -
5966 }
6067
 68+ /**
 69+ * Start doing stuff
 70+ * @access public
 71+ */
6172 function execute() {
6273 global $wgUser, $wgOut;
6374 global $wgDisableUploads;
6475
 76+ /** Show an error message if file upload is disabled */
6577 if ( $wgDisableUploads ) {
66 - $wgOut->addWikiText( wfMsg( "uploaddisabled" ) );
 78+ $wgOut->addWikiText( wfMsg( 'uploaddisabled' ) );
6779 return;
6880 }
69 - if ( ( 0 == $wgUser->getID() )
70 - or $wgUser->isBlocked() ) {
71 - $wgOut->errorpage( "uploadnologin", "uploadnologintext" );
 81+
 82+ /** Various rights checks */
 83+ if ( ( $wgUser->getID() == 0 )
 84+ OR $wgUser->isBlocked() ) {
 85+ $wgOut->errorpage( 'uploadnologin', 'uploadnologintext' );
7286 return;
7387 }
7488 if ( wfReadOnly() ) {
7589 $wgOut->readOnlyPage();
7690 return;
7791 }
 92+
7893 if ( $this->mReUpload ) {
7994 $this->unsaveUploadedFile();
80 - $this->mainUploadForm( "" );
81 - } else if ( "submit" == $this->mAction || $this->mUpload ) {
 95+ $this->mainUploadForm( '' );
 96+ } else if ( 'submit' == $this->mAction || $this->mUpload ) {
8297 $this->processUpload();
8398 } else {
84 - $this->mainUploadForm( "" );
 99+ $this->mainUploadForm( '' );
85100 }
86101 }
87102
88 -
 103+ /**
 104+ * Really do the upload
 105+ * Checks are made in SpecialUpload::execute()
 106+ * @access private
 107+ */
89108 function processUpload() {
90109 global $wgUser, $wgOut, $wgLang;
91110 global $wgUploadDirectory;
@@ -96,32 +115,32 @@
97116 if ( $wgUseCopyrightUpload ) {
98117 $this->mUploadAffirm = 1;
99118 if ($wgCheckCopyrightUpload &&
100 - (trim ( $this->mUploadCopyStatus ) == "" || trim ( $this->mUploadSource ) == "" )) {
 119+ (trim ( $this->mUploadCopyStatus ) == '' || trim ( $this->mUploadSource ) == '' )) {
101120 $this->mUploadAffirm = 0;
102121 }
103122 }
104123
105 - if ( 1 != $this->mUploadAffirm ) {
106 - $this->mainUploadForm( WfMsg( "noaffirmation" ) );
 124+ if ( $this->mUploadAffirm != 1) {
 125+ $this->mainUploadForm( WfMsg( 'noaffirmation' ) );
107126 return;
108127 }
109128
110 - if ( "" != $this->mOname ) {
111 - $basename = strrchr( $this->mOname, "/" );
 129+ if ( '' != $this->mOname ) {
 130+ $basename = strrchr( $this->mOname, '/' );
112131
113132 if ( false === $basename ) { $basename = $this->mOname; }
114133 else ( $basename = substr( $basename, 1 ) );
115134
116135
117 - $ext = strrchr( $basename, "." );
118 - if ( false === $ext ) { $ext = ""; }
 136+ $ext = strrchr( $basename, '.' );
 137+ if ( false === $ext ) { $ext = ''; }
119138 else { $ext = substr( $ext, 1 ); }
120139
121 - if ( "" == $ext ) { $xl = 0; } else { $xl = strlen( $ext ) + 1; }
 140+ if ( '' == $ext ) { $xl = 0; } else { $xl = strlen( $ext ) + 1; }
122141 $partname = substr( $basename, 0, strlen( $basename ) - $xl );
123142
124143 if ( strlen( $partname ) < 3 ) {
125 - $this->mainUploadForm( WfMsg( "minlength" ) );
 144+ $this->mainUploadForm( WfMsg( 'minlength' ) );
126145 return;
127146 }
128147
@@ -136,7 +155,7 @@
137156
138157 $nt = Title::newFromText( $basename );
139158 if( !$nt ) {
140 - return $this->uploadError( wfMsg( "illegalfilename", htmlspecialchars( $basename ) ) );
 159+ return $this->uploadError( wfMsg( 'illegalfilename', htmlspecialchars( $basename ) ) );
141160 }
142161 $nt->setNamespace( Namespace::getImage() );
143162 $this->mUploadSaveName = $nt->getDBkey();
@@ -144,36 +163,36 @@
145164 /* Don't allow users to override the blacklist */
146165 if( $this->checkFileExtension( $ext, $wgFileBlacklist ) ||
147166 ($wgStrictFileExtensions && !$this->checkFileExtension( $ext, $wgFileExtensions ) ) ) {
148 - return $this->uploadError( wfMsg( "badfiletype", htmlspecialchars( $ext ) ) );
 167+ return $this->uploadError( wfMsg( 'badfiletype', htmlspecialchars( $ext ) ) );
149168 }
150169
151170 $this->saveUploadedFile( $this->mUploadSaveName, $this->mUploadTempName );
152171 if ( !$nt->userCanEdit() ) {
153 - return $this->uploadError( wfMsg( "protectedpage" ) );
 172+ return $this->uploadError( wfMsg( 'protectedpage' ) );
154173 }
155174
156175 if ( ! $this->mIgnoreWarning ) {
157176 $warning = '';
158177 if( $changed_name || 0 != strcmp( ucfirst( $basename ), $this->mUploadSaveName ) ) {
159 - $warning .= '<li>'.wfMsg( "badfilename", htmlspecialchars( $this->mUploadSaveName ) ).'</li>';
 178+ $warning .= '<li>'.wfMsg( 'badfilename', htmlspecialchars( $this->mUploadSaveName ) ).'</li>';
160179 }
161180
162181 if ( $wgCheckFileExtensions ) {
163182 if ( ! $this->checkFileExtension( $ext, $wgFileExtensions ) ) {
164 - $warning .= '<li>'.wfMsg( "badfiletype", htmlspecialchars( $ext ) ).'</li>';
 183+ $warning .= '<li>'.wfMsg( 'badfiletype', htmlspecialchars( $ext ) ).'</li>';
165184 }
166185 }
167186 if ( $wgUploadSizeWarning && ( $this->mUploadSize > $wgUploadSizeWarning ) ) {
168 - $warning .= '<li>'.wfMsg( "largefile" ).'</li>';
 187+ $warning .= '<li>'.wfMsg( 'largefile' ).'</li>';
169188 }
170189 if ( $this->mUploadSize == 0 ) {
171 - $warning .= '<li>'.wfMsg( "emptyfile" ).'</li>';
 190+ $warning .= '<li>'.wfMsg( 'emptyfile' ).'</li>';
172191 }
173192 if( $nt->getArticleID() ) {
174193 $sk = $wgUser->getSkin();
175194 $dname = $wgLang->getNsText( Namespace::getImage() ) . ":{$this->mUploadSaveName}";
176195 $dlink = $sk->makeKnownLink( $dname, $dname );
177 - $warning .= '<li>'.wfMsg( "fileexists", $dlink ).'</li>';
 196+ $warning .= '<li>'.wfMsg( 'fileexists', $dlink ).'</li>';
178197 }
179198 if($warning != '') return $this->uploadWarning($warning);
180199 }
@@ -189,8 +208,8 @@
190209 $dname = $wgLang->getNsText( Namespace::getImage() ) . ":{$this->mUploadSaveName}";
191210 $dlink = $sk->makeKnownLink( $dname, $dname );
192211
193 - $wgOut->addHTML( "<h2>" . wfMsg( "successfulupload" ) . "</h2>\n" );
194 - $text = wfMsg( "fileuploaded", $ilink, $dlink );
 212+ $wgOut->addHTML( '<h2>' . wfMsg( 'successfulupload' ) . "</h2>\n" );
 213+ $text = wfMsg( 'fileuploaded', $ilink, $dlink );
195214 $wgOut->addHTML( "<p>{$text}\n" );
196215 $wgOut->returnToMain( false );
197216 }
@@ -208,7 +227,7 @@
209228 $wgSavedFile = "{$dest}/{$saveName}";
210229
211230 if ( is_file( $wgSavedFile ) ) {
212 - $wgUploadOldVersion = gmdate( "YmdHis" ) . "!{$saveName}";
 231+ $wgUploadOldVersion = gmdate( 'YmdHis' ) . "!{$saveName}";
213232
214233 if ( ! rename( $wgSavedFile, "${archive}/{$wgUploadOldVersion}" ) ) {
215234 $wgOut->fileRenameError( $wgSavedFile,
@@ -216,7 +235,7 @@
217236 return;
218237 }
219238 } else {
220 - $wgUploadOldVersion = "";
 239+ $wgUploadOldVersion = '';
221240 }
222241 if ( ! move_uploaded_file( $tempName, $wgSavedFile ) ) {
223242 $wgOut->fileCopyError( $tempName, $wgSavedFile );
@@ -234,10 +253,10 @@
235254 $wgOut->fileDeleteError( $wgSavedFile );
236255 return;
237256 }
238 - if ( "" != $wgUploadOldVersion ) {
 257+ if ( '' != $wgUploadOldVersion ) {
239258 $hash = md5( substr( $wgUploadOldVersion, 15 ) );
240 - $archive = "{$wgUploadDirectory}/archive/" . $hash{0} .
241 - "/" . substr( $hash, 0, 2 );
 259+ $archive = $wgUploadDirectory.'/archive/' . $hash{0} .
 260+ '/' . substr( $hash, 0, 2 );
242261
243262 if ( ! rename( "{$archive}/{$wgUploadOldVersion}", $wgSavedFile ) ) {
244263 $wgOut->fileRenameError( "{$archive}/{$wgUploadOldVersion}",
@@ -248,7 +267,7 @@
249268
250269 function uploadError( $error ) {
251270 global $wgOut;
252 - $sub = wfMsg( "uploadwarning" );
 271+ $sub = wfMsg( 'uploadwarning' );
253272 $wgOut->addHTML( "<h2>{$sub}</h2>\n" );
254273 $wgOut->addHTML( "<h4 style='error'>{$error}</h4>\n" );
255274 }
@@ -262,16 +281,16 @@
263282 $this->mSessionKey = mt_rand( 0, 0x7fffffff );
264283 $_SESSION['wsUploadFiles'][$this->mSessionKey] = $wgSavedFile;
265284
266 - $sub = wfMsg( "uploadwarning" );
 285+ $sub = wfMsg( 'uploadwarning' );
267286 $wgOut->addHTML( "<h2>{$sub}</h2>\n" );
268287 $wgOut->addHTML( "<ul class='warning'>{$warning}</ul><br/>\n" );
269288
270 - $save = wfMsg( "savefile" );
271 - $reupload = wfMsg( "reupload" );
272 - $iw = wfMsg( "ignorewarning" );
273 - $reup = wfMsg( "reuploaddesc" );
274 - $titleObj = Title::makeTitle( NS_SPECIAL, "Upload" );
275 - $action = $titleObj->escapeLocalURL( "action=submit" );
 289+ $save = wfMsg( 'savefile' );
 290+ $reupload = wfMsg( 'reupload' );
 291+ $iw = wfMsg( 'ignorewarning' );
 292+ $reup = wfMsg( 'reuploaddesc' );
 293+ $titleObj = Title::makeTitle( NS_SPECIAL, 'Upload' );
 294+ $action = $titleObj->escapeLocalURL( 'action=submit' );
276295
277296 if ( $wgUseCopyrightUpload )
278297 {
@@ -308,27 +327,27 @@
309328 global $wgOut, $wgUser, $wgLang, $wgUploadDirectory, $wgRequest;
310329 global $wgUseCopyrightUpload;
311330
312 - if ( "" != $msg ) {
313 - $sub = wfMsg( "uploaderror" );
 331+ if ( '' != $msg ) {
 332+ $sub = wfMsg( 'uploaderror' );
314333 $wgOut->addHTML( "<h2>{$sub}</h2>\n" .
315334 "<h4 style='error'>{$msg}</h4>\n" );
316335 } else {
317 - $sub = wfMsg( "uploadfile" );
 336+ $sub = wfMsg( 'uploadfile' );
318337 $wgOut->addHTML( "<h2>{$sub}</h2>\n" );
319338 }
320 - $wgOut->addWikiText( wfMsg( "uploadtext" ) );
 339+ $wgOut->addWikiText( wfMsg( 'uploadtext' ) );
321340 $sk = $wgUser->getSkin();
322341
323 - $fn = wfMsg( "filename" );
324 - $fd = wfMsg( "filedesc" );
325 - $ulb = wfMsg( "uploadbtn" );
 342+ $fn = wfMsg( 'filename' );
 343+ $fd = wfMsg( 'filedesc' );
 344+ $ulb = wfMsg( 'uploadbtn' );
326345
327 - $clink = $sk->makeKnownLink( wfMsg( "copyrightpage" ),
328 - wfMsg( "copyrightpagename" ) );
329 - $ca = wfMsg( "affirmation", $clink );
330 - $iw = wfMsg( "ignorewarning" );
 346+ $clink = $sk->makeKnownLink( wfMsg( 'copyrightpage' ),
 347+ wfMsg( 'copyrightpagename' ) );
 348+ $ca = wfMsg( 'affirmation', $clink );
 349+ $iw = wfMsg( 'ignorewarning' );
331350
332 - $titleObj = Title::makeTitle( NS_SPECIAL, "Upload" );
 351+ $titleObj = Title::makeTitle( NS_SPECIAL, 'Upload' );
333352 $action = $titleObj->escapeLocalURL();
334353
335354 $source = "
@@ -339,11 +358,11 @@
340359 if ( $wgUseCopyrightUpload )
341360 {
342361 $source = "
343 - <td align='right' nowrap='nowrap'>" . wfMsg ( "filestatus" ) . ":</td>
 362+ <td align='right' nowrap='nowrap'>" . wfMsg ( 'filestatus' ) . ":</td>
344363 <td><input tabindex='3' type='text' name=\"wpUploadCopyStatus\" value=\"" .
345364 htmlspecialchars($this->mUploadCopyStatus). "\" size='40' /></td>
346365 </tr><tr>
347 - <td align='right'>". wfMsg ( "filesource" ) . ":</td>
 366+ <td align='right'>". wfMsg ( 'filesource' ) . ":</td>
348367 <td><input tabindex='4' type='text' name=\"wpUploadSource\" value=\"" .
349368 htmlspecialchars($this->mUploadSource). "\" size='40' /></td>
350369 " ;

Status & tagging log