@@ -27,31 +27,20 @@ class TagHooks {
2727 private array $ parameters ;
2828
2929 /**
30- * @param Parser &$parser
30+ * @param array $parameters
3131 *
32- * @return mixed
32+ * @return array|string[]
3333 */
34- public function w8y ( Parser &$ parser ): mixed {
35- // First set global debug status
36- $ config = MediaWikiServices::getInstance ()->getMainConfig ();
37- if ( $ config ->has ( 'WikiApiary ' ) ) {
38- $ w8yConfig = $ config ->get ( 'WikiApiary ' );
39- DBHooks::$ debug = $ w8yConfig ['debug ' ];
40- } else {
41- DBHooks::$ debug = false ;
42- }
43-
34+ public static function handleIt ( array $ parameters ): array {
35+ $ action = Utils::getOptionSetting ( 'action ' , true , $ parameters );
36+ $ limit = Utils::getOptionSetting ( 'limit ' , true , $ parameters );
37+ $ format = Utils::getOptionSetting ( 'format ' , true , $ parameters );
4438 $ result = '' ;
45- Utils::$ parameters = $ this ->extractOptions ( array_slice ( func_get_args (),
46- 1 ) );
47- $ action = Utils::getOptionSetting ( 'action ' );
48- $ limit = Utils::getOptionSetting ( 'limit ' );
49- $ format = Utils::getOptionSetting ( 'format ' );
5039 switch ( $ action ) {
5140 case "extension " :
52- $ eName = Utils::getOptionSetting ( 'Extension name ' );
53- $ eType = Utils::getOptionSetting ( 'type ' );
54- $ limit = Utils::getOptionSetting ( 'limit ' );
41+ $ eName = Utils::getOptionSetting ( 'Extension name ' , true , $ parameters );
42+ $ eType = Utils::getOptionSetting ( 'type ' , true , $ parameters );
43+ $ limit = Utils::getOptionSetting ( 'limit ' , true , $ parameters );
5544 if ( $ eName === null || $ eType === null ) {
5645 break ;
5746 }
@@ -65,19 +54,17 @@ public function w8y( Parser &$parser ): mixed {
6554 break ;
6655 case "query " :
6756 $ query = new Query ();
68- $ get = Utils::getOptionSetting ( 'return ' );
69- $ table = Utils::getOptionSetting ( 'from ' );
70- $ where = Utils::getOptionSetting ( 'where ' );
57+ $ get = Utils::getOptionSetting ( 'return ' , true , $ parameters );
58+ $ table = Utils::getOptionSetting ( 'from ' , true , $ parameters );
59+ $ where = Utils::getOptionSetting ( 'where ' , true , $ parameters );
7160 $ result = $ query ->doQuery ( $ get ,
7261 $ table ,
7362 $ where ,
7463 $ limit ,
7564 $ format );
76- ResponseHandler::printDebugMessage ( $ result ,
77- "sql result " );
7865 break ;
7966 case "wiki " :
80- $ pId = Utils::getOptionSetting ( 'pageId ' );
67+ $ pId = Utils::getOptionSetting ( 'pageId ' , true , $ parameters );
8168 if ( $ pId === null ) {
8269 ResponseHandler::addMessage ( wfMessage ( 'w8y_missing-page-id ' )->text () );
8370 } else {
@@ -86,13 +73,11 @@ public function w8y( Parser &$parser ): mixed {
8673 $ format = 'table ' ;
8774 }
8875 $ result = $ query ->doQuery ( intval ( $ pId ), $ format );
89- ResponseHandler::printDebugMessage ( $ result ,
90- "sql result " );
9176 }
9277 break ;
9378 case "stats " :
94- $ type = Utils::getOptionSetting ( 'for ' );
95- $ where = Utils::getOptionSetting ( 'where ' );
79+ $ type = Utils::getOptionSetting ( 'for ' , true , $ parameters );
80+ $ where = Utils::getOptionSetting ( 'where ' , true , $ parameters );
9681 if ( $ limit === null ) {
9782 $ limit = 10 ;
9883 }
@@ -105,23 +90,41 @@ public function w8y( Parser &$parser ): mixed {
10590 $ format = 'table ' ;
10691 }
10792 $ result = $ query ->doQuery ( $ type , $ where , $ limit , $ format );
108- ResponseHandler::printDebugMessage ( $ result ,
109- "sql result " );
11093 }
11194 break ;
11295 case "addToDB " :
11396 break ;
11497 }
11598 if ( !empty ( ResponseHandler::getMessages () ) ) {
116- return ResponseHandler::getMessages ();
117- } elseif ( is_array ( $ result ) ) {
118- return "<pre> " . print_r ( $ result ,
119- true ) . "</pre> " ;
99+ return [ 'status ' => 'error ' , 'data ' => ResponseHandler::getMessages () ];
100+ } elseif ( is_array ( $ result ) && $ format !== 'json ' ) {
101+ return [ 'status ' => 'error ' , 'data ' => "<pre> " . print_r ( $ result , true ) . "</pre> " ];
120102 } else {
121- return $ result ;
103+ return [ ' status ' => ' ok ' , ' data ' => $ result ] ;
122104 }
123105 }
124106
107+ /**
108+ * @param Parser &$parser
109+ *
110+ * @return mixed
111+ */
112+ public function w8y ( Parser &$ parser ): mixed {
113+ // First set global debug status
114+ $ config = MediaWikiServices::getInstance ()->getMainConfig ();
115+ if ( $ config ->has ( 'WikiApiary ' ) ) {
116+ $ w8yConfig = $ config ->get ( 'WikiApiary ' );
117+ DBHooks::$ debug = $ w8yConfig ['debug ' ];
118+ } else {
119+ DBHooks::$ debug = false ;
120+ }
121+
122+ $ parameters = $ this ->extractOptions ( array_slice ( func_get_args (), 1 ) );
123+ Utils::$ parameters = $ parameters ;
124+ $ result = self ::handleIt ( $ parameters );
125+ return $ result ['data ' ];
126+ }
127+
125128 /**
126129 * Converts an array of values in form [0] => "name=value" into a real associative array in form [name] => value.
127130 * If no "=" is provided, true is assumed like this: [name] => true.
0 commit comments