Index: trunk/phase3/includes/api/ApiFormatXml.php |
— | — | @@ -43,7 +43,7 @@ |
44 | 44 | return true; |
45 | 45 | } |
46 | 46 | |
47 | | - public function executePrinter() { |
| 47 | + public function execute() { |
48 | 48 | $xmlindent = null; |
49 | 49 | extract($this->extractRequestParams()); |
50 | 50 | |
Index: trunk/phase3/includes/api/ApiBase.php |
— | — | @@ -91,6 +91,15 @@ |
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
| 95 | + * If the module may only be used with a certain format module, |
| 96 | + * it should override this method to return an instance of that formatter. |
| 97 | + * A value of null means the default format will be used. |
| 98 | + */ |
| 99 | + public function getCustomFormatModule() { |
| 100 | + return null; |
| 101 | + } |
| 102 | + |
| 103 | + /** |
95 | 104 | * Generates help message for this module, or false if there is no description |
96 | 105 | */ |
97 | 106 | public function makeHelpMsg() { |
Index: trunk/phase3/includes/api/ApiFormatYaml.php |
— | — | @@ -39,7 +39,7 @@ |
40 | 40 | return 'application/yaml'; |
41 | 41 | } |
42 | 42 | |
43 | | - public function executePrinter() { |
| 43 | + public function execute() { |
44 | 44 | $this->printText(Spyc :: YAMLDump($this->getResultData())); |
45 | 45 | } |
46 | 46 | |
Index: trunk/phase3/includes/api/ApiResult.php |
— | — | @@ -105,7 +105,7 @@ |
106 | 106 | |
107 | 107 | $data = & $this->getData(); |
108 | 108 | |
109 | | - if (isset ($path)) { |
| 109 | + if (!is_null($path)) { |
110 | 110 | if (is_array($path)) { |
111 | 111 | foreach ($path as $p) { |
112 | 112 | if (!isset ($data[$p])) |
Index: trunk/phase3/includes/api/ApiFormatJson.php |
— | — | @@ -39,7 +39,7 @@ |
40 | 40 | return 'application/json'; |
41 | 41 | } |
42 | 42 | |
43 | | - public function executePrinter() { |
| 43 | + public function execute() { |
44 | 44 | $json = new Services_JSON(); |
45 | 45 | $this->printText($json->encode($this->getResultData(), true)); |
46 | 46 | } |
Index: trunk/phase3/includes/api/ApiFormatBase.php |
— | — | @@ -54,15 +54,6 @@ |
55 | 55 | */ |
56 | 56 | public abstract function getMimeType(); |
57 | 57 | |
58 | | - public function execute() { |
59 | | - ApiBase :: dieDebug(__METHOD__, 'This is not an executable module'); |
60 | | - } |
61 | | - |
62 | | - /** |
63 | | - * Format modules must override this method to implement actual printing |
64 | | - */ |
65 | | - public abstract function executePrinter(); |
66 | | - |
67 | 58 | public function getNeedsRawData() { |
68 | 59 | return false; |
69 | 60 | } |
Index: trunk/phase3/includes/api/ApiMain.php |
— | — | @@ -101,6 +101,10 @@ |
102 | 102 | $this->dieUsage('Editing of this site is disabled. Make sure the $wgEnableWriteAPI=true; ' . |
103 | 103 | 'statement is included in the site\'s LocalSettings.php file', 'readonly'); |
104 | 104 | } |
| 105 | + |
| 106 | + public function createPrinterByName($format) { |
| 107 | + return new $this->mFormats[$format] ($this, $format); |
| 108 | + } |
105 | 109 | |
106 | 110 | public function execute() { |
107 | 111 | $this->profileIn(); |
— | — | @@ -128,8 +132,7 @@ |
129 | 133 | |
130 | 134 | // Printer may not be initialized if the extractRequestParams() fails for the main module |
131 | 135 | if (!isset ($this->mPrinter)) { |
132 | | - $format = self :: API_DEFAULT_FORMAT; |
133 | | - $this->mPrinter = new $this->mFormats[$format] ($this, $format); |
| 136 | + $this->mPrinter = $this->createPrinterByName(self :: API_DEFAULT_FORMAT); |
134 | 137 | } |
135 | 138 | |
136 | 139 | if ($e instanceof UsageException) { |
— | — | @@ -183,12 +186,13 @@ |
184 | 187 | $module = new $this->mModules[$action] ($this, $action); |
185 | 188 | |
186 | 189 | if (!$this->mInternalMode) { |
187 | | - if ($module instanceof ApiFormatBase) { |
188 | | - // The requested module will print data in its own format |
189 | | - $this->mPrinter = $module; |
190 | | - } else { |
| 190 | + |
| 191 | + // See if custom printer is used |
| 192 | + $this->mPrinter = $module->getCustomFormatModule(); |
| 193 | + |
| 194 | + if (is_null($this->mPrinter)) { |
191 | 195 | // Create an appropriate printer |
192 | | - $this->mPrinter = new $this->mFormats[$format] ($this, $format); |
| 196 | + $this->mPrinter = $this->createPrinterByName($format); |
193 | 197 | } |
194 | 198 | } |
195 | 199 | |
— | — | @@ -212,7 +216,7 @@ |
213 | 217 | $printer->initPrinter($isError); |
214 | 218 | if (!$printer->getNeedsRawData()) |
215 | 219 | $this->getResult()->SanitizeData(); |
216 | | - $printer->executePrinter(); |
| 220 | + $printer->execute(); |
217 | 221 | $printer->closePrinter(); |
218 | 222 | $printer->profileOut(); |
219 | 223 | } |
— | — | @@ -268,9 +272,9 @@ |
269 | 273 | } |
270 | 274 | |
271 | 275 | $msg .= "\n$astriks Formats $astriks\n\n"; |
272 | | - foreach ($this->mFormats as $moduleName => $moduleClass) { |
273 | | - $msg .= "* format=$moduleName *"; |
274 | | - $module = new $this->mFormats[$moduleName] ($this, $moduleName); |
| 276 | + foreach ($this->mFormats as $formatName => $moduleClass) { |
| 277 | + $msg .= "* format=$formatName *"; |
| 278 | + $module = $this->createPrinterByName($formatName); |
275 | 279 | $msg2 = $module->makeHelpMsg(); |
276 | 280 | if ($msg2 !== false) |
277 | 281 | $msg .= $msg2; |
Index: trunk/phase3/includes/api/ApiOpenSearch.php |
— | — | @@ -29,16 +29,14 @@ |
30 | 30 | require_once ("ApiFormatBase.php"); |
31 | 31 | } |
32 | 32 | |
33 | | -class ApiOpenSearch extends ApiFormatBase { |
| 33 | +class ApiOpenSearch extends ApiBase { |
34 | 34 | |
35 | | - private $mResult = array(); |
36 | | - |
37 | 35 | public function __construct($main, $action) { |
38 | 36 | parent :: __construct($main, $action); |
39 | 37 | } |
40 | 38 | |
41 | | - public function getMimeType() { |
42 | | - return 'application/json'; |
| 39 | + public function getCustomFormatModule() { |
| 40 | + return $this->getMain()->createPrinterByName('json'); |
43 | 41 | } |
44 | 42 | |
45 | 43 | public function execute() { |
— | — | @@ -63,20 +61,18 @@ |
64 | 62 | $result->SanitizeData(); |
65 | 63 | $data = $result->GetData(); |
66 | 64 | |
67 | | - // Reformat useful data for future printing |
68 | | - $result = array(); |
| 65 | + // Reformat useful data for future printing by JSON engine |
| 66 | + $srchres = array(); |
69 | 67 | foreach ($data['query']['allpages'] as $pageid => &$pageinfo) { |
70 | | - $result[] = $pageinfo['title']; |
| 68 | + $srchres[] = $pageinfo['title']; |
71 | 69 | } |
72 | 70 | |
73 | | - $this->mResult = array($command, $result); |
| 71 | + // Set top level elements |
| 72 | + $result = $this->getResult(); |
| 73 | + $result->addValue(null, 0, $command); |
| 74 | + $result->addValue(null, 1, $srchres); |
74 | 75 | } |
75 | 76 | |
76 | | - public function executePrinter() { |
77 | | - $json = new Services_JSON(); |
78 | | - $this->printText($json->encode($this->mResult, true)); |
79 | | - } |
80 | | - |
81 | 77 | protected function GetAllowedParams() { |
82 | 78 | return array ( |
83 | 79 | 'command' => null |
Index: trunk/phase3/includes/api/ApiPageSet.php |
— | — | @@ -385,9 +385,9 @@ |
386 | 386 | $pageids = array(); |
387 | 387 | $remaining = array_flip($revids); |
388 | 388 | |
389 | | - $tables = array('page', 'revision'); |
| 389 | + $tables = array('revision'); |
390 | 390 | $fields = array('rev_id','rev_page'); |
391 | | - $where = array( 'rev_deleted' => 0, 'rev_id' => $revids ); |
| 391 | + $where = array('rev_deleted' => 0, 'rev_id' => $revids); |
392 | 392 | |
393 | 393 | // Get pageIDs data from the `page` table |
394 | 394 | $this->profileDBIn(); |
Index: trunk/phase3/includes/api/ApiQueryWatchlist.php |
— | — | @@ -66,8 +66,7 @@ |
67 | 67 | |
68 | 68 | $options = array ( |
69 | 69 | 'LIMIT' => $limit +1, |
70 | | - 'ORDER BY' => 'rc_timestamp' . ($dirNewer ? '' : ' DESC'), |
71 | | - 'USE INDEX' => 'rc_timestamp'); |
| 70 | + 'ORDER BY' => 'rc_timestamp' . ($dirNewer ? '' : ' DESC')); |
72 | 71 | |
73 | 72 | if (is_null($resultPageSet)) { |
74 | 73 | $fields = array ( |
— | — | @@ -111,10 +110,15 @@ |
112 | 111 | $where[] = 'rc_this_oldid=page_latest'; |
113 | 112 | if (isset ($namespace)) |
114 | 113 | $where['wl_namespace'] = $namespace; |
| 114 | + |
115 | 115 | if (isset ($start)) |
116 | | - $where[] = 'rev_timestamp' . $after . $db->addQuotes($start); |
| 116 | + $where[] = 'rc_timestamp' . $after . $db->addQuotes($start); |
| 117 | + |
117 | 118 | if (isset ($end)) |
118 | | - $where[] = 'rev_timestamp' . $before . $db->addQuotes($end); |
| 119 | + $where[] = 'rc_timestamp' . $before . $db->addQuotes($end); |
| 120 | + |
| 121 | + if (!isset ($start) && !isset ($end)) |
| 122 | + $where[] = "rc_timestamp > ''"; |
119 | 123 | |
120 | 124 | $this->profileDBIn(); |
121 | 125 | $res = $db->select($tables, $fields, $where, __METHOD__, $options); |