コード例 #1
0
    /**
     * Displays the form for sending board blasts
     */
    function displayForm()
    {
        global $wgUser;
        $stats = new UserStats($wgUser->getID(), $wgUser->getName());
        $stats_data = $stats->getUserStats();
        $friendCount = $stats_data['friend_count'];
        $foeCount = $stats_data['foe_count'];
        $output = '<div class="board-blast-message-form">
				<h2>' . wfMsg('boardblaststep1') . '</h2>
				<form method="post" name="blast" action="">
					<input type="hidden" name="ids" id="ids" />
					<div class="blast-message-text">' . wfMsg('boardblastprivatenote') . '</div>
					<textarea name="message" id="message" cols="63" rows="4"></textarea>
				</form>
		</div>
		<div class="blast-nav">
				<h2>' . wfMsg('boardblaststep2') . '</h2>
				<div class="blast-nav-links">
					<a href="javascript:void(0);" onclick="javascript:select_all()">' . wfMsg('boardlinkselectall') . '</a> -
					<a href="javascript:void(0);" onclick="javascript:unselect_all()">' . wfMsg('boardlinkunselectall') . '</a> ';
        if ($friendCount > 0 && $foeCount > 0) {
            $output .= '- <a href="javascript:void(0);" onclick="javascript:toggle_friends(1)">' . wfMsg('boardlinkselectfriends') . '</a> -';
            $output .= '<a href="javascript:void(0);" onclick="javascript:toggle_friends(0)">' . wfMsg('boardlinkunselectfriends') . '</a>';
        }
        if ($foeCount > 0 && $friendCount > 0) {
            $output .= '- <a href="javascript:void(0);" onclick="javascript:toggle_foes(1)">' . wfMsg('boardlinkselectfoes') . '</a> -';
            $output .= '<a href="javascript:void(0);" onclick="javascript:toggle_foes(0)">' . wfMsg('boardlinkunselectfoes') . '</a>';
        }
        $output .= '</div>
		</div>';
        $rel = new UserRelationship($wgUser->getName());
        $relationships = $rel->getRelationshipList();
        $output .= '<div id="blast-friends-list" class="blast-friends-list">';
        $x = 1;
        $per_row = 3;
        if (count($relationships) > 0) {
            foreach ($relationships as $relationship) {
                if ($relationship['type'] == 1) {
                    $class = 'friend';
                } else {
                    $class = 'foe';
                }
                $id = $relationship['user_id'];
                $output .= '<div class="blast-' . $class . "-unselected\" id=\"user-{$id}\" onclick=\"javascript:toggle_user({$id})\">\r\n\t\t\t\t\t\t{$relationship['user_name']}\r\n\t\t\t\t\t</div>";
                if ($x == count($relationships) || $x != 1 && $x % $per_row == 0) {
                    $output .= '<div class="cleared"></div>';
                }
                $x++;
            }
        } else {
            $output .= '<div>' . wfMsg('boardnofriends') . '</div>';
        }
        $output .= '</div>

			<div class="cleared"></div>';
        $output .= '<div class="blast-message-box-button">
			<input type="button" value="' . wfMsg('boardsendbutton') . '" class="site-button" onclick="javascript:send_messages();" />
		</div>';
        return $output;
    }
コード例 #2
0
ファイル: UserStats.php プロジェクト: schwarer2006/wikia
function renderUserStats($input)
{
    global $wgUser;
    purgePage();
    getValue($username, $input, "user");
    $userstats = new UserStats();
    $userstats->setUsername($username);
    $output = $userstats->displayUserStats();
    return $output;
}
コード例 #3
0
    /**
     * 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;
    }
コード例 #4
0
ファイル: TopUsersTag.php プロジェクト: Reasno/SocialProfile
/**
 * Get the given amount of top users for the given timeframe.
 *
 * @return String: HTML
 */
function getTopUsersForTag($input, $args, $parser)
{
    global $wgLang;
    // Don't allow showing OVER 9000...I mean, over 50 users, duh.
    // Performance and all that stuff.
    if (!empty($args['limit']) && is_numeric($args['limit']) && $args['limit'] < 50) {
        $limit = intval($args['limit']);
    } else {
        $limit = 5;
    }
    if (!empty($args['period']) && strtolower($args['period']) == 'monthly') {
        $period = 'monthly';
    } else {
        // "period" argument not supplied/it's not "monthly", so assume weekly
        $period = 'weekly';
    }
    $fans = UserStats::getTopFansListPeriod($limit, $period);
    $x = 1;
    $topfans = '';
    foreach ($fans as $fan) {
        $avatar = new wAvatar($fan['user_id'], 'm');
        $user = Title::makeTitle(NS_USER, $fan['user_name']);
        $topfans .= "<div class=\"top-fan\">\n\t\t\t\t<span class=\"top-fan-number\">{$x}.</span>\n\t\t\t\t<a href=\"{$user->getFullURL()}\">{$avatar->getAvatarURL()}</a>\n\t\t\t\t<span class=\"top-fans-user\"><a href=\"{$user->getFullURL()}\">{$fan['user_name']}</a></span>\n\t\t\t\t<span class=\"top-fans-points\"><b>+" . $wgLang->formatNum($fan['points']) . '</b> ' . wfMessage('top-fans-points')->plain() . '</span>
			</div>';
        $x++;
    }
    return $topfans;
}
コード例 #5
0
ファイル: UserWelcome.php プロジェクト: Reasno/SocialProfile
function getWelcome()
{
    global $wgUser, $wgOut, $wgLang;
    // Add CSS
    $wgOut->addModuleStyles('ext.socialprofile.userwelcome.css');
    // Get stats and user level
    $stats = new UserStats($wgUser->getID(), $wgUser->getName());
    $stats_data = $stats->getUserStats();
    $user_level = new UserLevel($stats_data['points']);
    // Safe links
    $level_link = Title::makeTitle(NS_HELP, wfMessage('mp-userlevels-link')->inContentLanguage()->plain());
    $avatar_link = SpecialPage::getTitleFor('UploadAvatar');
    // Make an avatar
    $avatar = new wAvatar($wgUser->getID(), 'l');
    // Profile top images/points
    $output = '<div class="mp-welcome-logged-in">
	<h2>' . wfMessage('mp-welcome-logged-in', $wgUser->getName())->parse() . '</h2>
	<div class="mp-welcome-image">
	<a href="' . htmlspecialchars($wgUser->getUserPage()->getFullURL()) . '" rel="nofollow">' . $avatar->getAvatarURL() . '</a>';
    if (strpos($avatar->getAvatarImage(), 'default_') !== false) {
        $uploadOrEditMsg = 'mp-welcome-upload';
    } else {
        $uploadOrEditMsg = 'mp-welcome-edit';
    }
    $output .= '<div><a href="' . htmlspecialchars($avatar_link->getFullURL()) . '" rel="nofollow">' . wfMessage($uploadOrEditMsg)->plain() . '</a></div>';
    $output .= '</div>';
    global $wgUserLevels;
    if ($wgUserLevels) {
        $output .= '<div class="mp-welcome-points">
			<div class="points-and-level">
				<div class="total-points">' . wfMessage('mp-welcome-points', $wgLang->formatNum($stats_data['points']))->parse() . '</div>
				<div class="honorific-level"><a href="' . htmlspecialchars($level_link->getFullURL()) . '">(' . $user_level->getLevelName() . ')</a></div>
			</div>
			<div class="cleared"></div>
			<div class="needed-points">
				<br />' . wfMessage('mp-welcome-needed-points', htmlspecialchars($level_link->getFullURL()), $user_level->getNextLevelName(), $user_level->getPointsNeededToAdvance())->text() . '</div>
		</div>';
    }
    $output .= '<div class="cleared"></div>';
    $output .= getRequests();
    $output .= '</div>';
    return $output;
}
コード例 #6
0
function getWelcome()
{
    global $wgUser, $wgOut, $wgScriptPath, $wgUploadPath;
    // Add CSS
    $wgOut->addExtensionStyle($wgScriptPath . '/extensions/SocialProfile/UserWelcome/UserWelcome.css');
    // Get stats and user level
    $stats = new UserStats($wgUser->getID(), $wgUser->getName());
    $stats_data = $stats->getUserStats();
    $user_level = new UserLevel($stats_data['points']);
    // Safe links
    $level_link = Title::makeTitle(NS_HELP, wfMsgForContent('mp-userlevels-link'));
    $avatar_link = SpecialPage::getTitleFor('UploadAvatar');
    // Make an avatar
    $avatar = new wAvatar($wgUser->getID(), 'l');
    // Profile top images/points
    $output = '<div class="mp-welcome-logged-in">
	<h2>' . wfMsg('mp-welcome-logged-in', $wgUser->getName()) . '</h2>
	<div class="mp-welcome-image">
	<a href="' . $wgUser->getUserPage()->escapeFullURL() . '" rel="nofollow"><img src="' . $wgUploadPath . '/avatars/' . $avatar->getAvatarImage() . '" alt="" border="0"/></a>';
    if (strpos($avatar->getAvatarImage(), 'default_') !== false) {
        $output .= '<div><a href="' . $avatar_link->escapeFullURL() . '" rel="nofollow">' . wfMsg('mp-welcome-upload') . '</a></div>';
    } else {
        $output .= '<div><a href="' . $avatar_link->escapeFullURL() . '" rel="nofollow">' . wfMsg('mp-welcome-edit') . '</a></div>';
    }
    $output .= '</div>';
    global $wgUserLevels;
    if ($wgUserLevels) {
        $output .= '<div class="mp-welcome-points">
			<div class="points-and-level">
				<div class="total-points">' . wfMsgExt('mp-welcome-points', 'parsemag', $stats_data['points']) . '</div>
				<div class="honorific-level"><a href="' . $level_link->escapeFullURL() . '">(' . $user_level->getLevelName() . ')</a></div>
			</div>
			<div class="cleared"></div>
			<div class="needed-points">
				<br />' . wfMsgExt('mp-welcome-needed-points', 'parsemag', $level_link->escapeFullURL(), $user_level->getNextLevelName(), $user_level->getPointsNeededToAdvance()) . '</div>
		</div>';
    }
    $output .= '<div class="cleared"></div>';
    $output .= getRequests();
    $output .= '</div>';
    return $output;
}
コード例 #7
0
	/**
	 * Show the special page
	 *
	 * @param $par Mixed: parameter passed to the special page or null
	 */
	public function execute( $par ) {
		global $wgRequest, $wgOut, $wgUser, $wgScriptPath;

		$messages_show = 25;
		$output = '';
		$user_name = $wgRequest->getVal( 'user', $par );
		$page = $wgRequest->getInt( 'page', 1 );

		/**
		 * Redirect Non-logged in users to Login Page
		 * It will automatically return them to their Status page
		 */
		if( $wgUser->getID() == 0 && $user_name == '' ) {
			$wgOut->setPageTitle( wfMsg( 'userstatus-woops' ) );
			$login = SpecialPage::getTitleFor( 'Userlogin' );
			$wgOut->redirect( $login->getFullURL( 'returnto=Special:UserStatus' ) );
			return false;
		}

		/**
		 * 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 );
		$user = Title::makeTitle( NS_USER, $user_name );

		/**
		 * Error message for username that does not exist (from URL)
		 */
		if( $user_id == 0 ) {
			$wgOut->setPageTitle( wfMsg( 'userstatus-woops' ) );
			$wgOut->addHTML( wfMsg( 'userstatus-no-user' ) );
			return false;
		}

		/**
		 * Config for the page
		 */
		$per_page = $messages_show;

		$stats = new UserStats( $user_id, $user_name );
		$stats_data = $stats->getUserStats();
		$total = $stats_data['user_status_count'];

		$s = new UserStatus();
		$messages = $s->getStatusMessages( $user_id, 0, 0, $messages_show, $page );

		if ( !( $wgUser->getName() == $user_name ) ) {
			$wgOut->setPageTitle( wfMsg( 'userstatus-user-thoughts', $user_name ) );
		} else {
			$wgOut->setPageTitle( wfMsg( 'userstatus-your-thoughts' ) );
		}

		$output .= '<div class="gift-links">';
		if ( !( $wgUser->getName() == $user_name ) ) {
			$output .= "<a href=\"{$user->getFullURL()}\">" .
				wfMsg( 'userstatus-back-user-profile', $user_name ) . '</a>';
		} else {
			$output .= '<a href="' . $wgUser->getUserPage()->getFullURL() . '">' .
				wfMsg( 'userstatus-back-your-profile' ) . '</a>';
		}
		$output .= '</div>';

		if( $page == 1 ) {
			$start = 1;
		} else {
			$start = ( $page - 1 ) * $per_page + 1;
		}

		$end = $start + ( count( $messages ) ) - 1;
		wfDebug( "total = {$total}" );

		if( $total ) {
			$output .= '<div class="user-page-message-top">
				<span class="user-page-message-count" style="font-size: 11px; color: #666666;">' .
					wfMsgExt( 'userstatus-showing-thoughts', 'parsemag', $start, $end, $total ) .
				'</span>
			</div>';
		}

		/**
		 * Build next/prev navigation
		 */
		$numofpages = $total / $per_page;

		if( $numofpages > 1 ) {
			$output .= '<div class="page-nav">';
			if( $page > 1 ) {
				$output .= '<a href="' . $this->getTitle()->getFullURL( array(
					'user' => $user_name, 'page' => ( $page - 1 ) ) ) . '">' .
					wfMsg( 'userstatus-prev' ) . '</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="' . $this->getTitle()->getFullURL(
						array( 'user' => $user_name, 'page' => $i ) ) .
						"\">$i</a> ";
				}
			}

			if( ( $total - ( $per_page * $page ) ) > 0 ) {
				$output .= ' <a href="' . $this->getTitle()->getFullURL( array(
					'user' => $user_name, 'page' => ( $page + 1 ) ) ) . '">' .
					wfMsg( 'userstatus-next' ) . '</a>';
			}
			$output .= '</div><p>';
		}

		// Add CSS & JS
		if ( defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) ) {
			$wgOut->addModuleStyles( 'ext.userStatus' );
			$wgOut->addModuleScripts( 'ext.userStatus' );
		} else {
			$wgOut->addExtensionStyle( $wgScriptPath . '/extensions/UserStatus/UserStatus.css' );
			$wgOut->addScriptFile( $wgScriptPath . '/extensions/UserStatus/UserStatus.js' );
		}

		$output .= '<div class="user-status-container">';
		$thought_link = SpecialPage::getTitleFor( 'ViewThought' );
		if( $messages ) {
			foreach ( $messages as $message ) {
				$user = Title::makeTitle( NS_USER, $message['user_name'] );
				$avatar = new wAvatar( $message['user_id'], 'm' );

				$network_link = '<a href="' . SportsTeams::getNetworkURL( $message['sport_id'], $message['team_id'] ) . '">' .
					wfMsg( 'userstatus-all-team-updates', SportsTeams::getNetworkName( $message['sport_id'], $message['team_id'] ) ) .
				'</a>';

				$delete_link = '';
				if( $wgUser->getName() == $message['user_name'] ) {
					$delete_link = "<span class=\"user-board-red\">
						<a href=\"javascript:void(0);\" onclick=\"javascript:delete_message({$message['id']})\">" .
						wfMsg( 'userstatus-delete-thought-text' ) ."</a>
					</span>";
				}

				$message_text = preg_replace_callback(
					'/(<a[^>]*>)(.*?)(<\/a>)/i',
					array( 'UserStatus', 'cutLinkText' ),
					$message['text']
				);
				$vote_count = wfMsgExt( 'userstatus-num-agree', 'parsemag', $message['plus_count'] );

				$vote_link = '';
				if( $wgUser->isLoggedIn() && $wgUser->getName() != $message['user_name'] ) {
					if( !$message['voted'] ) {
						$vote_link = "<a href=\"javascript:void(0);\" onclick=\"vote_status({$message['id']},1)\">[" .
							wfMsg( 'userstatus-_agree' ) . "]</a>";
					} else {
						$vote_link = $vote_count;
					}
				}

				$view_thought_link = '<a href="' . $thought_link->getFullURL( "id={$message['id']}" ) . '">[' .
					wfMsg( 'userstatus-see-who-agrees' ) . ']</a>';

				$output .= '<div class="user-status-row">

					<div class="user-status-logo">

						<a href="' . SportsTeams::getNetworkURL( $message['sport_id'], $message['team_id'] ) . '">' .
							SportsTeams::getLogo( $message['sport_id'], $message['team_id'], 'm' ) .
						"</a>

					</div>

					<div class=\"user-status-message\">

						{$message_text}

						<div class=\"user-status-date\">" . 
							wfMsg( 'userstatus-ago', UserStatus::getTimeAgo( $message['timestamp'] ) ) .
							"<span class=\"user-status-vote\" id=\"user-status-vote-{$message['id']}\">
								{$vote_link}
							</span>
							{$view_thought_link}
							<span class=\"user-status-links\">
								{$delete_link}
							</span>
						</div>

					</div>

					<div class=\"cleared\"></div>

				</div>";
			}
		} else {
			$output .= '<p>' . wfMsg( 'userstatus-no-updates' ) . '</p>';
		}

		$output .= '</div>';

		$wgOut->addHTML( $output );
	}
コード例 #8
0
 /**
  * Get site followed users 
  *
  * @param $user:current username; $site_name:servername
  * @return array
  */
 public static function getSiteFollowersWithDetails($user, $site_name)
 {
     // return '';
     $dbr = wfGetDB(DB_SLAVE);
     $request = array();
     // $follower = UserUserFollow::getFollowedByUser( $user->getName() );
     $res = self::getSiteFollowers($user, $site_name);
     foreach ($res as $value) {
         $u_name = $value['user_name'];
         $temp['user'] = $u_name;
         // $temp['user'] = User::getEffectiveGroups($user);
         $userPage = Title::makeTitle(NS_USER, $u_name);
         $userPageURL = htmlspecialchars($userPage->getFullURL());
         $temp['userUrl'] = $userPageURL;
         $user_id = User::idFromName($u_name);
         $stats = new UserStats($user_id, $u_name);
         $stats_data = $stats->getUserStats();
         $user_level = new UserLevel($stats_data['points']);
         $temp['level'] = $user_level->getLevelName();
         $avatar = new wAvatar($user_id, 'm');
         $temp['url'] = $avatar->getAvatarURL();
         $tuser = User::newFromName($u_name);
         $temp['count'] = UserStats::getSiteEditsCount($tuser, $site_name);
         // if(in_array($u_name, $follower)){
         // 	$is_follow = 'Y';
         // }else{
         // 	$is_follow = 'N';
         // }
         // $temp['is_follow'] = $is_follow;
         $request[] = $temp;
     }
     foreach ($request as $key => $value) {
         $count[$key] = $value['count'];
     }
     array_multisort($count, SORT_DESC, $request);
     return $request;
 }
コード例 #9
0
                </li>
            </ul>
        </li>
        <li class="sidebar-brand left-manager">
            <a>管理员</a>
            <div>
            <?php 
$fanbox_link = SpecialPage::getTitleFor('UserList');
$group = 'sysop';
$ums = self::getSiteManager($wgHuijiPrefix, $group);
foreach ($ums as $value) {
    $uname = User::newFromId($value);
    $user_group = $uname->getEffectiveGroups();
    if (!in_array('bot', $user_group) && !in_array('bot-global', $user_group)) {
        $usersys['user_name'] = $uname->getName();
        $usersys['count'] = UserStats::getSiteEditsCount($uname, $wgHuijiPrefix);
        $userPage = Title::makeTitle(NS_USER, $uname->getName());
        $usersys['url'] = htmlspecialchars($userPage->getFullURL());
        $avatar = new wAvatar($value, 'm');
        $usersys['avatar'] = $avatar->getAvatarURL();
        $sysop[] = $usersys;
    }
}
foreach ($sysop as $key => $value) {
    $count[$key] = $value['count'];
}
array_multisort($count, SORT_DESC, $sysop);
$nums = count($ums) > 5 ? 5 : count($ums);
for ($j = 0; $j < $nums; $j++) {
    echo '<a href="' . $sysop[$j]['url'] . '"  title="' . $sysop[$j]['user_name'] . '">' . $sysop[$j]['avatar'] . '</a>';
}
コード例 #10
0
	/**
	 * 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 );
	}
コード例 #11
0
    /**
     * 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);
    }
コード例 #12
0
    /**
     * Get the user board for a given user.
     *
     * @param $user_id Integer: user's ID number
     * @param $user_name String: user name
     */
    function getUserBoard($user_id, $user_name)
    {
        global $wgUser, $wgOut, $wgUserProfileDisplay, $wgUserProfileScripts;
        // Anonymous users cannot have user boards
        if ($user_id == 0) {
            return '';
        }
        // Don't display anything if user board on social profiles isn't
        // enabled in site configuration
        if ($wgUserProfileDisplay['board'] == false) {
            return '';
        }
        $output = '';
        // Prevent E_NOTICE
        $wgOut->addScriptFile($wgUserProfileScripts . '/UserProfilePage.js');
        $rel = new UserRelationship($user_name);
        $friends = $rel->getRelationshipList(1, 4);
        $stats = new UserStats($user_id, $user_name);
        $stats_data = $stats->getUserStats();
        $total = $stats_data['user_board'];
        // If the user is viewing their own profile or is allowed to delete
        // board messages, add the amount of private messages to the total
        // sum of board messages.
        if ($wgUser->getName() == $user_name || $wgUser->isAllowed('userboard-delete')) {
            $total = $total + $stats_data['user_board_priv'];
        }
        $output .= '<div class="user-section-heading">
			<div class="user-section-title">' . wfMsg('user-board-title') . '</div>
			<div class="user-section-actions">
				<div class="action-right">';
        if ($wgUser->getName() == $user_name) {
            if ($friends) {
                $output .= '<a href="' . UserBoard::getBoardBlastURL() . '">' . wfMsg('user-send-board-blast') . '</a>';
            }
            if ($total > 10) {
                $output .= wfMsgExt('pipe-separator', 'escapenoentities');
            }
        }
        if ($total > 10) {
            $output .= '<a href="' . UserBoard::getUserBoardURL($user_name) . '">' . wfMsg('user-view-all') . '</a>';
        }
        $output .= '</div>
				<div class="action-left">';
        if ($total > 10) {
            $output .= wfMsg('user-count-separator', '10', $total);
        } elseif ($total > 0) {
            $output .= wfMsg('user-count-separator', $total, $total);
        }
        $output .= '</div>
				<div class="cleared"></div>
			</div>
		</div>
		<div class="cleared"></div>';
        if ($wgUser->getName() !== $user_name) {
            if ($wgUser->isLoggedIn() && !$wgUser->isBlocked()) {
                $output .= '<div class="user-page-message-form">
						<input type="hidden" id="user_name_to" name="user_name_to" value="' . addslashes($user_name) . '" />
						<span style="color:#797979;">' . wfMsgHtml('userboard_messagetype') . '</span>
						<select id="message_type">
							<option value="0">' . wfMsgHtml('userboard_public') . '</option>
							<option value="1">' . wfMsgHtml('userboard_private') . '</option>
						</select><p>
						<textarea name="message" id="message" cols="43" rows="4"/></textarea>
						<div class="user-page-message-box-button">
							<input type="button" value="' . wfMsg('userboard_sendbutton') . '" class="site-button" onclick="javascript:send_message();" />
						</div>
					</div>';
            } else {
                $login_link = SpecialPage::getTitleFor('Userlogin');
                $output .= '<div class="user-page-message-form">' . wfMsg('user-board-login-message', $login_link->escapeFullURL()) . '</div>';
            }
        }
        $output .= '<div id="user-page-board">';
        $b = new UserBoard();
        $output .= $b->displayMessages($user_id, 0, 10);
        $output .= '</div>';
        return $output;
    }
