format lint for PHPs

Signed-off-by: WaitSpring <me@waitspring.com>
这个提交包含在:
WaitSpring 2023-04-13 22:58:29 +08:00
父节点 5459b56dad
当前提交 d3f526c596
共有 3 个文件被更改,包括 232 次插入220 次删除

查看文件

@ -1,4 +1,5 @@
<?php <?php
/** /**
* NewSignupPage extension for MediaWiki -- enhances the default signup form * NewSignupPage extension for MediaWiki -- enhances the default signup form
* *
@ -9,53 +10,54 @@
* @copyright Copyright © 2022- Qiuwen Baike Contributors * @copyright Copyright © 2022- Qiuwen Baike Contributors
* @license GPL-2.0-or-later * @license GPL-2.0-or-later
*/ */
class NewSignupPage { class NewSignupPage
{
/** /**
* Add the JavaScript file to the page output on the signup page. * Add the JavaScript file to the page output on the signup page.
* *
* @param OutputPage &$out * @param OutputPage &$out
* @param Skin &$skin * @param Skin &$skin
*/ */
public static function onBeforePageDisplay( &$out, &$skin ) { public static function onBeforePageDisplay(&$out, &$skin)
$title = $out->getTitle(); {
$title = $out->getTitle();
// Only do our magic if we're on the signup page or login page // 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+) // It's called Special:CreateAccount or Special:UserLogin since AuthManager (MW 1.27+)
// Warning: Userlogin should be all lowercased! // Warning: Userlogin should be all lowercased!
if ( $title->isSpecial( 'CreateAccount' ) || $title->isSpecial( 'Userlogin' ) ) { if ($title->isSpecial('CreateAccount') || $title->isSpecial('Userlogin')) {
$out->addModules( ['ext.newsignuppage'] ); $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;
/** $db = $updater->getDB();
* 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(); 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 ) { $dir = __DIR__ . '/../sql';
// Table doesn't exist and shouldn't either -> bail out $dbType = $db->getType();
return true; $file = $dir . '/user_register_track.sql';
} if ($dbType === 'postgres') {
$file = $dir . '/user_register_track.postgres.sql';
$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 );
}
$updater->addExtensionTable('user_register_track', $file);
}
} }

查看文件

@ -7,71 +7,75 @@ use MediaWiki\Auth\AuthenticationRequest;
* @since MediaWiki 1.27 * @since MediaWiki 1.27
* @phan-file-suppress PhanTypeMismatchReturn It appears that phan seems to hate the retval of getFieldInfo()... * @phan-file-suppress PhanTypeMismatchReturn It appears that phan seems to hate the retval of getFieldInfo()...
*/ */
class NewSignupPageAuthenticationRequest extends AuthenticationRequest { class NewSignupPageAuthenticationRequest extends AuthenticationRequest
public $required = self::REQUIRED; // only ToS check is mandatory {
public $required = self::REQUIRED; // only ToS check is mandatory
/** /**
* @var int Email invitation source identifier to be stored in the * @var int Email invitation source identifier to be stored in the
* user_email_track table * user_email_track table
* @see /extensions/MiniInvite/includes/UserEmailTrack.class.php for details * @see /extensions/MiniInvite/includes/UserEmailTrack.class.php for details
*/ */
public $from; public $from;
/** /**
* @var string|int Username of the person who referred the user creating an * @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 * 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 * also automatically friend them and the new user if that configuration
* setting is enabled * setting is enabled
*/ */
public $referral; public $referral;
/** /**
* @var bool Was the "I agree to the terms of service" * @var bool Was the "I agree to the terms of service"
* checkbox checked? It must be in order for the account creation process * checkbox checked? It must be in order for the account creation process
* to continue. * to continue.
*/ */
public $wpTermsOfService; public $wpTermsOfService;
/** @var WebRequest */ /** @var WebRequest */
public $request; public $request;
/** /**
* @param WebRequest $request * @param WebRequest $request
*/ */
public function __construct( $request ) { public function __construct($request)
$this->request = $request; {
} $this->request = $request;
}
/** @inheritDoc */ /** @inheritDoc */
public function getFieldInfo() { public function getFieldInfo()
global $wgNewSignupPageToSURL, $wgNewSignupPagePPURL; {
return [ global $wgNewSignupPageToSURL, $wgNewSignupPagePPURL;
'from' => [ return [
'type' => 'hidden', 'from' => [
'optional' => true, 'type' => 'hidden',
'value' => $this->request->getInt( 'from' ) 'optional' => true,
], 'value' => $this->request->getInt('from')
'referral' => [ ],
'type' => 'hidden', 'referral' => [
'optional' => true, 'type' => 'hidden',
'value' => $this->request->getVal( 'referral' ) 'optional' => true,
], 'value' => $this->request->getVal('referral')
'wpTermsOfService' => [ ],
'type' => 'checkbox', 'wpTermsOfService' => [
'label' => wfMessage( 'type' => 'checkbox',
'newsignuppage-loginform-tos', 'label' => wfMessage(
$wgNewSignupPageToSURL, 'newsignuppage-loginform-tos',
$wgNewSignupPagePPURL $wgNewSignupPageToSURL,
) $wgNewSignupPagePPURL
] )
]; ]
} ];
}
/** @inheritDoc */ /** @inheritDoc */
public function loadFromSubmission( array $data ) { public function loadFromSubmission(array $data)
// We always want to use this request, so ignore parent's return value. {
parent::loadFromSubmission( $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 * @license GPL-2.0-or-later
* @note Uses GPL-licensed code from LoginReg extension (in beginSecondaryAccountCreation()) * @note Uses GPL-licensed code from LoginReg extension (in beginSecondaryAccountCreation())
*/ */
class NewSignupPageSecondaryAuthenticationProvider extends AbstractSecondaryAuthenticationProvider { class NewSignupPageSecondaryAuthenticationProvider extends AbstractSecondaryAuthenticationProvider
{
/** /**
* @param array $params * @param array $params
*/ */
public function __construct( $params = [] ) { public function __construct($params = [])
} {
}
/** /**
* Abort the creation of the new account if the user hasn't checked the * 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 * "I agree to the terms of service" checkbox and they aren't allowed to
* bypass that check. * bypass that check.
* *
* @param User $user * @param User $user
* @param User $creator * @param User $creator
* @param array $reqs * @param array $reqs
* @return StatusValue * @return StatusValue
*/ */
public function testForAccountCreation( $user, $creator, array $reqs ) { public function testForAccountCreation($user, $creator, array $reqs)
$req = AuthenticationRequest::getRequestByClass( $reqs, NewSignupPageAuthenticationRequest::class ); {
if ( $req = AuthenticationRequest::getRequestByClass($reqs, NewSignupPageAuthenticationRequest::class);
$req && $req->wpTermsOfService || if (
$creator->isAllowed( 'bypasstoscheck' ) $req && $req->wpTermsOfService ||
) { $creator->isAllowed('bypasstoscheck')
return StatusValue::newGood(); ) {
} else { return StatusValue::newGood();
return StatusValue::newFatal( 'newsignuppage-must-accept-tos' ); } else {
} return StatusValue::newFatal('newsignuppage-must-accept-tos');
} }
}
public function getAuthenticationRequests( $action, array $options ) { public function getAuthenticationRequests($action, array $options)
if ( $action === AuthManager::ACTION_CREATE || $action === AuthManager::ACTION_LOGIN ) { {
return [ new NewSignupPageAuthenticationRequest( if ($action === AuthManager::ACTION_CREATE || $action === AuthManager::ACTION_LOGIN) {
$this->manager->getRequest() return [new NewSignupPageAuthenticationRequest(
) ]; $this->manager->getRequest()
} )];
}
return []; return [];
} }
public function beginSecondaryAuthentication( $user, array $reqs ) { public function beginSecondaryAuthentication($user, array $reqs)
return AuthenticationResponse::newAbstain(); {
} return AuthenticationResponse::newAbstain();
}
public function beginSecondaryAccountCreation( $user, $creator, array $reqs ) { public function beginSecondaryAccountCreation($user, $creator, array $reqs)
global $wgAutoAddFriendOnInvite, $wgRegisterTrack; {
global $wgAutoAddFriendOnInvite, $wgRegisterTrack;
$req = AuthenticationRequest::getRequestByClass( $req = AuthenticationRequest::getRequestByClass(
$reqs, NewSignupPageAuthenticationRequest::class $reqs,
); NewSignupPageAuthenticationRequest::class
);
$referral_user = User::newFromName( $req->referral ); $referral_user = User::newFromName($req->referral);
$user_id_referral = 0; $user_id_referral = 0;
if ( $wgAutoAddFriendOnInvite && $referral_user instanceof User ) { if ($wgAutoAddFriendOnInvite && $referral_user instanceof User) {
$user_id_referral = $referral_user->getId(); $user_id_referral = $referral_user->getId();
if ( $user_id_referral ) { if ($user_id_referral) {
// need to create fake request first // need to create fake request first
$rel = new UserRelationship( $referral_user ); $rel = new UserRelationship($referral_user);
$request_id = $rel->addRelationshipRequest( $user, 1, '', false ); $request_id = $rel->addRelationshipRequest($user, 1, '', false);
// clear the status // clear the status
$rel->updateRelationshipRequestStatus( $request_id, 1 ); $rel->updateRelationshipRequestStatus($request_id, 1);
// automatically add relationships // automatically add relationships
$rel = new UserRelationship( $user ); $rel = new UserRelationship($user);
$rel->addRelationship( $request_id, true ); $rel->addRelationship($request_id, true);
// Update social statistics for both users (so that we don't // 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 // show "0 of 0" in the new user's profile when they in fact
// do have one friend already!) // do have one friend already!)
// @todo FIXME: broken until UserStatsTrack is refactored to support RequestContext // @todo FIXME: broken until UserStatsTrack is refactored to support RequestContext
// instead of global objects (the global object in incStatField() is _not_ // 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 // our $user even though by all logic it should be and it was in older versions
// of MW) // of MW)
$stats = new UserStatsTrack( $user->getId(), $user->getName() ); $stats = new UserStatsTrack($user->getId(), $user->getName());
$stats->updateRelationshipCount( 1 ); $stats->updateRelationshipCount(1);
$stats->incStatField( 'friend' ); $stats->incStatField('friend');
$statsReferringUser = new UserStatsTrack( $user_id_referral, $referral_user->getName() ); $statsReferringUser = new UserStatsTrack($user_id_referral, $referral_user->getName());
$statsReferringUser->updateRelationshipCount( 1 ); $statsReferringUser->updateRelationshipCount(1);
$statsReferringUser->incStatField( 'friend' ); $statsReferringUser->incStatField('friend');
} }
} }
if ( $wgRegisterTrack ) { if ($wgRegisterTrack) {
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
$cache->delete( $cache->makeKey( 'users', 'new', '1' ) ); $cache->delete($cache->makeKey('users', 'new', '1'));
// How the user registered (via email from friend, just on the site etc.)? // How the user registered (via email from friend, just on the site etc.)?
$from = $req->from; $from = $req->from;
if ( !$from ) { if (!$from) {
$from = 0; $from = 0;
} }
// Track if the user clicked on email from friend // Track if the user clicked on email from friend
if ( $referral_user instanceof User ) { if ($referral_user instanceof User) {
// Update the social statistics of the referring user (to give // Update the social statistics of the referring user (to give
// them points, if specified so on the configuration file) // them points, if specified so on the configuration file)
$stats = new UserStatsTrack( $referral_user->getId(), $referral_user->getName() ); $stats = new UserStatsTrack($referral_user->getId(), $referral_user->getName());
$stats->incStatField( 'referral_complete' ); $stats->incStatField('referral_complete');
// Add a new site activity event that will show up on the output // Add a new site activity event that will show up on the output
// of <siteactivity /> at least // of <siteactivity /> at least
if ( class_exists( 'UserSystemMessage' ) ) { if (class_exists('UserSystemMessage')) {
$m = new UserSystemMessage(); $m = new UserSystemMessage();
// Nees to be forContent because addMessage adds this into a // Nees to be forContent because addMessage adds this into a
// database table - we don't want to display Japanese text // database table - we don't want to display Japanese text
// to English users // to English users
$message = wfMessage( $message = wfMessage(
'newsignuppage-recruited', 'newsignuppage-recruited',
$user->getUserPage()->getFullURL(), $user->getUserPage()->getFullURL(),
$user->getName() $user->getName()
)->parse(); )->parse();
$m->addMessage( $m->addMessage(
$referral_user, $referral_user,
UserSystemMessage::TYPE_RECRUIT, UserSystemMessage::TYPE_RECRUIT,
$message $message
); );
} }
} }
// Track registration // Track registration
$dbw = wfGetDB( DB_MASTER ); $dbw = wfGetDB(DB_MASTER);
$dbw->insert( $dbw->insert(
'user_register_track', 'user_register_track',
[ [
'ur_actor' => $user->getActorId(), 'ur_actor' => $user->getActorId(),
'ur_actor_referral' => ( $referral_user instanceof User ? $referral_user->getActorId() : 0 ), 'ur_actor_referral' => ($referral_user instanceof User ? $referral_user->getActorId() : 0),
'ur_from' => $from, 'ur_from' => $from,
'ur_date' => $dbw->timestamp( date( 'Y-m-d H:i:s' ) ) 'ur_date' => $dbw->timestamp(date('Y-m-d H:i:s'))
], ],
__METHOD__ __METHOD__
); );
} }
return AuthenticationResponse::newPass();
}
return AuthenticationResponse::newPass();
}
} }