$paramsDescription = $this->getParamDescription();
$msg = '';
$paramPrefix = "\n" . str_repeat(' ', 19);
- foreach ($params as $paramName => & $paramSettings) {
+ foreach ($params as $paramName => $paramSettings) {
$desc = isset ($paramsDescription[$paramName]) ? $paramsDescription[$paramName] : '';
if (is_array($desc))
$desc = implode($paramPrefix, $desc);
'meta' => 'siteinfo',
'siprop' => 'general',
'list' => 'watchlist',
- 'wlstart' => wfTimestamp(TS_MW, time() - intval( 3 * 86400 )), // limit to 3 days
+ 'wlprop' => 'user|comment|timestamp',
+ 'wlstart' => wfTimestamp(TS_MW, time() - intval( 1 * 86400 )), // limit to 1 day
'wllimit' => 50
));
$module = new ApiMain($params);
$module->execute();
- // Get clean data
- $result = & $module->getResult();
- $result->SanitizeData();
- $data = & $result->GetData();
+ // Get data array
+ $data = & $module->getResultData();
$feedItems = array ();
foreach ($data['query']['watchlist'] as $index => $info) {
$title = $info['title'];
$titleUrl = Title :: newFromText($title)->getFullUrl();
- $feedItems[] = new FeedItem($title, '', $titleUrl, $info['timestamp'], $info['user']);
+ $feedItems[] = new FeedItem($title, $info['comment'], $titleUrl, $info['timestamp'], $info['user']);
}
global $wgFeedClasses, $wgSitename, $wgContLanguageCode;
$feedTitle = $wgSitename . ' - ' . wfMsgForContent('watchlist') . ' [' . $wgContLanguageCode . ']';
$feedUrl = Title :: makeTitle(NS_SPECIAL, 'Watchlist')->getFullUrl();
- $feed = new $wgFeedClasses[$feedformat] ($feedTitle, '!Watchlist!', $feedUrl);
+ $feed = new $wgFeedClasses[$feedformat] ($feedTitle, '!Watchlist (TODO)!', $feedUrl);
ApiFormatFeedWrapper :: setResult($this->getResult(), $feed, $feedItems);
}
?>
<br/>
<small>
- This result is being shown in <?=$this->mFormat?> format,
- which might not be suitable for your application.<br/>
- See <a href='api.php'>API help</a> for more information.<br/>
+ You are looking at the HTML representation of the <?=$this->mFormat?> format.<br/>
+ HTML is good for debugging, but probably not suitable for your application.<br/>
+ Please see "format" parameter documentation at the <a href='api.php'>API help</a>
+ for more information.<br/>
</small>
<?php
// encode all tags as safe blue strings
$text = ereg_replace('\<([^>]+)\>', '<font color=blue><\1></font>', $text);
// identify URLs
- $text = ereg_replace("[a-zA-Z]+://[^ '()<\n]+", '<a href="\\0">\\0</a>', $text);
+ $text = ereg_replace("[a-zA-Z]+://[^ '\"()<\n]+", '<a href="\\0">\\0</a>', $text);
// identify requests to api.php
$text = ereg_replace("api\\.php\\?[^ ()<\n\t]+", '<a href="\\0">\\0</a>', $text);
// make strings inside * bold
// Printer may not be initialized if the extractRequestParams() fails for the main module
if (!isset ($this->mPrinter)) {
$this->mPrinter = $this->createPrinterByName(self :: API_DEFAULT_FORMAT);
+ if ($this->mPrinter->getNeedsRawData())
+ $this->getResult()->setRawMode();
}
if ($e instanceof UsageException) {
// Reset and print just the error message
ob_clean();
- $this->mResult->Reset();
- $this->mResult->addValue(null, 'error', $errMessage);
+ $this->getResult()->reset();
+ $this->getResult()->addValue(null, 'error', $errMessage);
// If the error occured during printing, do a printer->profileOut()
$this->mPrinter->safeProfileOut();
// See if custom printer is used
$this->mPrinter = $module->getCustomPrinter();
-
if (is_null($this->mPrinter)) {
// Create an appropriate printer
$this->mPrinter = $this->createPrinterByName($format);
}
+
+ if ($this->mPrinter->getNeedsRawData())
+ $this->getResult()->setRawMode();
}
// Execute
$printer = $this->mPrinter;
$printer->profileIn();
$printer->initPrinter($isError);
- if (!$printer->getNeedsRawData())
- $this->getResult()->SanitizeData();
$printer->execute();
$printer->closePrinter();
$printer->profileOut();
$module->execute();
// Get clean data
- $result =& $module->getResult();
- $result->SanitizeData();
- $data =& $result->GetData();
+ $data =& $module->getResultData();
// Reformat useful data for future printing by JSON engine
$srchres = array();
private function outputGeneralPageInfo() {
$pageSet = $this->getPageSet();
+ $result = $this->getResult();
// Title normalizations
$normValues = array ();
}
if (!empty ($normValues)) {
- ApiResult :: setIndexedTagName($normValues, 'n');
- $this->getResult()->addValue('query', 'normalized', $normValues);
+ $result->setIndexedTagName($normValues, 'n');
+ $result->addValue('query', 'normalized', $normValues);
}
// Show redirect information
}
if (!empty ($redirValues)) {
- ApiResult :: setIndexedTagName($redirValues, 'r');
- $this->getResult()->addValue('query', 'redirects', $redirValues);
+ $result->setIndexedTagName($redirValues, 'r');
+ $result->addValue('query', 'redirects', $redirValues);
}
'revid' => $revid
);
}
- ApiResult :: setIndexedTagName($revids, 'rev');
- $this->getResult()->addValue('query', 'badrevids', $revids);
+ $result->setIndexedTagName($revids, 'rev');
+ $result->addValue('query', 'badrevids', $revids);
}
//
}
if (!empty ($pages)) {
- ApiResult :: setIndexedTagName($pages, 'page');
- $this->getResult()->addValue('query', 'pages', $pages);
+ $result->setIndexedTagName($pages, 'page');
+ $result->addValue('query', 'pages', $pages);
}
}
$db->freeResult($res);
if (is_null($resultPageSet)) {
- ApiResult :: setIndexedTagName($data, 'p');
- $this->getResult()->addValue('query', $this->getModuleName(), $data);
+ $result = $this->getResult();
+ $result->setIndexedTagName($data, 'p');
+ $result->addValue('query', $this->getModuleName(), $data);
}
}
}
if(!empty($params)) {
- ApiResult :: setIndexedTagName($params, 'param');
+ $this->getResult()->setIndexedTagName($params, 'param');
$vals = array_merge($vals, $params);
}
}
}
$db->freeResult($res);
- ApiResult :: setIndexedTagName($data, 'item');
+ $this->getResult()->setIndexedTagName($data, 'item');
$this->getResult()->addValue('query', $this->getModuleName(), $data);
}
$db->freeResult($res);
// Ensure that all revisions are shown as '<r>' elements
- $data = & $this->getResultData();
+ $result = $this->getResult();
+ $data = & $result->getData();
foreach ($data['query']['pages'] as & $page) {
if (is_array($page) && array_key_exists('revisions', $page)) {
- ApiResult :: setIndexedTagName($page['revisions'], 'rev');
+ $result->setIndexedTagName($page['revisions'], 'rev');
}
}
}
);
ApiResult :: setContent($data[$ns], $title);
}
- ApiResult :: setIndexedTagName($data, 'ns');
+ $this->getResult()->setIndexedTagName($data, 'ns');
$this->getResult()->addValue('query', $p, $data);
break;
$db->freeResult($res);
if (is_null($resultPageSet)) {
- ApiResult :: setIndexedTagName($data, 'item');
+ $this->getResult()->setIndexedTagName($data, 'item');
$this->getResult()->addValue('query', $this->getModuleName(), $data);
}
elseif ($allrev) {
class ApiResult extends ApiBase {
- private $mData;
+ private $mData, $mNeedsRaw;
/**
* Constructor
*/
public function __construct($main) {
parent :: __construct($main, 'result');
- $this->Reset();
+ $this->mNeedsRaw = false;
+ $this->reset();
}
- public function Reset() {
+ public function reset() {
$this->mData = array ();
}
+
+ /**
+ * Call this function when special elements such as '_element'
+ * are needed by the formatter, for example in XML printing.
+ */
+ public function setRawMode() {
+ $this->mNeedsRaw = true;
+ }
function & getData() {
return $this->mData;
* In case the array contains indexed values (in addition to named),
* all indexed values will have the given tag name.
*/
- public static function setIndexedTagName(& $arr, $tag) {
- // Do not use setElement() as it is ok to call this more than once
+ public function setIndexedTagName(& $arr, $tag) {
+ // In raw mode, add the '_element', otherwise just ignore
+ if (!$this->mNeedsRaw)
+ return;
if ($arr === null || $tag === null || !is_array($arr) || is_array($tag))
ApiBase :: dieDebug(__METHOD__, 'Bad parameter');
+ // Do not use setElement() as it is ok to call this more than once
$arr['_element'] = $tag;
}
ApiResult :: setElement($data, $name, $value);
}
- /**
- * Recursivelly removes any elements from the array that begin with an '_'.
- * The content element '*' is the only special element that is left.
- * Use this method when the entire data object gets sent to the user.
- */
- public function SanitizeData() {
- ApiResult :: SanitizeDataInt($this->mData);
- }
-
- private static function SanitizeDataInt(& $data) {
- foreach ($data as $key => & $value) {
- if ($key[0] === '_') {
- unset ($data[$key]);
- }
- elseif (is_array($value)) {
- ApiResult :: SanitizeDataInt($value);
- }
- }
- }
-
public function execute() {
ApiBase :: dieDebug(__METHOD__, 'execute() is not supported on Result object');
}