extractRequestParams(); $categoryMgr = new CategoryManager(); $this->requireMaxOneParameter( $params, 'pageid', 'title' ); $this->requireMaxOneParameter( $params, 'namespace', 'title' ); $this->addTables( 'linter' ); $this->addWhereFld( 'linter_cat', array_values( $categoryMgr->getCategoryIds( $params['categories'] ) ) ); $db = $this->getDB(); if ( $params['from'] !== null ) { $this->addWhere( 'linter_id >= ' . $db->addQuotes( $params['from'] ) ); } if ( $params['pageid'] !== null ) { // This can be an array or a single pageid $this->addWhereFld( 'linter_page', $params['pageid'] ); } if ( $params['namespace'] !== null ) { $this->addWhereFld( 'page_namespace', $params['namespace'] ); } if ( $params['title'] !== null ) { $title = $this->getTitleFromTitleOrPageId( [ 'title' => $params['title'] ] ); $this->addWhereFld( 'page_namespace', $title->getNamespace() ); $this->addWhereFld( 'page_title', $title->getDBkey() ); } $this->addTables( 'page' ); $this->addJoinConds( [ 'page' => [ 'INNER JOIN', 'page_id=linter_page' ] ] ); $this->addFields( [ 'linter_id', 'linter_cat', 'linter_params', 'linter_start', 'linter_end', 'page_namespace', 'page_title', ] ); // Be explicit about ORDER BY $this->addOption( 'ORDER BY', 'linter_id' ); // Add +1 to limit to know if there's another row for continuation $this->addOption( 'LIMIT', $params['limit'] + 1 ); $rows = $this->select( __METHOD__ ); $result = $this->getResult(); $count = 0; foreach ( $rows as $row ) { $lintError = Database::makeLintError( $row ); if ( !$lintError ) { continue; } $count++; if ( $count > $params['limit'] ) { $this->setContinueEnumParameter( 'from', $lintError->lintId ); break; } $title = Title::makeTitle( $row->page_namespace, $row->page_title ); $data = [ 'pageid' => $title->getArticleID(), 'ns' => $title->getNamespace(), 'title' => $title->getPrefixedText(), 'lintId' => $lintError->lintId, 'category' => $lintError->category, 'location' => $lintError->location, 'templateInfo' => $lintError->templateInfo, 'params' => $lintError->getExtraParams(), ]; // template info and params are an object $data['params'][ApiResult::META_TYPE] = 'assoc'; $data['templateInfo'][ApiResult::META_TYPE] = 'assoc'; $fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $data ); if ( !$fit ) { $this->setContinueEnumParameter( 'from', $lintError->lintId ); break; } } } public function getAllowedParams() { $visibleCats = ( new CategoryManager() )->getVisibleCategories(); return [ 'categories' => [ ApiBase::PARAM_TYPE => $visibleCats, ApiBase::PARAM_ISMULTI => true, // Default is to show all categories ApiBase::PARAM_DFLT => implode( '|', $visibleCats ), ], 'limit' => [ ApiBase::PARAM_DFLT => 10, ApiBase::PARAM_TYPE => 'limit', ApiBase::PARAM_MIN => 1, ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1, ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2 ], 'namespace' => [ ApiBase::PARAM_TYPE => 'namespace', ApiBase::PARAM_ISMULTI => true, ], 'pageid' => [ ApiBase::PARAM_TYPE => 'integer', ApiBase::PARAM_ISMULTI => true, ], 'title' => [ ApiBase::PARAM_TYPE => 'string', ], 'from' => [ ApiBase::PARAM_TYPE => 'integer', ], ]; } public function getExamplesMessages() { return [ 'action=query&list=linterrors&lntcategories=obsolete-tag' => 'apihelp-query+linterrors-example-1', ]; } }