return $this->getResult()->getData();
}
+ /**
+ * If the module may only be used with a certain format module,
+ * it should override this method to return an instance of that formatter.
+ * A value of null means the default format will be used.
+ */
+ public function getCustomFormatModule() {
+ return null;
+ }
+
/**
* Generates help message for this module, or false if there is no description
*/
*/
public abstract function getMimeType();
- public function execute() {
- ApiBase :: dieDebug(__METHOD__, 'This is not an executable module');
- }
-
- /**
- * Format modules must override this method to implement actual printing
- */
- public abstract function executePrinter();
-
public function getNeedsRawData() {
return false;
}
return 'application/json';
}
- public function executePrinter() {
+ public function execute() {
$json = new Services_JSON();
$this->printText($json->encode($this->getResultData(), true));
}
return true;
}
- public function executePrinter() {
+ public function execute() {
$xmlindent = null;
extract($this->extractRequestParams());
return 'application/yaml';
}
- public function executePrinter() {
+ public function execute() {
$this->printText(Spyc :: YAMLDump($this->getResultData()));
}
$this->dieUsage('Editing of this site is disabled. Make sure the $wgEnableWriteAPI=true; ' .
'statement is included in the site\'s LocalSettings.php file', 'readonly');
}
+
+ public function createPrinterByName($format) {
+ return new $this->mFormats[$format] ($this, $format);
+ }
public function execute() {
$this->profileIn();
// Printer may not be initialized if the extractRequestParams() fails for the main module
if (!isset ($this->mPrinter)) {
- $format = self :: API_DEFAULT_FORMAT;
- $this->mPrinter = new $this->mFormats[$format] ($this, $format);
+ $this->mPrinter = $this->createPrinterByName(self :: API_DEFAULT_FORMAT);
}
if ($e instanceof UsageException) {
$module = new $this->mModules[$action] ($this, $action);
if (!$this->mInternalMode) {
- if ($module instanceof ApiFormatBase) {
- // The requested module will print data in its own format
- $this->mPrinter = $module;
- } else {
+
+ // See if custom printer is used
+ $this->mPrinter = $module->getCustomFormatModule();
+
+ if (is_null($this->mPrinter)) {
// Create an appropriate printer
- $this->mPrinter = new $this->mFormats[$format] ($this, $format);
+ $this->mPrinter = $this->createPrinterByName($format);
}
}
$printer->initPrinter($isError);
if (!$printer->getNeedsRawData())
$this->getResult()->SanitizeData();
- $printer->executePrinter();
+ $printer->execute();
$printer->closePrinter();
$printer->profileOut();
}
}
$msg .= "\n$astriks Formats $astriks\n\n";
- foreach ($this->mFormats as $moduleName => $moduleClass) {
- $msg .= "* format=$moduleName *";
- $module = new $this->mFormats[$moduleName] ($this, $moduleName);
+ foreach ($this->mFormats as $formatName => $moduleClass) {
+ $msg .= "* format=$formatName *";
+ $module = $this->createPrinterByName($formatName);
$msg2 = $module->makeHelpMsg();
if ($msg2 !== false)
$msg .= $msg2;
require_once ("ApiFormatBase.php");
}
-class ApiOpenSearch extends ApiFormatBase {
+class ApiOpenSearch extends ApiBase {
- private $mResult = array();
-
public function __construct($main, $action) {
parent :: __construct($main, $action);
}
- public function getMimeType() {
- return 'application/json';
+ public function getCustomFormatModule() {
+ return $this->getMain()->createPrinterByName('json');
}
public function execute() {
$result->SanitizeData();
$data = $result->GetData();
- // Reformat useful data for future printing
- $result = array();
+ // Reformat useful data for future printing by JSON engine
+ $srchres = array();
foreach ($data['query']['allpages'] as $pageid => &$pageinfo) {
- $result[] = $pageinfo['title'];
+ $srchres[] = $pageinfo['title'];
}
- $this->mResult = array($command, $result);
+ // Set top level elements
+ $result = $this->getResult();
+ $result->addValue(null, 0, $command);
+ $result->addValue(null, 1, $srchres);
}
- public function executePrinter() {
- $json = new Services_JSON();
- $this->printText($json->encode($this->mResult, true));
- }
-
protected function GetAllowedParams() {
return array (
'command' => null
$pageids = array();
$remaining = array_flip($revids);
- $tables = array('page', 'revision');
+ $tables = array('revision');
$fields = array('rev_id','rev_page');
- $where = array( 'rev_deleted' => 0, 'rev_id' => $revids );
+ $where = array('rev_deleted' => 0, 'rev_id' => $revids);
// Get pageIDs data from the `page` table
$this->profileDBIn();
$options = array (
'LIMIT' => $limit +1,
- 'ORDER BY' => 'rc_timestamp' . ($dirNewer ? '' : ' DESC'),
- 'USE INDEX' => 'rc_timestamp');
+ 'ORDER BY' => 'rc_timestamp' . ($dirNewer ? '' : ' DESC'));
if (is_null($resultPageSet)) {
$fields = array (
$where[] = 'rc_this_oldid=page_latest';
if (isset ($namespace))
$where['wl_namespace'] = $namespace;
+
if (isset ($start))
- $where[] = 'rev_timestamp' . $after . $db->addQuotes($start);
+ $where[] = 'rc_timestamp' . $after . $db->addQuotes($start);
+
if (isset ($end))
- $where[] = 'rev_timestamp' . $before . $db->addQuotes($end);
+ $where[] = 'rc_timestamp' . $before . $db->addQuotes($end);
+
+ if (!isset ($start) && !isset ($end))
+ $where[] = "rc_timestamp > ''";
$this->profileDBIn();
$res = $db->select($tables, $fields, $where, __METHOD__, $options);
$data = & $this->getData();
- if (isset ($path)) {
+ if (!is_null($path)) {
if (is_array($path)) {
foreach ($path as $p) {
if (!isset ($data[$p]))