父节点
5459b56dad
当前提交
d3f526c596
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NewSignupPage extension for MediaWiki -- enhances the default signup form
|
||||
*
|
||||
|
@ -9,53 +10,54 @@
|
|||
* @copyright Copyright © 2022- Qiuwen Baike Contributors
|
||||
* @license GPL-2.0-or-later
|
||||
*/
|
||||
class NewSignupPage {
|
||||
class NewSignupPage
|
||||
{
|
||||
|
||||
/**
|
||||
* Add the JavaScript file to the page output on the signup page.
|
||||
*
|
||||
* @param OutputPage &$out
|
||||
* @param Skin &$skin
|
||||
*/
|
||||
public static function onBeforePageDisplay( &$out, &$skin ) {
|
||||
$title = $out->getTitle();
|
||||
/**
|
||||
* Add the JavaScript file to the page output on the signup page.
|
||||
*
|
||||
* @param OutputPage &$out
|
||||
* @param Skin &$skin
|
||||
*/
|
||||
public static function onBeforePageDisplay(&$out, &$skin)
|
||||
{
|
||||
$title = $out->getTitle();
|
||||
|
||||
// Only do our magic if we're on the signup page or login page
|
||||
// It's called Special:CreateAccount or Special:UserLogin since AuthManager (MW 1.27+)
|
||||
// Only do our magic if we're on the signup page or login page
|
||||
// It's called Special:CreateAccount or Special:UserLogin since AuthManager (MW 1.27+)
|
||||
|
||||
// Warning: Userlogin should be all lowercased!
|
||||
if ( $title->isSpecial( 'CreateAccount' ) || $title->isSpecial( 'Userlogin' ) ) {
|
||||
$out->addModules( ['ext.newsignuppage'] );
|
||||
}
|
||||
// Warning: Userlogin should be all lowercased!
|
||||
if ($title->isSpecial('CreateAccount') || $title->isSpecial('Userlogin')) {
|
||||
$out->addModules(['ext.newsignuppage']);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Creates the necessary database table when the user runs
|
||||
* maintenance/update.php, the core MediaWiki updater script, provided that
|
||||
* the configuration specifies us to create it.
|
||||
*
|
||||
* @param DatabaseUpdater $updater
|
||||
* @return bool True when we should not do anything
|
||||
*/
|
||||
public static function onLoadExtensionSchemaUpdates($updater)
|
||||
{
|
||||
global $wgRegisterTrack;
|
||||
|
||||
/**
|
||||
* Creates the necessary database table when the user runs
|
||||
* maintenance/update.php, the core MediaWiki updater script, provided that
|
||||
* the configuration specifies us to create it.
|
||||
*
|
||||
* @param DatabaseUpdater $updater
|
||||
* @return bool True when we should not do anything
|
||||
*/
|
||||
public static function onLoadExtensionSchemaUpdates( $updater ) {
|
||||
global $wgRegisterTrack;
|
||||
$db = $updater->getDB();
|
||||
|
||||
$db = $updater->getDB();
|
||||
if (!$db->tableExists('user_register_track') && !$wgRegisterTrack) {
|
||||
// Table doesn't exist and shouldn't either -> bail out
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( !$db->tableExists( 'user_register_track' ) && !$wgRegisterTrack ) {
|
||||
// Table doesn't exist and shouldn't either -> bail out
|
||||
return true;
|
||||
}
|
||||
|
||||
$dir = __DIR__ . '/../sql';
|
||||
$dbType = $db->getType();
|
||||
$file = $dir . '/user_register_track.sql';
|
||||
if ( $dbType === 'postgres' ) {
|
||||
$file = $dir . '/user_register_track.postgres.sql';
|
||||
}
|
||||
|
||||
$updater->addExtensionTable( 'user_register_track', $file );
|
||||
}
|
||||
$dir = __DIR__ . '/../sql';
|
||||
$dbType = $db->getType();
|
||||
$file = $dir . '/user_register_track.sql';
|
||||
if ($dbType === 'postgres') {
|
||||
$file = $dir . '/user_register_track.postgres.sql';
|
||||
}
|
||||
|
||||
$updater->addExtensionTable('user_register_track', $file);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,71 +7,75 @@ use MediaWiki\Auth\AuthenticationRequest;
|
|||
* @since MediaWiki 1.27
|
||||
* @phan-file-suppress PhanTypeMismatchReturn It appears that phan seems to hate the retval of getFieldInfo()...
|
||||
*/
|
||||
class NewSignupPageAuthenticationRequest extends AuthenticationRequest {
|
||||
public $required = self::REQUIRED; // only ToS check is mandatory
|
||||
class NewSignupPageAuthenticationRequest extends AuthenticationRequest
|
||||
{
|
||||
public $required = self::REQUIRED; // only ToS check is mandatory
|
||||
|
||||
/**
|
||||
* @var int Email invitation source identifier to be stored in the
|
||||
* user_email_track table
|
||||
* @see /extensions/MiniInvite/includes/UserEmailTrack.class.php for details
|
||||
*/
|
||||
public $from;
|
||||
/**
|
||||
* @var int Email invitation source identifier to be stored in the
|
||||
* user_email_track table
|
||||
* @see /extensions/MiniInvite/includes/UserEmailTrack.class.php for details
|
||||
*/
|
||||
public $from;
|
||||
|
||||
/**
|
||||
* @var string|int Username of the person who referred the user creating an
|
||||
* account to the wiki; used to give out points to the referring user and
|
||||
* also automatically friend them and the new user if that configuration
|
||||
* setting is enabled
|
||||
*/
|
||||
public $referral;
|
||||
/**
|
||||
* @var string|int Username of the person who referred the user creating an
|
||||
* account to the wiki; used to give out points to the referring user and
|
||||
* also automatically friend them and the new user if that configuration
|
||||
* setting is enabled
|
||||
*/
|
||||
public $referral;
|
||||
|
||||
/**
|
||||
* @var bool Was the "I agree to the terms of service"
|
||||
* checkbox checked? It must be in order for the account creation process
|
||||
* to continue.
|
||||
*/
|
||||
public $wpTermsOfService;
|
||||
/**
|
||||
* @var bool Was the "I agree to the terms of service"
|
||||
* checkbox checked? It must be in order for the account creation process
|
||||
* to continue.
|
||||
*/
|
||||
public $wpTermsOfService;
|
||||
|
||||
/** @var WebRequest */
|
||||
public $request;
|
||||
/** @var WebRequest */
|
||||
public $request;
|
||||
|
||||
/**
|
||||
* @param WebRequest $request
|
||||
*/
|
||||
public function __construct( $request ) {
|
||||
$this->request = $request;
|
||||
}
|
||||
/**
|
||||
* @param WebRequest $request
|
||||
*/
|
||||
public function __construct($request)
|
||||
{
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public function getFieldInfo() {
|
||||
global $wgNewSignupPageToSURL, $wgNewSignupPagePPURL;
|
||||
return [
|
||||
'from' => [
|
||||
'type' => 'hidden',
|
||||
'optional' => true,
|
||||
'value' => $this->request->getInt( 'from' )
|
||||
],
|
||||
'referral' => [
|
||||
'type' => 'hidden',
|
||||
'optional' => true,
|
||||
'value' => $this->request->getVal( 'referral' )
|
||||
],
|
||||
'wpTermsOfService' => [
|
||||
'type' => 'checkbox',
|
||||
'label' => wfMessage(
|
||||
'newsignuppage-loginform-tos',
|
||||
$wgNewSignupPageToSURL,
|
||||
$wgNewSignupPagePPURL
|
||||
)
|
||||
]
|
||||
];
|
||||
}
|
||||
/** @inheritDoc */
|
||||
public function getFieldInfo()
|
||||
{
|
||||
global $wgNewSignupPageToSURL, $wgNewSignupPagePPURL;
|
||||
return [
|
||||
'from' => [
|
||||
'type' => 'hidden',
|
||||
'optional' => true,
|
||||
'value' => $this->request->getInt('from')
|
||||
],
|
||||
'referral' => [
|
||||
'type' => 'hidden',
|
||||
'optional' => true,
|
||||
'value' => $this->request->getVal('referral')
|
||||
],
|
||||
'wpTermsOfService' => [
|
||||
'type' => 'checkbox',
|
||||
'label' => wfMessage(
|
||||
'newsignuppage-loginform-tos',
|
||||
$wgNewSignupPageToSURL,
|
||||
$wgNewSignupPagePPURL
|
||||
)
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public function loadFromSubmission( array $data ) {
|
||||
// We always want to use this request, so ignore parent's return value.
|
||||
parent::loadFromSubmission( $data );
|
||||
/** @inheritDoc */
|
||||
public function loadFromSubmission(array $data)
|
||||
{
|
||||
// We always want to use this request, so ignore parent's return value.
|
||||
parent::loadFromSubmission($data);
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,143 +10,149 @@ use MediaWiki\MediaWikiServices;
|
|||
* @license GPL-2.0-or-later
|
||||
* @note Uses GPL-licensed code from LoginReg extension (in beginSecondaryAccountCreation())
|
||||
*/
|
||||
class NewSignupPageSecondaryAuthenticationProvider extends AbstractSecondaryAuthenticationProvider {
|
||||
class NewSignupPageSecondaryAuthenticationProvider extends AbstractSecondaryAuthenticationProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* @param array $params
|
||||
*/
|
||||
public function __construct( $params = [] ) {
|
||||
}
|
||||
/**
|
||||
* @param array $params
|
||||
*/
|
||||
public function __construct($params = [])
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Abort the creation of the new account if the user hasn't checked the
|
||||
* "I agree to the terms of service" checkbox and they aren't allowed to
|
||||
* bypass that check.
|
||||
*
|
||||
* @param User $user
|
||||
* @param User $creator
|
||||
* @param array $reqs
|
||||
* @return StatusValue
|
||||
*/
|
||||
public function testForAccountCreation( $user, $creator, array $reqs ) {
|
||||
$req = AuthenticationRequest::getRequestByClass( $reqs, NewSignupPageAuthenticationRequest::class );
|
||||
if (
|
||||
$req && $req->wpTermsOfService ||
|
||||
$creator->isAllowed( 'bypasstoscheck' )
|
||||
) {
|
||||
return StatusValue::newGood();
|
||||
} else {
|
||||
return StatusValue::newFatal( 'newsignuppage-must-accept-tos' );
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Abort the creation of the new account if the user hasn't checked the
|
||||
* "I agree to the terms of service" checkbox and they aren't allowed to
|
||||
* bypass that check.
|
||||
*
|
||||
* @param User $user
|
||||
* @param User $creator
|
||||
* @param array $reqs
|
||||
* @return StatusValue
|
||||
*/
|
||||
public function testForAccountCreation($user, $creator, array $reqs)
|
||||
{
|
||||
$req = AuthenticationRequest::getRequestByClass($reqs, NewSignupPageAuthenticationRequest::class);
|
||||
if (
|
||||
$req && $req->wpTermsOfService ||
|
||||
$creator->isAllowed('bypasstoscheck')
|
||||
) {
|
||||
return StatusValue::newGood();
|
||||
} else {
|
||||
return StatusValue::newFatal('newsignuppage-must-accept-tos');
|
||||
}
|
||||
}
|
||||
|
||||
public function getAuthenticationRequests( $action, array $options ) {
|
||||
if ( $action === AuthManager::ACTION_CREATE || $action === AuthManager::ACTION_LOGIN ) {
|
||||
return [ new NewSignupPageAuthenticationRequest(
|
||||
$this->manager->getRequest()
|
||||
) ];
|
||||
}
|
||||
public function getAuthenticationRequests($action, array $options)
|
||||
{
|
||||
if ($action === AuthManager::ACTION_CREATE || $action === AuthManager::ACTION_LOGIN) {
|
||||
return [new NewSignupPageAuthenticationRequest(
|
||||
$this->manager->getRequest()
|
||||
)];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
public function beginSecondaryAuthentication( $user, array $reqs ) {
|
||||
return AuthenticationResponse::newAbstain();
|
||||
}
|
||||
public function beginSecondaryAuthentication($user, array $reqs)
|
||||
{
|
||||
return AuthenticationResponse::newAbstain();
|
||||
}
|
||||
|
||||
public function beginSecondaryAccountCreation( $user, $creator, array $reqs ) {
|
||||
global $wgAutoAddFriendOnInvite, $wgRegisterTrack;
|
||||
public function beginSecondaryAccountCreation($user, $creator, array $reqs)
|
||||
{
|
||||
global $wgAutoAddFriendOnInvite, $wgRegisterTrack;
|
||||
|
||||
$req = AuthenticationRequest::getRequestByClass(
|
||||
$reqs, NewSignupPageAuthenticationRequest::class
|
||||
);
|
||||
$req = AuthenticationRequest::getRequestByClass(
|
||||
$reqs,
|
||||
NewSignupPageAuthenticationRequest::class
|
||||
);
|
||||
|
||||
$referral_user = User::newFromName( $req->referral );
|
||||
$user_id_referral = 0;
|
||||
$referral_user = User::newFromName($req->referral);
|
||||
$user_id_referral = 0;
|
||||
|
||||
if ( $wgAutoAddFriendOnInvite && $referral_user instanceof User ) {
|
||||
$user_id_referral = $referral_user->getId();
|
||||
if ( $user_id_referral ) {
|
||||
// need to create fake request first
|
||||
$rel = new UserRelationship( $referral_user );
|
||||
$request_id = $rel->addRelationshipRequest( $user, 1, '', false );
|
||||
if ($wgAutoAddFriendOnInvite && $referral_user instanceof User) {
|
||||
$user_id_referral = $referral_user->getId();
|
||||
if ($user_id_referral) {
|
||||
// need to create fake request first
|
||||
$rel = new UserRelationship($referral_user);
|
||||
$request_id = $rel->addRelationshipRequest($user, 1, '', false);
|
||||
|
||||
// clear the status
|
||||
$rel->updateRelationshipRequestStatus( $request_id, 1 );
|
||||
// clear the status
|
||||
$rel->updateRelationshipRequestStatus($request_id, 1);
|
||||
|
||||
// automatically add relationships
|
||||
$rel = new UserRelationship( $user );
|
||||
$rel->addRelationship( $request_id, true );
|
||||
// automatically add relationships
|
||||
$rel = new UserRelationship($user);
|
||||
$rel->addRelationship($request_id, true);
|
||||
|
||||
// Update social statistics for both users (so that we don't
|
||||
// show "0 of 0" in the new user's profile when they in fact
|
||||
// do have one friend already!)
|
||||
// @todo FIXME: broken until UserStatsTrack is refactored to support RequestContext
|
||||
// instead of global objects (the global object in incStatField() is _not_
|
||||
// our $user even though by all logic it should be and it was in older versions
|
||||
// of MW)
|
||||
$stats = new UserStatsTrack( $user->getId(), $user->getName() );
|
||||
$stats->updateRelationshipCount( 1 );
|
||||
$stats->incStatField( 'friend' );
|
||||
// Update social statistics for both users (so that we don't
|
||||
// show "0 of 0" in the new user's profile when they in fact
|
||||
// do have one friend already!)
|
||||
// @todo FIXME: broken until UserStatsTrack is refactored to support RequestContext
|
||||
// instead of global objects (the global object in incStatField() is _not_
|
||||
// our $user even though by all logic it should be and it was in older versions
|
||||
// of MW)
|
||||
$stats = new UserStatsTrack($user->getId(), $user->getName());
|
||||
$stats->updateRelationshipCount(1);
|
||||
$stats->incStatField('friend');
|
||||
|
||||
$statsReferringUser = new UserStatsTrack( $user_id_referral, $referral_user->getName() );
|
||||
$statsReferringUser->updateRelationshipCount( 1 );
|
||||
$statsReferringUser->incStatField( 'friend' );
|
||||
}
|
||||
}
|
||||
$statsReferringUser = new UserStatsTrack($user_id_referral, $referral_user->getName());
|
||||
$statsReferringUser->updateRelationshipCount(1);
|
||||
$statsReferringUser->incStatField('friend');
|
||||
}
|
||||
}
|
||||
|
||||
if ( $wgRegisterTrack ) {
|
||||
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
|
||||
$cache->delete( $cache->makeKey( 'users', 'new', '1' ) );
|
||||
if ($wgRegisterTrack) {
|
||||
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
|
||||
$cache->delete($cache->makeKey('users', 'new', '1'));
|
||||
|
||||
// How the user registered (via email from friend, just on the site etc.)?
|
||||
$from = $req->from;
|
||||
if ( !$from ) {
|
||||
$from = 0;
|
||||
}
|
||||
// How the user registered (via email from friend, just on the site etc.)?
|
||||
$from = $req->from;
|
||||
if (!$from) {
|
||||
$from = 0;
|
||||
}
|
||||
|
||||
// Track if the user clicked on email from friend
|
||||
if ( $referral_user instanceof User ) {
|
||||
// Update the social statistics of the referring user (to give
|
||||
// them points, if specified so on the configuration file)
|
||||
$stats = new UserStatsTrack( $referral_user->getId(), $referral_user->getName() );
|
||||
$stats->incStatField( 'referral_complete' );
|
||||
// Track if the user clicked on email from friend
|
||||
if ($referral_user instanceof User) {
|
||||
// Update the social statistics of the referring user (to give
|
||||
// them points, if specified so on the configuration file)
|
||||
$stats = new UserStatsTrack($referral_user->getId(), $referral_user->getName());
|
||||
$stats->incStatField('referral_complete');
|
||||
|
||||
// Add a new site activity event that will show up on the output
|
||||
// of <siteactivity /> at least
|
||||
if ( class_exists( 'UserSystemMessage' ) ) {
|
||||
$m = new UserSystemMessage();
|
||||
// Nees to be forContent because addMessage adds this into a
|
||||
// database table - we don't want to display Japanese text
|
||||
// to English users
|
||||
$message = wfMessage(
|
||||
'newsignuppage-recruited',
|
||||
$user->getUserPage()->getFullURL(),
|
||||
$user->getName()
|
||||
)->parse();
|
||||
$m->addMessage(
|
||||
$referral_user,
|
||||
UserSystemMessage::TYPE_RECRUIT,
|
||||
$message
|
||||
);
|
||||
}
|
||||
}
|
||||
// Add a new site activity event that will show up on the output
|
||||
// of <siteactivity /> at least
|
||||
if (class_exists('UserSystemMessage')) {
|
||||
$m = new UserSystemMessage();
|
||||
// Nees to be forContent because addMessage adds this into a
|
||||
// database table - we don't want to display Japanese text
|
||||
// to English users
|
||||
$message = wfMessage(
|
||||
'newsignuppage-recruited',
|
||||
$user->getUserPage()->getFullURL(),
|
||||
$user->getName()
|
||||
)->parse();
|
||||
$m->addMessage(
|
||||
$referral_user,
|
||||
UserSystemMessage::TYPE_RECRUIT,
|
||||
$message
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Track registration
|
||||
$dbw = wfGetDB( DB_MASTER );
|
||||
$dbw->insert(
|
||||
'user_register_track',
|
||||
[
|
||||
'ur_actor' => $user->getActorId(),
|
||||
'ur_actor_referral' => ( $referral_user instanceof User ? $referral_user->getActorId() : 0 ),
|
||||
'ur_from' => $from,
|
||||
'ur_date' => $dbw->timestamp( date( 'Y-m-d H:i:s' ) )
|
||||
],
|
||||
__METHOD__
|
||||
);
|
||||
}
|
||||
|
||||
return AuthenticationResponse::newPass();
|
||||
}
|
||||
// Track registration
|
||||
$dbw = wfGetDB(DB_MASTER);
|
||||
$dbw->insert(
|
||||
'user_register_track',
|
||||
[
|
||||
'ur_actor' => $user->getActorId(),
|
||||
'ur_actor_referral' => ($referral_user instanceof User ? $referral_user->getActorId() : 0),
|
||||
'ur_from' => $from,
|
||||
'ur_date' => $dbw->timestamp(date('Y-m-d H:i:s'))
|
||||
],
|
||||
__METHOD__
|
||||
);
|
||||
}
|
||||
|
||||
return AuthenticationResponse::newPass();
|
||||
}
|
||||
}
|
||||
|
|
正在加载...
在新工单中引用