X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiFormatBase.php;h=d43259dd8da94ddb735bddabf7e52cd400e11ba2;hb=d0830af6ba44c6bb51496c6577df4615f6c1bb46;hp=63a55024b345c1ea835ecee04ea6282bbf30cf8e;hpb=5974804aee5bfc01ea6b49de8537df960035c0ce;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiFormatBase.php b/includes/api/ApiFormatBase.php index 63a55024b3..d43259dd8d 100644 --- a/includes/api/ApiFormatBase.php +++ b/includes/api/ApiFormatBase.php @@ -120,6 +120,16 @@ abstract class ApiFormatBase extends ApiBase { return $this->mDisabled; } + /** + * Whether this formatter can handle printing API errors. If this returns + * false, then on API errors the default printer will be instantiated. + * @since 1.23 + * @return bool + */ + public function canPrintErrors() { + return true; + } + /** * Initialize the printer function and prepare the output headers, etc. * This method must be the first outputting method during execution. @@ -271,12 +281,22 @@ See the complete documentation, // encode all comments or tags as safe blue strings $text = str_replace( '<', '<', $text ); $text = str_replace( '>', '>', $text ); + // identify requests to api.php - $text = preg_replace( "#api\\.php\\?[^ <\n\t]+#", '\\0', $text ); + $text = preg_replace( '#^(\s*)(api\.php\?[^ <\n\t]+)$#m', '\1\2', $text ); if ( $this->mHelp ) { - // make strings inside * bold - $text = preg_replace( "#\\*[^<>\n]+\\*#", '\\0', $text ); + // make lines inside * bold + $text = preg_replace( '#^(\s*)(\*[^<>\n]+\*)(\s*)$#m', '$1$2$3', $text ); } + + // Armor links (bug 61362) + $masked = array(); + $text = preg_replace_callback( '##', function ( $matches ) use ( &$masked ) { + $sha = sha1( $matches[0] ); + $masked[$sha] = $matches[0]; + return "<$sha>"; + }, $text ); + // identify URLs $protos = wfUrlProtocolsWithoutProtRel(); // This regex hacks around bug 13218 (" included in the URL) @@ -286,6 +306,12 @@ See the complete documentation, $text ); + // Unarmor links + $text = preg_replace_callback( '#<([0-9a-f]{40})>#', function ( $matches ) use ( &$masked ) { + $sha = $matches[1]; + return isset( $masked[$sha] ) ? $masked[$sha] : $matches[0]; + }, $text ); + /** * Temporary fix for bad links in help messages. As a special case, * XML-escaped metachars are de-escaped one level in the help message @@ -361,6 +387,15 @@ class ApiFormatFeedWrapper extends ApiFormatBase { return true; } + /** + * ChannelFeed doesn't give us a method to print errors in a friendly + * manner, so just punt errors to the default printer. + * @return false + */ + public function canPrintErrors() { + return false; + } + /** * This class expects the result data to be in a custom format set by self::setResult() * $result['_feed'] - an instance of one of the $wgFeedClasses classes