Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit 6f212c7

Browse files
committed
v0.5.1 Added limit to usedby query
1 parent 787cc21 commit 6f212c7

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ It takes two arguments :
7979

8080
**type** ( Query type, **version**, **documentation** or **usedby** )
8181

82+
**limit** ( only used with **usedby** )
8283
Example :
8384
```wikitext
8485
{{#w8y:action=extension

extension.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "WikiApiary",
3-
"version": "0.5.0",
3+
"version": "0.5.1",
44
"author": [
55
"[https://www.mediawiki.org/wiki/User:Cindy.cicalese Cindy Cicalese]"
66
],

includes/Scribunto/ScribuntoLuaLibrary.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,17 @@ public function w8y( ?array $arguments ): array {
4343
case "extension":
4444
$eName = Utils::getOptionSetting( 'Extension name', true, $arguments );
4545
$eType = Utils::getOptionSetting( 'type', true, $arguments );
46+
$limit = Utils::getOptionSetting( 'limit', true, $arguments );
4647
if ( $eName === null || $eType === null ) {
4748
return [];
4849
}
50+
if ( $limit === null ) {
51+
$limit = 10;
52+
} else {
53+
$limit = intval( trim( $limit ) );
54+
}
4955
$query = new Extensions();
50-
$result = $query->doQuery( $eName, $eType, 'lua' );
56+
$result = $query->doQuery( $eName, $eType, $limit, 'lua' );
5157
return [ $this->convertToLuaTable( $result ) ];
5258
case "wiki":
5359
$id = Utils::getOptionSetting( 'id', true, $arguments );
@@ -65,6 +71,8 @@ public function w8y( ?array $arguments ): array {
6571
$limit = Utils::getOptionSetting( 'limit', true, $arguments );
6672
if ( $limit === null ) {
6773
$limit = 10;
74+
} else {
75+
$limit = intval( trim( $limit ) );
6876
}
6977
$where = Utils::getOptionSetting( 'where', true, $arguments );
7078
if ( $where === null ) {

includes/TagHooks.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,17 @@ public function w8y( Parser &$parser ): mixed {
5151
case "extension":
5252
$eName = Utils::getOptionSetting( 'Extension name' );
5353
$eType = Utils::getOptionSetting( 'type' );
54+
$limit = Utils::getOptionSetting( 'limit' );
5455
if ( $eName === null || $eType === null ) {
5556
break;
5657
}
58+
if ( $limit === null ) {
59+
$limit = 10;
60+
} else {
61+
$limit = intval( trim( $limit ) );
62+
}
5763
$extension = new Extensions();
58-
$result = $extension->doQuery( $eName, $eType );
64+
$result = $extension->doQuery( $eName, $eType, $limit );
5965
break;
6066
case "query":
6167
$query = new Query();

includes/data/query/Extensions.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,12 @@ private function getExtensionDocumentation( string $extensionName, DBConnRef $db
117117

118118
/**
119119
* @param string $extensionName
120+
* @param int $limit
120121
* @param DBConnRef $dbr
121122
*
122123
* @return array
123124
*/
124-
private function getExtensionWiki( string $extensionName, DBConnRef $dbr ) {
125+
private function getExtensionWiki( string $extensionName, int $limit, DBConnRef $dbr ) {
125126
$select = [ Structure::WIKI_PAGEID ];
126127
$from = Structure::DBTABLE_WIKIS;
127128
$where = Structure::EXTENSION_NAME . ' LIKE "' . $extensionName . '"';
@@ -139,6 +140,7 @@ private function getExtensionWiki( string $extensionName, DBConnRef $dbr ) {
139140
leftJoin( Structure::DBTABLE_EXTENSIONS_LINK, null, Structure::DBTABLE_SCRAPE . '.' . Structure::SCRAPE_VR_ID . '=' . Structure::DBTABLE_EXTENSIONS_LINK . '.' . Structure::EXTENSION_LINK_VID )->
140141
leftJoin( Structure::DBTABLE_EXTENSIONS, null, Structure::DBTABLE_EXTENSIONS_LINK . '.' . Structure::EXTENSION_LINK_ID . '=' . Structure::DBTABLE_EXTENSIONS . '.' . Structure::EXTENSION_ID )->
141142
where( $where )->
143+
limit( $limit )->
142144
caller( __METHOD__ )->
143145
fetchResultSet();
144146
} catch ( \Exception $e ) {
@@ -174,11 +176,12 @@ private function getPageTitleFromId( int $id ): string {
174176
/**
175177
* @param string $extensionName
176178
* @param string $queryType
179+
* @param int $limit
177180
* @param string $export
178181
*
179182
* @return mixed
180183
*/
181-
public function doQuery( string $extensionName, string $queryType, string $export = "table" ): mixed {
184+
public function doQuery( string $extensionName, string $queryType, int $limit, string $export = "table" ): mixed {
182185
$lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
183186
$dbr = $lb->getConnectionRef( DB_REPLICA );
184187
$result = [];
@@ -198,7 +201,7 @@ public function doQuery( string $extensionName, string $queryType, string $expor
198201
];
199202
break;
200203
case "usedby":
201-
$result = $this->getExtensionWiki( $extensionName, $dbr );
204+
$result = $this->getExtensionWiki( $extensionName, $limit, $dbr );
202205
$tables = [ Structure::w8yMessage( Structure::WIKI_PAGEID ),
203206
Structure::w8yMessage( 'w8y_pageTitle' )
204207
];

0 commit comments

Comments
 (0)