Skip to content

Commit e2aa8c4

Browse files
Merge commit from fork
1 parent 04a34af commit e2aa8c4

4 files changed

Lines changed: 46 additions & 6 deletions

File tree

extension.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"descriptionmsg": "tableprogresstracking-desc",
88
"license-name": "Apache-2.0",
99
"type": "parserhook",
10-
"version": "1.2.0",
10+
"version": "1.2.1",
1111
"requires": {
1212
"MediaWiki": ">= 1.43.0"
1313
},

includes/Rest/DeleteProgressHandler.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44

55
use MediaWiki\Rest\Response;
66
use MediaWiki\Rest\SimpleHandler;
7+
use MediaWiki\Rest\TokenAwareHandlerTrait;
8+
use MediaWiki\Rest\Validator\Validator;
79
use Telepedia\Extensions\TableProgressTracking\ProgressService;
810
use Wikimedia\ParamValidator\ParamValidator;
911

1012
class DeleteProgressHandler extends SimpleHandler {
1113

14+
use TokenAwareHandlerTrait;
15+
1216
public function __construct(
1317
private readonly ProgressService $progressService
1418
) {
@@ -69,7 +73,22 @@ public function run( int $articleId, int $tableId ): Response {
6973
/**
7074
* @inheritDoc
7175
*/
72-
public function getParamSettings() {
76+
public function needsWriteAccess(): bool {
77+
return true;
78+
}
79+
80+
/**
81+
* @inheritDoc
82+
*/
83+
public function validate( Validator $restValidator ): void {
84+
parent::validate( $restValidator );
85+
$this->validateToken( false );
86+
}
87+
88+
/**
89+
* @inheritDoc
90+
*/
91+
public function getParamSettings(): array {
7392
return [
7493
'articleId' => [
7594
self::PARAM_SOURCE => 'path',
@@ -91,6 +110,6 @@ public function getBodyParamSettings(): array {
91110
ParamValidator::PARAM_TYPE => 'string',
92111
ParamValidator::PARAM_REQUIRED => true,
93112
]
94-
];
113+
] + $this->getTokenParamDefinition();
95114
}
96115
}

includes/Rest/TrackProgressHandler.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44

55
use MediaWiki\Rest\Response;
66
use MediaWiki\Rest\SimpleHandler;
7+
use MediaWiki\Rest\TokenAwareHandlerTrait;
8+
use MediaWiki\Rest\Validator\Validator;
79
use Telepedia\Extensions\TableProgressTracking\ProgressService;
810
use Wikimedia\ParamValidator\ParamValidator;
911

1012
class TrackProgressHandler extends SimpleHandler {
1113

14+
use TokenAwareHandlerTrait;
15+
1216
public function __construct(
1317
private readonly ProgressService $progressService
1418
) {
@@ -69,6 +73,21 @@ public function run( int $articleId, int $tableId ): Response {
6973
return $response;
7074
}
7175

76+
/**
77+
* @inheritDoc
78+
*/
79+
public function needsWriteAccess(): bool {
80+
return true;
81+
}
82+
83+
/**
84+
* @inheritDoc
85+
*/
86+
public function validate( Validator $restValidator ): void {
87+
parent::validate( $restValidator );
88+
$this->validateToken( false );
89+
}
90+
7291
/**
7392
* @inheritDoc
7493
*/
@@ -94,6 +113,6 @@ public function getBodyParamSettings(): array {
94113
ParamValidator::PARAM_TYPE => 'string',
95114
ParamValidator::PARAM_REQUIRED => true,
96115
]
97-
];
116+
] + $this->getTokenParamDefinition();
98117
}
99118
}

resources/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,13 @@ var ProgressTracker = {
182182
try {
183183
if ( checkbox.checked ) {
184184
await api.post( `/progress-tracking/${this.pageId}/${tableId}`, {
185-
entity_id: rowId
185+
entity_id: rowId,
186+
token: mw.user.tokens.get( 'csrfToken' )
186187
} );
187188
} else {
188189
await api.delete( `/progress-tracking/${this.pageId}/${tableId}`, {
189-
entity_id: rowId
190+
entity_id: rowId,
191+
token: mw.user.tokens.get( 'csrfToken' )
190192
} );
191193
}
192194

0 commit comments

Comments
 (0)