r95202 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95201‎ | r95202 | r95203 >
Date:13:28, 22 August 2011
Author:akshay
Status:reverted (Comments)
Tags:
Comment:
Followup r95185, changed name of class validateSignup to ValidateSignup, made necessary changes in other files as well
Modified paths:
  • /trunk/extensions/SignupAPI/includes/ValidateSignup.php (added) (history)

Diff [purge]

Index: trunk/extensions/SignupAPI/includes/ValidateSignup.php
@@ -0,0 +1,129 @@
 2+<?php
 3+
 4+if ( !defined( 'MEDIAWIKI' ) ) {
 5+ // Eclipse helper - will be ignored in production
 6+ require_once( 'ApiBase.php' );
 7+}
 8+
 9+/**
 10+ * Unit to create accounts in the current wiki
 11+ *
 12+ * @ingroup API
 13+ */
 14+class ValidateSignup extends ApiBase {
 15+
 16+ public function __construct( $main, $action ) {
 17+ parent::__construct( $main, $action );
 18+ }
 19+
 20+ public function execute() {
 21+ $params = $this->extractRequestParams();
 22+
 23+ $result = array();
 24+
 25+ switch ( $params['field'] ) {
 26+ case "username":
 27+ $mUser = User::newFromName( $params['inputVal'], 'creatable' );
 28+ if ( !is_object( $mUser ) ) {
 29+ $result['result'] = wfMsg( 'noname' );
 30+ $result['icon'] = 'MW-Icon-AlertMark.png';
 31+ }
 32+
 33+ if ( 0 != $mUser->idForName() ) {
 34+ $result['result'] = wfMsg( 'userexists' );
 35+ $result['icon'] = "MW-Icon-NoMark.png";
 36+ } else {
 37+ $result['result'] = wfMsg( 'ok' );
 38+ $result['icon'] = "MW-Icon-CheckMark.png";
 39+ }
 40+ break;
 41+
 42+ case "email" :
 43+ if ( $valid = User::isValidEmailAddr( $params['inputVal'] ) ) {
 44+ $result['result']= wfMsg( 'ok' );
 45+ $result['icon'] = "MW-Icon-CheckMark.png";
 46+ } else {
 47+ $result['result']= wfMsg( 'invalidemailaddress' );
 48+ $result['icon'] = "MW-Icon-NoMark.png";
 49+ }
 50+ break;
 51+
 52+ case "passwordlength" :
 53+ global $wgMinimalPasswordLength;
 54+ $result['result'] = $wgMinimalPasswordLength;
 55+ break;
 56+
 57+ default :
 58+ ApiBase::dieDebug( __METHOD__, "Unhandled case value: {$params['field']}" );
 59+ }
 60+
 61+ $this->getResult()->addValue( null, 'signup', $result );
 62+ }
 63+
 64+ public function mustBePosted() {
 65+ return false;
 66+ }
 67+
 68+ public function isReadMode() {
 69+ return false;
 70+ }
 71+
 72+ public function getAllowedParams() {
 73+ return array(
 74+ 'field' => null,
 75+ 'inputVal' => null,
 76+ 'password' => null,
 77+ 'retype' => null,
 78+ 'email' => null,
 79+ );
 80+ }
 81+
 82+ public function getParamDescription() {
 83+ return array(
 84+ 'name' => 'Desired Username',
 85+ 'password' => 'Password',
 86+ 'retype' => 'Re-typed Password',
 87+ 'email' => 'Email ID(optional)',
 88+ );
 89+ }
 90+
 91+ public function getDescription() {
 92+ return array(
 93+ 'This module validates the parameters posted by the signup form.'
 94+ );
 95+ }
 96+
 97+ public function getPossibleErrors() {
 98+ return array_merge( parent::getPossibleErrors(), array(
 99+ array( 'code' => 'WrongPassword', 'info' => 'Incorrect password entered. Please try again.' ),
 100+ array( 'code' => 'ReadOnlyPage', 'info' => 'Accounts cannot be created with read-only permissions' ),
 101+ array( 'code' => 'NoCookies', 'info' => 'The user account was not created, as we could not confirm its source.
 102+ Ensure you have cookies enabled, reload this page and try again.' ),
 103+ array( 'code' => 'NeedToken', 'info' => 'You need to resubmit your signup with the specified token' ),
 104+ array( 'code' => 'WrongToken', 'info' => 'You specified an invalid token' ),
 105+ array( 'code' => 'InsufficientPermission', 'info' => 'You do not have sufficient permissions to create account' ),
 106+ array( 'code' => 'CreateBlocked', 'info' => 'You have been blocked from creating accounts' ),
 107+ array( 'code' => 'IPBlocked', 'info' => 'Your IP is blocked from creating accounts' ),
 108+ array( 'code' => 'NoName', 'info' => 'You have not set a valid name for the username parameter' ),
 109+ array( 'code' => 'UserExists', 'info' => 'Username entered already in use. Please choose a different name.' ),
 110+ array( 'code' => 'WrongRetype', 'info' => 'The passwords you entered do not match.' ),
 111+ array( 'code' => 'InvalidPass', 'info' => 'You specified an invalid password' ),
 112+ array( 'code' => 'NoEmail', 'info' => 'No e-mail address specified' ),
 113+ array( 'code' => 'InvalidEmail', 'info' => 'You specified an invalid email address' ),
 114+ array( 'code' => 'BlockedByHook', 'info' => 'A hook blocked account creation' ),
 115+ array( 'code' => 'ExternalDBError', 'info' => 'There was either an authentication database error or you are not allowed to update your external account.' ),
 116+ array( 'code' => 'Throttled', 'info' => 'You have tried creating accounts too many times in a short period' ),
 117+ ) );
 118+ }
 119+
 120+ protected function getExamples() {
 121+ return array(
 122+ 'api.php?action=validatesignup&field=username&name=username'
 123+ );
 124+ }
 125+
 126+ public function getVersion() {
 127+ return __CLASS__ . ': $Id: validateSignup.php 91472 2011-07-05 18:43:51Z akshay $';
 128+ }
 129+
 130+}

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r95185Added resources for AJAX-ifying the signup form...akshay00:34, 22 August 2011

Comments

#Comment by Bryan (talk | contribs)   17:43, 22 August 2011

You should have used svn copy to preserve version history.

#Comment by Krinkle (talk | contribs)   20:06, 29 August 2011

Also don't forget the svn-props for Id.

#Comment by Akshay.agarwal (talk | contribs)   20:08, 29 August 2011

Sorry, would definitely keep them in mind next time :)

#Comment by Krinkle (talk | contribs)   21:11, 29 August 2011

I deleted this file, and reverted r95213, then redid the rename with svn move in r95698.

I didn't use svn copy since we don't need to keep both (a copy), just a move.

Some manuals talk about svn rename. svn rename is an alias for svn move, they are 100% the same. See also svn help for a list of commands and their aliases.

#Comment by Krinkle (talk | contribs)   21:11, 29 August 2011

#Comment by Krinkle (talk | contribs)   21:11, 29 August 2011

#Comment by Krinkle (talk | contribs)   21:12, 29 August 2011

Status & tagging log