aboutsummaryrefslogtreecommitdiffstats
path: root/includes/content/WikitextContent.php
Commit message (Collapse)AuthorAgeFilesLines
* content: Improve class docs for various Content classesTimo Tijhof2025-03-121-7/+2
| | | | | | | | | | | | | * Move duplicate brief and ingroup from file doc to class doc. <https://gerrit.wikimedia.org/r/q/message:ingroup+owner:Krinkle> * Ensure methods have an understable brief, separate from other text. <https://www.mediawiki.org/wiki/Manual:Coding_conventions/Documentation> * Remove obsolete `todo` comments. Bug: T364652 Change-Id: I6eebbf20775e73d008ef86c592a7128456abcb06
* Use $string === '' instead of strlen( $string ) === 0Fomafix2025-01-301-1/+1
| | | | | | | | | Add $string === false or $string === null where $string can have other types than a string. Also document null as possible return value in FileRepo. Change-Id: Iaa29ba01c3fd6bea506debdc6f929edfe881c808
* Use ParserOutput::getLinkList() internallyC. Scott Ananian2024-11-151-2/+1
| | | | | | | | This replaces the internal uses of the deprecated ParserOutput::get* methods and isolates the ParserOutput internal representation from most of the users. Change-Id: I32df68714ffdf2f0745b974f47bc3ccceef1f41c
* Use explicit nullable type on parameter argumentsUmherirrender2024-10-161-1/+1
| | | | | | | | | | | Implicitly marking parameter $... as nullable is deprecated in php8.4, the explicit nullable type must be used instead Created with autofix from Ide15839e98a6229c22584d1c1c88c690982e1d7a Break one long line in SpecialPage.php Bug: T376276 Change-Id: I807257b2ba1ab2744ab74d9572c9c3d3ac2a968e
* Move remaining four classes in includes/content into Content namespaceJames D. Forrester2024-08-101-1/+0
| | | | | Bug: T353458 Change-Id: Ia0f3e22078550be410c4b87faf6aa4eabe6e270d
* Add namespace to WikitextContentEbrahim Byagowi2024-08-061-1/+13
| | | | | | | It adds MediaWiki\Content namespace to WikitextContent and two classes related. Change-Id: Ib74e4c5b3edac6aa0e35d3b2093ce1d0b794cb6d
* Add namespace and deprecation alias to TextContentEbrahim Byagowi2024-05-191-0/+1
| | | | | | | | | This patch introduces a namespace declaration for the MediaWiki\Content to TextContent and establishes a class alias marked as deprecated since version 1.43. Bug: T353458 Change-Id: Ic251b1ddfcf6db9c85cb54cddf912aa827d2bc3a
* Namespace includes/contextJames D. Forrester2024-02-081-0/+1
| | | | | Bug: T353458 Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
* Replace unchecked MWException with SPL exceptionsDaimona Eaytoy2024-01-281-4/+2
| | | | | Bug: T328220 Change-Id: I4e0454ce3ad3741756e2010a76e548d6c9a6bcb5
* Move getRedirectTargetAndText out of WikitextContentdaniel2023-09-221-55/+18
| | | | | | | | WikitextContent should be a value object that does not need access to services. For this reason, getRedirectTargetAndText has to be moved to WikitextContentHandler. Change-Id: Ia6595caf7e913ef580709a4d076aa2cc9dbaacef
* Unit test for LinkRenderer::makeRedirectHeader() used by WikitextContentHandlerC. Scott Ananian2023-09-221-4/+23
| | | | Change-Id: I3577633670d0c2a771c690e3d6601300e1867222
* Remove redundant empty() constructsDaimona Eaytoy2023-09-081-1/+1
| | | | | | | | | | | | | empty() only makes sense when the expression it checks is possibly undefined, otherwise it's equivalent to a truthiness check with the additional downside of suppressing errors when it's not wanted. Replace it with simple truthiness checks, using strict comparison when that seems to help with polymorphic variables. These were caught by a bespoke phan plugin. Change-Id: I52999e5286a0d9ad70b0da40b41b9f998ecb990e
* Replace internal Hooks::runnerUmherirrender2023-05-111-1/+3
| | | | | | | | | The Hooks class contains deprecated functions and the whole class is going to get removed, so remove the convenience function and inline the code. Bug: T335536 Change-Id: I8ef3468a64a0199996f26ef293543fcacdf2797f
* Reorg: Namespace the Title classJames D. Forrester2023-03-021-0/+1
| | | | | | | | | | | | | | | | | | | This is moderately messy. Process was principally: * xargs rg --files-with-matches '^use Title;' | grep 'php$' | \ xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1' * rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \ xargs rg --files-with-matches 'Title\b' | \ xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1' * composer fix Then manual fix-ups for a few files that don't have any use statements. Bug: T166010 Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
* Reorg: Move MagicWord related files to under parser/Amir Sarabadani2022-12-091-0/+1
| | | | | | | This is approved as part of T166010 RFC. Bug: T321882 Change-Id: Ia4498c0a20e38a6a288dc14065ea8242c84fbc49
* Various doc fixes about false and null on method arguments/return typesUmherirrender2022-11-031-2/+2
| | | | | | Doc-only changes Change-Id: Ice974b3ba41708859dfe646e94b31c5ebbf26410
* Use short array destructuring instead of list()Tim Starling2022-10-211-1/+1
| | | | | | | | Introduced in PHP 7.1. Because it's shorter and looks nice. I used regex replacement. Change-Id: I0555e199d126cd44501f859cb4589f8bd49694da
* Fix edit API adding empty section title when creating new pagesBartosz Dziewoński2022-07-051-3/+2
| | | | | | | | | | | | | | | WikitextContent methods replaceSection() (used when adding a section to an existing page) and addSectionHeader() (used when creating a new page) behaved inconsistently - the former would omit the heading syntax when the section title was empty, but the latter would not. They both omit it now. Some callers of addSectionHeader() handled this case, but others did not, which caused T311489. (I am removing the checks now, since the change makes them redundant.) Bug: T311489 Change-Id: Icd59bcf2b75bf50865f19fac92bddabe0c183dcc
* Migrate risky callers of MediaWikiServices::getParser()Tim Starling2022-07-051-2/+2
| | | | | | | | Don't call MediaWikiServices::getParser() from ContentHandler. Always use ParserFactory::getInstance(). Bug: T310948 Change-Id: I5fcdc28111e0c5c7d4a76e69b3978402433ebad9
* Remove support for $wgMaxRedirectdaniel2022-05-061-8/+0
| | | | | | | Redirect chains have never worked as intended. Bug: T296430 Change-Id: If0e514c57b8f3d857d956a581f1b549518ecb099
* Use MainConfigNames instead of string literals, #4Aryeh Gregor2022-04-261-2/+4
| | | | | | | | | | | | | | | | | | | | | Now largely automated: VARS=$(grep -o "'[A-Za-z0-9_]*'" includes/MainConfigNames.php | \ tr "\n" '|' | sed "s/|$/\n/;s/'//g") sed -i -E "s/'($VARS)'/MainConfigNames::\1/g" \ $(grep -ERIl "'($VARS)'" includes/) Then git add -p with lots of error-prone manual checking. Then semi-manually add all the necessary "use" lines: vim $(grep -L 'use MediaWiki\\MainConfigNames;' \ $(git diff --cached --name-only --diff-filter=M HEAD^)) I didn't bother fixing lines that were over 100 characters unless they were over 120 and triggered phpcs. Bug: T305805 Change-Id: I74e0ab511abecb276717ad4276a124760a268147
* phan: Disable null_casts_as_any_type settingUmherirrender2022-03-211-0/+2
| | | | | | | | | | | Make phan stricter about null types by setting null_casts_as_any_type to false (the default in mediawiki-phan-config) Remaining false positive issues are suppressed. The suppression and the setting change can only be done together Bug: T242536 Bug: T301991 Change-Id: I0f295382b96fb3be8037a01c10487d9d591e7e01
* Refactor global variables to use MediaWikiServices insteadTChin2022-01-101-4/+4
| | | | | | | | | | | | Automatically refactors wg prefixed globals to use MediaWikiServices config using Rector. Doesn't include files that set globals or files that fail CI. Rector Gist: https://gist.github.com/tchin25/7cc54f6d23aedef010b22e4dfbead228 * This patch uses a modified source code rector library for our specific use case and the rector will have different effects without it. A writeup for future reference is here: https://meta.wikimedia.org/wiki/User:TChin_(WMF)/Using_Rector_On_MediaWiki Change-Id: I1a691f01cd82e60bf41207d32501edb4b9835e37
* Allow inserting new sections named '0'C. Scott Ananian2021-11-191-1/+1
| | | | | | | | This bug has apparently existed since sometime before b6fe2132264 in 2012 (!). Bug: T296112 Change-Id: Ic50965647117b91562493444d62dfdd2bbb5260e
* Replace Content::getParserOutput call to ContentRenderer::getParserOutputRoman Stolar2021-10-201-2/+2
| | | | | Bug: T287158 Change-Id: I8a13f45027e08e2d8ddefa140dd47a0c55094934
* Move Content::getParserOutput & AbstractContent::fillParserOutput to ↵Roman Stolar2021-09-291-51/+10
| | | | | | | | | | ContentHandler Update/Create override classes of ContentHandler. Soft-deprecate and remove method from Content and classes that override them. Bug: T287158 Change-Id: Idfcfbfe1a196cd69a04ca357281d08bb3d097ce2
* Detect and monitor against multiple Parser invocation during edit requestsCindy Cicalese2021-09-231-28/+0
| | | | | Bug: T288707 Change-Id: I0cca8f9bcf1d6e964b8b06c0c4490e83f4fb1de5
* Using @return never documentation on always-throw-functionUmherirrender2021-09-071-0/+1
| | | | | | | | | | This helps phan to detect unreachable code and also impossible types after the functions. It helps phan to avoid false positives for array keys when the keys are checked before Bug: T240141 Change-Id: I895f70e82b3053a46cd44135b15437e6f82a07b2
* Move Content::preloadTransform to ContentHandlerRoman Stolar2021-08-171-18/+0
| | | | | | | | | | | | | | | | Update ContentTransformer to access ContentHandler::preLoadTransform through the service. Prepare object to hold a data that required for ContentHandler::preLoadTranform params. This is a fully backwards compatible change. We are doing hard deprecation via MWDebug::detectDeprecatedOverride. However, with the ContentHandler calling Content and Content calling ContentHandler, it doesn't matter whether callers use Content or ContentHandler. This will allow us to naturally convert all callers. Bug: T287157 Change-Id: I89537e1e7d24c6e15252b2b51890a0bd81ea3e6b
* Move Content::preSaveTransform to ContentHandlerPetr Pchelko2021-07-291-33/+11
| | | | | | | | | | | | | | | | | | | Create ContentTransformer to access ContentHandler::preSaveTransform through the service. Prepare object to hold a data that required for ContentHandler::preSaveTranform params. This will require making a semi-backwards-incompatible change no matter what, we don't really have a great way of hard-deprecating overriding methods. However, with the ContentHandler calling Content and Content calling ContentHandler, and with the ProxyContent trick to stop infinite recursion, it doesn't matter whether callers use Content or ContentHandler. This will allow us to naturally convert all callers. But won't really allow hard-deprecation. Bug: T287156 Change-Id: If6a2025868ceca3a3b6f11baec39695e47292e40
* Make WikitextContentTest set the context title to avoid failuresAaron Schulz2020-10-201-0/+1
| | | | | | | | This avoids failures due to WikitextContent::isCountable() erroring out when no title is set for the main RequestContext. Bug: T257009 Change-Id: I70274e3876c5b7c273110f9afa713a85edcc6339
* Replace "@stable for calling" by "@stable to call"daniel2020-07-131-1/+1
| | | | | | | | | | | For compliance with the new version of the table interface policy (T255803). This patch was created by an automated search & replace operation on the includes/ directory. Bug: T257789 Change-Id: If560596f5e1e0a3da91afc36e656e7c27f040968
* Annotate newable classesdaniel2020-07-071-0/+6
| | | | | | | | This annotates classes that can safely be instantiated by extensions, per the Stable Interface Policy. Bug: T247862 Change-Id: Ia280f559874fc0750265ddeb7f831e65fd7d7d6a
* Hooks::run() call site migrationTim Starling2020-05-301-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Migrate all callers of Hooks::run() to use the new HookContainer/HookRunner system. General principles: * Use DI if it is already used. We're not changing the way state is managed in this patch. * HookContainer is always injected, not HookRunner. HookContainer is a service, it's a more generic interface, it is the only thing that provides isRegistered() which is needed in some cases, and a HookRunner can be efficiently constructed from it (confirmed by benchmark). Because HookContainer is needed for object construction, it is also needed by all factories. * "Ask your friendly local base class". Big hierarchies like SpecialPage and ApiBase have getHookContainer() and getHookRunner() methods in the base class, and classes that extend that base class are not expected to know or care where the base class gets its HookContainer from. * ProtectedHookAccessorTrait provides protected getHookContainer() and getHookRunner() methods, getting them from the global service container. The point of this is to ease migration to DI by ensuring that call sites ask their local friendly base class rather than getting a HookRunner from the service container directly. * Private $this->hookRunner. In some smaller classes where accessor methods did not seem warranted, there is a private HookRunner property which is accessed directly. Very rarely (two cases), there is a protected property, for consistency with code that conventionally assumes protected=private, but in cases where the class might actually be overridden, a protected accessor is preferred over a protected property. * The last resort: Hooks::runner(). Mostly for static, file-scope and global code. In a few cases it was used for objects with broken construction schemes, out of horror or laziness. Constructors with new required arguments: * AuthManager * BadFileLookup * BlockManager * ClassicInterwikiLookup * ContentHandlerFactory * ContentSecurityPolicy * DefaultOptionsManager * DerivedPageDataUpdater * FullSearchResultWidget * HtmlCacheUpdater * LanguageFactory * LanguageNameUtils * LinkRenderer * LinkRendererFactory * LocalisationCache * MagicWordFactory * MessageCache * NamespaceInfo * PageEditStash * PageHandlerFactory * PageUpdater * ParserFactory * PermissionManager * RevisionStore * RevisionStoreFactory * SearchEngineConfig * SearchEngineFactory * SearchFormWidget * SearchNearMatcher * SessionBackend * SpecialPageFactory * UserNameUtils * UserOptionsManager * WatchedItemQueryService * WatchedItemStore Constructors with new optional arguments: * DefaultPreferencesFactory * Language * LinkHolderArray * MovePage * Parser * ParserCache * PasswordReset * Router setHookContainer() now required after construction: * AuthenticationProvider * ResourceLoaderModule * SearchEngine Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
* Avoid PHP scalar type juggling in includes/ (part 2)Daimona Eaytoy2019-12-301-1/+1
| | | | | | Continuation of e5444ea55a8000f0040. Change-Id: I9f95e7de4e219dee3abcdd210bb708d949f378d0
* Unsuppress another phan issue (part 7)Daimona Eaytoy2019-09-031-0/+2
| | | | | | | Bug: T231636 Depends-On: I2cd24e73726394e3200a570c45d5e86b6849bfa9 Depends-On: I4fa3e6aad872434ca397325ed7a83f94973661d0 Change-Id: Ie6233561de78457cae5e4e44e220feec2d1272d8
* parser: document what 0/null rev IDs do when given to Parser::parseAaron Schulz2019-08-211-1/+2
| | | | | | This was extremely obscure and tricky to figure out before Change-Id: Ibdbb669431819eecd34de508735864e977d51021
* parser: add speculative page IDs to use with {{PAGEID}}Aaron Schulz2019-07-261-1/+1
| | | | | | | | | | This works similarly to speculative rev IDs with {{REVISIONID}}. Re-parses can be avoided if the page ID is correctly guessed. Also make the {{PAGEID:X}} parser function set vary-page-id. Bug: T226785 Change-Id: I0b19be45e6ddd6cde330bfcd09d243e4e5beda01
* Remove all $wgParser use from coreAryeh Gregor2019-04-171-17/+13
| | | | | | Bug: T160811 Change-Id: I0556c04d33386d0339e02e2bf7a1ee74d97c2abd
* Deprecate Content::getNativeData, add TextContent::getTextdaniel2019-01-161-12/+12
| | | | | | | | | | | | | getNativeData() is under-specified - callers can do nothing with the value returned by getNativeData without knowing the concrete Content class. And if they know the concrete class, they can and should use a specialized getter instead, anyway. Basically, getNativeData is overly generic, an example of polymorphism done poorly. Let's fix it now. Bug: T155582 Change-Id: Id2c61dcd38ab30416a25746e3680edb8791ae8e8
* Add logging for redundant parsing to WikitextContent.daniel2018-11-261-0/+28
| | | | | Bug: T205369 Change-Id: I67bfdc0340e0ddc1ecdaf3323f2171b2e752c680
* Give pages with ~~~~ a different cache TTLAryeh Gregor2018-08-121-1/+22
| | | | | | | This was supposed to already be the case, but it wasn't. The flag that was set got cleared and never did anything. Change-Id: Ide960f8cb9228f9a9d68c540369f122ada0a2a6f
* Convert remaining MagicWord:: calls to MagicWordFactoryAryeh Gregor2018-08-011-1/+3
| | | | | | Bug: T200247 Depends-On: Ie061fe90f9b9eca0cbf7e8199d9ca325c464867a Change-Id: I49c507f3875e46a8e15fd2c28d61c17188aabffc
* Drop 'comma' value for wgArticleCountMethodJames D. Forrester2018-03-011-18/+12
| | | | | | | | | | | | | | | | | We have three methods for page counting currently supported for wikitext non-redirect pages; 'any' counts any page that exists, 'link' counts any page that has any outbound links, and 'comma' which searches for any ',' in the text having loaded it. This last option is much slower than these other two, and is only used on a very small number of installations. Now by dropping support for this method we can simplify this code and so run it more often. Note that non-wikitext pages already did not support this count method. Installations with this setting set to 'comma', or any other string will now work as if it was configured with 'any'. Bug: T188472 Change-Id: I965927edcd2485ec4b49b2d80fdf216dbf19520b
* Changed Instances of rawParams() to plaintextParams()ryan101452017-12-071-1/+1
| | | | | Bug: T182213 Change-Id: Ibf24dee5ea19092e8a38e57f34c98f513d4c9b21
* Remove empty lines at begin of function, if, foreach, switchUmherirrender2017-07-011-1/+0
| | | | | | Organize phpcs.xml a bit Change-Id: Ifb767729b481b4b686e6d6444cf48b1f580cc478
* Fix parameter type docsLeszek Manicki2016-12-141-2/+2
| | | | | | | | | | | | Changes: - uses int instead of number as param and return value type, - uses stdClass instead of stdObject - fixes ResourceLoaderClientHtml constructor's $target param type: it is string|null, not an array (previously misspelled as "aray") - changes the type of references to XML parser in XMP lib to resource instead of not existing XMLParser Change-Id: I98c363ebc6658d1f4dcabad97a9a92f3fcd7ea8c
* content: Refactor normalization of line endings codeKunal Mehta2016-08-231-1/+0
| | | | | | | | | | | | | | | | | The code that normalizes line endings ("\r\n" and "\r" to "\n") and trims trailing whitespace is buried in Parser::preSaveTransform(), and was duplicated to TextContent in 96b6afb31dfcff, as non-wikitext content models should still be normalizing line endings. This splits the duplicated code into TextContent::normalizeLineEndings(), and utilize it in the Parser. Additionally, expand the documentation of TextContent::preSaveTransform() to document that subclasses should make sure they normalize line endings during the PST stage. And remove a useless rtrim() call from WikitextContent that did nothing. Change-Id: I9094c671d4bbd23d75436f8f1d682d6dd6e6d2fc
* Add missing null type hints to Content::isCountable and implementationsThiemo Mättig2016-02-251-2/+2
| | | | Change-Id: I6e3128dddd296f6d33da23332b8ff8393837b61b
* Convert all array() syntax to []Kunal Mehta2016-02-171-7/+7
| | | | | | | | | | Per wikitech-l consensus: https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html Notes: * Disabled CallTimePassByReference due to false positives (T127163) Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b