Commit graph

64 commits

Author SHA1 Message Date
Siddharth VP 82e5344ead Avoid recording template link to special page in getContent()
Replace Title::isExternal check with !Title::canExist(). The latter
subsumes the former. No content can be retrieved if the page cannot
exist in the database (such as special pages), and hence the
templatelinks row is unnecessary.

Bug: T377530
Change-Id: I44775980c4619f5ef719c6076976dd21095ba6e2
2024-11-18 19:05:38 +00:00
Ammarpad 756896edbb Ensure log report is always in valid UTF-8
Bug: T377473
Change-Id: Ica9bc98e100e169c6c4dd8398d410347c59ee2fd
2024-11-11 18:14:33 +00:00
Umherirrender 903e952604 Replace isset() with null check
isset() should only be used to suppress errors, not for null check.
When the variable is always defined, there is no need to use isset.
Found by a new phan plugin (2efea9f989)
https://www.mediawiki.org/wiki/Manual:Coding_conventions/PHP#isset

Change-Id: Ifba65aad2245b580f4361acf34ab46eabef60611
2024-10-27 12:25:57 +01:00
Andre Klapper 319d7bba52 Use explicit nullable type on parameter arguments (for PHP 8.4)
Implicitly marking parameter $... as nullable is deprecated in PHP
8.4. The explicit nullable type must be used instead.

Bug: T376276
Change-Id: I9cafaa51999fd2740da6c4fec9314fb9ace7c327
2024-10-26 15:10:35 +02:00
Umherirrender 9231163147 Use namespaced classes
Changes to the use statements done automatically via script

Change-Id: I28cb0daddf167e6e713b756e1f6ad0bbe98858ec
2024-10-20 11:54:11 +02:00
Umherirrender 7c1ea4284e build: Use inline ignore for MediaWiki.Usage.ForbiddenFunctions
This avoids addition of new code with the function,
or at least it gives extra attention on review when new code also uses
the inline ignore

Change-Id: I17981b52d9f96ee5f19ba46cf370c7477c81a72a
2024-09-23 17:40:51 +00:00
Siddharth VP 286add50b5 Don't record transclusion of current page from title methods
When the content or categories fields are accessed for the title object
of the current page, skip adding an entry in templatelinks.

* Cuts 5.9 million rows from enwiki templatelinks, where citation
templates use :getContent() to know what date format to use while
formatting citations.
* Prevents confusion about why a page is shown to transclude itself,
frequently brought up on technical support forums.

Change-Id: Id6a5e00572031f4a7258c99c6dc0f802385ee5fe
2024-09-23 16:28:03 +00:00
thiemowmde a630e3d129 Make use of ??=, ?: and similar operators where possible
The main benefit of these operators is that they avoid repeating
parts of the code.

Change-Id: I86ea0eb02715ad5b7c62a71849309ed7095c5972
2024-09-21 20:00:50 +00:00
Ebrahim Byagowi 27136f2afa Avoid use of deprecated wfGetUrlUtils
Change-Id: Ia36e0cf4a390f32fad7da55a503ac15afa85317a
2024-09-08 09:47:06 +03:30
James D. Forrester bb71303a81 Replace use of deprecated global URL functions with wfGetUrlUtils()
This is a quick fix rather than the proper DI fix.

Bug: T319340
Change-Id: I9e3bd0049b28efc634e1f394a487f86e27ef9e0d
2024-08-29 13:35:12 -04:00
thiemowmde 5ced07c366 Improve a few PHPDoc type hints
Mostly unspecific arrays that can be made more specific. This patch
intentionally doesn't touch any code, only comments.

Change-Id: I5b4690e6160c6c543f9fcb2f62c41f6329d48bdb
2024-08-27 16:54:41 +00:00
C. Scott Ananian 13b7e5ab31 Add title.content alias for Title::getContent()
No other access in the Title class contains a `get` prefix, so this
makes the title methods consistent.

Bug: T373047
Change-Id: I4a3a7498462b7b3b6143dc61f529e526ccb112e2
2024-08-22 11:30:26 -04:00
Siddharth VP a414aba445 Expose page categories to Lua
Added `categories` property in the lua title class which fetches page
categories. Analogous to getContent() which fetches page content. This
increments the expensive function count.

This enables category-specific editnotices (T85372) and other use-cases.

