From c1f9b1f7b1b77776192048005dcc66dcf3df2bfb Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 27 Dec 2014 15:41:37 +0100 Subject: Update to MediaWiki 1.24.1 --- includes/api/ApiFormatBase.php | 146 ++++++++++++++--------------------------- 1 file changed, 51 insertions(+), 95 deletions(-) (limited to 'includes/api/ApiFormatBase.php') diff --git a/includes/api/ApiFormatBase.php b/includes/api/ApiFormatBase.php index 70495439..9165ce88 100644 --- a/includes/api/ApiFormatBase.php +++ b/includes/api/ApiFormatBase.php @@ -30,22 +30,20 @@ * @ingroup API */ abstract class ApiFormatBase extends ApiBase { - private $mIsHtml, $mFormat, $mUnescapeAmps, $mHelp, $mCleared; private $mBufferResult = false, $mBuffer, $mDisabled = false; /** - * Constructor * If $format ends with 'fm', pretty-print the output in HTML. - * @param $main ApiMain + * @param ApiMain $main * @param string $format Format name */ - public function __construct( $main, $format ) { + public function __construct( ApiMain $main, $format ) { parent::__construct( $main, $format ); - $this->mIsHtml = ( substr( $format, - 2, 2 ) === 'fm' ); // ends with 'fm' + $this->mIsHtml = ( substr( $format, -2, 2 ) === 'fm' ); // ends with 'fm' if ( $this->mIsHtml ) { - $this->mFormat = substr( $format, 0, - 2 ); // remove ending 'fm' + $this->mFormat = substr( $format, 0, -2 ); // remove ending 'fm' } else { $this->mFormat = $format; } @@ -54,7 +52,7 @@ abstract class ApiFormatBase extends ApiBase { } /** - * Overriding class returns the mime type that should be sent to the client. + * Overriding class returns the MIME type that should be sent to the client. * This method is not called if getIsHtml() returns true. * @return string */ @@ -121,6 +119,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. @@ -146,9 +154,9 @@ abstract class ApiFormatBase extends ApiBase { $this->getMain()->getRequest()->response()->header( "Content-Type: $mime; charset=utf-8" ); //Set X-Frame-Options API results (bug 39180) - global $wgApiFrameOptions; - if ( $wgApiFrameOptions ) { - $this->getMain()->getRequest()->response()->header( "X-Frame-Options: $wgApiFrameOptions" ); + $apiFrameOptions = $this->getConfig()->get( 'ApiFrameOptions' ); + if ( $apiFrameOptions ) { + $this->getMain()->getRequest()->response()->header( "X-Frame-Options: $apiFrameOptions" ); } if ( $isHtml ) { @@ -156,17 +164,20 @@ abstract class ApiFormatBase extends ApiBase { -mUnescapeAmps ) { +mUnescapeAmps ) { ?> MediaWiki API - MediaWiki API Result - +
@@ -179,15 +190,14 @@ See the complete documentation,
  for help screens
-			          // because these are actually formatted to rely on
-			          // the monospaced font for layout purposes
+// @codingStandardsIgnoreEnd
+			// don't wrap the contents of the 
 for help screens
+			// because these are actually formatted to rely on
+			// the monospaced font for layout purposes
+			} else {
 ?>
 
 complete documentation,
 
 
 complete documentation,
 	 * The main format printing function. Call it to output the result
 	 * string to the user. This function will automatically output HTML
 	 * when format name ends in 'fm'.
-	 * @param $text string
+	 * @param string $text
 	 */
 	public function printText( $text ) {
 		if ( $this->mDisabled ) {
@@ -239,6 +247,7 @@ See the complete documentation,
 
 	/**
 	 * Get the contents of the buffer.
+	 * @return string
 	 */
 	public function getBuffer() {
 		return $this->mBuffer;
@@ -246,7 +255,7 @@ See the complete documentation,
 
 	/**
 	 * Set the flag to buffer the result instead of printing it.
-	 * @param $value bool
+	 * @param bool $value
 	 */
 	public function setBufferResult( $value ) {
 		$this->mBufferResult = $value;
@@ -254,7 +263,7 @@ See the complete documentation,
 
 	/**
 	 * Sets whether the pretty-printer should format *bold*
-	 * @param $help bool
+	 * @param bool $help
 	 */
 	public function setHelp( $help = true ) {
 		$this->mHelp = $help;
@@ -263,7 +272,7 @@ See the complete documentation,
 	/**
 	 * Pretty-print various elements in HTML format, such as xml tags and
 	 * URLs. This method also escapes characters like <
-	 * @param $text string
+	 * @param string $text
 	 * @return string
 	 */
 	protected function formatHTML( $text ) {
@@ -276,8 +285,8 @@ See the complete documentation,
 		// identify requests to api.php
 		$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)
@@ -291,7 +300,11 @@ See the complete documentation,
 		// identify URLs
 		$protos = wfUrlProtocolsWithoutProtRel();
 		// This regex hacks around bug 13218 (" included in the URL)
-		$text = preg_replace( "#(((?i)$protos).*?)(")?([ \\'\"<>\n]|<|>|")#", '\\1\\3\\4', $text );
+		$text = preg_replace(
+			"#(((?i)$protos).*?)(")?([ \\'\"<>\n]|<|>|")#",
+			'\\1\\3\\4',
+			$text
+		);
 
 		// Unarmor links
 		$text = preg_replace_callback( '#<([0-9a-f]{40})>#', function ( $matches ) use ( &$masked ) {
@@ -326,73 +339,16 @@ See the complete documentation,
 	public function getDescription() {
 		return $this->getIsHtml() ? ' (pretty-print in HTML)' : '';
 	}
-}
-
-/**
- * This printer is used to wrap an instance of the Feed class
- * @ingroup API
- */
-class ApiFormatFeedWrapper extends ApiFormatBase {
-
-	public function __construct( $main ) {
-		parent::__construct( $main, 'feed' );
-	}
-
-	/**
-	 * Call this method to initialize output data. See execute()
-	 * @param $result ApiResult
-	 * @param $feed object an instance of one of the $wgFeedClasses classes
-	 * @param array $feedItems of FeedItem objects
-	 */
-	public static function setResult( $result, $feed, $feedItems ) {
-		// Store output in the Result data.
-		// This way we can check during execution if any error has occurred
-		// Disable size checking for this because we can't continue
-		// cleanly; size checking would cause more problems than it'd
-		// solve
-		$result->disableSizeCheck();
-		$result->addValue( null, '_feed', $feed );
-		$result->addValue( null, '_feeditems', $feedItems );
-		$result->enableSizeCheck();
-	}
-
-	/**
-	 * Feed does its own headers
-	 *
-	 * @return null
-	 */
-	public function getMimeType() {
-		return null;
-	}
-
-	/**
-	 * Optimization - no need to sanitize data that will not be needed
-	 *
-	 * @return bool
-	 */
-	public function getNeedsRawData() {
-		return true;
-	}
 
 	/**
-	 * 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
-	 * $result['_feeditems']	- an array of FeedItem instances
+	 * To avoid code duplication with the deprecation of dbg, dump, txt, wddx,
+	 * and yaml, this method is added to do the necessary work. It should be
+	 * removed when those deprecated formats are removed.
 	 */
-	public function execute() {
-		$data = $this->getResultData();
-		if ( isset( $data['_feed'] ) && isset( $data['_feeditems'] ) ) {
-			$feed = $data['_feed'];
-			$items = $data['_feeditems'];
-
-			$feed->outHeader();
-			foreach ( $items as & $item ) {
-				$feed->outItem( $item );
-			}
-			$feed->outFooter();
-		} else {
-			// Error has occurred, print something useful
-			ApiBase::dieDebug( __METHOD__, 'Invalid feed class/item' );
-		}
+	protected function markDeprecated() {
+		$fm = $this->getIsHtml() ? 'fm' : '';
+		$name = $this->getModuleName();
+		$this->logFeatureUsage( "format=$name" );
+		$this->setWarning( "format=$name has been deprecated. Please use format=json$fm instead." );
 	}
 }
-- 
cgit v1.2.3-54-g00ecf