http://www.mediawiki.org/wiki/Special:Code/MediaWiki/85538
Revision: 85538 Author: ashley Date: 2011-04-06 14:04:22 +0000 (Wed, 06 Apr 2011) Log Message: ----------- SocialProfile: in UserRelationship stuff, renamed some badly named variables, broke some long lines, removed unused variables and used $wgRequest->getInt() for int values instead of getVal() Modified Paths: -------------- trunk/extensions/SocialProfile/UserRelationship/SpecialAddRelationship.php trunk/extensions/SocialProfile/UserRelationship/SpecialRemoveRelationship.php trunk/extensions/SocialProfile/UserRelationship/SpecialViewRelationships.php Modified: trunk/extensions/SocialProfile/UserRelationship/SpecialAddRelationship.php =================================================================== --- trunk/extensions/SocialProfile/UserRelationship/SpecialAddRelationship.php 2011-04-06 13:53:02 UTC (rev 85537) +++ trunk/extensions/SocialProfile/UserRelationship/SpecialAddRelationship.php 2011-04-06 14:04:22 UTC (rev 85538) @@ -15,7 +15,7 @@ class SpecialAddRelationship extends UnlistedSpecialPage { /** - * Constructor + * Constructor -- set up the new special page */ public function __construct() { parent::__construct( 'AddRelationship' ); @@ -37,61 +37,61 @@ $wgOut->addExtensionStyle( $wgUserRelationshipScripts . '/UserRelationship.css' ); - $usertitle = Title::newFromDBkey( $wgRequest->getVal( 'user' ) ); + $userTitle = Title::newFromDBkey( $wgRequest->getVal( 'user' ) ); - if ( !$usertitle ) { + if ( !$userTitle ) { $wgOut->setPageTitle( wfMsgHtml( 'ur-error-title' ) ); $wgOut->addWikiText( wfMsgNoTrans( 'ur-add-no-user' ) ); return false; } - $user = Title::makeTitle( NS_USER, $usertitle->getText() ); + $user = Title::makeTitle( NS_USER, $userTitle->getText() ); - $this->user_name_to = $usertitle->getText(); + $this->user_name_to = $userTitle->getText(); $this->user_id_to = User::idFromName( $this->user_name_to ); - $this->relationship_type = $wgRequest->getVal( 'rel_type' ); + $this->relationship_type = $wgRequest->getInt( 'rel_type' ); if ( !$this->relationship_type || !is_numeric( $this->relationship_type ) ) { $this->relationship_type = 1; } if ( ( $wgUser->getID() == $this->user_id_to ) && ( $wgUser->getID() != 0 ) ) { $wgOut->setPageTitle( wfMsg( 'ur-error-title' ) ); - $out .= '<div class="relationship-error-message">' - . wfMsg( 'ur-add-error-message-yourself' ) . + $out .= '<div class="relationship-error-message">' . + wfMsg( 'ur-add-error-message-yourself' ) . '</div> <div> <input type="button" class="site-button" value="' . wfMsg( 'ur-main-page' ) . '" size="20" onclick=\'window.location="index.php?title="' . wfMsgForContent( 'mainpage' ) . '"\' />'; - if ( $wgUser->isLoggedIn() ) { - $out .= '<input type="button" class="site-button" value="' . wfMsg( 'ur-your-profile' ) . '" size="20" onclick=\'window.location="' . $wgUser->getUserPage()->escapeFullURL() . '"\' />'; - } + if ( $wgUser->isLoggedIn() ) { + $out .= '<input type="button" class="site-button" value="' . wfMsg( 'ur-your-profile' ) . '" size="20" onclick=\'window.location="' . $wgUser->getUserPage()->escapeFullURL() . '"\' />'; + } $out .= '</div>'; $wgOut->addHTML( $out ); } elseif ( $wgUser->isBlocked() ) { $wgOut->setPageTitle( wfMsg( 'ur-error-title' ) ); - $out .= '<div class="relationship-error-message">' - . wfMsg( 'ur-add-error-message-blocked' ) . + $out .= '<div class="relationship-error-message">' . + wfMsg( 'ur-add-error-message-blocked' ) . '</div> <div> <input type="button" class="site-button" value="' . wfMsg( 'ur-main-page' ) . '" size="20" onclick=\'window.location="index.php?title="' . wfMsgForContent( 'mainpage' ) . '"\' />'; - if ( $wgUser->isLoggedIn() ) { - $out .= '<input type="button" class="site-button" value="' . wfMsg( 'ur-your-profile' ) . '" size="20" onclick=\'window.location="' . $wgUser->getUserPage()->escapeFullURL() . '"\' />'; - } + if ( $wgUser->isLoggedIn() ) { + $out .= '<input type="button" class="site-button" value="' . wfMsg( 'ur-your-profile' ) . '" size="20" onclick=\'window.location="' . $wgUser->getUserPage()->escapeFullURL() . '"\' />'; + } $out .= '</div>'; $wgOut->addHTML( $out ); } elseif ( $this->user_id_to == 0 ) { $wgOut->setPageTitle( wfMsg( 'ur-error-title' ) ); - $out .= '<div class="relationship-error-message">' - . wfMsg( 'ur-add-error-message-no-user' ) . + $out .= '<div class="relationship-error-message">' . + wfMsg( 'ur-add-error-message-no-user' ) . '</div> <div> <input type="button" class="site-button" value="' . wfMsg( 'ur-main-page' ) . '" size="20" onclick=\'window.location="index.php?title="' . wfMsgForContent( 'mainpage' ) . '"\' />'; - if ( $wgUser->isLoggedIn() ) { - $out .= '<input type="button" class="site-button" value="' . wfMsg( 'ur-your-profile' ) . '" size="20" onclick=\'window.location="' . $wgUser->getUserPage()->escapeFullURL() . '"\' />'; - } + if ( $wgUser->isLoggedIn() ) { + $out .= '<input type="button" class="site-button" value="' . wfMsg( 'ur-your-profile' ) . '" size="20" onclick=\'window.location="' . $wgUser->getUserPage()->escapeFullURL() . '"\' />'; + } $out .= '</div>'; $wgOut->addHTML( $out ); @@ -105,7 +105,8 @@ } $avatar = new wAvatar( $this->user_id_to, 'l' ); - $avatar_img = '<img src="' . $wgUploadPath . '/avatars/' . $avatar->getAvatarImage() . '" alt="" border="0" />'; + $avatar_img = '<img src="' . $wgUploadPath . '/avatars/' . + $avatar->getAvatarImage() . '" alt="" border="0" />'; $out = ''; $wgOut->setPageTitle( wfMsg( 'ur-error-title' ) ); @@ -131,7 +132,8 @@ } $avatar = new wAvatar( $this->user_id_to, 'l' ); - $avatar_img = '<img src="' . $wgUploadPath . '/avatars/' . $avatar->getAvatarImage() . '" alt="" border="0" />'; + $avatar_img = '<img src="' . $wgUploadPath . '/avatars/' . + $avatar->getAvatarImage() . '" alt="" border="0" />'; $out = ''; $wgOut->setPageTitle( wfMsg( 'ur-add-error-message-pending-request-title' ) ); @@ -177,7 +179,8 @@ $rel = $rel->addRelationshipRequest( $this->user_name_to, $this->relationship_type, $wgRequest->getVal( 'message' ) ); $avatar = new wAvatar( $this->user_id_to, 'l' ); - $avatar_img = '<img src="' . $wgUploadPath . '/avatars/' . $avatar->getAvatarImage() . '" alt="" border="0" />'; + $avatar_img = '<img src="' . $wgUploadPath . '/avatars/' . + $avatar->getAvatarImage() . '" alt="" border="0" />'; $out = ''; @@ -214,8 +217,6 @@ function displayForm() { global $wgOut, $wgUploadPath; - $form = ''; - if ( $this->relationship_type == 1 ) { $wgOut->setPageTitle( wfMsg( 'ur-add-title-friend', $this->user_name_to ) ); $add = wfMsg( 'ur-add-message-friend', $this->user_name_to ); @@ -227,18 +228,17 @@ } $avatar = new wAvatar( $this->user_id_to, 'l' ); - $avatar_img = '<img src="' . $wgUploadPath . '/avatars/' . $avatar->getAvatarImage() . '" alt="" border="0" />'; + $avatar_img = '<img src="' . $wgUploadPath . '/avatars/' . + $avatar->getAvatarImage() . '" alt="" border="0" />'; - $user_link = Title::makeTitle( NS_USER, $this->user_name_to ); - - $form .= "<form action=\"\" method=\"post\" enctype=\"multipart/form-data\" name=\"form1\"> + $form = "<form action=\"\" method=\"post\" enctype=\"multipart/form-data\" name=\"form1\"> <div class=\"relationship-action\"> {$avatar_img} " . $add . '<div class="cleared"></div> </div> - <div class="relationship-textbox-title">' - . wfMsg( 'ur-add-personal-message' ) . + <div class="relationship-textbox-title">' . + wfMsg( 'ur-add-personal-message' ) . '</div> <textarea name="message" id="message" rows="3" cols="50"></textarea> <div class="relationship-buttons"> Modified: trunk/extensions/SocialProfile/UserRelationship/SpecialRemoveRelationship.php =================================================================== --- trunk/extensions/SocialProfile/UserRelationship/SpecialRemoveRelationship.php 2011-04-06 13:53:02 UTC (rev 85537) +++ trunk/extensions/SocialProfile/UserRelationship/SpecialRemoveRelationship.php 2011-04-06 14:04:22 UTC (rev 85538) @@ -14,7 +14,7 @@ class SpecialRemoveRelationship extends UnlistedSpecialPage { /** - * Constructor + * Constructor -- set up the new special page */ public function __construct() { parent::__construct( 'RemoveRelationship' ); @@ -45,16 +45,19 @@ $this->user_name_to = $usertitle->getText(); $this->user_id_to = User::idFromName( $this->user_name_to ); - $this->relationship_type = UserRelationship::getUserRelationshipByID( $this->user_id_to, $wgUser->getID() ); + $this->relationship_type = UserRelationship::getUserRelationshipByID( + $this->user_id_to, + $wgUser->getID() + ); if ( $this->relationship_type == 1 ) { - $confirmtitle = wfMsg( 'ur-remove-relationship-title-confirm-friend', $this->user_name_to ); - $confirmmsg = wfMsg( 'ur-remove-relationship-message-confirm-friend', $this->user_name_to ); + $confirmTitle = wfMsg( 'ur-remove-relationship-title-confirm-friend', $this->user_name_to ); + $confirmMsg = wfMsg( 'ur-remove-relationship-message-confirm-friend', $this->user_name_to ); $error = wfMsg( 'ur-remove-error-not-loggedin-friend' ); $pending = wfMsg( 'ur-remove-error-message-pending-friend-request', $this->user_name_to ); } else { - $confirmtitle = wfMsg( 'ur-remove-relationship-title-confirm-foe', $this->user_name_to ); - $confirmmsg = wfMsg( 'ur-remove-relationship-message-confirm-foe', $this->user_name_to ); + $confirmTitle = wfMsg( 'ur-remove-relationship-title-confirm-foe', $this->user_name_to ); + $confirmMsg = wfMsg( 'ur-remove-relationship-message-confirm-foe', $this->user_name_to ); $error = wfMsg( 'ur-remove-error-not-loggedin-foe' ); $pending = wfMsg( 'ur-remove-error-message-pending-foe-request', $this->user_name_to ); } @@ -75,8 +78,8 @@ $wgOut->addHTML( $out ); } elseif ( $this->relationship_type == false ) { $wgOut->setPageTitle( wfMsg( 'ur-error-title' ) ); - $out .= '<div class="relationship-error-message">' - . wfMsg( 'ur-remove-error-message-no-relationship', $this->user_name_to ) . + $out .= '<div class="relationship-error-message">' . + wfMsg( 'ur-remove-error-message-no-relationship', $this->user_name_to ) . '</div> <div> <input type="button" class="site-button" value="' . wfMsg( 'ur-main-page' ) . '" size="20" onclick=\'window.location="index.php?title="' . wfMsgForContent( 'mainpage' ) . '"\' />'; @@ -88,9 +91,9 @@ $wgOut->addHTML( $out ); } elseif ( UserRelationship::userHasRequestByID( $this->user_id_to, $wgUser->getID() ) == true ) { $wgOut->setPageTitle( wfMsg( 'ur-error-title' ) ); - $out .= '<div class="relationship-error-message"> - ' . $pending . ' - </div> + $out .= '<div class="relationship-error-message">' . + $pending . + '</div> <div> <input type="button" class="site-button" value="' . wfMsg( 'ur-main-page' ) . '" size="20" onclick=\'window.location="index.php?title="' . wfMsgForContent( 'mainpage' ) . '"\' />'; if ( $wgUser->isLoggedIn() ) { @@ -101,8 +104,8 @@ $wgOut->addHTML( $out ); } elseif ( $wgUser->getID() == 0 ) { $wgOut->setPageTitle( wfMsg( 'ur-error-title' ) ); - $out .= '<div class="relationship-error-message">' - . $error . + $out .= '<div class="relationship-error-message">' . + $error . '</div> <div> <input type="button" class="site-button" value="' . wfMsg( 'ur-main-page' ) . '" size="20" onclick=\'window.location="index.php?title="' . wfMsgForContent( 'mainpage' ) . '"\' />'; @@ -115,18 +118,25 @@ } else { $rel = new UserRelationship( $wgUser->getName() ); if ( $wgRequest->wasPosted() && $_SESSION['alreadysubmitted'] == false ) { - $_SESSION['alreadysubmitted'] = true; - $rel->removeRelationshipByUserID( $this->user_id_to, $wgUser->getID() ); - $rel->sendRelationshipRemoveEmail( $this->user_id_to, $wgUser->getName(), $this->relationship_type ); + $rel->removeRelationshipByUserID( + $this->user_id_to, + $wgUser->getID() + ); + $rel->sendRelationshipRemoveEmail( + $this->user_id_to, + $wgUser->getName(), + $this->relationship_type + ); $avatar = new wAvatar( $this->user_id_to, 'l' ); - $avatar_img = '<img src="' . $wgUploadPath . '/avatars/' . $avatar->getAvatarImage() . '" alt="" border="" />'; + $avatar_img = '<img src="' . $wgUploadPath . '/avatars/' . + $avatar->getAvatarImage() . '" alt="" border="" />'; - $wgOut->setPageTitle( $confirmtitle ); + $wgOut->setPageTitle( $confirmTitle ); $out .= "<div class=\"relationship-action\"> - {$avatar_img} - " . $confirmmsg . " - <div class=\"relationship-buttons\"> + {$avatar_img}" . + $confirmMsg . + "<div class=\"relationship-buttons\"> <input type=\"button\" class=\"site-button\" value=\"" . wfMsg( 'ur-main-page' ) . "\" size=\"20\" onclick=\"window.location='index.php?title=" . wfMsgForContent( 'mainpage' ) . "'\"/> <input type=\"button\" class=\"site-button\" value=\"" . wfMsg( 'ur-your-profile' ) . "\" size=\"20\" onclick=\"window.location='" . $wgUser->getUserPage()->escapeFullURL() . "'\"/> </div> @@ -149,9 +159,9 @@ function displayForm() { global $wgOut, $wgUploadPath; - $form = ''; $avatar = new wAvatar( $this->user_id_to, 'l' ); - $avatar_img = '<img src="' . $wgUploadPath . '/avatars/' . $avatar->getAvatarImage() . '" alt="avatar" />'; + $avatar_img = '<img src="' . $wgUploadPath . '/avatars/' . + $avatar->getAvatarImage() . '" alt="avatar" />'; if ( $this->relationship_type == 1 ) { $title = wfMsg( 'ur-remove-relationship-title-friend', $this->user_name_to ); @@ -161,10 +171,11 @@ $remove = wfMsg( 'ur-remove-relationship-message-foe', $this->user_name_to, wfMsg( 'ur-remove' ) ); } $wgOut->setPageTitle( $title ); - $form .= "<form action=\"\" method=\"post\" enctype=\"multipart/form-data\" name=\"form1\"> + + $form = "<form action=\"\" method=\"post\" enctype=\"multipart/form-data\" name=\"form1\"> <div class=\"relationship-action\"> - {$avatar_img} - " . $remove . + {$avatar_img}" . + $remove . '<div class="relationship-buttons"> <input type="hidden" name="user" value="' . addslashes( $this->user_name_to ) . '" /> <input type="button" class="site-button" value="' . wfMsg( 'ur-remove' ) . '" size="20" onclick="document.form1.submit()" /> @@ -173,7 +184,8 @@ <div class="cleared"></div> </div> - </form>'; + </form>'; + return $form; } } Modified: trunk/extensions/SocialProfile/UserRelationship/SpecialViewRelationships.php =================================================================== --- trunk/extensions/SocialProfile/UserRelationship/SpecialViewRelationships.php 2011-04-06 13:53:02 UTC (rev 85537) +++ trunk/extensions/SocialProfile/UserRelationship/SpecialViewRelationships.php 2011-04-06 14:04:22 UTC (rev 85538) @@ -14,7 +14,7 @@ class SpecialViewRelationships extends SpecialPage { /** - * Constructor + * Constructor -- set up the new special page */ public function __construct() { parent::__construct( 'ViewRelationships' ); @@ -33,11 +33,11 @@ $output = ''; /** - * Get querystring variables + * Get query string variables */ $user_name = $wgRequest->getVal( 'user' ); - $rel_type = $wgRequest->getVal( 'rel_type' ); - $page = $wgRequest->getVal( 'page' ); + $rel_type = $wgRequest->getInt( 'rel_type' ); + $page = $wgRequest->getInt( 'page' ); /** * Redirect Non-logged in users to Login Page @@ -76,8 +76,8 @@ */ if ( $user_id == 0 ) { $wgOut->setPageTitle( wfMsg( 'ur-error-title' ) ); - $out .= '<div class="relationship-error-message">' - . wfMsg( 'ur-error-message-no-user' ) . + $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' ) . '"\' />'; @@ -108,7 +108,9 @@ $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> + <a href="' . $back_link->escapeFullURL() . '">' . + wfMsg( 'ur-backlink', $rel->user_name ) . + '</a> </div> <div class="relationship-count">' . wfMsgExt( @@ -123,7 +125,9 @@ $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> + <a href="' . $back_link->escapeFullURL() . '">' . + wfMsg( 'ur-backlink', $rel->user_name ) . + '</a> </div> <div class="relationship-count">' . wfMsgExt( @@ -146,9 +150,9 @@ // Safe titles $user = Title::makeTitle( NS_USER, $relationship['user_name'] ); - $add_relationship_link = SpecialPage::getTitleFor( 'AddRelationship' ); - $remove_relationship_link = SpecialPage::getTitleFor( 'RemoveRelationship' ); - $give_gift_link = SpecialPage::getTitleFor( 'GiveGift' ); + $addRelationshipLink = SpecialPage::getTitleFor( 'AddRelationship' ); + $removeRelationshipLink = SpecialPage::getTitleFor( 'RemoveRelationship' ); + $giveGiftLink = SpecialPage::getTitleFor( 'GiveGift' ); $avatar = new wAvatar( $relationship['user_id'], 'ml' ); @@ -160,7 +164,8 @@ $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 ); + $user_name_display = substr( $relationship['user_name'], 0, 30 ) . + ' ' . substr( $relationship['user_name'], 30, 50 ); } else { $user_name_display = $relationship['user_name']; } @@ -174,15 +179,15 @@ <div class=\"relationship-actions\">"; if ( $indivRelationship == false ) { $output .= $wgLang->pipeList( array( - '<a href="' . $add_relationship_link->escapeFullURL( 'user=' . $user_safe . '&rel_type=1' ) . '">' . wfMsg( 'ur-add-friend' ) . '</a>', - '<a href="' . $add_relationship_link->escapeFullURL( 'user=' . $user_safe . '&rel_type=2' ) . '">' . wfMsg( 'ur-add-foe' ) . '</a>', + '<a href="' . $addRelationshipLink->escapeFullURL( 'user=' . $user_safe . '&rel_type=1' ) . '">' . wfMsg( 'ur-add-friend' ) . '</a>', + '<a href="' . $addRelationshipLink->escapeFullURL( 'user=' . $user_safe . '&rel_type=2' ) . '">' . wfMsg( 'ur-add-foe' ) . '</a>', '' ) ); } elseif ( $user_name == $wgUser->getName() ) { - $output .= '<a href="' . $remove_relationship_link->escapeFullURL( 'user=' . $user_safe ) . '">' . $rem . '</a>'; + $output .= '<a href="' . $removeRelationshipLink->escapeFullURL( 'user=' . $user_safe ) . '">' . $rem . '</a>'; $output .= wfMsgExt( 'pipe-separator', 'escapenoentities' ); } - $output .= '<a href="' . $give_gift_link->escapeFullURL( 'user=' . $user_safe ) . '">' . wfMsg( 'ur-give-gift' ) . '</a>'; + $output .= '<a href="' . $giveGiftLink->escapeFullURL( 'user=' . $user_safe ) . '">' . wfMsg( 'ur-give-gift' ) . '</a>'; $output .= '</div> <div class="cleared"></div> @@ -202,12 +207,12 @@ $total = intval( str_replace( ',', '', $total ) ); $numofpages = $total / $per_page; - $page_link = SpecialPage::getTitleFor( 'ViewRelationships' ); + $pageLink = SpecialPage::getTitleFor( 'ViewRelationships' ); if ( $numofpages > 1 ) { $output .= '<div class="page-nav">'; if ( $page > 1 ) { - $output .= '<a href="' . $page_link->escapeFullURL( 'user=' . $user_name . '&rel_type=' . $rel_type . '&page=' . ( $page - 1 ) ) . '">' . wfMsg( 'ur-previous' ) . '</a> '; + $output .= '<a href="' . $pageLink->escapeFullURL( 'user=' . $user_name . '&rel_type=' . $rel_type . '&page=' . ( $page - 1 ) ) . '">' . wfMsg( 'ur-previous' ) . '</a> '; } if ( ( $total % $per_page ) != 0 ) { @@ -224,19 +229,16 @@ if ( $i == $page ) { $output .= ( $i . ' ' ); } else { - $output .= '<a href="' . $page_link->escapeFullURL( 'user=' . $user_name . '&rel_type=' . $rel_type . '&page=' . $i ) . "\">$i</a> "; + $output .= '<a href="' . $pageLink->escapeFullURL( 'user=' . $user_name . '&rel_type=' . $rel_type . '&page=' . $i ) . "\">$i</a> "; } } if ( ( $total - ( $per_page * $page ) ) > 0 ) { - $output .= ' <a href="' . $page_link->escapeFullURL( 'user=' . $user_name . '&rel_type=' . $rel_type . '&page=' . ( $page + 1 ) ) . '">' . wfMsg( 'ur-next' ) . '</a>'; + $output .= ' <a href="' . $pageLink->escapeFullURL( 'user=' . $user_name . '&rel_type=' . $rel_type . '&page=' . ( $page + 1 ) ) . '">' . wfMsg( 'ur-next' ) . '</a>'; } $output .= '</div>'; } - /** - * Build next/prev nav - */ $wgOut->addHTML( $output ); } } _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs