r102288 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102287‎ | r102288 | r102289 >
Date:15:12, 7 November 2011
Author:ashley
Status:resolved
Tags:socialprofile 
Comment:
SocialProfile: as per Markus' in-depth review:
*var -> private
*use $wgUser->isLoggedIn() instead of hacky $wgUser->getId() == 0 stuff
*store method's return value in a variable instead of calling the same function twice
*use DB_SLAVE for reads
Modified paths:
  • /trunk/extensions/SocialProfile/UserRelationship/SpecialAddRelationship.php (modified) (history)
  • /trunk/extensions/SocialProfile/UserRelationship/SpecialViewRelationshipRequests.php (modified) (history)
  • /trunk/extensions/SocialProfile/UserRelationship/SpecialViewRelationships.php (modified) (history)
  • /trunk/extensions/SocialProfile/UserRelationship/UserRelationshipClass.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SocialProfile/UserRelationship/SpecialViewRelationshipRequests.php
@@ -31,7 +31,7 @@
3232 * Redirect Non-logged in users to Login Page
3333 * It will automatically return them to the ViewRelationshipRequests page
3434 */
35 - if ( $wgUser->getID() == 0 ) {
 35+ if ( !$wgUser->isLoggedIn() ) {
3636 $wgOut->setPageTitle( wfMsg( 'ur-error-page-title' ) );
3737 $login = SpecialPage::getTitleFor( 'Userlogin' );
3838 $wgOut->redirect(
@@ -47,7 +47,7 @@
4848 $friend_request_count = $rel->getOpenRequestCount( $wgUser->getID(), 1 );
4949 $foe_request_count = $rel->getOpenRequestCount( $wgUser->getID(), 2 );
5050
51 - if ( count( $_POST ) && $_SESSION['alreadysubmitted'] == false ) {
 51+ if ( $wgRequest->wasPosted() && $_SESSION['alreadysubmitted'] == false ) {
5252 $_SESSION['alreadysubmitted'] = true;
5353 $rel->addRelationshipRequest(
5454 $this->user_name_to,
Index: trunk/extensions/SocialProfile/UserRelationship/SpecialAddRelationship.php
@@ -53,6 +53,10 @@
5454 if ( !$this->relationship_type || !is_numeric( $this->relationship_type ) ) {
5555 $this->relationship_type = 1;
5656 }
 57+ $hasRelationship = UserRelationship::getUserRelationshipByID(
 58+ $this->user_id_to,
 59+ $wgUser->getID()
 60+ );
5761
5862 if ( ( $wgUser->getID() == $this->user_id_to ) && ( $wgUser->getID() != 0 ) ) {
5963 $wgOut->setPageTitle( wfMsg( 'ur-error-title' ) );
@@ -96,9 +100,9 @@
97101
98102 $wgOut->addHTML( $out );
99103
100 - } elseif ( UserRelationship::getUserRelationshipByID( $this->user_id_to, $wgUser->getID() ) >= 1 ) {
 104+ } elseif ( $hasRelationship >= 1 ) {
101105
102 - if ( UserRelationship::getUserRelationshipByID( $this->user_id_to, $wgUser->getID() ) == 1 ) {
 106+ if ( $hasRelationship == 1 ) {
103107 $error = wfMsg( 'ur-add-error-message-existing-relationship-friend', $this->user_name_to );
104108 } else {
105109 $error = wfMsg( 'ur-add-error-message-existing-relationship-foe', $this->user_name_to );
Index: trunk/extensions/SocialProfile/UserRelationship/SpecialViewRelationships.php
@@ -43,7 +43,7 @@
4444 * Redirect Non-logged in users to Login Page
4545 * It will automatically return them to the ViewRelationships page
4646 */
47 - if ( $wgUser->getID() == 0 && $user_name == '' ) {
 47+ if ( !$wgUser->isLoggedIn() && $user_name == '' ) {
4848 $wgOut->setPageTitle( wfMsg( 'ur-error-page-title' ) );
4949 $login = SpecialPage::getTitleFor( 'Userlogin' );
5050 $wgOut->redirect( $login->escapeFullURL( 'returnto=Special:ViewRelationships' ) );
@@ -69,14 +69,14 @@
7070 $user_name = $wgUser->getName();
7171 }
7272 $user_id = User::idFromName( $user_name );
73 - $user = Title::makeTitle( NS_USER, $user_name );
 73+ $userPage = Title::makeTitle( NS_USER, $user_name );
7474
7575 /**
7676 * Error message for username that does not exist (from URL)
7777 */
7878 if ( $user_id == 0 ) {
7979 $wgOut->setPageTitle( wfMsg( 'ur-error-title' ) );
80 - $out .= '<div class="relationship-error-message">' .
 80+ $out = '<div class="relationship-error-message">' .
8181 wfMsg( 'ur-error-message-no-user' ) .
8282 '</div>
8383 <div class="relationship-request-buttons">
@@ -149,7 +149,7 @@
150150 );
151151
152152 // Safe titles
153 - $user = Title::makeTitle( NS_USER, $relationship['user_name'] );
 153+ $userPage = Title::makeTitle( NS_USER, $relationship['user_name'] );
154154 $addRelationshipLink = SpecialPage::getTitleFor( 'AddRelationship' );
155155 $removeRelationshipLink = SpecialPage::getTitleFor( 'RemoveRelationship' );
156156 $giveGiftLink = SpecialPage::getTitleFor( 'GiveGift' );
@@ -171,10 +171,10 @@
172172 }
173173
174174 $output .= "<div class=\"relationship-item\">
175 - <a href=\"{$user->escapeFullURL()}\">{$avatar_img}</a>
 175+ <a href=\"{$userPage->escapeFullURL()}\">{$avatar_img}</a>
176176 <div class=\"relationship-info\">
177177 <div class=\"relationship-name\">
178 - <a href=\"{$user->escapeFullURL()}\">{$user_name_display}</a>
 178+ <a href=\"{$userPage->escapeFullURL()}\">{$user_name_display}</a>
179179 </div>
180180 <div class=\"relationship-actions\">";
181181 if ( $indivRelationship == false ) {
Index: trunk/extensions/SocialProfile/UserRelationship/UserRelationshipClass.php
@@ -3,17 +3,13 @@
44 * Functions for managing relationship data
55 */
66 class UserRelationship {
7 - /**#@+
8 - * @private
9 - */
10 - var $user_id;
11 - var $user_name;
 7+ private $user_id;
 8+ private $user_name;
129
1310 /**
1411 * Constructor
15 - * @private
1612 */
17 - /* private */ function __construct( $username ) {
 13+ public function __construct( $username ) {
1814 $title1 = Title::newFromDBkey( $username );
1915 $this->user_name = $title1->getText();
2016 $this->user_id = User::idFromName( $this->user_name );
@@ -365,8 +361,8 @@
366362 * @return bool
367363 */
368364 public function verifyRelationshipRequest( $relationshipRequestId ) {
369 - $dbw = wfGetDB( DB_MASTER );
370 - $s = $dbw->selectRow(
 365+ $dbr = wfGetDB( DB_SLAVE );
 366+ $s = $dbr->selectRow(
371367 'user_relationship_request',
372368 array( 'ur_user_id_to' ),
373369 array( 'ur_id' => $relationshipRequestId ),
@@ -386,8 +382,8 @@
387383 * @return Mixed: integer or boolean false
388384 */
389385 static function getUserRelationshipByID( $user1, $user2 ) {
390 - $dbw = wfGetDB( DB_MASTER );
391 - $s = $dbw->selectRow(
 386+ $dbr = wfGetDB( DB_SLAVE );
 387+ $s = $dbr->selectRow(
392388 'user_relationship',
393389 array( 'r_type' ),
394390 array( 'r_user_id' => $user1, 'r_user_id_relation' => $user2 ),
@@ -406,8 +402,8 @@
407403 * @return bool
408404 */
409405 static function userHasRequestByID( $user1, $user2 ) {
410 - $dbw = wfGetDB( DB_MASTER );
411 - $s = $dbw->selectRow(
 406+ $dbr = wfGetDB( DB_SLAVE );
 407+ $s = $dbr->selectRow(
412408 'user_relationship_request',
413409 array( 'ur_type' ),
414410 array(
@@ -432,7 +428,7 @@
433429 * ID, type, requester, etc.
434430 */
435431 public function getRequest( $id ) {
436 - $dbr = wfGetDB( DB_MASTER );
 432+ $dbr = wfGetDB( DB_SLAVE );
437433 $res = $dbr->select(
438434 'user_relationship_request',
439435 array(
@@ -470,7 +466,7 @@
471467 * @return Array: array of open relationship requests
472468 */
473469 public function getRequestList( $status, $limit = 0 ) {
474 - $dbr = wfGetDB( DB_MASTER );
 470+ $dbr = wfGetDB( DB_SLAVE );
475471
476472 $options = array();
477473

Follow-up revisions

RevisionCommit summaryAuthorDate
r104105SocialProfile: partial revert of r102176, r102180 and r102288 -- UserProfile'...ashley23:39, 23 November 2011

Status & tagging log