public function execute($par) { // Shortcut by using $par if ($par) { $this->getOutput()->redirect($this->getTitle()->getLinkURL(array('user' => $par))); return; } $this->setHeaders(); $this->outputHeader(); // Parse options $opt = new \FormOptions(); $opt->add('user', ''); $opt->add('delete', ''); $opt->add('reason', ''); $opt->fetchValuesFromRequest($this->getRequest()); // Parse user $user = $opt->getValue('user'); $userObj = \User::newFromName($user); $userExists = $userObj && $userObj->getId() !== 0; // If current task is delete and user is not allowed $canDoAdmin = $this->getUser()->isAllowed('avataradmin'); if ($opt->getValue('delete')) { if (!$canDoAdmin) { throw new \PermissionsError('avataradmin'); } // Delete avatar if the user exists if ($userExists) { if (Avatars::deleteAvatar($userObj)) { global $wgAvatarLogInRC; $logEntry = new \ManualLogEntry('avatar', 'delete'); $logEntry->setPerformer($this->getUser()); $logEntry->setTarget($userObj->getUserPage()); $logEntry->setComment($opt->getValue('reason')); $logId = $logEntry->insert(); $logEntry->publish($logId, $wgAvatarLogInRC ? 'rcandudp' : 'udp'); } } } $this->getOutput()->addModules(array('mediawiki.userSuggest')); $this->showForm($user); if ($userExists) { $haveAvatar = Avatars::hasAvatar($userObj); if ($haveAvatar) { $html = \Xml::tags('img', array('src' => Avatars::getLinkFor($user, 'original') . '&nocache&ver=' . dechex(time()), 'height' => 400), ''); $html = \Xml::tags('p', array(), $html); $this->getOutput()->addHTML($html); // Add a delete button if ($canDoAdmin) { $this->showDeleteForm($user); } } else { $this->getOutput()->addWikiMsg('viewavatar-noavatar'); } } else { if ($user) { $this->getOutput()->addWikiMsg('viewavatar-nouser'); } } }
private function processUpload() { $request = $this->getRequest(); $dataurl = $request->getVal('avatar'); if (!$dataurl || parse_url($dataurl, PHP_URL_SCHEME) !== 'data') { $this->displayMessage($this->msg('avatar-notuploaded')); return false; } $img = Thumbnail::open($dataurl); global $wgMaxAvatarResolution; switch ($img->type) { case IMAGETYPE_GIF: case IMAGETYPE_PNG: case IMAGETYPE_JPEG: break; default: $this->displayMessage($this->msg('avatar-invalid')); return false; } // Must be square if ($img->width !== $img->height) { $this->displayMessage($this->msg('avatar-notsquare')); return false; } // Check if image is too small if ($img->width < 32 || $img->height < 32) { $this->displayMessage($this->msg('avatar-toosmall')); return false; } // Check if image is too big if ($img->width > $wgMaxAvatarResolution || $img->height > $wgMaxAvatarResolution) { $this->displayMessage($this->msg('avatar-toolarge')); return false; } $user = $this->getUser(); Avatars::deleteAvatar($user); // Avatar directories global $wgAvatarUploadDirectory; $uploadDir = $wgAvatarUploadDirectory . '/' . $this->getUser()->getId() . '/'; @mkdir($uploadDir, 0777, true); // We do this to convert format to png $img->createThumbnail($wgMaxAvatarResolution, $uploadDir . 'original.png'); // We only create thumbnail with default resolution here. Others are generated on demand global $wgDefaultAvatarRes; $img->createThumbnail($wgDefaultAvatarRes, $uploadDir . $wgDefaultAvatarRes . '.png'); $img->cleanup(); $this->displayMessage($this->msg('avatar-saved')); global $wgAvatarLogInRC; $logEntry = new \ManualLogEntry('avatar', 'upload'); $logEntry->setPerformer($this->getUser()); $logEntry->setTarget($this->getUser()->getUserPage()); $logId = $logEntry->insert(); $logEntry->publish($logId, $wgAvatarLogInRC ? 'rcandudp' : 'udp'); return true; }