<commit_before><?php

class ApiEchoNotifications extends ApiQueryBase {

	public function __construct( $query, $moduleName ) {
		parent::__construct( $query, $moduleName, 'not' );
	}

	public function execute() {
		// To avoid API warning, register the parameter used to bust browser cache
		$this->getMain()->getVal( '_' );

		$user = $this->getUser();
		if ( $user->isAnon() ) {
			$this->dieUsage( 'Login is required', 'login-required' );
		}

		$params = $this->extractRequestParams();
		$prop = $params['prop'];

		/* @deprecated */
		if ( $params['format'] === 'flyout' ) {
			$this->setWarning(
				"notformat=flyout has been deprecated and will be removed soon.\n".
				"Use notformat=model to get the raw data or notformat=special\n".
				"for pre-rendered HTML."
			);
		} elseif ( $params['format'] === 'html' ) {
			$this->setWarning(
				"notformat=html has been deprecated and will be removed soon.\n".
				"Use notformat=special instead."
			);
		}

		if ( $params['noforn'] ) {
			$foreignNotifications = null;
		} else {
			$foreignNotifications = new EchoForeignNotifications( $user );
		}

		$result = array();
		if ( in_array( 'list', $prop ) ) {
			// Group notification results by section
			if ( $params['groupbysection'] ) {
				foreach ( $params['sections'] as $section ) {
					$result[$section] = $this->getSectionPropList(
						$user, $section, $params['filter'], $params['limit'],
						$params[$section . 'continue'], $params['format'], $params[$section . 'unreadfirst']
					);

					if ( $foreignNotifications && $foreignNotifications->getCount( $section ) > 0 ) {
						// insert fake notification for foreign notifications
						$result[$section]['list'][-1] = $this->makeForeignNotification( $user, $params['format'], $foreignNotifications, $section );
					}

					$this->getResult()->setIndexedTagName( $result[$section]['list'], 'notification' );
					// 'index' is built on top of 'list'
					if ( in_array( 'index', $prop ) ) {
						$result[$section]['index'] = $this->getPropIndex( $result[$section]['list'] );
						$this->getResult()->setIndexedTagName( $result[$section]['index'], 'id' );
					}
				}
			} else {
				$attributeManager = EchoAttributeManager::newFromGlobalVars();
				$result = $this->getPropList(
					$user,
					$attributeManager->getUserEnabledEventsbySections( $user, 'web', $params['sections'] ),
					$params['filter'], $params['limit'], $params['continue'], $params['format']
				);

				if ( $foreignNotifications ) {
					// insert fake notifications for foreign notifications
					foreach ( EchoAttributeManager::$sections as $i => $section ) {
						if ( $foreignNotifications->getCount( $section ) > 0 ) {
							$result['list'][-$i-1] = $this->makeForeignNotification( $user, $params['format'], $foreignNotifications, $section );
						}
					}
				}

				$this->getResult()->setIndexedTagName( $result['list'], 'notification' );
				// 'index' is built on top of 'list'
				if ( in_array( 'index', $prop ) ) {
					$result['index'] = $this->getPropIndex( $result['list'] );
					$this->getResult()->setIndexedTagName( $result['index'], 'id' );
				}
			}

			// add API endpoint for each of the wikis where notification data
			// can be queried from
			if ( $foreignNotifications ) {
				$result['sources'] = $foreignNotifications->getApiEndpoints( $foreignNotifications->getWikis() );
			}
		}

		if ( in_array( 'count', $prop ) ) {
			$result = array_merge_recursive(
				$result,
				$this->getPropCount( $user, $params['sections'], $params['groupbysection'], $foreignNotifications )
			);
		}<commit_msg>Don't list foreign notifications for both sections when not using groupbysection<commit_after><?php

class ApiEchoNotifications extends ApiQueryBase {

	public function __construct( $query, $moduleName ) {
		parent::__construct( $query, $moduleName, 'not' );
	}

	public function execute() {
		// To avoid API warning, register the parameter used to bust browser cache
		$this->getMain()->getVal( '_' );

		$user = $this->getUser();
		if ( $user->isAnon() ) {
			$this->dieUsage( 'Login is required', 'login-required' );
		}

		$params = $this->extractRequestParams();
		$prop = $params['prop'];

		/* @deprecated */
		if ( $params['format'] === 'flyout' ) {
			$this->setWarning(
				"notformat=flyout has been deprecated and will be removed soon.\n".
				"Use notformat=model to get the raw data or notformat=special\n".
				"for pre-rendered HTML."
			);
		} elseif ( $params['format'] === 'html' ) {
			$this->setWarning(
				"notformat=html has been deprecated and will be removed soon.\n".
				"Use notformat=special instead."
			);
		}

		if ( $params['noforn'] ) {
			$foreignNotifications = null;
		} else {
			$foreignNotifications = new EchoForeignNotifications( $user );
		}

		$result = array();
		if ( in_array( 'list', $prop ) ) {
			// Group notification results by section
			if ( $params['groupbysection'] ) {
				foreach ( $params['sections'] as $section ) {
					$result[$section] = $this->getSectionPropList(
						$user, $section, $params['filter'], $params['limit'],
						$params[$section . 'continue'], $params['format'], $params[$section . 'unreadfirst']
					);

					if ( $foreignNotifications && $foreignNotifications->getCount( $section ) > 0 ) {
						// insert fake notification for foreign notifications
						$result[$section]['list'][-1] = $this->makeForeignNotification( $user, $params['format'], $foreignNotifications, $section );
					}

					$this->getResult()->setIndexedTagName( $result[$section]['list'], 'notification' );
					// 'index' is built on top of 'list'
					if ( in_array( 'index', $prop ) ) {
						$result[$section]['index'] = $this->getPropIndex( $result[$section]['list'] );
						$this->getResult()->setIndexedTagName( $result[$section]['index'], 'id' );
					}
				}
			} else {
				$attributeManager = EchoAttributeManager::newFromGlobalVars();
				$result = $this->getPropList(
					$user,
					$attributeManager->getUserEnabledEventsbySections( $user, 'web', $params['sections'] ),
					$params['filter'], $params['limit'], $params['continue'], $params['format']
				);

				if ( $foreignNotifications ) {
					// insert fake notifications for foreign notifications
					foreach ( $params['sections'] as $i => $section ) {
						if ( $foreignNotifications->getCount( $section ) > 0 ) {
							$result['list'][-$i-1] = $this->makeForeignNotification( $user, $params['format'], $foreignNotifications, $section );
						}
					}
				}

				$this->getResult()->setIndexedTagName( $result['list'], 'notification' );
				// 'index' is built on top of 'list'
				if ( in_array( 'index', $prop ) ) {
					$result['index'] = $this->getPropIndex( $result['list'] );
					$this->getResult()->setIndexedTagName( $result['index'], 'id' );
				}
			}

			// add API endpoint for each of the wikis where notification data
			// can be queried from
			if ( $foreignNotifications ) {
				$result['sources'] = $foreignNotifications->getApiEndpoints( $foreignNotifications->getWikis() );
			}
		}

		if ( in_array( 'count', $prop ) ) {
			$result = array_merge_recursive(
				$result,
				$this->getPropCount( $user, $params['sections'], $params['groupbysection'], $foreignNotifications )
			);
		}
{'fraction_non_alphanumeric': 0.17609627887674645, 'fraction_numerical': 0.0011066537557061834, 'mean_word_length': 3.7347740667976423, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2349092', 'n_tokens_mistral': 2693, 'n_tokens_neox': 2187, 'n_words': 506}