| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\Notifications\Api; |
| 4 |
|
| 5 |
use MediaWiki\Api\ApiBase; |
| 6 |
use MediaWiki\Api\ApiQuery; |
| 7 |
use MediaWiki\Api\ApiQueryBase; |
| 8 |
use MediaWiki\Config\Config; |
| 9 |
use MediaWiki\Extension\Notifications\AttributeManager; |
| 10 |
use MediaWiki\Extension\Notifications\Bundler; |
| 11 |
use MediaWiki\Extension\Notifications\Controller\NotificationController; |
| 12 |
use MediaWiki\Extension\Notifications\DataOutputFormatter; |
| 13 |
use MediaWiki\Extension\Notifications\ForeignNotifications; |
| 14 |
use MediaWiki\Extension\Notifications\Mapper\NotificationMapper; |
| 15 |
use MediaWiki\Extension\Notifications\Model\Notification; |
| 16 |
use MediaWiki\Extension\Notifications\NotifUser; |
| 17 |
use MediaWiki\Extension\Notifications\SeenTime; |
| 18 |
use MediaWiki\Extension\Notifications\Services; |
| 19 |
use MediaWiki\Title\Title; |
| 20 |
use MediaWiki\User\User; |
| 21 |
use MediaWiki\User\UserIdentity; |
| 22 |
use MediaWiki\WikiMap\WikiMap; |
| 23 |
use Wikimedia\ParamValidator\ParamValidator; |
| 24 |
use Wikimedia\ParamValidator\TypeDef\IntegerDef; |
| 25 |
|
| 26 |
class ApiEchoNotifications extends ApiQueryBase { |
| 27 |
use ApiCrossWiki; |
| 28 |
use ApiEchoPermissionsTrait; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
protected $crossWikiSummary = false; |
| 34 |
|
| 35 |
|
| 36 |
private $allowedNotifierTypes; |
| 37 |
|
| 38 |
public function __construct( ApiQuery $query, string $moduleName, Config $mainConfig ) { |
| 39 |
parent::__construct( $query, $moduleName, 'not' ); |
| 40 |
$this->allowedNotifierTypes = array_keys( $mainConfig->get( 'EchoNotifiers' ) ); |
| 41 |
} |
| 42 |
|
| 43 |
public function execute() { |
| 44 |
$this->checkReadNotificationsPermissions(); |
| 45 |
|
| 46 |
|
| 47 |
$this->getMain()->getVal( '_' ); |
| 48 |
|
| 49 |
$params = $this->extractRequestParams(); |
| 50 |
|
| 51 |
|
| 52 |
if ( $params['format'] === 'flyout' ) { |
| 53 |
$this->addDeprecation( 'apiwarn-echo-deprecation-flyout', |
| 54 |
'action=query&meta=notifications¬format=flyout' ); |
| 55 |
} elseif ( $params['format'] === 'html' ) { |
| 56 |
$this->addDeprecation( 'apiwarn-echo-deprecation-html', |
| 57 |
'action=query&meta=notifications¬format=html' ); |
| 58 |
} |
| 59 |
|
| 60 |
if ( $this->allowCrossWikiNotifications() ) { |
| 61 |
$this->crossWikiSummary = $params['crosswikisummary']; |
| 62 |
} |
| 63 |
|
| 64 |
$results = []; |
| 65 |
if ( in_array( WikiMap::getCurrentWikiId(), $this->getRequestedWikis() ) ) { |
| 66 |
$results[WikiMap::getCurrentWikiId()] = $this->getLocalNotifications( $params ); |
| 67 |
} |
| 68 |
|
| 69 |
if ( $this->getRequestedForeignWikis() ) { |
| 70 |
$foreignResults = $this->getFromForeign(); |
| 71 |
foreach ( $foreignResults as $wiki => $result ) { |
| 72 |
if ( isset( $result['query']['notifications'] ) ) { |
| 73 |
$results[$wiki] = $result['query']['notifications']; |
| 74 |
} |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
$result = $this->mergeResults( $results, $params ); |
| 80 |
if ( $params['groupbysection'] ) { |
| 81 |
foreach ( $params['sections'] as $section ) { |
| 82 |
if ( in_array( 'list', $params['prop'] ) ) { |
| 83 |
$this->getResult()->setIndexedTagName( $result[$section]['list'], 'notification' ); |
| 84 |
} |
| 85 |
} |
| 86 |
} else { |
| 87 |
if ( in_array( 'list', $params['prop'] ) ) { |
| 88 |
$this->getResult()->setIndexedTagName( $result['list'], 'notification' ); |
| 89 |
} |
| 90 |
} |
| 91 |
$this->getResult()->addValue( 'query', $this->getModuleName(), $result ); |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
protected function getLocalNotifications( array $params ) { |
| 99 |
$user = $this->getUser(); |
| 100 |
$prop = $params['prop']; |
| 101 |
$titles = null; |
| 102 |
if ( $params['titles'] ) { |
| 103 |
$titles = array_values( array_filter( array_map( [ Title::class, 'newFromText' ], $params['titles'] ) ) ); |
| 104 |
if ( in_array( '[]', $params['titles'] ) ) { |
| 105 |
$titles[] = null; |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
$result = []; |
| 110 |
if ( in_array( 'list', $prop ) ) { |
| 111 |
|
| 112 |
if ( $params['groupbysection'] ) { |
| 113 |
foreach ( $params['sections'] as $section ) { |
| 114 |
$result[$section] = $this->getSectionPropList( |
| 115 |
$user, $section, $params['filter'], $params['limit'], |
| 116 |
$params[$section . 'continue'], $params['format'], |
| 117 |
$titles, $params[$section . 'unreadfirst'], $params['bundle'], |
| 118 |
$params['notifiertypes'] |
| 119 |
); |
| 120 |
|
| 121 |
if ( $this->crossWikiSummary ) { |
| 122 |
|
| 123 |
$foreignNotification = $this->makeForeignNotification( $user, $params['format'], $section ); |
| 124 |
if ( $foreignNotification ) { |
| 125 |
array_unshift( $result[$section]['list'], $foreignNotification ); |
| 126 |
} |
| 127 |
} |
| 128 |
} |
| 129 |
} else { |
| 130 |
$attributeManager = Services::getInstance()->getAttributeManager(); |
| 131 |
$result = $this->getPropList( |
| 132 |
$user, |
| 133 |
$attributeManager->getUserEnabledEventsBySections( $user, $params['notifiertypes'], |
| 134 |
$params['sections'] ), |
| 135 |
$params['filter'], $params['limit'], $params['continue'], $params['format'], |
| 136 |
$titles, $params['unreadfirst'], $params['bundle'] |
| 137 |
); |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
$section = count( $params['sections'] ) === 1 |
| 142 |
? reset( $params['sections'] ) |
| 143 |
: AttributeManager::ALL; |
| 144 |
if ( $this->crossWikiSummary ) { |
| 145 |
$foreignNotification = $this->makeForeignNotification( $user, $params['format'], $section ); |
| 146 |
if ( $foreignNotification ) { |
| 147 |
array_unshift( $result['list'], $foreignNotification ); |
| 148 |
} |
| 149 |
} |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
if ( in_array( 'count', $prop ) ) { |
| 154 |
$result = array_merge_recursive( |
| 155 |
$result, |
| 156 |
$this->getPropCount( $user, $params['sections'], $params['groupbysection'] ) |
| 157 |
); |
| 158 |
} |
| 159 |
|
| 160 |
if ( in_array( 'seenTime', $prop ) ) { |
| 161 |
$result = array_merge_recursive( |
| 162 |
$result, |
| 163 |
$this->getPropSeenTime( $user, $params['sections'], $params['groupbysection'] ) |
| 164 |
); |
| 165 |
} |
| 166 |
|
| 167 |
return $result; |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
protected function getSectionPropList( |
| 185 |
User $user, |
| 186 |
$section, |
| 187 |
$filter, |
| 188 |
$limit, |
| 189 |
$continue, |
| 190 |
$format, |
| 191 |
?array $titles = null, |
| 192 |
$unreadFirst = false, |
| 193 |
$bundle = false, |
| 194 |
array $notifierTypes = [ 'web' ] |
| 195 |
) { |
| 196 |
$attributeManager = Services::getInstance()->getAttributeManager(); |
| 197 |
$sectionEvents = $attributeManager->getUserEnabledEventsBySections( $user, $notifierTypes, [ $section ] ); |
| 198 |
|
| 199 |
if ( !$sectionEvents ) { |
| 200 |
$result = [ |
| 201 |
'list' => [], |
| 202 |
'continue' => null |
| 203 |
]; |
| 204 |
} else { |
| 205 |
$result = $this->getPropList( |
| 206 |
$user, $sectionEvents, $filter, $limit, $continue, $format, $titles, $unreadFirst, $bundle |
| 207 |
); |
| 208 |
} |
| 209 |
|
| 210 |
return $result; |
| 211 |
} |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
protected function getPropList( |
| 229 |
User $user, |
| 230 |
array $eventTypes, |
| 231 |
$filter, |
| 232 |
$limit, |
| 233 |
$continue, |
| 234 |
$format, |
| 235 |
?array $titles = null, |
| 236 |
$unreadFirst = false, |
| 237 |
$bundle = false |
| 238 |
) { |
| 239 |
$result = [ |
| 240 |
'list' => [], |
| 241 |
'continue' => null |
| 242 |
]; |
| 243 |
|
| 244 |
$notifMapper = new NotificationMapper(); |
| 245 |
|
| 246 |
|
| 247 |
if ( in_array( 'read', $filter ) && in_array( '!read', $filter ) ) { |
| 248 |
|
| 249 |
if ( $unreadFirst ) { |
| 250 |
|
| 251 |
$notifs = $notifMapper->fetchUnreadByUser( $user, $limit + 1, $continue, $eventTypes, $titles ); |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
if ( $notifs && $continue ) { |
| 268 |
|
| 269 |
$first = reset( $notifs ); |
| 270 |
$continueId = intval( trim( strrchr( $continue, '|' ), '|' ) ); |
| 271 |
if ( $first->getEvent()->getId() !== $continueId ) { |
| 272 |
|
| 273 |
|
| 274 |
$notifs = []; |
| 275 |
} |
| 276 |
} |
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
$count = count( $notifs ); |
| 281 |
|
| 282 |
if ( $count <= $limit ) { |
| 283 |
|
| 284 |
|
| 285 |
$mixedNotifs = $notifMapper->fetchByUser( |
| 286 |
$user, |
| 287 |
$limit - $count + 1, |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
$count > 0 ? null : $continue, |
| 292 |
$eventTypes, |
| 293 |
array_keys( $notifs ), |
| 294 |
$titles |
| 295 |
); |
| 296 |
foreach ( $mixedNotifs as $notif ) { |
| 297 |
$notifs[$notif->getEvent()->getId()] = $notif; |
| 298 |
} |
| 299 |
} |
| 300 |
} else { |
| 301 |
$notifs = $notifMapper->fetchByUser( $user, $limit + 1, $continue, $eventTypes, [], $titles ); |
| 302 |
} |
| 303 |
} elseif ( in_array( 'read', $filter ) ) { |
| 304 |
$notifs = $notifMapper->fetchReadByUser( $user, $limit + 1, $continue, $eventTypes, $titles ); |
| 305 |
} else { |
| 306 |
|
| 307 |
$notifs = $notifMapper->fetchUnreadByUser( $user, $limit + 1, $continue, $eventTypes, $titles ); |
| 308 |
} |
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
$overfetchedItem = count( $notifs ) > $limit ? array_pop( $notifs ) : null; |
| 313 |
|
| 314 |
$bundler = null; |
| 315 |
if ( $bundle ) { |
| 316 |
$bundler = new Bundler(); |
| 317 |
$notifs = $bundler->bundle( $notifs ); |
| 318 |
} |
| 319 |
|
| 320 |
while ( $notifs !== [] ) { |
| 321 |
|
| 322 |
$notif = array_shift( $notifs ); |
| 323 |
$output = DataOutputFormatter::formatOutput( $notif, $format, $user, $this->getLanguage() ); |
| 324 |
if ( $output !== false ) { |
| 325 |
$result['list'][] = $output; |
| 326 |
} elseif ( $bundler && $notif->getBundledNotifications() ) { |
| 327 |
|
| 328 |
|
| 329 |
$notifs = array_merge( $bundler->bundle( $notif->getBundledNotifications() ), $notifs ); |
| 330 |
} |
| 331 |
} |
| 332 |
|
| 333 |
|
| 334 |
if ( $overfetchedItem ) { |
| 335 |
|
| 336 |
$timestamp = wfTimestamp( TS_UNIX, $overfetchedItem->getTimestamp() ); |
| 337 |
$id = $overfetchedItem->getEvent()->getId(); |
| 338 |
$result['continue'] = $timestamp . '|' . $id; |
| 339 |
} |
| 340 |
|
| 341 |
return $result; |
| 342 |
} |
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
protected function getPropCount( UserIdentity $user, array $sections, $groupBySection ) { |
| 352 |
$result = []; |
| 353 |
$notifUser = NotifUser::newFromUser( $user ); |
| 354 |
$global = $this->crossWikiSummary ? 'preference' : false; |
| 355 |
|
| 356 |
$totalRawCount = 0; |
| 357 |
foreach ( $sections as $section ) { |
| 358 |
$rawCount = $notifUser->getNotificationCount( $section, $global ); |
| 359 |
if ( $groupBySection ) { |
| 360 |
$result[$section]['rawcount'] = $rawCount; |
| 361 |
$result[$section]['count'] = NotificationController::formatNotificationCount( $rawCount ); |
| 362 |
} |
| 363 |
$totalRawCount += $rawCount; |
| 364 |
} |
| 365 |
$result['rawcount'] = $totalRawCount; |
| 366 |
$result['count'] = NotificationController::formatNotificationCount( $totalRawCount ); |
| 367 |
|
| 368 |
return $result; |
| 369 |
} |
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
protected function getPropSeenTime( UserIdentity $user, array $sections, $groupBySection ) { |
| 379 |
$result = []; |
| 380 |
$seenTimeHelper = SeenTime::newFromUser( $user ); |
| 381 |
|
| 382 |
if ( $groupBySection ) { |
| 383 |
foreach ( $sections as $section ) { |
| 384 |
$result[$section]['seenTime'] = $seenTimeHelper->getTime( $section, TS_ISO_8601 ); |
| 385 |
} |
| 386 |
} else { |
| 387 |
$result['seenTime'] = []; |
| 388 |
foreach ( $sections as $section ) { |
| 389 |
$result['seenTime'][$section] = $seenTimeHelper->getTime( $section, TS_ISO_8601 ); |
| 390 |
} |
| 391 |
} |
| 392 |
|
| 393 |
return $result; |
| 394 |
} |
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
protected function makeForeignNotification( |
| 404 |
User $user, |
| 405 |
$format, |
| 406 |
$section = AttributeManager::ALL |
| 407 |
) { |
| 408 |
$wikis = $this->getForeignNotifications()->getWikis( $section ); |
| 409 |
$count = $this->getForeignNotifications()->getCount( $section ); |
| 410 |
$maxTimestamp = $this->getForeignNotifications()->getTimestamp( $section ); |
| 411 |
$timestampsByWiki = []; |
| 412 |
foreach ( $wikis as $wiki ) { |
| 413 |
$timestampsByWiki[$wiki] = $this->getForeignNotifications()->getWikiTimestamp( $wiki, $section ); |
| 414 |
} |
| 415 |
|
| 416 |
if ( $count === 0 || $wikis === [] ) { |
| 417 |
return false; |
| 418 |
} |
| 419 |
|
| 420 |
|
| 421 |
usort( $wikis, static function ( $a, $b ) use ( $section, $timestampsByWiki ) { |
| 422 |
return (int)$timestampsByWiki[$b]->getTimestamp( TS_UNIX ) |
| 423 |
- (int)$timestampsByWiki[$a]->getTimestamp( TS_UNIX ); |
| 424 |
} ); |
| 425 |
|
| 426 |
$row = (object)[ |
| 427 |
'event_id' => -1, |
| 428 |
'event_type' => 'foreign', |
| 429 |
'event_variant' => null, |
| 430 |
'event_agent_id' => $user->getId(), |
| 431 |
'event_agent_ip' => null, |
| 432 |
'event_page_id' => null, |
| 433 |
'event_extra' => serialize( [ |
| 434 |
'section' => $section ?: 'all', |
| 435 |
'wikis' => $wikis, |
| 436 |
'count' => $count |
| 437 |
] ), |
| 438 |
'event_deleted' => 0, |
| 439 |
|
| 440 |
'notification_user' => $user->getId(), |
| 441 |
'notification_timestamp' => $maxTimestamp, |
| 442 |
'notification_read_timestamp' => null, |
| 443 |
'notification_bundle_hash' => md5( 'bogus' ), |
| 444 |
]; |
| 445 |
|
| 446 |
|
| 447 |
$notif = Notification::newFromRow( $row ); |
| 448 |
$output = DataOutputFormatter::formatOutput( $notif, $format, $user, $this->getLanguage() ); |
| 449 |
|
| 450 |
|
| 451 |
$output['section'] = $section ?: 'all'; |
| 452 |
$output['count'] = $count; |
| 453 |
$output['sources'] = ForeignNotifications::getApiEndpoints( $wikis ); |
| 454 |
|
| 455 |
foreach ( $output['sources'] as $wiki => &$data ) { |
| 456 |
$data['ts'] = $timestampsByWiki[$wiki]->getTimestamp( TS_ISO_8601 ); |
| 457 |
} |
| 458 |
return $output; |
| 459 |
} |
| 460 |
|
| 461 |
protected function getForeignQueryParams() { |
| 462 |
$params = $this->getRequest()->getValues(); |
| 463 |
|
| 464 |
|
| 465 |
unset( $params['notcrosswikisummary'] ); |
| 466 |
|
| 467 |
return $params; |
| 468 |
} |
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
protected function mergeResults( array $results, array $params ) { |
| 476 |
$primary = array_shift( $results ); |
| 477 |
if ( !$primary ) { |
| 478 |
$primary = []; |
| 479 |
} |
| 480 |
|
| 481 |
if ( in_array( 'list', $params['prop'] ) ) { |
| 482 |
$primary = $this->mergeList( $primary, $results, $params['groupbysection'] ); |
| 483 |
} |
| 484 |
|
| 485 |
if ( in_array( 'count', $params['prop'] ) && !$this->crossWikiSummary ) { |
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
$primary = $this->mergeCount( $primary, $results, $params['groupbysection'] ); |
| 490 |
} |
| 491 |
|
| 492 |
return $primary; |
| 493 |
} |
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
protected function mergeList( array $primary, array $results, $groupBySection ) { |
| 502 |
|
| 503 |
$sort = static function ( $a, $b ) { |
| 504 |
return $a['timestamp']['utcunix'] - $b['timestamp']['utcunix']; |
| 505 |
}; |
| 506 |
|
| 507 |
if ( $groupBySection ) { |
| 508 |
foreach ( AttributeManager::$sections as $section ) { |
| 509 |
if ( !isset( $primary[$section]['list'] ) ) { |
| 510 |
$primary[$section]['list'] = []; |
| 511 |
} |
| 512 |
foreach ( $results as $result ) { |
| 513 |
$primary[$section]['list'] = array_merge( $primary[$section]['list'], $result[$section]['list'] ); |
| 514 |
} |
| 515 |
usort( $primary[$section]['list'], $sort ); |
| 516 |
} |
| 517 |
} else { |
| 518 |
if ( !isset( $primary['list'] ) || !is_array( $primary['list'] ) ) { |
| 519 |
$primary['list'] = []; |
| 520 |
} |
| 521 |
foreach ( $results as $result ) { |
| 522 |
$primary['list'] = array_merge( $primary['list'], $result['list'] ); |
| 523 |
} |
| 524 |
usort( $primary['list'], $sort ); |
| 525 |
} |
| 526 |
|
| 527 |
return $primary; |
| 528 |
} |
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
protected function mergeCount( array $primary, array $results, $groupBySection ) { |
| 537 |
if ( $groupBySection ) { |
| 538 |
foreach ( AttributeManager::$sections as $section ) { |
| 539 |
if ( !isset( $primary[$section]['rawcount'] ) ) { |
| 540 |
$primary[$section]['rawcount'] = 0; |
| 541 |
} |
| 542 |
foreach ( $results as $result ) { |
| 543 |
$primary[$section]['rawcount'] += $result[$section]['rawcount']; |
| 544 |
} |
| 545 |
$primary[$section]['count'] = NotificationController::formatNotificationCount( |
| 546 |
$primary[$section]['rawcount'] ); |
| 547 |
} |
| 548 |
} |
| 549 |
|
| 550 |
if ( !isset( $primary['rawcount'] ) ) { |
| 551 |
$primary['rawcount'] = 0; |
| 552 |
} |
| 553 |
foreach ( $results as $result ) { |
| 554 |
|
| 555 |
$primary['rawcount'] += $result['rawcount']; |
| 556 |
} |
| 557 |
$primary['count'] = NotificationController::formatNotificationCount( $primary['rawcount'] ); |
| 558 |
|
| 559 |
return $primary; |
| 560 |
} |
| 561 |
|
| 562 |
public function getAllowedParams() { |
| 563 |
$sections = AttributeManager::$sections; |
| 564 |
|
| 565 |
$params = $this->getCrossWikiParams() + [ |
| 566 |
'filter' => [ |
| 567 |
ParamValidator::PARAM_ISMULTI => true, |
| 568 |
ParamValidator::PARAM_DEFAULT => 'read|!read', |
| 569 |
ParamValidator::PARAM_TYPE => [ |
| 570 |
'read', |
| 571 |
'!read', |
| 572 |
], |
| 573 |
], |
| 574 |
'prop' => [ |
| 575 |
ParamValidator::PARAM_ISMULTI => true, |
| 576 |
ParamValidator::PARAM_TYPE => [ |
| 577 |
'list', |
| 578 |
'count', |
| 579 |
'seenTime', |
| 580 |
], |
| 581 |
ParamValidator::PARAM_DEFAULT => 'list', |
| 582 |
], |
| 583 |
'sections' => [ |
| 584 |
ParamValidator::PARAM_DEFAULT => implode( '|', $sections ), |
| 585 |
ParamValidator::PARAM_TYPE => $sections, |
| 586 |
ParamValidator::PARAM_ISMULTI => true, |
| 587 |
], |
| 588 |
'groupbysection' => [ |
| 589 |
ParamValidator::PARAM_TYPE => 'boolean', |
| 590 |
ParamValidator::PARAM_DEFAULT => false, |
| 591 |
], |
| 592 |
'format' => [ |
| 593 |
ParamValidator::PARAM_TYPE => [ |
| 594 |
'model', |
| 595 |
'special', |
| 596 |
|
| 597 |
'flyout', |
| 598 |
|
| 599 |
'html', |
| 600 |
], |
| 601 |
ApiBase::PARAM_HELP_MSG_PER_VALUE => [], |
| 602 |
], |
| 603 |
'limit' => [ |
| 604 |
ParamValidator::PARAM_TYPE => 'limit', |
| 605 |
ParamValidator::PARAM_DEFAULT => 20, |
| 606 |
IntegerDef::PARAM_MIN => 1, |
| 607 |
IntegerDef::PARAM_MAX => ApiBase::LIMIT_SML1, |
| 608 |
IntegerDef::PARAM_MAX2 => ApiBase::LIMIT_SML2, |
| 609 |
], |
| 610 |
'continue' => [ |
| 611 |
ApiBase::PARAM_HELP_MSG => 'api-help-param-continue', |
| 612 |
], |
| 613 |
'unreadfirst' => [ |
| 614 |
ParamValidator::PARAM_TYPE => 'boolean', |
| 615 |
ParamValidator::PARAM_DEFAULT => false, |
| 616 |
], |
| 617 |
'titles' => [ |
| 618 |
ParamValidator::PARAM_ISMULTI => true, |
| 619 |
], |
| 620 |
'bundle' => [ |
| 621 |
ParamValidator::PARAM_TYPE => 'boolean', |
| 622 |
ParamValidator::PARAM_DEFAULT => false, |
| 623 |
], |
| 624 |
'notifiertypes' => [ |
| 625 |
ParamValidator::PARAM_TYPE => $this->allowedNotifierTypes, |
| 626 |
ParamValidator::PARAM_ISMULTI => true, |
| 627 |
ParamValidator::PARAM_DEFAULT => 'web', |
| 628 |
], |
| 629 |
]; |
| 630 |
foreach ( $sections as $section ) { |
| 631 |
$params[$section . 'continue'] = null; |
| 632 |
$params[$section . 'unreadfirst'] = [ |
| 633 |
ParamValidator::PARAM_TYPE => 'boolean', |
| 634 |
ParamValidator::PARAM_DEFAULT => false, |
| 635 |
]; |
| 636 |
} |
| 637 |
|
| 638 |
if ( $this->allowCrossWikiNotifications() ) { |
| 639 |
$params += [ |
| 640 |
|
| 641 |
|
| 642 |
'crosswikisummary' => [ |
| 643 |
ParamValidator::PARAM_TYPE => 'boolean', |
| 644 |
ParamValidator::PARAM_DEFAULT => false, |
| 645 |
], |
| 646 |
]; |
| 647 |
} |
| 648 |
|
| 649 |
return $params; |
| 650 |
} |
| 651 |
|
| 652 |
|
| 653 |
protected function getExamplesMessages() { |
| 654 |
return [ |
| 655 |
'action=query&meta=notifications' |
| 656 |
=> 'apihelp-query+notifications-example-1', |
| 657 |
'action=query&meta=notifications¬prop=count¬sections=alert|message¬groupbysection=1' |
| 658 |
=> 'apihelp-query+notifications-example-2', |
| 659 |
'action=query&meta=notifications¬notifiertypes=email' |
| 660 |
=> 'apihelp-query+notifications-example-3', |
| 661 |
]; |
| 662 |
} |
| 663 |
|
| 664 |
public function getHelpUrls() { |
| 665 |
return 'https://www.mediawiki.org/wiki/Special:MyLanguage/Echo_(Notifications)/API'; |
| 666 |
} |
| 667 |
} |