PageRenderTime 44ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/extensions/ConfirmAccount/UserCredentials_body.php

https://github.com/ChuguluGames/mediawiki-svn
PHP | 214 lines | 162 code | 36 blank | 16 comment | 17 complexity | 02d599473df41acec0a384b718ed9132 MD5 | raw file
  1. <?php
  2. class UserCredentialsPage extends SpecialPage
  3. {
  4. function __construct() {
  5. parent::__construct( 'UserCredentials', 'lookupcredentials' );
  6. }
  7. function execute( $par ) {
  8. global $wgRequest, $wgOut, $wgUser, $wgAccountRequestTypes;
  9. if ( !$wgUser->isAllowed( 'lookupcredentials' ) ) {
  10. $wgOut->permissionRequired( 'lookupcredentials' );
  11. return;
  12. }
  13. $this->setHeaders();
  14. # A target user
  15. $this->target = $wgRequest->getText( 'target' );
  16. # Attachments
  17. $this->file = $wgRequest->getVal( 'file' );
  18. $this->skin = $wgUser->getSkin();
  19. if ( $this->file ) {
  20. $this->showFile( $this->file );
  21. } elseif ( $this->target ) {
  22. $this->showForm();
  23. $this->showCredentials();
  24. } else {
  25. $this->showForm();
  26. }
  27. $wgOut->addModules( 'ext.confirmAccount' ); // CSS
  28. }
  29. function showForm() {
  30. global $wgOut, $wgScript;
  31. $username = str_replace( '_', ' ', $this->target );
  32. $form = Xml::openElement( 'form', array( 'name' => 'stablization', 'action' => $wgScript, 'method' => 'get' ) );
  33. $form .= "<fieldset><legend>" . wfMsg( 'usercredentials-leg' ) . "</legend>";
  34. $form .= "<table><tr>";
  35. $form .= "<td>" . Html::Hidden( 'title', $this->getTitle()->getPrefixedText() ) . "</td>";
  36. $form .= "<td>" . wfMsgHtml( "usercredentials-user" ) . "</td>";
  37. $form .= "<td>" . Xml::input( 'target', 35, $username, array( 'id' => 'wpUsername' ) ) . "</td>";
  38. $form .= "<td>" . Xml::submitButton( wfMsg( 'go' ) ) . "</td>";
  39. $form .= "</tr></table>";
  40. $form .= "</fieldset></form>\n";
  41. $wgOut->addHTML( $form );
  42. }
  43. function showCredentials() {
  44. global $wgOut, $wgUser, $wgLang, $wgAccountRequestTypes;
  45. $titleObj = SpecialPage::getTitleFor( 'UserCredentials' );
  46. $row = $this->getRequest();
  47. if ( !$row ) {
  48. $wgOut->addHTML( wfMsgHtml( 'usercredentials-badid' ) );
  49. return;
  50. }
  51. $wgOut->addWikiText( wfMsg( "usercredentials-text" ) );
  52. $user = User::newFromName( $this->target );
  53. $list = array();
  54. foreach ( $user->getGroups() as $group )
  55. $list[] = self::buildGroupLink( $group );
  56. $grouplist = '';
  57. if ( count( $list ) > 0 ) {
  58. $grouplist = '<tr><td>' . wfMsgHtml( 'usercredentials-member' ) . '</td><td>' . implode( ', ', $list ) . '</td></tr>';
  59. }
  60. $form = "<fieldset>";
  61. $form .= '<legend>' . wfMsgHtml( 'usercredentials-leg-user' ) . '</legend>';
  62. $form .= '<table cellpadding=\'4\'>';
  63. $form .= "<tr><td>" . wfMsgHtml( 'username' ) . "</td>";
  64. $form .= "<td>" . $this->skin->makeLinkObj( $user->getUserPage(), htmlspecialchars( $user->getUserPage()->getText() ) ) . "</td></tr>\n";
  65. $econf = $row->acd_email_authenticated ? ' <strong>' . wfMsgHtml( 'confirmaccount-econf' ) . '</strong>' : '';
  66. $form .= "<tr><td>" . wfMsgHtml( 'usercredentials-email' ) . "</td>";
  67. $form .= "<td>" . htmlspecialchars( $row->acd_email ) . $econf . "</td></tr>\n";
  68. $form .= $grouplist;
  69. $form .= '</table></fieldset>';
  70. $areaSet = RequestAccountPage::expandAreas( $row->acd_areas );
  71. if ( wfMsg( 'requestaccount-areas' ) ) {
  72. $form .= '<fieldset>';
  73. $form .= '<legend>' . wfMsgHtml( 'confirmaccount-leg-areas' ) . '</legend>';
  74. $areas = explode( "\n*", "\n" . wfMsg( 'requestaccount-areas' ) );
  75. $form .= "<div style='height:150px; overflow:scroll; background-color:#f9f9f9;'>";
  76. $form .= "<table cellspacing='5' cellpadding='0' style='background-color:#f9f9f9;'><tr valign='top'>";
  77. $count = 0;
  78. $att = array( 'disabled' => 'disabled' );
  79. foreach ( $areas as $area ) {
  80. $set = explode( "|", $area, 3 );
  81. if ( $set[0] && isset( $set[1] ) ) {
  82. $count++;
  83. if ( $count > 5 ) {
  84. $form .= "</tr><tr valign='top'>";
  85. $count = 1;
  86. }
  87. $formName = "wpArea-" . htmlspecialchars( str_replace( ' ', '_', $set[0] ) );
  88. if ( isset( $set[1] ) ) {
  89. $pg = Linker::link( Title::newFromText( $set[1] ), wfMsgHtml( 'requestaccount-info' ), array(), array(), "known" );
  90. } else {
  91. $pg = '';
  92. }
  93. $form .= "<td>" . Xml::checkLabel( $set[0], $formName, $formName, in_array( $formName, $areaSet ), $att ) . " {$pg}</td>\n";
  94. }
  95. }
  96. $form .= "</tr></table></div>";
  97. $form .= '</fieldset>';
  98. }
  99. $form .= '<fieldset>';
  100. $form .= '<legend>' . wfMsgHtml( 'usercredentials-leg-person' ) . '</legend>';
  101. $form .= '<table cellpadding=\'4\'>';
  102. $form .= "<tr><td>" . wfMsgHtml( 'usercredentials-real' ) . "</td>";
  103. $form .= "<td>" . htmlspecialchars( $row->acd_real_name ) . "</td></tr>\n";
  104. $form .= '</table>';
  105. $form .= "<p>" . wfMsgHtml( 'usercredentials-bio' ) . "</p>";
  106. $form .= "<p><textarea tabindex='1' readonly='readonly' name='wpBio' id='wpNewBio' rows='10' cols='80' style='width:100%'>" .
  107. htmlspecialchars( $row->acd_bio ) .
  108. "</textarea></p>\n";
  109. $form .= '</fieldset>';
  110. $form .= '<fieldset>';
  111. $form .= '<legend>' . wfMsgHtml( 'usercredentials-leg-other' ) . '</legend>';
  112. global $wgAccountRequestExtraInfo ;
  113. if( $wgAccountRequestExtraInfo ) {
  114. $form .= '<p>' . wfMsgHtml( 'usercredentials-attach' ) . ' ';
  115. if ( $row->acd_filename ) {
  116. $form .= $this->skin->makeKnownLinkObj( $titleObj, htmlspecialchars( $row->acd_filename ),
  117. 'file=' . $row->acd_storage_key );
  118. } else {
  119. $form .= wfMsgHtml( 'confirmaccount-none-p' );
  120. }
  121. $form .= "</p><p>" . wfMsgHtml( 'usercredentials-notes' ) . "</p>\n";
  122. $form .= "<p><textarea tabindex='1' readonly='readonly' name='wpNotes' id='wpNotes' rows='3' cols='80' style='width:100%'>" .
  123. htmlspecialchars( $row->acd_notes ) .
  124. "</textarea></p>\n";
  125. $form .= "<p>" . wfMsgHtml( 'usercredentials-urls' ) . "</p>\n";
  126. $form .= ConfirmAccountsPage::parseLinks( $row->acd_urls );
  127. }
  128. if ( $wgUser->isAllowed( 'requestips' ) ) {
  129. $blokip = SpecialPage::getTitleFor( 'blockip' );
  130. $form .= "<p>" . wfMsgHtml( 'usercredentials-ip' ) . " " . htmlspecialchars( $row->acd_ip ) . "</p>\n";
  131. }
  132. $form .= '</fieldset>';
  133. $wgOut->addHTML( $form );
  134. }
  135. /**
  136. * Format a link to a group description page
  137. *
  138. * @param string $group
  139. * @return string
  140. */
  141. private static function buildGroupLink( $group ) {
  142. static $cache = array();
  143. if ( !isset( $cache[$group] ) )
  144. $cache[$group] = User::makeGroupLinkHtml( $group, User::getGroupMember( $group ) );
  145. return $cache[$group];
  146. }
  147. /**
  148. * Show a private file requested by the visitor.
  149. */
  150. function showFile( $key ) {
  151. global $wgOut, $wgRequest, $wgConfirmAccountFSRepos, $IP;
  152. $wgOut->disable();
  153. # We mustn't allow the output to be Squid cached, otherwise
  154. # if an admin previews a private image, and it's cached, then
  155. # a user without appropriate permissions can toddle off and
  156. # nab the image, and Squid will serve it
  157. $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
  158. $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
  159. $wgRequest->response()->header( 'Pragma: no-cache' );
  160. require_once( "$IP/includes/StreamFile.php" );
  161. $repo = new FSRepo( $wgConfirmAccountFSRepos['accountcreds'] );
  162. $path = $repo->getZonePath( 'public' ).'/'.
  163. $key[0].'/'.$key[0].$key[1].'/'.$key[0].$key[1].$key[2].'/'.$key;
  164. wfStreamFile( $path );
  165. }
  166. function getRequest() {
  167. $uid = User::idFromName( $this->target );
  168. if ( !$uid )
  169. return false;
  170. # For now, just get the first revision...
  171. $dbr = wfGetDB( DB_SLAVE );
  172. $row = $dbr->selectRow( 'account_credentials', '*',
  173. array( 'acd_user_id' => $uid ),
  174. __METHOD__,
  175. array( 'ORDER BY' => 'acd_user_id,acd_id ASC' ) );
  176. return $row;
  177. }
  178. }