/**
	 * Sends the notification about a new gift to the user who received the
	 * gift, if the user wants notifications about new gifts and their e-mail
	 * is confirmed.
	 *
	 * @param $user_id_to Integer: user ID of the receiver of the gift
	 * @param $user_from Mixed: name of the user who sent the gift
	 * @param $gift_id Integer: ID number of the given gift
	 * @param $type Integer: gift type; unused
	 */
	public function sendGiftNotificationEmail( $user_id_to, $user_from, $gift_id, $type ) {
		$gift = Gifts::getGift( $gift_id );
		$user = User::newFromId( $user_id_to );
		$user->loadFromDatabase();
		if ( $user->isEmailConfirmed() && $user->getIntOption( 'notifygift', 1 ) ) {
			$giftsLink = SpecialPage::getTitleFor( 'ViewGifts' );
			$updateProfileLink = SpecialPage::getTitleFor( 'UpdateProfile' );
			if ( trim( $user->getRealName() ) ) {
				$name = $user->getRealName();
			} else {
				$name = $user->getName();
			}
			$subject = wfMsgExt( 'gift_received_subject', 'parsemag',
				$user_from,
				$gift['gift_name']
			);
			$body = wfMsgExt( 'gift_received_body', 'parsemag',
				$name,
				$user_from,
				$gift['gift_name'],
				$giftsLink->getFullURL(),
				$updateProfileLink->getFullURL()
			);

			$user->sendMail( $subject, $body );
		}
	}
Exemplo n.º 2
0
 function canUserManage()
 {
     global $wgUser;
     if ($wgUser->isBlocked() || $wgUser->isAnon()) {
         return false;
     }
     $gift = Gifts::getGift($this->gift_id);
     if ($wgUser->getID() == $gift['creator_user_id'] || in_array('giftadmin', $wgUser->getGroups())) {
         return true;
     }
     return false;
 }
