match( $this->getRequest()->getIP() ) ) { $this->dieWithError( 'apierror-linter-invalid-ip', 'invalid-ip' ); } $params = $this->extractRequestParams(); $data = FormatJson::decode( $params['data'], true ); if ( !is_array( $data ) ) { $this->dieWithError( 'apierror-linter-invalid-data', 'invalid-data' ); } $errors = []; $title = Title::newFromText( $params['page'] ); if ( !$title || !$title->getArticleID() || $title->getLatestRevID() != $params['revision'] ) { $this->dieWithError( 'apierror-linter-invalid-title', 'invalid-title' ); } $categoryMgr = new CategoryManager(); $catCounts = []; foreach ( $data as $info ) { if ( !$categoryMgr->isKnownCategory( $info['type'] ) ) { continue; } $count = $catCounts[$info['type']] ?? 0; if ( $count > Database::MAX_PER_CAT ) { // Drop continue; } $catCounts[$info['type']] = $count + 1; if ( !isset( $info['dsr'] ) ) { LoggerFactory::getInstance( 'Linter' )->warning( 'dsr for {page} @ rev {revid}, for lint: {lint} is missing', [ 'page' => $params['page'], 'revid' => $params['revision'], 'lint' => $info['type'], ] ); continue; } $info['location'] = array_slice( $info['dsr'], 0, 2 ); if ( isset( $info['templateInfo'] ) && $info['templateInfo'] ) { $info['params']['templateInfo'] = $info['templateInfo']; } $errors[] = $info; } $job = new RecordLintJob( $title, [ 'errors' => $errors, 'revision' => $params['revision'], ] ); JobQueueGroup::singleton()->push( $job ); $this->getResult()->addValue( $this->getModuleName(), 'success', true ); } public function isInternal() { return true; } public function getAllowedParams() { return [ 'data' => [ ApiBase::PARAM_TYPE => 'string', ApiBase::PARAM_REQUIRED => true, ], 'page' => [ ApiBase::PARAM_TYPE => 'string', ApiBase::PARAM_REQUIRED => true, ], 'revision' => [ ApiBase::PARAM_TYPE => 'integer', ApiBase::PARAM_REQUIRED => true, ], ]; } }