Bug: T50175
Change-Id: Ie8e0762c537374e6086abe9f9916b8200582776a
2024-08-07 16:50:07 +00:00
Mark A. Hershberger c684be1e52 Capture stderr from ‘lua -v' to get the version number.
Bug: T368832
Change-Id: Iff6e908686ee0e81088a81316927d1b250e6af1a
2024-07-08 21:11:23 +00:00
Bartosz Dziewoński ce1fa91c54 Don't depend on Message implementation details
You're not really supposed to know how Message represents the
parameters internally.

Change-Id: I5767dcc96af77b21655609cb9ce43bcaf9e07e19
2024-06-17 16:25:22 +00:00
Umherirrender db8f22c1d4 Use namespaced classes
Changes to the use statements done automatically via script

Change-Id: Iedad37d75aee4d2a6960ab20148f813c6cf7061a
2024-06-10 20:41:43 +02:00
theknightwho acd7ec66ea Avoid modules that should return false wrongly returning true
When modules are first loaded by `require` in package.lua, it checks
for a return value with `if res then`. If that check fails, the module
will be cached with the default value `true` at line 109, and that
value is then returned.

That check should be changed to `if res ~= nil then`, because
otherwise a module with a return value of `false` will be cached with
the value `true`.

This also necessitates a corresponding change to the check at line 93,
which is when `package.loaded` is initially checked to see if a package
has been loaded before, as that value could be `false`.

Bug: T362045
Change-Id: Id42e26a922c13971c25ed8654e822dc6fdcb6ca7
2024-05-24 02:10:41 +00:00
theknightwho fc3104e9c6 Optimisations for mw.clone
`mw.clone` is called on the global table for each new `{{#invoke:}}`,
which is a major contributor to loading times on large pages. This
change introduces various speed optimisations that make it around
15% faster:

* `recursiveClone` is declared outside of the main function, to avoid
  generating a new closure each time `mw.clone` is called.
* This means `tableRefs` has to be passed as an argument to
  `recursiveClone` instead of being an upvalue, which also decreases
  access time.
* `recursiveClone` is only called after a `type` then `tableRefs` check
  confirms a value is an unseen table, meaning it's only called when
  needed, not for every key/value pair (which add noticeable overhead
  when cloning large tables).
* `getmetable` is only called once, not twice, by using a local
  variable.
* `tableRefs[elt]` is only accessed once, by using a ternary operator.
* Any global accesses have been replaced by local ones.

Bug: T357199
Change-Id: I51593a971f0be728255723ca300d1ce692ead256
2024-05-24 02:08:41 +00:00
theknightwho a091b46d65 Use correct variable for error message in mw.loadJsonData
`mw.loadJsonData` in mw.lua throws an error if the input argument is
not a string. The error message should refer to the type of the input
argument `module`, not that of the variable `arg` (which is usually
undeclared, giving the type `nil`).

This also necessitates updating test `mw.loadJsonData, bad title (1)`
in CommonTests.lua, which checks for the error message if the input
is the number 0; the correct message should say "got number", not
"got nil".

Bug: T364987
Change-Id: I8362e91489a8ddc4c890e2799892f692c497c9b9
2024-05-15 14:05:32 +01:00
Wandji69 a7111aac69 Use ObjectCacheFactory instead of deprecated ObjectCache method
Bug: T363770
Change-Id: I416c511ef22afde3d519f66818c9b64e0ef21178
2024-05-14 20:07:42 +00:00
thiemowmde 4c4392b4f3 Use PHP's more recent ?? operator where it makes sense
… as well as avoid an overly complicated printf call where a string
cast does the same.

Change-Id: I66b51572d0f2f9e72b9ef7c32f9a62ebb698d739
2024-04-28 17:28:51 +00:00
Dringsim 8307c6b328 Change use of AtEase to at operator
Change-Id: I0c92ba1ca00d43b3e7d636872372dd451f372a29
2024-04-23 01:57:14 +00:00
C. Scott Ananian dfdf5cb54a LanguageLibrary: Ensure language code is a string
Defense in depth: catch the error early when calling mw.language.new()
with a non-string `code` argument; but also check late when popping
the code off the argument array in case something altered the code
property after construction.

Bug: T361664
Change-Id: I04476d3e1c32c87e1df95cc9a0dddcaff475b756
2024-04-11 16:20:24 +00:00
C. Scott Ananian 5bde75bf38 TitleLibrary: Don't register external titles as dependencies
In TitleLibrary::getContentInternal(), an external (interwiki) title will
fail when we try to `Parser::fetchCurrentRevisionRecordOfTitle`, but by
that time we've already tried to add it to the dependency list for the
page via `ParserOutput::addTemplate()`, which causes issues further on.

