/**
  * Show the special page
  *
  * @param $gift_category Mixed: parameter passed to the page or null
  */
 public function execute($gift_category)
 {
     global $wgUserLevels;
     $out = $this->getOutput();
     $user = $this->getUser();
     // If the user doesn't have the required 'awardsmanage' permission, display an error
     if (!$user->isAllowed('awardsmanage')) {
         $out->permissionRequired('awardsmanage');
         return;
     }
     // Show a message if the database is in read-only mode
     if (wfReadOnly()) {
         $out->readOnlyPage();
         return;
     }
     // If user is blocked, s/he doesn't need to access this page
     if ($user->isBlocked()) {
         $out->blockedPage();
         return;
     }
     // Set the robot policies, etc.
     $out->setArticleRelated(false);
     $out->setRobotPolicy('noindex,nofollow');
     $wgUserLevels = '';
     $g = new SystemGifts();
     $g->update_system_gifts();
 }
	/**
	 * Show the special page
	 *
	 * @param $gift_category Mixed: parameter passed to the page or null
	 */
	public function execute( $gift_category ) {
		global $wgUser, $wgOut, $wgUserLevels;

		// If the user doesn't have the required 'awardsmanage' permission, display an error
		if ( !$wgUser->isAllowed( 'awardsmanage' ) ) {
			$wgOut->permissionRequired( 'awardsmanage' );
			return;
		}

		// Show a message if the database is in read-only mode
		if ( wfReadOnly() ) {
			$wgOut->readOnlyPage();
			return;
		}

		// If user is blocked, s/he doesn't need to access this page
		if ( $wgUser->isBlocked() ) {
			$wgOut->blockedPage();
			return;
		}

		$wgUserLevels = '';

		$g = new SystemGifts();
		$g->update_system_gifts();
	}
	/**
	 * Sends notification e-mail to the user with the ID $user_id_to whenever
	 * they get a new system gift (award) if their e-mail address is confirmed
	 * and they have opted in to these notifications on their social
	 * preferences.
	 *
	 * @param $user_id_to Integer: user ID of the recipient
	 * @param $gift_id Integer: system gift ID number
	 */
	public function sendGiftNotificationEmail( $user_id_to, $gift_id ) {
		$gift = SystemGifts::getGift( $gift_id );
		$user = User::newFromId( $user_id_to );
		$user->loadFromDatabase();
		if ( $user->isEmailConfirmed() && $user->getIntOption( 'notifygift', 1 ) ) {
			$gifts_link = SpecialPage::getTitleFor( 'ViewSystemGifts' );
			$update_profile_link = SpecialPage::getTitleFor( 'UpdateProfile' );
			$subject = wfMsgExt( 'system_gift_received_subject', 'parsemag',
				$gift['gift_name']
			);
			if ( trim( $user->getRealName() ) ) {
				$name = $user->getRealName();
			} else {
				$name = $user->getName();
			}
			$body = wfMsgExt( 'system_gift_received_body', 'parsemag',
				$name,
				$gift['gift_name'],
				$gift['gift_description'],
				$gifts_link->getFullURL(),
				$update_profile_link->getFullURL()
			);

			$user->sendMail( $subject, $body );
		}
	}
    /**
     * Show the special page
     *
     * @param $par Mixed: parameter passed to the page or null
     */
    public function execute($par)
    {
        global $wgUser, $wgOut, $wgRequest, $wgUploadPath, $wgSystemGiftsScripts;
        $wgOut->addExtensionStyle($wgSystemGiftsScripts . '/SystemGift.css');
        $output = '';
        // Prevent E_NOTICE
        // If gift ID wasn't passed in the URL parameters or if it's not
        // numeric, display an error message
        $giftId = $wgRequest->getInt('gift_id');
        if (!$giftId || !is_numeric($giftId)) {
            $wgOut->setPageTitle(wfMsg('ga-error-title'));
            $wgOut->addHTML(wfMsg('ga-error-message-invalid-link'));
            return false;
        }
        $gift = UserSystemGifts::getUserGift($giftId);
        if ($gift) {
            if ($gift['status'] == 1) {
                if ($gift['user_name'] == $wgUser->getName()) {
                    $g = new UserSystemGifts($gift['user_name']);
                    $g->clearUserGiftStatus($gift['id']);
                    $g->decNewSystemGiftCount($wgUser->getID());
                }
            }
            // DB stuff
            $dbr = wfGetDB(DB_MASTER);
            $res = $dbr->select('user_system_gift', array('DISTINCT sg_user_name', 'sg_user_id', 'sg_gift_id', 'sg_date'), array("sg_gift_id = {$gift['gift_id']}", "sg_user_name <> '" . $dbr->strencode($gift['user_name']) . "'"), __METHOD__, array('GROUP BY' => 'sg_user_name', 'ORDER BY' => 'sg_date DESC', 'OFFSET' => 0, 'LIMIT' => 6));
            $wgOut->setPageTitle(wfMsg('ga-gift-title', $gift['user_name'], $gift['name']));
            $profileURL = Title::makeTitle(NS_USER, $gift['user_name'])->escapeFullURL();
            $output .= '<div class="back-links">' . wfMsg('ga-back-link', $profileURL, $gift['user_name']) . '</div>';
            $message = $wgOut->parse(trim($gift['description']), false);
            $output .= '<div class="ga-description-container">';
            $giftImage = "<img src=\"{$wgUploadPath}/awards/" . SystemGifts::getGiftImage($gift['gift_id'], 'l') . '" border="0" alt=""/>';
            $output .= "<div class=\"ga-description\">\r\n\t\t\t\t\t{$giftImage}\r\n\t\t\t\t\t<div class=\"ga-name\">{$gift['name']}</div>\r\n\t\t\t\t\t<div class=\"ga-timestamp\">({$gift['timestamp']})</div>\r\n\t\t\t\t\t<div class=\"ga-description-message\">\"{$message}\"</div>";
            $output .= '<div class="cleared"></div>
				</div>';
            $output .= '<div class="ga-recent">
					<div class="ga-recent-title">' . wfMsg('ga-recent-recipients-award') . '</div>
					<div class="ga-gift-count">' . wfMsgExt('ga-gift-given-count', 'parsemag', $gift['gift_count']) . '</div>';
            foreach ($res as $row) {
                $userToId = $row->sg_user_id;
                $avatar = new wAvatar($userToId, 'ml');
                $userNameLink = Title::makeTitle(NS_USER, $row->sg_user_name);
                $output .= '<a href="' . $userNameLink->escapeFullURL() . "\">\r\n\t\t\t\t\t{$avatar->getAvatarURL()}\r\n\t\t\t\t</a>";
            }
            $output .= '<div class="cleared"></div>
				</div>
			</div>';
            $wgOut->addHTML($output);
        } else {
            $wgOut->setPageTitle(wfMsg('ga-error-title'));
            $wgOut->addHTML(wfMsg('ga-error-message-invalid-link'));
        }
    }
