X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiQueryTags.php;h=1b154faecbb924864dafdd8ec3491f47111f046d;hb=c05926bc7ce57cbea42e90053ef799fa58b9da1e;hp=43eb7e806640fc9cb797c4a12f4448fdc627816a;hpb=86448ece43db70f21d591b7d0ce52447664a2600;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQueryTags.php b/includes/api/ApiQueryTags.php index 43eb7e8066..1b154faecb 100644 --- a/includes/api/ApiQueryTags.php +++ b/includes/api/ApiQueryTags.php @@ -53,37 +53,24 @@ class ApiQueryTags extends ApiQueryBase { $softwareDefinedTags = array_fill_keys( ChangeTags::listSoftwareDefinedTags(), 0 ); $explicitlyDefinedTags = array_fill_keys( ChangeTags::listExplicitlyDefinedTags(), 0 ); $softwareActivatedTags = array_fill_keys( ChangeTags::listSoftwareActivatedTags(), 0 ); + $tagStats = ChangeTags::tagUsageStatistics(); - $definedTags = array_merge( $softwareDefinedTags, $explicitlyDefinedTags ); + $tagHitcounts = array_merge( $softwareDefinedTags, $explicitlyDefinedTags, $tagStats ); + $tags = array_keys( $tagHitcounts ); # Fetch defined tags that aren't past the continuation if ( $params['continue'] !== null ) { $cont = $params['continue']; - $tags = array_filter( array_keys( $definedTags ), function ( $v ) use ( $cont ) { + $tags = array_filter( $tags, function ( $v ) use ( $cont ) { return $v >= $cont; } ); - $tags = array_fill_keys( $tags, 0 ); - } else { - $tags = $definedTags; - } - - # Merge in all used tags - $this->addTables( 'change_tag' ); - $this->addFields( 'ct_tag' ); - $this->addFields( [ 'hitcount' => $fld_hitcount ? 'COUNT(*)' : '0' ] ); - $this->addOption( 'LIMIT', $limit + 1 ); - $this->addOption( 'GROUP BY', 'ct_tag' ); - $this->addWhereRange( 'ct_tag', 'newer', $params['continue'], null ); - $res = $this->select( __METHOD__ ); - foreach ( $res as $row ) { - $tags[$row->ct_tag] = (int)$row->hitcount; } # Now make sure the array is sorted for proper continuation - ksort( $tags ); + sort( $tags ); $count = 0; - foreach ( $tags as $tagName => $hitcount ) { + foreach ( $tags as $tagName ) { if ( ++$count > $limit ) { $this->setContinueEnumParameter( 'continue', $tagName ); break; @@ -102,7 +89,7 @@ class ApiQueryTags extends ApiQueryBase { } if ( $fld_hitcount ) { - $tag['hitcount'] = $hitcount; + $tag['hitcount'] = intval( $tagHitcounts[$tagName] ); } $isSoftware = isset( $softwareDefinedTags[$tagName] ); @@ -178,6 +165,6 @@ class ApiQueryTags extends ApiQueryBase { } public function getHelpUrls() { - return 'https://www.mediawiki.org/wiki/API:Tags'; + return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Tags'; } }