コード例 #13
0
 /**
  * Show the special page
  *
  * @param $par Mixed: parameter passed to the page or null
  */
 public function execute($par)
 {
     global $wgUser, $wgOut, $wgRequest, $wgMemc, $wgContLang, $wgHooks, $wgSupressPageTitle, $wgPollScripts;
     $wgSupressPageTitle = true;
     // Blocked users cannot create polls
     if ($wgUser->isBlocked()) {
         $wgOut->blockedPage(false);
         return false;
     }
     // Check that the DB isn't locked
     if (wfReadOnly()) {
         $wgOut->readOnlyPage();
         return;
     }
     /**
      * Redirect anonymous users to login page
      * It will automatically return them to the CreatePoll page
      */
     if ($wgUser->getID() == 0) {
         $wgOut->setPageTitle(wfMsgHtml('poll-woops'));
         $login = SpecialPage::getTitleFor('Userlogin');
         $wgOut->redirect($login->getLocalURL('returnto=Special:CreatePoll'));
         return false;
     }
     /**
      * Create Poll Thresholds based on User Stats
      */
     global $wgCreatePollThresholds;
     if (is_array($wgCreatePollThresholds) && count($wgCreatePollThresholds) > 0) {
         $canCreate = true;
         $stats = new UserStats($wgUser->getID(), $wgUser->getName());
         $stats_data = $stats->getUserStats();
         $threshold_reason = '';
         foreach ($wgCreatePollThresholds as $field => $threshold) {
             if ($stats_data[$field] < $threshold) {
                 $canCreate = false;
                 $threshold_reason .= ($threshold_reason ? ', ' : '') . "{$threshold} {$field}";
             }
         }
         if ($canCreate == false) {
             $wgSupressPageTitle = false;
             $wgOut->setPageTitle(wfMsg('poll-create-threshold-title'));
             $wgOut->addHTML(wfMsg('poll-create-threshold-reason', $threshold_reason));
             return '';
         }
     }
     // i18n for JS
     $wgHooks['MakeGlobalVariablesScript'][] = 'CreatePoll::addJSGlobals';
     // Add CSS & JS
     $wgOut->addScriptFile($wgPollScripts . '/Poll.js');
     $wgOut->addExtensionStyle($wgPollScripts . '/Poll.css');
     // If the request was POSTed, try creating the poll
     if ($wgRequest->wasPosted() && $_SESSION['alreadysubmitted'] == false) {
         $_SESSION['alreadysubmitted'] = true;
         // Add poll
         $poll_title = Title::makeTitleSafe(NS_POLL, $wgRequest->getVal('poll_question'));
         if (is_null($poll_title) && !$poll_title instanceof Title) {
             $wgSupressPageTitle = false;
             $wgOut->setPageTitle(wfMsg('poll-create-threshold-title'));
             $wgOut->addHTML(wfMsg('poll-create-threshold-reason', $threshold_reason));
             return '';
         }
         // Put choices in wikitext (so we can track changes)
         $choices = '';
         for ($x = 1; $x <= 10; $x++) {
             if ($wgRequest->getVal("answer_{$x}")) {
                 $choices .= $wgRequest->getVal("answer_{$x}") . "\n";
             }
         }
         // Create poll wiki page
         $localizedCategoryNS = $wgContLang->getNsText(NS_CATEGORY);
         $article = new Article($poll_title);
         $article->doEdit("<userpoll>\n{$choices}</userpoll>\n\n[[" . $localizedCategoryNS . ':' . wfMsgForContent('poll-category') . "]]\n" . '[[' . $localizedCategoryNS . ':' . wfMsgForContent('poll-category-user', $wgUser->getName()) . "]]\n" . '[[' . $localizedCategoryNS . ":{{subst:CURRENTMONTHNAME}} {{subst:CURRENTDAY}}, {{subst:CURRENTYEAR}}]]\n\n__NOEDITSECTION__", wfMsgForContent('poll-edit-desc'));
         $newPageId = $article->getID();
         $p = new Poll();
         $poll_id = $p->addPollQuestion($wgRequest->getVal('poll_question'), $wgRequest->getVal('poll_image_name'), $newPageId);
         // Add choices
         for ($x = 1; $x <= 10; $x++) {
             if ($wgRequest->getVal("answer_{$x}")) {
                 $p->addPollChoice($poll_id, $wgRequest->getVal("answer_{$x}"), $x);
             }
         }
         // Clear poll cache
         $key = wfMemcKey('user', 'profile', 'polls', $wgUser->getID());
         $wgMemc->delete($key);
         // Redirect to new poll page
         $wgOut->redirect($poll_title->getFullURL());
     } else {
         $_SESSION['alreadysubmitted'] = false;
         include 'create-poll.tmpl.php';
         $template = new CreatePollTemplate();
         $wgOut->addTemplate($template);
     }
 }
コード例 #14
0
    /**
     * Get the user board for a given user.
     *
     * @param $user_id Integer: user's ID number
     * @param $user_name String: user name
     */
    function getUserBoard($user_id, $user_name)
    {
        global $wgUser, $wgOut, $wgUserProfileDisplay;
        // Anonymous users cannot have user boards
        if ($user_id == 0) {
            return '';
        }
        // Don't display anything if user board on social profiles isn't
        // enabled in site configuration
        if ($wgUserProfileDisplay['board'] == false) {
            return '';
        }
        $output = '';
        // Prevent E_NOTICE
        // Add JS
        $wgOut->addModules('ext.socialprofile.userprofile.js');
        $rel = new UserRelationship($user_name);
        $friends = $rel->getRelationshipList(1, 4);
        $stats = new UserStats($user_id, $user_name);
        $stats_data = $stats->getUserStats();
        $total = $stats_data['user_board'];
        // If the user is viewing their own profile or is allowed to delete
        // board messages, add the amount of private messages to the total
        // sum of board messages.
        if ($wgUser->getName() == $user_name || $wgUser->isAllowed('userboard-delete')) {
            $total = $total + $stats_data['user_board_priv'];
        }
        $output .= '<div class="panel panel-default"><div class="user-section-heading panel-heading">
			<div class="user-section-title">' . wfMessage('user-board-title')->escaped() . '</div>
			<div class="user-section-actions">
				<div class="action-right">';
        if ($wgUser->getName() == $user_name) {
            if ($friends) {
                $output .= '<a href="' . UserBoard::getBoardBlastURL() . '">' . wfMessage('user-send-board-blast')->escaped() . '</a>';
            }
            if ($total > 10) {
                $output .= wfMessage('pipe-separator')->escaped();
            }
        }
        if ($total > 10) {
            $output .= '<a href="' . UserBoard::getUserBoardURL($user_name) . '">' . wfMessage('user-view-all')->escaped() . '</a>';
        }
        $output .= '</div>
				<div class="action-left">';
        if ($total > 10) {
            $output .= wfMessage('user-count-separator', '10', $total)->escaped();
        } elseif ($total > 0) {
            $output .= wfMessage('user-count-separator', $total, $total)->escaped();
        }
        $output .= '</div>
				<div class="cleared"></div>
			</div>
		</div>
		<div class="cleared"></div> <div class="panel-body">';
        if ($wgUser->getName() != $user_name) {
            if ($wgUser->isLoggedIn() && !$wgUser->isBlocked()) {
                $output .= '<div class="user-page-message-form">
						<input type="hidden" id="user_name_to" name="user_name_to" value="' . addslashes($user_name) . '" />
						<span class="profile-board-message-type">' . wfMessage('userboard_messagetype')->escaped() . '</span>
						<select id="message_type">
							<option value="0">' . wfMessage('userboard_public')->escaped() . '</option>
							<option value="1">' . wfMessage('userboard_private')->escaped() . '</option>
						</select><p><div class="form-group" style="padding:14px;">
                                      <textarea class="form-control" name="message" id="message" placeholder=""></textarea>
                                    </div>
						
						<div class="user-page-message-box-button">
							<input type="button" value="' . wfMessage('userboard_sendbutton')->escaped() . '" class="site-button mw-ui-button mw-ui-progressive" />
						</div>
					</div>';
            } else {
                $login_link = SpecialPage::getTitleFor('Userlogin');
                $output .= '<div class="user-page-message-form">' . wfMessage('user-board-login-message', $login_link->getFullURL())->escaped() . '</div>';
            }
        }
        $output .= '<div id="user-page-board">';
        $b = new UserBoard();
        $output .= $b->displayMessages($user_id, 0, 10);
        $output .= '</div></div></div>';
        return $output;
    }
