From a943d0da14f1ff4435409171a32f03cb958025ad Mon Sep 17 00:00:00 2001 From: Waldir Pimenta Date: Wed, 16 Jan 2013 19:31:37 +0000 Subject: [PATCH] Fix API output formatting (change lines delimited with * as bold) Problem: on API documentation pages, lines delimited with asterisks are automatically converted to bold. However, some lines aren't, such as the one with the url in the main header of the root API page: https://en.wikipedia.org/w/api.php Not only this is breaks the standard formatting for module headers, etc, but if the font used by the browser for monospaced text doesn't preserve character width between bold and regular weight (which it should), any layout structures will break. Example: http://i.imgur.com/PVh6i.png The regex that applies bold to the lines starting and ending in * doesn't accept < and > inside the string, but these are added by the url-formatting regex. Simply changing the order of these operations fixes the issue. Note: this change also removes the regex applying italics to lines in the $ ... $ form, as suggested by Anomie and Yurik in code review comments. Change-Id: I7173f812bebb8a722fefdaa6cce9fcd554c82c84 --- includes/api/ApiFormatBase.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/includes/api/ApiFormatBase.php b/includes/api/ApiFormatBase.php index 8ad9b8ca35..434b3c0282 100644 --- a/includes/api/ApiFormatBase.php +++ b/includes/api/ApiFormatBase.php @@ -248,7 +248,7 @@ See the complete documentation, } /** - * Sets whether the pretty-printer should format *bold* and $italics$ + * Sets whether the pretty-printer should format *bold* * @param $help bool */ public function setHelp( $help = true ) { @@ -264,22 +264,19 @@ See the complete documentation, protected function formatHTML( $text ) { // Escape everything first for full coverage $text = htmlspecialchars( $text ); - // encode all comments or tags as safe blue strings $text = str_replace( '<', '<', $text ); $text = str_replace( '>', '>', $text ); - // identify URLs - $protos = wfUrlProtocolsWithoutProtRel(); - // This regex hacks around bug 13218 (" included in the URL) - $text = preg_replace( "#(((?i)$protos).*?)(")?([ \\'\"<>\n]|<|>|")#", '\\1\\3\\4', $text ); // identify requests to api.php $text = preg_replace( "#api\\.php\\?[^ <\n\t]+#", '\\0', $text ); if ( $this->mHelp ) { // make strings inside * bold $text = preg_replace( "#\\*[^<>\n]+\\*#", '\\0', $text ); - // make strings inside $ italic - $text = preg_replace( "#\\$[^<>\n]+\\$#", '\\0', $text ); } + // identify URLs + $protos = wfUrlProtocolsWithoutProtRel(); + // This regex hacks around bug 13218 (" included in the URL) + $text = preg_replace( "#(((?i)$protos).*?)(")?([ \\'\"<>\n]|<|>|")#", '\\1\\3\\4', $text ); /** * Temporary fix for bad links in help messages. As a special case, -- 2.20.1