/** * Show the special page * * @param $par Mixed: parameter passed to the page or null */ public function execute( $par ) { global $wgUser, $wgOut, $wgRequest, $wgMemc, $wgUploadPath, $wgUserGiftsScripts; $wgOut->addExtensionStyle( $wgUserGiftsScripts . '/UserGifts.css' ); $this->gift_id = $wgRequest->getInt( 'gift_id' ); $rel = new UserGifts( $wgUser->getName() ); if ( !$this->gift_id || !is_numeric( $this->gift_id ) ) { $wgOut->setPageTitle( wfMsg( 'g-error-title' ) ); $wgOut->addHTML( wfMsg( 'g-error-message-invalid-link' ) ); return false; } if ( $rel->doesUserOwnGift( $wgUser->getID(), $this->gift_id ) == false ) { $wgOut->setPageTitle( wfMsg( 'g-error-title' ) ); $wgOut->addHTML( wfMsg( 'g-error-do-not-own' ) ); return false; } $gift = $rel->getUserGift( $this->gift_id ); if ( $wgRequest->wasPosted() && $_SESSION['alreadysubmitted'] == false ) { $_SESSION['alreadysubmitted'] = true; $user_page_link = Title::makeTitle( NS_USER, $wgUser->getName() ); if ( $rel->doesUserOwnGift( $wgUser->getID(), $this->gift_id ) == true ) { $wgMemc->delete( wfMemcKey( 'user', 'profile', 'gifts', $wgUser->getID() ) ); $rel->deleteGift( $this->gift_id ); } $gift_image = '<img src="' . $wgUploadPath . '/awards/' . Gifts::getGiftImage( $gift['gift_id'], 'l' ) . '" border="0" alt="" />'; $wgOut->setPageTitle( wfMsg( 'g-remove-success-title', $gift['name'] ) ); $out = '<div class="back-links"> <a href="' . $wgUser->getUserPage()->escapeFullURL() . '">' . wfMsg( 'g-back-link', $gift['user_name_to'] ) . '</a> </div> <div class="g-container">' . $gift_image . wfMsg( 'g-remove-success-message', $gift['name'] ) . '<div class="cleared"></div> </div> <div class="g-buttons"> <input type="button" class="site-button" value="' . wfMsg( 'g-main-page' ) . '" size="20" onclick="window.location=\'index.php?title=' . wfMsgForContent( 'mainpage' ) . '\'" /> <input type="button" class="site-button" value="' . wfMsg( 'g-your-profile' ) . '" size="20" onclick="window.location=\'' . $user_page_link->escapeFullURL() . '\'" /> </div>'; $wgOut->addHTML( $out ); } else { $_SESSION['alreadysubmitted'] = false; $wgOut->addHTML( $this->displayForm() ); } }
/** * Show the special page * * @param $par Mixed: parameter passed to the page or null */ public function execute($par) { global $wgMemc, $wgUploadPath; $out = $this->getOutput(); $request = $this->getRequest(); $user = $this->getUser(); // Set the page title, robot policies, etc. $this->setHeaders(); // Add CSS $out->addModuleStyles('ext.socialprofile.usergifts.css'); $this->gift_id = $request->getInt('gift_id'); $rel = new UserGifts($user->getName()); // Make sure that we have a gift ID, can't do anything without that if (!$this->gift_id || !is_numeric($this->gift_id)) { $out->setPageTitle($this->msg('g-error-title')->plain()); $out->addHTML($this->msg('g-error-message-invalid-link')->plain()); return false; } // And also ensure that we're not trying to delete *someone else's* gift(s)... if ($rel->doesUserOwnGift($user->getID(), $this->gift_id) == false) { $out->setPageTitle($this->msg('g-error-title')->plain()); $out->addHTML($this->msg('g-error-do-not-own')->plain()); return false; } $gift = $rel->getUserGift($this->gift_id); if ($request->wasPosted() && $_SESSION['alreadysubmitted'] == false) { $_SESSION['alreadysubmitted'] = true; $user_page_link = Title::makeTitle(NS_USER, $user->getName()); if ($rel->doesUserOwnGift($user->getID(), $this->gift_id) == true) { $wgMemc->delete(wfForeignMemcKey('huiji', '', 'user', 'profile', 'gifts', $user->getID())); $rel->deleteGift($this->gift_id); } $gift_image = '<img src="' . $wgUploadPath . '/awards/' . Gifts::getGiftImage($gift['gift_id'], 'l') . '" border="0" alt="" />'; $out->setPageTitle($this->msg('g-remove-success-title', $gift['name'])->parse()); $out = '<div class="back-links"> <a href="' . htmlspecialchars($user->getUserPage()->getFullURL()) . '">' . $this->msg('g-back-link', $gift['user_name_to'])->parse() . '</a> </div> <div class="g-container">' . $gift_image . $this->msg('g-remove-success-message', $gift['name'])->parse() . '<div class="cleared"></div> </div> <div class="g-buttons"> <input type="button" class="site-button" value="' . $this->msg('g-main-page')->plain() . '" size="20" onclick="window.location=\'index.php?title=' . $this->msg('mainpage')->inContentLanguage()->escaped() . '\'" /> <input type="button" class="site-button" value="' . $this->msg('g-your-profile')->plain() . '" size="20" onclick="window.location=\'' . htmlspecialchars($user_page_link->getFullURL()) . '\'" /> </div>'; $out->addHTML($out); } else { $_SESSION['alreadysubmitted'] = false; $out->addHTML($this->displayForm()); } }