Commit graph

154 commits

Author SHA1 Message Date
jenkins-bot
96393c492e Merge "Add various fallback values for null return values" 2022-03-09 22:32:29 +00:00
Umherirrender
5410a5691d snapshot: Add @var documentation for class properties
Change-Id: I80ba53bdeb730a115ab3eec4849a38a13a896cdb
2022-03-09 21:54:18 +00:00
Umherirrender
19925ef026 Add various fallback values for null return values
Found by phan strict checks

Change-Id: I83187b5fd25b015d2c75e22d4b5202803653d743
2022-03-09 20:15:36 +01:00
Umherirrender
04d4b5addb export: Cast File::getSize to string on dump
Xml::element needs a string to produce the tag,
explicit cast the integer and convert the possible false to zero.

Found by phan strict checks

Change-Id: I349d9ab2f999a569a90402d5197fba56e5451fc2
2022-03-03 14:09:27 +00:00
Umherirrender
9efd9ca45e Add explicit casts between scalar types
* Some functions accept only string, cast ints and floats to string
* After preg_matches or explode() casts numbers to int to do maths
* Cast unix timestamps to int to do maths
* Cast return values from timestamp format function to int
* Cast bitwise operator to bool when needed as bool

* php internal functions like floor/round/ceil documented to return
  float, most cases the result is used as int, added casts

Found by phan strict checks

Change-Id: Icb2de32107f43817acc45fe296fb77acf65c1786
2022-03-01 18:19:33 +01:00
Umherirrender
b126dbe3f2 Fix various documentation related to null types
The functions returning null or the class property is set explict null

Found by phan strict checks

Change-Id: I4a271093fb6526564d8083a08249c64cb21f2453
2022-02-26 10:31:24 +01:00
C. Scott Ananian
9e033de4f2 Don't double-escape the ellipses in Language::truncateForVisual()
It turns out this gets rid of a bunch of suppressed
"SecurityCheck-DoubleEscaped" that appear to have been accurate
warnings.

There seems to have been some confusion about how ::truncateForVisual()
is supposed to be used; in particular it is to be passed *unescaped*
output, because it is not (generally speaking) safe to truncate
HTML-escaped strings.  The goal of ::truncateForVisual() is to have
a specific number of codepoints in the output for display purposes,
the encoding of those codepoints is not an issue (htmlspecialchars
can be applied to the *return value*.)  If you need a specific number
of *bytes* you should be using ::truncateForDatabase().  If you want
a certain number of *HTML bytes* then the ::truncateHtml() method
is probably what you want.

Slightly refactor some code in RevDelLogItem to avoid a false positive.

Bug: T301205
Bug: T290624
Change-Id: I893362e049aedfa699043fcf27caf4815196f748
2022-02-10 17:09:18 -05:00
Tim Starling
6ccfe5d5c9 Fix PHP 8.0 failure of WikiExporterFactoryTest
In PHP 7, "some unlikely string 2" was a valid value for the $text
parameter to XmlDumpWriter::__construct(), because non-strict comparison
was used, so "some unlikely string 2" was coerced to integer 0 which is
equal to WRITE_CONTENT. In PHP 8.0, non-strict comparison has changed such
that "some unlikely string 2" != 0.

Pass strict=true to in_array() so that the test fails on both versions.
Please review for potential production impact.

Fix the test so that it passes after this change.

Bug: T283275
Change-Id: I5a84fb70db9d02ea10f87299eb41f80ba8fc787c
2022-01-21 15:20:57 +11:00
daniel
3bed8b11e9 BackupDumper: fix default value of --schema-version
Bug: T299174
Change-Id: I7303fada7fc32efa91d45c18cfb581a47a695286
2022-01-13 23:00:11 +01:00
Ariel T. Glenn
ca741848df Partial revert of I1a691f01cd82e60bf41207d32501edb4b9835e37 to unbreak dumps
Bug: T299020
Change-Id: I32fc4b0240efb2845bf064d07942fdbc9fe94342
2022-01-12 08:10:43 +02:00
jenkins-bot
d3f76ae3a0 Merge "export: Remove ignoring rev_page_id index" 2022-01-11 16:43:24 +00:00
TChin
47adb6d65a Refactor global variables to use MediaWikiServices instead
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
2022-01-10 13:55:53 -05:00
Amir Sarabadani
c843af877b export: Remove ignoring rev_page_id index
We are removing this index and that would cause queries that explicitly
ignore this index to fail.

Bug: T163532
Change-Id: I688c669a89f079e92213f41463b8e2a83c1a54b3
2022-01-10 10:46:55 +01:00
jenkins-bot
c114150637 Merge "WikiExporter: Avoid bitwise op with non-integer" 2021-12-08 15:57:00 +00:00
Ammarpad
dc66f78308 WikiExporter: Avoid bitwise op with non-integer
Before PHP8, the operation evaluates to zero; from PHP8, TypeError is raised