Bug: T362222
Change-Id: I171e97f17b6de176f92ced47757d10c341c979fd
2024-04-10 11:32:44 -04:00
Timo Tijhof 796c3dddfd Replace 'hash' with CACHE_HASH to improve discovery
Bug: T139216
Change-Id: Icd75953ccdb71543f3100f659fa32e1a1e7d1e26
2024-03-29 15:38:08 -07:00
Umherirrender 52af61330f Add explicit parentheses around mixed boolean operator
Mixing different binary boolean operators within an expression
without using parentheses to clarify precedence is not allowed (T358966)

Change-Id: I6d3edc5f8dddcfc6bd6a7d2a8f2ad9467372908d
2024-03-23 00:59:35 +01:00
Fomafix 70605bf630 Replace global configuration variables
Use overrideConfigValues instead of setMwGlobals in tests.

Change-Id: Icaf7d8d9bb3a4c1eb981ef83a12719c2619039fa
2024-03-18 04:40:44 +00:00
Umherirrender 09f2905ae6 build: Upgrade mediawiki/mediawiki-codesniffer to v43.0.0
Change-Id: Idf24dd1742439d80aaecc308eda386a1afbb0bdc
2024-03-10 23:46:30 +01:00
vlakoff 6c340bff8d Synchronize mw.text.nowiki() with wfEscapeWikiText in core
Added escapes for "!" and ";" as well as additional escapes
at beginning and end of string.

Bug: T168763
Co-Authored-By: vlakoff <vlakoff@gmail.com>
Co-Authored-By: C. Scott Ananian <cananian@wikimedia.org>
Depends-On: I34f2fa8c329e6f6771453b2f94dc4afbec31dac8
Change-Id: I6c9dcfdbbb2c6eff9414e24d3f2693ebe576505a
2024-02-15 05:29:36 +00:00
Reedy d07d4039e6 mw.title: add pageLang property
Bug: T321239
Bug: T161976
Change-Id: I0f7c80a4bd2339c3cce34030b862e29d984aa714
2024-01-17 18:20:06 +00:00
C. Scott Ananian f5f4355633 Set some title properties to nil for interwiki links
In order to avoid misleading the caller, set some title properties to
nil for interwiki links. That value should still be falsey, but can
prevent making unwarranted assumptions about the destination of
interwiki links.

Split from I847ac4b7587b98be06b25fe14765e9efdc7b774d because this
could possibly have effects on existing modules.

Change-Id: I06efea9b264ba0f09bfb36e6bf1bb04f1cdd03e4
2024-01-16 20:49:42 +00:00
vlakoff e1bd4911bd Add a property "talkNsText" to mw.title objects
Bug: T180911
Change-Id: I847ac4b7587b98be06b25fe14765e9efdc7b774d
2024-01-16 20:36:22 +00:00
Umherirrender 68aebf853c Use namespaced classes
This requires 1.42 for some new names

Done automatically via script

Change-Id: I6f6899981eab571cabb57534d7d98ce546a30a75
2024-01-05 19:24:06 +01:00
Reedy 836baa7142 LuaBit: Minor cleanup
Bug: T353678
Change-Id: I19527eb162c20b5a6017dc3c4dd2b98bf5cad5d9
2023-12-18 23:46:16 +00:00
Reedy 54e9dd05be LuaBit: Save files with unix EOL
Change-Id: Ia757198e32e2beb060ccee9577012bf3c91d49e5
2023-12-18 23:46:09 +00:00
C. Scott Ananian 9694e8f543 mw.language: add :toBcp47Code() method
This allows conversion of MediaWiki-internal codes to standardized
codes suitable for inclusion in HTML.

Change-Id: I5d2102ca57cc6861b8ec144a90f9c17b630f38ce
2023-12-15 00:18:54 +00:00
DannyS712 e30641e439 Add redirects for modules
ScribuntoContent now supports content being redirects, if the underlying
ScribuntoEngine does so. For Lua, a redirect looks like:

    return require [[Module:Foo]]

which also happens to be perfectly valid Lua. There is intentionally no
`#REDIRECT`-style token (like in wikitext/JavaScript/CSS) because no one
will create a page with this content except for the purposes of a
redirect.

