<commit_before><?php
/**
 *
 * @license MIT
 * @file
 *
 * @author <NAME>
 * @author <NAME>
 */

namespace Kartographer;

use ApiBase;
use FormatJson;
use Parser;
use ParserOptions;
use stdClass;
use Title;

/**
 * This class implements action=sanitize-mapdata API, validating and sanitizing user-entered
 * GeoJSON.
 * @package Kartographer
 */
class ApiSanitizeMapData extends ApiBase {

	public function execute() {
		$params = $this->extractRequestParams();

		$title = Title::newFromText( $params['title'] );

		if ( !$title ) {
			if ( is_callable( [ $this, 'dieWithError' ] ) ) {
				$this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $params['title'] ) ] );
			} else {
				$this->dieUsage( 'Invalid title given', 'invalidtitle' );
			}
		}

		if ( is_callable( [ $this, 'checkTitleUserPermissions' ] ) ) {
			$this->checkTitleUserPermissions( $title, 'read' );
		} else {
			if ( !$title->userCan( 'read', $this->getUser() ) ) {
				$this->dieUsage( "You don't have permission to view this page", 'permissiondenied' );
			}
		}

		$this->sanitizeJson( $title, $params['text'] );
	}

	private function sanitizeJson( Title $title, $text ) {
		/** @var Parser $wgParser */
		global $wgParser;

		$parser = $wgParser->getFreshParser();
		$parserOptions = new ParserOptions( $this->getUser() );
		$parser->startExternalParse( $title, $parserOptions, Parser::OT_HTML );
		$parser->setTitle( $title );
		$parser->clearState();
		$simpleStyle = new SimpleStyleParser( $parser, null );<commit_msg>Remove deprecated dieUsage methods<commit_after><?php
/**
 *
 * @license MIT
 * @file
 *
 * @author <NAME>
 * @author <NAME>
 */

namespace Kartographer;

use ApiBase;
use FormatJson;
use Parser;
use ParserOptions;
use stdClass;
use Title;

/**
 * This class implements action=sanitize-mapdata API, validating and sanitizing user-entered
 * GeoJSON.
 * @package Kartographer
 */
class ApiSanitizeMapData extends ApiBase {

	public function execute() {
		$params = $this->extractRequestParams();

		$title = Title::newFromText( $params['title'] );

		if ( !$title ) {
			$this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $params['title'] ) ] );
		}

		$this->checkTitleUserPermissions( $title, 'read' );

		$this->sanitizeJson( $title, $params['text'] );
	}

	private function sanitizeJson( Title $title, $text ) {
		/** @var Parser $wgParser */
		global $wgParser;

		$parser = $wgParser->getFreshParser();
		$parserOptions = new ParserOptions( $this->getUser() );
		$parser->startExternalParse( $title, $parserOptions, Parser::OT_HTML );
		$parser->setTitle( $title );
		$parser->clearState();
		$simpleStyle = new SimpleStyleParser( $parser, null );
{'fraction_non_alphanumeric': 0.1623740201567749, 'fraction_numerical': 0.0, 'mean_word_length': 4.436105476673428, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 29, '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': '2990589', 'n_tokens_mistral': 958, 'n_tokens_neox': 891, 'n_words': 206}