@@ -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