mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/WikiEditor
synced 2024-11-23 15:57:15 +00:00
Use PHP type hints where possible
Also remove the `return true` on onRecentChange_save because this is optional. Change-Id: Ic1104ae901384f3e6699269b761c05a99d2334b3
This commit is contained in:
parent
994d7c7830
commit
6a45353ca2
|
@ -65,24 +65,11 @@ class Hooks implements
|
|||
/** @var string[] */
|
||||
private static $tags = [ 'wikieditor' ];
|
||||
|
||||
/** @var Config */
|
||||
private $config;
|
||||
|
||||
/** @var UserEditTracker */
|
||||
private $userEditTracker;
|
||||
|
||||
/** @var UserOptionsLookup */
|
||||
private $userOptionsLookup;
|
||||
|
||||
/** @var MobileContext|null */
|
||||
private Config $config;
|
||||
private UserEditTracker $userEditTracker;
|
||||
private UserOptionsLookup $userOptionsLookup;
|
||||
private ?MobileContext $mobileContext;
|
||||
|
||||
/**
|
||||
* @param Config $config
|
||||
* @param UserEditTracker $userEditTracker
|
||||
* @param UserOptionsLookup $userOptionsLookup
|
||||
* @param MobileContext|null $mobileContext
|
||||
*/
|
||||
public function __construct(
|
||||
Config $config,
|
||||
UserEditTracker $userEditTracker,
|
||||
|
@ -101,7 +88,7 @@ class Hooks implements
|
|||
* @param string $sessionId
|
||||
* @return bool Whether to sample the session
|
||||
*/
|
||||
protected function inEventSample( $sessionId ) {
|
||||
protected function inEventSample( string $sessionId ): bool {
|
||||
// Sample 6.25%
|
||||
$samplingRate = $this->config->has( 'WMESchemaEditAttemptStepSamplingRate' ) ?
|
||||
$this->config->get( 'WMESchemaEditAttemptStepSamplingRate' ) : 0.0625;
|
||||
|
@ -128,7 +115,11 @@ class Hooks implements
|
|||
* @param array $data Data to log for this action
|
||||
* @return void
|
||||
*/
|
||||
public function doEventLogging( $action, $article, $data = [] ) {
|
||||
public function doEventLogging(
|
||||
string $action,
|
||||
Article $article,
|
||||
array $data = []
|
||||
): void {
|
||||
if ( defined( 'MW_PHPUNIT_TEST' ) ) {
|
||||
return;
|
||||
}
|
||||
|
@ -209,7 +200,12 @@ class Hooks implements
|
|||
* @param string $sessionId Session identifier
|
||||
* @return bool Whether the event was logged or not.
|
||||
*/
|
||||
public function doVisualEditorFeatureUseLogging( $feature, $action, $article, $sessionId ) {
|
||||
public function doVisualEditorFeatureUseLogging(
|
||||
string $feature,
|
||||
string $action,
|
||||
Article $article,
|
||||
string $sessionId
|
||||
): bool {
|
||||
$extensionRegistry = ExtensionRegistry::getInstance();
|
||||
if ( !$extensionRegistry->isLoaded( 'EventLogging' ) || !$extensionRegistry->isLoaded( 'WikimediaEvents' ) ) {
|
||||
return false;
|
||||
|
@ -387,7 +383,7 @@ class Hooks implements
|
|||
* @param Config $config
|
||||
* @return array
|
||||
*/
|
||||
public static function getModuleData( RL\Context $context, Config $config ) {
|
||||
public static function getModuleData( RL\Context $context, Config $config ): array {
|
||||
return [
|
||||
// expose magic words for use by the wikieditor toolbar
|
||||
'magicWords' => self::getMagicWords(),
|
||||
|
@ -402,7 +398,7 @@ class Hooks implements
|
|||
* @param Config $config
|
||||
* @return array
|
||||
*/
|
||||
public static function getModuleDataSummary( RL\Context $context, Config $config ) {
|
||||
public static function getModuleDataSummary( RL\Context $context, Config $config ): array {
|
||||
return [
|
||||
'magicWords' => self::getMagicWords(),
|
||||
'signature' => self::getSignatureMessage( $context, true ),
|
||||
|
@ -416,7 +412,7 @@ class Hooks implements
|
|||
* @param bool $raw
|
||||
* @return string
|
||||
*/
|
||||
private static function getSignatureMessage( MessageLocalizer $ml, $raw = false ) {
|
||||
private static function getSignatureMessage( MessageLocalizer $ml, bool $raw = false ): string {
|
||||
$msg = $ml->msg( 'sig-text' )->params( '~~~~' )->inContentLanguage();
|
||||
return $raw ? $msg->plain() : $msg->text();
|
||||
}
|
||||
|
@ -425,7 +421,7 @@ class Hooks implements
|
|||
* Expose useful magic words which are used by the wikieditor toolbar
|
||||
* @return string[][]
|
||||
*/
|
||||
private static function getMagicWords() {
|
||||
private static function getMagicWords(): array {
|
||||
$requiredMagicWords = [
|
||||
'redirect',
|
||||
'img_alt',
|
||||
|
@ -450,7 +446,7 @@ class Hooks implements
|
|||
* @param WebRequest $request
|
||||
* @return string
|
||||
*/
|
||||
private static function getEditingStatsId( WebRequest $request ) {
|
||||
private static function getEditingStatsId( WebRequest $request ): string {
|
||||
$fromRequest = $request->getRawVal( 'editingStatsId' );
|
||||
if ( $fromRequest !== null ) {
|
||||
return $fromRequest;
|
||||
|
@ -585,7 +581,7 @@ class Hooks implements
|
|||
/**
|
||||
* @param string[] &$tags
|
||||
*/
|
||||
protected function registerTags( &$tags ) {
|
||||
protected function registerTags( array &$tags ): void {
|
||||
$tags = array_merge( $tags, static::$tags );
|
||||
}
|
||||
|
||||
|
@ -598,6 +594,5 @@ class Hooks implements
|
|||
if ( $request->getRawVal( 'wikieditorUsed' ) === 'yes' ) {
|
||||
$recentChange->addTags( 'wikieditor' );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue