Revision: 48325 Author: ashley Date: 2009-03-11 19:37:15 +0000 (Wed, 11 Mar 2009)
Log Message: ----------- SocialProfile: cleanup to ViewGift special page. also converted a raw sql query to use Database wrapper class...shouldn't break things Modified Paths: -------------- trunk/extensions/SocialProfile/UserGifts/SpecialViewGift.php Modified: trunk/extensions/SocialProfile/UserGifts/SpecialViewGift.php =================================================================== --- trunk/extensions/SocialProfile/UserGifts/SpecialViewGift.php 2009-03-11 19:36:19 UTC (rev 48324) +++ trunk/extensions/SocialProfile/UserGifts/SpecialViewGift.php 2009-03-11 19:37:15 UTC (rev 48325) @@ -6,7 +6,7 @@ * Constructor */ public function __construct(){ - parent::__construct('ViewGift'); + parent::__construct( 'ViewGift' ); } /** @@ -15,29 +15,30 @@ * @param $par Mixed: parameter passed to the page or null */ public function execute( $par ){ - global $wgUser, $wgOut, $wgTitle, $wgRequest, $wgDBprefix, $wgUploadPath, $wgUserGiftsScripts; - wfLoadExtensionMessages('UserGifts'); + global $wgUser, $wgOut, $wgRequest, $wgUploadPath, $wgUserGiftsScripts; + wfLoadExtensionMessages( 'UserGifts' ); $wgOut->addStyle( '../..' . $wgUserGiftsScripts . '/UserGifts.css' ); - $output = ''; // Prevent E_NOTICE $user_name = ''; // Prevent E_NOTICE - $gift_id = $wgRequest->getVal('gift_id'); - if( !$gift_id || !is_numeric($gift_id) ){ - $wgOut->setPageTitle( wfMsg('g-error-title') ); - $wgOut->addHTML( wfMsg('g-error-message-invalid-link') ); + $gift_id = $wgRequest->getVal( 'gift_id' ); + if( !$gift_id || !is_numeric( $gift_id ) ){ + $wgOut->setPageTitle( wfMsg( 'g-error-title' ) ); + $wgOut->addHTML( wfMsg( 'g-error-message-invalid-link' ) ); return false; } - if( !$user_name ) $user_name = $wgUser->getName(); - $gift = UserGifts::getUserGift($gift_id); - $user_safe = urlencode($gift['user_name_to']); - $id = User::idFromName($user_name); + if( !$user_name ){ + $user_name = $wgUser->getName(); + } + $gift = UserGifts::getUserGift( $gift_id ); + $user_safe = urlencode( $gift['user_name_to'] ); + $id = User::idFromName( $user_name ); $relationship = UserRelationship::getUserRelationshipByID( $id, $wgUser->getID() ); // DB stuff - $dbr = wfGetDB( DB_MASTER ); + $dbr = wfGetDB( DB_SLAVE ); if( $gift ) { @@ -49,54 +50,63 @@ } } - $sql = "SELECT DISTINCT ug_user_name_to, ug_user_id_to, ug_date FROM ".$wgDBprefix."user_gift WHERE ug_gift_id={$gift["gift_id"]} AND ug_user_name_to<>'" . addslashes($gift["user_name_to"]) . "' GROUP BY ug_user_name_to ORDER BY ug_date DESC LIMIT 0,6"; - $res = $dbr->query($sql); + $res = $dbr->select( 'user_gift', + array( 'DISTINCT ug_user_name_to', 'ug_user_id_to', 'ug_date' ), + array( 'ug_gift_id' => $gift['gift_id'], "ug_user_name_to<>'" . addslashes( $gift['user_name_to'] ) . "'" ), + __METHOD__, + array( 'GROUP BY' => 'ug_user_name_to', 'ORDER BY' => 'ug_date DESC', 'LIMIT' => 6 ) + ); - $output .= $wgOut->setPageTitle( wfMsgExt( 'g-description-title', array( 'parsemag' ), $gift['user_name_to'], $gift['name'] ) ); + $output = $wgOut->setPageTitle( wfMsgExt( 'g-description-title', 'parsemag', $gift['user_name_to'], $gift['name'] ) ); $output .= '<div class="back-links"> - <a href="' . Title::makeTitle( NS_USER, $gift['user_name_to'] )->escapeFullURL() . '">' . wfMsg( 'g-back-link', $gift['user_name_to'] ) . '</a> + <a href="' . Title::makeTitle( NS_USER, $gift['user_name_to'] )->escapeFullURL() . '">' + . wfMsg( 'g-back-link', $gift['user_name_to'] ) . '</a> </div>'; $user = Title::makeTitle( NS_USER, $gift['user_name_from'] ); $remove_gift_link = SpecialPage::getTitleFor( 'RemoveGift' ); - $give_gift_link = SpecialPage::getTitleFor( 'GiveGift'); + $give_gift_link = SpecialPage::getTitleFor( 'GiveGift' ); - $avatar = new wAvatar($gift['user_id_from'], 's'); - $avatar_img = "<img src='{$wgUploadPath}/avatars/" . $avatar->getAvatarImage() . "' alt='' border='0'/>"; - $gift_image = "<img src=\"{$wgUploadPath}/awards/" . Gifts::getGiftImage($gift['gift_id'], 'l') . "\" border=\"0\" alt=\"\" />"; + $avatar = new wAvatar( $gift['user_id_from'], 's' ); + $avatar_img = '<img src="' . $wgUploadPath . '/avatars/' . $avatar->getAvatarImage() . '" alt="" border="0" />'; + $gift_image = '<img src="' . $wgUploadPath . '/awards/' . Gifts::getGiftImage( $gift['gift_id'], 'l' ) . '" border="0" alt="" />'; $message = $wgOut->parse( trim( $gift['message'] ), false ); $output .= '<div class="g-description-container">'; - $gift_image = "<img src=\"{$wgUploadPath}/awards/" . Gifts::getGiftImage($gift['gift_id'], 'l') . "\" border=\"0\" alt=\"\"/>"; + $gift_image = '<img src="'. $wgUploadPath .'/awards/' . Gifts::getGiftImage( $gift['gift_id'], 'l' ) . '" border="0" alt="" />'; - $output .= "<div class=\"g-description\"> - {$gift_image} - <div class=\"g-name\">{$gift["name"]}</div> - <div class=\"g-timestamp\">({$gift["timestamp"]})</div> - <div class=\"g-from\">from <a href=\"".$user->escapeFullURL()."\">{$gift["user_name_from"]}</a></div>"; - if( $message ) $output .= "<div class=\"g-user-message\">\"{$message}\"</div>"; - $output .= "<div class=\"cleared\"></div> - <div class=\"g-describe\">{$gift["description"]}</div> - <div class=\"g-actions\"> - <a href=\"".$give_gift_link->escapeFullURL('gift_id='.$gift['gift_id'])."\">".wfMsg('g-to-another')."</a>"; + $output .= '<div class="g-description">' + . $gift_image .' + <div class="g-name">'. $gift['name'] .'</div> + <div class="g-timestamp">('. $gift['timestamp'] .')</div> + <div class="g-from">'. wfMsg( 'g-from', $user->escapeFullURL(), $gift['user_name_from'] ) .'</div>'; + if( $message ){ + $output .= '<div class="g-user-message">'. $message .'</div>'; + } + $output .= '<div class="cleared"></div> + <div class="g-describe">'. $gift['description'] .'</div> + <div class="g-actions"> + <a href="'.$give_gift_link->escapeFullURL('gift_id='.$gift['gift_id']).'">'. wfMsg( 'g-to-another' ) .'</a>'; if( $gift['user_name_to'] == $wgUser->getName() ) { + $output .= ' '; $output .= wfMsgExt( 'pipe-separator' , 'escapenoentities' ); - $output .= "<a href=\"" . $remove_gift_link->escapeFullURL( 'gift_id=' . $gift['id'] ) . "\">" . wfMsg( 'g-remove-gift' ) . "</a>"; + $output .= ' '; + $output .= '<a href="' . $remove_gift_link->escapeFullURL( 'gift_id=' . $gift['id'] ) . '">' . wfMsg( 'g-remove-gift' ) . '</a>'; } $output .= '</div> </div>'; $output .= '<div class="g-recent"> - <div class="g-recent-title">'.wfMsg('g-recent-recipients').'</div> + <div class="g-recent-title">'.wfMsg( 'g-recent-recipients' ).'</div> <div class="g-gift-count">'.wfMsgExt( 'g-given', 'parsemag', $gift['gift_count'] ).'</div>'; while( $row = $dbr->fetchObject( $res ) ) { $user_to_id = $row->ug_user_id_to; - $avatar = new wAvatar($user_to_id, 'ml'); + $avatar = new wAvatar( $user_to_id, 'ml' ); $user_name_link = Title::makeTitle( NS_USER, $row->ug_user_name_to ); $output .= "<a href=\"".$user_name_link->escapeFullURL()."\"> @@ -107,11 +117,10 @@ </div> </div>'; - $wgOut->addHTML($output); - + $wgOut->addHTML( $output ); } else { - $wgOut->setPageTitle( wfMsg('g-error-title') ); - $wgOut->addHTML( wfMsg('g-error-message-invalid-link') ); + $wgOut->setPageTitle( wfMsg( 'g-error-title' ) ); + $wgOut->addHTML( wfMsg( 'g-error-message-invalid-link' ) ); } } } \ No newline at end of file _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs