/**
     * 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'));
        }
    }
    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());
        }
    }
    /**
     * 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);
    }
    /**
     * 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);
    }
    /**
     * 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);
    }