Bug: T296545
Change-Id: Ibdbf431fe7adb3cc3150aaf87d69b5989a1f0ac3
2021-12-08 08:09:12 +00:00
Derick Alangi
8fe9e0317f Introduce Redirect(Lookup&Store) services to handle redirects
The concept of a redirect chain didn't really work for a value of
max redirect > 1. In the ideal world, we just want to have a source
which points to target (source -> target) discarding the concept of
a redirect chain completely.

Having something like: source -> target -> target1 -> target2 doesn't
really work well with the current database design.

NOTE: Support for $wgMaxRedirect will be removed soon hence
deprecation without interfaces for replacement.

Bug: T290639
Change-Id: I469de6f85e405e8ddbe7abaa5b99b77cb9cf415d
2021-12-01 19:14:22 +01:00
Matěj Suchánek
50b010e5e8 Don't throw away '0' edit summary
Those "$comment ?? ''" are a bit ugly, but the other way around is
changing the return values of some ::getDescription implementations,
which is dangerous, at least.

Change-Id: I07e6b58258c256d19b058c56280150b70a46b407
2021-11-24 10:33:36 +00:00
Amir Sarabadani
275ca9c483 export: Ignore rev_page_id index
To see the difference in performance in different runs. Might get
reverted if the performance impact turns out being too much.

Bug: T285149
Change-Id: Iad7004a4786e9767074180d7a90a7a41c94a3cc5
2021-11-17 07:03:57 +01:00
Umherirrender
10e2f98a17 import/export: Add documentation for nullable arguments
Change-Id: Id8e4553a054a36011433d5705c699d1c2730456e
2021-10-16 21:49:18 +00:00
Alexander Vorwerk
af305e61cc Remove NS_IMAGE and NS_IMAGE_TALK from DumpNamespaceFilter
NS_IMAGE and NS_IMAGE_TALK have been removed as aliases of NS_FILE
and NS_FILE_TALK in 1.34.

Change-Id: I6f00366314645c4b9d627ed1810d6346499f087d
2021-10-11 15:23:44 +02:00
Alexander Vorwerk
111a7fd02d Update @since doc for WikiExporterFactory
The introduction got merged after 1.37 got branched.

Change-Id: I1c51e5c7910026f4834e7041b8ae781985fe422e
2021-09-16 19:10:46 +02:00
jenkins-bot
76ba780e41 Merge "WikiExporter: inject services" 2021-09-16 17:04:04 +00:00
Umherirrender
07b499fbcf build: Update mediawiki/mediawiki-phan-config to 0.11.0
Addition and remove of suppression needs to be done with the version
update.

Change-Id: I3288b3cefa744b507eadebb67b8ab08c86517c1c
2021-09-07 17:19:05 +02:00
Alexander Vorwerk
2fbf13812a WikiExporter: inject services
This patch injects services into WikiExporter. It also adds a
WikiExporterFactory service for creating WikiExporter instances.

Change-Id: Ib1547defea54c309865c116bc83d617c21568843
2021-09-06 10:03:37 +00:00
Umherirrender
2e4ee47c3d Cleanup mixed space/tab line indent
Change-Id: I833052a656b1ce419c0929f6f0514f2a33c2c4cc
2021-09-04 00:52:31 +02:00
Ariel T. Glenn
14e58963fc prevent PageIdentity checks in RevisionStore from breaking xml dumps
Bug: T286877
Change-Id: I77de8d25a9722d0bea69206c48a77fc8f5bf46e2
2021-07-19 12:20:18 -07:00
Petr Pchelko
5455e58967 Deprecate File::getUser in favor of File::getUploader
Change-Id: I8a45a8fdfa827f203e6bc123cb685d02c3612bb0
2021-06-02 09:06:09 -07:00
Tim Starling
83e184670c Stop using legacy ActorMigration field "log_user"
Bug: T278917
Change-Id: I1b78bad7e1fa43f5f82908567a7daad9c6cc79b9
2021-04-28 16:29:04 +10:00
daniel
8f9ff905f3 WikiExporter: replace Title in method signatures
Bug: T278459
Change-Id: I354f59accb05f7678f30dbead8aa79378cb0cf26
2021-04-09 19:16:38 +00:00
Umherirrender
8de3b7d324 Use static closures where safe to use
This is micro-optimization of closure code to avoid binding the closure
to $this where it is not needed.

Created by I25a17fb22b6b669e817317a0f45051ae9c608208

