[19:54:49] @reception123 do you want me to reopen the task w/ the MDN status cause i realize now the task was meant for the parent idea of closing requests :p [20:01:15] also: @originalauthority happy now? PHPStorm [20:01:17] https://cdn.discordapp.com/attachments/1006789349498699827/1230971504376938496/dEHPIsa.png?ex=6635428c&is=6622cd8c&hm=3b801542797b837390fb904783f2bdcf309b6a57dc502c230e2ca2b4ff7f7c25& [20:01:52] Ah my old faithful [20:02:30] Github education license go br [20:02:42] this counts as educational right? [20:04:01] It's cloudseeding time [20:04:06] CloudFlare my beloved [20:04:19] is intellisense for mw classes a thing for phpstorm [20:04:25] <3 [20:04:26] yes [20:06:04] If you install intellephense or whatever it is [20:06:18] [yes_honey](https://cdn.discordapp.com/emojis/1121176745777836123.webp?size=48&quality=lossless&name=yes_honey) [20:06:19] Once phpstorm indexes the project it will give recommendations, throw errors etc in the edito [20:06:24] whuch button is that [20:07:57] eh [20:08:13] it should index it as soon as you open the project [20:08:18] but idk if it works for wsl [20:09:01] well I opened the extension directory [20:15:54] how do indexz [20:28:53] idk it does it automatically for me [20:29:00] theres a button for it somewhere [21:27:13] erm how does on make an edit to a page in extensions code [21:27:29] I have no idea where to look on mw.org(im stoopid) [21:33:57] eh [21:34:58] post your edit to the apu [21:35:02] api* [21:39:18] ah okay. what if i want to attribute the edit to a user on their behalf(which thinking now may not be a great idea) but either way it would need to have a system account to make the edit [21:40:20] as far as I'm aware you don't need to worry about that, MediaWiki will handle all of that when it arrives at the API from the session variables. [21:41:20] yeah you need to first obtain a csrf token and then just post to the "edit" api and mediawiki will handle the rest. [21:42:12] in a php backend extension? [21:42:18] for reference https://www.mediawiki.org/wiki/API:Edit looks like you can do it in php but its a bit messy ( I don't really like CURL, maybe guzzle would work if you really want to do it in the extension php, but its probably easier to use JS and thats the way I think most people do it) [21:42:30] thought it would me more like the add a block process [21:42:34] yes because if the post is being done in JS its running on the front end [21:43:03] its not really js [21:43:17] oh [21:43:20] you can do [21:43:20] the js is only for a color picker, the post data being sent is the values [21:43:41] my plan is to save the color values on a Mediawiki:smtsmt.json page [21:43:46] [1/2] `ContentHandler::makeContent( $text, $title)` like done in the maintenance script: [21:43:46] [2/2] https://phabricator.wikimedia.org/source/mediawiki/browse/REL1_41/maintenance/edit.php [21:44:05] would that work with different content models as well? [21:44:54] theoretically, I think so [21:47:03] I think if you were to specify the page as MediaWiki:Colours.json or something, then mediawiki would be smart enough when it saves the page to the database to select the appropriate content model [21:48:47] would prob have to make the- [21:48:48] wait [21:48:57] how the hell do you even work with JSON in PHP [21:49:23] `json_encode_ and `json_decode_ [21:49:53] strings or arrays? [21:49:58] wdym? [21:50:18] does it take in and produce a strong or does it convert php arrays [21:50:35] `json_encode` will take either a string or an array [21:51:03] I think? I've never tested it with a string because idk why you'd want to encode a string to json [21:51:26] XSS, obviously [21:52:13] [1/8] so you would need to build the array something like [21:52:14] [2/8] ```php [21:52:14] [3/8] $colours = [ [21:52:14] [4/8] 'black' => '#000', [21:52:15] [5/8] 'white' => '#fff' [21:52:15] [6/8] ]; [21:52:15] [7/8] $enc_colour = json_encode( $colours ); [21:52:16] [8/8] ``` [21:52:35] and then probably do some validation that what you have ended up with is actually json [21:53:19] actually you probably don't need to do that validation until you're reverting it back to an array [21:53:50] PHP 8.3 introduces `json_validate` which is a nice feature I'm excited for [21:57:21] [1/7] my idea is smt like ```php [21:57:22] [2/7] $colours = [ [21:57:22] [3/7] 'baselinkcolor' => $data['baselinkcolor'], [21:57:22] [4/7] 'visitedlinkcolor' => $data['visitedlinkcolor'], [21:57:23] [5/7] ]; [21:57:23] [6/7] ...``` [21:57:23] [7/7] with value validation via the method HTMLForms provides so im not entirely sure how needed validation of the json is [21:57:42] to be frank if i add it is gonna prob depend on how easy it is [21:57:47] [Bearerofthecurse](https://cdn.discordapp.com/emojis/1164188084754206731.webp?size=48&quality=lossless&name=Bearerofthecurse) [21:58:14] yeah that was my bad you don't need to validate after json_encode, only when using json_decode [21:58:39] tru [21:59:27] [1/6] also the validation is pretty easy its just something like [21:59:27] [2/6] ```php [21:59:27] [3/6] public function isValid( $colours ): boolean { [21:59:28] [4/6] json_decode( $colours ); [21:59:28] [5/6] return json_last_error() === JSON_ERROR_NONE; [21:59:28] [6/6] } [21:59:29] also need to validate the values since its a page its getting css values from [21:59:37] or i could [21:59:38] like [21:59:51] HTML form has a validation callback I think? [21:59:54] use a hook to 1984 edits on the page by users at all [21:59:58] hai [22:00:34] let me find it [22:01:07] https://www.mediawiki.org/wiki/Manual:HTMLForm_Tutorial_2#Adding_Validation [22:01:20] [1/14] yeah I'm using [22:01:21] [2/14] ```php [22:01:21] [3/14] 'points' => [ [22:01:21] [4/14] 'type' => 'int', [22:01:21] [5/14] 'label-message' => 'createachievement-points', [22:01:22] [6/14] 'required' => true, [22:01:22] [7/14] 'validation-callback' => [ $this, 'validatePoints' ], [22:01:22] [8/14] ], [22:01:23] [9/14] ..... [22:01:23] [10/14] public function validatePoints( $value ) { [22:01:23] [11/14] return $value > 0 ? true : $this->msg( 'createachievement-points-invalid' )->plain(); [22:01:24] [12/14] } [22:01:24] [13/14] ``` [22:01:25] [14/14] for my achievements extension [22:01:46] should probably parse that message oopsie [22:02:00] its gonna take a bit to get used to the ? : syntax lol [22:02:06] p [22:02:16] i still prefer the long way [22:02:33] I only tend to use the tertiary if its a return statement [22:03:06] does returning a msg normally just be taken as an error message/abort? [22:03:34] in the instance of validation, returning a message will result in the form being rejected yes [22:04:13] return `true` for the condition that allows the form to carry on with its mission [22:04:34] lemme try and just get the single form field to save to a page onwiki [22:04:50] feel free to ping if you need [22:05:25] sure thing [22:05:40] need to find the docs on special page requestsd rq to get the user [22:06:00] `RequestContext::getMain()->getUser()` [22:09:34] (also whats the different between `$this->getRequest()` and `RequestContext`) [22:11:11] $this will use the current request, its usually what you want [22:11:36] You'd use RequestContext if the request isnt available to you (such as if youre not on a special page etc) iirc [22:11:58] hm [22:12:16] so wouldn't $this work in processCallback? [22:12:58] wait $this->getUser() exists as well [22:13:04] Hmm i couldn't say 100%, try it [22:13:14] Yeah you probably want that one then [22:13:18] when in doubt fuck it we ball [22:15:51] aight so crtl c crtl v alone will not work with the script [22:15:55] oh well thinking it i [22:24:28] hm, would `$page = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title );` need to be adapted for a special page? [22:33:15] I would use mediawikiservices [22:33:47] Ive never done it like that myself idk if that works(potentially it does), but personally i would pass MediaWiki services to the constructor [22:36:14] PHPStorm said the service container thing didn’t exist [22:36:24] It’s probably cause it’s a maint script [22:38:33] getServiceContainer should be used for maintenance scripts per modern standards but it doesn't exist anywhere else afaik [22:38:47] oh MW 1.41+ only [22:39:16] So mediawiki services would be the appropriate replacement hereV [22:39:55] Yeah if not in a maint script or `MediaWikiServices::getInstance()` [22:41:01] And from that get factory got it(I’m gonna be out for a bit so I’ll try later or tmr) [22:41:15] (I would require it in the constructor aswell and pass it to $this->services) [22:44:10] ❔ [22:47:27] [1/7] ```php [22:47:27] [2/7] public function __construct( MediaWikiServices $services) { [22:47:27] [3/7] $this->services = $services [22:47:27] [4/7] } [22:47:28] [5/7] .... [22:47:28] [6/7] $this->services->getInstance->WikiPageFactory() [22:47:28] [7/7] ``` [22:48:20] So in the special page constructor? [22:48:40] yup [22:48:55] its something like that anyway [22:49:03] might as well just do DI then [22:49:16] No, you'd pass WikiPageFactory not services to the constructor and build the special page on factory [22:49:17] pass just the services you need instead of MWServices as a whole [22:49:32] but yeah that's the way [22:50:33] Still a bit confused but definitely something to work with, thanks! [23:07:49] [1/2] (gtg now but feel free to lmk if this is goof) [23:07:50] [2/2] https://cdn.discordapp.com/attachments/1006789349498699827/1231018448923000903/sGOxAel.png?ex=66356e45&is=6622f945&hm=143813f6301d5b0458aaa56b92160944c8179835ce4f4eed18f69992b44db273& [23:09:27] last line is unneeded, just take whatever you need from the factory and save that in a variable. [23:15:07] True [23:16:05] But the factory will work like this for the purposes of `$this->factory->newFromTitle( $title );` Gucci