From a58285fd06c8113c45377c655dd43cef6337e815 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 11 Jan 2007 19:06:07 +0000 Subject: Aktualisierung auf MediaWiki 1.9.0 --- includes/api/ApiFormatBase.php | 109 ++++++++++++++++++++++++++++++++++------- 1 file changed, 90 insertions(+), 19 deletions(-) (limited to 'includes/api/ApiFormatBase.php') diff --git a/includes/api/ApiFormatBase.php b/includes/api/ApiFormatBase.php index 6f5b4aca..611960d3 100644 --- a/includes/api/ApiFormatBase.php +++ b/includes/api/ApiFormatBase.php @@ -75,32 +75,40 @@ abstract class ApiFormatBase extends ApiBase { function initPrinter($isError) { $isHtml = $this->getIsHtml(); $mime = $isHtml ? 'text/html' : $this->getMimeType(); + + // Some printers (ex. Feed) do their own header settings, + // in which case $mime will be set to null + if (is_null($mime)) + return; // skip any initialization + header("Content-Type: $mime; charset=utf-8;"); if ($isHtml) { ?> - - - MediaWiki API - - + + + + MediaWiki API + + -
- - This result is being shown in mFormat?> format, - which might not be suitable for your application.
- See API help for more information.
-
+
+ +You are looking at the HTML representation of the mFormat?> format.
+HTML is good for debugging, but probably is not suitable for your application.
+Please see "format" parameter documentation at the API help +for more information. +
-
+
 getIsHtml()) {
 ?>
-		
- + +
+ + ]+)\>', '<\1>', $text); + $text = ereg_replace('\<([^>]+)\>', '<\1>', $text); // identify URLs - $text = ereg_replace("[a-zA-Z]+://[^ '()<\n]+", '\\0', $text); + $protos = "http|https|ftp|gopher"; + $text = ereg_replace("($protos)://[^ '\"()<\n]+", '\\0', $text); // identify requests to api.php $text = ereg_replace("api\\.php\\?[^ ()<\n\t]+", '\\0', $text); // make strings inside * bold @@ -151,11 +162,71 @@ abstract class ApiFormatBase extends ApiBase { * Returns usage examples for this format. */ protected function getExamples() { - return 'api.php?action=query&meta=siteinfo&si=namespaces&format=' . $this->getModuleName(); + return 'api.php?action=query&meta=siteinfo&siprop=namespaces&format=' . $this->getModuleName(); + } + + protected function getDescription() { + return $this->getIsHtml() ? ' (pretty-print in HTML)' : ''; } public static function getBaseVersion() { - return __CLASS__ . ': $Id: ApiFormatBase.php 16757 2006-10-03 05:41:55Z yurik $'; + return __CLASS__ . ': $Id: ApiFormatBase.php 17374 2006-11-03 06:53:47Z yurik $'; + } +} + +/** + * This printer is used to wrap an instance of the Feed class + */ +class ApiFormatFeedWrapper extends ApiFormatBase { + + public function __construct($main) { + parent :: __construct($main, 'feed'); + } + + /** + * Call this method to initialize output data + */ + public static function setResult($result, $feed, $feedItems) { + // Store output in the Result data. + // This way we can check during execution if any error has occured + $data = & $result->getData(); + $data['_feed'] = $feed; + $data['_feeditems'] = $feedItems; + } + + /** + * Feed does its own headers + */ + public function getMimeType() { + return null; + } + + /** + * Optimization - no need to sanitize data that will not be needed + */ + public function getNeedsRawData() { + return true; + } + + 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 occured, print something usefull + // TODO: make this error more informative using ApiBase :: dieDebug() or similar + wfHttpError(500, 'Internal Server Error', ''); + } + } + + public function getVersion() { + return __CLASS__ . ': $Id: ApiFormatBase.php 17374 2006-11-03 06:53:47Z yurik $'; } } -?> \ No newline at end of file +?> -- cgit v1.2.3-54-g00ecf