/**
     * Displays the form for sending board blasts
     */
    function displayForm()
    {
        $user = $this->getUser();
        $stats = new UserStats($user->getID(), $user->getName());
        $stats_data = $stats->getUserStats();
        $friendCount = $stats_data['friend_count'];
        $foeCount = $stats_data['foe_count'];
        $output = '<div class="board-blast-message-form">
				<h2>' . $this->msg('boardblaststep1')->escaped() . '</h2>
				<form method="post" name="blast" action="">
					<input type="hidden" name="ids" id="ids" />
					<div class="blast-message-text">' . $this->msg('boardblastprivatenote')->escaped() . '</div>
					<textarea name="message" id="message" cols="63" rows="4"></textarea>
				</form>
		</div>
		<div class="blast-nav">
				<h2>' . $this->msg('boardblaststep2')->escaped() . '</h2>
				<div class="blast-nav-links">
					<a href="javascript:void(0);" class="blast-select-all-link">' . $this->msg('boardlinkselectall')->escaped() . '</a> -
					<a href="javascript:void(0);" class="blast-unselect-all-link">' . $this->msg('boardlinkunselectall')->escaped() . '</a> ';
        $output .= '</div>
		</div>';
        $uuf = new UserUserFollow();
        $follows = $uuf->getFollowList($user, 0);
        $output .= '<div id="blast-friends-list" class="blast-friends-list">';
        $x = 1;
        $per_row = 3;
        if (count($follows) > 0) {
            foreach ($follows as $follow) {
                if ($follow['type'] == 1) {
                    $class = 'friend';
                } else {
                    $class = 'foe';
                }
                $id = $follow['user_id'];
                $output .= '<div class="blast-' . $class . "-unselected\" id=\"user-{$id}\">\n\t\t\t\t\t\t{$follow['user_name']}\n\t\t\t\t\t</div>";
                if ($x == count($follows) || $x != 1 && $x % $per_row == 0) {
                    $output .= '<div class="cleared"></div>';
                }
                $x++;
            }
        } else {
            $output .= '<div>' . $this->msg('boardnofriends')->escaped() . '</div>';
        }
        $output .= '</div>

			<div class="cleared"></div>';
        $output .= '<div class="blast-message-box-button">
			<input type="button" value="' . $this->msg('boardsendbutton')->escaped() . '" class="site-button" />
		</div>';
        return $output;
    }
    /**
     * Show the special page
     *
     * @param $params Mixed: parameter(s) passed to the page or null
     */
    public function execute($params)
    {
        global $wgUser;
        $lang = $this->getLanguage();
        $out = $this->getOutput();
        $request = $this->getRequest();
        $user = $this->getUser();
        // Set the page title, robot policies, etc.
        $this->setHeaders();
        // Add CSS
        $out->addModuleStyles('ext.socialprofile.useruserfollows.css');
        // Add JS
        $out->addModuleScripts('ext.socialprofile.useruserfollows.js');
        $output = '';
        /**
         * Get query string variables
         */
        $user_name = $request->getVal('user');
        $rel_type = $request->getInt('rel_type');
        $page = $request->getInt('page');
        /**
         * Redirect Non-logged in users to Login Page
         * It will automatically return them to the ViewRelationships page
         */
        // if ( !$user->isLoggedIn() && $user_name == '' ) {
        // 	$out->setPageTitle( $this->msg( 'ur-error-page-title' )->plain() );
        // 	$login = SpecialPage::getTitleFor( 'Userlogin' );
        // 	$out->redirect( htmlspecialchars( $login->getFullURL( 'returnto=Special:ViewFollows' ) ) );
        // 	return false;
        // }
        /**
         * Set up config for page / default values
         */
        if (!$page || !is_numeric($page)) {
            $page = 1;
        }
        if (!$rel_type || !is_numeric($rel_type)) {
            $rel_type = 2;
        }
        $per_page = 10;
        $per_row = 2;
        /**
         * If no user is set in the URL, we assume its the current user
         */
        if (!$user_name) {
            $user_name = $user->getName();
        }
        $user_id = User::idFromName($user_name);
        $target_user = User::newFromId($user_id);
        $userPage = Title::makeTitle(NS_USER, $user_name);
        /**
         * Error message for username that does not exist (from URL)
         */
        if ($user_id == 0) {
            $out->setPageTitle($this->msg('ur-error-title')->plain());
            $output = '<div class="relationship-error-message">' . $this->msg('ur-error-message-no-user')->plain() . '</div>
			<div class="relationship-request-buttons">
				<input type="button" class="site-button" value="' . $this->msg('ur-main-page')->plain() . '" onclick=\'window.location="index.php?title=' . $this->msg('mainpage')->inContentLanguage()->escaped() . '"\' />';
            if ($user->isLoggedIn()) {
                $output .= '<input type="button" class="site-button" value="' . $this->msg('ur-your-profile')->plain() . '" onclick=\'window.location="' . htmlspecialchars($user->getUserPage()->getFullURL()) . '"\' />';
            }
            $output .= '</div>';
            $out->addHTML($output);
            return false;
        }
        /**
         * Get all relationships
         */
        $uuf = new UserUserFollow();
        $follows = $uuf->getFollowList($target_user, $rel_type, '', $page);
        $star_page = $per_page * ($page - 1);
        $per_follow = array_slice($follows, $star_page, $per_page);
        $followerCount = UserUserFollow::getFollowerCount($target_user);
        $followingCount = UserUserFollow::getFollowingCount($target_user);
        $back_link = Title::makeTitle(NS_USER, $user_name);
        $target = SpecialPage::getTitleFor('ViewFollows');
        $query1 = array('user' => $user_name, 'rel_type' => 1);
        $query2 = array('user' => $user_name, 'rel_type' => 2);
        $blast = SpecialPage::getTitleFor('SendBoardBlast');
        if ($user_name == $wgUser->getName()) {
            $noticestr = '关注我的人';
            $noticedstr = '我关注的人';
        } else {
            $noticestr = '关注' . $user_name . '的人';
            $noticedstr = $user_name . '关注的人';
        }
        if ($rel_type == 1) {
            $out->setPageTitle($this->msg('ur-title-friend', $user_name)->parse());
            $total = $followingCount;
            $target = SpecialPage::getTitleFor('ViewFollows');
            $query1 = array('user' => $user_name, 'rel_type' => 1);
            $query2 = array('user' => $user_name, 'rel_type' => 2);
            $rem = $this->msg('ur-remove-relationship-friend')->plain();
            $output .= '<div class="back-links">
			<a href="' . htmlspecialchars($back_link->getFullURL()) . '">' . $this->msg('ur-backlink', $user_name)->parse() . '</a> | ' . Linker::LinkKnown($target, $noticestr, array(), $query2) . '
		</div>
		<div class="relationship-wrapper"><div class="relationship-count">' . $this->msg('ur-relationship-count-friends', $user_name, $total)->text() . '</div><div class="relationship-list">';
        } else {
            $out->setPageTitle($this->msg('ur-title-foe', $user_name)->parse());
            $total = $followerCount;
            $rem = $this->msg('ur-remove-relationship-foe')->plain();
            $output .= '<div class="back-links">
			<a href="' . htmlspecialchars($back_link->getFullURL()) . '">' . $this->msg('ur-backlink', $user_name)->parse() . '</a> | ' . Linker::LinkKnown($target, $noticedstr, array(), $query1);
            if ($user_name == $wgUser->getName()) {
                $output .= '| ' . Linker::LinkKnown($blast, '向关注我的人群发信息');
            }
            $output .= '</div>
		<div class="relationship-wrapper"><div class="relationship-count">' . $this->msg('ur-relationship-count-foes', $user_name, $total)->text() . '</div><div class="relationship-list">';
        }
        if ($per_follow) {
            $x = 1;
            foreach ($per_follow as $follow) {
                // $indivRelationship = UserRelationship::getUserRelationshipByID(
                // 	$relationship['user_id'],
                // 	$user->getID()
                // );
                $username = $follow['user_name'];
                $userobj = User::newFromName($username);
                $ust = new UserStatus($userobj);
                $allinfo = $ust->getUserAllInfo();
                // Safe titles
                $userPage = Title::makeTitle(NS_USER, $allinfo['username']);
                // $indivFollow = $uuf->checkUserUserFollow($user, User::newFromId($follow['user_id']));
                $is_follow = $allinfo['is_follow'];
                if ($is_follow == 'Y') {
                    $followButton = '<li  class="user-user-follow unfollow" data-username="******"><a><i class="fa fa-minus-square-o"></i>取关</a></li> ';
                } else {
                    $followButton = '<li class="user-user-follow" data-username="******"><i class="fa fa-plus-square-o"></i></i>关注</li> ';
                }
                $userPageURL = htmlspecialchars($userPage->getFullURL());
                // $avatar = new wAvatar( $follow['user_id'], 'ml' );
                // $avatar_img = $avatar->getAvatarURL();
                $avatar_img = $allinfo['url'];
                $user_gender = $allinfo['gender'];
                $user_status = $allinfo['status'];
                $user_count = $allinfo['usercounts'];
                $user_counted = $allinfo['usercounted'];
                $editcount = $allinfo['editcount'];
                // $commonfollow = $allinfo['commonfollow'];
                // $minefollowerhim = $allinfo['minefollowerhim'];
                $user_level = $allinfo['level'];
                $username_length = strlen($allinfo['username']);
                $username_space = stripos($allinfo['username'], ' ');
                if (($username_space == false || $username_space >= "30") && $username_length > 30) {
                    $user_name_display = substr($allinfo['username'], 0, 30) . ' ' . substr($allinfo['username'], 30, 50);
                } else {
                    $user_name_display = $allinfo['username'];
                }
                if ($user_gender == 'male') {
                    $genderIcon = '♂';
                } elseif ($user_gender == 'female') {
                    $genderIcon = '♀';
                } else {
                    $genderIcon = '♂/♀';
                }
                $output .= "<div class=\"relationship-item\">\r\n\t\t\t\t\t<a href=\"{$userPageURL}\" data-name=\"{$user_name_display}\">{$avatar_img}</a>\r\n\t\t\t\t\t<div class=\"relationship-info\">\r\n\t\t\t\t\t\t<div class=\"relationship-name\">\r\n\t\t\t\t\t\t\t<a href=\"{$userPageURL}\">{$user_name_display}</a><i>{$genderIcon}</i><i>{$user_level}</i>\r\n\t\t\t\t\t\t</div>\r\n\t\t\t\t\t<div class=\"relationship-actions\">";
                if (empty($user_status)) {
                    $output .= '<div>这个人很懒</div>';
                } else {
                    $output .= '<div>' . $user_status . '</div>';
                }
                $output .= '<div>关注数:' . $user_count . ' | 被关注:' . $user_counted . ' | 编辑:' . $editcount . '</div>';
                if ($allinfo['username'] != $wgUser->getName()) {
                    $output .= '<ul class="relationship-list-btn">' . $followButton;
                } else {
                    $output .= '<ul class="relationship-list-btn">';
                }
                $target = SpecialPage::getTitleFor('GiveGift');
                $query = array('user' => $follow['user_name']);
                $output .= '<li>' . Linker::LinkKnown($target, '<i class="fa fa-gift"></i>礼物</a>', array(), $query) . '</li> </ul>';
                $output .= '</div>
					<div class="cleared"></div>
				</div>';
                $output .= '</div>';
                if ($x == count($follows) || $x != 1 && $x % $per_row == 0) {
                    $output .= '<div class="cleared"></div>';
                }
                $x++;
            }
        }
        /**
         * Build next/prev nav
         */
        $total = intval(str_replace(',', '', $total));
        $numofpages = $total / $per_page;
        $pageLink = $this->getPageTitle();
        if ($numofpages > 1) {
            $output .= '<nav class="page-nav pagination">';
            if ($page > 1) {
                $output .= '<li>' . Linker::link($pageLink, '<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($pageLink, $i, array(), array('user' => $user_name, 'rel_type' => $rel_type, 'page' => $i)) . '</li>';
                }
            }
            if ($total - $per_page * $page > 0) {
                $output .= '<li>' . Linker::link($pageLink, '<span aria-hidden="true">&raquo;</span>', array(), array('user' => $user_name, 'rel_type' => $rel_type, 'page' => $page + 1)) . '</li>';
            }
            $output .= '</nav></div></div></div></div>';
        }
        $out->addHTML($output);
    }
 /**
  * get the current user's following users
  * @return array
  */
 public function getFollowingUsers()
 {
     if ($this->mFollowingUsers != '') {
         return $this->mFollowingUsers;
     }
     $uuf = new UserUserFollow();
     $this->mFollowingUsers = $uuf->getFollowList($this->mUser, 1);
     //$this->mFollowingUsers = UserUserFollow::getFollowedByUser($this->mUser);
     $cache = self::getUserCache();
     $cache->set($this->mUser->getId(), $this);
     return $this->mFollowingUsers;
 }
    /**
     * 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);
    }