Remove use of old API doc methods
[lhc/web/wiklou.git] / includes / api / ApiBase.php
index bb86536..c66e5d5 100644 (file)
@@ -348,45 +348,7 @@ abstract class ApiBase extends ContextSource {
         * @return array
         */
        protected function getExamplesMessages() {
-               // Fall back to old non-localised method
-               $ret = [];
-
-               $examples = $this->getExamples();
-               if ( $examples ) {
-                       if ( !is_array( $examples ) ) {
-                               $examples = [ $examples ];
-                       } elseif ( $examples && ( count( $examples ) & 1 ) == 0 &&
-                               array_keys( $examples ) === range( 0, count( $examples ) - 1 ) &&
-                               !preg_match( '/^\s*api\.php\?/', $examples[0] )
-                       ) {
-                               // Fix up the ugly "even numbered elements are description, odd
-                               // numbered elemts are the link" format (see doc for self::getExamples)
-                               $tmp = [];
-                               $examplesCount = count( $examples );
-                               for ( $i = 0; $i < $examplesCount; $i += 2 ) {
-                                       $tmp[$examples[$i + 1]] = $examples[$i];
-                               }
-                               $examples = $tmp;
-                       }
-
-                       foreach ( $examples as $k => $v ) {
-                               if ( is_numeric( $k ) ) {
-                                       $qs = $v;
-                                       $msg = '';
-                               } else {
-                                       $qs = $k;
-                                       $msg = self::escapeWikiText( $v );
-                                       if ( is_array( $msg ) ) {
-                                               $msg = implode( ' ', $msg );
-                                       }
-                               }
-
-                               $qs = preg_replace( '/^\s*api\.php\?/', '', $qs );
-                               $ret[$qs] = $this->msg( 'api-help-fallback-example', [ $msg ] );
-                       }
-               }
-
-               return $ret;
+               return [];
        }
 
        /**
@@ -1784,25 +1746,6 @@ abstract class ApiBase extends ContextSource {
                return $user;
        }
 
-       /**
-        * A subset of wfEscapeWikiText for BC texts
-        *
-        * @since 1.25
-        * @param string|array $v
-        * @return string|array
-        */
-       private static function escapeWikiText( $v ) {
-               if ( is_array( $v ) ) {
-                       return array_map( 'self::escapeWikiText', $v );
-               } else {
-                       return strtr( $v, [
-                               '__' => '_&#95;', '{' => '&#123;', '}' => '&#125;',
-                               '[[Category:' => '[[:Category:',
-                               '[[File:' => '[[:File:', '[[Image:' => '[[:Image:',
-                       ] );
-               }
-       }
-
        /**
         * Create a Message from a string or array
         *
@@ -1853,6 +1796,12 @@ abstract class ApiBase extends ContextSource {
                                        'blocked',
                                        [ 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $user->getBlock() ) ]
                                ) );
+                       } elseif ( is_array( $error ) && $error[0] === 'blockedtext-partial' && $user->getBlock() ) {
+                               $status->fatal( ApiMessage::create(
+                                       'apierror-blocked-partial',
+                                       'blocked',
+                                       [ 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $user->getBlock() ) ]
+                               ) );
                        } elseif ( is_array( $error ) && $error[0] === 'autoblockedtext' && $user->getBlock() ) {
                                $status->fatal( ApiMessage::create(
                                        'apierror-autoblocked',
@@ -2027,6 +1976,12 @@ abstract class ApiBase extends ContextSource {
                                'autoblocked',
                                [ 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $block ) ]
                        );
+               } elseif ( !$block->isSitewide() ) {
+                       $this->dieWithError(
+                               'apierror-blocked-partial',
+                               'blocked',
+                               [ 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $block ) ]
+                       );
                } else {
                        $this->dieWithError(
                                'apierror-blocked',
@@ -2218,10 +2173,6 @@ abstract class ApiBase extends ContextSource {
        /**
         * Get final module summary
         *
-        * Ideally this will just be the getSummaryMessage(). However, for
-        * backwards compatibility, if that message does not exist then the first
-        * line of wikitext from the description message will be used instead.
-        *
         * @since 1.30
         * @return Message
         */
@@ -2231,17 +2182,6 @@ abstract class ApiBase extends ContextSource {
                        $this->getModuleName(),
                        $this->getModulePath(),
                ] );
-               if ( !$msg->exists() ) {
-                       wfDeprecated( 'API help "description" messages', '1.30' );
-                       $msg = self::makeMessage( $this->getDescriptionMessage(), $this->getContext(), [
-                               $this->getModulePrefix(),
-                               $this->getModuleName(),
-                               $this->getModulePath(),
-                       ] );
-                       $msg = self::makeMessage( 'rawmessage', $this->getContext(), [
-                               preg_replace( '/\n.*/s', '', $msg->text() )
-                       ] );
-               }
                return $msg;
        }
 
