r91595 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91594‎ | r91595 | r91596 >
Date:20:12, 6 July 2011
Author:akshay
Status:deferred (Comments)
Tags:signupapi 
Comment:
Added source tracking, fixed whitespace issues
Modified paths:
  • /trunk/extensions/SignupAPI/SignupAPI.php (modified) (history)
  • /trunk/extensions/SignupAPI/includes/APISignup.php (modified) (history)
  • /trunk/extensions/SignupAPI/includes/SpecialUserSignup.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SignupAPI/SignupAPI.php
@@ -37,3 +37,94 @@
3838 $wgSpecialPages['UserSignup'] = 'SignupForm';
3939
4040 $wgAPIModules['signup'] = 'ApiSignup';
 41+
 42+# Schema updates for update.php
 43+$wgHooks['LoadExtensionSchemaUpdates'][] = 'fnMyHook';
 44+function fnMyHook() {
 45+ global $wgExtNewTables;
 46+ $wgExtNewTables[] = array(
 47+ 'sourcetracking',
 48+ dirname( __FILE__ ) . '/sourcetracking.sql' );
 49+ return true;
 50+}
 51+
 52+# Add source tracking to personal URL's
 53+$wgHooks['PersonalUrls'][] = 'addSourceTracking';
 54+
 55+function addSourceTracking( &$personal_urls, &$title )
 56+{
 57+ global $wgRequest,$wgUser;
 58+
 59+ #generate source tracking parameters
 60+ $sourceAction = $wgRequest->getVal( 'action' );
 61+ $sourceNS = $title->getNamespace();
 62+ $sourceArticle = $title->getArticleID();
 63+ $loggedin = $wgUser->isLoggedIn();
 64+ $thispage = $title->getPrefixedDBkey();
 65+ $thisurl = $title->getPrefixedURL();
 66+ $query = array();
 67+ if ( !$wgRequest->wasPosted() ) {
 68+ $query = $wgRequest->getValues();
 69+ unset( $query['title'] );
 70+ unset( $query['returnto'] );
 71+ unset( $query['returntoquery'] );
 72+ }
 73+ $thisquery = wfUrlencode( wfArrayToCGI( $query ) );
 74+
 75+ // Get the returnto and returntoquery parameters from the query string
 76+ // or fall back on $this->thisurl or $this->thisquery
 77+ // We can't use getVal()'s default value feature here because
 78+ // stuff from $wgRequest needs to be escaped, but thisurl and thisquery
 79+ // are already escaped.
 80+ $page = $wgRequest->getVal( 'returnto' );
 81+ if ( !is_null( $page ) ) {
 82+ $page = wfUrlencode( $page );
 83+ } else {
 84+ $page = $thisurl;
 85+ }
 86+ $query = $wgRequest->getVal( 'returntoquery' );
 87+ if ( !is_null( $query ) ) {
 88+ $query = wfUrlencode( $query );
 89+ } else {
 90+ $query = $thisquery;
 91+ }
 92+ $returnto = "returnto=$page";
 93+ if ( $query != '' ) {
 94+ $returnto .= "&returntoquery=$query";
 95+ }
 96+
 97+ if (isset ( $personal_urls['login'] ) ) {
 98+ $login_url = $personal_urls['login'];
 99+ $login_url['href'] = $login_url['href']."&source_action=$sourceAction&source_ns=$sourceNS&source_article=$sourceArticle";
 100+ $personal_urls['login'] = $login_url;
 101+ }
 102+
 103+ if ( isset ( $personal_urls['anonlogin'] ) ) {
 104+ $login_url = $personal_urls['anonlogin'];
 105+ $login_url['href'] = $login_url['href']."&source_action=$sourceAction&source_ns=$sourceNS&source_article=$sourceArticle";
 106+ $personal_urls['anonlogin'] = $login_url;
 107+ }
 108+
 109+ if ( isset ( $personal_urls['createaccount'] ) ) {
 110+ global $wgServer, $wgSecureLogin;
 111+ $page = $wgRequest->getVal( 'returnto' );
 112+ $is_signup = $wgRequest->getText( 'type' ) == "signup";
 113+ $createaccount_url = array(
 114+ 'text' => wfMsg( 'createaccount' ),
 115+ 'href' => SkinTemplate::makeSpecialUrl( 'Usersignup', "$returnto&type=signup&wpSourceAction=$sourceAction&wpSourceNS=$sourceNS&wpSourceArticle=$sourceArticle" ),
 116+ 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup
 117+ );
 118+
 119+ if ( substr( $wgServer, 0, 5 ) === 'http:' && $wgSecureLogin ) {
 120+ $title = SpecialPage::getTitleFor( 'Usersignup' );
 121+ $https_url = preg_replace( '/^http:/', 'https:', $title->getFullURL( "type=signup" ) );
 122+ $createaccount_url['href'] = $https_url;
 123+ $createaccount_url['class'] = 'link-https';
 124+ }
 125+ $personal_urls['createaccount'] = $createaccount_url;
 126+ }
 127+
 128+ return true;
 129+}
 130+
 131+
Index: trunk/extensions/SignupAPI/includes/APISignup.php
@@ -13,7 +13,7 @@
1414 class ApiSignup extends ApiBase {
1515
1616 public function __construct( $main, $action ) {
17 - parent::__construct( $main, $action);
 17+ parent::__construct( $main, $action );
1818 }
1919
2020 public function execute() {
@@ -28,6 +28,9 @@
2929 'wpEmail' => $params['email'],
3030 'wpDomain' => $params['domain'],
3131 'wpReason' => $params['realname'],
 32+ 'wpSourceAction' => $params['source_action'],
 33+ 'wpSourceNS' => $params['source_ns'],
 34+ 'wpSourceArticle' => $params['source_article'],
3235 'wpRemember' => ''
3336 ) );
3437
@@ -158,6 +161,9 @@
159162 'email' => null,
160163 'domain' => null,
161164 'realname' => null,
 165+ 'source_action' => null,
 166+ 'source_ns' => null,
 167+ 'source_article' => null,
162168 );
163169 }
164170
@@ -169,11 +175,12 @@
170176 'email' => 'Email ID(optional)',
171177 'domain' => 'Domain (optional)',
172178 'realname' => 'Real Name(optional)',
 179+ 'source_action' => 'Source Action',
 180+ 'source_ns' => 'Source Namespace ID',
 181+ 'source_article' => 'Source Article ID',
173182 );
174183 }
175184
176 -
177 -
178185 public function getDescription() {
179186 return array(
180187 'This module validates the parameters posted by the signup form.',
Index: trunk/extensions/SignupAPI/includes/SpecialUserSignup.php
@@ -48,7 +48,6 @@
4949 const THROTLLED = 17;
5050 const INIT_FAILED = 18;
5151
52 -
5352 //Initialise all variables to be used
5453 var $mUsername, $mPassword, $mRetype, $mReturnTo, $mCookieCheck, $mPosted;
5554 var $mAction, $mCreateaccount, $mCreateaccountMail;
@@ -56,7 +55,8 @@
5756 var $mSkipCookieCheck, $mReturnToQuery, $mToken, $mStickHTTPS;
5857 var $mType, $mReason, $mRealName;
5958 var $abortError = '';
60 - var $mUser,$mConfirmationMailStatus,$mRunCookieRedirect,$mRunCreationConfirmation;
 59+ var $mUser, $mConfirmationMailStatus, $mRunCookieRedirect, $mRunCreationConfirmation;
 60+ var $mSourceAction, $mSourceNS, $msourceArticle;
6161
6262 /**
6363 * @var ExternalUser
@@ -105,6 +105,10 @@
106106 $this->mSkipCookieCheck = $request->getCheck( 'wpSkipCookieCheck' );
107107 $this->mToken = $request->getVal( 'wpCreateaccountToken' );
108108
 109+ $this->mSourceAction = $request->getVal( 'wpSourceAction' );
 110+ $this->mSourceNS = $request->getVal( 'wpSourceNS' );
 111+ $this->msourceArticle = $request->getVal( 'wpSourceArticle' );
 112+
109113 if( $wgEnableEmail ) {
110114 $this->mEmail = $request->getText( 'wpEmail' );
111115 } else {
@@ -124,6 +128,7 @@
125129 }
126130
127131 public function execute( $par ) {
 132+
128133 if ( session_id() == '' ) {
129134 wfSetupSession();
130135 }
@@ -137,11 +142,12 @@
138143 return;
139144 } elseif( $this->mPosted ) {
140145 if( $this->mCreateaccount ) {
141 - return $this->processSignup();
 146+ return $this->processSignup();
142147 } elseif ( $this->mCreateaccountMail ) {
143 - return $this->addNewAccountMailPassword();
 148+ return $this->addNewAccountMailPassword();
144149 }
145150 }
 151+
146152 $this->mainSignupForm( '' );
147153 }
148154
@@ -267,12 +273,11 @@
268274 return self::NEED_TOKEN;
269275 }
270276
271 -
272277 # Validate the createaccount token
273278 if ( $this->mToken !== self::getCreateaccountToken() ) {
274279 return self::WRONG_TOKEN;
275280 }
276 -
 281+
277282 # Check permissions
278283 if ( !$wgUser->isAllowed( 'createaccount' ) ) {
279284 return self::INSUFFICIENT_PERMISSION;
@@ -351,12 +356,13 @@
352357 }
353358
354359 self::clearCreateaccountToken();
 360+
355361 $mUser = $this->initUser( $mUser, false );
356362 if( $mUser == null ) {
357 - return self::INIT_FAILED;
 363+ return self::INIT_FAILED;
358364 }
359365
360 - $this->addNewAccount($mUser);
 366+ $this->addNewAccount( $mUser );
361367 return self::SUCCESS;
362368 }
363369
@@ -399,6 +405,8 @@
400406 $ssUpdate = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
401407 $ssUpdate->doUpdate();
402408
 409+ $this->addToSourceTracking( $mUser );
 410+
403411 return $mUser;
404412 }
405413
@@ -414,51 +422,66 @@
415423 $wgOut->addWikiText( $this->mConfirmationMailStatus->getWikiText( 'confirmemail_sendfailed' ) );
416424 }
417425 }
 426+
418427 if( $this->mRunCookieRedirect ) {
419428 $this->cookieRedirectCheck( 'new' );
420429 }
 430+
421431 # Confirm that the account was created
422 - if($this->mRunCreationConfirmation) {
 432+ if( $this->mRunCreationConfirmation ) {
423433 $self = SpecialPage::getTitleFor( 'Userlogin' );
424434 $wgOut->setPageTitle( wfMsgHtml( 'accountcreated' ) );
425435 $wgOut->addWikiMsg( 'accountcreatedtext', $mUser->getName() );
426436 $wgOut->returnToMain( false, $self );
427437 }
 438+
428439 $this->successfulCreation();
429440 break;
 441+
430442 case self::INVALID_DOMAIN:
431443 $this->mainSignupForm( wfMsg( 'wrongpassword' ) );
432444 break;
 445+
433446 case self::READ_ONLY_PAGE:
434447 $wgOut->readOnlyPage();
435448 break;
 449+
436450 case self::NO_COOKIES:
437451 $this->mainSignupForm( wfMsgExt( 'nocookiesfornew', array( 'parseinline' ) ) );
438452 break;
 453+
439454 case self::NEED_TOKEN:
440455 $this->mainSignupForm( wfMsg( 'sessionfailure' ) );
441456 break;
 457+
442458 case self::WRONG_TOKEN:
443459 $this->mainSignupForm( wfMsg( 'sessionfailure' ) );
444460 break;
 461+
445462 case self::INSUFFICIENT_PERMISSION:
446463 $wgOut->permissionRequired( 'createaccount' );
447464 break;
 465+
448466 case self::CREATE_BLOCKED:
449467 $this->userBlockedMessage( $wgUser->isBlockedFromCreateAccount() );
450468 break;
 469+
451470 case self::IP_BLOCKED:
452471 $this->mainSignupForm( wfMsg( 'sorbs_create_account_reason' ) . ' (' . htmlspecialchars( $ip ) . ')' );
453472 break;
 473+
454474 case self::NO_NAME:
455475 $this->mainSignupForm( wfMsg( 'noname' ) );
456476 break;
 477+
457478 case self::USER_EXISTS:
458479 $this->mainSignupForm( wfMsg( 'userexists' ) );
459480 break;
 481+
460482 case self::WRONG_RETYPE:
461483 $this->mainSignupForm( wfMsg( 'badretype' ) );
462484 break;
 485+
463486 case self::INVALID_PASS:
464487 if ( is_array( $valid ) ) {
465488 $message = array_shift( $valid );
@@ -470,26 +493,33 @@
471494 }
472495 $this->mainSignupForm( wfMsgExt( $message, array( 'parsemag' ), $params ) );
473496 break;
 497+
474498 case self::NO_EMAIL:
475499 $this->mainSignupForm( wfMsg( 'noemailtitle' ) );
476500 break;
 501+
477502 case self::INVALID_EMAIL:
478503 $this->mainSignupForm( wfMsg( 'invalidemailaddress' ) );
479504 break;
 505+
480506 case self::BLOCKED_BY_HOOK:
481507 wfDebug( "LoginForm::addNewAccountInternal: a hook blocked creation\n" );
482508 $this->mainSignupForm( $abortError );
483509 break;
 510+
484511 case self::EXTR_DB_ERROR:
485512 $this->mainSignupForm( wfMsg( 'externaldberror' ) );
486513 break;
 514+
487515 case self::THROTLLED:
488516 global $wgAccountCreationThrottle;
489517 $this->mainSignupForm( wfMsgExt( 'acct_creation_throttle_hit', array( 'parseinline' ), $wgAccountCreationThrottle ) );
490518 break;
 519+
491520 case self::INIT_FAILED:
492521 $this->mainSignupForm( wfMsg( 'init_failed' ) );
493522 break;
 523+
494524 default:
495525 throw new MWException( 'Unhandled case value' );
496526 }
@@ -586,7 +616,7 @@
587617 * @private
588618 */
589619 function mainSignupForm( $msg, $msgtype = 'error' ) {
590 - global $wgUser, $wgOut, $wgHiddenPrefs;
 620+ global $wgUser, $wgOut, $wgHiddenPrefs, $wgRequest;
591621 global $wgEnableEmail, $wgEnableUserEmail;
592622 global $wgLoginLanguageSelector;
593623 global $wgAuth, $wgEmailConfirmToEdit, $wgCookieExpiration;
@@ -618,7 +648,7 @@
619649 }
620650
621651 $template = new UsercreateTemplate();
622 - $q = 'action=submitlogin&type=signup';
 652+ $q = "action=submitlogin&type=signup&wpSourceAction=$this->mSourceAction&wpSourceNS=$this->mSourceNS&wpSourceArticle=$this->msourceArticle";
623653 $linkq = 'type=login';
624654 $linkmsg = 'gotaccount';
625655
@@ -677,6 +707,10 @@
678708 $template->set( 'cansecurelogin', ( $wgSecureLogin === true ) );
679709 $template->set( 'stickHTTPS', $this->mStickHTTPS );
680710
 711+ $template->set( 'wpSourceAction', $this->mSourceAction );
 712+ $template->set( 'wpSourceNS', $this->mSourceNS );
 713+ $template->set( 'wpSourceArticle', $this->msourceArticle );
 714+
681715 if ( !self::getCreateaccountToken() ) {
682716 self::setCreateaccountToken();
683717 }
@@ -714,11 +748,11 @@
715749 */
716750 function showCreateOrLoginLink( &$mUserser ) {
717751 if( $this->mType == 'signup' ) {
718 - return true;
 752+ return true;
719753 } elseif( $mUserser->isAllowed( 'createaccount' ) ) {
720 - return true;
 754+ return true;
721755 } else {
722 - return false;
 756+ return false;
723757 }
724758 }
725759
@@ -800,12 +834,12 @@
801835 *
802836 * @return string
803837 */
804 -
805838 function makeLanguageSelector() {
806839 global $wgLang;
807840
808841 $msg = wfMessage( 'loginlanguagelinks' )->inContentLanguage();
809842 if( !$msg->isBlank() ) {
 843+
810844 $langs = explode( "\n", $msg->text() );
811845 $links = array();
812846 foreach( $langs as $lang ) {
@@ -866,4 +900,18 @@
867901 $wgOut->returnToMain( null );
868902 }
869903 }
 904+
 905+ private function addToSourceTracking( $mUser ) {
 906+ $sourcetracking_data = array(
 907+ 'userid' => $mUser->getId(),
 908+ 'source_action' => $this->mSourceAction,
 909+ 'source_ns' => $this->mSourceNS,
 910+ 'source_article' => $this->msourceArticle
 911+ );
 912+
 913+ $dbw = wfGetDB( DB_MASTER );
 914+ $dbw->insert( 'sourcetracking', $sourcetracking_data );
 915+
 916+ return true;
 917+ }
870918 }

Comments

#Comment by Reedy (talk | contribs)   00:30, 7 July 2011

You've still got a mix of spaces and tabs for whitespace

Status & tagging log