コード例 #15
0
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      UserStats $value A UserStats object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(UserStats $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getStatNo();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
コード例 #16
0
 public static function increaseLoginCount($userId)
 {
     $userStats = UserStats::model()->findByPk($userId);
     if (empty($userStats)) {
         $userStats = new UserStats();
         $userStats->user_id = $userId;
         $userStats->num_logins = 1;
         $userStats->save(false);
         return false;
     } else {
         /** @var $userStats UserStats */
         $userStats->num_logins++;
         $userStats->save(false);
         return true;
     }
 }
コード例 #17
0
 /**
  * get user stats
  * @param  string $prefix if $prefix is null, return this user stats of all sites, else return the prefix stats
  * @return array
  */
 public function getStats($prefix = '')
 {
     $statsObj = new UserStats($this->mUser->getId(), $this->mUser->getName());
     if ($prefix === '') {
         return $statsObj->getUserStats();
     } else {
         $result = array();
         $result['edits'] = $statsObj->getSiteEditsCount($this->mUser, $prefix);
         return $result;
     }
     // getSiteEditsCount( $user, $prefix )
 }
コード例 #18
0
    /**
     * Show the special page
     *
     * @param $params Mixed: parameter(s) passed to the page or null
     */
    public function execute($params)
    {
        $out = $this->getOutput();
        $request = $this->getRequest();
        $currentUser = $this->getUser();
        // Set the page title, robot policies, etc.
        $this->setHeaders();
        // Add CSS & JS
        $out->addModuleStyles('ext.socialprofile.userboard.css');
        $out->addModules('ext.socialprofile.userboard.js');
        $ub_messages_show = 25;
        $user_name = $request->getVal('user');
        $user_name_2 = $request->getVal('conv');
        $user_id_2 = '';
        // Prevent E_NOTICE
        $page = $request->getInt('page', 1);
        /**
         * Redirect Non-logged in users to Login Page
         * It will automatically return them to the UserBoard page
         */
        if ($currentUser->getID() == 0 && $user_name == '') {
            $login = SpecialPage::getTitleFor('Userlogin');
            $out->redirect($login->getFullURL('returnto=Special:UserBoard'));
            return false;
        }
        /**
         * If no user is set in the URL, we assume its the current user
         */
        if (!$user_name) {
            $user_name = $currentUser->getName();
        }
        $user_id = User::idFromName($user_name);
        $user = Title::makeTitle(NS_USER, $user_name);
        if ($user_name_2) {
            $user_id_2 = User::idFromName($user_name_2);
            $user_2 = Title::makeTitle(NS_USER, $user_name);
        }
        /**
         * Error message for username that does not exist (from URL)
         */
        if ($user_id == 0) {
            $out->showErrorPage('error', 'userboard_noexist');
            return false;
        }
        /**
         * Config for the page
         */
        $per_page = $ub_messages_show;
        $b = new UserBoard();
        $ub_messages = $b->getUserBoardMessages($user_id, $user_id_2, $ub_messages_show, $page);
        if (!$user_id_2) {
            $stats = new UserStats($user_id, $user_name);
            $stats_data = $stats->getUserStats();
            $total = $stats_data['user_board'];
            // If user is viewing their own board or is allowed to delete
            // others' board messages, show the total count of board messages
            // to them (public + private messages)
            if ($currentUser->getName() == $user_name || $currentUser->isAllowed('userboard-delete')) {
                $total = $total + $stats_data['user_board_priv'];
            }
        } else {
            $total = $b->getUserBoardToBoardCount($user_id, $user_id_2);
        }
        if (!$user_id_2) {
            if (!($currentUser->getName() == $user_name)) {
                $out->setPageTitle($this->msg('userboard_owner', $user_name)->parse());
            } else {
                $b->clearNewMessageCount($currentUser->getID());
                $out->setPageTitle($this->msg('userboard_yourboard')->parse());
            }
        } else {
            if ($currentUser->getName() == $user_name) {
                $out->setPageTitle($this->msg('userboard_yourboardwith', $user_name_2)->parse());
            } else {
                $out->setPageTitle($this->msg('userboard_otherboardwith', $user_name, $user_name_2)->parse());
            }
        }
        $output = '<div class="user-board-top-links">';
        $output .= '<a href="' . htmlspecialchars($user->getFullURL()) . '">&lt; ' . $this->msg('userboard_backprofile', $user_name)->parse() . '</a>';
        $output .= '</div>';
        $board_to_board = '';
        // Prevent E_NOTICE
        if ($page == 1) {
            $start = 1;
        } else {
            $start = ($page - 1) * $per_page + 1;
        }
        $end = $start + count($ub_messages) - 1;
        if ($currentUser->getName() != $user_name) {
            $board_to_board = '<a href="' . UserBoard::getUserBoardToBoardURL($currentUser->getName(), $user_name) . '">' . $this->msg('userboard_boardtoboard')->plain() . '</a>';
        }
        if ($total) {
            $output .= '<div class="user-page-message-top">
			<span class="user-page-message-count">' . $this->msg('userboard_showingmessages', $total, $start, $end, $end - $start + 1)->parse() . "</span> {$board_to_board}\n\t\t\t</div>";
        }
        /**
         * Build next/prev navigation links
         */
        $qs = array();
        if ($user_id_2) {
            $qs['conv'] = $user_name_2;
        }
        $numofpages = $total / $per_page;
        if ($numofpages > 1) {
            $output .= '<div class="page-nav">';
            if ($page > 1) {
                $output .= Linker::link($this->getPageTitle(), $this->msg('userboard_prevpage')->plain(), array(), array('user' => $user_name, 'page' => $page - 1) + $qs);
            }
            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($this->getPageTitle(), $i, array(), array('user' => $user_name, 'page' => $i) + $qs) . $this->msg('word-separator')->plain();
                }
            }
            if ($total - $per_page * $page > 0) {
                $output .= $this->msg('word-separator')->plain() . Linker::link($this->getPageTitle(), $this->msg('userboard_nextpage')->plain(), array(), array('user' => $user_name, 'page' => $page + 1) + $qs);
            }
            $output .= '</div><p>';
        }
        $can_post = false;
        $user_name_from = '';
        // Prevent E_NOTICE
        if (!$user_id_2) {
            if ($currentUser->getName() != $user_name) {
                $can_post = true;
                $user_name_to = htmlspecialchars($user_name, ENT_QUOTES);
            }
        } else {
            if ($currentUser->getName() == $user_name) {
                $can_post = true;
                $user_name_to = htmlspecialchars($user_name_2, ENT_QUOTES);
                $user_name_from = htmlspecialchars($user_name, ENT_QUOTES);
            }
        }
        if ($currentUser->isBlocked()) {
            // only let them post to admins
            //$user_to = User::newFromId( $user_id );
            // if( !$user_to->isAllowed( 'delete' ) ) {
            $can_post = false;
            // }
        }
        if ($can_post) {
            if ($currentUser->isLoggedIn() && !$currentUser->isBlocked()) {
                $output .= '<div class="user-page-message-form">
					<input type="hidden" id="user_name_to" name="user_name_to" value="' . $user_name_to . '"/>
					<input type="hidden" id="user_name_from" name="user_name_from" value="' . $user_name_from . '"/>
					<span class="user-board-message-type">' . $this->msg('userboard_messagetype')->plain() . ' </span>
					<select id="message_type">
						<option value="0">' . $this->msg('userboard_public')->plain() . '</option>
						<option value="1">' . $this->msg('userboard_private')->plain() . '</option>
					</select>
					<p>
					<textarea name="message" id="message" cols="63" rows="4"></textarea>

					<div class="user-page-message-box-button">
						<input type="button" value="' . $this->msg('userboard_sendbutton')->plain() . '" class="site-button" data-per-page="' . $per_page . '" />
					</div>

				</div>';
            } else {
                $output .= '<div class="user-page-message-form">' . $this->msg('userboard_loggedout')->parse() . '</div>';
            }
        }
        $output .= '<div id="user-page-board">';
        if ($ub_messages) {
            foreach ($ub_messages as $ub_message) {
                $user = Title::makeTitle(NS_USER, $ub_message['user_name_from']);
                $avatar = new wAvatar($ub_message['user_id_from'], 'm');
                $board_to_board = '';
                $board_link = '';
                $ub_message_type_label = '';
                $delete_link = '';
                if ($currentUser->getName() != $ub_message['user_name_from']) {
                    $board_to_board = '<a href="' . UserBoard::getUserBoardToBoardURL($user_name, $ub_message['user_name_from']) . '">' . $this->msg('userboard_boardtoboard')->plain() . '</a>';
                    $board_link = '<a href="' . UserBoard::getUserBoardURL($ub_message['user_name_from']) . '">' . $this->msg('userboard_sendmessage', $ub_message['user_name_from'])->parse() . '</a>';
                } else {
                    $board_link = '<a href="' . UserBoard::getUserBoardURL($ub_message['user_name_from']) . '">' . $this->msg('userboard_myboard')->plain() . '</a>';
                }
                // If the user owns this private message or they are allowed to
                // delete board messages, show the "delete" link to them
                if ($currentUser->getName() == $ub_message['user_name'] || $currentUser->isAllowed('userboard-delete')) {
                    $delete_link = "<span class=\"user-board-red\">\n\t\t\t\t\t\t<a href=\"javascript:void(0);\" data-message-id=\"{$ub_message['id']}\">" . $this->msg('userboard_delete')->plain() . '</a>
					</span>';
                }
                // Mark private messages as such
                if ($ub_message['type'] == 1) {
                    $ub_message_type_label = '(' . $this->msg('userboard_private')->plain() . ')';
                }
                // had global function to cut link text if too long and no breaks
                // $ub_message_text = preg_replace_callback( "/(<a[^>]*>)(.*?)(<\/a>)/i", 'cut_link_text', $ub_message['message_text'] );
                $ub_message_text = $ub_message['message_text'];
                $userPageURL = htmlspecialchars($user->getFullURL());
                $output .= "<div class=\"user-board-message\">\n\t\t\t\t\t<div class=\"user-board-message-content\">\n\t\t\t\t\t\t<div class=\"user-board-message-image\">\n\t\t\t\t\t\t\t<a href=\"{$userPageURL}\" title=\"{$ub_message['user_name_from']}\">{$avatar->getAvatarURL()}</a>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t<a href=\"{$userPageURL}\" title=\"{$ub_message['user_name_from']}}\">{$ub_message['user_name_from']} </a> {$ub_message_type_label}\n\t\t\t\t\t\t<div class=\"user-board-message-time\">" . $this->msg('userboard_posted_ago', $b->getTimeAgo($ub_message['timestamp']))->parse() . "</div>\n\t\t\t\t\t\t<div class=\"user-board-message-body\">\n\t\t\t\t\t\t\t{$ub_message_text}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t<div class=\"cleared\"></div>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div class=\"user-board-message-links\">\n\t\t\t\t\t\t{$board_link}\n\t\t\t\t\t\t{$board_to_board}\n\t\t\t\t\t\t{$delete_link}\n\t\t\t\t\t</div>\n\t\t\t\t</div>";
            }
        } else {
            $output .= '<p>' . $this->msg('userboard_nomessages')->parse() . '</p>';
        }
        $output .= '</div>';
        $out->addHTML($output);
    }
コード例 #19
0
<link rel='stylesheet' type='text/css' href='css/table_print.css' />
<b><?php 
echo "User Log";
?>
</b>
<br><br>
<?php 
$lab_config_id = $_REQUEST['location'];
$lab_config = LabConfig::getById($lab_config_id);
if ($lab_config == null) {
    echo LangUtil::$generalTerms['MSG_NOTFOUND'];
    return;
}
$date_from = $_REQUEST['yyyy_from'] . "-" . $_REQUEST['mm_from'] . "-" . $_REQUEST['dd_from'];
$date_to = $_REQUEST['yyyy_to'] . "-" . $_REQUEST['mm_to'] . "-" . $_REQUEST['dd_to'];
$ust = new UserStats();
//echo "<pre>";
//echo "</pre>";
$log_type = $_REQUEST['log_type'];
$user_id = $_REQUEST['user_id'];
$uiinfo = "from=" . $date_from . "&to=" . $date_to . "&ud=" . $user_id . "&ld=" . $log_type;
putUILog('reports_user_stats_individual', $uiinfo, basename($_SERVER['REQUEST_URI'], ".php"), 'X', 'X', 'X');
$user_obj = get_user_by_id($user_id);
?>
<script type='text/javascript'>
		$(document).ready(function(){
			$('#testsdone_table').tablesorter();
		});
		</script>
<table>
	<tbody>
コード例 #20
0
 /**
  * Declares an association between this object and a UserStats object.
  *
  * @param      UserStats $v
  * @return     UserStatEquip The current object (for fluent API support)
  * @throws     PropelException
  */
 public function setUserStats(UserStats $v = null)
 {
     if ($v === null) {
         $this->setUserStatId(NULL);
     } else {
         $this->setUserStatId($v->getStatNo());
     }
     $this->aUserStats = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the UserStats object, it will not be re-added.
     if ($v !== null) {
         $v->addUserStatEquip($this);
     }
     return $this;
 }
