Cast API timeSpentBackend to an int
[lhc/web/wiklou.git] / includes / api / ApiQueryAllLinks.php
index 903dee4..ac90605 100644 (file)
  */
 class ApiQueryAllLinks extends ApiQueryGeneratorBase {
 
-       private $table, $tablePrefix, $indexTag,
-               $description, $descriptionWhat, $descriptionTargets, $descriptionLinking;
+       private $table, $tablePrefix, $indexTag;
        private $fieldTitle = 'title';
        private $dfltNamespace = NS_MAIN;
        private $hasNamespace = true;
        private $useIndex = null;
-       private $props = array(), $propHelp = array();
+       private $props = [];
 
        public function __construct( ApiQuery $query, $moduleName ) {
                switch ( $moduleName ) {
@@ -47,10 +46,6 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
                                $this->tablePrefix = 'pl_';
                                $this->useIndex = 'pl_namespace';
                                $this->indexTag = 'l';
-                               $this->description = 'Enumerate all links that point to a given namespace';
-                               $this->descriptionWhat = 'link';
-                               $this->descriptionTargets = 'linked titles';
-                               $this->descriptionLinking = 'linking';
                                break;
                        case 'alltransclusions':
                                $prefix = 'at';
@@ -59,11 +54,6 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
                                $this->dfltNamespace = NS_TEMPLATE;
                                $this->useIndex = 'tl_namespace';
                                $this->indexTag = 't';
-                               $this->description =
-                                       'List all transclusions (pages embedded using {{x}}), including non-existing';
-                               $this->descriptionWhat = 'transclusion';
-                               $this->descriptionTargets = 'transcluded titles';
-                               $this->descriptionLinking = 'transcluding';
                                break;
                        case 'allfileusages':
                                $prefix = 'af';
@@ -73,28 +63,16 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
                                $this->dfltNamespace = NS_FILE;
                                $this->hasNamespace = false;
                                $this->indexTag = 'f';
-                               $this->description = 'List all file usages, including non-existing';
-                               $this->descriptionWhat = 'file';
-                               $this->descriptionTargets = 'file titles';
-                               $this->descriptionLinking = 'using';
                                break;
                        case 'allredirects':
                                $prefix = 'ar';
                                $this->table = 'redirect';
                                $this->tablePrefix = 'rd_';
                                $this->indexTag = 'r';
-                               $this->description = 'List all redirects to a namespace';
-                               $this->descriptionWhat = 'redirect';
-                               $this->descriptionTargets = 'target pages';
-                               $this->descriptionLinking = 'redirecting';
-                               $this->props = array(
+                               $this->props = [
                                        'fragment' => 'rd_fragment',
                                        'interwiki' => 'rd_interwiki',
-                               );
-                               $this->propHelp = array(
-                                       ' fragment - Adds the fragment from the redirect, if any',
-                                       ' interwiki - Adds the interwiki prefix from the redirect, if any',
-                               );
+                               ];
                                break;
                        default:
                                ApiBase::dieDebug( __METHOD__, 'Unknown module name' );
@@ -135,11 +113,11 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
                }
 
                if ( $params['unique'] ) {
-                       $matches = array_intersect_key( $prop, $this->props + array( 'ids' => 1 ) );
+                       $matches = array_intersect_key( $prop, $this->props + [ 'ids' => 1 ] );
                        if ( $matches ) {
                                $p = $this->getModulePrefix();
                                $this->dieUsage(
-                                       "Cannot use {$p}prop=" . join( '|', array_keys( $matches ) ) . " with {$p}unique",
+                                       "Cannot use {$p}prop=" . implode( '|', array_keys( $matches ) ) . " with {$p}unique",
                                        'params'
                                );
                        }
@@ -183,8 +161,8 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
                                $params['prefix'], $namespace ), $db->anyString() ) );
                }
 
-               $this->addFields( array( 'pl_title' => $pfx . $fieldTitle ) );
-               $this->addFieldsIf( array( 'pl_from' => $pfx . 'from' ), !$params['unique'] );
+               $this->addFields( [ 'pl_title' => $pfx . $fieldTitle ] );
+               $this->addFieldsIf( [ 'pl_from' => $pfx . 'from' ], !$params['unique'] );
                foreach ( $this->props as $name => $field ) {
                        $this->addFieldsIf( $field, isset( $prop[$name] ) );
                }
@@ -196,7 +174,7 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
                $this->addOption( 'LIMIT', $limit + 1 );
 
                $sort = ( $params['dir'] == 'descending' ? ' DESC' : '' );
-               $orderBy = array();
+               $orderBy = [];
                $orderBy[] = $pfx . $fieldTitle . $sort;
                if ( !$params['unique'] ) {
                        $orderBy[] = $pfx . 'from' . $sort;
@@ -205,8 +183,8 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
 
                $res = $this->select( __METHOD__ );
 
-               $pageids = array();
-               $titles = array();
+               $pageids = [];
+               $titles = [];
                $count = 0;
                $result = $this->getResult();
                foreach ( $res as $row ) {
@@ -222,7 +200,9 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
                        }
 
                        if ( is_null( $resultPageSet ) ) {
-                               $vals = array();
+                               $vals = [
+                                       ApiResult::META_TYPE => 'assoc',
+                               ];
                                if ( $fld_ids ) {
                                        $vals['fromid'] = intval( $row->pl_from );
                                }
@@ -235,7 +215,7 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
                                                $vals[$name] = $row->$field;
                                        }
                                }