Exemplo n.º 3
0
 /**
  * Sends the (echo) notification about a new gift to the user who received the
  * gift, if the user wants notifications about new gifts and their e-mail
  * is confirmed.
  *
  * @param $user_id_to Integer: user ID of the receiver of the gift
  * @param $user_from Mixed: name of the user who sent the gift
  * @param $gift_id Integer: ID number of the given gift
  * @param $type Integer: gift type; unused
  */
 public function sendGiftNotificationEmail($user_id_to, $user_from, $gift_id, $type)
 {
     $gift = Gifts::getGift($gift_id);
     $user = User::newFromId($user_id_to);
     $user->loadFromDatabase();
     //send an echo notification
     $agent = User::newFromName($user_from);
     $giftsLink = SpecialPage::getTitleFor('ViewGift');
     EchoEvent::create(array('type' => 'gift-receive', 'extra' => array('gift-user-id' => $user_id_to, 'gift-id' => $gift_id), 'agent' => $agent, 'title' => $giftsLink));
     // if ( $user->isEmailConfirmed() && $user->getIntOption( 'notifygift', 1 ) ) {
     // 	$giftsLink = SpecialPage::getTitleFor( 'ViewGifts' );
     // 	$updateProfileLink = SpecialPage::getTitleFor( 'UpdateProfile' );
     // 	if ( trim( $user->getRealName() ) ) {
     // 		$name = $user->getRealName();
     // 	} else {
     // 		$name = $user->getName();
     // 	}
     // 	$subject = wfMessage( 'gift_received_subject',
     // 		$user_from,
     // 		$gift['gift_name']
     // 	)->parse();
     // 	$body = wfMessage( 'gift_received_body',
     // 		$name,
     // 		$user_from,
     // 		$gift['gift_name'],
     // 		$giftsLink->getFullURL(),
     // 		$updateProfileLink->getFullURL()
     // 	)->parse();
     // 	// The email contains HTML, so actually send it out as such, too.
     // 	// That's why this no longer uses User::sendMail().
     // 	// @see https://bugzilla.wikimedia.org/show_bug.cgi?id=68045
     // 	global $wgPasswordSender;
     // 	$sender = new MailAddress( $wgPasswordSender,
     // 		wfMessage( 'emailsender' )->inContentLanguage()->text() );
     // 	$to = new MailAddress( $user );
     // 	UserMailer::send( $to, $sender, $subject, $body, null, 'text/html; charset=UTF-8' );
     // }
 }
	function displayForm( $gift_id ) {
		global $wgUser;

		if ( !$gift_id && !$this->canUserCreateGift() ) {
			return $this->displayGiftList();
		}

		$form = '<div><b><a href="' . $this->getTitle()->escapeFullURL() .
			'">' . wfMsg( 'giftmanager-view' ) . '</a></b></div>';

		if ( $gift_id ) {
			$gift = Gifts::getGift( $gift_id );
			if (
				$wgUser->getID() != $gift['creator_user_id'] &&
				(
					!in_array( 'giftadmin', $wgUser->getGroups() ) &&
					!$wgUser->isAllowed( 'delete' )
				)
			)
			{
				throw new ErrorPageError( 'error', 'badaccess' );
			}
		}

		$form .= '<form action="" method="post" enctype="multipart/form-data" name="gift">';
		$form .= '<table border="0" cellpadding="5" cellspacing="0" width="500">';
		$form .= '<tr>
		<td width="200" class="view-form">' . wfMsg( 'g-gift-name' ) . '</td>
		<td width="695"><input type="text" size="45" class="createbox" name="gift_name" value="' .
			( isset( $gift['gift_name'] ) ? $gift['gift_name'] : '' ) . '"/></td>
		</tr>
		<tr>
		<td width="200" class="view-form" valign="top">' . wfMsg( 'giftmanager-description' ) . '</td>
		<td width="695"><textarea class="createbox" name="gift_description" rows="2" cols="30">' .
			( isset( $gift['gift_description'] ) ? $gift['gift_description'] : '' ) . '</textarea></td>
		</tr>';
		if ( $gift_id ) {
			$creator = Title::makeTitle( NS_USER, $gift['creator_user_name'] );
			$form .= '<tr>
			<td class="view-form">' .
				wfMsgExt( 'g-created-by', 'parsemag', $gift['creator_user_name'] ) .
			'</td>
			<td><a href="' . $creator->escapeFullURL() . '">' .
				$gift['creator_user_name'] . '</a></td>
			</tr>';
		}

		// If the user isn't in the gift admin group, they can only create
		// private gifts
		if ( !$wgUser->isAllowed( 'giftadmin' ) ) {
			$form .= '<input type="hidden" name="access" value="1" />';
		} else {
			$publicSelected = $privateSelected = '';
			if ( isset( $gift['access'] ) && $gift['access'] == 0 ) {
				$publicSelected = ' selected="selected"';
			}
			if ( isset( $gift['access'] ) && $gift['access'] == 1 ) {
				$privateSelected = ' selected="selected"';
			}
			$form .= '<tr>
				<td class="view-form">' . wfMsg( 'giftmanager-access' ) . '</td>
				<td>
				<select name="access">
					<option value="0"' . $publicSelected . '>' .
						wfMsg( 'giftmanager-public' ) .
					'</option>
					<option value="1"' . $privateSelected . '>' .
						wfMsg( 'giftmanager-private' ) .
					'</option>
				</select>
				</td>
			</tr>';
		}

		if ( $gift_id ) {
			global $wgUploadPath;
			$gml = SpecialPage::getTitleFor( 'GiftManagerLogo' );
			$gift_image = '<img src="' . $wgUploadPath . '/awards/' .
				Gifts::getGiftImage( $gift_id, 'l' ) . '" border="0" alt="' .
				wfMsg( 'g-gift' ) . '" />';
			$form .= '<tr>
			<td width="200" class="view-form" valign="top">' . wfMsg( 'giftmanager-giftimage' ) . '</td>
			<td width="695">' . $gift_image .
			'<p>
			<a href="' . $gml->escapeFullURL( 'gift_id=' . $gift_id ) . '">' .
				wfMsg( 'giftmanager-image' ) . '</a>
			</td>
			</tr>';
		}

		if ( isset( $gift['gift_id'] ) ) {
			$button = wfMsg( 'edit' );
		} else {
			$button = wfMsg( 'g-create-gift' );
		}

		$form .= '<tr>
			<td colspan="2">
				<input type="hidden" name="id" value="' . ( isset( $gift['gift_id'] ) ? $gift['gift_id'] : '' ) . '" />
				<input type="button" class="createbox" value="' . $button . '" size="20" onclick="document.gift.submit()" />
				<input type="button" class="createbox" value="' . wfMsg( 'cancel' ) . '" size="20" onclick="history.go(-1)" />
			</td>
		</tr>
		</table>

		</form>';
		return $form;
	}
    /**
     * Display the form for sending out a single gift.
     * Relies on the gift_id URL parameter and bails out if it's not there.
     *
     * @return String: HTML
     */
    function displayFormSingle()
    {
        global $wgUser, $wgOut, $wgRequest, $wgUploadPath;
        $giftId = $wgRequest->getInt('gift_id');
        if (!$giftId || !is_numeric($giftId)) {
            $wgOut->setPageTitle(wfMsg('g-error-title'));
            $wgOut->addHTML(wfMsg('g-error-message-invalid-link'));
            return false;
        }
        $gift = Gifts::getGift($giftId);
        if (empty($gift)) {
            return false;
        }
        if ($gift['access'] == 1 && $wgUser->getID() != $gift['creator_user_id']) {
            return $this->displayFormAll();
        }
        // Safe titles
        $user = Title::makeTitle(NS_USER, $this->user_name_to);
        $giveGiftLink = SpecialPage::getTitleFor('GiveGift');
        $wgOut->setPageTitle(wfMsg('g-give-to-user-title', $gift['gift_name'], $this->user_name_to));
        $gift_image = "<img id=\"gift_image_{$gift['gift_id']}\" src=\"{$wgUploadPath}/awards/" . Gifts::getGiftImage($gift['gift_id'], 'l') . '" border="0" alt="" />';
        $output = '<form action="" method="post" enctype="multipart/form-data" name="gift">
			<div class="g-message">' . wfMsg('g-give-to-user-message', $this->user_name_to, $giveGiftLink->escapeFullURL('user='******'gift_id']}\" class=\"g-container\">\r\n\t\t\t\t{$gift_image}\r\n\t\t\t\t<div class=\"g-title\">{$gift['gift_name']}</div>";
        if ($gift['gift_description']) {
            $output .= '<div class="g-describe">' . $gift['gift_description'] . '</div>';
        }
        $output .= '</div>
			<div class="cleared"></div>
			<div class="g-add-message">' . wfMsg('g-add-message') . '</div>
			<textarea name="message" id="message" rows="4" cols="50"></textarea>
			<div class="g-buttons">
				<input type="hidden" name="gift_id" value="' . $giftId . '" />
				<input type="hidden" name="user_name" value="' . addslashes($this->user_name_to) . '" />
				<input type="button" class="site-button" value="' . wfMsg('g-send-gift') . '" size="20" onclick="document.gift.submit()" />
				<input type="button" class="site-button" value="' . wfMsg('g-cancel') . '" size="20" onclick="history.go(-1)" />
			</div>
		</form>';
        return $output;
    }
	/**
	 * Displays the main form for removing a gift permanently
	 *
	 * @return String: HTML output
	 */
	function displayForm() {
		global $wgOut, $wgUploadPath;

		$gift = Gifts::getGift( $this->gift_id );

		$gift_image = '<img src="' . $wgUploadPath . '/awards/' .
			Gifts::getGiftImage( $this->gift_id, 'l' ) .
			'" border="0" alt="gift" />';

		$wgOut->setPageTitle( wfMsg( 'g-remove-title', $gift['gift_name'] ) );

		$output = '<div class="back-links">
			<a href="' . SpecialPage::getTitleFor( 'GiftManager' )->escapeFullURL() . '">' .
				wfMsg( 'g-viewgiftlist' ) . '</a>
		</div>
		<form action="" method="post" enctype="multipart/form-data" name="form1">
			<div class="g-remove-message">' .
				wfMsg( 'g-delete-message', $gift['gift_name'] ) .
			'</div>
			<div class="g-container">' .
				$gift_image .
				'<div class="g-name">' . $gift['gift_name'] . '</div>
			</div>
			<div class="cleared"></div>
			<div class="g-buttons">
				<input type="button" class="site-button" value="' . wfMsg( 'g-remove' ) . '" size="20" onclick="document.form1.submit()" />
				<input type="button" class="site-button" value="' . wfMsg( 'g-cancel' ) . '" size="20" onclick="history.go(-1)" />
			</div>
		</form>';

		return $output;
	}