コード例 #21
0
ファイル: user-stats.php プロジェクト: KelasKayu/wordpress
        wp_register_script("{$this->namespace}-tablesorter-widget", USERSTATS_URLPATH . "/js/jquery.tablesorter.widgets.min.js", array('jquery'), $this->version, true);
    }
    /**
     * Register styles used by this plugin for enqueuing elsewhere
     *
     * @uses wp_register_style()
     */
    function wp_register_styles()
    {
        // Admin Stylesheet
        wp_register_style("{$this->namespace}-admin", USERSTATS_URLPATH . "/css/admin.css", array(), $this->version, 'screen');
        wp_register_style("{$this->namespace}-front", USERSTATS_URLPATH . "/css/userstats.css", array(), $this->version, 'screen');
    }
}
if (!isset($UserStats)) {
    UserStats::instance();
}
register_activation_hook(__FILE__, array('UserStats', 'activate'));
register_deactivation_hook(__FILE__, array('UserStats', 'deactivate'));
function asz_round($value)
{
    if (version_compare(PHP_VERSION, '5.3.0', '<')) {
        $x = round(floor($value * 100) / 100, 2);
    } else {
        $x = round($value, 2, PHP_ROUND_HALF_UP);
    }
    return $x;
}
function asz_get_post_views()
{
    if (is_single()) {
コード例 #22
0
function wfUserFollowsRecommend($follower, $followee)
{
    global $wgUser;
    $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_UNKNOWN);
    // This feature is only available for logged-in users.
    if (!$wgUser->isLoggedIn()) {
        $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_NOT_LOGGED_IN);
        return $out;
    }
    // No need to allow blocked users to access this page, they could abuse it, y'know.
    if ($wgUser->isBlocked()) {
        $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_BLOCKED);
        return $out;
    }
    // Database operations require write mode
    if (wfReadOnly()) {
        $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_READ_ONLY);
        return $out;
    }
    // Are we even allowed to do this?
    if (!$wgUser->isAllowed('edit')) {
        $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_NOT_ALLOWED);
        return $out;
    }
    $uuf = new UserUserFollow();
    if ($follower === $wgUser->getName() && $followee !== $follower) {
        if ($uuf->addUserUserFollow($wgUser, User::newFromName($followee)) !== false) {
            $weekRank = UserStats::getUserRank(20, 'week');
            $monthRank = UserStats::getUserRank(20, 'month');
            $totalRank = UserStats::getUserRank(20, 'total');
            if (count($weekRank) >= 8) {
                $recommend = $weekRank;
            } elseif (count($monthRank) >= 8) {
                $recommend = $monthRank;
            } else {
                $recommend = $totalRank;
            }
            $recommendRes = array();
            $flres = array();
            foreach ($recommend as $value) {
                $tuser = User::newFromName($value['user_name']);
                $isFollow = $uuf->checkUserUserFollow($wgUser, $tuser);
                if (!$isFollow && $value['user_name'] != $wgUser->getName()) {
                    $flres['avatar'] = $value['avatarImage'];
                    $flres['username'] = $value['user_name'];
                    $flres['userurl'] = $value['user_url'];
                    $recommendRes[] = $flres;
                }
            }
            $n = count($recommendRes);
            $i = 5;
            $newUser = isset($recommendRes[$i]) ? $recommendRes[$i] : null;
            $res = array('success' => true, 'result' => $newUser);
            $out = json_encode($res);
            return $out;
        }
    }
}
コード例 #23
0
ファイル: reports.php プロジェクト: caseyi/BLIS
$page_elems->getProgressSpinner(LangUtil::$generalTerms['CMD_FETCHING']);
?>
						</span>
					</td>
				</tr>
			</table>
		</form>
	</div>
	
        <div id='user_stats_div' style='display:none;' class='reports_subdiv'>
		<b><?php 
echo "User Statistics";
?>
</b>
                <?php 
$userStats = new UserStats();
?>
		<!--<br><br>
                
                <a id="ustats_a" class="ustats_link_u" href='javascript:show_user_stats_submenu(1);'>User Stats for All Users</a>
                |
                <a id="ustats_i" class="ustats_link_u" href='javascript:show_user_stats_submenu(2);'>User Logs for Individual Users</a>

                <br><br>-->
                

		<form name="user_stats_form" id="user_stats_form" action="reports_user_stats_all.php" method='post' target='_blank'>
                    <table cellpadding="4px">
			
				<tr valign='top'>
					<td><?php 
コード例 #24
0
echo "Collective User Stats";
?>
</b> 
<?php 
/*| <a href="javascript:toggle_stat_table();" id='showtablelink'> # echo LangUtil::$pageTerms['MSG_SHOWGRAPH']; </a> */
?>
 | <a href='reports.php?show_ust'>&laquo; <?php 
echo LangUtil::$pageTerms['MSG_BACKTOREPORTS'];
?>
</a>
<br><br>
<?php 
$lab_config_id = $_REQUEST['location'];
$date_from = $_REQUEST['yyyy_from'] . "-" . $_REQUEST['mm_from'] . "-" . $_REQUEST['dd_from'];
$date_to = $_REQUEST['yyyy_to'] . "-" . $_REQUEST['mm_to'] . "-" . $_REQUEST['dd_to'];
$ust = new UserStats();
$pr_c = $_POST['count_type_pr'];
$sr_c = $_POST['count_type_sr'];
$tr_c = $_POST['count_type_tr'];
$re_c = $_POST['count_type_re'];
$uiinfo = "from=" . $date_from . "&to=" . $date_to . "&pr=" . $pr_c . "&sr=" . $sr_c . "&tr=" . $tr_c . "&re=" . $re_c;
putUILog('reports_user_stats_all', $uiinfo, basename($_SERVER['REQUEST_URI'], ".php"), 'X', 'X', 'X');
//echo $pr_c."-".$sr_c."-".$tr_c."-".$re_c;
/*if($pr_c == 'Yes')
    echo "+++++++++++++++++++++++++";
else
    echo "-------------------------";*/
//echo "Hey:";
//print_r($ust->getTestStats(116, $lab_config_id,$date_from, $date_to));
DbUtil::switchToLabConfig($lab_config_id);
$lab_config = get_lab_config_by_id($lab_config_id);
コード例 #25
0
ファイル: index.php プロジェクト: bionicle12/testsite
<?php

session_start();
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
include_once 'autoloader.php';
include_once 'config.php';
Lang::init();
UserStats::setstats();
if (isset($_GET['ajax'])) {
    include_once 'ajax/index.php';
    exit;
}
$route = new Router();
$route->navigate();
コード例 #26
0
    /**
     * Show the special page
     *
     * @param $params Mixed: parameter(s) passed to the page or null
     */
    public function execute($params)
    {
        global $wgUser, $wgOut, $wgRequest, $wgScriptPath, $wgHooks, $wgUserBoardScripts;
        // This hooked function adds a global JS variable that UserBoard.js
        // uses to the HTML
        $wgHooks['MakeGlobalVariablesScript'][] = 'SpecialViewUserBoard::addJSGlobals';
        // Add CSS & JS
        $wgOut->addExtensionStyle($wgUserBoardScripts . '/UserBoard.css');
        $wgOut->addScriptFile($wgUserBoardScripts . '/UserBoard.js');
        $ub_messages_show = 25;
        $user_name = $wgRequest->getVal('user');
        $user_name_2 = $wgRequest->getVal('conv');
        $user_id_2 = '';
        // Prevent E_NOTICE
        $page = $wgRequest->getInt('page', 1);
        /**
         * Redirect Non-logged in users to Login Page
         * It will automatically return them to the UserBoard page
         */
        if ($wgUser->getID() == 0 && $user_name == '') {
            $login = SpecialPage::getTitleFor('Userlogin');
            $wgOut->redirect($login->getFullURL('returnto=Special:UserBoard'));
            return false;
        }
        /**
         * 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);
        $user = Title::makeTitle(NS_USER, $user_name);
        $user_safe = str_replace('&', '%26', $user_name);
        if ($user_name_2) {
            $user_id_2 = User::idFromName($user_name_2);
            $user_2 = Title::makeTitle(NS_USER, $user_name);
            $user_safe_2 = urlencode($user_name_2);
        }
        /**
         * Error message for username that does not exist (from URL)
         */
        if ($user_id == 0) {
            $wgOut->showErrorPage('error', 'userboard_noexist');
            return false;
        }
        /**
         * Config for the page
         */
        $per_page = $ub_messages_show;
        $b = new UserBoard();
        $ub_messages = $b->getUserBoardMessages($user_id, $user_id_2, $ub_messages_show, $page);
        if (!$user_id_2) {
            $stats = new UserStats($user_id, $user_name);
            $stats_data = $stats->getUserStats();
            $total = $stats_data['user_board'];
            // If user is viewing their own board or is allowed to delete
            // others' board messages, show the total count of board messages
            // to them (public + private messages)
            if ($wgUser->getName() == $user_name || $wgUser->isAllowed('userboard-delete')) {
                $total = $total + $stats_data['user_board_priv'];
            }
        } else {
            $total = $b->getUserBoardToBoardCount($user_id, $user_id_2);
        }
        if (!$user_id_2) {
            if (!($wgUser->getName() == $user_name)) {
                $wgOut->setPageTitle(wfMsg('userboard_owner', $user_name));
            } else {
                $b->clearNewMessageCount($wgUser->getID());
                $wgOut->setPageTitle(wfMsg('userboard_yourboard'));
            }
        } else {
            if ($wgUser->getName() == $user_name) {
                $wgOut->setPageTitle(wfMsg('userboard_yourboardwith', $user_name_2));
            } else {
                $wgOut->setPageTitle(wfMsg('userboard_otherboardwith', $user_name, $user_name_2));
            }
        }
        $output = '<div class="user-board-top-links">';
        $output .= '<a href="' . $user->escapeFullURL() . '">&lt; ' . wfMsg('userboard_backprofile', $user_name) . '</a>';
        $output .= '</div>';
        $board_to_board = '';
        // Prevent E_NOTICE
        if ($page == 1) {
            $start = 1;
        } else {
            $start = ($page - 1) * $per_page + 1;
        }
        $end = $start + count($ub_messages) - 1;
        if ($wgUser->getName() != $user_name) {
            $board_to_board = '<a href="' . UserBoard::getUserBoardToBoardURL($wgUser->getName(), $user_name) . '">' . wfMsg('userboard_boardtoboard') . '</a>';
        }
        if ($total) {
            $output .= '<div class="user-page-message-top">
			<span class="user-page-message-count">' . wfMsg('userboard_showingmessages', $total, $start, $end, $end - $start + 1) . "</span> {$board_to_board}\n\t\t\t</div>";
        }
        /**
         * Build next/prev nav
         */
        $qs = '';
        if ($user_id_2) {
            $qs = "&conv={$user_safe_2}";
        }
        $numofpages = $total / $per_page;
        if ($numofpages > 1) {
            $output .= '<div class="page-nav">';
            if ($page > 1) {
                $output .= '<a href="' . $wgScriptPath . "/index.php?title=Special:UserBoard&user={$user_safe}&page=" . ($page - 1) . "{$qs}\">" . wfMsg('userboard_prevpage') . '</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="' . $wgScriptPath . "/index.php?title=Special:UserBoard&user={$user_safe}&page={$i}{$qs}\">{$i}</a> ";
                }
            }
            if ($total - $per_page * $page > 0) {
                $output .= ' <a href="' . $wgScriptPath . "/index.php?title=Special:UserBoard&user={$user_safe}&page=" . ($page + 1) . "{$qs}\">" . wfMsg('userboard_nextpage') . '</a>';
            }
            $output .= '</div><p>';
        }
        /**
         * Build next/prev nav
         */
        $can_post = false;
        $user_name_from = '';
        // Prevent E_NOTICE
        if (!$user_id_2) {
            if ($wgUser->getName() != $user_name) {
                $can_post = true;
                $user_name_to = htmlspecialchars($user_name, ENT_QUOTES);
            }
        } else {
            if ($wgUser->getName() == $user_name) {
                $can_post = true;
                $user_name_to = htmlspecialchars($user_name_2, ENT_QUOTES);
                $user_name_from = htmlspecialchars($user_name, ENT_QUOTES);
            }
        }
        if ($wgUser->isBlocked()) {
            // only let them post to admins
            //$user_to = User::newFromId( $user_id );
            // if( !$user_to->isAllowed( 'delete' ) ) {
            $can_post = false;
            // }
        }
        if ($can_post) {
            if ($wgUser->isLoggedIn() && !$wgUser->isBlocked()) {
                $output .= '<div class="user-page-message-form">
					<input type="hidden" id="user_name_to" name="user_name_to" value="' . $user_name_to . '"/>
					<input type="hidden" id="user_name_from" name="user_name_from" value="' . $user_name_from . '"/>
					<span class="user-board-message-type">' . wfMsg('userboard_messagetype') . ' </span>
					<select id="message_type">
						<option value="0">' . wfMsg('userboard_public') . '</option>
						<option value="1">' . wfMsg('userboard_private') . '</option>
					</select>
					<p>
					<textarea name="message" id="message" cols="63" rows="4"></textarea>

					<div class="user-page-message-box-button">
						<input type="button" value="' . wfMsg('userboard_sendbutton') . '" class="site-button" onclick="javascript:UserBoard.sendMessage(' . $per_page . ');" />
					</div>

				</div>';
            } else {
                $login_link = SpecialPage::getTitleFor('Userlogin');
                $output .= '<div class="user-page-message-form">' . wfMsg('userboard_loggedout', $login_link->escapeFullURL()) . '</div>';
            }
        }
        $output .= '<div id="user-page-board">';
        if ($ub_messages) {
            foreach ($ub_messages as $ub_message) {
                $user = Title::makeTitle(NS_USER, $ub_message['user_name_from']);
                $avatar = new wAvatar($ub_message['user_id_from'], 'm');
                $board_to_board = '';
                $board_link = '';
                $ub_message_type_label = '';
                $delete_link = '';
                if ($wgUser->getName() != $ub_message['user_name_from']) {
                    $board_to_board = '<a href="' . UserBoard::getUserBoardToBoardURL($user_name, $ub_message['user_name_from']) . '">' . wfMsg('userboard_boardtoboard') . '</a>';
                    $board_link = '<a href="' . UserBoard::getUserBoardURL($ub_message['user_name_from']) . '">' . wfMsg('userboard_sendmessage', $ub_message['user_name_from']) . '</a>';
                } else {
                    $board_link = '<a href="' . UserBoard::getUserBoardURL($ub_message['user_name_from']) . '">' . wfMsg('userboard_myboard') . '</a>';
                }
                // If the user owns this private message or they are allowed to
                // delete board messages, show the "delete" link to them
                if ($wgUser->getName() == $ub_message['user_name'] || $wgUser->isAllowed('userboard-delete')) {
                    $delete_link = "<span class=\"user-board-red\">\n\t\t\t\t\t\t<a href=\"javascript:void(0);\" onclick=\"javascript:UserBoard.deleteMessage({$ub_message['id']})\">" . wfMsg('userboard_delete') . '</a>
					</span>';
                }
                // Mark private messages as such
                if ($ub_message['type'] == 1) {
                    $ub_message_type_label = '(' . wfMsg('userboard_private') . ')';
                }
                // had global function to cut link text if too long and no breaks
                // $ub_message_text = preg_replace_callback( "/(<a[^>]*>)(.*?)(<\/a>)/i", 'cut_link_text', $ub_message['message_text'] );
                $ub_message_text = $ub_message['message_text'];
                $output .= "<div class=\"user-board-message\">\n\t\t\t\t\t<div class=\"user-board-message-from\">\n\t\t\t\t\t\t\t<a href=\"{$user->escapeFullURL()}\" title=\"{$ub_message['user_name_from']}}\">{$ub_message['user_name_from']} </a> {$ub_message_type_label}\n\t\t\t\t\t</div>\n\t\t\t\t\t<div class=\"user-board-message-time\">" . wfMsgHtml('userboard_posted_ago', $b->getTimeAgo($ub_message['timestamp'])) . "</div>\n\t\t\t\t\t<div class=\"user-board-message-content\">\n\t\t\t\t\t\t<div class=\"user-board-message-image\">\n\t\t\t\t\t\t\t<a href=\"{$user->escapeFullURL()}\" title=\"{$ub_message['user_name_from']}\">{$avatar->getAvatarURL()}</a>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t<div class=\"user-board-message-body\">\n\t\t\t\t\t\t\t{$ub_message_text}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t<div class=\"cleared\"></div>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div class=\"user-board-message-links\">\n\t\t\t\t\t\t{$board_link}\n\t\t\t\t\t\t{$board_to_board}\n\t\t\t\t\t\t{$delete_link}\n\t\t\t\t\t</div>\n\t\t\t\t</div>";
            }
        } else {
            $invite_title = SpecialPage::getTitleFor('InviteContacts');
            $output .= '<p>' . wfMsg('userboard_nomessages', $invite_title->escapeFullURL()) . '</p>';
        }
        $output .= '</div>';
        $wgOut->addHTML($output);
    }
