http://www.mediawiki.org/wiki/Special:Code/MediaWiki/60230

Revision: 60230
Author:   ashley
Date:     2009-12-19 19:45:19 +0000 (Sat, 19 Dec 2009)

Log Message:
-----------
SocialProfile: some cleanup to SystemGifts stuff

Modified Paths:
--------------
    trunk/extensions/SocialProfile/SystemGifts/SpecialSystemGiftManager.php
    trunk/extensions/SocialProfile/SystemGifts/SpecialSystemGiftManagerLogo.php
    trunk/extensions/SocialProfile/SystemGifts/SpecialViewSystemGifts.php

Modified: 
trunk/extensions/SocialProfile/SystemGifts/SpecialSystemGiftManager.php
===================================================================
--- trunk/extensions/SocialProfile/SystemGifts/SpecialSystemGiftManager.php     
2009-12-19 19:34:06 UTC (rev 60229)
+++ trunk/extensions/SocialProfile/SystemGifts/SpecialSystemGiftManager.php     
2009-12-19 19:45:19 UTC (rev 60230)
@@ -39,22 +39,27 @@
                }
 
                // Add CSS
-               $wgOut->addStyle( $wgSystemGiftsScripts . '/SystemGift.css' );
+               $wgOut->addExtensionStyle( $wgSystemGiftsScripts . 
'/SystemGift.css' );
 
                if ( $wgRequest->wasPosted() ) {
                        $g = new SystemGifts();
 
                        if ( !( $_POST['id'] ) ) {
                                $gift_id = $g->addGift(
-                                       $wgRequest->getVal( 'gift_name' ), 
$wgRequest->getVal( 'gift_description' ),
-                                       $wgRequest->getVal( 'gift_category' ), 
$wgRequest->getVal( 'gift_threshold' )
+                                       $wgRequest->getVal( 'gift_name' ),
+                                       $wgRequest->getVal( 'gift_description' 
),
+                                       $wgRequest->getVal( 'gift_category' ),
+                                       $wgRequest->getVal( 'gift_threshold' )
                                );
                                $wgOut->addHTML( '<span class="view-status">' . 
wfMsg( 'ga-created' ) . '</span><br /><br />' );
                        } else {
                                $gift_id = $wgRequest->getVal( 'id' );
-                               $g->updateGift( $gift_id,
-                                       $wgRequest->getVal( 'gift_name' ), 
$wgRequest->getVal( 'gift_description' ),
-                                       $wgRequest->getVal( 'gift_category' ), 
$wgRequest->getVal( 'gift_threshold' )
+                               $g->updateGift(
+                                       $gift_id,
+                                       $wgRequest->getVal( 'gift_name' ),
+                                       $wgRequest->getVal( 'gift_description' 
),
+                                       $wgRequest->getVal( 'gift_category' ),
+                                       $wgRequest->getVal( 'gift_threshold' )
                                );
                                $wgOut->addHTML( '<span class="view-status">' . 
wfMsg( 'ga-saved' ) . '</span><br /><br />' );
                        }
@@ -79,8 +84,8 @@
                if ( $gifts ) {
                        foreach ( $gifts as $gift ) {
                                $output .= '<div class="Item">
-                                               <a href="' . $wgScriptPath . 
'/index.php?title=Special:SystemGiftManager&amp;id=' . $gift['id'] . '">' . 
$gift['gift_name'] . '</a>
-                                       </div>' . "\n";
+                                       <a href="' . $wgScriptPath . 
'/index.php?title=Special:SystemGiftManager&amp;id=' . $gift['id'] . '">' . 
$gift['gift_name'] . '</a>
+                               </div>' . "\n";
                        }
                }
                return '<div id="views">' . $output . '</div>';
@@ -91,7 +96,9 @@
 
                $form = '<div><b><a href="' . $wgScriptPath . 
'/index.php?title=Special:SystemGiftManager">' . wfMsg( 'ga-viewlist' ) . 
'</a></b></div>';
 
-               if ( $gift_id ) $gift = SystemGifts::getGift( $gift_id );
+               if ( $gift_id ) {
+                       $gift = SystemGifts::getGift( $gift_id );
+               }
 
                $form .= '<form action="" method="post" 
enctype="multipart/form-data" name="gift">
                <table border="0" cellpadding="5" cellspacing="0" width="500">

Modified: 
trunk/extensions/SocialProfile/SystemGifts/SpecialSystemGiftManagerLogo.php
===================================================================
--- trunk/extensions/SocialProfile/SystemGifts/SpecialSystemGiftManagerLogo.php 
2009-12-19 19:34:06 UTC (rev 60229)
+++ trunk/extensions/SocialProfile/SystemGifts/SpecialSystemGiftManagerLogo.php 
2009-12-19 19:45:19 UTC (rev 60230)
@@ -121,7 +121,7 @@
                if ( $this->mReUpload ) {
                        $this->unsaveUploadedFile();
                        $this->mainUploadForm();
-               } else if ( 'submit' == $this->mAction || $this->mUpload ) {
+               } elseif ( 'submit' == $this->mAction || $this->mUpload ) {
                        $this->processUpload();
                } else {
                        $this->mainUploadForm();
@@ -231,14 +231,24 @@
        }
 
        function createThumbnail( $imageSrc, $ext, $imgDest, $thumbWidth ) {
-               list( $origWidth, $origHeight, $TypeCode ) = getimagesize( 
$imageSrc );
+               list( $origWidth, $origHeight, $typeCode ) = getimagesize( 
$imageSrc );
 
-               if ( $origWidth < $thumbWidth ) $thumbWidth = $origWidth;
+               if ( $origWidth < $thumbWidth ) {
+                       $thumbWidth = $origWidth;
+               }
                $thumbHeight = ( $thumbWidth * $origHeight / $origWidth );
-               if ( $thumbHeight < $thumbWidth ) $border = " -bordercolor 
white        -border 0x" . ( ( $thumbWidth - $thumbHeight ) / 2 );
-               if ( $TypeCode == 2 ) exec( "convert -size " . $thumbWidth . 
"x" . $thumbWidth . " -resize " . $thumbWidth . "          -quality 100 " . 
$border . " " . $imageSrc . " " . $this->avatarUploadDirectory . "/sg_" . 
$imgDest . ".jpg" );
-               if ( $TypeCode == 1 ) exec( "convert -size " . $thumbWidth . 
"x" . $thumbWidth . " -resize " . $thumbWidth . "  " . $imageSrc . " " . 
$border . " " . $this->avatarUploadDirectory . "/sg_" . $imgDest . ".gif" );
-               if ( $TypeCode == 3 ) exec( "convert -size " . $thumbWidth . 
"x" . $thumbWidth . " -resize " . $thumbWidth . "   " . $imageSrc . " " . 
$this->avatarUploadDirectory . "/sg_" . $imgDest . ".png" );
+               if ( $thumbHeight < $thumbWidth ) {
+                       $border = " -bordercolor white -border  0x" . ( ( 
$thumbWidth - $thumbHeight ) / 2 );
+               }
+               if ( $typeCode == 2 ) {
+                       exec( 'convert -size ' . $thumbWidth . 'x' . 
$thumbWidth . ' -resize ' . $thumbWidth . '  -quality 100 ' . $border . ' ' . 
$imageSrc . ' ' . $this->avatarUploadDirectory . '/sg_' . $imgDest . '.jpg' );
+               }
+               if ( $typeCode == 1 ) {
+                       exec( 'convert -size ' . $thumbWidth . 'x' . 
$thumbWidth . ' -resize ' . $thumbWidth . ' ' . $imageSrc . ' ' . $border . ' ' 
. $this->avatarUploadDirectory . '/sg_' . $imgDest . '.gif' );
+               }
+               if ( $typeCode == 3 ) {
+                       exec( 'convert -size ' . $thumbWidth . 'x' . 
$thumbWidth . ' -resize ' . $thumbWidth . ' ' . $imageSrc . ' ' . 
$this->avatarUploadDirectory . '/sg_' . $imgDest . '.png' );
+               }
        }
 
        /**
@@ -260,38 +270,62 @@
 
                $this->mSavedFile = "{$dest}/{$saveName}";
 
-               $this->createThumbnail( $tempName, $ext, $this->gift_id . "_l", 
75 );
-               $this->createThumbnail( $tempName, $ext, $this->gift_id . 
"_ml", 50 );
-               $this->createThumbnail( $tempName, $ext, $this->gift_id . "_m", 
30 );
-               $this->createThumbnail( $tempName, $ext, $this->gift_id . "_s", 
16 );
+               $this->createThumbnail( $tempName, $ext, $this->gift_id . '_l', 
75 );
+               $this->createThumbnail( $tempName, $ext, $this->gift_id . 
'_ml', 50 );
+               $this->createThumbnail( $tempName, $ext, $this->gift_id . '_m', 
30 );
+               $this->createThumbnail( $tempName, $ext, $this->gift_id . '_s', 
16 );
 
-               if ( $ext == "JPG" && is_file( $this->avatarUploadDirectory . 
"/sg_" . $this->gift_id . "_l.jpg" ) ) {
+               if ( $ext == 'JPG' && is_file( $this->avatarUploadDirectory . 
'/sg_' . $this->gift_id . '_l.jpg' ) ) {
                        $type = 2;
                }
-               if ( $ext == "GIF" && is_file( $this->avatarUploadDirectory . 
"/sg_" . $this->gift_id . "_l.gif" ) ) {
+               if ( $ext == 'GIF' && is_file( $this->avatarUploadDirectory . 
'/sg_' . $this->gift_id . '_l.gif' ) ) {
                        $type = 1;
                }
-               if ( $ext == "PNG" && is_file( $this->avatarUploadDirectory . 
"/sg_" . $this->gift_id . "_l.png" ) ) {
+               if ( $ext == 'PNG' && is_file( $this->avatarUploadDirectory . 
'/sg_' . $this->gift_id . '_l.png' ) ) {
                        $type = 3;
                }
 
-               if ( $ext != "JPG" ) {
-                       if ( is_file( $this->avatarUploadDirectory . "/sg_" . 
$this->gift_id . "_s.jpg" ) ) unlink( $this->avatarUploadDirectory . "/sg_" . 
$this->gift_id . "_s.jpg" );
-                       if ( is_file( $this->avatarUploadDirectory . "/sg_" . 
$this->gift_id . "_m.jpg" ) ) unlink( $this->avatarUploadDirectory . "/sg_" . 
$this->gift_id . "_m.jpg" );
-                       if ( is_file( $this->avatarUploadDirectory . "/sg_" . 
$this->gift_id . "_l.jpg" ) ) unlink( $this->avatarUploadDirectory . "/sg_" . 
$this->gift_id . "_l.jpg" );
-                       if ( is_file( $this->avatarUploadDirectory . "/sg_" . 
$this->gift_id . "_l.jpg" ) ) unlink( $this->avatarUploadDirectory . "/sg_" . 
$this->gift_id . "_ml.jpg" );
+               if ( $ext != 'JPG' ) {
+                       if ( is_file( $this->avatarUploadDirectory . '/sg_' . 
$this->gift_id . '_s.jpg' ) ) {
+                               unlink( $this->avatarUploadDirectory . '/sg_' . 
$this->gift_id . '_s.jpg' );
+                       }
+                       if ( is_file( $this->avatarUploadDirectory . '/sg_' . 
$this->gift_id . '_m.jpg' ) ) {
+                               unlink( $this->avatarUploadDirectory . '/sg_' . 
$this->gift_id . '_m.jpg' );
+                       }
+                       if ( is_file( $this->avatarUploadDirectory . '/sg_' . 
$this->gift_id . '_l.jpg' ) ) {
+                               unlink( $this->avatarUploadDirectory . '/sg_' . 
$this->gift_id . '_l.jpg' );
+                       }
+                       if ( is_file( $this->avatarUploadDirectory . '/sg_' . 
$this->gift_id . '_l.jpg' ) ) {
+                               unlink( $this->avatarUploadDirectory . '/sg_' . 
$this->gift_id . '_ml.jpg' );
+                       }
                }
-               if ( $ext != "GIF" ) {
-                       if ( is_file( $this->avatarUploadDirectory . "/sg_" . 
$this->gift_id . "_s.gif" ) ) unlink( $this->avatarUploadDirectory . "/sg_" . 
$this->gift_id . "_s.gif" );
-                       if ( is_file( $this->avatarUploadDirectory . "/sg_" . 
$this->gift_id . "_m.gif" ) ) unlink( $this->avatarUploadDirectory . "/sg_" . 
$this->gift_id . "_m.gif" );
-                       if ( is_file( $this->avatarUploadDirectory . "/sg_" . 
$this->gift_id . "_l.gif" ) ) unlink( $this->avatarUploadDirectory . "/sg_" . 
$this->gift_id . "_l.gif" );
-                       if ( is_file( $this->avatarUploadDirectory . "/sg_" . 
$this->gift_id . "_l.gif" ) ) unlink( $this->avatarUploadDirectory . "/sg_" . 
$this->gift_id . "_ml.gif" );
+               if ( $ext != 'GIF' ) {
+                       if ( is_file( $this->avatarUploadDirectory . '/sg_' . 
$this->gift_id . '_s.gif' ) ) {
+                               unlink( $this->avatarUploadDirectory . '/sg_' . 
$this->gift_id . '_s.gif' );
+                       }
+                       if ( is_file( $this->avatarUploadDirectory . '/sg_' . 
$this->gift_id . '_m.gif' ) ) {
+                               unlink( $this->avatarUploadDirectory . '/sg_' . 
$this->gift_id . '_m.gif' );
+                       }
+                       if ( is_file( $this->avatarUploadDirectory . '/sg_' . 
$this->gift_id . '_l.gif' ) ) {
+                               unlink( $this->avatarUploadDirectory . '/sg_' . 
$this->gift_id . '_l.gif' );
+                       }
+                       if ( is_file( $this->avatarUploadDirectory . '/sg_' . 
$this->gift_id . '_l.gif' ) ) {
+                               unlink( $this->avatarUploadDirectory . '/sg_' . 
$this->gift_id . '_ml.gif' );
+                       }
                }
-               if ( $ext != "PNG" ) {
-                       if ( is_file( $this->avatarUploadDirectory . "/sg_" . 
$this->gift_id . "_s.png" ) ) unlink( $this->avatarUploadDirectory . "/sg_" . 
$this->gift_id . "_s.png" );
-                       if ( is_file( $this->avatarUploadDirectory . "/sg_" . 
$this->gift_id . "_m.png" ) ) unlink( $this->avatarUploadDirectory . "/sg_" . 
$this->gift_id . "_m.png" );
-                       if ( is_file( $this->avatarUploadDirectory . "/sg_" . 
$this->gift_id . "_l.png" ) ) unlink( $this->avatarUploadDirectory . "/sg_" . 
$this->gift_id . "_l.png" );
-                       if ( is_file( $this->avatarUploadDirectory . "/sg_" . 
$this->gift_id . "_l.png" ) ) unlink( $this->avatarUploadDirectory . "/sg_" . 
$this->gift_id . "_ml.png" );
+               if ( $ext != 'PNG' ) {
+                       if ( is_file( $this->avatarUploadDirectory . '/sg_' . 
$this->gift_id . '_s.png' ) ) {
+                               unlink( $this->avatarUploadDirectory . '/sg_' . 
$this->gift_id . '_s.png' );
+                       }
+                       if ( is_file( $this->avatarUploadDirectory . '/sg_' . 
$this->gift_id . '_m.png' ) ) {
+                               unlink( $this->avatarUploadDirectory . '/sg_' . 
$this->gift_id . '_m.png' );
+                       }
+                       if ( is_file( $this->avatarUploadDirectory . '/sg_'. 
$this->gift_id . '_l.png' ) ) {
+                               unlink( $this->avatarUploadDirectory . '/sg_' . 
$this->gift_id . '_l.png' );
+                       }
+                       if ( is_file( $this->avatarUploadDirectory . '/sg_' . 
$this->gift_id . '_l.png' ) ) {
+                               unlink( $this->avatarUploadDirectory . '/sg_' . 
$this->gift_id . '_ml.png' );
+                       }
                }
 
                if ( $type < 0 ) {
@@ -315,7 +349,7 @@
        function saveTempUploadedFile( $saveName, $tempName ) {
                global $wgOut;
                $archive = wfImageArchiveDir( $saveName, 'temp' );
-               $stash = $archive . '/' . gmdate( "YmdHis" ) . '!' . $saveName;
+               $stash = $archive . '/' . gmdate( 'YmdHis' ) . '!' . $saveName;
 
                if ( !move_uploaded_file( $tempName, $stash ) ) {
                        $wgOut->fileCopyError( $tempName, $stash );
@@ -347,7 +381,8 @@
                $_SESSION['wsUploadData'][$key] = array(
                        'mUploadTempName' => $stash,
                        'mUploadSize' => $this->mUploadSize,
-                       'mOname' => $this->mOname );
+                       'mOname' => $this->mOname
+               );
                return $key;
        }
 
@@ -375,9 +410,15 @@
 
                $output = '<h2>' . wfMsg( 'ga-uploadsuccess' ) . '</h2>';
                $output .= '<h5>' . wfMsg( 'ga-imagesbelow' ) . '</h5>';
-               if ( $status == 1 ) $ext = 'gif';
-               if ( $status == 2 ) $ext = 'jpg';
-               if ( $status == 3 ) $ext = 'png';
+               if ( $status == 1 ) {
+                       $ext = 'gif';
+               }
+               if ( $status == 2 ) {
+                       $ext = 'jpg';
+               }
+               if ( $status == 3 ) {
+                       $ext = 'png';
+               }
 
                $output .= '<table cellspacing="0" cellpadding="5">
                <tr>
@@ -497,8 +538,11 @@
 
                $cols = intval( $wgUser->getOption( 'cols' ) );
                $ew = $wgUser->getOption( 'editwidth' );
-               if ( $ew ) $ew = " style=\"width:100%\"";
-               else $ew = '';
+               if ( $ew ) {
+                       $ew = ' style="width:100%"';
+               } else {
+                       $ew = '';
+               }
 
                if ( '' != $msg ) {
                        $sub = wfMsg( 'uploaderror' );
@@ -555,18 +599,23 @@
                }
                $wgOut->addHTML( $output );
 
-               $wgOut->addHTML( "
-       <form id='upload' method='post' enctype='multipart/form-data' 
action=\"\">
-       <table border='0'><tr>
+               $wgOut->addHTML( '
+       <form id="upload" method="post" enctype="multipart/form-data" action="">
+       <table border="0">
+               <tr>
 
-       <td style='color:#666666;font-weight:800'>" . wfMsg( 
'ga-file-instructions' ) . wfMsg( 'ga-choosefile' ) . "<br />
-       <input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' 
style='width:100px' />
-       </td></tr><tr>
-       {$source}
-       </tr>
-       <tr><td>
-       <input tabindex='5' type='submit' name='wpUpload' value=\"{$ulb}\" />
-       </td></tr></table></form>\n" );
+                       <td style="color:#666666;font-weight:800">' . wfMsg( 
'ga-file-instructions' ) . wfMsg( 'ga-choosefile' ) . '<br />
+                               <input tabindex="1" type="file" 
name="wpUploadFile" id="wpUploadFile" style="width:100px" />
+                       </td>
+               </tr>
+               <tr>' . $source . '</tr>
+               <tr>
+                       <td>
+                               <input tabindex="5" type="submit" 
name="wpUpload" value="' . $ulb . '" />
+                       </td>
+               </tr>
+               </table></form>' . "\n"
+               );
        }
 
        /**
@@ -627,7 +676,6 @@
                # check mime type, if desired
                global $wgVerifyMimeType;
                if ( $wgVerifyMimeType ) {
-
                        # check mime type against file extension
                        if ( !$this->verifyExtension( $mime, $extension ) ) {
                                return new WikiErrorMsg( 'uploadcorrupt' );
@@ -679,7 +727,7 @@
 
                $match = $magic->isMatchingExtension( $extension, $mime );
 
-               if ( $match === NULL ) {
+               if ( $match === null ) {
                        wfDebug( __METHOD__ . ": no file extension known for 
mime type $mime, passing file\n" );
                        return true;
                } elseif ( $match === true ) {
@@ -705,8 +753,9 @@
                # ugly hack: for text files, always look at the entire file.
                # For binarie field, just check the first K.
 
-               if ( strpos( $mime, 'text/' ) === 0 ) $chunk = 
file_get_contents( $file );
-               else {
+               if ( strpos( $mime, 'text/' ) === 0 ) {
+                       $chunk = file_get_contents( $file );
+               } else {
                        $fp = fopen( $file, 'rb' );
                        $chunk = fread( $fp, 1024 );
                        fclose( $fp );
@@ -714,14 +763,22 @@
 
                $chunk = strtolower( $chunk );
 
-               if ( !$chunk ) return false;
+               if ( !$chunk ) {
+                       return false;
+               }
 
                # decode from UTF-16 if needed (could be used for obfuscation).
-               if ( substr( $chunk, 0, 2 ) == "\xfe\xff" ) $enc = "UTF-16BE";
-               elseif ( substr( $chunk, 0, 2 ) == "\xff\xfe" ) $enc = 
"UTF-16LE";
-               else $enc = NULL;
+               if ( substr( $chunk, 0, 2 ) == "\xfe\xff" ) {
+                       $enc = 'UTF-16BE';
+               } elseif ( substr( $chunk, 0, 2 ) == "\xff\xfe" ) {
+                       $enc = 'UTF-16LE';
+               } else {
+                       $enc = null;
+               }
 
-               if ( $enc ) $chunk = iconv( $enc, "ASCII//IGNORE", $chunk );
+               if ( $enc ) {
+                       $chunk = iconv( $enc, 'ASCII//IGNORE', $chunk );
+               }
 
                $chunk = trim( $chunk );
 
@@ -730,23 +787,25 @@
                wfDebug( __METHOD__ . ": checking for embedded scripts and HTML 
stuff\n" );
 
                # check for HTML doctype
-               if ( eregi( "<!DOCTYPE *X?HTML", $chunk ) ) return true;
+               if ( preg_match( "/<!DOCTYPE *X?HTML/i", $chunk ) ) {
+                       return true;
+               }
 
                /**
-               * Internet Explorer for Windows performs some really stupid 
file type
-               * autodetection which can cause it to interpret valid image 
files as HTML
-               * and potentially execute JavaScript, creating a cross-site 
scripting
-               * attack vectors.
-               *
-               * Apple's Safari browser also performs some unsafe file type 
autodetection
-               * which can cause legitimate files to be interpreted as HTML if 
the
-               * web server is not correctly configured to send the right 
content-type
-               * (or if you're really uploading plain text and octet streams!)
-               *
-               * Returns true if IE is likely to mistake the given file for 
HTML.
-               * Also returns true if Safari would mistake the given file for 
HTML
-               * when served with a generic content-type.
-               */
+                * Internet Explorer for Windows performs some really stupid 
file type
+                * autodetection which can cause it to interpret valid image 
files as HTML
+                * and potentially execute JavaScript, creating a cross-site 
scripting
+                * attack vectors.
+                *
+                * Apple's Safari browser also performs some unsafe file type 
autodetection
+                * which can cause legitimate files to be interpreted as HTML 
if the
+                * web server is not correctly configured to send the right 
content-type
+                * (or if you're really uploading plain text and octet streams!)
+                *
+                * Returns true if IE is likely to mistake the given file for 
HTML.
+                * Also returns true if Safari would mistake the given file for 
HTML
+                * when served with a generic content-type.
+                */
 
                $tags = array(
                        '<body',
@@ -766,20 +825,26 @@
                }
 
                /*
-               * look for javascript
-               */
+                * look for JavaScript
+                */
 
                # resolve entity-refs to look at attributes. may be harsh on 
big files... cache result?
                $chunk = Sanitizer::decodeCharReferences( $chunk );
 
                # look for script-types
-               if ( preg_match( "!type\s*=\s*['\"]?\s*(\w*/)?(ecma|java)!sim", 
$chunk ) ) return true;
+               if ( preg_match( "!type\s*=\s*['\"]?\s*(\w*/)?(ecma|java)!sim", 
$chunk ) ) {
+                       return true;
+               }
 
                # look for html-style script-urls
-               if ( preg_match( 
"!(href|src|data)\s*=\s*['\"]?\s*(ecma|java)script:!sim", $chunk ) ) return 
true;
+               if ( preg_match( 
"!(href|src|data)\s*=\s*['\"]?\s*(ecma|java)script:!sim", $chunk ) ) {
+                       return true;
+               }
 
                # look for css-style script-urls
-               if ( preg_match( "!url\s*\(\s*['\"]?\s*(ecma|java)script:!sim", 
$chunk ) ) return true;
+               if ( preg_match( "!url\s*\(\s*['\"]?\s*(ecma|java)script:!sim", 
$chunk ) ) {
+                       return true;
+               }
 
                wfDebug( __METHOD__ . ": no scripts found\n" );
                return false;
@@ -800,7 +865,7 @@
 
                if ( !$wgAntivirus ) { # disabled?
                        wfDebug( __METHOD__ . ": virus scanner disabled\n" );
-                       return NULL;
+                       return null;
                }
 
                if ( !$wgAntivirusSetup[$wgAntivirus] ) {
@@ -812,14 +877,17 @@
                }
 
                # look up scanner configuration
-               $virus_scanner = $wgAntivirusSetup[$wgAntivirus]["command"]; # 
command pattern
-               $virus_scanner_codes = 
$wgAntivirusSetup[$wgAntivirus]["codemap"]; # exit-code map
-               $msg_pattern = 
$wgAntivirusSetup[$wgAntivirus]["messagepattern"]; # message pattern
+               $virus_scanner = $wgAntivirusSetup[$wgAntivirus]['command']; # 
command pattern
+               $virus_scanner_codes = 
$wgAntivirusSetup[$wgAntivirus]['codemap']; # exit-code map
+               $msg_pattern = 
$wgAntivirusSetup[$wgAntivirus]['messagepattern']; # message pattern
 
                $scanner = $virus_scanner; # copy, so we can resolve the pattern
 
-               if ( strpos( $scanner, "%f" ) === false ) $scanner .= " " . 
wfEscapeShellArg( $file ); # simple pattern: append file to scan
-               else $scanner = str_replace( "%f", wfEscapeShellArg( $file ), 
$scanner ); # complex pattern: replace "%f" with file to scan
+               if ( strpos( $scanner, "%f" ) === false ) {
+                       $scanner .= ' ' . wfEscapeShellArg( $file ); # simple 
pattern: append file to scan
+               } else {
+                       $scanner = str_replace( "%f", wfEscapeShellArg( $file 
), $scanner ); # complex pattern: replace "%f" with file to scan
+               }
 
                wfDebug( __METHOD__ . ": running virus scan: $scanner \n" );
 
@@ -829,37 +897,48 @@
                # NOTE: there's a 50 line workaround to make stderr redirection 
work on windows, too.
                # that does not seem to be worth the pain.
                # Ask me (Duesentrieb) about it if it's ever needed.
-               if ( wfIsWindows() ) exec( "$scanner", $output, $code );
-               else exec( "$scanner 2>&1", $output, $code );
+               if ( wfIsWindows() ) {
+                       exec( "$scanner", $output, $code );
+               } else {
+                       exec( "$scanner 2>&1", $output, $code );
+               }
 
                $exit_code = $code; # remeber for user feedback
 
                if ( $virus_scanner_codes ) { # map exit code to AV_xxx 
constants.
-                       if ( isset( $virus_scanner_codes[$code] ) ) $code = 
$virus_scanner_codes[$code]; # explicite mapping
-                       else if ( isset( $virus_scanner_codes["*"] ) ) $code = 
$virus_scanner_codes["*"]; # fallback mapping
+                       if ( isset( $virus_scanner_codes[$code] ) ) {
+                               $code = $virus_scanner_codes[$code]; # 
explicite mapping
+                       } elseif ( isset( $virus_scanner_codes['*'] ) ) {
+                               $code = $virus_scanner_codes['*']; # fallback 
mapping
+                       }
                }
 
                if ( $code === AV_SCAN_FAILED ) { # scan failed (code was 
mapped to false by $virus_scanner_codes)
                        wfDebug( __METHOD__ . ": failed to scan $file (code 
$exit_code).\n" );
 
-                       if ( $wgAntivirusRequired )
+                       if ( $wgAntivirusRequired ) {
                                return wfMsg( 'virus-scanfailed', $exit_code );
-                       else return NULL;
-               } else if ( $code === AV_SCAN_ABORTED ) { # scan failed because 
filetype is unknown (probably immune)
+                       } else {
+                               return null;
+                       }
+               } elseif ( $code === AV_SCAN_ABORTED ) { # scan failed because 
filetype is unknown (probably immune)
                        wfDebug( __METHOD__ . ": unsupported file type $file 
(code $exit_code).\n" );
-                       return NULL;
-               } else if ( $code === AV_NO_VIRUS ) {
+                       return null;
+               } elseif ( $code === AV_NO_VIRUS ) {
                        wfDebug( __METHOD__ . ": file passed virus scan.\n" );
                        return false; # no virus found
                } else {
                        $output = join( "\n", $output );
                        $output = trim( $output );
 
-                       if ( !$output ) $output = true; # if ther's no output, 
return true
-                       else if ( $msg_pattern ) {
+                       if ( !$output ) {
+                               $output = true; # if there's no output, return 
true
+                       } elseif ( $msg_pattern ) {
                                $groups = array();
                                if ( preg_match( $msg_pattern, $output, $groups 
) ) {
-                                       if ( $groups[1] ) $output = $groups[1];
+                                       if ( $groups[1] ) {
+                                               $output = $groups[1];
+                                       }
                                }
                        }
 

Modified: trunk/extensions/SocialProfile/SystemGifts/SpecialViewSystemGifts.php
===================================================================
--- trunk/extensions/SocialProfile/SystemGifts/SpecialViewSystemGifts.php       
2009-12-19 19:34:06 UTC (rev 60229)
+++ trunk/extensions/SocialProfile/SystemGifts/SpecialViewSystemGifts.php       
2009-12-19 19:45:19 UTC (rev 60230)
@@ -18,7 +18,7 @@
                global $wgUser, $wgOut, $wgRequest, $wgMemc, $wgUploadPath, 
$wgSystemGiftsScripts;
                wfLoadExtensionMessages( 'SystemGifts' );
 
-               $wgOut->addStyle( '../..' . $wgSystemGiftsScripts . 
'/SystemGift.css' );
+               $wgOut->addExtensionStyle( $wgSystemGiftsScripts . 
'/SystemGift.css' );
 
                $output = '';
                $user_name = $wgRequest->getVal( 'user' );
@@ -30,7 +30,7 @@
                 */
                if ( $wgUser->getID() == 0 && $user_name == '' ) {
                        $wgOut->setPageTitle( wfMsg( 'ga-error-title' ) );
-                       $login = SpecialPage::getTitleFor( 'UserLogin' );
+                       $login = SpecialPage::getTitleFor( 'Userlogin' );
                        $wgOut->redirect( $login->escapeFullURL( 
'returnto=Special:ViewSystemGifts' ) );
                        return false;
                }
@@ -38,7 +38,9 @@
                /**
                 * If no user is set in the URL, we assume its the current user
                 */
-               if ( !$user_name ) $user_name = $wgUser->getName();
+               if ( !$user_name ) {
+                       $user_name = $wgUser->getName();
+               }
                $user_id = User::idFromName( $user_name );
                $user = Title::makeTitle( NS_USER, $user_name );
                $user_safe = urlencode( $user_name );
@@ -56,7 +58,9 @@
                * Config for the page
                */
                $per_page = 10;
-               if ( !$page || !is_numeric( $page ) ) $page = 1;
+               if ( !$page || !is_numeric( $page ) ) {
+                       $page = 1;
+               }
                $per_row = 2;
 
                /**
@@ -65,14 +69,13 @@
                $rel = new UserSystemGifts( $user_name );
 
                $gifts = $rel->getUserGiftList( 0, $per_page, $page );
-               $total = $rel->getGiftCountByUsername( $user_name ); // 
count($relationships);
+               $total = $rel->getGiftCountByUsername( $user_name );
 
                $relationship = UserRelationship::getUserRelationshipByID( 
$user_id, $wgUser->getID() );
 
                /**
                 * Show gift count for user
                 */
-
                $output .= $wgOut->setPageTitle( wfMsg( 'ga-title', 
$rel->user_name ) );
 
                $output .= '<div class="back-links">
@@ -105,7 +108,9 @@
 
                                        $output .= '<div class="cleared"></div>
                                </div>';
-                               if ( $x == count( $gifts ) || $x != 1 && $x % 
$per_row == 0 ) $output .= '<div class="cleared"></div>';
+                               if ( $x == count( $gifts ) || $x != 1 && $x % 
$per_row == 0 ) {
+                                       $output .= '<div 
class="cleared"></div>';
+                               }
 
                                $x++;
                        }
@@ -121,23 +126,29 @@
                if ( $numofpages > 1 ) {
                        $output .= '<div class="page-nav">';
                        if ( $page > 1 ) {
-                               $output .= "<a href=\"" . 
$page_link->escapeFullURL( 'user=' . $user_name . '&rel_type=' . $rel_type . 
'&page=' . ( $page - 1 ) ) . "\">" . wfMsg( 'ga-previous' ) . "</a> ";
+                               $output .= '<a href="' . 
$page_link->escapeFullURL( 'user=' . $user_name . '&rel_type=' . $rel_type . 
'&page=' . ( $page - 1 ) ) . '">' . wfMsg( 'ga-previous' ) . '</a> ';
                        }
 
-                       if ( ( $total % $per_page ) != 0 ) $numofpages++;
-                       if ( $numofpages >= 9 && $page < $total ) $numofpages = 
9 + $page;
-                       if ( $numofpages >= ( $total / $per_page ) ) 
$numofpages = ( $total / $per_page ) + 1;
+                       if ( ( $total % $per_page ) != 0 ) {
+                               $numofpages++;
+                       }
+                       if ( $numofpages >= 9 && $page < $total ) {
+                               $numofpages = 9 + $page;
+                       }
+                       if ( $numofpages >= ( $total / $per_page ) ) {
+                               $numofpages = ( $total / $per_page ) + 1;
+                       }
 
                        for ( $i = 1; $i <= $numofpages; $i++ ) {
                                if ( $i == $page ) {
-                                       $output .= ( $i . " " );
+                                       $output .= ( $i . ' ' );
                                } else {
-                                       $output .= "<a href=\"" . 
$page_link->escapeFullURL( 'user=' . $user_name . '&rel_type=' . $rel_type . 
'&page=' . $i ) . "\">$i</a> ";
+                                       $output .= '<a href="' . 
$page_link->escapeFullURL( 'user=' . $user_name . '&rel_type=' . $rel_type . 
'&page=' . $i ) . "\">$i</a> ";
                                }
                        }
 
                        if ( ( $total - ( $per_page * $page ) ) > 0 ) {
-                               $output .= " <a href=\"" . 
$page_link->escapeFullURL( 'user=' . $user_name . '&rel_type=' . $rel_type . 
'&page=' . ( $page + 1 ) ) . "\">" . wfMsg( 'ga-next' ) . "</a>";
+                               $output .= ' <a href="' . 
$page_link->escapeFullURL( 'user=' . $user_name . '&rel_type=' . $rel_type . 
'&page=' . ( $page + 1 ) ) . '">' . wfMsg( 'ga-next' ) . '</a>';
                        }
                        $output .= '</div>';
                }



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to