Esempio n. 5
0
/**
 * Updates user's points after they've made an edit in a namespace that is
 * listed in the $wgNamespacesForEditPoints array.
 */
function incEditCount($article, $revision, $baseRevId)
{
    global $wgUser, $wgNamespacesForEditPoints, $wgMemc, $wgHuijiPrefix;
    // only keep tally for allowable namespaces
    if (!is_array($wgNamespacesForEditPoints) || in_array($article->getTitle()->getNamespace(), $wgNamespacesForEditPoints)) {
        $stats = new UserStatsTrack($wgUser->getID(), $wgUser->getName());
        $stats->incStatField('edit');
    }
    $dbr = wfGetDB(DB_SLAVE);
    $num = SiteStats::edits();
    $sg = SystemGifts::checkEditsCounts($num);
    $usg = new UserSystemGifts($wgUser->getName());
    if ($sg) {
        $usg->sendSystemGift(17);
    }
    $key = wfForeignMemcKey('huiji', '', 'revision', 'high_edit_site_followed', $wgUser->getName(), $wgHuijiPrefix);
    $wgMemc->incr($key);
    $key = wfForeignMemcKey('huiji', '', 'revision', 'last_edit_user', $article->getTitle()->getArticleId(), $wgHuijiPrefix);
    $wgMemc->delete($key);
    return true;
}
 /**
  * Sends notification echo to the user with the ID $user_id_to whenever
  * they get a new system gift (award) if their e-mail address is confirmed
  * and they have opted in to these notifications on their social
  * preferences.
  *
  * @param $user_id_to Integer: user ID of the recipient
  * @param $gift_id Integer: system gift ID number
  */
 public function sendGiftNotificationEmail($user_id_to, $gift_id)
 {
     $gift = SystemGifts::getGift($gift_id);
     $user = User::newFromId($user_id_to);
     $user->loadFromDatabase();
     //send an echo notification
     $giftsLink = SpecialPage::getTitleFor('ViewSystemGift');
     EchoEvent::create(array('type' => 'system-gift-receive', 'extra' => array('gift-user-id' => $user_id_to, 'gift-id' => $gift_id), 'title' => $giftsLink));
     // if ( $user->isEmailConfirmed() && $user->getIntOption( 'notifygift', 1 ) ) {
     // 	$gifts_link = SpecialPage::getTitleFor( 'ViewSystemGifts' );
     // 	$update_profile_link = SpecialPage::getTitleFor( 'UpdateProfile' );
     // 	$subject = wfMessage( 'system_gift_received_subject',
     // 		$gift['gift_name']
     // 	)->text();
     // 	if ( trim( $user->getRealName() ) ) {
     // 		$name = $user->getRealName();
     // 	} else {
     // 		$name = $user->getName();
     // 	}
     // 	$body = wfMessage( 'system_gift_received_body',
     // 		$name,
     // 		$gift['gift_name'],
     // 		$gift['gift_description'],
     // 		$gifts_link->getFullURL(),
     // 		$update_profile_link->getFullURL()
     // 	)->text();
     // 	// 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' );
     // }
 }
	/**
	 * Displays the main upload form, optionally with a highlighted
	 * error message up at the top.
	 *
	 * @param string $msg as HTML
	 * @access private
	 */
	function mainUploadForm( $msg = '' ) {
		global $wgOut, $wgUser, $wgLang, $wgUploadDirectory, $wgRequest;
		global $wgUseCopyrightUpload;

		$cols = intval( $wgUser->getOption( 'cols' ) );
		$ew = $wgUser->getOption( 'editwidth' );
		if ( $ew ) {
			$ew = ' style="width:100%"';
		} else {
			$ew = '';
		}

		if ( $msg != '' ) {
			$sub = wfMsg( 'uploaderror' );
			$wgOut->addHTML( "<h2>{$sub}</h2>\n" .
				"<h4 class='error'>{$msg}</h4>\n" );
		}

		$sk = $wgUser->getSkin();

		$sourcefilename = wfMsg( 'sourcefilename' );
		$destfilename = wfMsg( 'destfilename' );

		$fd = wfMsg( 'filedesc' );
		$ulb = wfMsg( 'uploadbtn' );

		$iw = wfMsg( 'ignorewarning' );

		$titleObj = SpecialPage::getTitleFor( 'Upload' );
		$action = $titleObj->escapeLocalURL();

		$encDestFile = htmlspecialchars( $this->mDestFile );
		$source = null;

		if ( $wgUseCopyrightUpload ) {
			$source = "
	<td align='right' nowrap='nowrap'>" . wfMsg( 'filestatus' ) . "</td>
	<td><input tabindex='3' type='text' name=\"wpUploadCopyStatus\" value=\"" .
	htmlspecialchars( $this->mUploadCopyStatus ) . "\" size='40' /></td>
	</tr><tr>
	<td align='right'>" . wfMsg( 'filesource' ) . "</td>
	<td><input tabindex='4' type='text' name='wpUploadSource' value=\"" .
	htmlspecialchars( $this->mUploadSource ) . "\" style='width:100px' /></td>
	";
		}

		$watchChecked = $wgUser->getOption( 'watchdefault' )
			? 'checked="checked"'
			: '';

		global $wgUploadPath;
		$gift_image = SystemGifts::getGiftImage( $this->gift_id, 'l' );
		if ( $gift_image != '' ) {
			$output = '<table>
				<tr>
					<td style="color:#666666;font-weight:800">' . wfMsg( 'ga-currentimage' ) . '</td>
				</tr>
				<tr>
					<td>
						<img src="' . $wgUploadPath . '/awards/' . $gift_image . '" border="0" alt="' . wfMsg( 'ga-gift' ) . '" />
					</td>
				</tr>
			</table>
		<br />';
		}
		$wgOut->addHTML( $output );

		$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"
		);
	}
    function displayForm($gift_id)
    {
        global $wgUploadPath;
        $form = '<div><b><a href="' . $this->getTitle()->escapeFullURL() . '">' . wfMsg('ga-viewlist') . '</a></b></div>';
        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">
			<tr>
				<td width="200" class="view-form">' . wfMsg('ga-giftname') . '</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('ga-giftdesc') . '</td>
				<td width="695"><textarea class="createbox" name="gift_description" rows="2" cols="30">' . (isset($gift['gift_description']) ? $gift['gift_description'] : '') . '</textarea></td>
			</tr>
			<tr>
				<td width="200" class="view-form">' . wfMsg('ga-gifttype') . '</td>
				<td width="695">
					<select name="gift_category">' . "\n";
        $g = new SystemGifts();
        foreach ($g->getCategories() as $category => $id) {
            $sel = '';
            if (isset($gift['gift_category']) && $gift['gift_category'] == $id) {
                $sel = ' selected="selected"';
            }
            $indent = "\t\t\t\t\t\t";
            $form .= $indent . '<option' . $sel . " value=\"{$id}\">{$category}</option>\n";
        }
        $form .= "\t\t\t\t\t" . '</select>
				</td>
			</tr>
		<tr>
			<td width="200" class="view-form">' . wfMsg('ga-threshold') . '</td>
			<td width="695"><input type="text" size="25" class="createbox" name="gift_threshold" value="' . (isset($gift['gift_threshold']) ? $gift['gift_threshold'] : '') . '"/></td>
		</tr>';
        if ($gift_id) {
            $sgml = SpecialPage::getTitleFor('SystemGiftManagerLogo');
            $gift_image = '<img src="' . $wgUploadPath . '/awards/' . SystemGifts::getGiftImage($gift_id, 'l') . '" border="0" alt="gift" />';
            $form .= '<tr>
			<td width="200" class="view-form" valign="top">' . wfMsg('ga-giftimage') . '</td>
			<td width="695">' . $gift_image . '<a href="' . $sgml->escapeFullURL('gift_id=' . $gift_id) . '">' . wfMsg('ga-img') . '</a>
			</td>
			</tr>';
        }
        if (isset($gift['gift_id'])) {
            $button = wfMsg('edit');
        } else {
            $button = wfMsg('ga-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;
    }
    function getAwards($user_name)
    {
        global $wgUser, $wgMemc, $wgUserProfileDisplay, $wgUploadPath;
        // If not enabled in site settings, don't display
        if ($wgUserProfileDisplay['awards'] == false) {
            return '';
        }
        $output = '';
        // System gifts
        $sg = new UserSystemGifts($user_name);
        // Try cache
        $sg_key = wfMemcKey('user', 'profile', 'system_gifts', "{$sg->user_id}");
        $data = $wgMemc->get($sg_key);
        if (!$data) {
            wfDebug("Got profile awards for user {$user_name} from DB\n");
            $system_gifts = $sg->getUserGiftList(0, 4);
            $wgMemc->set($sg_key, $system_gifts, 60 * 60 * 4);
        } else {
            wfDebug("Got profile awards for user {$user_name} from cache\n");
            $system_gifts = $data;
        }
        $system_gift_count = $sg->getGiftCountByUsername($user_name);
        $system_gift_link = SpecialPage::getTitleFor('ViewSystemGifts');
        $per_row = 4;
        if ($system_gifts) {
            $x = 1;
            $output .= '<div class="user-section-heading">
				<div class="user-section-title">' . wfMsg('user-awards-title') . '</div>
				<div class="user-section-actions">
					<div class="action-right">';
            if ($system_gift_count > 4) {
                $output .= '<a href="' . $system_gift_link->escapeFullURL('user='******'" rel="nofollow">' . wfMsg('user-view-all') . '</a>';
            }
            $output .= '</div>
					<div class="action-left">';
            if ($system_gift_count > 4) {
                $output .= wfMsg('user-count-separator', '4', $system_gift_count);
            } else {
                $output .= wfMsg('user-count-separator', $system_gift_count, $system_gift_count);
            }
            $output .= '</div>
					<div class="cleared"></div>
				</div>
			</div>
			<div class="cleared"></div>
			<div class="user-gift-container">';
            foreach ($system_gifts as $gift) {
                if ($gift['status'] == 1 && $user_name == $wgUser->getName()) {
                    $sg->clearUserGiftStatus($gift['id']);
                    $wgMemc->delete($sg_key);
                    $sg->decNewSystemGiftCount($wgUser->getID());
                }
                $gift_image = '<img src="' . $wgUploadPath . '/awards/' . SystemGifts::getGiftImage($gift['gift_id'], 'ml') . '" border="0" alt="" />';
                $gift_link = $user = SpecialPage::getTitleFor('ViewSystemGift');
                $class = '';
                if ($gift['status'] == 1) {
                    $class = 'class="user-page-new"';
                }
                $output .= '<a href="' . $gift_link->escapeFullURL('gift_id=' . $gift['id']) . '" ' . $class . " rel=\"nofollow\">\r\n\t\t\t\t\t{$gift_image}\r\n\t\t\t\t</a>";
                if ($x == count($system_gifts) || $x != 1 && $x % $per_row == 0) {
                    $output .= '<div class="cleared"></div>';
                }
                $x++;
            }
            $output .= '</div>';
        }
        return $output;
    }
    /**
     * Show the special page
     *
     * @param $par Mixed: parameter passed to the page or null
     */
    public function execute($par)
    {
        global $wgUploadPath;
        $out = $this->getOutput();
        $user = $this->getUser();
        // Set the page title, robot policies, etc.
        $this->setHeaders();
        // Add CSS
        $out->addModuleStyles('ext.socialprofile.systemgifts.css');
        $output = '';
        // Prevent E_NOTICE
        // If gift ID wasn't passed in the URL parameters or if it's not
        // numeric, display an error message
        $giftId = $this->getRequest()->getInt('gift_id');
        if (!$giftId || !is_numeric($giftId)) {
            $out->setPageTitle($this->msg('ga-error-title')->plain());
            $out->addHTML($this->msg('ga-error-message-invalid-link')->plain());
            return false;
        }
        $gift = UserSystemGifts::getUserGift($giftId);
        if ($gift) {
            if ($gift['status'] == 1) {
                if ($gift['user_name'] == $user->getName()) {
                    $g = new UserSystemGifts($gift['user_name']);
                    $g->clearUserGiftStatus($gift['id']);
                    $g->decNewSystemGiftCount($user->getID());
                }
            }
            // DB stuff
            $dbr = wfGetDB(DB_SLAVE);
            $res = $dbr->select('user_system_gift', array('DISTINCT sg_user_name', 'sg_user_id', 'sg_gift_id', 'sg_date'), array("sg_gift_id = {$gift['gift_id']}", 'sg_user_name <> ' . $dbr->addQuotes($gift['user_name'])), __METHOD__, array('GROUP BY' => 'sg_user_name', 'ORDER BY' => 'sg_date DESC', 'OFFSET' => 0, 'LIMIT' => 6));
            $out->setPageTitle($this->msg('ga-gift-title', $gift['user_name'], $gift['name'])->parse());
            $profileURL = htmlspecialchars(Title::makeTitle(NS_USER, $gift['user_name'])->getFullURL());
            $output .= '<div class="back-links">' . $this->msg('ga-back-link', $profileURL, $gift['user_name'])->text() . '</div>';
            $message = $out->parse(trim($gift['description']), false);
            $output .= '<div class="ga-description-container">';
            $giftImage = "<img src=\"{$wgUploadPath}/awards/" . SystemGifts::getGiftImage($gift['gift_id'], 'l') . '" border="0" alt=""/>';
            $output .= "<div class=\"ga-description\">\n\t\t\t\t\t{$giftImage}\n\t\t\t\t\t<div class=\"ga-name\">{$gift['name']}</div>\n\t\t\t\t\t<div class=\"ga-timestamp\">({$gift['timestamp']})</div>\n\t\t\t\t\t<div class=\"ga-description-message\">{$message}</div>";
            $output .= '<div class="cleared"></div>
				</div>';
            // If someone else in addition to the current user has gotten this
            // award, then and only then show the "Other recipients of this
            // award" header and the list of avatars
            if ($gift['gift_count'] > 1) {
                $output .= '<div class="ga-recent">
					<div class="ga-recent-title">' . $this->msg('ga-recent-recipients-award')->plain() . '</div>
					<div class="ga-gift-count">' . $this->msg('ga-gift-given-count')->numParams($gift['gift_count'])->parse() . '</div>';
                foreach ($res as $row) {
                    $userToId = $row->sg_user_id;
                    $avatar = new wAvatar($userToId, 'ml');
                    $userNameLink = Title::makeTitle(NS_USER, $row->sg_user_name);
                    $output .= '<a href="' . htmlspecialchars($userNameLink->getFullURL()) . "\">\n\t\t\t\t\t{$avatar->getAvatarURL()}\n\t\t\t\t</a>";
                }
                $output .= '<div class="cleared"></div>
				</div>';
                // .ga-recent
            }
            $output .= '</div>';
            $out->addHTML($output);
        } else {
            $out->setPageTitle($this->msg('ga-error-title')->plain());
            $out->addHTML($this->msg('ga-error-message-invalid-link')->plain());
        }
    }
    /**
     * Displays the main upload form, optionally with a highlighted
     * error message up at the top.
     *
     * @param string $msg as HTML
     * @access private
     */
    function mainUploadForm($msg = '')
    {
        global $wgUseCopyrightUpload;
        $out = $this->getOutput();
        if ($msg != '') {
            $sub = $this->msg('uploaderror')->plain();
            $out->addHTML("<h2>{$sub}</h2>\n" . "<h4 class='error'>{$msg}</h4>\n");
        }
        $ulb = $this->msg('uploadbtn')->plain();
        $titleObj = SpecialPage::getTitleFor('Upload');
        $action = htmlspecialchars($titleObj->getLocalURL());
        $encDestFile = htmlspecialchars($this->mDestFile);
        $source = null;
        if ($wgUseCopyrightUpload) {
            $source = "\n\t<td align='right' nowrap='nowrap'>" . $this->msg('filestatus')->plain() . "</td>\n\t<td><input tabindex='3' type='text' name=\"wpUploadCopyStatus\" value=\"" . htmlspecialchars($this->mUploadCopyStatus) . "\" size='40' /></td>\n\t</tr><tr>\n\t<td align='right'>" . $this->msg('filesource')->plain() . "</td>\n\t<td><input tabindex='4' type='text' name='wpUploadSource' value=\"" . htmlspecialchars($this->mUploadSource) . "\" style='width:100px' /></td>\n\t";
        }
        global $wgUploadPath;
        $gift_image = SystemGifts::getGiftImage($this->gift_id, 'l');
        if ($gift_image != '') {
            $output = '<table>
				<tr>
					<td style="color:#666666;font-weight:800">' . $this->msg('ga-currentimage')->plain() . '</td>
				</tr>
				<tr>
					<td>
						<img src="' . $wgUploadPath . '/awards/' . $gift_image . '" border="0" alt="' . $this->msg('ga-gift')->plain() . '" />
					</td>
				</tr>
			</table>
		<br />';
        }
        $out->addHTML($output);
        $out->addHTML('
	<form id="upload" method="post" enctype="multipart/form-data" action="">
	<table border="0">
		<tr>

			<td style="color:#666666;font-weight:800">' . $this->msg('ga-file-instructions')->escaped() . $this->msg('ga-choosefile')->plain() . '<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");
    }
Esempio n. 12
0
 /**
  * Get recently received system gifts (awards) from the user_system_gift
  * and system_gift tables and set them in the appropriate class member
  * variables.
  */
 private function setSystemGiftsRec()
 {
     global $wgUploadPath, $wgLang;
     $dbr = wfGetDB(DB_SLAVE);
     $where = $this->where('sg_user_id');
     $option = $this->option('sg_id');
     $res = $dbr->select(array('user_system_gift', 'system_gift'), array('sg_id', 'sg_user_id', 'sg_user_name', 'UNIX_TIMESTAMP(sg_date) AS item_date', 'gift_name', 'gift_id'), $where, __METHOD__, $option, array('system_gift' => array('INNER JOIN', 'gift_id = sg_gift_id')));
     foreach ($res as $row) {
         global $wgMemc;
         $key = wfForeignMemcKey('huiji', '', 'setSystemGiftsRec', $row->sg_id);
         $html = $wgMemc->get($key);
         $timeago = HuijiFunctions::getTimeAgo($row->item_date) . '前';
         if ($html != '') {
             $html = $this->updateTime($html, $timeago);
         } else {
             $user_title = Title::makeTitle(NS_USER, $row->sg_user_name);
             $system_gift_image = '<img src="' . $wgUploadPath . '/awards/' . SystemGifts::getGiftImage($row->gift_id, 'm') . '" border="0" alt="" />';
             $system_gift_link = SpecialPage::getTitleFor('ViewSystemGift');
             $user_name_short = $wgLang->truncate($row->sg_user_name, 25);
             $avatar = new wAvatar($row->sg_user_id, 'ml');
             $avatarUrl = $avatar->getAvatarURL();
             // $timeago = HuijiFunctions::getTimeAgo($row->item_date).'前';
             /* build html */
             $html = $this->templateParser->processTemplate('user-home-item', array('userAvatar' => $avatarUrl, 'userName' => '<b><a href="' . htmlspecialchars($user_title->getFullURL()) . "\">{$user_name_short}</a></b>", 'timestamp' => $timeago, 'description' => wfMessage('useractivity-award', '<b><a href="' . htmlspecialchars($user_title->getFullURL()) . "\">{$row->sg_user_name}</a></b>", $row->sg_user_name)->text(), 'hasShowcase' => true, 'showcase' => '<a href="' . htmlspecialchars($system_gift_link->getFullURL('gift_id=' . $row->sg_id)) . "\" rel=\"nofollow\">\n\t\t\t\t\t\t\t\t\t\t\t{$system_gift_image}\n\t\t\t\t\t\t\t\t\t\t\t{$row->gift_name}\n\t\t\t\t\t\t\t\t\t</a>\n\t\t\t\t\t\t\t\t\t"));
             $wgMemc->set($key, $html);
         }
         $this->activityLines[] = array('type' => 'system_gift-rec', 'timestamp' => $row->item_date, 'data' => $html);
         $this->items[] = array('id' => $row->sg_id, 'type' => 'system_gift', 'timestamp' => $row->item_date, 'pagetitle' => $row->gift_name, 'namespace' => $row->gift_id, 'username' => $row->sg_user_name, 'userid' => $row->sg_user_id, 'comment' => '-', 'new' => '0', 'minor' => 0);
     }
 }
	/**
	 * Displays the main form for removing a system gift permanently.
	 *
	 * @return String: HTML output
	 */
	function displayForm() {
		global $wgOut, $wgUploadPath;

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

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

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

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

		return $output;
	}
    /**
     * Show the special page
     *
     * @param $par Mixed: parameter passed to the page or null
     */
    public function execute($par)
    {
        global $wgUser, $wgOut, $wgRequest, $wgUploadPath, $wgSystemGiftsScripts;
        $wgOut->addExtensionStyle($wgSystemGiftsScripts . '/SystemGift.css');
        $output = '';
        $user_name = $wgRequest->getVal('user');
        $page = $wgRequest->getVal('page');
        /**
         * Redirect Non-logged in users to Login Page
         * It will automatically return them to the ViewSystemGifts page
         */
        if ($wgUser->getID() == 0 && $user_name == '') {
            $wgOut->setPageTitle(wfMsg('ga-error-title'));
            $login = SpecialPage::getTitleFor('Userlogin');
            $wgOut->redirect($login->escapeFullURL('returnto=Special:ViewSystemGifts'));
            return false;
        }
        /**
         * If no user is set in the URL, we assume it's the current user
         */
        if (!$user_name) {
            $user_name = $wgUser->getName();
        }
        $user_id = User::idFromName($user_name);
        /**
         * Error message for username that does not exist (from URL)
         */
        if ($user_id == 0) {
            $wgOut->setPageTitle(wfMsg('ga-error-title'));
            $wgOut->addHTML(wfMsg('ga-error-message-no-user'));
            return false;
        }
        /**
         * Config for the page
         */
        $per_page = 10;
        if (!$page || !is_numeric($page)) {
            $page = 1;
        }
        $per_row = 2;
        /**
         * Get all Gifts for this user into the array
         */
        $rel = new UserSystemGifts($user_name);
        $gifts = $rel->getUserGiftList(0, $per_page, $page);
        $total = $rel->getGiftCountByUsername($user_name);
        /**
         * Show gift count for user
         */
        $wgOut->setPageTitle(wfMsg('ga-title', $rel->user_name));
        $output .= '<div class="back-links">' . wfMsg('ga-back-link', $wgUser->getUserPage()->escapeFullURL(), $rel->user_name) . '</div>';
        $output .= '<div class="ga-count">' . wfMsgExt('ga-count', 'parsemag', $rel->user_name, $total) . '</div>';
        // Safelinks
        $view_system_gift_link = SpecialPage::getTitleFor('ViewSystemGift');
        if ($gifts) {
            $x = 1;
            foreach ($gifts as $gift) {
                $gift_image = "<img src=\"{$wgUploadPath}/awards/" . SystemGifts::getGiftImage($gift['gift_id'], 'ml') . '" border="0" alt="" />';
                $output .= "<div class=\"ga-item\">\r\n\t\t\t\t\t{$gift_image}\r\n\t\t\t\t\t<a href=\"" . $view_system_gift_link->escapeFullURL('gift_id=' . $gift['id']) . "\">{$gift['gift_name']}</a>";
                if ($gift['status'] == 1) {
                    if ($user_name == $wgUser->getName()) {
                        $rel->clearUserGiftStatus($gift['id']);
                        $rel->decNewSystemGiftCount($wgUser->getID());
                    }
                    $output .= '<span class="ga-new">' . wfMsg('ga-new') . '</span>';
                }
                $output .= '<div class="cleared"></div>
				</div>';
                if ($x == count($gifts) || $x != 1 && $x % $per_row == 0) {
                    $output .= '<div class="cleared"></div>';
                }
                $x++;
            }
        }
        /**
         * Build next/prev nav
         */
        $numofpages = $total / $per_page;
        $page_link = SpecialPage::getTitleFor('ViewSystemGifts');
        if ($numofpages > 1) {
            $output .= '<div class="page-nav">';
            if ($page > 1) {
                $output .= '<a href="' . $page_link->escapeFullURL('user='******'&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;
            }
            for ($i = 1; $i <= $numofpages; $i++) {
                if ($i == $page) {
                    $output .= $i . ' ';
                } else {
                    $output .= '<a href="' . $page_link->escapeFullURL('user='******'&page=' . $i) . "\">{$i}</a> ";
                }
            }
            if ($total - $per_page * $page > 0) {
                $output .= ' <a href="' . $page_link->escapeFullURL('user='******'&page=' . ($page + 1)) . '">' . wfMsg('ga-next') . '</a>';
            }
            $output .= '</div>';
        }
        /**
         * Build next/prev nav
         */
        $wgOut->addHTML($output);
    }
	/**
	 * Get recently received system gifts (awards) from the user_system_gift
	 * and system_gift tables and set them in the appropriate class member
	 * variables.
	 */
	private function setSystemGiftsRec() {
		global $wgUploadPath;

		$dbr = wfGetDB( DB_SLAVE );

		$where = array();

		if ( !empty( $this->rel_type ) ) {
			$users = $dbr->select(
				'user_relationship',
				'r_user_id_relation',
				array(
					'r_user_id' => $this->user_id,
					'r_type' => $this->rel_type
				),
				__METHOD__
			);
			$userArray = array();
			foreach ( $users as $user ) {
				$userArray[] = $user;
			}
			$userIDs = implode( ',', $userArray );
			if ( !empty( $userIDs ) ) {
				$where[] = "sg_user_id IN ($userIDs)";
			}
		}

		if ( !empty( $this->show_current_user ) ) {
			$where['sg_user_id'] = $this->user_id;
		}

		$res = $dbr->select(
			array( 'user_system_gift', 'system_gift' ),
			array(
				'sg_id', 'sg_user_id', 'sg_user_name',
				'UNIX_TIMESTAMP(sg_date) AS item_date', 'gift_name', 'gift_id'
			),
			$where,
			__METHOD__,
			array(
				'ORDER BY' => 'sg_id DESC',
				'LIMIT' => $this->item_max,
				'OFFSET' => 0
			),
			array( 'system_gift' => array( 'INNER JOIN', 'gift_id = sg_gift_id' ) )
		);

		foreach ( $res as $row ) {
			$user_title = Title::makeTitle( NS_USER, $row->sg_user_name );
			$system_gift_image = '<img src="' . $wgUploadPath . '/awards/' .
				SystemGifts::getGiftImage( $row->gift_id, 'm' ) .
				'" border="0" alt="" />';
			$system_gift_link = SpecialPage::getTitleFor( 'ViewSystemGift' );

			$html = wfMsg( 'useractivity-award', "<b><a href=\"{$user_title->escapeFullURL()}\">{$row->sg_user_name}</a></b>" ) .
			'<div class="item">
				<a href="' . $system_gift_link->escapeFullURL( 'gift_id=' . $row->sg_id ) . "\" rel=\"nofollow\">
					{$system_gift_image}
					{$row->gift_name}
				</a>
			</div>";

			$this->activityLines[] = array(
				'type' => 'system_gift',
				'timestamp' => $row->item_date,
				'data' => ' ' . $html
			);

			$this->items[] = array(
				'id' => $row->sg_id,
				'type' => 'system_gift',
				'timestamp' => $row->item_date,
				'pagetitle' => $row->gift_name,
				'namespace' => $row->gift_id,
				'username' => $row->sg_user_name,
				'userid' => $row->sg_user_id,
				'comment' => '-',
				'new' => '0',
				'minor' => 0
			);
		}
	}
    /**
     * Show the special page
     *
     * @param $par Mixed: parameter passed to the page or null
     */
    public function execute($par)
    {
        global $wgUploadPath, $wgUser;
        $out = $this->getOutput();
        $request = $this->getRequest();
        $user = $this->getUser();
        // Set the page title, robot policies, etc.
        $this->setHeaders();
        // Add CSS
        $out->addModuleStyles('ext.socialprofile.systemgifts.css');
        $output = '';
        $user_name = $request->getVal('user');
        if ($user_name) {
            $user = User::newFromName($user_name);
        }
        $page = $request->getInt('page', 1);
        /**
         * Redirect Non-logged in users to Login Page
         * It will automatically return them to the ViewSystemGifts page
         */
        if ($user->getID() == 0 && $user_name == '') {
            $out->setPageTitle($this->msg('ga-error-title')->plain());
            $login = SpecialPage::getTitleFor('Userlogin');
            $out->redirect(htmlspecialchars($login->getFullURL('returnto=Special:ViewSystemGifts')));
            return false;
        }
        /**
         * If no user is set in the URL, we assume it's the current user
         */
        if (!$user_name) {
            $user_name = $user->getName();
        }
        $user_id = User::idFromName($user_name);
        /**
         * Error message for username that does not exist (from URL)
         */
        if ($user_id == 0) {
            $out->setPageTitle($this->msg('ga-error-title')->plain());
            $out->addHTML($this->msg('ga-error-message-no-user')->plain());
            return false;
        }
        /**
         * Config for the page
         */
        $per_page = 20;
        $per_row = 2;
        /**
         * Get all Gifts for this user into the array
         */
        $rel = new UserSystemGifts($user_name);
        $gifts = $rel->getUserGiftList(0, $per_page, $page);
        $total = '<span style="color:#428bca;font-size:20px;font-weight: bold;">' . $rel->getGiftCountByUsername($user_name) . '</span>';
        $curUserObj = User::newFromName($user_name);
        $uuf = new UserUserFollow();
        $follows = $uuf->getFollowList($curUserObj, 1, '', $page);
        $follows[] = array('user_name' => $curUserObj->getName());
        $giftCount = array();
        foreach ($follows as $value) {
            $giftCount[$value['user_name']] = $rel->getGiftCountByUsername($value['user_name']);
        }
        arsort($giftCount);
        $max = count($giftCount);
        $countRes = array();
        $i = 1;
        foreach ($giftCount as $key => $value) {
            $countRes[$key] = $i;
            $i++;
        }
        if ($curUserObj->getName() == $wgUser->getName()) {
            $who = '我';
        } else {
            $who = $curUserObj->getName();
        }
        // print_r($countRes);
        /**
         * Show gift count for user
         */
        $allGiftList = '/wiki/' . SpecialPage::getTitleFor('SystemGiftList');
        $out->setPageTitle($this->msg('ga-title', $rel->user_name)->parse());
        $output .= '<div class="back-links">' . $this->msg('ga-back-link', htmlspecialchars($user->getUserPage()->getFullURL()), $rel->user_name)->text() . '</div>';
        $output .= '<div class="ga-count">' . $this->msg('ga-count', $rel->user_name, $total)->parse() . ', 在' . $who . '的好友中排第<span style="color:#428bca;font-size:20px;font-weight: bold;">' . $countRes[$curUserObj->getName()] . '</span>名</div>';
        $output .= '<div><a href="' . $allGiftList . '">查看所有奖励</a></div><div class="giftlist">';
        // Safelinks
        $view_system_gift_link = SpecialPage::getTitleFor('ViewSystemGift');
        // print_r($gifts);
        // print_r($countRes);
        if ($gifts) {
            foreach ($gifts as $gift) {
                $gift_image = "<div class='img'><img src=\"{$wgUploadPath}/awards/" . SystemGifts::getGiftImage($gift['gift_id'], 'l') . '" border="0" alt="" /></div>';
                $output .= "<div class=\"ga-item have\">\n\t\t\t\t\t<a href=\"" . htmlspecialchars($view_system_gift_link->getFullURL('gift_id=' . $gift['id'])) . "\" data-toggle='popover' data-trigger='hover' title='{$gift['gift_name']}' data-content='{$gift['gift_description']}'>\n                    {$gift_image}";
                if ($gift['status'] == 1) {
                    if ($user_name == $user->getName()) {
                        $rel->clearUserGiftStatus($gift['id']);
                        $rel->decNewSystemGiftCount($user->getID());
                    }
                    /*$output .= '&nbsp<span class="label label-success">' .
                    		$this->msg( 'ga-new' )->plain() . '</span>';*/
                }
                $output .= '<div class="cleared"></div>
				</a></div>';
            }
            $output .= '</div>';
        }
        /**
         * Build next/prev nav
         */
        $pcount = $rel->getGiftCountByUsername($user_name);
        $numofpages = $pcount / $per_page;
        $page_link = $this->getPageTitle();
        if ($numofpages > 1) {
            $output .= '<div class="page-nav-wrapper"><nav class="page-nav pagination">';
            if ($page > 1) {
                $output .= '<li>' . Linker::link($page_link, '<span aria-hidden="true">&laquo;</span>', array(), array('user' => $user_name, 'page' => $page - 1)) . '</li>';
            }
            if ($pcount % $per_page != 0) {
                $numofpages++;
            }
            if ($numofpages >= 9 && $page < $pcount) {
                $numofpages = 9 + $page;
            }
            // if ( $numofpages >= ( $total / $per_page ) ) {
            // 	$numofpages = ( $total / $per_page ) + 1;
            // }
            for ($i = 1; $i <= $numofpages; $i++) {
                if ($i == $page) {
                    $output .= '<li class="active"><a href="#">' . $i . ' <span class="sr-only">(current)</span></a></li>';
                } else {
                    $output .= '<li>' . Linker::link($page_link, $i, array(), array('user' => $user_name, 'page' => $i));
                }
            }
            if ($pcount - $per_page * $page > 0) {
                $output .= '<li>' . Linker::link($page_link, '<span aria-hidden="true">&raquo;</span>', array(), array('user' => $user_name, 'page' => $page + 1)) . '</li>';
            }
            $output .= '</nav></div>';
        }
        /**
         * Output everything
         */
        $out->addHTML($output);
    }
Esempio n. 17
0
 /**
  * Increase a given social statistic field by $val.
  *
  * @param $field String: field name in user_stats database table
  * @param $val Integer: increase $field by this amount, defaults to 1
  */
 function incStatField($field, $val = 1)
 {
     global $wgUser, $wgMemc, $wgSystemGifts, $wgUserStatsTrackWeekly, $wgUserStatsTrackMonthly;
     if (!$wgUser->isAllowed('bot') && !$wgUser->isAnon() && $this->stats_fields[$field]) {
         $dbw = wfGetDB(DB_MASTER);
         $dbw->update('user_stats', array($this->stats_fields[$field] . '=' . $this->stats_fields[$field] . "+{$val}"), array('stats_user_id' => $this->user_id), __METHOD__);
         $this->updateTotalPoints();
         $this->clearCache();
         // update weekly/monthly points
         if (isset($this->point_values[$field]) && !empty($this->point_values[$field])) {
             if ($wgUserStatsTrackWeekly) {
                 $this->updateWeeklyPoints($this->point_values[$field]);
             }
             if ($wgUserStatsTrackMonthly) {
                 $this->updateMonthlyPoints($this->point_values[$field]);
             }
         }
         $s = $dbw->selectRow('user_stats', array($this->stats_fields[$field]), array('stats_user_id' => $this->user_id), __METHOD__);
         $stat_field = $this->stats_fields[$field];
         $field_count = $s->{$stat_field};
         $key = wfForeignMemcKey('huiji', '', 'system_gift', 'id', $field . '-' . $field_count);
         $data = $wgMemc->get($key);
         if ($data != '' && is_int($data)) {
             wfDebug("Got system gift ID from cache\n");
             $systemGiftID = $data;
         } else {
             $g = new SystemGifts();
             $systemGiftID = $g->doesGiftExistForThreshold($field, $field_count);
             if ($systemGiftID) {
                 $wgMemc->set($key, $systemGiftID, 60 * 30);
             }
         }
         if ($systemGiftID) {
             $sg = new UserSystemGifts($this->user_name);
             $sg->sendSystemGift($systemGiftID);
         }
     }
 }
    /**
     * Show the special page
     *
     * @param $par Mixed: parameter passed to the page or null
     */
    public function execute($par)
    {
        global $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.systemgifts.css');
        $output = '';
        $user_name = $request->getVal('user');
        if ($user_name) {
            $user_current = User::newFromName($user_name);
        }
        $page = $request->getInt('page', 1);
        /**
         * Redirect Non-logged in users to Login Page
         * It will automatically return them to the ViewSystemGifts page
         */
        if ($user->getID() == 0 && $user_name == '') {
            $out->setPageTitle($this->msg('ga-error-title')->plain());
            $login = SpecialPage::getTitleFor('Userlogin');
            $out->redirect(htmlspecialchars($login->getFullURL('returnto=Special:ViewSystemGifts')));
            return false;
        }
        /**
         * If no user is set in the URL, we assume it's the current user
         */
        if (!$user_name) {
            $user_name = $user->getName();
        }
        $user_id = User::idFromName($user_name);
        /**
         * Error message for username that does not exist (from URL)
         */
        if ($user_id == 0) {
            $out->setPageTitle($this->msg('ga-error-title')->plain());
            $out->addHTML($this->msg('ga-error-message-no-user')->plain());
            return false;
        }
        /**
         * Config for the page
         */
        $per_page = 10;
        $per_row = 2;
        /**
         * Get all Gifts for this user into the array
         */
        $rel = new UserSystemGifts($user_name);
        $gifts = $rel->getUserGiftList(0, $per_page, $page);
        $total = $rel->getGiftCountByUsername($user_name);
        /**
         * Show gift count for user
         */
        $out->setPageTitle($this->msg('ga-title', $rel->user_name)->parse());
        $output .= '<div class="back-links">' . $this->msg('ga-back-link', htmlspecialchars($user_current->getUserPage()->getFullURL()), $rel->user_name)->text() . '</div>';
        $output .= '<div class="ga-count">' . $this->msg('ga-count', $rel->user_name, $total)->parse() . '</div>';
        // Safelinks
        $view_system_gift_link = SpecialPage::getTitleFor('ViewSystemGift');
        if ($gifts) {
            $x = 1;
            foreach ($gifts as $gift) {
                $gift_image = "<img src=\"{$wgUploadPath}/awards/" . SystemGifts::getGiftImage($gift['gift_id'], 'ml') . '" border="0" alt="" />';
                $output .= "<div class=\"ga-item\">\n\t\t\t\t\t{$gift_image}\n\t\t\t\t\t<a href=\"" . htmlspecialchars($view_system_gift_link->getFullURL('gift_id=' . $gift['id'])) . "\">{$gift['gift_name']}</a>";
                if ($gift['status'] == 1) {
                    if ($user_name == $user->getName()) {
                        $rel->clearUserGiftStatus($gift['id']);
                        $rel->decNewSystemGiftCount($user->getID());
                    }
                    $output .= '&nbsp<span class="label label-success">' . $this->msg('ga-new')->plain() . '</span>';
                }
                $output .= '<div class="cleared"></div>
				</div>';
                if ($x == count($gifts) || $x != 1 && $x % $per_row == 0) {
                    $output .= '<div class="cleared"></div>';
                }
                $x++;
            }
        }
        /**
         * Build next/prev nav
         */
        $numofpages = $total / $per_page;
        $page_link = $this->getPageTitle();
        if ($numofpages > 1) {
            $output .= '<nav class="page-nav pagination">';
            if ($page > 1) {
                $output .= '<li>' . Linker::link($page_link, '<span aria-hidden="true">&laquo;</span>', array(), array('user' => $user_name, 'rel_type' => $rel_type, 'page' => $page - 1)) . '</li>';
            }
            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 .= '<li class="active"><a href="#">' . $i . ' <span class="sr-only">(current)</span></a></li>';
                } else {
                    $output .= '<li>' . Linker::link($page_link, $i, array(), array('user' => $user_name, 'page' => $i));
                }
            }
            if ($total - $per_page * $page > 0) {
                $output .= '<li>' . Linker::link($page_link, '<span aria-hidden="true">&raquo;</span>', array(), array('user' => $user_name, 'rel_type' => $rel_type, 'page' => $page + 1)) . '</li>';
            }
            $output .= '</nav>';
        }
        /**
         * Output everything
         */
        $out->addHTML($output);
    }