コード例 #27
0
	/**
	 * Shows the initial page that prompts the image upload.
	 */
	function showHomePage() {
		global $wgRequest, $wgUser, $wgOut, $wgScriptPath;

		// You need to be logged in to create a new picture game (because
		// usually only registered users can upload files)
		if( !$wgUser->isLoggedIn() ) {
			$wgOut->setPageTitle( wfMsg( 'picturegame-creategametitle' ) );
			$output = wfMsg( 'picturegame-creategamenotloggedin' );
			$output .= "<p>
				<input type=\"button\" class=\"site-button\" onclick=\"window.location='" .
					SpecialPage::getTitleFor( 'Userlogin', 'signup' )->escapeFullURL() .
					"'\" value=\"" . wfMsg( 'picturegame-signup' ) . "\" />
				<input type=\"button\" class=\"site-button\" onclick=\"window.location='" .
					SpecialPage::getTitleFor( 'Userlogin' )->escapeFullURL() .
					"'\" value=\"" . wfMsg( 'picturegame-login' ) . "\" />
			</p>";
			$wgOut->addHTML( $output );
			return;
		}

		/**
		 * Create Picture Game Thresholds based on User Stats
		 */
		global $wgCreatePictureGameThresholds;
		if( is_array( $wgCreatePictureGameThresholds ) && count( $wgCreatePictureGameThresholds ) > 0 ) {
			$can_create = true;

			$stats = new UserStats( $wgUser->getID(), $wgUser->getName() );
			$stats_data = $stats->getUserStats();

			$threshold_reason = '';
			foreach( $wgCreatePictureGameThresholds as $field => $threshold ) {
				if ( str_replace( ',', '', $stats_data[$field] ) < $threshold ) {
					$can_create = false;
					$threshold_reason .= ( ( $threshold_reason ) ? ', ' : '' ) . "$threshold $field";
				}
			}

			if( $can_create == false ) {
				global $wgSupressPageTitle;
				$wgSupressPageTitle = false;
				$wgOut->setPageTitle( wfMsg( 'picturegame-create-threshold-title' ) );
				$wgOut->addHTML( wfMsg( 'picturegame-create-threshold-reason', $threshold_reason ) );
				return '';
			}
		}

		// Show a link to the admin panel for picture game admins
		if( $wgUser->isAllowed( 'picturegameadmin' ) ) {
			$adminlink = '<a href="' . $this->getTitle()->escapeFullURL( 'picGameAction=adminPanel' ) . '"> ' .
				wfMsg( 'picturegame-adminpanel' ) . ' </a>';
		}

		$dbr = wfGetDB( DB_MASTER );

		$excludedIds = $dbr->select(
			'picturegame_votes',
			'picid',
			array( 'username' => $wgUser->getName() ),
			__METHOD__
		);

		$excluded = array();
		foreach ( $excludedIds as $excludedId ) {
			$excluded[] = $excludedId->picid;
		}

		$canSkip = false;
		if ( !empty( $excluded ) ) {
			$myCount = (int)$dbr->selectField(
				'picturegame_images',
				'COUNT(*) AS mycount',
				array(
					'id NOT IN(' . implode( ',', $excluded  ) . ')',
					'flag != ' . PICTUREGAME_FLAG_FLAGGED,
					"img1 <> ''",
					"img2 <> ''"
				),
				__METHOD__
			);
			if ( $myCount > 0 ) {
				$canSkip = true;
			}
		}
		/*$sql = "SELECT COUNT(*) AS mycount FROM picturegame_images WHERE picturegame_images.id NOT IN
				(SELECT picid FROM picturegame_votes WHERE picturegame_votes.username='******')
			AND flag != " . PICTUREGAME_FLAG_FLAGGED . " AND img1 <> '' AND img2 <> '' LIMIT 1;";
		$res = $dbr->query( $sql, __METHOD__ );
		$row = $dbr->fetchObject( $res );

		$canSkip = ( $row->mycount != 0 ? true : false );*/

		// used for the key
		$now = time();

		$wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'picturegame-creategametitle' ) ) );

		$wgOut->addExtensionStyle( $wgScriptPath . '/extensions/PictureGame/picturegame/startgame.css' );
		// Anonymous functions are fun :) Too bad for you, PHP <= 5.2.x users!
		// @see http://php.net/manual/en/functions.anonymous.php
		global $wgHooks;
		$wgHooks['MakeGlobalVariablesScript'][] = function( $vars ) {
			// for the upload form (see PictureGame.js, the uploadComplete
			// functions)
			$vars['__picturegame_edit__'] = wfMsg( 'picturegame-js-edit' );
			return true;
		};

		$output = "\t\t" . '<div class="pick-game-welcome-message">
			<h1>' . wfMsg( 'picturegame-creategametitle' ) . '</h1>';
		$output .= wfMsg( 'picturegame-creategamewelcome' );
		$output .= '<br />

			<div id="skipButton" class="startButton">';
		$play_button_text = wfMsg( 'picturegame-creategameplayinstead' );
		$skipButton = '';
		if ( $canSkip ) {
			$skipButton = "<input class=\"site-button\" type=\"button\" onclick=\"javascript:PictureGame.skipToGame()\" value=\"{$play_button_text}\"/>";
		}
		$output .= $skipButton .
				'</div>
			</div>

			<div class="uploadLeft">
				<div id="uploadTitle" class="uploadTitle">
					<form id="picGamePlay" name="picGamePlay" method="post" action="' .
						$this->getTitle()->escapeFullURL( 'picGameAction=createGame' ) . '">
						<h1>' . wfMsg( 'picturegame-creategamegametitle' ) . '</h1>
						<div class="picgame-errors" id="picgame-errors"></div>
						<p>
							<input name="picGameTitle" id="picGameTitle" type="text" value="" size="40" />
						</p>
						<input name="picOneURL" id="picOneURL" type="hidden" value="" />
						<input name="picTwoURL" id="picTwoURL" type="hidden" value="" />';
						/*<input name=\"picOneDesc\" id=\"picOneDesc\" type=\"hidden\" value=\"\" />
						<input name=\"picTwoDesc\" id=\"picTwoDesc\" type=\"hidden\" value=\"\" />*/
		$uploadObj = SpecialPage::getTitleFor( 'PictureGameAjaxUpload' );
		$output .= '<input name="key" type="hidden" value="' . md5( $now . $this->SALT ) . '" />
						<input name="chain" type="hidden" value="' . $now . '" />
					</form>
				</div>

				<div class="content">
					<div id="uploadImageForms" class="uploadImage">

						<div id="imageOneUpload" class="imageOneUpload">
							<h1>' . wfMsg( 'picturegame-createeditfirstimage' ) . '</h1>
							<!--Caption:<br /><input name="picOneDesc" id="picOneDesc" type="text" value="" /><br />-->
							<div id="imageOneUploadError"></div>
							<div id="imageOneLoadingImg" class="loadingImg" style="display:none">
								<img src="' . $wgScriptPath . '/extensions/PictureGame/images/ajax-loader-white.gif" alt="" />
							</div>
							<div id="imageOne" class="imageOne" style="display:none;"></div>
							<iframe class="imageOneUpload-frame" scrolling="no" frameborder="0" width="400" id="imageOneUpload-frame" src="' .
								$uploadObj->escapeFullURL( 'callbackPrefix=imageOne_' ) . '"></iframe>
						</div>

						<div id="imageTwoUpload" class="imageTwoUpload">
							<h1>' . wfMsg( 'picturegame-createeditsecondimage' ) . '</h1>
							<!--Caption:<br /><input name="picTwoDesc" id="picTwoDesc" type="text" value="" /><br />-->
							<div id="imageTwoUploadError"></div>
							<div id="imageTwoLoadingImg" class="loadingImg" style="display:none">
								<img src="' . $wgScriptPath . '/extensions/PictureGame/images/ajax-loader-white.gif" alt="" />
							</div>
							<div id="imageTwo" class="imageTwo" style="display:none;"></div>
							<iframe id="imageTwoUpload-frame" scrolling="no" frameborder="0" width="610" src="' .
								$uploadObj->escapeFullURL( 'callbackPrefix=imageTwo_' ) . '"></iframe>
						</div>

						<div class="cleared"></div>
					</div>
				</div>
			</div>

			<div id="startButton" class="startButton" style="display: none;">
				<input type="button" onclick="PictureGame.startGame()" value="' . wfMsg( 'picturegame-creategamecreateplay' ) . '" />
			</div>';

		$wgOut->addHTML( $output );
	}
