/**
	 * Show the special page
	 *
	 * @param $params Mixed: parameter(s) passed to the page or null
	 */
	public function execute( $params ) {
		global $wgUser, $wgOut, $wgRequest, $wgUserRelationshipScripts, $wgLang;

		$wgOut->addExtensionStyle( $wgUserRelationshipScripts . '/UserRelationship.css' );

		$output = '';

		/**
		 * Get query string variables
		 */
		$user_name = $wgRequest->getVal( 'user' );
		$rel_type = $wgRequest->getInt( 'rel_type' );
		$page = $wgRequest->getInt( 'page' );

		/**
		 * Redirect Non-logged in users to Login Page
		 * It will automatically return them to the ViewRelationships page
		 */
		if ( !$wgUser->isLoggedIn() && $user_name == '' ) {
			$wgOut->setPageTitle( wfMsg( 'ur-error-page-title' ) );
			$login = SpecialPage::getTitleFor( 'Userlogin' );
			$wgOut->redirect( $login->escapeFullURL( 'returnto=Special:ViewRelationships' ) );
			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 = 1;
		}
		$per_page = 50;
		$per_row = 2;

		/**
		 * If no user is set in the URL, we assume its the current user
		 */
		if ( !$user_name ) {
			$user_name = $wgUser->getName();
		}
		$user_id = User::idFromName( $user_name );
		$userPage = Title::makeTitle( NS_USER, $user_name );

		/**
		 * Error message for username that does not exist (from URL)
		 */
		if ( $user_id == 0 ) {
			$wgOut->setPageTitle( wfMsg( 'ur-error-title' ) );
			$out = '<div class="relationship-error-message">' .
				wfMsg( 'ur-error-message-no-user' ) .
			'</div>
			<div class="relationship-request-buttons">
				<input type="button" class="site-button" value="' . wfMsg( 'ur-main-page' ) . '" onclick=\'window.location="index.php?title=' . wfMsgForContent( 'mainpage' ) . '"\' />';
			if ( $wgUser->isLoggedIn() ) {
				$out .= '<input type="button" class="site-button" value="' . wfMsg( 'ur-your-profile' ) . '" onclick=\'window.location="' . $wgUser->getUserPage()->escapeFullURL() . '"\' />';
			}
			$out .= '</div>';
			$wgOut->addHTML( $out );
			return false;
		}

		/**
		 * Get all relationships
		 */
		$rel = new UserRelationship( $user_name );
		$relationships = $rel->getRelationshipList( $rel_type, $per_page, $page );

		$stats = new UserStats( $rel->user_id, $rel->user_name );
		$stats_data = $stats->getUserStats();
		$friend_count = $stats_data['friend_count'];
		$foe_count = $stats_data['foe_count'];

		$back_link = Title::makeTitle( NS_USER, $rel->user_name );
		$inviteContactsLink = SpecialPage::getTitleFor( 'InviteContacts' );

		if ( $rel_type == 1 ) {
			$output .= $wgOut->setPageTitle( wfMsg( 'ur-title-friend', $rel->user_name ) );
			$total = $friend_count;
			$rem = wfMsg( 'ur-remove-relationship-friend' );
			$output .= '<div class="back-links">
			<a href="' . $back_link->escapeFullURL() . '">' .
				wfMsg( 'ur-backlink', $rel->user_name ) .
			'</a>
		</div>
		<div class="relationship-count">' .
			wfMsgExt(
				'ur-relationship-count-friends',
				'parsemag',
				$rel->user_name,
				$total,
				$inviteContactsLink->escapeFullURL()
			) . '</div>';
		} else {
			$output .= $wgOut->setPageTitle( wfMsg( 'ur-title-foe', $rel->user_name ) );
			$total = $foe_count;
			$rem = wfMsg( 'ur-remove-relationship-foe' );
			$output .= '<div class="back-links">
			<a href="' . $back_link->escapeFullURL() . '">' .
				wfMsg( 'ur-backlink', $rel->user_name ) .
			'</a>
		</div>
		<div class="relationship-count">'
			. wfMsgExt(
				'ur-relationship-count-foes',
				'parsemag',
				$rel->user_name,
				$total,
				$inviteContactsLink->escapeFullURL()
			) . '</div>';
		}

		if ( $relationships ) {
			$x = 1;

			foreach ( $relationships as $relationship ) {
				$indivRelationship = UserRelationship::getUserRelationshipByID(
					$relationship['user_id'],
					$wgUser->getID()
				);

				// Safe titles
				$userPage = Title::makeTitle( NS_USER, $relationship['user_name'] );
				$addRelationshipLink = SpecialPage::getTitleFor( 'AddRelationship' );
				$removeRelationshipLink = SpecialPage::getTitleFor( 'RemoveRelationship' );
				$giveGiftLink = SpecialPage::getTitleFor( 'GiveGift' );

				$avatar = new wAvatar( $relationship['user_id'], 'ml' );

				$avatar_img = $avatar->getAvatarURL();

				$user_safe = urlencode( $relationship['user_name'] );

				$username_length = strlen( $relationship['user_name'] );
				$username_space = stripos( $relationship['user_name'], ' ' );

				if ( ( $username_space == false || $username_space >= "30" ) && $username_length > 30 ) {
					$user_name_display = substr( $relationship['user_name'], 0, 30 ) .
						' ' . substr( $relationship['user_name'], 30, 50 );
				} else {
					$user_name_display = $relationship['user_name'];
				}

				$output .= "<div class=\"relationship-item\">
					<a href=\"{$userPage->escapeFullURL()}\">{$avatar_img}</a>
					<div class=\"relationship-info\">
						<div class=\"relationship-name\">
							<a href=\"{$userPage->escapeFullURL()}\">{$user_name_display}</a>
						</div>
					<div class=\"relationship-actions\">";
				if ( $indivRelationship == false ) {
					$output .= $wgLang->pipeList( array(
						'<a href="' . $addRelationshipLink->escapeFullURL( 'user='******'&rel_type=1' ) . '">' . wfMsg( 'ur-add-friend' ) . '</a>',
						'<a href="' . $addRelationshipLink->escapeFullURL( 'user='******'&rel_type=2' ) . '">' . wfMsg( 'ur-add-foe' ) . '</a>',
						''
					) );
				} elseif ( $user_name == $wgUser->getName() ) {
					$output .= '<a href="' . $removeRelationshipLink->escapeFullURL( 'user='******'">' . $rem . '</a>';
					$output .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
				}
				$output .= '<a href="' . $giveGiftLink->escapeFullURL( 'user='******'">' . wfMsg( 'ur-give-gift' ) . '</a>';

				$output .= '</div>
					<div class="cleared"></div>
				</div>';

				$output .= '</div>';
				if ( $x == count( $relationships ) || $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 = SpecialPage::getTitleFor( 'ViewRelationships' );

		if ( $numofpages > 1 ) {
			$output .= '<div class="page-nav">';
			if ( $page > 1 ) {
				$output .= '<a href="' . $pageLink->escapeFullURL( 'user='******'&rel_type=' . $rel_type . '&page=' . ( $page - 1 ) ) . '">' . wfMsg( 'ur-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="' . $pageLink->escapeFullURL( 'user='******'&rel_type=' . $rel_type . '&page=' . $i ) . "\">$i</a> ";
				}
			}

			if ( ( $total - ( $per_page * $page ) ) > 0 ) {
				$output .= ' <a href="' . $pageLink->escapeFullURL( 'user='******'&rel_type=' . $rel_type . '&page=' . ( $page + 1 ) ) . '">' . wfMsg( 'ur-next' ) . '</a>';
			}
			$output .= '</div>';
		}

		$wgOut->addHTML( $output );
	}
	/**
	 * Show the special page
	 *
	 * @param $params Mixed: parameter(s) passed to the page or null
	 */
	public function execute( $params ) {
		global $wgUser, $wgOut, $wgRequest, $wgUserRelationshipScripts;

		// Can't use $this->setHeaders(); here because then it'll set the page
		// title to <removerelationship> and we don't want that, we'll be
		// messing with the page title later on in the code
		$wgOut->setArticleRelated( false );
		$wgOut->setRobotPolicy( 'noindex,nofollow' );

		$wgOut->addExtensionStyle( $wgUserRelationshipScripts . '/UserRelationship.css' );

		$usertitle = Title::newFromDBkey( $wgRequest->getVal( 'user' ) );
		if ( !$usertitle ) {
			$wgOut->setPageTitle( wfMsgHtml( 'ur-error-title' ) );
			$wgOut->addWikiText( wfMsgNoTrans( 'ur-add-no-user' ) );
			return false;
		}

		$this->user_name_to = $usertitle->getText();
		$this->user_id_to = User::idFromName( $this->user_name_to );
		$this->relationship_type = UserRelationship::getUserRelationshipByID(
			$this->user_id_to,
			$wgUser->getID()
		);

		if ( $this->relationship_type == 1 ) {
			$confirmTitle = wfMsg( 'ur-remove-relationship-title-confirm-friend', $this->user_name_to );
			$confirmMsg = wfMsg( 'ur-remove-relationship-message-confirm-friend', $this->user_name_to );
			$error = wfMsg( 'ur-remove-error-not-loggedin-friend' );
			$pending = wfMsg( 'ur-remove-error-message-pending-friend-request', $this->user_name_to );
		} else {
			$confirmTitle = wfMsg( 'ur-remove-relationship-title-confirm-foe', $this->user_name_to );
			$confirmMsg = wfMsg( 'ur-remove-relationship-message-confirm-foe', $this->user_name_to );
			$error = wfMsg( 'ur-remove-error-not-loggedin-foe' );
			$pending = wfMsg( 'ur-remove-error-message-pending-foe-request', $this->user_name_to );
		}

		$out = '';
		if ( $wgUser->getID() == $this->user_id_to ) {
			$wgOut->setPageTitle( wfMsg( 'ur-error-title' ) );
			$out .= '<div class="relationship-error-message">' .
				wfMsg( 'ur-remove-error-message-remove-yourself' ) .
			'</div>
			<div>
				<input type="button" class="site-button" value="' . wfMsg( 'ur-main-page' ) . '" size="20" onclick=\'window.location="index.php?title=' . wfMsgForContent( 'mainpage' ) . '"\' />';
			if ( $wgUser->isLoggedIn() ) {
				$out .= '<input type="button" class="site-button" value="' . wfMsg( 'ur-your-profile' ) . '" size="20" onclick=\'window.location="' . $wgUser->getUserPage()->escapeFullURL() . '"\' />';
			}
			$out .= '</div>';

			$wgOut->addHTML( $out );
		} elseif ( $this->relationship_type == false ) {
			$wgOut->setPageTitle( wfMsg( 'ur-error-title' ) );
			$out .= '<div class="relationship-error-message">' .
				wfMsg( 'ur-remove-error-message-no-relationship', $this->user_name_to ) .
			'</div>
			<div>
				<input type="button" class="site-button" value="' . wfMsg( 'ur-main-page' ) . '" size="20" onclick=\'window.location="index.php?title="' . wfMsgForContent( 'mainpage' ) . '"\' />';
			if ( $wgUser->isLoggedIn() ) {
				$out .= '<input type="button" class="site-button" value="' . wfMsg( 'ur-your-profile' ) . '" size="20" onclick=\'window.location="' . $wgUser->getUserPage()->escapeFullURL() . '"\' />';
			}
			$out .= '</div>';

			$wgOut->addHTML( $out );
		} elseif ( UserRelationship::userHasRequestByID( $this->user_id_to, $wgUser->getID() ) == true ) {
			$wgOut->setPageTitle( wfMsg( 'ur-error-title' ) );
			$out .= '<div class="relationship-error-message">' .
				$pending .
				'</div>
			<div>
				<input type="button" class="site-button" value="' . wfMsg( 'ur-main-page' ) . '" size="20" onclick=\'window.location="index.php?title="' . wfMsgForContent( 'mainpage' ) . '"\' />';
			if ( $wgUser->isLoggedIn() ) {
				$out .= '<input type="button" class="site-button" value="' . wfMsg( 'ur-your-profile' ) . '" size="20" onclick=\'window.location="' . $wgUser->getUserPage()->escapeFullURL() . '"\' />';
			}
			$out .= '</div>';

			$wgOut->addHTML( $out );
		} elseif ( $wgUser->getID() == 0 ) {
			$wgOut->setPageTitle( wfMsg( 'ur-error-title' ) );
			$out .= '<div class="relationship-error-message">' .
				$error .
			'</div>
			<div>
				<input type="button" class="site-button" value="' . wfMsg( 'ur-main-page' ) . '" size="20" onclick=\'window.location="index.php?title="' . wfMsgForContent( 'mainpage' ) . '"\' />';
			if ( $wgUser->isLoggedIn() ) {
				$out .= '<input type="button" class="site-button" value="' . wfMsg( 'ur-your-profile' ) . '" size="20" onclick=\'window.location="' . $wgUser->getUserPage()->escapeFullURL() . '"\' />';
			}
			$out .= '</div>';

			$wgOut->addHTML( $out );
		} else {
			$rel = new UserRelationship( $wgUser->getName() );
	 		if ( $wgRequest->wasPosted() && $_SESSION['alreadysubmitted'] == false ) {
				$_SESSION['alreadysubmitted'] = true;
				$rel->removeRelationshipByUserID(
					$this->user_id_to,
					$wgUser->getID()
				);
				$rel->sendRelationshipRemoveEmail(
					$this->user_id_to,
					$wgUser->getName(),
					$this->relationship_type
				);
				$avatar = new wAvatar( $this->user_id_to, 'l' );

				$wgOut->setPageTitle( $confirmTitle );

				$out .= "<div class=\"relationship-action\">
					{$avatar->getAvatarURL()}" .
					$confirmMsg .
					"<div class=\"relationship-buttons\">
						<input type=\"button\" class=\"site-button\" value=\"" . wfMsg( 'ur-main-page' ) . "\" size=\"20\" onclick=\"window.location='index.php?title=" . wfMsgForContent( 'mainpage' ) . "'\"/>
						<input type=\"button\" class=\"site-button\" value=\"" . wfMsg( 'ur-your-profile' ) . "\" size=\"20\" onclick=\"window.location='" . $wgUser->getUserPage()->escapeFullURL() . "'\"/>
					</div>
					<div class=\"cleared\"></div>
					</div>";

				$wgOut->addHTML( $out );
			} else {
				$_SESSION['alreadysubmitted'] = false;
				$wgOut->addHTML( $this->displayForm() );
			}

		}
	}
    /**
     * Show the special page
     *
     * @param $params Mixed: parameter(s) passed to the page or null
     */
    public function execute($params)
    {
        $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.userrelationship.css');
        $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:ViewRelationships')));
            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 = 1;
        }
        $per_page = 50;
        $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);
        $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
         */
        $rel = new UserRelationship($user_name);
        $relationships = $rel->getRelationshipList($rel_type, $per_page, $page);
        $stats = new UserStats($rel->user_id, $rel->user_name);
        $stats_data = $stats->getUserStats();
        $friend_count = $stats_data['friend_count'];
        $foe_count = $stats_data['foe_count'];
        $back_link = Title::makeTitle(NS_USER, $rel->user_name);
        if ($rel_type == 1) {
            $out->setPageTitle($this->msg('ur-title-friend', $rel->user_name)->parse());
            $total = $friend_count;
            $rem = $this->msg('ur-remove-relationship-friend')->plain();
            $output .= '<div class="back-links">
			<a href="' . htmlspecialchars($back_link->getFullURL()) . '">' . $this->msg('ur-backlink', $rel->user_name)->parse() . '</a>
		</div>
		<div class="relationship-count">' . $this->msg('ur-relationship-count-friends', $rel->user_name, $total)->text() . '</div>';
        } else {
            $out->setPageTitle($this->msg('ur-title-foe', $rel->user_name)->parse());
            $total = $foe_count;
            $rem = $this->msg('ur-remove-relationship-foe')->plain();
            $output .= '<div class="back-links">
			<a href="' . htmlspecialchars($back_link->getFullURL()) . '">' . $this->msg('ur-backlink', $rel->user_name)->parse() . '</a>
		</div>
		<div class="relationship-count">' . $this->msg('ur-relationship-count-foes', $rel->user_name, $total)->text() . '</div>';
        }
        if ($relationships) {
            $x = 1;
            foreach ($relationships as $relationship) {
                $indivRelationship = UserRelationship::getUserRelationshipByID($relationship['user_id'], $user->getID());
                // Safe titles
                $userPage = Title::makeTitle(NS_USER, $relationship['user_name']);
                $addRelationshipLink = SpecialPage::getTitleFor('AddRelationship');
                $removeRelationshipLink = SpecialPage::getTitleFor('RemoveRelationship');
                $giveGiftLink = SpecialPage::getTitleFor('GiveGift');
                $userPageURL = htmlspecialchars($userPage->getFullURL());
                $avatar = new wAvatar($relationship['user_id'], 'ml');
                $avatar_img = $avatar->getAvatarURL();
                $username_length = strlen($relationship['user_name']);
                $username_space = stripos($relationship['user_name'], ' ');
                if (($username_space == false || $username_space >= "30") && $username_length > 30) {
                    $user_name_display = substr($relationship['user_name'], 0, 30) . ' ' . substr($relationship['user_name'], 30, 50);
                } else {
                    $user_name_display = $relationship['user_name'];
                }
                $output .= "<div class=\"relationship-item\">\n\t\t\t\t\t<a href=\"{$userPageURL}\">{$avatar_img}</a>\n\t\t\t\t\t<div class=\"relationship-info\">\n\t\t\t\t\t\t<div class=\"relationship-name\">\n\t\t\t\t\t\t\t<a href=\"{$userPageURL}\">{$user_name_display}</a>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t<div class=\"relationship-actions\">";
                if ($indivRelationship == false) {
                    $output .= $lang->pipeList(array(Linker::link($addRelationshipLink, $this->msg('ur-add-friend')->plain(), array(), array('user' => $relationship['user_name'], 'rel_type' => 1)), Linker::link($addRelationshipLink, $this->msg('ur-add-foe')->plain(), array(), array('user' => $relationship['user_name'], 'rel_type' => 2)), ''));
                } elseif ($user_name == $user->getName()) {
                    $output .= Linker::link($removeRelationshipLink, $rem, array(), array('user' => $relationship['user_name']));
                    $output .= $this->msg('pipe-separator')->escaped();
                }
                $output .= Linker::link($giveGiftLink, $this->msg('ur-give-gift')->plain(), array(), array('user' => $relationship['user_name']));
                $output .= '</div>
					<div class="cleared"></div>
				</div>';
                $output .= '</div>';
                if ($x == count($relationships) || $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 .= '<div class="page-nav">';
            if ($page > 1) {
                $output .= Linker::link($pageLink, $this->msg('ur-previous')->plain(), array(), array('user' => $user_name, 'rel_type' => $rel_type, 'page' => $page - 1)) . $this->msg('word-separator')->plain();
            }
            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 .= Linker::link($pageLink, $i, array(), array('user' => $user_name, 'rel_type' => $rel_type, 'page' => $i)) . $this->msg('word-separator')->plain();
                }
            }
            if ($total - $per_page * $page > 0) {
                $output .= $this->msg('word-separator')->plain() . Linker::link($pageLink, $this->msg('ur-next')->plain(), array(), array('user' => $user_name, 'rel_type' => $rel_type, 'page' => $page + 1));
            }
            $output .= '</div>';
        }
        $out->addHTML($output);
    }
    /**
     * Get the header for the social profile page, which includes the user's
     * points and user level (if enabled in the site configuration) and lots
     * more.
     *
     * @param $user_id Integer: user ID
     * @param $user_name String: user name
     */
    function getProfileTop($user_id, $user_name)
    {
        global $wgTitle, $wgUser, $wgUploadPath, $wgLang;
        global $wgUserLevels;
        $stats = new UserStats($user_id, $user_name);
        $stats_data = $stats->getUserStats();
        $user_level = new UserLevel($stats_data['points']);
        $level_link = Title::makeTitle(NS_HELP, wfMsgForContent('user-profile-userlevels-link'));
        if (!$this->profile_data) {
            $profile = new UserProfile($user_name);
            $this->profile_data = $profile->getProfile();
        }
        $profile_data = $this->profile_data;
        // Variables and other crap
        $page_title = $wgTitle->getText();
        $title_parts = explode('/', $page_title);
        $user = $title_parts[0];
        $id = User::idFromName($user);
        $user_safe = urlencode($user);
        // Safe urls
        $add_relationship = SpecialPage::getTitleFor('AddRelationship');
        $remove_relationship = SpecialPage::getTitleFor('RemoveRelationship');
        $give_gift = SpecialPage::getTitleFor('GiveGift');
        $send_board_blast = SpecialPage::getTitleFor('SendBoardBlast');
        $update_profile = SpecialPage::getTitleFor('UpdateProfile');
        $watchlist = SpecialPage::getTitleFor('Watchlist');
        $contributions = SpecialPage::getTitleFor('Contributions', $user);
        $send_message = SpecialPage::getTitleFor('UserBoard');
        $upload_avatar = SpecialPage::getTitleFor('UploadAvatar');
        $user_page = Title::makeTitle(NS_USER, $user);
        $user_social_profile = Title::makeTitle(NS_USER_PROFILE, $user);
        $user_wiki = Title::makeTitle(NS_USER_WIKI, $user);
        if ($id != 0) {
            $relationship = UserRelationship::getUserRelationshipByID($id, $wgUser->getID());
        }
        $avatar = new wAvatar($this->user_id, 'l');
        wfDebug('profile type: ' . $profile_data['user_page_type'] . "\n");
        $output = '';
        if ($this->isOwner()) {
            $toggle_title = SpecialPage::getTitleFor('ToggleUserPage');
            if ($this->profile_data['user_page_type'] == 1) {
                $toggleMessage = wfMsg('user-type-toggle-old');
            } else {
                $toggleMessage = wfMsg('user-type-toggle-new');
            }
            $output .= '<div id="profile-toggle-button">
				<a href="' . $toggle_title->escapeFullURL() . '" rel="nofollow">' . $toggleMessage . '</a>
			</div>';
        }
        $output .= '<div id="profile-image">
			<img src="' . $wgUploadPath . '/avatars/' . $avatar->getAvatarImage() . '" alt="" border="0" />
		</div>';
        $output .= '<div id="profile-right">';
        $output .= '<div id="profile-title-container">
				<div id="profile-title">' . $user_name . '</div>';
        if ($wgUserLevels) {
            $output .= '<div id="points-level">
					<a href="' . $level_link->escapeFullURL() . '">' . wfMsgExt('user-profile-points', 'parsemag', $stats_data['points']) . '</a>
					</div>
					<div id="honorific-level">
						<a href="' . $level_link->escapeFullURL() . '" rel="nofollow">(' . $user_level->getLevelName() . ')</a>
					</div>';
        }
        $output .= '<div class="cleared"></div>
			</div>
			<div class="profile-actions">';
        if ($this->isOwner()) {
            $output .= $wgLang->pipeList(array('<a href="' . $update_profile->escapeFullURL() . '">' . wfMsg('user-edit-profile') . '</a>', '<a href="' . $upload_avatar->escapeFullURL() . '">' . wfMsg('user-upload-avatar') . '</a>', '<a href="' . $watchlist->escapeFullURL() . '">' . wfMsg('user-watchlist') . '</a>', ''));
        } elseif ($wgUser->isLoggedIn()) {
            if ($relationship == false) {
                $output .= $wgLang->pipeList(array('<a href="' . $add_relationship->escapeFullURL('user='******'&rel_type=1') . '" rel="nofollow">' . wfMsg('user-add-friend') . '</a>', '<a href="' . $add_relationship->escapeFullURL('user='******'&rel_type=2') . '" rel="nofollow">' . wfMsg('user-add-foe') . '</a>', ''));
            } else {
                if ($relationship == 1) {
                    $output .= $wgLang->pipeList(array('<a href="' . $remove_relationship->escapeFullURL('user='******'">' . wfMsg('user-remove-friend') . '</a>', ''));
                }
                if ($relationship == 2) {
                    $output .= $wgLang->pipeList(array('<a href="' . $remove_relationship->escapeFullURL('user='******'">' . wfMsg('user-remove-foe') . '</a>', ''));
                }
            }
            global $wgUserBoard;
            if ($wgUserBoard) {
                $output .= '<a href="' . $send_message->escapeFullURL('user='******'&conv=' . $user_safe) . '" rel="nofollow">' . wfMsg('user-send-message') . '</a>';
                $output .= wfMsgExt('pipe-separator', 'escapenoentities');
            }
            $output .= '<a href="' . $give_gift->escapeFullURL('user='******'" rel="nofollow">' . wfMsg('user-send-gift') . '</a>';
            $output .= wfMsgExt('pipe-separator', 'escapenoentities');
        }
        $output .= '<a href="' . $contributions->escapeFullURL() . '" rel="nofollow">' . wfMsg('user-contributions') . '</a> ';
        // Links to User:user_name from User_profile:
        if ($wgTitle->getNamespace() == NS_USER_PROFILE && $this->profile_data['user_id'] && $this->profile_data['user_page_type'] == 0) {
            $output .= '| <a href="' . $user_page->escapeFullURL() . '" rel="nofollow">' . wfMsg('user-page-link') . '</a> ';
        }
        // Links to User:user_name from User_profile:
        if ($wgTitle->getNamespace() == NS_USER && $this->profile_data['user_id'] && $this->profile_data['user_page_type'] == 0) {
            $output .= '| <a href="' . $user_social_profile->escapeFullURL() . '" rel="nofollow">' . wfMsg('user-social-profile-link') . '</a> ';
        }
        if ($wgTitle->getNamespace() == NS_USER && (!$this->profile_data['user_id'] || $this->profile_data['user_page_type'] == 1)) {
            $output .= '| <a href="' . $user_wiki->escapeFullURL() . '" rel="nofollow">' . wfMsg('user-wiki-link') . '</a>';
        }
        $output .= '</div>

		</div>';
        return $output;
    }
Esempio n. 5
0
    /**
     * Get the header for the social profile page, which includes the user's
     * points and user level (if enabled in the site configuration) and lots
     * more.
     *
     * @param $user_id Integer: user ID
     * @param $user_name String: user name
     */
    function getProfileTop($user_id, $user_name)
    {
        global $wgOut, $wgUser, $wgLang;
        global $wgUserLevels;
        $stats = new UserStats($user_id, $user_name);
        $stats_data = $stats->getUserStats();
        $user_level = new UserLevel($stats_data['points']);
        $level_link = Title::makeTitle(NS_HELP, wfMessage('user-profile-userlevels-link')->inContentLanguage()->text());
        $this->initializeProfileData($user_name);
        $profile_data = $this->profile_data;
        // Variables and other crap
        $page_title = $this->getTitle()->getText();
        $title_parts = explode('/', $page_title);
        $user = $title_parts[0];
        $id = User::idFromName($user);
        $user_safe = urlencode($user);
        // Safe urls
        $add_relationship = SpecialPage::getTitleFor('AddRelationship');
        $remove_relationship = SpecialPage::getTitleFor('RemoveRelationship');
        $give_gift = SpecialPage::getTitleFor('GiveGift');
        $send_board_blast = SpecialPage::getTitleFor('SendBoardBlast');
        $update_profile = SpecialPage::getTitleFor('UpdateProfile');
        $watchlist = SpecialPage::getTitleFor('Watchlist');
        $contributions = SpecialPage::getTitleFor('Contributions', $user);
        $send_message = SpecialPage::getTitleFor('UserBoard');
        $upload_avatar = SpecialPage::getTitleFor('UploadAvatar');
        $user_page = Title::makeTitle(NS_USER, $user);
        $user_social_profile = Title::makeTitle(NS_USER_PROFILE, $user);
        $user_wiki = Title::makeTitle(NS_USER_WIKI, $user);
        $us = new UserStatus($this->user);
        $city = $us->getCity();
        $city = Sanitizer::escapeHtmlAllowEntities($city);
        $birthday = $us->getBirthday();
        $status = $us->getStatus();
        $status = Sanitizer::escapeHtmlAllowEntities($status);
        $gender = $us->getGender();
        if ($gender == 'male') {
            $genderIcon = '♂';
            $gendertext = '他';
        } elseif ($gender == 'female') {
            $genderIcon = '♀';
            $gendertext = '她';
        } else {
            $genderIcon = '♂/♀';
            $gendertext = 'TA';
        }
        if ($this->isOwner()) {
            $gendertext = '你';
        }
        if ($id != 0) {
            $relationship = UserRelationship::getUserRelationshipByID($id, $wgUser->getID());
        }
        $avatar = new wAvatar($this->user_id, 'l');
        wfDebug('profile type: ' . $profile_data['user_page_type'] . "\n");
        $output = '';
        //get more
        $target = SpecialPage::getTitleFor('ShowFollowedSites');
        $query = array('user_id' => $wgUser->getId(), 'target_user_id' => $this->user_id);
        $mailVerify = $wgUser->getEmailAuthenticationTimestamp();
        if ($mailVerify == NULL) {
            $href = "/wiki/Special:ConfirmEmail";
        } else {
            $href = "/wiki/Special:UploadAvatar";
        }
        $output .= '<div id="profile-right" class="col-md-6 col-sm-12 col-xs-12">';
        $output .= '<div id="profile-title-container">
				<h1 id="profile-title">
				<div id="profile-image">' . ($this->isOwner() ? '<div class="profile-image-container crop-headimg" id="crop-avatar"><div class="avatar-view upload-tool" title="上传头像">' . $avatar->getOwnerAvatarURL() . '</div>' . $this->cropModal() . '</div>' : $avatar->getAvatarURL()) . '</div>' . $user_name . '</h1></div>';
        $output .= '<div class="modal fade watch-url" tabindex="-1" role="dialog" aria-labelledby="mySmModalLabel" aria-hidden="true">
                      <div class="modal-dialog modal-sm">
                        <div class="modal-content">
                          <div class="modal-header">
                              <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                              <h4 class="modal-title" id="gridSystemModalLabel">' . $gendertext . '关注的wiki</h4>
                          </div>
                            <div class="modal-body">
	                            <div class="list-group">
								</div>
								' . Linker::LinkKnown($target, '<i class="fa fa-arrows-alt"></i> 全部', array('type' => 'button', 'class' => 'btn btn-default'), $query) . '
							</div>
                        </div>
                      </div>
                    </div>';
        // Show the user's level and the amount of points they have if
        // UserLevels has been configured contributions
        $notice = SpecialPage::getTitleFor('ViewFollows');
        $contributions = SpecialPage::getTitleFor('Contributions');
        $output .= '<div>
					    <ul class="user-follow-msg">
					        <li><h5>编辑</h5>' . Linker::link($contributions, $stats_data['edits'], array(), array('target' => $user, 'contribs' => 'user')) . '</li>
					        <li><h4>|</h4></li>
					        <li><h5>关注</h5>' . Linker::link($notice, UserUserFollow::getFollowingCount(User::newFromName($user)), array('id' => 'user-following-count'), array('user' => $user, 'rel_type' => 1)) . '</li>
					        <li><h4>|</h4></li>
					        <li><h5>被关注</h5>' . Linker::link($notice, UserUserFollow::getFollowerCount(User::newFromName($user)), array('id' => 'user-follower-count'), array('user' => $user, 'rel_type' => 2)) . '</li>
                        </ul>
                        <div class="cleared"></div>
                    </div>
                    <!--<span id="user-site-count">' . '</span>个站点。-->';
        if ($wgUserLevels) {
            $progress = $user_level->getLevelProgress() * 100;
            $output .= '<div id="honorific-level" class="label">
						<a href="' . htmlspecialchars($level_link->getFullURL()) . '" rel="nofollow">' . $user_level->getLevelName() . '</a>
					</div>
					<div id="points-level" class="progress">
						<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="' . $progress . '" aria-valuemin="0" aria-valuemax="100" style="width: ' . $progress . '%">
							<span class="sr-only">' . wfMessage('user-profile-points', $wgLang->formatNum($stats_data['points']))->escaped() . '</span>
						</div>

					</div>';
        }
        $output .= '<div class="profile-actions">';
        $output .= '<div class="form-container ' . ($this->isOwner() ? 'owner' : '') . '"><div class="form-msg"><a class="form-location ' . ($this->isOwner() ? 'edit' : '') . '">' . ($city == '' ? $this->isOwner() ? '填写居住地' : '居住地未公开' : $city) . '</a>
                    <span class="span-color">|</span><a class="form-date ' . ($this->isOwner() ? 'edit' : '') . '" data-birthday="' . ($birthday == '' || $birthday == '0000-00-00' ? '' : $birthday) . '">' . ($birthday == '' || $birthday == '0000-00-00' ? $this->isOwner() ? '填写生日' : '生日未公开' : '') . '</a>
                    <span class="span-color">|</span><a class="form-sex ' . ($this->isOwner() ? 'edit' : '') . '" data-sex="' . $gender . '">' . $genderIcon . '</a></div>';
        $output .= '<div class="user-autograph"><a class="form-autograph ' . ($this->isOwner() ? 'edit' : '') . '">' . ($status == '' ? $this->isOwner() ? '填写个人状态' : '这个人很懒,什么都没有写...' : $status) . '</a></div></div>';
        // Links to User:user_name from User_profile:
        // if ( $this->getTitle()->getNamespace() == NS_USER_PROFILE && $this->profile_data['user_id'] && $this->profile_data['user_page_type'] == 0 ) {
        // 	$output .= '| <a href="' . htmlspecialchars( $user_page->getFullURL() ) . '" rel="nofollow">' .
        // 		wfMessage( 'user-page-link' )->escaped() . '</a> ';
        // }
        // // Links to User:user_name from User_profile:
        // if ( $this->getTitle()->getNamespace() == NS_USER && $this->profile_data['user_id'] && $this->profile_data['user_page_type'] == 0 ) {
        // 	$output .= '| <a href="' . htmlspecialchars( $user_social_profile->getFullURL() ) . '" rel="nofollow">' .
        // 		wfMessage( 'user-social-profile-link' )->escaped() . '</a> ';
        // }
        // if ( $this->getTitle()->getNamespace() == NS_USER && ( !$this->profile_data['user_id'] || $this->profile_data['user_page_type'] == 1 ) ) {
        // 	$output .= '| <a href="' . htmlspecialchars( $user_wiki->getFullURL() ) . '" rel="nofollow">' .
        // 		wfMessage( 'user-wiki-link' )->escaped() . '</a>';
        // }
        $output .= '</div></div>';
        return $output;
    }
	/**
	 * Show the special page
	 *
	 * @param $params Mixed: parameter(s) passed to the page or null
	 */
	public function execute( $params ) {
		global $wgUser, $wgOut, $wgRequest, $wgUserRelationshipScripts;

		// Can't use $this->setHeaders(); here because then it'll set the page
		// title to <removerelationship> and we don't want that, we'll be
		// messing with the page title later on in the code
		$wgOut->setArticleRelated( false );
		$wgOut->setRobotPolicy( 'noindex,nofollow' );

		$wgOut->addExtensionStyle( $wgUserRelationshipScripts . '/UserRelationship.css' );

		$userTitle = Title::newFromDBkey( $wgRequest->getVal( 'user' ) );

		if ( !$userTitle ) {
			$wgOut->setPageTitle( wfMsgHtml( 'ur-error-title' ) );
			$wgOut->addWikiText( wfMsgNoTrans( 'ur-add-no-user' ) );
			return false;
		}

		$user = Title::makeTitle( NS_USER, $userTitle->getText() );

		$this->user_name_to = $userTitle->getText();
		$this->user_id_to = User::idFromName( $this->user_name_to );
		$this->relationship_type = $wgRequest->getInt( 'rel_type' );
		if ( !$this->relationship_type || !is_numeric( $this->relationship_type ) ) {
			$this->relationship_type = 1;
		}
		$hasRelationship = UserRelationship::getUserRelationshipByID(
			$this->user_id_to,
			$wgUser->getID()
		);

		if ( ( $wgUser->getID() == $this->user_id_to ) && ( $wgUser->getID() != 0 ) ) {
			$wgOut->setPageTitle( wfMsg( 'ur-error-title' ) );
			$out .= '<div class="relationship-error-message">' .
				wfMsg( 'ur-add-error-message-yourself' ) .
			'</div>
			<div>
				<input type="button" class="site-button" value="' . wfMsg( 'ur-main-page' ) . '" size="20" onclick=\'window.location="index.php?title="' . wfMsgForContent( 'mainpage' ) . '"\' />';
			if ( $wgUser->isLoggedIn() ) {
				$out .= '<input type="button" class="site-button" value="' . wfMsg( 'ur-your-profile' ) . '" size="20" onclick=\'window.location="' . $wgUser->getUserPage()->escapeFullURL() . '"\' />';
			}
			$out .= '</div>';

			$wgOut->addHTML( $out );

		} elseif ( $wgUser->isBlocked() ) {
			$wgOut->setPageTitle( wfMsg( 'ur-error-title' ) );
			$out .= '<div class="relationship-error-message">' .
				wfMsg( 'ur-add-error-message-blocked' ) .
			'</div>
			<div>
				<input type="button" class="site-button" value="' . wfMsg( 'ur-main-page' ) . '" size="20" onclick=\'window.location="index.php?title="' . wfMsgForContent( 'mainpage' ) . '"\' />';
			if ( $wgUser->isLoggedIn() ) {
				$out .= '<input type="button" class="site-button" value="' . wfMsg( 'ur-your-profile' ) . '" size="20" onclick=\'window.location="' . $wgUser->getUserPage()->escapeFullURL() . '"\' />';
			}
			$out .= '</div>';

			$wgOut->addHTML( $out );

		} elseif ( $this->user_id_to == 0 ) {
			$wgOut->setPageTitle( wfMsg( 'ur-error-title' ) );
			$out .= '<div class="relationship-error-message">' .
				wfMsg( 'ur-add-error-message-no-user' ) .
			'</div>
			<div>
				<input type="button" class="site-button" value="' . wfMsg( 'ur-main-page' ) . '" size="20" onclick=\'window.location="index.php?title="' . wfMsgForContent( 'mainpage' ) . '"\' />';
			if ( $wgUser->isLoggedIn() ) {
				$out .= '<input type="button" class="site-button" value="' . wfMsg( 'ur-your-profile' ) . '" size="20" onclick=\'window.location="' . $wgUser->getUserPage()->escapeFullURL() . '"\' />';
			}
			$out .= '</div>';

			$wgOut->addHTML( $out );

		} elseif ( $hasRelationship >= 1 ) {

			if ( $hasRelationship == 1 ) {
				$error = wfMsg( 'ur-add-error-message-existing-relationship-friend', $this->user_name_to );
			} else {
				$error = wfMsg( 'ur-add-error-message-existing-relationship-foe', $this->user_name_to );
			}

			$avatar = new wAvatar( $this->user_id_to, 'l' );

			$out = '';
			$wgOut->setPageTitle( wfMsg( 'ur-error-title' ) );

			$out .= "<div class=\"relationship-action\">
				{$avatar->getAvatarURL()}
				" . $error . "
				<div class=\"relationship-buttons\">
					<input type=\"button\" class=\"site-button\" value=\"" . wfMsg( 'ur-main-page' ) . "\" size=\"20\" onclick=\"window.location='index.php?title=" . wfMsgForContent( 'mainpage' ) . "'\"/>
					<input type=\"button\" class=\"site-button\" value=\"" . wfMsg( 'ur-your-profile' ) . "\" size=\"20\" onclick=\"window.location='" . $wgUser->getUserPage()->escapeFullURL() . "'\"/>
				</div>
				<div class=\"cleared\"></div>
			</div>";

			$wgOut->addHTML( $out );

		} elseif ( UserRelationship::userHasRequestByID( $this->user_id_to, $wgUser->getID() ) == true ) {

			if ( $this->relationship_type == 1 ) {
				$error = wfMsg( 'ur-add-error-message-pending-friend-request', $this->user_name_to );
			} else {
				$error = wfMsg( 'ur-add-error-message-pending-foe-request', $this->user_name_to );
			}

			$avatar = new wAvatar( $this->user_id_to, 'l' );

			$out = '';
			$wgOut->setPageTitle( wfMsg( 'ur-add-error-message-pending-request-title' ) );
			$out .= "<div class=\"relationship-action\">
				{$avatar->getAvatarURL()}
				" . $error . "
				<div class=\"relationship-buttons\">
					<input type=\"button\" class=\"site-button\" value=\"" . wfMsg( 'ur-main-page' ) . "\" size=\"20\" onclick=\"window.location='index.php?title=" . wfMsgForContent( 'mainpage' ) . "'\"/>
					<input type=\"button\" class=\"site-button\" value=\"" . wfMsg( 'ur-your-profile' ) . "\" size=\"20\" onclick=\"window.location='" . $wgUser->getUserPage()->escapeFullURL() . "'\"/>
				</div>
				<div class=\"cleared\"></div>
			</div>";

			$wgOut->addHTML( $out );
		} elseif ( UserRelationship::userHasRequestByID( $wgUser->getID(), $this->user_id_to ) == true ) {
			$relationship_request = SpecialPage::getTitleFor( 'ViewRelationshipRequests' );
			$wgOut->redirect( $relationship_request->getFullURL() );
		} elseif ( $wgUser->getID() == 0 ) {
			$login_link = SpecialPage::getTitleFor( 'Userlogin' );

			if ( $this->relationship_type == 1 ) {
				$error = wfMsg( 'ur-add-error-message-not-loggedin-friend' );
			} else {
				$error = wfMsg( 'ur-add-error-message-not-loggedin-foe' );
			}

			$out = '';
			$wgOut->setPageTitle( wfMsg( 'ur-error-title' ) );
			$out .= '<div class="relationship-error-message">'
				. $error .
			'</div>
			<div>
				<input type="button" class="site-button" value="' . wfMsg( 'ur-main-page' ) . '" size="20" onclick=\'window.location="index.php?title="' . wfMsgForContent( 'mainpage' ) . '"\' />
				<input type="button" class="site-button" value="' . wfMsg( 'ur-login' ) . '" size="20" onclick="window.location=\'' . $login_link->escapeFullURL() . '\'" />';
			$out .= '</div>';

			$wgOut->addHTML( $out );
		} else {
			$rel = new UserRelationship( $wgUser->getName() );

			if ( $wgRequest->wasPosted() && $_SESSION['alreadysubmitted'] == false ) {
				$_SESSION['alreadysubmitted'] = true;
				$rel = $rel->addRelationshipRequest( $this->user_name_to, $this->relationship_type, $wgRequest->getVal( 'message' ) );

				$avatar = new wAvatar( $this->user_id_to, 'l' );

				$out = '';

				if ( $this->relationship_type == 1 ) {
					$wgOut->setPageTitle( wfMsg( 'ur-add-sent-title-friend', $this->user_name_to ) );
					$sent = wfMsg( 'ur-add-sent-message-friend', $this->user_name_to );
				} else {
					$wgOut->setPageTitle( wfMsg( 'ur-add-sent-title-foe', $this->user_name_to ) );
					$sent = wfMsg( 'ur-add-sent-message-foe', $this->user_name_to );
				}

				$out .= "<div class=\"relationship-action\">
					{$avatar->getAvatarURL()}
					" . $sent . "
					<div class=\"relationship-buttons\">
						<input type=\"button\" class=\"site-button\" value=\"" . wfMsg( 'ur-main-page' ) . "\" size=\"20\" onclick=\"window.location='index.php?title=" . wfMsgForContent( 'mainpage' ) . "'\"/>
						<input type=\"button\" class=\"site-button\" value=\"" . wfMsg( 'ur-your-profile' ) . "\" size=\"20\" onclick=\"window.location='" . $wgUser->getUserPage()->escapeFullURL() . "'\"/>
					</div>
					<div class=\"cleared\"></div>
				</div>";

				$wgOut->addHTML( $out );
			} else {
				$_SESSION['alreadysubmitted'] = false;
				$wgOut->addHTML( $this->displayForm() );
			}
		}
	}