| Index: trunk/extensions/SocialProfile/UserProfile/SpecialUploadAvatar.php |
| — | — | @@ -22,17 +22,15 @@ |
| 23 | 23 | * Constructor |
| 24 | 24 | */ |
| 25 | 25 | public function __construct( $request = null ) { |
| 26 | | - global $wgRequest; |
| 27 | | - |
| 28 | 26 | SpecialPage::__construct( 'UploadAvatar', 'upload', false/* listed? */ ); |
| 29 | | - $this->loadRequest( is_null( $request ) ? $wgRequest : $request ); |
| 30 | 27 | } |
| 31 | 28 | |
| 32 | 29 | /** |
| 33 | 30 | * Let the parent handle most of the request, but specify the Upload |
| 34 | 31 | * class ourselves |
| 35 | 32 | */ |
| 36 | | - protected function loadRequest( $request ) { |
| | 33 | + protected function loadRequest() { |
| | 34 | + $request = $this->getRequest(); |
| 37 | 35 | parent::loadRequest( $request ); |
| 38 | 36 | $this->mUpload = new UploadAvatar(); |
| 39 | 37 | $this->mUpload->initializeFromRequest( $request ); |
| — | — | @@ -45,18 +43,19 @@ |
| 46 | 44 | * @param $params Mixed: parameter(s) passed to the page or null |
| 47 | 45 | */ |
| 48 | 46 | public function execute( $params ) { |
| 49 | | - global $wgOut, $wgUser, $wgUserProfileScripts; |
| | 47 | + global $wgUserProfileScripts; |
| 50 | 48 | |
| 51 | | - $wgOut->addExtensionStyle( $wgUserProfileScripts . '/UserProfile.css' ); |
| | 49 | + $out = $this->getOutput(); |
| | 50 | + $out->addExtensionStyle( $wgUserProfileScripts . '/UserProfile.css' ); |
| 52 | 51 | parent::execute( $params ); |
| 53 | 52 | |
| 54 | 53 | if ( $this->mUploadSuccessful ) { |
| 55 | 54 | // Cancel redirect |
| 56 | | - $wgOut->redirect( '' ); |
| | 55 | + $out->redirect( '' ); |
| 57 | 56 | |
| 58 | 57 | $this->showSuccess( $this->mUpload->mExtension ); |
| 59 | 58 | // Run a hook on avatar change |
| 60 | | - wfRunHooks( 'NewAvatarUploaded', array( $wgUser ) ); |
| | 59 | + wfRunHooks( 'NewAvatarUploaded', array( $this->getUser() ) ); |
| 61 | 60 | } |
| 62 | 61 | } |
| 63 | 62 | |
| — | — | @@ -66,19 +65,20 @@ |
| 67 | 66 | * @param $ext String: file extension (gif, jpg or png) |
| 68 | 67 | */ |
| 69 | 68 | private function showSuccess( $ext ) { |
| 70 | | - global $wgUser, $wgOut, $wgDBname, $wgUploadPath, $wgUploadAvatarInRecentChanges; |
| | 69 | + global $wgDBname, $wgUploadPath, $wgUploadAvatarInRecentChanges; |
| 71 | 70 | |
| | 71 | + $user = $this->getUser(); |
| 72 | 72 | $log = new LogPage( 'avatar' ); |
| 73 | 73 | if ( !$wgUploadAvatarInRecentChanges ) { |
| 74 | 74 | $log->updateRecentChanges = false; |
| 75 | 75 | } |
| 76 | 76 | $log->addEntry( |
| 77 | 77 | 'avatar', |
| 78 | | - $wgUser->getUserPage(), |
| | 78 | + $user->getUserPage(), |
| 79 | 79 | wfMsgForContent( 'user-profile-picture-log-entry' ) |
| 80 | 80 | ); |
| 81 | 81 | |
| 82 | | - $uid = $wgUser->getId(); |
| | 82 | + $uid = $user->getId(); |
| 83 | 83 | |
| 84 | 84 | $output = '<h1>' . wfMsg( 'uploadavatar' ) . '</h1>'; |
| 85 | 85 | $output .= UserProfile::getEditProfileNav( wfMsg( 'user-profile-section-picture' ) ); |
| — | — | @@ -128,7 +128,7 @@ |
| 129 | 129 | $output .= '</table>'; |
| 130 | 130 | $output .= '</div>'; |
| 131 | 131 | |
| 132 | | - $wgOut->addHTML( $output ); |
| | 132 | + $this->getOutput()->addHTML( $output ); |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
| — | — | @@ -141,14 +141,13 @@ |
| 142 | 142 | * @return HTML output |
| 143 | 143 | */ |
| 144 | 144 | protected function getUploadForm( $message = '', $sessionKey = '', $hideIgnoreWarning = false ) { |
| 145 | | - global $wgOut, $wgUser, $wgUseCopyrightUpload; |
| | 145 | + global $wgUseCopyrightUpload; |
| 146 | 146 | |
| 147 | 147 | if ( $message != '' ) { |
| 148 | 148 | $sub = wfMsg( 'uploaderror' ); |
| 149 | | - $wgOut->addHTML( "<h2>{$sub}</h2>\n" . |
| | 149 | + $this->getOutput()->addHTML( "<h2>{$sub}</h2>\n" . |
| 150 | 150 | "<h4 class='error'>{$message}</h4>\n" ); |
| 151 | 151 | } |
| 152 | | - $sk = $wgUser->getSkin(); |
| 153 | 152 | |
| 154 | 153 | $ulb = wfMsg( 'uploadbtn' ); |
| 155 | 154 | |
| — | — | @@ -183,8 +182,16 @@ |
| 184 | 183 | </table>'; |
| 185 | 184 | } |
| 186 | 185 | |
| 187 | | - $output .= '<form id="upload" method="post" enctype="multipart/form-data" action=""> |
| 188 | | - <table border="0"> |
| | 186 | + $output .= '<form id="upload" method="post" enctype="multipart/form-data" action="">'; |
| | 187 | + // The following two lines are delicious copypasta from HTMLForm.php, |
| | 188 | + // function getHiddenFields() and they are required; wpEditToken is, as |
| | 189 | + // of MediaWiki 1.19, checked _unconditionally_ in |
| | 190 | + // SpecialUpload::loadRequest() and having the hidden title doesn't |
| | 191 | + // hurt either |
| | 192 | + // @see https://bugzilla.wikimedia.org/show_bug.cgi?id=30953 |
| | 193 | + $output .= Html::hidden( 'wpEditToken', $this->getUser()->getEditToken(), array( 'id' => 'wpEditToken' ) ) . "\n"; |
| | 194 | + $output .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n"; |
| | 195 | + $output .= '<table border="0"> |
| 189 | 196 | <tr> |
| 190 | 197 | <td> |
| 191 | 198 | <p class="profile-update-title">' . |
| — | — | @@ -218,10 +225,10 @@ |
| 219 | 226 | * @return String: full img HTML tag |
| 220 | 227 | */ |
| 221 | 228 | function getAvatar( $size ) { |
| 222 | | - global $wgUser, $wgDBname, $wgUploadDirectory, $wgUploadPath; |
| | 229 | + global $wgDBname, $wgUploadDirectory, $wgUploadPath; |
| 223 | 230 | $files = glob( |
| 224 | 231 | $wgUploadDirectory . '/avatars/' . $wgDBname . '_' . |
| 225 | | - $wgUser->getID() . '_' . $size . "*" |
| | 232 | + $this->getUser()->getID() . '_' . $size . '*' |
| 226 | 233 | ); |
| 227 | 234 | if ( isset( $files[0] ) && $files[0] ) { |
| 228 | 235 | return "<img src=\"{$wgUploadPath}/avatars/" . |
| — | — | @@ -335,7 +342,7 @@ |
| 336 | 343 | * Create the thumbnails and delete old files |
| 337 | 344 | */ |
| 338 | 345 | public function performUpload( $comment, $pageText, $watch, $user ) { |
| 339 | | - global $wgUploadDirectory, $wgUser, $wgDBname, $wgMemc; |
| | 346 | + global $wgUploadDirectory, $wgDBname, $wgMemc; |
| 340 | 347 | |
| 341 | 348 | $this->avatarUploadDirectory = $wgUploadDirectory . '/avatars'; |
| 342 | 349 | |
| — | — | @@ -356,13 +363,13 @@ |
| 357 | 364 | |
| 358 | 365 | $dest = $this->avatarUploadDirectory; |
| 359 | 366 | |
| 360 | | - $uid = $wgUser->getId(); |
| | 367 | + $uid = $user->getId(); |
| 361 | 368 | $avatar = new wAvatar( $uid, 'l' ); |
| 362 | 369 | // If this is the user's first custom avatar, update statistics (in |
| 363 | 370 | // case if we want to give out some points to the user for uploading |
| 364 | 371 | // their first avatar) |
| 365 | 372 | if ( strpos( $avatar->getAvatarImage(), 'default_' ) !== false ) { |
| 366 | | - $stats = new UserStatsTrack( $uid, $wgUser->getName() ); |
| | 373 | + $stats = new UserStatsTrack( $uid, $user->getName() ); |
| 367 | 374 | $stats->incStatField( 'user_image' ); |
| 368 | 375 | } |
| 369 | 376 | |