コード例 #28
0
	function renderWelcomePage() {
		global $wgRequest, $wgUser, $wgOut, $wgHooks;

		// No access for blocked users
		if( $wgUser->isBlocked() ) {
			$wgOut->blockedPage( false );
			return false;
		}

		/**
		 * Create Quiz Thresholds based on User Stats
		 */
		global $wgCreateQuizThresholds;
		if( is_array( $wgCreateQuizThresholds ) && count( $wgCreateQuizThresholds ) > 0 ) {
			$can_create = true;

			$stats = new UserStats( $wgUser->getID(), $wgUser->getName() );
			$stats_data = $stats->getUserStats();

			$threshold_reason = '';
			foreach( $wgCreateQuizThresholds as $field => $threshold ) {
				if ( $stats_data[$field] < $threshold ) {
					$can_create = false;
					$threshold_reason .= ( ( $threshold_reason ) ? ', ' : '' ) . "$threshold $field";
				}
			}

			if( $can_create == false ) {
				global $wgSupressPageTitle;
				$wgSupressPageTitle = false;
				$wgOut->setPageTitle( wfMsg( 'quiz-create-threshold-title' ) );
				$wgOut->addHTML( wfMsg( 'quiz-create-threshold-reason', $threshold_reason ) );
				return '';
			}
		}

		$chain = time();
		$key = md5( $this->SALT . $chain );
		$max_answers = 8;

		// Add i18n messages (and max_answers) for the JS file
		$wgHooks['MakeGlobalVariablesScript'][] = 'QuizGameHome::addJSGlobalsForRenderWelcomePage';

		$wgOut->setPageTitle( wfMsg( 'quiz-create-title' ) );

		$output = '<div id="quiz-container" class="quiz-container">

			<div class="create-message">
				<h1>' . wfMsg( 'quiz-create-title' ) . '</h1>
				<p>' . wfMsgExt( 'quiz-create-message', 'parse' ) . '</p>
				<p><input class="site-button" type="button" onclick="document.location=\'' .
					$this->getTitle()->escapeFullURL( 'questionGameAction=launchGame' ) .
					'\'" value="' . wfMsg( 'quiz-play-quiz' ) . '" /></p>
			</div>

			<div class="quizgame-create-form" id="quizgame-create-form">
				<form id="quizGameCreate" name="quizGameCreate" method="post" action="' .
					$this->getTitle()->escapeFullURL( 'questionGameAction=createGame' ) . '">
				<div id="quiz-game-errors" style="color:red"></div>

				<h1>' . wfMsg( 'quiz-create-write-question' ) . '</h1>
				<input name="quizgame-question" id="quizgame-question" type="text" value="" size="64" />
				<h1 class="write-answer">' . wfMsg( 'quiz-create-write-answers' ) . '</h1>
				<span style="margin-top:10px;">' . wfMsg( 'quiz-create-check-correct' ) . '</span>';

		for( $x = 1; $x <= $max_answers; $x++ ) {
			$output .= "<div id=\"quizgame-answer-container-{$x}\" class=\"quizgame-answer\"" .
				( ( $x > 2 ) ? ' style="display:none;"' : '' ) . ">
				<span class=\"quizgame-answer-number\">{$x}.</span>
				<input name=\"quizgame-answer-{$x}\" id=\"quizgame-answer-{$x}\" type=\"text\" value=\"\" size=\"32\" onkeyup=\"QuizGame.updateAnswerBoxes();\" />
				<input type=\"checkbox\" onclick=\"javascript:QuizGame.welcomePage_toggleCheck(this)\" id=\"quizgame-isright-{$x}\" name=\"quizgame-isright-{$x}\">
			</div>";
		}

		$output .= '<input id="quizGamePictureName" name="quizGamePictureName" type="hidden" value="" />
				<input id="key" name="key" type="hidden" value="' . $key . '" />
				<input id="chain" name="chain" type="hidden" value="' . $chain . '" />

			</form>

			<h1 style="margin-top:20px">' .
				wfMsg( 'quiz-create-add-picture' ) . '</h1>
			<div id="quizgame-picture-upload" style="display:block;">

				<div id="real-form" style="display:block; height:90px;">
					<iframe id="imageUpload-frame" class="imageUpload-frame" width="650"
						scrolling="no" border="0" frameborder="0" src="' .
						SpecialPage::getTitleFor( 'QuestionGameUpload' )->escapeFullURL( 'wpThumbWidth=75&wpCategory=Quizgames' ) . '">
					</iframe>
				</div>
			</div>
			<div id="quizgame-picture-preview" class="quizgame-picture-preview"></div>
			<p id="quizgame-picture-reupload" style="display:none">
				<a href="javascript:QuizGame.showAttachPicture()">' .
					wfMsg( 'quiz-create-edit-picture' ) . '</a>
			</p>
			</div>

			<div id="startButton" class="startButton">
				<input type="button" class="site-button" onclick="QuizGame.startGame()" value="' . wfMsg( 'quiz-create-play' ) . '" />
			</div>

			</div>';

		$wgOut->addHTML( $output );
	}
コード例 #29
0
 /**
  * Updates the total amount of points the user has.
  *
  * @return Array
  */
 public function updateTotalPoints()
 {
     global $wgEnableFacebook, $wgUserLevels;
     if ($this->user_id == 0) {
         return array();
     }
     $stats_data = array();
     if (is_array($wgUserLevels)) {
         // Load points before update
         $stats = new UserStats($this->user_id, $this->user_name);
         $stats_data = $stats->getUserStats();
         $points_before = $stats_data['points'];
         // Load Honorific Level before update
         $user_level = new UserLevel($points_before);
         $level_number_before = $user_level->getLevelNumber();
     }
     $dbw = wfGetDB(DB_MASTER);
     $res = $dbw->select('user_stats', '*', array("stats_user_id = {$this->user_id}"), __METHOD__);
     $row = $dbw->fetchObject($res);
     if ($row) {
         // recaculate point total
         $new_total_points = 1000;
         if ($this->point_values) {
             foreach ($this->point_values as $point_field => $point_value) {
                 if ($this->stats_fields[$point_field]) {
                     $field = $this->stats_fields[$point_field];
                     $new_total_points += $point_value * $row->{$field};
                 }
             }
         }
         if ($wgEnableFacebook) {
             $s = $dbw->selectRow('fb_link_view_opinions', array('fb_user_id', 'fb_user_session_key'), array('fb_user_id_wikia' => $this->user_id), __METHOD__);
             if ($s !== false) {
                 $new_total_points += $this->point_values['facebook'];
             }
         }
         $dbw->update('user_stats', array('stats_total_points' => $new_total_points), array('stats_user_id' => $this->user_id), __METHOD__);
         // If user levels is in settings, check to see if user advanced with update
         if (is_array($wgUserLevels)) {
             // Get New Honorific Level
             $user_level = new UserLevel($new_total_points);
             $level_number_after = $user_level->getLevelNumber();
             // Check if the user advanced to a new level on this update
             if ($level_number_after > $level_number_before) {
                 $m = new UserSystemMessage();
                 $m->addMessage($this->user_name, 2, wfMessage('level-advanced-to', $user_level->getLevelName())->inContentLanguage()->parse());
                 $m->sendAdvancementNotificationEmail($this->user_id, $user_level->getLevelName());
             }
         }
         $this->clearCache();
     }
     return $stats_data;
 }
