X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiFormatBase.php;h=834588a1caaeeffd792ff822bfd7c3a761771131;hb=59254f1bc827cec0872a27d222a3d1f4f9beadda;hp=6863193990f0350011b17b6677760b3252f360ef;hpb=30842f073db026443d5b9a07e92a28fab8562bfb;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiFormatBase.php b/includes/api/ApiFormatBase.php index 6863193990..834588a1ca 100644 --- a/includes/api/ApiFormatBase.php +++ b/includes/api/ApiFormatBase.php @@ -30,12 +30,12 @@ if (!defined('MEDIAWIKI')) { /** * This is the abstract base class for API formatters. - * - * @addtogroup API + * + * @ingroup API */ abstract class ApiFormatBase extends ApiBase { - private $mIsHtml, $mFormat, $mUnescapeAmps, $mHelp; + private $mIsHtml, $mFormat, $mUnescapeAmps, $mHelp, $mCleared; /** * Create a new instance of the formatter. @@ -50,6 +50,7 @@ abstract class ApiFormatBase extends ApiBase { else $this->mFormat = $format; $this->mFormat = strtoupper($this->mFormat); + $this->mCleared = false; } /** @@ -62,7 +63,7 @@ abstract class ApiFormatBase extends ApiBase { /** * If formatter outputs data results as is, the results must first be sanitized. * An XML formatter on the other hand uses special tags, such as "_element" for special handling, - * and thus needs to override this function to return true. + * and thus needs to override this function to return true. */ public function getNeedsRawData() { return false; @@ -82,8 +83,8 @@ abstract class ApiFormatBase extends ApiBase { /** * Returns true when an HTML filtering printer should be used. - * The default implementation assumes that formats ending with 'fm' - * should be formatted in HTML. + * The default implementation assumes that formats ending with 'fm' + * should be formatted in HTML. */ public function getIsHtml() { return $this->mIsHtml; @@ -111,7 +112,7 @@ abstract class ApiFormatBase extends ApiBase { -mUnescapeAmps) { +mUnescapeAmps) { ?> MediaWiki API MediaWiki API Result @@ -127,7 +128,7 @@ abstract class ApiFormatBase extends ApiBase { You are looking at the HTML representation of the mFormat ); ?> format.
HTML is good for debugging, but probably is not suitable for your application.
-See complete documentation, or +See complete documentation, or API help for more information.
complete documentation, or if ($this->getIsHtml()) echo $this->formatHTML($text); else + { + // For non-HTML output, clear all errors that might have been + // displayed if display_errors=On + // Do this only once, of course + if(!$this->mCleared) + { + ob_clean(); + $this->mCleared = true; + } echo $text; + } } /** @@ -175,21 +186,23 @@ See complete documentation, or public function setHelp( $help = true ) { $this->mHelp = true; } - + /** * Prety-print various elements in HTML format, such as xml tags and URLs. * This method also replaces any '<' with < */ protected function formatHTML($text) { + global $wgUrlProtocols; + // Escape everything first for full coverage $text = htmlspecialchars($text); // encode all comments or tags as safe blue strings $text = preg_replace('/\<(!--.*?--|.*?)\>/', '<\1>', $text); // identify URLs - $protos = "http|https|ftp|gopher"; + $protos = implode("|", $wgUrlProtocols); # This regex hacks around bug 13218 (" included in the URL) - $text = preg_replace("#(($protos)://.*?)(")?([ \\'\"()<\n])#", '\\1\\3\\4', $text); + $text = preg_replace("#(($protos).*?)(")?([ \\'\"()<\n])#", '\\1\\3\\4', $text); // identify requests to api.php $text = preg_replace("#api\\.php\\?[^ \\()<\n\t]+#", '\\0', $text); if( $this->mHelp ) { @@ -198,7 +211,7 @@ See complete documentation, or // make strings inside $ italic $text = ereg_replace("\\$[^<>\n]+\\$", '\\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 * for legibility. Should be removed once we have completed a fully-html @@ -226,8 +239,8 @@ See complete documentation, or } /** - * This printer is used to wrap an instance of the Feed class - * @addtogroup API + * This printer is used to wrap an instance of the Feed class + * @ingroup API */ class ApiFormatFeedWrapper extends ApiFormatBase { @@ -276,12 +289,11 @@ class ApiFormatFeedWrapper extends ApiFormatBase { $feed->outItem($item); $feed->outFooter(); } else { - // Error has occured, print something usefull - // TODO: make this error more informative using ApiBase :: dieDebug() or similar - wfHttpError(500, 'Internal Server Error', ''); + // Error has occured, print something useful + ApiBase::dieDebug( __METHOD__, 'Invalid feed class/item' ); } } - + public function getVersion() { return __CLASS__ . ': $Id$'; }