Manual talk:Content.php

Latest comment: 2 months ago by Germy Parker in topic getText()

getText()

edit

I was banging my head against the wall trying to figure out how to get the text from a page -- I tried so many different ways and finally resorted to asking ChatGPT -- but ChatGPT told me to use Content->getText(), which, according to this page and the class reference page does not exist.

(The link to the Content class reference page is incorrect here, not sure how to fix that, it seems like the link box is being generated programmatically somewhere; the correct link is this: https://doc.wikimedia.org/mediawiki-core/master/php/interfaceMediaWiki_1_1Content_1_1Content.html )

So I tried Gemini, and I tried Claude -- they also gave me a variety of incorrect ways until I decided just to try `Content->getText()` ...and it worked???

I don't understand why it worked. Shouldn't the function be listed here somewhere? Or, if I'm misunderstanding how it works, can someone add a little section on how to use `Content` to get page text? Germy Parker (talk) 17:38, 31 August 2024 (UTC)Reply

Thanks for your comment. I fixed the link. What version of MediaWiki are you using? What code are you using? The Content interface is not intended to be used directly. AbstractContent is a base class you can extend and then there are multiple subclasses for more specific purposes. Cavila 18:40, 31 August 2024 (UTC)Reply
Sorry, i missed this! I appreciate your response. I found a workaround, and unfortunately it's been so long I don't exactly remember where it was or how I fixed it. (I'm doing two MW projects atm, both on v1.42, so I'm not even sure which project it was in.)
I'm not sure if I'm a niche use-case, but I feel like there would be some value in a kind of "new-to-MW" developers guide, not for new developers (like this one), but developers who have some experience but are unfamiliar with the important core design stuff. The two main kinds of content that I would personally find useful would be 1) a few examples of how to (*correctly*) handle common tasks, like "this is how you change the text on a page", and 2) a few notable things like "this is how you know which interfaces are intended to be used directly and which aren't".
And I know such a guide is more work to write than it is to ask for, but, as MediaWiki.org itself proves, starting small might be enough to get the ball rolling. Maybe I'll take a stab at it -- at the risk of being completely wrong! Germy Parker (talk) 17:18, 22 September 2024 (UTC)Reply
Return to "Content.php" page.