aboutsummaryrefslogtreecommitdiffstats
path: root/includes/site
Commit message (Collapse)AuthorAgeFilesLines
* Replace call_user_func with dynamic function callUmherirrender2025-02-131-1/+1
| | | | | | | | Use modern php syntax to call a callable. Reduce the stack trace to improve performance and better IDE and static analyzer support Change-Id: I9ef131032a662a3b8db69aa7079dbd51f88f575a
* Remove 2-line PHPDocs that just repeat the types from the codethiemowmde2025-01-172-6/+0
| | | | | | | | | | | | | | | | Same as Ia294bf4 did for 1-line comments. This patch removes slightly more complex 2-line PHPDoc comments that don't add any new information to the code, but literally repeat what the code already says. They say "don't document the code, code the documentation", and we are doing this more and more. We just tend to forget to remove the obsolete comments. Note I'm also removing a line of text in a few cases when it's very short and literally says the same as the method name. Again, such comments add zero new information. Change-Id: I01535404bab458c6c47e48e5456403b7a64198ed
* Remove trivial 1-line PHPDocs that just repeat the codethiemowmde2025-01-161-6/+0
| | | | | | | | | | | | | I assume these are all either auto-generated by an IDE or the language-level type declarations have been added later. In any case the comments don't add any new information to what the code already says. This is just extra clutter that makes the code harder to read, I would argue. There are many, many more comments like this. In this patch I intentionally focus on the most trivial 1-line comments. Change-Id: Ia294bf4ce0d8a77036842fe25884bc175c2b0e7d
* Remove unchecked exception annotationsAdam Wight2024-09-171-1/+0
| | | | | | | | | | | | | | | Callers should not catch an unchecked exception, so it doesn't belong in a function signature. Unchecked exceptions indicate a coding error, which by definition the code will not be able to handle correctly. If any of these exceptions were supposed to be in response to an edge case, user input, or initial conditions, then they should be changed to a runtime error. If the exception class cannot be changed, then the annotation should include a comment explaining its purpose and prognosis. Bug: T240672 Change-Id: I2e640b9737cb68090a8e1cb70067d1b74037d647
* Make use of the ??= and ?? operators where it makes sensethiemowmde2024-08-261-4/+1
| | | | | | | | This touches various production classes and maintenance scripts. The code should do the exact same as before. The main benefit is that the syntax avoids any repetition. Change-Id: I5c552125469f4d7fb5b0fe494d198951b05eb35f
* site: Streamline Site class using modern PHP featuresthiemowmde2024-07-181-16/+6
| | | | | | | I believe this makes such code much easier to read and less error-prone. Change-Id: I40023b28b934bc75d1217d23ad6ec181312db11e
* Add namespace to the root classes of ObjectCacheEbrahim Byagowi2024-07-101-1/+1
| | | | | | | | | And deprecated aliases for the the no namespaced classes. ReplicatedBagOStuff that already is deprecated isn't moved. Bug: T353458 Change-Id: Ie01962517e5b53e59b9721e9996d4f1ea95abb51
* Fix various version mention for class_aliasUmherirrender2024-07-0510-10/+10
| | | | | | | | Versions are changed in 8e940c4f214ff7d17b53f51c6a46a5cf7fc2c92e, but that makes the version wrong Follow-Up: I7f85d931d3b79da23e87b4e5692b2e14be8fcaa0 Change-Id: Iae43725b8e0fffc4d44bf57f6227334b41290bd9
* Add namespace and deprecation alias to FormatJsonEbrahim Byagowi2024-05-161-1/+1
| | | | | | | | | This patch introduces a namespace declaration for the MediaWiki\Json to FormatJson and establishes a class alias marked as deprecated since version 1.43. Bug: T353458 Change-Id: I5e1311e4eb7a878a7db319b725ae262f40671c32
* Add namespace and deprecation alias to Xml and XmlSelectEbrahim Byagowi2024-05-161-1/+1
| | | | | | | | | | This patch introduces a new namespace declaration, MediaWiki\Xml and adds Xml and XmlSelect to it and establishes class aliases marked as deprecated since version 1.43. Bug: T353458 Change-Id: I45cccd540b6e15f267d3ab588a064fbeb719d921
* Typo fixesfrankie2024-04-231-1/+1
| | | | | | | Two small typo fixes for dev environment and gerrit setup. Bug: T362742 Change-Id: I92399002019a8df51731f8c927ca606f91211b51
* Standardise all our class alias deprecation comments for ease of greppingJames D. Forrester2024-03-1910-30/+10
| | | | Change-Id: I7f85d931d3b79da23e87b4e5692b2e14be8fcaa0
* Replace more instances of deprecated MWExceptionDaimona Eaytoy2024-01-191-7/+2
| | | | | Bug: T328220 Change-Id: Iba90f7f9b5766bccc05380d040138d74d5e9558a
* Replace a few array_key_exists with the ??= syntaxthiemowmde2024-01-081-4/+0
| | | | | | | | Or just remove it. It's not needed when the structure is already an array. PHP will happily initialize multi-dimentional arrays when needed. Change-Id: I93845e8d6f870d147bd55cfe3827bc94b375d0ba
* Merge "Inline once-called short private methods to its caller, part 1"jenkins-bot2023-12-191-8/+1
|\
| * Inline once-called short private methods to its caller, part 1Amir Sarabadani2023-12-181-8/+1
| | | | | | | | | | | | | | | | | | This makes the code easier to read to avoid jumps and improves encapsulation by not allowing the rest of the class having access to the logic. Of course, if needed then some code can be refactored out again but for now let's not do YAGNI. Change-Id: Ic37524e386fc04fd67e33768417ff8425f85b0ca
* | Namespace remaining files in includes/siteJames D. Forrester2023-12-148-14/+63
|/ | | | | Bug: T353458 Change-Id: I38da09f28cd68add721ba7b05f351acb56515d95
* Namespace Site and SiteListAmir Sarabadani2023-12-1410-9/+43
| | | | | Bug: T353458 Change-Id: I31f7cba42c02701e462eb3ed6bcc3928d438c1ef
* Remove redundant empty() constructs (2)Daimona 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: I70b629dbf9e47cf3ba48ff439b18f19e839677f4
* In query builders, use insertInto() and deleteFrom() instead of insert() and ↵Tim Starling2023-09-081-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | delete() The design principle for SelectQueryBuilder was to make the chained builder calls look as much like SQL as possible, so that developers could leverage their knowledge of SQL to understand what the query builder is doing. That's why SelectQueryBuilder::select() takes a list of fields, and by the same principle, it makes sense for UpdateQueryBuilder::update() to take a table. However with "insert" and "delete", the SQL designers chose to add prepositions "into" and "from", and I think it makes sense to follow that here. In terms of natural language, we update a table, but we don't delete a table, or insert a table. We delete rows from a table, or insert rows into a table. The table is not the object of the verb. So, add insertInto() as an alias for insert(), and add deleteFrom() as an alias for delete(). Use the new methods in MW core callers where PHPStorm knows the type. Change-Id: Idb327a54a57a0fb2288ea067472c1e9727016000
* Fix various typos and documentation issuesMatěj Suchánek2023-08-272-2/+2
| | | | Change-Id: I2cd4b647c01d84cfe0e1b4d55e155ced8c918b17
* site: Migrate DBSiteStore to use ICPAmir Sarabadani2023-08-241-9/+9
| | | | | Bug: T330641 Change-Id: If4bd4c0f3b2b74d3056db9b9521e7e6f1a25f307
* Mass migrate Database::insert calls to InsertQueryBuilderAmir Sarabadani2023-08-071-10/+8
| | | | | | | Done automatically based on a php parser written on top of ANTLR4 Bug: T335377 Change-Id: Ie8fabc594edab18e55cb1d5bbf573762106e3d71
* Migrate last batch of simple Database::select* calls to SQBAmir Sarabadani2023-08-011-18/+10
| | | | | | | Done semi-automatically via a parser written on top of ANTLR4 Bug: T311866 Change-Id: Ib71d6810e480d7176726082347b569e346557de7
* site: Use DeleteQueryBuilder in DBSiteStoreUmherirrender2023-07-061-6/+9
| | | | | | | | | Possible after ALL_ROWS support was added (7cf42e26) Also remove return from clear(), it is not documented on the interface Bug: T340065 Change-Id: Ibc41c92148c317862e8e3ea9583e2e28cfa0f61f
* Replace IDatabase::delete with DeleteQueryBuilderUmherirrender2023-06-211-5/+4
| | | | Change-Id: Ie0c1c955ca1a7028f75f24563fdeb9f94285af30
* Replace deprecated MWExceptionDaimona Eaytoy2023-06-091-8/+1
| | | | | Bug: T328220 Change-Id: I66be7a6dd752d6b9c254beb65f4eb5ace3c89776
* Migrate Database::update() to UpdateQueryBuilderAmir Sarabadani2023-06-081-1/+5
| | | | | | | | I did this using a script written on top of antlr4 parser so it doesn't have some clean ups a human would do but it's pretty nice already. Bug: T330640 Change-Id: I608566700c6d737ee986bf47dda87effc69614d6
* site: Simplify SiteList by removing GenericArrayObject indirectionTimo Tijhof2023-06-051-32/+113
| | | | | | | | | | | | | | | | | | | | | | | | | == Background == In 2012, commit afe46f1403a (Id7e9b59c7e) added libs/GenericArrayObject along with an (unused) abstract GenericArrayObjectTest case. The same code was also added to the Wikibase extension with change 6347b35a55cd (Ifa7f1dc702). The code was then factored out from Wikibase into the wmde/Diff library. In 2013, GenericArrayObject was removed from wmde/Diff in the commit at https://github.com/wmde/Diff/commit/d9c2bd5c140e2a783fd42298db6c. == This change == Remove the GenericArrayObject indirection from SiteList as there exist nothing outside SiteList refering to it in Codesearch Everywhere, and even in SiteList much of the code in GenericArrayObject is overridden, unused, or otherwise needlessly indirect. Change-Id: Ifea09c5de50af1616058d8baa9037db273dfb0e5
* Remove uses Database::update()/Database::insert() return valuesAaron Schulz2023-05-271-7/+3
| | | | Change-Id: I527ea0900cc76faac9506b2a43a2b1522b35dfbd
* 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
* Replace some usages of MWExceptionDaimona Eaytoy2023-01-261-27/+7
| | | | | | | | These exceptions are not documented with @throws and they're really not meant to be caught. Bug: T86704 Change-Id: I07f32e42c6fd4bc8785bac91547858f15a9fc2a8
* site\MediaWikiPageNameNormalizer: Replace deprecated Http::getUmherirrender2022-12-141-11/+11
| | | | | Bug: T305813 Change-Id: I138aecd6275b7e9b2a852565e67e083460b8286d
* Merge "Various doc fixes about false on method arguments/return types"jenkins-bot2022-11-173-4/+4
|\
| * Various doc fixes about false on method arguments/return typesUmherirrender2022-11-103-4/+4
| | | | | | | | | | | | Doc-only changes Change-Id: I5177f582ae7ee70c357e9389fed14819faf79463
* | Merge "Remove pre PHP 7.4 serialize()/unserialize()"jenkins-bot2022-11-101-23/+1
|\ \ | |/ |/|
| * Remove pre PHP 7.4 serialize()/unserialize()Reedy2022-11-101-23/+1
| | | | | | | | | | Depends-On: I3b893152ed278a72b5e74ccf91a3381f319bfcd9 Change-Id: I9f69a9316eaec23103262ec2ffd5b85baaf16f3f
* | site: Hard-deprecate MediaWikiSite::getFileUrl() without $pathLucas Werkmeister2022-11-101-1/+3
|/ | | | | | | | | All callers available in codesearch pass in a $path (and for all callers except getFileUrl()’s own test, that path is 'api.php'); omitting the path hasn’t worked correctly for almost ten years (see change I5ed7e169c9, commit 779df10df7). Change-Id: I50819efb66fd72f2b5a1cd83d5cdd3a148742299
* site: Switch new code from MWException to RuntimeExceptionTimo Tijhof2022-11-082-28/+8
| | | | | | | | | | | | Follows-up I5ed7e169c9753 (779df10d, T319219) which introduced a new use of MWException, as per T86704. While at it, also remove a few unhelpful `@throws` annotations that do nothing other than save an outdated IDE scan of what throw statements internally exist. These aren't meant to be caught and thus aren't of use to consumers of these docs as per T321683. Change-Id: I4ef964342de80eb2c1dec99cd6258727e6cd1a2c
* site: Use common terms in docs for script path and article pathTimo Tijhof2022-11-081-31/+25
| | | | | | | | | | | | Its unfortunate that this class has encoded these unusual terms in its stable API but we can at least use more common terminology and document what these things actually are. Virutally every word in the explaination "a full file path [is] a site url and relative file path", meant something different from its usual meaning, namely the full URL to an entry point script under /w/. Change-Id: I15f1c9d56f61e622734bb3ddc304025ad4bfc169
* site: Annotate CachingSiteStore as `@internal` and perform minor cleanupTimo Tijhof2022-11-0511-196/+123
| | | | | | | | | | | | | | | | | | | | | | | | | | * Recognise CachingSiteStore as the internal class that it is. * Clean up the file header and move ingroup annotation, similar to other commits under <https://gerrit.wikimedia.org/r/q/message:ingroup+owner:Krinkle>. The one here was particularly odd as it placed the license inside the class doc block rather than the file doc block. * Remove unused $cacheKey and $cacheTimeout constructor args. They were also not covered by any unit tests. * Avoid use of `empty()` as per <https://www.mediawiki.org/wiki/Manual:Coding_conventions/PHP> * Use a more conventional cache key in CachingSiteStore, keeping the dynamic part for a later segment and keeping the first segment explicitly tied to a single concrete key group. This also improves ergonomics of cache statistics e.g. in Grafana and makes the cache key easier to locate in codesearch/grep, and more recognisable, e.g. starting with the code component ("site"). Change-Id: I541ad62551ab76127d70ef665272fd1d590ab556
* Fix Site::getPath() + MediaWikiSite::getFileUrl() confusionLucas Werkmeister2022-11-042-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | | Site::getPath() has returned null since change I08ffa6a970 (commit a00337c3f8), almost ten years ago; I think on the whole it’s safer to fix the prose documentation and keep the @return and actual returned value as they are, rather than the other way around. MediaWikiSite::getPageUrl() compared the $filePath to false instead of null, so the comparison would always be true; but on closer inspection, I think this code was supposed to check $path, not $filePath, in the first place. The only reason this didn’t come up so far is that all known callers pass in a custom path (specifically, all non-test callers pass in 'api.php'), so the $path = false default was never used. To avoid a deprecation warning in PHP 8.1 when passing a null $filePath into str_replace(), throw in that case instead – the function isn’t documented to return string|null, and none of the callers seem prepared to handle a null return as far as I can tell, so throwing seems better than returning null. Tests that produce a null $filePath need to be fixed to complete the Site object (compare Wikibase change If20688411e). Bug: T319219 Change-Id: I5ed7e169c9753486c765fd816d1b21016c5c1def Depends-On: If20688411e3f0108b0c0ba3b91e5cc264b70a208
* site: Consistently return null from Site::getDomain()Mark A. Hershberger2022-07-062-4/+10
| | | | | | | | | | | | | Note that null triggers the following for php 8.1: PHP Deprecated: strrev(): Passing null to parameter #1 ($string) of type string is deprecated Got a few of these in WikiMapTest::testMakeForeignLink(), caused by a single call in DBSiteStore. Bug: T289926 Change-Id: I0b29963ec0e2e8a38a66e250e81fbc16e42465ab
* Get rid of warnings on PHP 8.1Aryeh Gregor2022-06-132-4/+4
| | | | | | | | | | | This is mostly about adding return types to methods that implement PHP interfaces, and not passing null to core functions that want a string. After this patch, and an update to return types in RemexHtml, tests/phpunit/integration/ has no more errors than in PHP 8.0. Bug: T289879 Bug: T289926 Change-Id: Ia424f5cc897070f4188ae126b5bf6a1f552db0e1
* Use MainConfigNames instead of string literals, #3Aryeh Gregor2022-04-261-1/+3
| | | | | | | | | | | | | This edition brought to you by: grep -ERIn $(grep -o "'[A-Za-z0-9_]*'" includes/MainConfigNames.php | tr "\n" '|' | sed 's/|$/\n/') includes/ I only corrected a fraction of the results provided by that command. I'm submitting the partial patch now so it doesn't bitrot. Bug: T305805 Change-Id: If1918c0b3d88cdf90403921e4310740e206d6962
* Merge "Implement __serialize/__unserialize for PHP 8.1 support"jenkins-bot2022-02-072-14/+27
|\
| * Implement __serialize/__unserialize for PHP 8.1 supportReedy2022-02-012-14/+27
| | | | | | | | | | Bug: T299312 Change-Id: I8a758ed52b18d52cf083b645fbd88725cca983e8
* | Try not to discard Excimer timeout exceptionsTim Starling2022-02-021-0/+4
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | Don't catch and discard exceptions from the RequestTimeout library, except when the exception is properly handled and the code seems to be trying to wrap things up. In most cases the exception is rethrown. Ideally it should instead be done by narrowing the catch, and this was feasible in a few cases. But sometimes the exception being caught is an instance of the base class (notably DateTime::__construct()). Often Exception is the root of the hierarchy of exceptions being thrown and so is the obvious catch-all. Notes on specific callers: * In the case of ResourceLoader::respond(), exceptions were caught for API correctness, but processing continued. I added an outer try block for timeout handling so that termination would be more prompt. * In LCStoreCDB the Exception being caught was Cdb\Exception not \Exception. I added an alias to avoid confusion. * In ImageGallery I added a special exception class. * In Message::__toString() the rationale for catching disappears in PHP 7.4.0+, so I added a PHP version check. * In PoolCounterRedis, let the shutdown function do its thing, but rethrow the exception for logging. Change-Id: I4c3770b9efc76a1ce42ed9f59329c36de04d657c
* Stop using is_resource() where possibleTim Starling2022-01-261-0/+1
| | | | | | | | | | | | | | | | * Enforce the ban on is_resource in phpcs * In OrderedStreamingForkController, the comment was incorrect. I confirmed using a small test script that if the child closes one end of a socket pair, the other end will still be open, and is_resource() will still return true, and fclose() will not fail. The issue was introduced in c82d30d19cc2b2182, it was not present in the CirrusSearch copy of the class. * Allow is_resource() for debug logging. * Allow is_resource() for parameter validation where a stream may be passed to a function, since there is no alternative. Bug: T260735 Change-Id: I59a752f7bb4b043ddfb2434b52a02f9221bf54db
* Suppress deprecation warnings from libxml_disable_entity_loader()Tim Starling2022-01-211-3/+6
| | | | | | | | | | As discussed in the task, there is no simple replacement for this function. Reduces core PHPUnit error count from 121 to 2. Bug: T268847 Change-Id: Ia8697e1c3ba369346b39ef50d94ea8b132eb9c80