Merge "Push all DeferredUpdates to POSTSEND queue when running that queue"
[lhc/web/wiklou.git] / includes / api / ApiBase.php
index aa970f4..bc3def8 100644 (file)
@@ -894,7 +894,7 @@ abstract class ApiBase extends ContextSource {
         * Get a WikiPage object from a title or pageid param, if possible.
         * Can die, if no param is set or if the title or page id is not valid.
         *
-        * @param array $params
+        * @param array $params User provided set of parameters, as from $this->extractRequestParams()
         * @param bool|string $load Whether load the object's state from the database:
         *        - false: don't load (if the pageid is given, it will still be loaded)
         *        - 'fromdb': load from a replica DB
@@ -935,7 +935,7 @@ abstract class ApiBase extends ContextSource {
         * Can die, if no param is set or if the title or page id is not valid.
         *
         * @since 1.29
-        * @param array $params
+        * @param array $params User provided set of parameters, as from $this->extractRequestParams()
         * @return Title
         */
        public function getTitleFromTitleOrPageId( $params ) {
@@ -967,7 +967,6 @@ abstract class ApiBase extends ContextSource {
         * @return bool
         */
        protected function getWatchlistValue( $watchlist, $titleObj, $userOption = null ) {
-
                $userWatching = $this->getUser()->isWatched( $titleObj, User::IGNORE_USER_RIGHTS );
 
                switch ( $watchlist ) {
@@ -2241,7 +2240,49 @@ abstract class ApiBase extends ContextSource {
                        }
                        $msgs[$param] = [ $msg ];
 
-                       if ( isset( $settings[ApiBase::PARAM_HELP_MSG_PER_VALUE] ) ) {
+                       if ( isset( $settings[ApiBase::PARAM_TYPE] ) &&
+                               $settings[ApiBase::PARAM_TYPE] === 'submodule'
+                       ) {
+                               if ( isset( $settings[ApiBase::PARAM_SUBMODULE_MAP] ) ) {
+                                       $map = $settings[ApiBase::PARAM_SUBMODULE_MAP];
+                               } else {
+                                       $prefix = $this->isMain() ? '' : ( $this->getModulePath() . '+' );
+                                       $map = [];
+                                       foreach ( $this->getModuleManager()->getNames( $param ) as $submoduleName ) {
+                                               $map[$submoduleName] = $prefix . $submoduleName;
+                                       }
+                               }
+                               ksort( $map );
+                               $submodules = [];
+                               $deprecatedSubmodules = [];
+                               foreach ( $map as $v => $m ) {
+                                       $arr = &$submodules;
+                                       $isDeprecated = false;
+                                       $summary = null;
+                                       try {
+                                               $submod = $this->getModuleFromPath( $m );
+                                               if ( $submod ) {
+                                                       $summary = $submod->getFinalSummary();
+                                                       $isDeprecated = $submod->isDeprecated();
+                                                       if ( $isDeprecated ) {
+                                                               $arr = &$deprecatedSubmodules;
+                                                       }
+                                               }
+                                       } catch ( ApiUsageException $ex ) {
+                                               // Ignore
+                                       }
+                                       if ( $summary ) {
+                                               $key = $summary->getKey();
+                                               $params = $summary->getParams();
+                                       } else {
+                                               $key = 'api-help-undocumented-module';
+                                               $params = [ $m ];
+                                       }
+                                       $m = new ApiHelpParamValueMessage( "[[Special:ApiHelp/$m|$v]]", $key, $params, $isDeprecated );
+                                       $arr[] = $m->setContext( $this->getContext() );
+                               }
+                               $msgs[$param] = array_merge( $msgs[$param], $submodules, $deprecatedSubmodules );
+                       } elseif ( isset( $settings[ApiBase::PARAM_HELP_MSG_PER_VALUE] ) ) {
                                if ( !is_array( $settings[ApiBase::PARAM_HELP_MSG_PER_VALUE] ) ) {
                                        self::dieDebug( __METHOD__,
                                                'ApiBase::PARAM_HELP_MSG_PER_VALUE is not valid' );