Change-Id: I0ffc6200f6c6693d78a3151cb8cea7dce7c21653
2021-02-11 00:13:52 +00:00
Umherirrender
56b2bd653a Improve and add documentation to import/export related classes
Change-Id: Ib2a74c1ac1a1902341e289961f4c1aa4dadd4bd8
2021-02-01 19:35:49 +00:00
jenkins-bot
625f0e5339 Merge "Change object to stdClass type hints in export related classes" 2020-11-18 00:24:00 +00:00
jenkins-bot
c7f12ebae2 Merge "Replace deprecated WikiPage::factory in import/export related classes" 2020-11-18 00:15:28 +00:00
Umherirrender
539b6abba2 Replace deprecated WikiPage::factory in import/export related classes
Change-Id: I58c5d1bc7bfca872fe0bcfdc51828dcef5abdf02
2020-11-15 18:32:21 +00:00
Umherirrender
4a702c5457 Change object to stdClass type hints in export related classes
Change-Id: Ifa09fe1f733a0bfdfdede5ccde0dc21c6c81b299
2020-11-15 09:44:00 +00:00
Umherirrender
4c2d2ec407 Improve docs about @param/@return object[] $row to stdClass[]
Change-Id: I4f85d90548caa1403e822ecb2333ab44787346f2
2020-11-13 23:38:06 +01:00
Umherirrender
9fb6d107ba Improve docs about @param/@return object $row to stdClass
Change-Id: I743d992db703f2b46b6e3abf80c14d026c6599f4
2020-11-13 00:08:21 +01:00
jenkins-bot
72a90d3d06 Merge "Document hook names in hook interfaces." 2020-10-02 16:15:21 +00:00
Umherirrender
d790580fda Fix typos related to repeated words
Change-Id: Ibc187d95b003017255bc87adf56afae7a59bd3db
2020-09-27 10:25:36 +00:00
daniel
2e57447c58 Document hook names in hook interfaces.
Bug: T258665
Change-Id: Ifddbf57f8aa2e3eb0d5845601376cbafa08ed407
2020-09-27 12:03:12 +02:00
Ariel T. Glenn
fd9998ee38 make prefetch for dumps work with large revisions for multiple files
Bug: T213405
Change-Id: Id8a08aad3e597b9548ae36f1b1564c51ac6346ad
2020-07-13 14:01:42 +03:00
daniel
e6e0ad2472 Replace "@stable for implementation" with "@stable to implement"
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: I17e5e92e24c708ffc846945a136347670a3a20c7
2020-07-13 11:05:49 +02:00
daniel
f59bf8a22f Use @internal instead of @private per policy
https://www.mediawiki.org/wiki/Stable_interface_policy mandates the use
of @internal. The semantics of @private was never properly defined.

Bug: T247862
Change-Id: I4c7c6e7b5a80e86456965521f88d1dfa7d698f84
2020-06-26 14:14:23 +02:00
Tim Starling
bb63899861 XmlDumpWriter: make invokeLenient take a closure
Assembling a function call from an object, method name and argument array
defeats static analysis and reduces readability. Instead, pass a closure
to invokeLenient().

Change-Id: Ia9d91d56af2895dbcc674afacc9a45b42d58c9f3
2020-06-04 01:38:46 +00:00
Tim Starling
47a1619027 Remove terminating line breaks from debug messages
A terminating line break has not been required in wfDebug() since 2014,
however no migration was done. Some of these line breaks found their way
into LoggerInterface::debug() calls, where they mess up the formatting
of the debug log.

So, remove terminating line breaks from wfDebug() and
LoggerInterface::debug() calls.

Also:
* Fix the stripping of leading line breaks from the log header emitted
  by Setup.php. This feature, accidentally broken in 2014, allows
  requests to be distinguished in the log file.
* Avoid using the global variable $self.
* Move the logging of the client IP back to Setup.php. It was moved to
  WebRequest in the hopes that it would not always be needed, however
  $wgRequest->getIP() is now called unconditionally a few lines up in
  Setup.php. This means that it is put in its proper place after the
  "start request" message.
* Wrap the log header code in a closure so that variables like $name do
  not leak into global scope.
* In Linker.php, remove a few instances of an unnecessary second
  parameter to wfDebug().

Change-Id: I96651d3044a95b9d210b51cb8368edc76bebbb9e
2020-06-03 12:01:16 +10:00
Tim Starling
e0a6dba3db WikiExporter: Cache a RevisionStore object
For style/readability.

Change-Id: I243c212122545b7252454e2e67531017707400bf
2020-06-01 01:00:24 +00:00
Tim Starling
68c433bd23 Hooks::run() call site migration
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
2020-05-30 14:23:28 +00:00
Ariel T. Glenn
29992f2527 Xml dumps should not die when the page redirect target cannot be determined
Bug: T253468
Change-Id: I4212073df993d60669d199c254fec242bde653d7
2020-05-24 17:33:33 +03:00
Reedy
c7206dae3f export: Remove excessive indenting and unnecessary else
Change-Id: I393e86774d832d8f89b6d29c82d3e7bc45d21a09
2020-05-09 22:16:27 +01:00
Umherirrender
018f9a3bd4 Add missing visibility on methods related to import/export
Change-Id: Iec6646a55a8c5d8e8a56dc7bccf8ef98a998ce1a
2020-05-09 11:56:48 +00:00