diff --git a/CHANGELOG.md b/CHANGELOG.md index 681809a..de74546 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ This changelog only shows recent version history, because of the lack of documentation from the former maintainers. The very first changelog (1.0.2) is likely incomplete. ## Version 2 +### 2.0.1 +* New offset parameter in oredictsearch for continuation (#34). +* oredictsearch no longer sorts by entry ID as the key; it is now an array of hashes. +* oredictentry and oredictsearch now return the entry ID with the rest of the data. +* Fix oredictsearch registration in the entry point (not the extension.json) +* Improve oredictsearch API query. +* Fix oredictsearch limit issues (#35). +* Fix oredictsearch +* Clean up database things and improve security. + ### 2.0.0 * Fix OreDict entry shuffling and page loading issues related to that. * Database sanitization issues that could later turn into security holes. diff --git a/OreDict.body.php b/OreDict.body.php index 6f18973..2f2dcf0 100755 --- a/OreDict.body.php +++ b/OreDict.body.php @@ -472,6 +472,7 @@ static public function getArrayFromRow($row) { 'item_name' => $row->item_name, 'grid_params' => $row->grid_params, 'flags' => $row->flags, + 'id' => $row->entry_id ); } } diff --git a/OreDict.php b/OreDict.php index c186ab4..cec2fd7 100755 --- a/OreDict.php +++ b/OreDict.php @@ -4,7 +4,7 @@ * * @file * @ingroup Extensions - * @version 2.0.0 + * @version 2.0.1 * @author Jinbobo * @license */ @@ -18,7 +18,7 @@ 'path' => __FILE__, 'name' => 'OreDict', 'descriptionmsg' => 'oredict-desc', - 'version' => '2.0.0', + 'version' => '2.0.1', 'author' => '[http://ftb.gamepedia.com/User:Jinbobo Jinbobo], Telshin, [http://ftb.gamepedia.com/User:Retep998 Retep998], [http://ftb.gamepedia.com/User:TheSatanicSanta SatanicSanta], noahm', 'url' => 'http://help.gamepedia.com/Extension:OreDict' ); @@ -40,7 +40,7 @@ $wgAutoloadClasses['OreDictQueryEntryApi'] = __DIR__ . '/api/OreDictQueryEntryApi.php'; $wgAPIPropModules['oredictentry'] = 'OreDictQueryEntryApi'; $wgAutoloadClasses['OreDictQuerySearchApi'] = __DIR__ . '/api/OreDictQuerySearchApi.php'; -$wgApiListClasses['oredictsearch'] = 'OreDictQuerySearchApi'; +$wgAPIListModules['oredictsearch'] = 'OreDictQuerySearchApi'; $wgAutoloadClasses['OreDict'] = dirname(__FILE__)."/OreDict.body.php"; $wgAutoloadClasses['OreDictItem'] = dirname(__FILE__)."/OreDict.body.php"; diff --git a/api/OreDictQuerySearchApi.php b/api/OreDictQuerySearchApi.php index 5eda0a1..4fc5462 100644 --- a/api/OreDictQuerySearchApi.php +++ b/api/OreDictQuerySearchApi.php @@ -30,6 +30,11 @@ public function getAllowedParams() { ApiBase::PARAM_TYPE => 'string', ApiBase::PARAM_DFLT => '', ), + 'offset' => array( + ApiBase::PARAM_TYPE => 'integer', + ApiBase::PARAM_DFLT => 0, + ApiBase::PARAM_MIN => 0, + ) ); } @@ -40,6 +45,7 @@ public function getParamDescription() { 'mod' => 'Restricts results to this mod', 'tag' => 'Restricts results to this tag name', 'name' => 'Restricts results to this item name', + 'offset' => 'The query offset, like a continue param.' ); } @@ -60,63 +66,52 @@ public function execute() { $mod = $this->getParameter('mod'); $name = $this->getParameter('name'); $limit = $this->getParameter('limit'); + $offset = $this->getParameter('offset'); $dbr = wfGetDB(DB_SLAVE); - $resultPrefix = $dbr->select( - 'ext_oredict_items', - '*', - array('item_name BETWEEN '.$dbr->addQuotes($prefix)." AND 'zzzzzzzz'"), - __METHOD__, - array('LIMIT' => $limit) - ); - $resultTag = $dbr->select( - 'ext_oredict_items', - '*', - array('tag_name' => $tag), - __METHOD__, - array('LIMIT' => $limit) - ); - $resultMod = $dbr->select( - 'ext_oredict_items', - '*', - array('mod_name' => $mod), - __METHOD__, - array('Limit' => $limit) - ); - $resultName = $dbr->select( + $conditions = array(); + if ($prefix != '') { + $conditions[] = 'item_name BETWEEN ' . $dbr->addQuotes($prefix) . " AND 'zzzzzzzzz'"; + } + if ($tag != '') { + $conditions['tag_name'] = $tag; + } + if ($mod != '') { + $conditions['mod_name'] = $mod; + } + if ($name != '') { + $conditions['item_name'] = $name; + } + + $results = $dbr->select( 'ext_oredict_items', '*', - array('item_name' => $name), - __METHOD__, - array('LIMIT' => $limit) + $conditions, + __METHOD__ ); $ret = array(); - if ($resultTag->numRows() > 0) { - foreach ($resultTag as $row) { - $ret[$row->entry_id] = OreDict::getArrayFromRow($row); - } - } - - if ($resultMod->numRows() > 0) { - foreach ($resultMod as $row) { - $ret[$row->entry_id] = OreDict::getArrayFromRow($row); + $i = 0; + $more = $results->numRows() - $offset > $limit; + if ($results->numRows() > 0) { + foreach ($results as $row) { + if ($i < $offset) { + $i++; + continue; + } + if (count($ret) < $limit) { + $i++; + $ret[] = OreDict::getArrayFromRow($row); + } } } - if ($resultName->numRows() > 0) { - foreach ($resultName as $row) { - $ret[$row->entry_id] = OreDict::getArrayFromRow($row); - } - } - - if ($resultPrefix->numRows() > 0) { - foreach ($resultPrefix as $row) { - $ret[$row->entry_id] = OreDict::getArrayFromRow($row); - } + if ($more) { + $this->getResult()->addValue('continue', 'offset', $i); } + $this->getResult()->addValue('query', 'totalhits', $results->numRows()); $this->getResult()->addValue('query', 'oredictentries', $ret); } -} \ No newline at end of file +} diff --git a/extension.json b/extension.json index 43ec211..d2c97ff 100644 --- a/extension.json +++ b/extension.json @@ -1,6 +1,6 @@ { "name": "OreDict", - "version": "2.0.0", + "version": "2.0.1", "author": "[http://ftb.gamepedia.com/User:Jinbobo Jinbobo], Telshin, [http://ftb.gamepedia.com/User:Retep998 Retep998], [http://ftb.gamepedia.com/User:TheSatanicSanta Eli Foster], noahm, applehat", "url": "http://help.gamepedia.com/Extension:OreDict", "descriptionmsg": "oredict-desc",