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

Commit 08fd3c7

Browse files
committed
Added docurl query for extensions. Fixed Lua argument version -> type
1 parent f679cae commit 08fd3c7

File tree

4 files changed

+66
-8
lines changed

4 files changed

+66
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ It takes two arguments :
7777

7878
**Extension name** ( Name of the extension to query )
7979

80-
**type** ( Query type, currenly only **version** is supported )
80+
**type** ( Query type, **version** or **documentation** )
8181

8282
Example :
8383
```wikitext

includes/Scribunto/ScribuntoLuaLibrary.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ public function w8y( ?array $arguments ): array {
4242
switch ( $action ) {
4343
case "extension":
4444
$eName = Utils::getOptionSetting( 'Extension name', true, $arguments );
45-
$eVersion = Utils::getOptionSetting( 'version', true, $arguments );
46-
if ( $eName === null || $eVersion === null ) {
45+
$eType = Utils::getOptionSetting( 'type', true, $arguments );
46+
if ( $eName === null || $eType === null ) {
4747
return [];
4848
}
4949
$query = new Extensions();
50-
$result = $query->doQuery( $eName, $eVersion, 'lua' );
50+
$result = $query->doQuery( $eName, $eType, 'lua' );
5151
return [ $this->convertToLuaTable( $result ) ];
5252
case "wiki":
5353
$id = Utils::getOptionSetting( 'id', true, $arguments );

includes/data/Structure.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Structure {
3232
public const EXTENSION_ID = 'w8y_ed_ed_id';
3333
public const EXTENSION_NAME = 'w8y_ed_name';
3434
public const EXTENSION_VERSION = 'w8y_ed_version';
35+
public const EXTENSION_DOC_URL = 'w8y_ed_doc_url';
3536
public const EXTENSION_LINK_VID = 'w8y_el_vr_id';
3637
public const EXTENSION_LINK_ID = 'w8y_el_ed_id';
3738
public const SKIN_LINK_VID = 'w8y_sl_vr_id';

includes/data/query/Extensions.php

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,57 @@ private function getExtensionVersions( string $extensionName, DBConnRef $dbr ) {
5656
$t = 0;
5757
if ( $res->numRows() > 0 ) {
5858
while ( $row = $res->fetchRow() ) {
59-
$ret[$t]['w8y_ed_version'] = $row[Structure::EXTENSION_VERSION];
59+
$ret[$t][Structure::EXTENSION_VERSION] = $row[Structure::EXTENSION_VERSION];
60+
$ret[$t]['w8y_count'] = $row['count'];
61+
$t++;
62+
}
63+
}
64+
65+
return $ret;
66+
}
67+
68+
/**
69+
* @param string $extensionName
70+
* @param DBConnRef $dbr
71+
*
72+
* @return array
73+
*/
74+
private function getExtensionDocumentation( string $extensionName, DBConnRef $dbr ) {
75+
$select = [ Structure::EXTENSION_DOC_URL, 'count' => 'count(*)' ];
76+
$from = Structure::DBTABLE_WIKIS;
77+
$where = Structure::EXTENSION_NAME . ' LIKE "' . $extensionName . '" AND ';
78+
$where .= Structure::EXTENSION_DOC_URL . ' IS NOT NULL';
79+
// SELECT w8y_ed_doc_url,
80+
// COUNT(*) AS C
81+
// FROM w8y_wikis
82+
// JOIN w8y_scrape_records ON w8y_wi_last_sr_id = w8y_sr_sr_id
83+
// JOIN w8y_extension_links ON w8y_sr_vr_id = w8y_el_vr_id
84+
// JOIN w8y_extension_data ON w8y_el_ed_id = w8y_ed_ed_id
85+
// WHERE w8y_ed_name like "ParserFunctions"
86+
// AND w8y_ed_doc_url IS NOT NULL
87+
// GROUP BY w8y_ed_doc_url
88+
// ORDER BY C DESC;
89+
try {
90+
$res = $dbr->newSelectQueryBuilder()->
91+
select( $select )->
92+
from( $from )->
93+
leftJoin( Structure::DBTABLE_SCRAPE, null, Structure::DBTABLE_WIKIS . '.' . Structure::WIKI_LAST_SR_RCRD . '=' . Structure::DBTABLE_SCRAPE . '.' . Structure::SR_ID )->
94+
leftJoin( Structure::DBTABLE_EXTENSIONS_LINK, null, Structure::DBTABLE_SCRAPE . '.' . Structure::SCRAPE_VR_ID . '=' . Structure::DBTABLE_EXTENSIONS_LINK . '.' . Structure::EXTENSION_LINK_VID )->
95+
leftJoin( Structure::DBTABLE_EXTENSIONS, null, Structure::DBTABLE_EXTENSIONS_LINK . '.' . Structure::EXTENSION_LINK_ID . '=' . Structure::DBTABLE_EXTENSIONS . '.' . Structure::EXTENSION_ID )->
96+
where( $where )->
97+
groupBy( Structure::EXTENSION_DOC_URL )->
98+
orderBy( 'count', 'DESC' )->
99+
caller( __METHOD__ )->
100+
fetchResultSet();
101+
} catch ( \Exception $e ) {
102+
wfDebug( $e->getMessage(), 'w8y' );
103+
return [];
104+
}
105+
$ret = [];
106+
$t = 0;
107+
if ( $res->numRows() > 0 ) {
108+
while ( $row = $res->fetchRow() ) {
109+
$ret[$t][Structure::EXTENSION_DOC_URL] = $row[Structure::EXTENSION_DOC_URL];
60110
$ret[$t]['w8y_count'] = $row['count'];
61111
$t++;
62112
}
@@ -76,20 +126,27 @@ public function doQuery( string $extensionName, string $queryType, string $expor
76126
$lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
77127
$dbr = $lb->getConnectionRef( DB_REPLICA );
78128
$result = [];
129+
$tables = [];
79130

80131
switch ( $queryType ) {
81132
case "version":
82133
$result = $this->getExtensionVersions( $extensionName, $dbr );
134+
$tables = [ Structure::w8yMessage( Structure::EXTENSION_VERSION ),
135+
Structure::w8yMessage( 'w8y_count' )
136+
];
137+
break;
138+
case "documentation":
139+
$result = $this->getExtensionDocumentation( $extensionName, $dbr );
140+
$tables = [ Structure::w8yMessage( Structure::EXTENSION_DOC_URL ),
141+
Structure::w8yMessage( 'w8y_count' )
142+
];
83143
break;
84144
default:
85145
$result = [];
86146
}
87147

88148
switch ( $export ) {
89149
case "table":
90-
$tables = [ Structure::w8yMessage( Structure::EXTENSION_VERSION ),
91-
Structure::w8yMessage( 'w8y_count' )
92-
];
93150
return Utils::renderTable( $result, '', $tables, true );
94151
case "arrayfunctions":
95152
return [ Utils::exportArrayFunction( $result ), 'nowiki' => true ];

0 commit comments

Comments
 (0)