r48333 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r48332‎ | r48333 | r48334 >
Date:21:39, 11 March 2009
Author:ashley
Status:ok
Tags:
Comment:
SocialProfile: cleanup to SpecialSystemGiftManagerLogo.php
Modified paths:
  • /trunk/extensions/SocialProfile/SystemGifts/SpecialSystemGiftManagerLogo.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SocialProfile/SystemGifts/SpecialSystemGiftManagerLogo.php
@@ -44,13 +44,13 @@
4545 }
4646
4747 $this->gift_id = $wgRequest->getVal( 'gift_id' );
48 - $this->initLogo($wgRequest);
 48+ $this->initLogo( $wgRequest );
4949 $this->executeLogo();
5050 }
5151
5252 function initLogo( &$request ){
5353 $this->fileExtensions = array( 'gif', 'jpg', 'jpeg', 'png' );
54 -
 54+
5555 if( !$request->wasPosted() ) {
5656 # GET requests just give the main form; no data except wpDestfile.
5757 return;
@@ -59,12 +59,12 @@
6060 $this->mIgnoreWarning = $request->getCheck( 'wpIgnoreWarning');
6161 $this->mReUpload = $request->getCheck( 'wpReUpload' );
6262 $this->mUpload = $request->getCheck( 'wpUpload' );
63 -
 63+
6464 $this->mUploadDescription = $request->getText( 'wpUploadDescription' );
6565 $this->mUploadCopyStatus = $request->getText( 'wpUploadCopyStatus' );
6666 $this->mUploadSource = $request->getText( 'wpUploadSource' );
6767 $this->mWatchthis = $request->getBool( 'wpWatchthis' );
68 - wfDebug( "UploadForm: watchthis is: '$this->mWatchthis'\n" );
 68+ wfDebug( __METHOD__ . ": watchthis is: '$this->mWatchthis'\n" );
6969
7070 $this->mAction = $request->getVal( 'action' );
7171 $this->mSessionKey = $request->getInt( 'wpSessionKey' );
@@ -99,7 +99,7 @@
100100 public function executeLogo() {
101101 global $wgUser, $wgOut;
102102 global $wgEnableUploads, $wgUploadDirectory;
103 - $this->avatarUploadDirectory = $wgUploadDirectory . "/awards";
 103+ $this->avatarUploadDirectory = $wgUploadDirectory . '/awards';
104104 /** Show an error message if file upload is disabled */
105105 if( !$wgEnableUploads ) {
106106 $wgOut->addWikiMsg( 'uploaddisabled' );
@@ -141,7 +141,7 @@
142142 * If there was no filename or a zero size given, give up quick.
143143 */
144144 if( trim( $this->mOname ) == '' || empty( $this->mUploadSize ) ) {
145 - return $this->mainUploadForm('<li>'.wfMsg( 'emptyfile' ).'</li>');
 145+ return $this->mainUploadForm( '<li>'.wfMsg( 'emptyfile' ).'</li>' );
146146 }
147147
148148 # Chop off any directories in the given filename
@@ -181,9 +181,9 @@
182182 * probably not accept it.
183183 */
184184 if( !$this->mStashed ) {
185 - $veri = $this->verify($this->mUploadTempName, $finalExt);
 185+ $veri = $this->verify( $this->mUploadTempName, $finalExt );
186186
187 - if( $veri !== true ) { //it's a wiki error...
 187+ if( $veri !== true ) { // it's a wiki error...
188188 return $this->uploadError( $veri->toString() );
189189 }
190190 }
@@ -215,7 +215,7 @@
216216 * Stash the file in a temporary location; the user can choose
217217 * to let it through and we'll complete the upload then.
218218 */
219 - return $this->uploadWarning($warning);
 219+ return $this->uploadWarning( $warning );
220220 }
221221 }
222222
@@ -223,22 +223,22 @@
224224 * Try actually saving the thing...
225225 * It will show an error form on failure.
226226 */
227 - $status = $this->saveUploadedFile( $this->mUploadSaveName, $this->mUploadTempName, strtoupper($fullExt) );
 227+ $status = $this->saveUploadedFile( $this->mUploadSaveName, $this->mUploadTempName, strtoupper( $fullExt ) );
228228
229229 if( $status > 0 ) {
230 - $this->showSuccess($status);
 230+ $this->showSuccess( $status );
231231 }
232232 }
233233
234234 function createThumbnail( $imageSrc, $ext, $imgDest, $thumbWidth ){
235 - list($origWidth, $origHeight, $TypeCode) = getimagesize($imageSrc);
 235+ list( $origWidth, $origHeight, $TypeCode ) = getimagesize( $imageSrc );
236236
237 - if($origWidth < $thumbWidth)$thumbWidth = $origWidth;
 237+ if( $origWidth < $thumbWidth ) $thumbWidth = $origWidth;
238238 $thumbHeight = ($thumbWidth * $origHeight / $origWidth);
239 - if($thumbHeight < $thumbWidth)$border = " -bordercolor white -border 0x" . (($thumbWidth - $thumbHeight) / 2);
240 - if($TypeCode == 2)exec("convert -size " . $thumbWidth . "x" . $thumbWidth . " -resize " . $thumbWidth . " -quality 100 " . $border . " " . $imageSrc . " " . $this->avatarUploadDirectory . "/sg_" . $imgDest . ".jpg");
241 - if($TypeCode == 1)exec("convert -size " . $thumbWidth . "x" . $thumbWidth . " -resize " . $thumbWidth . " " . $imageSrc . " " . $border . " " . $this->avatarUploadDirectory . "/sg_" . $imgDest . ".gif");
242 - if($TypeCode == 3)exec("convert -size " . $thumbWidth . "x" . $thumbWidth . " -resize " . $thumbWidth . " " . $imageSrc . " " . $this->avatarUploadDirectory . "/sg_" . $imgDest . ".png");
 239+ if( $thumbHeight < $thumbWidth ) $border = " -bordercolor white -border 0x" . (($thumbWidth - $thumbHeight) / 2);
 240+ if( $TypeCode == 2 ) exec("convert -size " . $thumbWidth . "x" . $thumbWidth . " -resize " . $thumbWidth . " -quality 100 " . $border . " " . $imageSrc . " " . $this->avatarUploadDirectory . "/sg_" . $imgDest . ".jpg");
 241+ if( $TypeCode == 1 ) exec("convert -size " . $thumbWidth . "x" . $thumbWidth . " -resize " . $thumbWidth . " " . $imageSrc . " " . $border . " " . $this->avatarUploadDirectory . "/sg_" . $imgDest . ".gif");
 242+ if( $TypeCode == 3 ) exec("convert -size " . $thumbWidth . "x" . $thumbWidth . " -resize " . $thumbWidth . " " . $imageSrc . " " . $this->avatarUploadDirectory . "/sg_" . $imgDest . ".png");
243243 }
244244
245245 /**
@@ -254,44 +254,44 @@
255255 * is a PHP-managed upload temporary
256256 */
257257 function saveUploadedFile( $saveName, $tempName, $ext ) {
258 - global $wgUploadDirectory, $wgOut, $wgUser, $wgDBname;
 258+ global $wgUploadDirectory, $wgOut, $wgUser;
259259
260260 $dest = $this->avatarUploadDirectory;
261261
262262 $this->mSavedFile = "{$dest}/{$saveName}";
263263
264 - $this->createThumbnail($tempName, $ext, $this->gift_id . "_l", 75);
265 - $this->createThumbnail($tempName, $ext, $this->gift_id . "_ml", 50);
266 - $this->createThumbnail($tempName, $ext, $this->gift_id . "_m", 30);
267 - $this->createThumbnail($tempName, $ext, $this->gift_id . "_s", 16);
 264+ $this->createThumbnail( $tempName, $ext, $this->gift_id . "_l", 75 );
 265+ $this->createThumbnail( $tempName, $ext, $this->gift_id . "_ml", 50 );
 266+ $this->createThumbnail( $tempName, $ext, $this->gift_id . "_m", 30 );
 267+ $this->createThumbnail( $tempName, $ext, $this->gift_id . "_s", 16 );
268268
269 - if( $ext == "JPG" && is_file( $this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_l.jpg") ){
 269+ if( $ext == "JPG" && is_file( $this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_l.jpg" ) ){
270270 $type = 2;
271271 }
272 - if( $ext == "GIF" && is_file( $this->avatarUploadDirectory . "/sg_" . $this->gift_id. "_l.gif") ){
 272+ if( $ext == "GIF" && is_file( $this->avatarUploadDirectory . "/sg_" . $this->gift_id. "_l.gif" ) ){
273273 $type = 1;
274274 }
275 - if( $ext == "PNG" && is_file( $this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_l.png") ){
 275+ if( $ext == "PNG" && is_file( $this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_l.png" ) ){
276276 $type = 3;
277277 }
278278
279279 if( $ext!= "JPG" ){
280 - if( is_file($this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_s.jpg") ) unlink($this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_s.jpg");
281 - if( is_file($this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_m.jpg") ) unlink($this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_m.jpg");
282 - if( is_file($this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_l.jpg") ) unlink($this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_l.jpg");
283 - if( is_file($this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_l.jpg") ) unlink($this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_ml.jpg");
 280+ if( is_file( $this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_s.jpg" ) ) unlink( $this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_s.jpg" );
 281+ if( is_file( $this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_m.jpg" ) ) unlink( $this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_m.jpg" );
 282+ if( is_file( $this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_l.jpg" ) ) unlink( $this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_l.jpg" );
 283+ if( is_file( $this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_l.jpg" ) ) unlink( $this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_ml.jpg" );
284284 }
285285 if( $ext != "GIF" ){
286 - if( is_file($this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_s.gif") ) unlink($this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_s.gif");
287 - if( is_file($this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_m.gif") ) unlink($this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_m.gif");
288 - if( is_file($this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_l.gif") ) unlink($this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_l.gif");
289 - if( is_file($this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_l.gif") ) unlink($this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_ml.gif");
 286+ if( is_file( $this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_s.gif" ) ) unlink( $this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_s.gif" );
 287+ if( is_file( $this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_m.gif" ) ) unlink( $this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_m.gif" );
 288+ if( is_file( $this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_l.gif" ) ) unlink( $this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_l.gif" );
 289+ if( is_file( $this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_l.gif" ) ) unlink( $this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_ml.gif" );
290290 }
291291 if( $ext != "PNG" ){
292 - if( is_file($this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_s.png") ) unlink($this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_s.png");
293 - if( is_file($this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_m.png") ) unlink($this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_m.png");
294 - if( is_file($this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_l.png") ) unlink($this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_l.png");
295 - if( is_file($this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_l.png") ) unlink($this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_ml.png");
 292+ if( is_file( $this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_s.png" ) ) unlink( $this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_s.png" );
 293+ if( is_file( $this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_m.png" ) ) unlink( $this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_m.png" );
 294+ if( is_file( $this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_l.png" ) ) unlink( $this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_l.png" );
 295+ if( is_file( $this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_l.png" ) ) unlink( $this->avatarUploadDirectory . "/sg_" . $this->gift_id . "_ml.png" );
296296 }
297297
298298 if( $type < 0 ){
@@ -334,7 +334,7 @@
335335 * @return int
336336 * @access private
337337 */
338 - function stashSession() {
 338+ function stashSession() {
339339 $stash = $this->saveTempUploadedFile(
340340 $this->mUploadSaveName, $this->mUploadTempName );
341341
@@ -369,30 +369,45 @@
370370 * @access private
371371 */
372372 function showSuccess( $status ) {
373 - global $wgUser, $wgOut, $wgContLang, $wgDBname, $wgUploadPath, $wgScriptPath, $wgLang;
374 - wfLoadExtensionMessages('SystemGifts');
 373+ global $wgUser, $wgOut, $wgUploadPath, $wgScriptPath, $wgLang;
 374+ wfLoadExtensionMessages( 'SystemGifts' );
375375 $ext = 'jpg';
376376
377 - $output = '<h2>'.wfMsg('ga-uploadsuccess').'</h2>';
378 - $output .= '<h5>'.wfMsg('ga-imagesbelow').'</h5>';
379 - if( $status == 1 ) $ext = "gif";
380 - if( $status == 2 ) $ext = "jpg";
381 - if( $status == 3 ) $ext = "png";
 377+ $output = '<h2>'.wfMsg( 'ga-uploadsuccess' ).'</h2>';
 378+ $output .= '<h5>'.wfMsg( 'ga-imagesbelow' ).'</h5>';
 379+ if( $status == 1 ) $ext = 'gif';
 380+ if( $status == 2 ) $ext = 'jpg';
 381+ if( $status == 3 ) $ext = 'png';
382382
383 - $output .= '<table cellspacing="0" cellpadding="5">';
384 - $output .= '<tr><td valign="top" style="color:#666666;font-weight:800">'.wfMsg('ga-large').'</td><td><img src="'.$wgUploadPath.'/awards/sg_' . $this->gift_id . '_l.' . $ext . '?ts=' . rand() . '"></td></tr>';
385 - $output .= '<tr><td valign="top" style="color:#666666;font-weight:800">'.wfMsg('ga-mediumlarge').'</td><td><img src="'.$wgUploadPath.'/awards/sg_' . $this->gift_id . '_ml.' . $ext . '?ts=' . rand() . '"></td></tr>';
386 - $output .= '<tr><td valign="top" style="color:#666666;font-weight:800">'.wfMsg('ga-medium').'</td><td><img src="'.$wgUploadPath.'/awards/sg_' . $this->gift_id . '_m.' . $ext . '?ts=' . rand() . '"></td></tr>';
387 - $output .= '<tr><td valign="top" style="color:#666666;font-weight:800">'.wfMsg('ga-small').'</td><td><img src="'.$wgUploadPath.'/awards/sg_' . $this->gift_id . '_s.' . $ext . '?ts' . rand() . '"></td></tr>';
388 - $output .= '<tr><td><input type="button" onclick="javascript:history.go(-1)" value="'.wfMsg('ga-goback').'"></td></tr>';
 383+ $output .= '<table cellspacing="0" cellpadding="5">
 384+ <tr>
 385+ <td valign="top" style="color:#666666;font-weight:800">'.wfMsg( 'ga-large' ).'</td>
 386+ <td><img src="'.$wgUploadPath.'/awards/sg_' . $this->gift_id . '_l.' . $ext . '?ts=' . rand() . '"></td>
 387+ </tr>
 388+ <tr>
 389+ <td valign="top" style="color:#666666;font-weight:800">'.wfMsg( 'ga-mediumlarge' ).'</td>
 390+ <td><img src="'.$wgUploadPath.'/awards/sg_' . $this->gift_id . '_ml.' . $ext . '?ts=' . rand() . '"></td>
 391+ </tr>
 392+ <tr>
 393+ <td valign="top" style="color:#666666;font-weight:800">'.wfMsg( 'ga-medium' ).'</td>
 394+ <td><img src="'.$wgUploadPath.'/awards/sg_' . $this->gift_id . '_m.' . $ext . '?ts=' . rand() . '"></td>
 395+ </tr>
 396+ <tr>
 397+ <td valign="top" style="color:#666666;font-weight:800">'.wfMsg( 'ga-small' ).'</td>
 398+ <td><img src="'.$wgUploadPath.'/awards/sg_' . $this->gift_id . '_s.' . $ext . '?ts' . rand() . '"></td>
 399+ </tr>
 400+ <tr>
 401+ <td>
 402+ <input type="button" onclick="javascript:history.go(-1)" value="'.wfMsg( 'ga-goback' ).'">
 403+ </td>
 404+ </tr>';
389405
390 - // FIXME: contains very hard coded URLs
391406 $output .= $wgLang->pipeList( array(
392 - '<tr><td><a href="' . $wgScriptPath . '/index.php?title=Special:SystemGiftManager">' . wfMsg( 'ga-back-gift-list' ) . '</a>',
393 - '<a href="' . $wgScriptPath . '/index.php?title=Special:SystemGiftManager&amp;id=' . $this->gift_id . '">' . wfMsg( 'ga-back-edit-gift') . '</a></td></tr>'
 407+ '<tr><td><a href="' . $wgScriptPath . '/index.php?title=Special:SystemGiftManager">' . wfMsg( 'ga-back-gift-list' ) . '</a>&nbsp;',
 408+ '&nbsp;<a href="' . $wgScriptPath . '/index.php?title=Special:SystemGiftManager&amp;id=' . $this->gift_id . '">' . wfMsg( 'ga-back-edit-gift') . '</a></td></tr>'
394409 ) );
395410 $output .= '</table>';
396 - $wgOut->addHTML($output);
 411+ $wgOut->addHTML( $output );
397412 }
398413
399414 /**
@@ -401,11 +416,11 @@
402417 */
403418 function uploadError( $error ) {
404419 global $wgOut;
405 - wfLoadExtensionMessages('SystemGifts');
 420+ wfLoadExtensionMessages( 'SystemGifts' );
406421 $sub = wfMsg( 'uploadwarning' );
407422 $wgOut->addHTML( "<h2>{$sub}</h2>\n" );
408423 $wgOut->addHTML( "<h4 class='error'>{$error}</h4>\n" );
409 - $wgOut->addHTML( '<br /><input type="button" onclick="javascript:history.go(-1)" value="'.wfMsg('ga-goback').'">' );
 424+ $wgOut->addHTML( '<br /><input type="button" onclick="javascript:history.go(-1)" value="'.wfMsg( 'ga-goback' ).'">' );
410425 }
411426
412427 /**
@@ -457,7 +472,7 @@
458473 {$copyright}
459474 <table border='0'>
460475 <tr>
461 -
 476+
462477 <tr>
463478 <td align='right'>
464479 <input tabindex='2' type='button' onclick=javascript:history.go(-1) value='Back' />
@@ -478,7 +493,7 @@
479494 function mainUploadForm( $msg = '' ) {
480495 global $wgOut, $wgUser, $wgLang, $wgUploadDirectory, $wgRequest;
481496 global $wgUseCopyrightUpload;
482 - wfLoadExtensionMessages('SystemGifts');
 497+ wfLoadExtensionMessages( 'SystemGifts' );
483498
484499 $cols = intval( $wgUser->getOption( 'cols' ) );
485500 $ew = $wgUser->getOption( 'editwidth' );
@@ -490,7 +505,7 @@
491506 $wgOut->addHTML( "<h2>{$sub}</h2>\n" .
492507 "<h4 class='error'>{$msg}</h4>\n" );
493508 }
494 - //$wgOut->addWikiText( wfMsg( 'uploadtext' ) );
 509+
495510 $sk = $wgUser->getSkin();
496511
497512 $sourcefilename = wfMsg( 'sourcefilename' );
@@ -509,13 +524,13 @@
510525
511526 if ( $wgUseCopyrightUpload ) {
512527 $source = "
513 - <td align='right' nowrap='nowrap'>" . wfMsg ( 'filestatus' ) . ":</td>
 528+ <td align='right' nowrap='nowrap'>" . wfMsg( 'filestatus' ) . "</td>
514529 <td><input tabindex='3' type='text' name=\"wpUploadCopyStatus\" value=\"" .
515 - htmlspecialchars($this->mUploadCopyStatus). "\" size='40' /></td>
 530+ htmlspecialchars( $this->mUploadCopyStatus ). "\" size='40' /></td>
516531 </tr><tr>
517 - <td align='right'>". wfMsg ( 'filesource' ) . ":</td>
 532+ <td align='right'>". wfMsg( 'filesource' ) . "</td>
518533 <td><input tabindex='4' type='text' name='wpUploadSource' value=\"" .
519 - htmlspecialchars($this->mUploadSource). "\" style='width:100px' /></td>
 534+ htmlspecialchars( $this->mUploadSource ). "\" style='width:100px' /></td>
520535 ";
521536 }
522537
@@ -524,18 +539,27 @@
525540 : '';
526541
527542 global $wgUploadPath;
528 - $gift_image = SystemGifts::getGiftImage($this->gift_id, 'l');
 543+ $gift_image = SystemGifts::getGiftImage( $this->gift_id, 'l' );
529544 if( $gift_image != '' ){
530 - $output = '<table><tr><td style="color:#666666;font-weight:800">'.wfMsg('ga-currentimage').'</td></tr>';
531 - $output .= '<tr><td><img src="'.$wgUploadPath.'/awards/' . $gift_image . '" border="0" alt="'.wfMsg('ga-gift').'" /></td></tr></table><br />';
 545+ $output = '<table>
 546+ <tr>
 547+ <td style="color:#666666;font-weight:800">'.wfMsg( 'ga-currentimage' ).'</td>
 548+ </tr>
 549+ <tr>
 550+ <td>
 551+ <img src="' . $wgUploadPath . '/awards/' . $gift_image . '" border="0" alt="'.wfMsg( 'ga-gift' ).'" />
 552+ </td>
 553+ </tr>
 554+ </table>
 555+ <br />';
532556 }
533 - $wgOut->addHTML($output);
 557+ $wgOut->addHTML( $output );
534558
535559 $wgOut->addHTML( "
536560 <form id='upload' method='post' enctype='multipart/form-data' action=\"\">
537561 <table border='0'><tr>
538562
539 - <td style='color:#666666;font-weight:800'>".wfMsg('ga-file-instructions')."<p>".wfMsg('ga-choosefile')."<br />
 563+ <td style='color:#666666;font-weight:800'>".wfMsg( 'ga-file-instructions' ) . wfMsg( 'ga-choosefile' )."<br />
540564 <input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' style='width:100px' />
541565 </td></tr><tr>
542566 {$source}
@@ -598,10 +622,8 @@
599623 function verify( $tmpfile, $extension ) {
600624 #magically determine mime type
601625 $magic = & wfGetMimeMagic();
602 - $mime = $magic->guessMimeType($tmpfile, false);
 626+ $mime = $magic->guessMimeType( $tmpfile, false );
603627
604 - $fname = "SpecialSystemGiftManagerLogo::verify";
605 -
606628 #check mime type, if desired
607629 global $wgVerifyMimeType;
608630 if( $wgVerifyMimeType ) {
@@ -613,26 +635,26 @@
614636
615637 #check mime type blacklist
616638 global $wgMimeTypeBlacklist;
617 - if( isset($wgMimeTypeBlacklist) && !is_null($wgMimeTypeBlacklist)
 639+ if( isset( $wgMimeTypeBlacklist ) && !is_null( $wgMimeTypeBlacklist )
618640 && $this->checkFileExtension( $mime, $wgMimeTypeBlacklist ) ) {
619641 return new WikiErrorMsg( 'badfiletype', htmlspecialchars( $mime ) );
620642 }
621643 }
622644
623645 #check for htmlish code and javascript
624 - if( $this->detectScript ( $tmpfile, $mime ) ) {
 646+ if( $this->detectScript( $tmpfile, $mime ) ) {
625647 return new WikiErrorMsg( 'uploadscripted' );
626648 }
627649
628650 /**
629651 * Scan the uploaded file for viruses
630652 */
631 - $virus = $this->detectVirus($tmpfile);
 653+ $virus = $this->detectVirus( $tmpfile );
632654 if ( $virus ) {
633 - return new WikiErrorMsg( 'uploadvirus', htmlspecialchars($virus) );
 655+ return new WikiErrorMsg( 'uploadvirus', htmlspecialchars( $virus ) );
634656 }
635657
636 - wfDebug( "$fname: all clear; passing.\n" );
 658+ wfDebug( __METHOD__ . ": all clear; passing.\n" );
637659 return true;
638660 }
639661
@@ -644,32 +666,28 @@
645667 * @return bool
646668 */
647669 function verifyExtension( $mime, $extension ) {
648 - $fname = 'SpecialSystemGiftManagerLogo::verifyExtension';
649 -
650670 $magic =& wfGetMimeMagic();
651671
652672 if ( !$mime || $mime == 'unknown' || $mime == 'unknown/unknown' )
653673 if ( !$magic->isRecognizableExtension( $extension ) ) {
654 - wfDebug( "$fname: passing file with unknown detected mime type; unrecognized extension '$extension', can't verify\n" );
 674+ wfDebug( __METHOD__ . ": passing file with unknown detected mime type; unrecognized extension '$extension', can't verify\n" );
655675 return true;
656676 } else {
657 - wfDebug( "$fname: rejecting file with unknown detected mime type; recognized extension '$extension', so probably invalid file\n" );
 677+ wfDebug( __METHOD__ . ": rejecting file with unknown detected mime type; recognized extension '$extension', so probably invalid file\n" );
658678 return false;
659679 }
660680
661681 $match = $magic->isMatchingExtension( $extension, $mime );
662682
663683 if( $match === NULL ) {
664 - wfDebug( "$fname: no file extension known for mime type $mime, passing file\n" );
 684+ wfDebug( __METHOD__ . ": no file extension known for mime type $mime, passing file\n" );
665685 return true;
666686 } elseif( $match === true ) {
667 - wfDebug( "$fname: mime type $mime matches extension $extension, passing file\n" );
668 -
 687+ wfDebug( __METHOD__ . ": mime type $mime matches extension $extension, passing file\n" );
669688 #TODO: if it's a bitmap, make sure PHP or ImageMagic resp. can handle it!
670689 return true;
671 -
672690 } else {
673 - wfDebug( "$fname: mime type $mime mismatches file extension $extension, rejecting file\n" );
 691+ wfDebug( __METHOD__ . ": mime type $mime mismatches file extension $extension, rejecting file\n" );
674692 return false;
675693 }
676694 }
@@ -684,11 +702,10 @@
685703 * @return bool true if the file contains something looking like embedded scripts
686704 */
687705 function detectScript( $file, $mime ) {
688 -
689706 #ugly hack: for text files, always look at the entire file.
690707 #For binarie field, just check the first K.
691708
692 - if (strpos($mime,'text/')===0) $chunk = file_get_contents( $file );
 709+ if( strpos( $mime, 'text/' ) === 0 ) $chunk = file_get_contents( $file );
693710 else {
694711 $fp = fopen( $file, 'rb' );
695712 $chunk = fread( $fp, 1024 );
@@ -697,23 +714,23 @@
698715
699716 $chunk = strtolower( $chunk );
700717
701 - if (!$chunk) return false;
 718+ if( !$chunk ) return false;
702719
703720 #decode from UTF-16 if needed (could be used for obfuscation).
704 - if (substr($chunk,0,2)=="\xfe\xff") $enc = "UTF-16BE";
705 - elseif (substr($chunk,0,2)=="\xff\xfe") $enc = "UTF-16LE";
 721+ if( substr( $chunk, 0, 2 ) == "\xfe\xff" ) $enc = "UTF-16BE";
 722+ elseif( substr( $chunk, 0, 2 ) == "\xff\xfe" ) $enc = "UTF-16LE";
706723 else $enc = NULL;
707724
708 - if ($enc) $chunk = iconv($enc, "ASCII//IGNORE", $chunk);
 725+ if( $enc ) $chunk = iconv( $enc, "ASCII//IGNORE", $chunk );
709726
710 - $chunk = trim($chunk);
 727+ $chunk = trim( $chunk );
711728
712729 #FIXME: convert from UTF-16 if necessarry!
713730
714 - wfDebug("SpecialSystemGiftManagerLogo::detectScript: checking for embedded scripts and HTML stuff\n");
 731+ wfDebug( __METHOD__ . ": checking for embedded scripts and HTML stuff\n");
715732
716733 #check for HTML doctype
717 - if (eregi("<!DOCTYPE *X?HTML", $chunk)) return true;
 734+ if( eregi( "<!DOCTYPE *X?HTML", $chunk ) ) return true;
718735
719736 /**
720737 * Internet Explorer for Windows performs some really stupid file type
@@ -756,15 +773,15 @@
757774 $chunk = Sanitizer::decodeCharReferences( $chunk );
758775
759776 #look for script-types
760 - if( preg_match("!type\s*=\s*['\"]?\s*(\w*/)?(ecma|java)!sim", $chunk) ) return true;
 777+ if( preg_match( "!type\s*=\s*['\"]?\s*(\w*/)?(ecma|java)!sim", $chunk ) ) return true;
761778
762779 #look for html-style script-urls
763 - if( preg_match("!(href|src|data)\s*=\s*['\"]?\s*(ecma|java)script:!sim", $chunk) ) return true;
 780+ if( preg_match( "!(href|src|data)\s*=\s*['\"]?\s*(ecma|java)script:!sim", $chunk ) ) return true;
764781
765782 #look for css-style script-urls
766 - if( preg_match("!url\s*\(\s*['\"]?\s*(ecma|java)script:!sim", $chunk) ) return true;
 783+ if( preg_match( "!url\s*\(\s*['\"]?\s*(ecma|java)script:!sim", $chunk ) ) return true;
767784
768 - wfDebug("SpecialSystemGiftManagerLogo::detectScript: no scripts found\n");
 785+ wfDebug( __METHOD__ . ": no scripts found\n" );
769786 return false;
770787 }
771788
@@ -781,16 +798,13 @@
782799 function detectVirus( $file ) {
783800 global $wgAntivirus, $wgAntivirusSetup, $wgAntivirusRequired;
784801
785 - $fname = "SpecialSystemGiftManagerLogo::detectVirus";
786 -
787802 if( !$wgAntivirus ) { #disabled?
788 - wfDebug("$fname: virus scanner disabled\n");
789 -
 803+ wfDebug( __METHOD__ . ": virus scanner disabled\n" );
790804 return NULL;
791805 }
792806
793807 if( !$wgAntivirusSetup[$wgAntivirus] ) {
794 - wfDebug("$fname: unknown virus scanner: $wgAntivirus\n");
 808+ wfDebug( __METHOD__ . ": unknown virus scanner: $wgAntivirus\n" );
795809
796810 $wgOut->addHTML( '<div class="error">'. wfMsg( 'virus-badscanner', $wgAntivirus ) . "\n" );
797811
@@ -804,10 +818,10 @@
805819
806820 $scanner = $virus_scanner; #copy, so we can resolve the pattern
807821
808 - if( strpos( $scanner, "%f" ) === false ) $scanner.= " ".wfEscapeShellArg($file); #simple pattern: append file to scan
809 - else $scanner = str_replace( "%f", wfEscapeShellArg($file), $scanner ); #complex pattern: replace "%f" with file to scan
 822+ if( strpos( $scanner, "%f" ) === false ) $scanner.= " ".wfEscapeShellArg( $file ); #simple pattern: append file to scan
 823+ else $scanner = str_replace( "%f", wfEscapeShellArg( $file ), $scanner ); #complex pattern: replace "%f" with file to scan
810824
811 - wfDebug("$fname: running virus scan: $scanner \n");
 825+ wfDebug( __METHOD__ . ": running virus scan: $scanner \n" );
812826
813827 #execute virus scanner
814828 $code = false;
@@ -826,19 +840,20 @@
827841 }
828842
829843 if( $code === AV_SCAN_FAILED ) { #scan failed (code was mapped to false by $virus_scanner_codes)
830 - wfDebug("$fname: failed to scan $file (code $exit_code).\n");
 844+ wfDebug( __METHOD__ . ": failed to scan $file (code $exit_code).\n" );
831845
832 - if ($wgAntivirusRequired) return wfMsg( 'virus-scanfailed', $exit_code );
 846+ if( $wgAntivirusRequired )
 847+ return wfMsg( 'virus-scanfailed', $exit_code );
833848 else return NULL;
834 - } else if( $code === AV_SCAN_ABORTED ) { #scan failed because filetype is unknown (probably imune)
835 - wfDebug("$fname: unsupported file type $file (code $exit_code).\n");
 849+ } else if( $code === AV_SCAN_ABORTED ) { #scan failed because filetype is unknown (probably immune)
 850+ wfDebug( __METHOD__ . ": unsupported file type $file (code $exit_code).\n" );
836851 return NULL;
837852 } else if( $code === AV_NO_VIRUS ) {
838 - wfDebug("$fname: file passed virus scan.\n");
 853+ wfDebug( __METHOD__ . ": file passed virus scan.\n" );
839854 return false; #no virus found
840855 } else {
841 - $output = join("\n", $output);
842 - $output = trim($output);
 856+ $output = join( "\n", $output );
 857+ $output = trim( $output );
843858
844859 if( !$output ) $output = true; #if ther's no output, return true
845860 else if( $msg_pattern ) {
@@ -848,7 +863,7 @@
849864 }
850865 }
851866
852 - wfDebug("$fname: FOUND VIRUS! scanner feedback: $output");
 867+ wfDebug( __METHOD__ . ": FOUND VIRUS! scanner feedback: $output" );
853868 return $output;
854869 }
855870 }

Status & tagging log