@@ -2253,18 +2193,6 @@ abstract class ApiBase extends ContextSource {
         * @return Message[]
         */
        public function getFinalDescription() {
-               $desc = $this->getDescription();
-
-               // Avoid PHP 7.1 warning of passing $this by reference
-               $apiModule = $this;
-               Hooks::run( 'APIGetDescription', [ &$apiModule, &$desc ], '1.25' );
-               $desc = self::escapeWikiText( $desc );
-               if ( is_array( $desc ) ) {
-                       $desc = implode( "\n", $desc );
-               } else {
-                       $desc = (string)$desc;
-               }
-
                $summary = self::makeMessage( $this->getSummaryMessage(), $this->getContext(), [
                        $this->getModulePrefix(),
                        $this->getModuleName(),
@@ -2278,20 +2206,7 @@ abstract class ApiBase extends ContextSource {
                        ]
                );
 
-               if ( $summary->exists() ) {
-                       $msgs = [ $summary, $extendedDescription ];
-               } else {
-                       wfDeprecated( 'API help "description" messages', '1.30' );
-                       $description = self::makeMessage( $this->getDescriptionMessage(), $this->getContext(), [
-                               $this->getModulePrefix(),
-                               $this->getModuleName(),
-                               $this->getModulePath(),
-                       ] );
-                       if ( !$description->exists() ) {
-                               $description = $this->msg( 'api-help-fallback-description', $desc );
-                       }
-                       $msgs = [ $description ];
-               }
+               $msgs = [ $summary, $extendedDescription ];
 
                Hooks::run( 'APIGetDescriptionMessages', [ $this, &$msgs ] );
 
@@ -2343,17 +2258,6 @@ abstract class ApiBase extends ContextSource {
                $name = $this->getModuleName();
                $path = $this->getModulePath();
 
-               $desc = $this->getParamDescription();
-
-               // Avoid PHP 7.1 warning of passing $this by reference
-               $apiModule = $this;
-               Hooks::run( 'APIGetParamDescription', [ &$apiModule, &$desc ], '1.25' );
-
-               if ( !$desc ) {
-                       $desc = [];
-               }
-               $desc = self::escapeWikiText( $desc );
-
                $params = $this->getFinalParams( self::GET_VALUES_FOR_HELP );
                $msgs = [];
                foreach ( $params as $param => $settings ) {
@@ -2361,25 +2265,10 @@ abstract class ApiBase extends ContextSource {
                                $settings = [];
                        }
 
-                       $d = $desc[$param] ?? '';
-                       if ( is_array( $d ) ) {
-                               // Special handling for prop parameters
-                               $d = array_map( function ( $line ) {
-                                       if ( preg_match( '/^\s+(\S+)\s+-\s+(.+)$/', $line, $m ) ) {
-                                               $line = "\n;{$m[1]}:{$m[2]}";
-                                       }
-                                       return $line;
-                               }, $d );
-                               $d = implode( ' ', $d );
-                       }
-
                        if ( isset( $settings[self::PARAM_HELP_MSG] ) ) {
                                $msg = $settings[self::PARAM_HELP_MSG];
                        } else {
                                $msg = $this->msg( "apihelp-{$path}-param-{$param}" );
-                               if ( !$msg->exists() ) {
-                                       $msg = $this->msg( 'api-help-fallback-parameter', $d );
-                               }
                        }
                        $msg = self::makeMessage( $msg, $this->getContext(),
                                [ $prefix, $param, $name, $path ] );
@@ -2642,6 +2531,7 @@ abstract class ApiBase extends ContextSource {
         * @return Message|string|array|false
         */
        protected function getDescription() {
+               wfDeprecated( __METHOD__, '1.25' );
                return false;
        }
 
@@ -2658,6 +2548,7 @@ abstract class ApiBase extends ContextSource {
         * @return array|bool False on no parameter descriptions
         */
        protected function getParamDescription() {
+               wfDeprecated( __METHOD__, '1.25' );
                return [];
        }
 
@@ -2678,6 +2569,7 @@ abstract class ApiBase extends ContextSource {
         * @return bool|string|array
         */
        protected function getExamples() {
+               wfDeprecated( __METHOD__, '1.25' );
                return false;
        }
 
@@ -2690,6 +2582,7 @@ abstract class ApiBase extends ContextSource {
         * @return string|array|Message
         */
        protected function getDescriptionMessage() {
+               wfDeprecated( __METHOD__, '1.30' );
                return [ [
                        "apihelp-{$this->getModulePath()}-description",
                        "apihelp-{$this->getModulePath()}-summary",