Bug: T120794
Co-Authored-By: DannyS712 <DannyS712.enwiki@gmail.com>
Co-Authored-By: C. Scott Ananian <cscott@cscott.net>
Co-Authored-By: Jackmcbarn <jackmcbarn@gmail.com>
Change-Id: I405e7953d00af8a34d5e8addc61a245732c71e8e
2023-12-13 17:34:30 -05:00
Umherirrender 8f6ead1f82 Replace empty() with falsy check
empty() should only be used to suppress errors
When the type of the variable is array,
a falsy check is the same (checks for null, false and empty array)
Found by a new phan plugin (T234237)

Change-Id: Id855be9dd25a27d9e46e3065dacbd268177b073d
2023-10-21 23:30:25 +02:00
Umherirrender 29a9a8aec6 build: Change phan suppression to @phan-var for proc_get_status return
phan under php8.1 also detects PhanImpossibleTypeComparisonInLoop here,
but that cannot suppressed under php7.4,
so use @phan-var to set to the correct type, but keep the comment.
The suppression was added with 8328acb9 for a update of phan

According to the doc proc_get_status can only return array
(at least under php8.1)

Change-Id: Ieda5abc30126eed2e3a9f5fc283d36e64180f496
2023-10-06 19:37:10 +00:00
Umherirrender e126de6a78 Rethrow TimeoutException when using mw.language.formatDate function
timeout while converting timestamps should be a timeout for the whole
parse of that wikitext and not hidden by a invalid time.
Just let the exception bubble up to the caller
See ca71e69f for more information

Change-Id: I1f44e45dcc9b052717814990a3f5ce3a1bdf9d26
2023-10-02 21:03:02 +02:00
Umherirrender 80198cd635 Use ::class for class name resolution
Change-Id: I92a73fd6eccd3cf963ce1ff50ccf4f7aac6a0e1e
2023-09-21 22:46:00 +02:00
Daimona Eaytoy 7e54c088ac Avoid DB access in databaseless tests
- Force a content model on the title used by LuaEngineTestBase, so that
  calls to getPageLanguage() won't end up hitting the DB
- Don't actually use SiteStats from SiteLibrary in unit tests. There
  seem to be no test actually using this data.

Bug: T345372
Change-Id: I35884f04b582678982fb5f64d9199bab41cd8bce
2023-08-31 19:12:55 +00:00
gerritbot b7a5e6fadd Replace some moved Title class uses, now MediaWiki\Title\Title
Bug: T321681
Change-Id: I27924141187aef8fe2f6500ec0c4b6360d268c28
2023-08-19 12:22:05 +00:00
Anne Haunime b3f55c05e9 Optimize mw.text.trim() with default charset
Using code by David Manura, published at lua-users.org/wiki/StringTrim

Note '\t\r\n\f ' is replaced with '%s', thus '\v' (vertical tab) is added to the characters trimmed by default.

Bug: T338561
Change-Id: I98e2677f1181b88f4cd97cffca3a53ce426ec5cd
2023-07-14 15:59:20 +00:00
Daimona Eaytoy 846495fe45 Replace deprecated MWException
Bug: T328220
Change-Id: I38be06abdabff29276f07c378f3ef434973fb8d6
2023-06-09 14:43:44 +02:00
gerritbot 881d0c2bbd Update moved class RawMessage
See T321882. Moved in I195cf4c67bd514

Bug: T321681
Change-Id: I9c5e19e62f5faf73e6825e29090f6e1ae84ae3fb
2023-05-19 10:31:10 +00:00
gerritbot 57e391d32a Update moved class Category
See T321882. Moved in I0b86acfdea

Bug: T321681
Change-Id: I98440222d04b3c15523a7e00d447933f85b360ed
2023-05-15 13:26:48 +00:00
Umherirrender e2c3b41026 Use LanguageNameUtils::AUTONYMS/DEFINED instead of hard coded value
Easier to spot the documentation what happen with this option

Change-Id: Ic053e8daf14a74306b7ca3052503a59a19d16743
2022-12-29 13:43:27 +01:00
Umherirrender a20054fa34 Replace deprecated Language::isValidCode/isSupportedLanguage
Bug: T325974
Change-Id: I0245ea66abeebd9ae9b6d1edce9e8e93a479fdc0
2022-12-29 03:04:32 +01:00
Umherirrender bf4bdddb41 Replace deprecated Language::getFallbacksFor
Bug: T325979
Change-Id: Ia9658d0ce5bcd0c322cca0ffcec6aee82fb20a62
2022-12-29 02:01:09 +00:00