-                               $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals );
+                               $fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $vals );
                                if ( !$fit ) {
                                        if ( $params['unique'] ) {
                                                $this->setContinueEnumParameter( 'continue', $row->pl_title );
@@ -252,7 +232,7 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
                }
 
                if ( is_null( $resultPageSet ) ) {
-                       $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), $this->indexTag );
+                       $result->addIndexedTagName( [ 'query', $this->getModuleName() ], $this->indexTag );
                } elseif ( $params['unique'] ) {
                        $resultPageSet->populateFromTitles( $titles );
                } else {
@@ -261,38 +241,41 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
        }
 
        public function getAllowedParams() {
-               $allowedParams = array(
-                       'continue' => null,
+               $allowedParams = [
+                       'continue' => [
+                               ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
+                       ],
                        'from' => null,
                        'to' => null,
                        'prefix' => null,
                        'unique' => false,
-                       'prop' => array(
+                       'prop' => [
                                ApiBase::PARAM_ISMULTI => true,
                                ApiBase::PARAM_DFLT => 'title',
                                ApiBase::PARAM_TYPE => array_merge(
-                                       array( 'ids', 'title' ), array_keys( $this->props )
+                                       [ 'ids', 'title' ], array_keys( $this->props )
                                ),
-                       ),
-                       'namespace' => array(
+                               ApiBase::PARAM_HELP_MSG_PER_VALUE => [],
+                       ],
+                       'namespace' => [
                                ApiBase::PARAM_DFLT => $this->dfltNamespace,
                                ApiBase::PARAM_TYPE => 'namespace'
-                       ),
-                       'limit' => array(
+                       ],
+                       '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
-                       ),
-                       'dir' => array(
+                       ],
+                       'dir' => [
                                ApiBase::PARAM_DFLT => 'ascending',
-                               ApiBase::PARAM_TYPE => array(
+                               ApiBase::PARAM_TYPE => [
                                        'ascending',
                                        'descending'
-                               )
-                       ),
-               );
+                               ]
+                       ],
+               ];
                if ( !$this->hasNamespace ) {
                        unset( $allowedParams['namespace'] );
                }
@@ -300,60 +283,21 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
                return $allowedParams;
        }
 
-       public function getParamDescription() {
-               $p = $this->getModulePrefix();
-               $what = $this->descriptionWhat;
-               $targets = $this->descriptionTargets;
-               $linking = $this->descriptionLinking;
-               $paramDescription = array(
-                       'from' => "The title of the $what to start enumerating from",
-                       'to' => "The title of the $what to stop enumerating at",
-                       'prefix' => "Search for all $targets that begin with this value",
-                       'unique' => array(
-                               "Only show distinct $targets. Cannot be used with {$p}prop=" .
-                                       join( '|', array_keys( array( 'ids' => 1 ) + $this->props ) ) . '.',
-                               'When used as a generator, yields target pages instead of source pages.',
-                       ),
-                       'prop' => array(
-                               'What pieces of information to include',
-                               " ids      - Adds the pageid of the $linking page (Cannot be used with {$p}unique)",
-                               " title    - Adds the title of the $what",
-                       ),
-                       'namespace' => 'The namespace to enumerate',
-                       'limit' => 'How many total items to return',
-                       'continue' => 'When more results are available, use this to continue',
-                       'dir' => 'The direction in which to list',
-               );
-               foreach ( $this->propHelp as $help ) {
-                       $paramDescription['prop'][] = "$help (Cannot be used with {$p}unique)";
-               }
-               if ( !$this->hasNamespace ) {
-                       unset( $paramDescription['namespace'] );
-               }
-
-               return $paramDescription;
-       }
-
-       public function getDescription() {
-               return $this->description;
-       }
-
-       public function getExamples() {
+       protected function getExamplesMessages() {
                $p = $this->getModulePrefix();
                $name = $this->getModuleName();
-               $what = $this->descriptionWhat;
-               $targets = $this->descriptionTargets;
+               $path = $this->getModulePath();
 
-               return array(
-                       "api.php?action=query&list={$name}&{$p}from=B&{$p}prop=ids|title"
-                               => "List $targets with page ids they are from, including missing ones. Start at B",
-                       "api.php?action=query&list={$name}&{$p}unique=&{$p}from=B"
-                               => "List unique $targets",
-                       "api.php?action=query&generator={$name}&g{$p}unique=&g{$p}from=B"
-                               => "Gets all $targets, marking the missing ones",
-                       "api.php?action=query&generator={$name}&g{$p}from=B"
-                               => "Gets pages containing the {$what}s",
-               );
+               return [
+                       "action=query&list={$name}&{$p}from=B&{$p}prop=ids|title"
+                               => "apihelp-$path-example-B",
+                       "action=query&list={$name}&{$p}unique=&{$p}from=B"
+                               => "apihelp-$path-example-unique",
+                       "action=query&generator={$name}&g{$p}unique=&g{$p}from=B"
+                               => "apihelp-$path-example-unique-generator",
+                       "action=query&generator={$name}&g{$p}from=B"
+                               => "apihelp-$path-example-generator",
+               ];
        }
 
        public function getHelpUrls() {