PageRenderTime 45ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/SocialProfile/UserRelationship/SpecialRemoveRelationship.php

http://semantic-social-profile.googlecode.com/
PHP | 191 lines | 144 code | 21 blank | 26 comment | 21 complexity | 683f2d7bbd2448241dcc5aede25dd3ff MD5 | raw file
  1. <?php
  2. /**
  3. * A special page for removing existing friends/foes for the current logged in user
  4. *
  5. * Example URL: /index.php?title=Special:RemoveRelationship&user=Awrigh01
  6. *
  7. * @file
  8. * @ingroup Extensions
  9. * @author David Pean <david.pean@gmail.com>
  10. * @copyright Copyright Š 2007, Wikia Inc.
  11. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
  12. */
  13. class SpecialRemoveRelationship extends UnlistedSpecialPage {
  14. /**
  15. * Constructor -- set up the new special page
  16. */
  17. public function __construct() {
  18. parent::__construct( 'RemoveRelationship' );
  19. }
  20. /**
  21. * Show the special page
  22. *
  23. * @param $params Mixed: parameter(s) passed to the page or null
  24. */
  25. public function execute( $params ) {
  26. global $wgUser, $wgOut, $wgRequest, $wgUploadPath, $wgUserRelationshipScripts;
  27. // Can't use $this->setHeaders(); here because then it'll set the page
  28. // title to <removerelationship> and we don't want that, we'll be
  29. // messing with the page title later on in the code
  30. $wgOut->setArticleRelated( false );
  31. $wgOut->setRobotPolicy( 'noindex,nofollow' );
  32. $wgOut->addExtensionStyle( $wgUserRelationshipScripts . '/UserRelationship.css' );
  33. $usertitle = Title::newFromDBkey( $wgRequest->getVal( 'user' ) );
  34. if ( !$usertitle ) {
  35. $wgOut->setPageTitle( wfMsgHtml( 'ur-error-title' ) );
  36. $wgOut->addWikiText( wfMsgNoTrans( 'ur-add-no-user' ) );
  37. return false;
  38. }
  39. $this->user_name_to = $usertitle->getText();
  40. $this->user_id_to = User::idFromName( $this->user_name_to );
  41. $this->relationship_type = UserRelationship::getUserRelationshipByID(
  42. $this->user_id_to,
  43. $wgUser->getID()
  44. );
  45. if ( $this->relationship_type == 1 ) {
  46. $confirmTitle = wfMsg( 'ur-remove-relationship-title-confirm-friend', $this->user_name_to );
  47. $confirmMsg = wfMsg( 'ur-remove-relationship-message-confirm-friend', $this->user_name_to );
  48. $error = wfMsg( 'ur-remove-error-not-loggedin-friend' );
  49. $pending = wfMsg( 'ur-remove-error-message-pending-friend-request', $this->user_name_to );
  50. } else {
  51. $confirmTitle = wfMsg( 'ur-remove-relationship-title-confirm-foe', $this->user_name_to );
  52. $confirmMsg = wfMsg( 'ur-remove-relationship-message-confirm-foe', $this->user_name_to );
  53. $error = wfMsg( 'ur-remove-error-not-loggedin-foe' );
  54. $pending = wfMsg( 'ur-remove-error-message-pending-foe-request', $this->user_name_to );
  55. }
  56. $out = '';
  57. if ( $wgUser->getID() == $this->user_id_to ) {
  58. $wgOut->setPageTitle( wfMsg( 'ur-error-title' ) );
  59. $out .= '<div class="relationship-error-message">'
  60. . wfMsg( 'ur-remove-error-message-remove-yourself' ) .
  61. '</div>
  62. <div>
  63. <input type="button" class="site-button" value="' . wfMsg( 'ur-main-page' ) . '" size="20" onclick=\'window.location="index.php?title=' . wfMsgForContent( 'mainpage' ) . '"\' />';
  64. if ( $wgUser->isLoggedIn() ) {
  65. $out .= '<input type="button" class="site-button" value="' . wfMsg( 'ur-your-profile' ) . '" size="20" onclick=\'window.location="' . $wgUser->getUserPage()->escapeFullURL() . '"\' />';
  66. }
  67. $out .= '</div>';
  68. $wgOut->addHTML( $out );
  69. } elseif ( $this->relationship_type == false ) {
  70. $wgOut->setPageTitle( wfMsg( 'ur-error-title' ) );
  71. $out .= '<div class="relationship-error-message">' .
  72. wfMsg( 'ur-remove-error-message-no-relationship', $this->user_name_to ) .
  73. '</div>
  74. <div>
  75. <input type="button" class="site-button" value="' . wfMsg( 'ur-main-page' ) . '" size="20" onclick=\'window.location="index.php?title="' . wfMsgForContent( 'mainpage' ) . '"\' />';
  76. if ( $wgUser->isLoggedIn() ) {
  77. $out .= '<input type="button" class="site-button" value="' . wfMsg( 'ur-your-profile' ) . '" size="20" onclick=\'window.location="' . $wgUser->getUserPage()->escapeFullURL() . '"\' />';
  78. }
  79. $out .= '</div>';
  80. $wgOut->addHTML( $out );
  81. } elseif ( UserRelationship::userHasRequestByID( $this->user_id_to, $wgUser->getID() ) == true ) {
  82. $wgOut->setPageTitle( wfMsg( 'ur-error-title' ) );
  83. $out .= '<div class="relationship-error-message">' .
  84. $pending .
  85. '</div>
  86. <div>
  87. <input type="button" class="site-button" value="' . wfMsg( 'ur-main-page' ) . '" size="20" onclick=\'window.location="index.php?title="' . wfMsgForContent( 'mainpage' ) . '"\' />';
  88. if ( $wgUser->isLoggedIn() ) {
  89. $out .= '<input type="button" class="site-button" value="' . wfMsg( 'ur-your-profile' ) . '" size="20" onclick=\'window.location="' . $wgUser->getUserPage()->escapeFullURL() . '"\' />';
  90. }
  91. $out .= '</div>';
  92. $wgOut->addHTML( $out );
  93. } elseif ( $wgUser->getID() == 0 ) {
  94. $wgOut->setPageTitle( wfMsg( 'ur-error-title' ) );
  95. $out .= '<div class="relationship-error-message">' .
  96. $error .
  97. '</div>
  98. <div>
  99. <input type="button" class="site-button" value="' . wfMsg( 'ur-main-page' ) . '" size="20" onclick=\'window.location="index.php?title="' . wfMsgForContent( 'mainpage' ) . '"\' />';
  100. if ( $wgUser->isLoggedIn() ) {
  101. $out .= '<input type="button" class="site-button" value="' . wfMsg( 'ur-your-profile' ) . '" size="20" onclick=\'window.location="' . $wgUser->getUserPage()->escapeFullURL() . '"\' />';
  102. }
  103. $out .= '</div>';
  104. $wgOut->addHTML( $out );
  105. } else {
  106. $rel = new UserRelationship( $wgUser->getName() );
  107. if ( $wgRequest->wasPosted() && $_SESSION['alreadysubmitted'] == false ) {
  108. $_SESSION['alreadysubmitted'] = true;
  109. $rel->removeRelationshipByUserID(
  110. $this->user_id_to,
  111. $wgUser->getID()
  112. );
  113. $rel->sendRelationshipRemoveEmail(
  114. $this->user_id_to,
  115. $wgUser->getName(),
  116. $this->relationship_type
  117. );
  118. $avatar = new wAvatar( $this->user_id_to, 'l' );
  119. $avatar_img = '<img src="' . $wgUploadPath . '/avatars/' .
  120. $avatar->getAvatarImage() . '" alt="" border="" />';
  121. $wgOut->setPageTitle( $confirmTitle );
  122. $out .= "<div class=\"relationship-action\">
  123. {$avatar_img}" .
  124. $confirmMsg .
  125. "<div class=\"relationship-buttons\">
  126. <input type=\"button\" class=\"site-button\" value=\"" . wfMsg( 'ur-main-page' ) . "\" size=\"20\" onclick=\"window.location='index.php?title=" . wfMsgForContent( 'mainpage' ) . "'\"/>
  127. <input type=\"button\" class=\"site-button\" value=\"" . wfMsg( 'ur-your-profile' ) . "\" size=\"20\" onclick=\"window.location='" . $wgUser->getUserPage()->escapeFullURL() . "'\"/>
  128. </div>
  129. <div class=\"cleared\"></div>
  130. </div>";
  131. $wgOut->addHTML( $out );
  132. } else {
  133. $_SESSION['alreadysubmitted'] = false;
  134. $wgOut->addHTML( $this->displayForm() );
  135. }
  136. }
  137. }
  138. /**
  139. * Displays the form for removing a friend or a foe
  140. * @return $form Mixed: HTML code for the form
  141. */
  142. function displayForm() {
  143. global $wgOut, $wgUploadPath;
  144. $avatar = new wAvatar( $this->user_id_to, 'l' );
  145. $avatar_img = '<img src="' . $wgUploadPath . '/avatars/' .
  146. $avatar->getAvatarImage() . '" alt="avatar" />';
  147. if ( $this->relationship_type == 1 ) {
  148. $title = wfMsg( 'ur-remove-relationship-title-friend', $this->user_name_to );
  149. $remove = wfMsg( 'ur-remove-relationship-message-friend', $this->user_name_to, wfMsg( 'ur-remove' ) );
  150. } else {
  151. $title = wfMsg( 'ur-remove-relationship-title-foe', $this->user_name_to );
  152. $remove = wfMsg( 'ur-remove-relationship-message-foe', $this->user_name_to, wfMsg( 'ur-remove' ) );
  153. }
  154. $wgOut->setPageTitle( $title );
  155. $form = "<form action=\"\" method=\"post\" enctype=\"multipart/form-data\" name=\"form1\">
  156. <div class=\"relationship-action\">
  157. {$avatar_img}" .
  158. $remove .
  159. '<div class="relationship-buttons">
  160. <input type="hidden" name="user" value="' . addslashes( $this->user_name_to ) . '" />
  161. <input type="button" class="site-button" value="' . wfMsg( 'ur-remove' ) . '" size="20" onclick="document.form1.submit()" />
  162. <input type="button" class="site-button" value="' . wfMsg( 'ur-cancel' ) . '" size="20" onclick="history.go(-1)" />
  163. </div>
  164. <div class="cleared"></div>
  165. </div>
  166. </form>';
  167. return $form;
  168. }
  169. }