Index: trunk/extensions/SignupAPI/SignupAPI.php |
— | — | @@ -37,3 +37,94 @@ |
38 | 38 | $wgSpecialPages['UserSignup'] = 'SignupForm'; |
39 | 39 | |
40 | 40 | $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 @@ |
14 | 14 | class ApiSignup extends ApiBase { |
15 | 15 | |
16 | 16 | public function __construct( $main, $action ) { |
17 | | - parent::__construct( $main, $action); |
| 17 | + parent::__construct( $main, $action ); |
18 | 18 | } |
19 | 19 | |
20 | 20 | public function execute() { |
— | — | @@ -28,6 +28,9 @@ |
29 | 29 | 'wpEmail' => $params['email'], |
30 | 30 | 'wpDomain' => $params['domain'], |
31 | 31 | 'wpReason' => $params['realname'], |
| 32 | + 'wpSourceAction' => $params['source_action'], |
| 33 | + 'wpSourceNS' => $params['source_ns'], |
| 34 | + 'wpSourceArticle' => $params['source_article'], |
32 | 35 | 'wpRemember' => '' |
33 | 36 | ) ); |
34 | 37 | |
— | — | @@ -158,6 +161,9 @@ |
159 | 162 | 'email' => null, |
160 | 163 | 'domain' => null, |
161 | 164 | 'realname' => null, |
| 165 | + 'source_action' => null, |
| 166 | + 'source_ns' => null, |
| 167 | + 'source_article' => null, |
162 | 168 | ); |
163 | 169 | } |
164 | 170 | |
— | — | @@ -169,11 +175,12 @@ |
170 | 176 | 'email' => 'Email ID(optional)', |
171 | 177 | 'domain' => 'Domain (optional)', |
172 | 178 | 'realname' => 'Real Name(optional)', |
| 179 | + 'source_action' => 'Source Action', |
| 180 | + 'source_ns' => 'Source Namespace ID', |
| 181 | + 'source_article' => 'Source Article ID', |
173 | 182 | ); |
174 | 183 | } |
175 | 184 | |
176 | | - |
177 | | - |
178 | 185 | public function getDescription() { |
179 | 186 | return array( |
180 | 187 | 'This module validates the parameters posted by the signup form.', |
Index: trunk/extensions/SignupAPI/includes/SpecialUserSignup.php |
— | — | @@ -48,7 +48,6 @@ |
49 | 49 | const THROTLLED = 17; |
50 | 50 | const INIT_FAILED = 18; |
51 | 51 | |
52 | | - |
53 | 52 | //Initialise all variables to be used |
54 | 53 | var $mUsername, $mPassword, $mRetype, $mReturnTo, $mCookieCheck, $mPosted; |
55 | 54 | var $mAction, $mCreateaccount, $mCreateaccountMail; |
— | — | @@ -56,7 +55,8 @@ |
57 | 56 | var $mSkipCookieCheck, $mReturnToQuery, $mToken, $mStickHTTPS; |
58 | 57 | var $mType, $mReason, $mRealName; |
59 | 58 | var $abortError = ''; |
60 | | - var $mUser,$mConfirmationMailStatus,$mRunCookieRedirect,$mRunCreationConfirmation; |
| 59 | + var $mUser, $mConfirmationMailStatus, $mRunCookieRedirect, $mRunCreationConfirmation; |
| 60 | + var $mSourceAction, $mSourceNS, $msourceArticle; |
61 | 61 | |
62 | 62 | /** |
63 | 63 | * @var ExternalUser |
— | — | @@ -105,6 +105,10 @@ |
106 | 106 | $this->mSkipCookieCheck = $request->getCheck( 'wpSkipCookieCheck' ); |
107 | 107 | $this->mToken = $request->getVal( 'wpCreateaccountToken' ); |
108 | 108 | |
| 109 | + $this->mSourceAction = $request->getVal( 'wpSourceAction' ); |
| 110 | + $this->mSourceNS = $request->getVal( 'wpSourceNS' ); |
| 111 | + $this->msourceArticle = $request->getVal( 'wpSourceArticle' ); |
| 112 | + |
109 | 113 | if( $wgEnableEmail ) { |
110 | 114 | $this->mEmail = $request->getText( 'wpEmail' ); |
111 | 115 | } else { |
— | — | @@ -124,6 +128,7 @@ |
125 | 129 | } |
126 | 130 | |
127 | 131 | public function execute( $par ) { |
| 132 | + |
128 | 133 | if ( session_id() == '' ) { |
129 | 134 | wfSetupSession(); |
130 | 135 | } |
— | — | @@ -137,11 +142,12 @@ |
138 | 143 | return; |
139 | 144 | } elseif( $this->mPosted ) { |
140 | 145 | if( $this->mCreateaccount ) { |
141 | | - return $this->processSignup(); |
| 146 | + return $this->processSignup(); |
142 | 147 | } elseif ( $this->mCreateaccountMail ) { |
143 | | - return $this->addNewAccountMailPassword(); |
| 148 | + return $this->addNewAccountMailPassword(); |
144 | 149 | } |
145 | 150 | } |
| 151 | + |
146 | 152 | $this->mainSignupForm( '' ); |
147 | 153 | } |
148 | 154 | |
— | — | @@ -267,12 +273,11 @@ |
268 | 274 | return self::NEED_TOKEN; |
269 | 275 | } |
270 | 276 | |
271 | | - |
272 | 277 | # Validate the createaccount token |
273 | 278 | if ( $this->mToken !== self::getCreateaccountToken() ) { |
274 | 279 | return self::WRONG_TOKEN; |
275 | 280 | } |
276 | | - |
| 281 | + |
277 | 282 | # Check permissions |
278 | 283 | if ( !$wgUser->isAllowed( 'createaccount' ) ) { |
279 | 284 | return self::INSUFFICIENT_PERMISSION; |
— | — | @@ -351,12 +356,13 @@ |
352 | 357 | } |
353 | 358 | |
354 | 359 | self::clearCreateaccountToken(); |
| 360 | + |
355 | 361 | $mUser = $this->initUser( $mUser, false ); |
356 | 362 | if( $mUser == null ) { |
357 | | - return self::INIT_FAILED; |
| 363 | + return self::INIT_FAILED; |
358 | 364 | } |
359 | 365 | |
360 | | - $this->addNewAccount($mUser); |
| 366 | + $this->addNewAccount( $mUser ); |
361 | 367 | return self::SUCCESS; |
362 | 368 | } |
363 | 369 | |
— | — | @@ -399,6 +405,8 @@ |
400 | 406 | $ssUpdate = new SiteStatsUpdate( 0, 0, 0, 0, 1 ); |
401 | 407 | $ssUpdate->doUpdate(); |
402 | 408 | |
| 409 | + $this->addToSourceTracking( $mUser ); |
| 410 | + |
403 | 411 | return $mUser; |
404 | 412 | } |
405 | 413 | |
— | — | @@ -414,51 +422,66 @@ |
415 | 423 | $wgOut->addWikiText( $this->mConfirmationMailStatus->getWikiText( 'confirmemail_sendfailed' ) ); |
416 | 424 | } |
417 | 425 | } |
| 426 | + |
418 | 427 | if( $this->mRunCookieRedirect ) { |
419 | 428 | $this->cookieRedirectCheck( 'new' ); |
420 | 429 | } |
| 430 | + |
421 | 431 | # Confirm that the account was created |
422 | | - if($this->mRunCreationConfirmation) { |
| 432 | + if( $this->mRunCreationConfirmation ) { |
423 | 433 | $self = SpecialPage::getTitleFor( 'Userlogin' ); |
424 | 434 | $wgOut->setPageTitle( wfMsgHtml( 'accountcreated' ) ); |
425 | 435 | $wgOut->addWikiMsg( 'accountcreatedtext', $mUser->getName() ); |
426 | 436 | $wgOut->returnToMain( false, $self ); |
427 | 437 | } |
| 438 | + |
428 | 439 | $this->successfulCreation(); |
429 | 440 | break; |
| 441 | + |
430 | 442 | case self::INVALID_DOMAIN: |
431 | 443 | $this->mainSignupForm( wfMsg( 'wrongpassword' ) ); |
432 | 444 | break; |
| 445 | + |
433 | 446 | case self::READ_ONLY_PAGE: |
434 | 447 | $wgOut->readOnlyPage(); |
435 | 448 | break; |
| 449 | + |
436 | 450 | case self::NO_COOKIES: |
437 | 451 | $this->mainSignupForm( wfMsgExt( 'nocookiesfornew', array( 'parseinline' ) ) ); |
438 | 452 | break; |
| 453 | + |
439 | 454 | case self::NEED_TOKEN: |
440 | 455 | $this->mainSignupForm( wfMsg( 'sessionfailure' ) ); |
441 | 456 | break; |
| 457 | + |
442 | 458 | case self::WRONG_TOKEN: |
443 | 459 | $this->mainSignupForm( wfMsg( 'sessionfailure' ) ); |
444 | 460 | break; |
| 461 | + |
445 | 462 | case self::INSUFFICIENT_PERMISSION: |
446 | 463 | $wgOut->permissionRequired( 'createaccount' ); |
447 | 464 | break; |
| 465 | + |
448 | 466 | case self::CREATE_BLOCKED: |
449 | 467 | $this->userBlockedMessage( $wgUser->isBlockedFromCreateAccount() ); |
450 | 468 | break; |
| 469 | + |
451 | 470 | case self::IP_BLOCKED: |
452 | 471 | $this->mainSignupForm( wfMsg( 'sorbs_create_account_reason' ) . ' (' . htmlspecialchars( $ip ) . ')' ); |
453 | 472 | break; |
| 473 | + |
454 | 474 | case self::NO_NAME: |
455 | 475 | $this->mainSignupForm( wfMsg( 'noname' ) ); |
456 | 476 | break; |
| 477 | + |
457 | 478 | case self::USER_EXISTS: |
458 | 479 | $this->mainSignupForm( wfMsg( 'userexists' ) ); |
459 | 480 | break; |
| 481 | + |
460 | 482 | case self::WRONG_RETYPE: |
461 | 483 | $this->mainSignupForm( wfMsg( 'badretype' ) ); |
462 | 484 | break; |
| 485 | + |
463 | 486 | case self::INVALID_PASS: |
464 | 487 | if ( is_array( $valid ) ) { |
465 | 488 | $message = array_shift( $valid ); |
— | — | @@ -470,26 +493,33 @@ |
471 | 494 | } |
472 | 495 | $this->mainSignupForm( wfMsgExt( $message, array( 'parsemag' ), $params ) ); |
473 | 496 | break; |
| 497 | + |
474 | 498 | case self::NO_EMAIL: |
475 | 499 | $this->mainSignupForm( wfMsg( 'noemailtitle' ) ); |
476 | 500 | break; |
| 501 | + |
477 | 502 | case self::INVALID_EMAIL: |
478 | 503 | $this->mainSignupForm( wfMsg( 'invalidemailaddress' ) ); |
479 | 504 | break; |
| 505 | + |
480 | 506 | case self::BLOCKED_BY_HOOK: |
481 | 507 | wfDebug( "LoginForm::addNewAccountInternal: a hook blocked creation\n" ); |
482 | 508 | $this->mainSignupForm( $abortError ); |
483 | 509 | break; |
| 510 | + |
484 | 511 | case self::EXTR_DB_ERROR: |
485 | 512 | $this->mainSignupForm( wfMsg( 'externaldberror' ) ); |
486 | 513 | break; |
| 514 | + |
487 | 515 | case self::THROTLLED: |
488 | 516 | global $wgAccountCreationThrottle; |
489 | 517 | $this->mainSignupForm( wfMsgExt( 'acct_creation_throttle_hit', array( 'parseinline' ), $wgAccountCreationThrottle ) ); |
490 | 518 | break; |
| 519 | + |
491 | 520 | case self::INIT_FAILED: |
492 | 521 | $this->mainSignupForm( wfMsg( 'init_failed' ) ); |
493 | 522 | break; |
| 523 | + |
494 | 524 | default: |
495 | 525 | throw new MWException( 'Unhandled case value' ); |
496 | 526 | } |
— | — | @@ -586,7 +616,7 @@ |
587 | 617 | * @private |
588 | 618 | */ |
589 | 619 | function mainSignupForm( $msg, $msgtype = 'error' ) { |
590 | | - global $wgUser, $wgOut, $wgHiddenPrefs; |
| 620 | + global $wgUser, $wgOut, $wgHiddenPrefs, $wgRequest; |
591 | 621 | global $wgEnableEmail, $wgEnableUserEmail; |
592 | 622 | global $wgLoginLanguageSelector; |
593 | 623 | global $wgAuth, $wgEmailConfirmToEdit, $wgCookieExpiration; |
— | — | @@ -618,7 +648,7 @@ |
619 | 649 | } |
620 | 650 | |
621 | 651 | $template = new UsercreateTemplate(); |
622 | | - $q = 'action=submitlogin&type=signup'; |
| 652 | + $q = "action=submitlogin&type=signup&wpSourceAction=$this->mSourceAction&wpSourceNS=$this->mSourceNS&wpSourceArticle=$this->msourceArticle"; |
623 | 653 | $linkq = 'type=login'; |
624 | 654 | $linkmsg = 'gotaccount'; |
625 | 655 | |
— | — | @@ -677,6 +707,10 @@ |
678 | 708 | $template->set( 'cansecurelogin', ( $wgSecureLogin === true ) ); |
679 | 709 | $template->set( 'stickHTTPS', $this->mStickHTTPS ); |
680 | 710 | |
| 711 | + $template->set( 'wpSourceAction', $this->mSourceAction ); |
| 712 | + $template->set( 'wpSourceNS', $this->mSourceNS ); |
| 713 | + $template->set( 'wpSourceArticle', $this->msourceArticle ); |
| 714 | + |
681 | 715 | if ( !self::getCreateaccountToken() ) { |
682 | 716 | self::setCreateaccountToken(); |
683 | 717 | } |
— | — | @@ -714,11 +748,11 @@ |
715 | 749 | */ |
716 | 750 | function showCreateOrLoginLink( &$mUserser ) { |
717 | 751 | if( $this->mType == 'signup' ) { |
718 | | - return true; |
| 752 | + return true; |
719 | 753 | } elseif( $mUserser->isAllowed( 'createaccount' ) ) { |
720 | | - return true; |
| 754 | + return true; |
721 | 755 | } else { |
722 | | - return false; |
| 756 | + return false; |
723 | 757 | } |
724 | 758 | } |
725 | 759 | |
— | — | @@ -800,12 +834,12 @@ |
801 | 835 | * |
802 | 836 | * @return string |
803 | 837 | */ |
804 | | - |
805 | 838 | function makeLanguageSelector() { |
806 | 839 | global $wgLang; |
807 | 840 | |
808 | 841 | $msg = wfMessage( 'loginlanguagelinks' )->inContentLanguage(); |
809 | 842 | if( !$msg->isBlank() ) { |
| 843 | + |
810 | 844 | $langs = explode( "\n", $msg->text() ); |
811 | 845 | $links = array(); |
812 | 846 | foreach( $langs as $lang ) { |
— | — | @@ -866,4 +900,18 @@ |
867 | 901 | $wgOut->returnToMain( null ); |
868 | 902 | } |
869 | 903 | } |
| 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 | + } |
870 | 918 | } |