コード例 #30
0
ファイル: PollPage.php プロジェクト: schwarer2006/wikia
    /**
     * Called on every poll page view.
     */
    public function view()
    {
        global $wgUser, $wgTitle, $wgOut, $wgRequest, $wgScriptPath, $wgUploadPath, $wgLang;
        global $wgSupressPageTitle, $wgNameSpacesWithEditMenu;
        // Perform no custom handling if the poll in question has been deleted
        if (!$this->getID()) {
            parent::view();
        }
        $wgSupressPageTitle = true;
        $wgOut->setHTMLTitle($wgTitle->getText());
        $wgOut->setPageTitle($wgTitle->getText());
        $wgNameSpacesWithEditMenu[] = NS_POLL;
        $wgOut->addScript("<script type=\"text/javascript\">\n\t\t\t\$( function() { LightBox.init(); PollNY.show(); } );\n\t\t</script>\n");
        $createPollObj = SpecialPage::getTitleFor('CreatePoll');
        $wgOut->addHTML("<script type=\"text/javascript\">\n\t\t\tvar _POLL_OPEN_MESSAGE = \"" . addslashes(wfMsg('poll-open-message')) . "\";\n\t\t\tvar _POLL_CLOSE_MESSAGE = \"" . addslashes(wfMsg('poll-close-message')) . "\";\n\t\t\tvar _POLL_FLAGGED_MESSAGE = \"" . addslashes(wfMsg('poll-flagged-message')) . "\";\n\t\t\tvar _POLL_FINISHED = \"" . addslashes(wfMsg('poll-finished', $createPollObj->getFullURL(), $wgTitle->getFullURL())) . "\";\n\t\t</script>");
        // Get total polls count so we can tell the user how many they have
        // voted for out of total
        $dbr = wfGetDB(DB_MASTER);
        $total_polls = 0;
        $s = $dbr->selectRow('poll_question', array('COUNT(*) AS count'), array(), __METHOD__);
        if ($s !== false) {
            $total_polls = number_format($s->count);
        }
        $stats = new UserStats($wgUser->getID(), $wgUser->getName());
        $stats_current_user = $stats->getUserStats();
        $sk = $wgUser->getSkin();
        $p = new Poll();
        $poll_info = $p->getPoll($wgTitle->getArticleID());
        if (!isset($poll_info['id'])) {
            return '';
        }
        // Set up submitter data
        $user_title = Title::makeTitle(NS_USER, $poll_info['user_name']);
        $avatar = new wAvatar($poll_info['user_id'], 'l');
        $avatarID = $avatar->getAvatarImage();
        $stats = new UserStats($poll_info['user_id'], $poll_info['user_name']);
        $stats_data = $stats->getUserStats();
        $user_name_short = $wgLang->truncate($poll_info['user_name'], 27);
        $output = '<div class="poll-right">';
        // Show the "create a poll" link to registered users
        if ($wgUser->isLoggedIn()) {
            $output .= '<div class="create-link">
				<a href="' . $createPollObj->escapeFullURL() . '">
					<img src="' . $wgScriptPath . '/extensions/PollNY/images/addIcon.gif" alt="" />' . wfMsg('poll-create') . '</a>
			</div>';
        }
        $output .= '<div class="credit-box">
					<h1>' . wfMsg('poll-submitted-by') . "</h1>\n\t\t\t\t\t<div class=\"submitted-by-image\">\n\t\t\t\t\t\t<a href=\"{$user_title->getFullURL()}\">\n\t\t\t\t\t\t\t<img src=\"{$wgUploadPath}/avatars/{$avatarID}\" style=\"border:1px solid #d7dee8; width:50px; height:50px;\"/>\n\t\t\t\t\t\t</a>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div class=\"submitted-by-user\">\n\t\t\t\t\t\t<a href=\"{$user_title->getFullURL()}\">{$user_name_short}</a>\n\t\t\t\t\t\t<ul>\n\t\t\t\t\t\t\t<li>\n\t\t\t\t\t\t\t\t<img src=\"{$wgScriptPath}/extensions/PollNY/images/voteIcon.gif\" alt=\"\" />\n\t\t\t\t\t\t\t\t{$stats_data['votes']}\n\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t\t<li>\n\t\t\t\t\t\t\t\t<img src=\"{$wgScriptPath}/extensions/PollNY/images/pencilIcon.gif\" alt=\"\" />\n\t\t\t\t\t\t\t\t{$stats_data['edits']}\n\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t\t<li>\n\t\t\t\t\t\t\t\t<img src=\"{$wgScriptPath}/extensions/PollNY/images/commentsIcon.gif\" alt=\"\" />\n\t\t\t\t\t\t\t\t{$stats_data['comments']}\n\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div class=\"cleared\"></div>\n\n\t\t\t\t\t<a href=\"" . SpecialPage::getTitleFor('ViewPoll')->escapeFullURL('user='******'user_name']) . '">' . wfMsgExt('poll-view-all-by', 'parsemag', $user_name_short) . '</a>

				</div>';
        $output .= '<div class="poll-stats">';
        if ($wgUser->isLoggedIn()) {
            $output .= wfMsgExt('poll-voted-for', 'parsemag', '<b>' . $stats_current_user['poll_votes'] . '</b>', $total_polls, number_format($stats_current_user['poll_votes'] * 5));
        } else {
            $output .= wfMsgExt('poll-would-have-earned', 'parse', number_format($total_polls * 5));
        }
        $output .= '</div>' . "\n";
        $toggle_flag_label = $poll_info['status'] == 1 ? wfMsg('poll-flag-poll') : wfMsg('poll-unflag-poll');
        $toggle_flag_status = $poll_info['status'] == 1 ? 2 : 1;
        if ($poll_info['status'] == 1) {
            // Creator and admins can change the status of a poll
            $toggle_label = $poll_info['status'] == 1 ? wfMsg('poll-close-poll') : wfMsg('poll-open-poll');
            $toggle_status = $poll_info['status'] == 1 ? 0 : 1;
        }
        $output .= '<div class="poll-links">' . "\n";
        // Poll administrators can access the poll admin panel
        if ($wgUser->isAllowed('polladmin')) {
            $output .= '<a href="' . SpecialPage::getTitleFor('AdminPoll')->escapeFullURL() . '">' . wfMsg('poll-admin-panel') . '</a> | ';
        }
        if ($poll_info['status'] == 1 && ($poll_info['user_id'] == $wgUser->getID() || $wgUser->isAllowed('polladmin'))) {
            $output .= "<a href=\"javascript:void(0)\" onclick=\"PollNY.toggleStatus({$toggle_status});\">{$toggle_label}</a> |";
        }
        if ($poll_info['status'] == 1 || $wgUser->isAllowed('polladmin')) {
            $output .= " <a href=\"javascript:void(0)\" onclick=\"PollNY.toggleStatus({$toggle_flag_status});\">{$toggle_flag_label}</a>";
        }
        $output .= "\n" . '</div>' . "\n";
        // .poll-links
        $output .= '</div>' . "\n";
        // .poll-right
        $output .= '<div class="poll">' . "\n";
        $output .= "<h1 class=\"pagetitle\">{$wgTitle->getText()}</h1>\n";
        if ($poll_info['image']) {
            $poll_image_width = 150;
            $poll_image = wfFindFile($poll_info['image']);
            $poll_image_url = $width = '';
            if (is_object($poll_image)) {
                $poll_image_url = $poll_image->createThumb($poll_image_width);
                if ($poll_image->getWidth() >= $poll_image_width) {
                    $width = $poll_image_width;
                } else {
                    $width = $poll_image->getWidth();
                }
            }
            $poll_image_tag = '<img width="' . $width . '" alt="" src="' . $poll_image_url . '"/>';
            $output .= "<div class=\"poll-image\">{$poll_image_tag}</div>";
        }
        // Display question and let user vote
        if (!$p->userVoted($wgUser->getName(), $poll_info['id']) && $poll_info['status'] == 1) {
            $output .= '<div id="loading-poll">' . wfMsg('poll-js-loading') . '</div>' . "\n";
            $output .= '<div id="poll-display" style="display:none;">' . "\n";
            $output .= '<form name="poll"><input type="hidden" id="poll_id" name="poll_id" value="' . $poll_info['id'] . '"/>' . "\n";
            foreach ($poll_info['choices'] as $choice) {
                $output .= '<div class="poll-choice">
					<input type="radio" name="poll_choice" onclick="PollNY.vote()" id="poll_choice" value="' . $choice['id'] . '" />' . $choice['choice'] . '</div>';
            }
            $output .= '</form>
					</div>' . "\n";
            $output .= '<div class="poll-timestamp">' . wfMsg('poll-createdago', Poll::getTimeAgo($poll_info['timestamp'])) . '</div>' . "\n";
            $output .= "\t\t\t\t\t" . '<div class="poll-button">
					<a href="javascript:PollNY.skip();">' . wfMsg('poll-skip') . '</a>
				</div>';
            if ($wgRequest->getInt('prev_id')) {
                $p = new Poll();
                $poll_info_prev = $p->getPoll($wgRequest->getInt('prev_id'));
                $poll_title = Title::makeTitle(NS_POLL, $poll_info_prev['question']);
                $output .= '<div class="previous-poll">';
                $output .= '<div class="previous-poll-title">' . wfMsg('poll-previous-poll') . " - <a href=\"{$poll_title->getFullURL()}\">{$poll_info_prev['question']}</a></div>\n\t\t\t\t\t<div class=\"previous-sub-title\">" . wfMsgExt('poll-view-answered-times', 'parsemag', $poll_info_prev['votes']) . '</div>';
                $x = 1;
                foreach ($poll_info_prev['choices'] as $choice) {
                    if ($poll_info_prev['votes'] > 0) {
                        $percent = round($choice['votes'] / $poll_info_prev['votes'] * 100);
                        $bar_width = floor(360 * ($choice['votes'] / $poll_info_prev['votes']));
                    } else {
                        $percent = 0;
                        $bar_width = 0;
                    }
                    if (empty($choice['votes'])) {
                        $choice['votes'] = 0;
                    }
                    $bar_img = '<img src="' . $wgScriptPath . '/extensions/PollNY/images/vote-bar-' . $x . '.gif" class="image-choice-' . $x . '" style="width:' . $bar_width . 'px;height:11px;"/>';
                    $output .= "<div class=\"previous-poll-choice\">\n\t\t\t\t\t\t\t\t<div class=\"previous-poll-choice-left\">{$choice['choice']} ({$percent}%)</div>";
                    $output .= "<div class=\"previous-poll-choice-right\">{$bar_img} <span class=\"previous-poll-choice-votes\">" . wfMsgExt('poll-votes', 'parsemag', $choice['votes']) . '</span></div>';
                    $output .= '</div>';
                    $x++;
                }
                $output .= '</div>';
            }
        } else {
            $show_results = true;
            // Display message if poll has been closed for voting
            if ($poll_info['status'] == 0) {
                $output .= '<div class="poll-closed">' . wfMsg('poll-closed') . '</div>';
            }
            // Display message if poll has been flagged
            if ($poll_info['status'] == 2) {
                $output .= '<div class="poll-closed">' . wfMsg('poll-flagged') . '</div>';
                if (!$wgUser->isAllowed('polladmin')) {
                    $show_results = false;
                }
            }
            if ($show_results) {
                $x = 1;
                foreach ($poll_info['choices'] as $choice) {
                    if ($poll_info['votes'] > 0) {
                        $percent = round($choice['votes'] / $poll_info['votes'] * 100);
                        $bar_width = floor(480 * ($choice['votes'] / $poll_info['votes']));
                    } else {
                        $percent = 0;
                        $bar_width = 0;
                    }
                    // If it's not set, it means that no-one has voted for that
                    // choice yet...it also means that we need to set it
                    // manually here so that i18n displays properly
                    if (empty($choice['votes'])) {
                        $choice['votes'] = 0;
                    }
                    $bar_img = "<img src=\"{$wgScriptPath}/extensions/PollNY/images/vote-bar-{$x}.gif\" class=\"image-choice-{$x}\" style=\"width:{$bar_width}px;height:12px;\"/>";
                    $output .= "<div class=\"poll-choice\">\n\t\t\t\t\t<div class=\"poll-choice-left\">{$choice['choice']} ({$percent}%)</div>";
                    $output .= "<div class=\"poll-choice-right\">{$bar_img} <span class=\"poll-choice-votes\">" . wfMsgExt('poll-votes', 'parsemag', $choice['votes']) . '</span></div>';
                    $output .= '</div>';
                    $x++;
                }
            }
            $output .= '<div class="poll-total-votes">(' . wfMsgExt('poll-based-on-votes', 'parsemag', $poll_info['votes']) . ')</div>
			<div class="poll-timestamp">' . wfMsg('poll-createdago', Poll::getTimeAgo($poll_info['timestamp'])) . '</div>


			<div class="poll-button">
				<input type="hidden" id="poll_id" name="poll_id" value="' . $poll_info['id'] . '" />
				<a href="javascript:PollNY.loadingLightBox();PollNY.goToNewPoll();">' . wfMsg('poll-next-poll') . '</a>
			</div>';
        }
        // "Embed this on a wiki page" feature
        $poll_embed_name = htmlspecialchars($wgTitle->getText(), ENT_QUOTES);
        $output .= '<br />
			<table cellpadding="0" cellspacing="2" border="0">
				<tr>
					<td>
						<b>' . wfMsg('poll-embed') . "</b>\n\t\t\t\t\t</td>\n\t\t\t\t\t<td>\n\t\t\t\t\t\t<form name=\"embed_poll\">\n\t\t\t\t\t\t\t<input name='embed_code' style='width:300px;font-size:10px;' type='text' value='<pollembed title=\"{$poll_embed_name}\" />' onclick='javascript:document.embed_poll.embed_code.focus();document.embed_poll.embed_code.select();' readonly='readonly' />\n\t\t\t\t\t\t</form>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\t\t\t</table>\n";
        $output .= '</div>' . "\n";
        // .poll
        $output .= '<div class="cleared"></div>';
        $wgOut->addHTML($output);
        global $wgPollDisplay;
        if ($wgPollDisplay['comments']) {
            $wgOut->addWikiText('<comments/>');
        }
    }