Commit graph

1179 commits

Author SHA1 Message Date
Reedy
b038d6333a Fix even more PSR12.Properties.ConstantVisibility.NotFound
Change-Id: I6d98efcfac1f1c0ab6a442e0af6d5daa6ef7801a
2020-05-16 00:28:41 +00:00
C. Scott Ananian
2712cb8330 Fix impedance mismatch with Parser::getRevisionRecordObject()
Parser::getRevisionRecordObject() returns `null` if the revision is
missing, but it invokes ParserOptions::getCurrentRevisionRecordCallback()
(ie, Parser::statelessFetchRevisionRecord() by default) which returns
`false` as its error condition.

This reverts commit ae74a29af3, and instead
fixes the bug at its root.

Bug: T251952
Change-Id: If36b35391f7833a1aded8b5a0de706d44187d423
2020-05-06 12:44:05 -04:00
DannyS712
28cb11e8ca Replace uses and hard deprecate Revision::getSha1
Bug: T251233
Change-Id: I815db5120094909b2820b8ca56d65a62f6af82d1
2020-04-30 17:44:11 +00:00
Tim Starling
df65f09669 Revert "Correct capitalization of BeforeParserFetchTemplateAndTitle hook"
In the new hook system, it is invalid to have two hooks that differ only
in case.

This reverts commit afb5b38e15.

Change-Id: I160ece0a7bc68c748037b383137364b787be86a0
2020-04-30 07:50:24 +10:00
Arlo Breault
4d4e14372f Move french space armoring after doBlockLevels
This was moved before doBlockLevels in c23cb2c when it used to be a more
general cleanup that conflicted with it.  Since 02ff859 that no longer
seems necessary.

Further, this gives the consistency of armoring inside wikilinks and
avoids some unnecessary row definition list colons being armored.

Maybe this should be moved to the end of internalParseHalfParsed after
language conversion but before tidying, where the other call to the
sanitizer happens, Sanitizer::normalizeCharReferences.  But let's change
things one step at a time and start by moving it here before we try to
move it further.

The goal here being to make french space armoring a post-processing
step, rather than an intermediate transformation, more consistent with
how Parsoid will/wants to do it.

Bug: T197879
Change-Id: I3eae3719ab8fb50b7996d4fd8a9fa0d5ca250023
2020-04-29 16:51:28 -04:00
DannyS712
b8e6903183 Replace uses and hard deprecate Parser::getRevisionObject
Also removes a use of Revision::getUserText

Bug: T249384
Bug: T250579
Change-Id: I9c7763cc1d3442cd41d1ffc804fb18bfbd8be84f
2020-04-28 21:02:58 +00:00
C. Scott Ananian
efb5afe7eb Fix incorrect return type documentation for Parser::getRevisionUser()
Change-Id: I2ad51797d841e4cc2a433a27bbaa07b5a2f9a62c
2020-04-27 18:59:02 +00:00
jenkins-bot
eb88d78c3a Merge "Refactor magic word implementations out of Parser.php" 2020-04-22 08:34:54 +00:00
jenkins-bot
ad4c3e47cc Merge "Replace uses and hard deprecate Revision::newFromTitle" 2020-04-20 15:29:28 +00:00
DannyS712
0f826d1f73 Replace uses and hard deprecate Revision::newFromTitle
Also fixed a use of ::newFromId in benchmarkParse and Parser

Bug: T249183
Change-Id: I3219a72f1085836205dc497e2236b52db24d7c16
2020-04-18 04:47:10 +00:00
C. Scott Ananian
b328aa3311 Add ParserBeforePreprocess hook
This will allow us to deprecate the ParserBeforeStrip and ParserAfterStrip
hooks by covering the one case where ParserBeforeStrip is called but
ParserBeforeInternalParse is not.

Bug: T250450
Change-Id: Ia298fecba77e97fc30dc30a09ac69a4239767d8c
2020-04-17 17:20:22 -04:00
C. Scott Ananian
95350d3dcf Deprecate ParserBeforeTidy hook
Untidy parser output should not be exposed outside mediawiki core.
Callers should use ParserAfterTidy instead.

Code search:
https://codesearch.wmflabs.org/deployed/?q=ParserBeforeTidy&i=nope&files=&repos=
https://codesearch.wmflabs.org/search/?q=ParserBeforeTidy&i=nope&files=&repos=

Depends-On: Ia6bd94fc937a9bff77843e6734e88ba8991d04ec
Change-Id: I4a0aae7b17fb522a5e4f90edad3a0b7137b270a6
2020-04-17 17:20:20 -04:00
C. Scott Ananian
afb5b38e15 Correct capitalization of BeforeParserFetchTemplateAndTitle hook
We deprecate the incorrect capitalization and add a new hook with the
correct capitalization.  There are very few users of this hook, and none
in WMF-deployed code.

WMF-deployed code search:
https://codesearch.wmflabs.org/deployed/?q=BeforeParserFetchTemplateAndtitle&i=nope&files=&repos=

Everything code search:
https://codesearch.wmflabs.org/search/?q=BeforeParserFetchTemplateAndtitle&i=nope&files=&repos=

It would be tempting to remove this hook entirely, but it seems to
serve a valuable purpose in allowing page and template fetches at a
specific "old" timestamp.  (Extension:Memento and Extension:TimeTravel
don't seem to have implemented this feature, however.)

Change-Id: I501b0ee35b81fee424d45084088a6ed63c3dfd54
2020-04-17 17:19:44 -04:00
C. Scott Ananian
d8bb54a965 Deprecate infrequently-used parser-related hooks
The following parser-related hooks have no users in deployed code:
- InternalParseBeforeSanitize
- ParserFetchTemplate
- ParserSectionCreate
- ParserPreSaveTransformComplete
- BeforeParserrenderImageGallery

Code search in WMF-deployed code:
https://codesearch.wmflabs.org/deployed/?q=%5Cb%28InternalParseBeforeSanitize%7CParserFetchTemplate%7CParserSectionCreate%7CParserPreSaveTransformComplete%7CBeforeParserrenderImageGallery%29%5Cb&i=nope&files=&repos=

Code search in all code:
https://codesearch.wmflabs.org/search/?q=%5Cb%28InternalParseBeforeSanitize%7CParserFetchTemplate%7CParserSectionCreate%7CParserPreSaveTransformComplete%7CBeforeParserrenderImageGallery%29%5Cb&i=nope&files=&repos=

Removing as many infrequently-used hooks as possible will aid our
transition from the legacy parser to alternative parsers.

Bug: T236809
Change-Id: I3a09fbe6436232ae0b417ad61b19f8df6d0485e0
2020-04-17 17:18:01 -04:00
C. Scott Ananian
7a2331706f Deprecate Parser::firstCallInit()
Originally we created a Parser object on every request, and so care
was taken to make Parser construction lightweight.  In particular,
all potentially costly initialization was moved into a separate
Parser::firstCallInit() method.  Starting with 1.32, parser construction
has instead been done lazily, via the ParserFactory registered with
MediaWikiServices.  The extra complexity associated with the old manual
lazy initialization of Parser is therefore no longer needed.

Deprecate Parser::firstCallInit() as part of a general plan to refactor
the Parser class to allow subclasses and alternate parser implementations.
Add some tests to assert that parsers are being created lazily, and are
not being created when they are not needed.

Bug: T250444
Change-Id: Iffd2b38a2f848dad88010d243250b37506b2c715
2020-04-17 12:49:34 -04:00
C. Scott Ananian
8546e633b1 Make Parser::$mVariables private
This was overlooked in a5afda55bf, probably
because casual inspection of
 https://codesearch.wmflabs.org/deployed/?q=mVariables&i=nope&files=&repos=
made it look like extensions/AbuseFilter was using Parser::$mVariables.

But AbuseFilterParser (and AbuseFilterCachingParser) is its own thing, not
a subclass of Parser, and the (re)use of the $mVariables name for the
property is just coincidence.

Change-Id: I4debb11c804b2ef4f1b727d521f38f35de691708
2020-04-17 12:49:34 -04:00
DannyS712
84ef6d8315 Add RevisionRecord alternatives to Parser and ParserOptions methods
The following Parser methods were deprecated in favor of new methods:
- ::fetchCurrentRevisionOfTitle (use fetchCurrentRevisionRecordOfTitle)
- ::statelessFetchRevision (use statelessFetchRevisionRecord)
- ::getRevisionObject (use getRevisionRecordObject)

The following ParserOptions methods were likewise deprecated:
- ::getCurrentRevisionCallback (use getCurrentRevisionRecordCallback)
- ::setCurrentRevisionCallback (use setCurrentRevisionRecordCallback)

To ensure backwards compatibility with calling the ParserOptions
CurrentRevisionCallback methods, while allowing extensions to call
the CurrentRevisionRecordCallback methods without worrying about if
other extensions also deployed have been updated, both
::getCurrentRevisionCallback and ::getCurrentRevisionRecordCallback,
if the respective option is still set to the default, check if the
other option is set and, if it is, convert the other option rather
than returning thed default.

It's not pretty, but it works, and will be hard deprecated shortly
and removed in 1.36.

Bug: T249384
Change-Id: I66cbcb963a96cc49c75ca72faa7e439ae6d6614d
2020-04-17 16:29:09 +00:00
C. Scott Ananian
a2cb76937d Hard deprecate Parser::OutputType and Parser::Options
These were deprecated earlier.

Code search: https://codesearch.wmflabs.org/deployed/?q=-%3E%28OutputType%7COptions%29%5C%28&i=nope&files=&repos=

Depends-On: I548a710cdfa0eedb5a28b4e0196839995f5de568
Depends-On: I08b0788461fae5fa48818aa2eda01c866499b30e
Depends-On: I70e0ecb201d5ffdc3ccb75caf552a1dee4ad9e60
Depends-On: Ieea168b47e1a0f5b67d0e2db8503281e0f4743c8
Change-Id: I7e1902158e5bfa1a2466e2e30e13cb396228eab7
2020-04-16 16:37:02 -04:00
C. Scott Ananian
7dd65ba43d Deprecate old-style accessor/mutation methods of Parser
Parser::Options(), Parser::OutputType(), and Parser::Title() have been
deprecated.  All of these had incomplete replacements with either a
::get* method or a ::set* method (and in the case of Title, both).
Add the missing getters or setters where required.

Only Parser::Title() has been hard deprecated.  Replacing the other
uses in deployed code requires the newly-added Parser::getOutputType()
or Parser::setOptions() methods, so we can't replace those methods in
our deployed code after this patch has been merged.

Code search:
https://codesearch.wmflabs.org/deployed/?q=-%3E%28OutputType%7CTitle%7COptions%29%5C%28&i=nope&files=&repos=

Bug: T236809
Change-Id: I0b4d5f170216597afb259cedbb13b8028d284715
2020-04-16 16:37:02 -04:00
C. Scott Ananian
0eaaceea3e Hard-deprecate direct calls to Parser::__construct()
These were deprecated in 1.34, but let's put in some hard deprecation
warnings for 1.35 since this class is certainly going to be refactored
in the future to allow both the legacy parser and Parsoid to extend
Parser as a base class.  Access via the ParserFactory will be fine,
but cut down on the number of different ways Parsers can be constructed
and initialized.

Code search:
https://codesearch.wmflabs.org/deployed/?q=new%20Parser%5C%28&i=nope&files=&repos=
https://codesearch.wmflabs.org/deployed/?q=getMockBuilder%5C%28%20Parser%3A%3A&i=nope&files=&repos=
https://codesearch.wmflabs.org/deployed/?q=new%20Parser%3B&i=nope&files=&repos=

Bug: T236811
Depends-On: Ib3be450c55e1793b027d9b4dae692ba5891b0328
Depends-On: I9d16513f8bd449a43b0a0afbd73651a5c0afa588
Depends-On: I74efda708470efeb82f8f80346ec1ee7e9fd8f2b
Depends-On: I777475d0ab0144e53240173f501d6c8da35d33fb
Change-Id: If36283ec0b78b188b61f658639105d1ed7653e0a
2020-04-16 16:34:34 -04:00
jenkins-bot
b75d059690 Merge "Deprecate $wgParserConf" 2020-04-16 20:32:36 +00:00
jenkins-bot
ff4134cb9f Merge "Parser: Add type hints for objects, arrays and callables" 2020-04-16 20:21:15 +00:00
C. Scott Ananian
a286a59e86 Deprecate $wgParserConf
This setting has been effectively constant since 2008.  In modern code
we should be using a ParserFactory instead to customize Parser creation
and not calling the Parser constructor directly (T236811).

Because the ParserFactory is cached, which freezes the current value of
the content language and other options, we need to reset the ParserFactory
object when running parser tests (T248977).  Thanks to
Peter Ovchyn <peter.ovchyn@speedandfunction.com> for first uncovering this
issue and suggesting a fix in I4203bf7719a8555a09b72cdb5b1ae7a6e1505acf.

Code search:
https://codesearch.wmflabs.org/deployed/?q=wgParserConf&i=nope&files=&repos=
https://codesearch.wmflabs.org/deployed/?q=ParserConf&i=nope&files=&repos=

Bug: T248977
Bug: T236811
Depends-On: I97d58750c91b06eeca5d810509becdf53a39cc95
Depends-On: Idf59cd54146d31c1c32883f4318e6a0bf60e1a8a
Change-Id: I787f22ea9bf59a049b13631ba6974866a1300988
2020-04-16 15:57:37 -04:00
C. Scott Ananian
83a22b7fcd Remove codepaths which ran parser in 'untidy' mode
Disabling tidy has been deprecated since 1.33.  This cleans up the code
paths which still used untidy output.

Bug: T198214
Change-Id: I821ef3b8f59b272d983583d407b2f0794fe1e791
2020-04-13 21:34:04 +00:00
Fomafix
99104944e8 Parser: Add type hints for objects, arrays and callables
Also
* remove unneeded reference &$user in getUserSig.
* add missing false in Doxygen tags.

Change-Id: Icc3860cda66918f56d9014d6c19c4be47d4b5464
2020-04-11 15:49:06 +02:00
C. Scott Ananian
0a53c9725a Refactor magic word implementations out of Parser.php
This allows them to be more easily reused by other Parser implementations
(ie, Parsoid), and helps keep Parser.php compact.

Bug: T236813
Change-Id: I68fb1e786374e445b7df047934c532d7e10b8e94
2020-04-10 14:43:40 -04:00
C. Scott Ananian
8c18f2b41c Add a wfDeprecated to an overlooked code path where parser output is not tidy
We formally deprecated running the parser with tidy disabled in 1.33, but
I missed a hard-deprecation on this code path.

Be careful not to spam the logs with deprecation warnings triggered by
(deprecated) API requests, though.

Change-Id: I10f64e76ec0c5aee8b26fc00bc11ebb0e39f961b
2020-04-02 11:53:53 -04:00
C. Scott Ananian
a5afda55bf Deprecate most public fields of Parser; make private those unused outside core
Fields which have at least one user outside of mediawiki-core (as reported
by the 'everything' search in codesearch.wmflabs.org) have been deprecated;
those which have no users have been immediately made private.

Code search url for the fields made private:
https://codesearch.wmflabs.org/search/?q=-%3E%28mFunctionSynonyms%7CmFunctionTagHooks%7CmStripList%7CmVarCache%7CmImageParams%7CmImageParamsMagicArray%7CmSubstWords%7CmConf%7CmExtLinkBracketedRegex%7CmUrlProtocols%7CmAutonumber%7CmLinkHolders%7CmDefaultSort%7CmTplRedirCache%7CmForceTocPosition%7CmTplDomCache%7CmOutputType%7CmLangLinkLanguages%7CcurrentRevisionCache%7CmProfiler%7CmLinkRenderer%29&i=nope&files=&repos=

Bug: T248889
Change-Id: I28e88e574ec9f99231bd590e9a87fbc1c4349fa1
2020-03-31 11:47:34 -04:00
C. Scott Ananian
3a7ecc11b4 Prepare to deprecate public fields of Parser
This is preparatory work for I28e88e574ec9f99231bd590e9a87fbc1c4349fa1
which simply splits comma-separated lists into individual lines and
does minor documentation tweaks, so that the main body of the follow-up
patch is easier to review.

Bug: T248889
Change-Id: I196d047ce694fe0e8447bd96455c7fb1b75247e4
2020-03-31 11:47:34 -04:00
C. Scott Ananian
baca583042 Make private some Parser constants
These have no users outside Parser.php.

Code search url for the constants made private:
https://codesearch.wmflabs.org/search/?q=%28EXT_LINK_ADDR%7CEXT_IMAGE_REGEX%7CSPACE_NOT_NL%29&i=nope&files=&repos=

Bug: T248889
Change-Id: I46f19c4386c2f2e8cbdb8979db628493127c1925
2020-03-31 11:47:34 -04:00
C. Scott Ananian
9d12c89378 Remove Parser::$mRevIdForTs
Nothing appears to use Parser::$mRevIdForTs, it's not even initialized.
Remove this unnecessary field.

Code search:
https://codesearch.wmflabs.org/search/?q=mRevIdForTs&i=nope&files=&repos=

Bug: T248889
Change-Id: Ic023cde7e8b1101978c674d0694ab5d4cb9ee900
2020-03-30 23:41:08 +00:00
C. Scott Ananian
a6b1cdac97 Remove Parser::$mIncludeCount
Nothing appears to use Parser::$mIncludeCount, not even the parser itself.
Remove this unnecessary field.

Code search:
https://codesearch.wmflabs.org/search/?q=mIncludeCount&i=nope&files=&repos=

Bug: T248889
Change-Id: I15892c5bfdc6a1f2763824f4a9e5cfbc90e48b54
2020-03-30 21:46:23 +00:00
C. Scott Ananian
f35fcb811a Remove Parser::$mDefaultStripList
The reset state of the Parser $mStripList was made a public field,
presumably so it could be customized by extensions?  But nobody seems
to have ever used this.  Remove this unnecessary extension point.

Code search:
https://codesearch.wmflabs.org/search/?q=mDefaultStripList&i=nope&files=&repos=

Bug: T248889
Change-Id: I10fa521f62e6b9696ab6b96bcf7eb05091b35022
2020-03-30 21:45:28 +00:00
C. Scott Ananian
a3c9621ad0 Deprecate unusual uses of the ParserGetVariableValueSwitch hook
Ensure that the value returned is always also added to the cache, since
we (eventually) want to remove the hook's access to
$parser->mVarCache.  Also don't allow monkeying with the value passed
as $magicWordId, even though it's a reference.

Code search:
https://codesearch.wmflabs.org/deployed/?q=ParserGetVariableValueSwitch&i=nope&files=&repos=

Bug: T236813
Depends-On: Ia12faefada7e4cf04f1a6b12b3ed1703bf28e437
Depends-On: Ia9e2e00c6b7d0e62cbe80c3b124165b691b1ff3d
Depends-On: I1e48fa47b8723958d543a69aaf9b62b872200dc5
Depends-On: If9a0885a8664c22473ade712364c2dd0a5c04e0b
Change-Id: I3d6b281f8e4e0bf68eefbf9767047527b4573b79
2020-03-27 08:59:21 -04:00
C. Scott Ananian
063445581c Always cache magic word expansions
The existing magic word API (including hooks) gives implementers direct
access to $parser->mVarCache and full control of caching.  Simplify the
implementation (prior to moving the magic word implementations out of
Parser.php) by always caching built-in magic words in $parser->mVarCache.

The cases which were skipping the cache don't vary anyway.

This behavior change is split from the rest of the refactoring in
I68fb1e786374e445b7df047934c532d7e10b8e94 to allow it to be deployed
separately, just in case there was some strange reason this would
cause regressions in practice.

Bug: T236813
Change-Id: I34a0d9a37e41c854c801d546427fc8cd0fe39dc4
2020-03-27 08:58:39 -04:00
C. Scott Ananian
99f6b82995 Deprecate the ParserGetVariableValueVarCache hook
We don't want to expose the internal caching mechanism of the parser.
There are no uses in deployed WMF code:

https://codesearch.wmflabs.org/deployed/?q=ParserGetVariableValueVarCache&i=nope&files=&repos=

Bug: T236813
Change-Id: I1b0a5cf7d32be86a45d7231940360e2bfce7275f
2020-03-26 18:47:30 -04:00
C. Scott Ananian
37022ad343 Remove Parser::getDefaultPreprocessorClass(), deprecated in 1.34
Code search:
https://codesearch.wmflabs.org/search/?q=getDefaultPreprocessorClass&i=nope&files=&repos=

Bug: T204945
Change-Id: Ie7c0d8d9b61088efce9719878b3abcc9ed9ebc80
2020-03-26 16:10:34 -04:00
C. Scott Ananian
5468ab66ba Deprecate Parser::enableOOUI()
All existing uses in our codebase are to OutputPage::enableOOUI.

Further, the implementation here in Parser::enableOOUI calls
OutputPage::setupOOUI() without arguments, which means that the skin
and the page directionality are not initialized correctly.
(OutputPage::enableOOUI() does this correctly).  So even if anyone
*was* using Parser::enableOOUI... they shouldn't be.

Use $parser->getOutput()->enableOOUI() instead.

This was originally added in 2d50e28975 to
enable OOUI to be used from parser tags (T101666), but the current patches
for this (eg I29e876c768819413bf31499f067d545732e591b0) can just use
$parser->getOutput()->enableOOUI() instead.

Code search:
https://codesearch.wmflabs.org/search/?q=enableOOUI&i=nope&files=&repos=

Bug: T236809
Change-Id: I71be19c1d735fef5b781c68ef7ba47cafc37595d
2020-03-26 16:09:05 -04:00
Petr Pchelko
1e4beb3107 Hard deprecate Revision::newKnownCurrent
Bug: T246284
Change-Id: Iba93fdeb0a88e6fa4068f03367b23a1f670257c6
2020-03-18 11:52:44 -07:00
Umherirrender
47ef87e272 Bundle services at top of TraditionalImageGallery::toHtml
Add Parser::getBadFileLookup to get the instance from there when having
a parser instance

Change-Id: I48e254406ffb62d847404a5f8e81a35f8d4c83f1
2020-03-14 20:29:37 +00:00
Umherirrender
878330ae30 Use MediaWikiServices::getRepoGroup
Change-Id: Ibcef425c2e0c95d6d2f98b8d889f85ebcb33f20a
2020-03-14 13:16:12 +01:00
Tim Starling
eb6c5f70d9 Add ParserPreSaveTransformComplete hook
This is needed to migrate an extension (AutoWIGO2) that uses ArticleSave
to a version of MW after that hook was removed. The extension was using
ArticleSave to do its own PST processing, which probably doesn't work
with PageContentSave, and wasn't really the right way to do it in the
first place. Surprisingly, there were no useful hooks in PST or its
callers.

Change-Id: If1b3d7ea130a2b77609afe206eedc8445e1ab9f9
2020-03-08 09:52:09 +11:00
Thiemo Kreuz
1606d4a206 parser: Fix incomplete PHPDocs, remove meaningless comments
As long as no parsing was started, and $this->startParse() was not
triggered at least once, the $this->mOptions property is null. This
does have a lot of consequences. I'm intentionally not fixing all of
them in this patch to not make it to big, only the most obvious ones.

This came up in I6714400 which was actually running into this issue.

This patch also removes a few comments that *literally* repeat what
the code already says. Such comments are not helpful, but clutter the
code, make it harder to read, and create error-prone redundancy.

Change-Id: Ic1ab18242b2f79d3da2a2e7c25e3af3e6907f7b4
2020-03-04 11:08:00 +01:00
Thiemo Kreuz
c05bdcee8b Remove unreachable null checks after isset()
isset() does two things: It checks if a variable (or array element)
is declared, *and* it checks if it is null. If a variable is null,
isset() fails as if the variable was not set. All these additional
null checks are dead code.

Change-Id: I71e8cc26dac839c9d081bf00b4164b7b5147e586
2020-02-28 21:40:48 +00:00
Tim Starling
44d51cb04e Fix the namespace of SpecialPageFactory
Follows-up d4045035b0.

This class was added to the MediaWiki\Special namespace, contrary to the
plan in T166010 which reserves that namespace for core special pages.
Instead, use MediaWiki\SpecialPage, following the directory in which it
is located.

Also, fix two bugs which prevented the introduction of a namespaced
class alias.

Bug: T166010
Change-Id: I6e31340aaae32a89beb7e45b79d76a7fea9808d2
2020-02-21 13:46:19 +11:00
Petr Pchelko
204fa7e509 Remove usages of deprecated Language methods
Change-Id: Iad3375b141b1d87c890baec6ecd16ed92f93e699
2020-02-16 00:45:48 +00:00
Aaron Schulz
ea6bc312e7 parser: apply $wgMiserMode restriction to REVISIONID for NS_USER/NS_PROJECT
Bug: T235957
Change-Id: I7dbf7ab5b730a18d44e4bbaad46475c01d3b1291
2020-02-07 22:55:52 -08:00
Peter Ovchyn
50e3bd4fac parser: Inject a LanguageConverterFactory through DI containers:
1. into class Parser
2. into class LinkHoderArray
3. into class DefaultPreferencesFactory

Add more tests for DefaultPreferencesFactory:
1. testVariantsSupport verifies that converter with variants is used correctly.
2. Test testUserGroupMemberships verifies that membership is used correctly

Bug: T243320, T243321, T243317
Change-Id: I1e5c37e18332d0d32391c74c06e3d84862e48df8
2020-02-04 14:42:03 +02:00
Peter Ovchyn
61e0908fa2 languages: Introduce LanguageConverterFactory
Done:
* Replace LanguageConverter::newConverter by LanguageConverterFactory::getLanguageConverter
* Remove LanguageConverter::newConverter from all subclasses
* Add LanguageConverterFactory integration tests which covers all languages by their code.
* Caching of LanguageConverters in factory
* Make all tests running (hope that's would be enough)
* Uncomment  the deprecated functions.
* Rename FakeConverter to TrivialLanguageConverter
* Create ILanguageConverter to have shared ancestor
* Make the LanguageConverter class abstract.
* Create table with mapping between lang code and converter instead of using name convention
* ILanguageConverter @internal
* Clean up code

Change-Id: I0e4d77de0f44e18c19956a1ffd69d30e63cf51bf
Bug: T226833, T243332
2020-02-03 11:38:03 +02:00
C. Scott Ananian
a20d4094f8 Deprecate/make private internal callbacks invoked inside Parser.php
Parser::magicLinkCallback() and Parser::makeFreeExternalLink() are not
called from outside the parser and have been made private.

Parser::attributeStripCallback() did have one use outside MediaWiki core,
so it has been deprecated rather than made private.  The one use inside
the parser has been converted to an anonymous callback.

Code search:
https://codesearch.wmflabs.org/search/?q=magicLinkCallback%7CmakeFreeExternalLink%7CattributeStripCallback&i=nope&files=&repos=

Change-Id: Id909b745f9dea1481d09de4747f4aa32648bf85b
2020-01-30 14:00:36 -05:00
C. Scott Ananian
70c4ea9b1a Make private Parser::incrementIncludeSize(), which is not used outside the class
Code search:
https://codesearch.wmflabs.org/search/?q=incrementIncludeSize&i=fosho&files=&repos=

Change-Id: I14da911be23ef2d806c876ebb9ac9cf1fe782e24
2020-01-30 13:08:47 -05:00
C. Scott Ananian
dc4fd76e69 Hard-deprecate Parser::doBlockLevels(), which Parsoid won't support
This is an odd "partial parse" endpoint which won't be supported by
the unified Parsoid parser.  Most places it appears in our codebase
it is just a name-check, mostly complaining about how broken it is.
It is not called by any WMF-deployed code.

Code search:
https://codesearch.wmflabs.org/search/?q=doBlockLevels&i=fosho&files=&repos=

Change-Id: Iad2a1e5ed593c1f6299b8b45e4390b415537c84c
2020-01-30 12:58:13 -05:00
C. Scott Ananian
0fc8f7cf83 Hard-deprecate Parser::fetchTemplate()
This is a follow up to I6f7c3e31ff394781fbaaef267a2772de05f85bf2, which
deprecated Parser::fetchTemplate but forgot to include the wfDeprecated()
call.

Code search:
https://codesearch.wmflabs.org/search/?q=fetchTemplate%5C%28&i=nope&files=&repos=

Change-Id: I912b538e6e77c35498308c168316803ddde1f137
2020-01-30 12:50:19 -05:00
C. Scott Ananian
25f3b8ad68 Deprecate Parser::fetchTemplate() in favor of ::fetchTemplateAndTitle()
This reduces the API surface of Parser, in preparation for further
refactoring of the Parser class.  Parser::fetchTemplateAndTitle() was
introduced in MW 1.6.0 in 2007, so is always appropriate as a replacement.

Code search:
https://codesearch.wmflabs.org/search/?q=fetchTemplate%5C%28&i=nope&files=&repos=

Depends-On: I2865b12b55aa1412a861fb8db10239018a1d1580
Change-Id: I6f7c3e31ff394781fbaaef267a2772de05f85bf2
2020-01-28 20:00:54 -05:00
C. Scott Ananian
a8f3eb96ce Hard deprecate Parser::setFunctionTagHook()
This is not used in production code.

Code search:
https://codesearch.wmflabs.org/search/?q=setFunctionTagHook%7CmFunctionTagHooks&i=nope&files=&repos=

Change-Id: Ie03b1687d1c65be23213035d7cb4011ef763b69a
2020-01-28 16:20:40 -08:00
C. Scott Ananian
9f0adbdb81 Remove Parser::setTransparentTagHook()
The transparent tag hooks are not used anywhere in public git.

Codesearch link:
https://codesearch.wmflabs.org/search/?q=setTransparentTagHook%7CreplaceTransparentTags%7CmTransparentTagHooks&i=nope&files=&repos=

Depends-On: I0df0ca2fc7ed05dc6dc413bd0a6d38533b66e428
Change-Id: I8384f47bbcde7604efa41b83db0dbc4f429219a8
2020-01-28 16:20:40 -08:00
jenkins-bot
eaebf057f3 Merge "Remove $wgMaxGeneratedPPNodeCount" 2020-01-29 00:14:55 +00:00
C. Scott Ananian
e149a38d4f Remove $wgMaxGeneratedPPNodeCount
This no longer has any effect.  The getter and setter in ParserOptions
aren't used in any public git code, and so have been removed without
deprecation.

Bug: T204945
Followup-To: I727f003f9a42d0c92bcbcce8a8289d5af6cd1298
Change-Id: Id48effcba48d1ae1621a4e17a70e65b73f2473b7
2020-01-28 16:54:53 -05:00
jenkins-bot
5e462e5efe Merge "Remove all traces of preprocessorClass from $wgParserConf" 2020-01-26 21:48:23 +00:00
jenkins-bot
f9a08c0c83 Merge "Remove Preprocessor_DOM, deprecated in 1.34" 2020-01-26 02:02:44 +00:00
C. Scott Ananian
0eb9f18d8d Remove all traces of preprocessorClass from $wgParserConf
Bug: T204945
Followup-To: I727f003f9a42d0c92bcbcce8a8289d5af6cd1298
Change-Id: I23821686ad666728d7d196e089f40be4b76b7390
2020-01-25 13:15:16 -05:00
C. Scott Ananian
5cbb64f56a Remove Preprocessor_DOM, deprecated in 1.34
Remove the deprecated Preprocessor_DOM class, which was hard-deprecated
in 1.34.  This begins to simplify parser configuration and reduce redundant
code paths, but I've left two things for cleanup in a future patch:

1. The `preprocessorClass` configuration option to the parser, exposed
in `$wgParserConf`, ServiceWiring, ParserFactory, etc.  There is no reason
for this to be exposed as configurable, but I've left this clean up to a
future patch.

2. The `$wgMaxGeneratedPPNodeCount` configuration, exposed also in
ParserOptions.  Only Preprocessor_DOM calculated this count, and since
we are only using Preprocessor_Hash now, this configuration has no effect.
But since this value was exposed in ParserOptions and elsewhere, I've
deprecated where needed but left this clean up to a future patch.

Bug: T204945
Change-Id: I727f003f9a42d0c92bcbcce8a8289d5af6cd1298
2020-01-25 11:22:45 -05:00
C. Scott Ananian
b01642a27c Mark @internal a number of Parser methods not used outside MW core
These should not be considered a part of the public MW API.

Note that interwikiTransclude is used in maintenance scripts in the
Math extension, but that seems to be a reasonable use of an @internal
method.

Code search link:
https://codesearch.wmflabs.org/deployed/?q=limitationWarn%7CisCurrentRevisionOfTitleCached%7CinterwikiTransclude%7CargSubstitution%7CrenderImageGallery%7CgetFlatSectionInfo%7CmarkerSkipCallback%7CparseWidthParam&i=nope&files=&repos=

Change-Id: I50e52fd57ba3b5ad7cc7f2b21ec772374268179f
2020-01-25 16:12:04 +00:00
Thiemo Kreuz
ea01e7cfbb parser: Remove unused ParserAfterUnstrip hook
Introduced in 2015 via If83b062. Unfortunately the patch fails to mention
why the hook was introduced. A review comment asking for the missing
information was ignored.

The hook was introduced exclusively for the Cite extension, see I0e136f9.
The Cite change got reverted a few days later via I1a71854. As far as I
can tell the hook (oddly specific and underspecified anyway) was never
used again, neither for Cite nor for anything else.

Now unused: https://codesearch.wmflabs.org/search/?q=ParserAfterUnstrip

I suggest to just remove it with no deprecation phase.

My team is currently working on Cite, essentially turning it upside down.
I'm not aware of a need for this hook.

Change-Id: If68a88d7afff60385ff1e33fd13716b20d01a313
2020-01-25 09:20:52 +01:00
James D. Forrester
0958a0bce4 Coding style: Auto-fix MediaWiki.Usage.IsNull.IsNull
Change-Id: I90cfe8366c0245c9c67e598d17800684897a4e27
2020-01-10 14:17:13 -08:00
James D. Forrester
4f2d1efdda Coding style: Auto-fix MediaWiki.Classes.UnsortedUseStatements.UnsortedUse
Change-Id: I94a0ae83c65e8ee419bbd1ae1e86ab21ed4d8210
2020-01-10 09:32:25 -08:00
Aaron Schulz
6de44014de parser: further restrict "revisionid" by namespace in $wgMiserMode
Follows-up c537eb1868.

The restrictions used to only apply to "content" namespaces, which
is typically just NS_MAIN. Wikis like Commons and Wikidata use custom
values, NS_FILE and $LexemeNamespace, respectively.

Now, only yield the integer ID for user, project, and talk pages.
This means that NS_FILE, NS_CATEGORY, and other namespaces with
content intended for readers, only yield '' or '-' for this work.

Bug: T235957
Change-Id: Id0110c9ee91ad5750164e9a047bcd6d7621930c1
2020-01-06 11:16:51 -08:00
Kunal Mehta
99007e96c7 Use namespaced IPUtils class
Change-Id: I047e099a93203a59093946d336a143d899d0271f
2020-01-01 02:36:49 -08:00
Daimona Eaytoy
598c4d7fcb build: Upgrade phan to 0.9.0
Scalar casts are still allowed (for now), because there's a huge amount
of false positives. Ditto for invalid array offsets.

Thoughts about the rest: luckily, many false positives with array offsets
have gone. Moreover, since *Internal issues are suppressed in the base
config, we can remove inline suppressions.

Unfortunately, there are a couple of new issues about array additions
with only false positives, because apparently they don't take
branches into account.

Change-Id: I5a3913c6e762f77bfdae55051a395fae95d1f841
2019-12-07 20:16:19 +00:00
jenkins-bot
097ad02261 Merge "REST compare: bundle section offset information" 2019-11-13 01:18:01 +00:00
Thiemo Kreuz
cf42131019 Streamline/fix code by using short ?: and ?? syntax
Change-Id: I27dc0c8a1a184571ed96abdea22af953510457cd
2019-11-11 11:17:13 +01:00
Tim Starling
8299d7ae8f REST compare: bundle section offset information
Bug: T236964
Change-Id: Ib97b0fa0de682404fb9df2ecef55a3526c54a31f
2019-11-11 16:25:35 +11:00
James D. Forrester
8255ecd074 Parser: Drop ::disableCache(), deprecated in 1.28
Change-Id: Ide0b28f821c55fb008e50c199032f1c34334ac1d
2019-11-05 17:07:00 -05:00
jenkins-bot
ee2751a70b Merge "Minor cleanups" 2019-11-05 10:46:25 +00:00
C. Scott Ananian
8dbc866e91 Hard deprecate Parser::disableCache()
Among deployed extensions, only used in the Quiz extension.

Full list of uses (some false positives):
https://codesearch.wmflabs.org/search/?q=disableCache&i=nope&files=&repos=

Depends-On: I956a88120d07d76d1afa9d06e95d31055f9b07f1
Change-Id: I6419754de6cbc01af07b6c0eafb8396bd720a58d
2019-11-04 21:22:11 +00:00
C. Scott Ananian
3397bd43e7 Parser: remove/make private historically-public methods
These were hard-deprecated in 1.34.  This continues work to clean up
the Parser API.

Bug: T236810
Change-Id: I0b2258a63d73370fd770612a6ca437509676d71c
2019-11-04 15:43:20 -05:00
C. Scott Ananian
cff5c92cb9 Parser: Add Title type hints
This reverts commit c16b0a533e0d7350bceca7ccbe490efa3e3ce4c4, now
that an appropriate period of time has passed since this behavior
was deprecated.

Bug: T235392
Change-Id: I076ae0dbfbbb8be731367e4641f9c8aacf7586e9
2019-11-04 14:08:26 -05:00
Max Semenik
f1c9cf8879 Minor cleanups
* Identifier case
* Returning a void function result
* Unused variable
* Missing documentation

Change-Id: Ibfd2fc5ae1d91c7c9c6a34bcd4523384d3bca576
2019-11-03 17:10:23 -08:00
Tim Starling
68d87dba9f Remove Parser::serializeHalfParsedText() and helpers
It was deprecated in 1.31, It was a failed experiment, intended to
improve performance, but it never worked and makes the code
much more complex. I also removed two LinkHolderArray helpers which were
accidentally not marked deprecated -- codesearch confirms that they are
not called by anything.

Change-Id: I74754265dde388b590f0b4c995cb4a35a1318299
2019-11-01 15:22:29 +11:00
jenkins-bot
74a646c0f2 Merge "Parser: Remove ::getConverterLanguage(), deprecated in 1.32" 2019-11-01 01:55:28 +00:00
Fomafix
14b853672d Parser: Remove ::getConverterLanguage(), deprecated in 1.32
Use Parser::getTargetLanguage() instead.

Change-Id: Id1075b91f84d2c1766754410476aafb7c9144604
2019-11-01 01:43:15 +00:00
C. Scott Ananian
023bb7677f Deprecate Parser::replaceLinkHolders / replaceLinkHoldersText
Because this method is used in the ImageMap extension, we can't
immediately hard-deprecate replaceLinkHolders.

Code search:
https://codesearch.wmflabs.org/deployed/?q=replaceLinkHolders&i=nope&files=&repos=

Bug: T236810
Change-Id: If02130ffc86d0d9db2a455efcd29641a8206f0a0
2019-10-29 16:53:35 -04:00
C. Scott Ananian
736b6b27f3 Deprecate additional public methods of Parser
Affected:
Parser::armorLinks()
Parser::makeKnownLinkHolder()
Parser::getImageParams()
Parser::parseLinkParameter()
Parser::stripAltText()

It wasn't obvious there was a better name for these, so just rename
them with a `...Private` suffix and deprecate the old names.  When
the deprecated public methods are removed we'll rename the private
methods to remove the `...Private` suffix again.

Code search:
https://codesearch.wmflabs.org/deployed/?q=armorLinks%7CmakeKnownLinkHolder%7CgetImageParams%7CparseLinkParameter%7CstripAltText&i=nope&files=&repos=

Bug: T236810
Change-Id: I44458490fa86abd0ead048a4c94021da6be333f0
2019-10-29 16:53:35 -04:00
C. Scott Ananian
d7cd12e81f Deprecate Parser::splitWhitespace() / Parser::createAssocArgs()
These methods are not used anywhere in deployed code.

Parser::createAssocArgs() is used in Extension:DataTable2, but it should
just copy the implementation from Parser, it's very little code.

Code search:
https://codesearch.wmflabs.org/deployed/?q=splitWhitespace%7CcreateAssocArgs&i=nope&files=&repos=

Bug: T236810
Change-Id: I4e6a39e2ecf7a3a568e26ad1d8ce1166a44a5ad9
2019-10-29 16:52:22 -04:00
C. Scott Ananian
dcae22c8fa Deprecate Parser::areSubpagesAllowed() / Parser::maybeDoSubpageLink()
These are unused outside the Parser and are so short it's not worth
renaming them to make them private; just hard-deprecate the methods
and inline the implementation in the small # of places they appear.

Code search:
https://codesearch.wmflabs.org/deployed/?q=areSubpagesAllowed%7CmaybeDoSubpageLink&i=nope&files=&repos=

Bug: T236810
Change-Id: Ia06c65409a3158b083bcc59c9f6e347945b375c0
2019-10-29 16:50:21 -04:00
C. Scott Ananian
045ec0a408 Deprecate Parser implementation methods (will be private in next release)
The following public methods were renamed and made private; the old name
is hard-deprecated and calls the new renamed private method:

Parser::doMagicLinks() => handleMagicLinks()
Parser::doDoubleUnderscore() => handleMagicLinks()
Parser::doHeadings() => handleHeadings()
Parser::doAllQuotes() => handleAllQuotes()
Parser::replaceExternalLinks() => handleExternalLinks()
Parser::replaceInternalLinks() => handleInternalLinks()
Parser::replaceInternalLinks2() => handleInternalLinks2()
Parser::getVariableValue() => expandMagicVariable()
Parser::initialiseVariables() => initializeVariables()
Parser::formatHeadings() => finalizeHeadings()
Parser::test{Pst,Preprocess,Srvus}() => fuzzTest{Pst,Preprocess,Srvus}()

Additionally, the following methods are not used externally, but are
used outside the Parser class by core code.  They have been marked
@internal:

Parser::doQuotes() (used by {{#displaytitle}}),
Parser::getExternalLink{Rel,Attribs}() (used by Linker),
Parser::normalizeLinkUrl() (used by Special:LinkSearch and elsewhere).
Parser::{brace,arg,extension}Substitution() (used by PPFrame)

Code search query:
https://codesearch.wmflabs.org/deployed/?q=do%28MagicLinks%7CDoubleUnderscore%7CHeadings%7CAllQuotes%29%7Creplace%28ExternalLinks%7CInternalLinks%28%7C2%29%29%7CgetVariableValue%7CinitialiseVariables%7CformatHeadings%7Ctest%28Pst%7CPreprocess%7CSrvus%29%7CdoQuotes%7CgetExternalLink%28Rel%7CAttribs%29%7CnormalizeLinkUrl%7C%28brace%2Carg%2Cextension%29Substitution&i=nope&files=&repos=

Bug: T236810
Change-Id: I19a43ffc5dcfdd2981b51079c33422c964acb076
2019-10-29 14:00:29 -04:00
jenkins-bot
7a54595d10 Merge "Parser: Hard deprecate getConverterLanguage" 2019-10-28 08:48:44 +00:00
Fomafix
9bae9db4cc Parser: Hard deprecate getConverterLanguage
getConverterLanguage is deprecated since MediaWiki 1.32.
getConverterLanguage always return a Language object and never null.

Change-Id: Ia0480c76416ef1e925619d9e85c7134c2ecf2296
Depends-On: Iea4771161d129c49f6482e1a6822e1324bf2fb49
2019-10-27 19:58:41 +00:00
jenkins-bot
a10deed7cb Merge "Parser.php: Export an experimental convenience method for Parsoid/PHP" 2019-10-18 20:48:56 +00:00
C. Scott Ananian
dd9e6124b4 Deprecate setting Parser::mTitle to null
This never happens in core code; however extensions have slipped into
a state of sin.

Bug: T235392
Change-Id: Ia254949cd8b3bc162b11dcc911dcce40d91bf1b7
2019-10-18 15:46:53 -04:00
Subramanya Sastry
c90e20f1cb Parser.php: Export an experimental convenience method for Parsoid/PHP
* This ensures we run all necessary hooks that extensions expect
  will be run for their content.

* We will rip out this method once we decide / discover that we don't
  need it anymore.

Change-Id: I683bd6c3cc2c3f4d65326adab78cdf70ae39a51a
2019-10-18 11:30:39 -05:00
Fomafix
d91a136ae7 Revert "Parser: Add Title type hints"
This change reverts most of commit 3dff713fe4.

Especially the return type hints for getTitle() and Title() are reduced
to allow the type null as return value, because SematicMediaWiki uses
this by

	$this->parser->getTitle() instanceof Title

to check if there is a valid Title object.

The parameter type hints for setTitle() and Title() are kept.

Bug: T235392
Change-Id: I72ac1c9d37059876dbc7cd38158e7abd212da8fe
2019-10-18 08:28:49 +02:00
Daimona Eaytoy
e3412efac3 Unsuppress PhanParamReqAfterOpt, use PHP71 nullable types
These were all checked with codesearch to ensure nothing is overriding
these methods.
For the most part, I've updated the signature to use nullable types; for
two Pager's, I've just made all parameters non-optional, because you're
already forced to pass them with a required parameter at the end.

Bug: T231636
Change-Id: Ie047891f55fcd322039194cfa9a8549e4f1f6f14
2019-10-10 11:53:58 +02:00
James D. Forrester
74f8ae0a24 [BREAKING CHANGE] Services: Convert Parser's static to a const now HHVM is gone
Change-Id: I54eafc84694bf68fe791b482865a1763c0439cbf
2019-10-09 12:26:48 -07:00
Fomafix
3dff713fe4 Parser: Add Title type hints
getTitle() and Title() will never return NULL anymore. When mTitle is
not set then a TypeError be thrown at runtime. The explicit local
checks for is_null( $this->mTitle ) are not needed anymore when
$this-getTitle() instead of $this->mTitle is used.

Change-Id: I09a178e5c6938954edb2949f13660227d6a01fbc
2019-09-26 16:34:12 +02:00
jenkins-bot
c96b8354fc Merge "Parser: Use 'Special:Badtitle/Parser' instead of 'NO TITLE'" 2019-09-26 14:15:53 +00:00
Fomafix
a6e8182b9b Parser: Use 'Special:Badtitle/Parser' instead of 'NO TITLE'
Change-Id: I818ac7d4766c3e52b56c2bd4abddb88e4140003b
2019-09-22 21:35:15 +02:00
Daimona Eaytoy
b138a9b228 Fix using null for a non-nullable argument
These are reported by phan as PhanTypeMismatchArgumentNullableInternal
when null_casts_as_any_type is disabled.

Change-Id: I85076ee31c1bfc59a19600e84da0d915e425890a
2019-09-19 16:55:03 +00:00
Daimona Eaytoy
b5cbb5ab3f Upgrade phan config to 0.7.1
This allows us to remove many suppressions for phan false positives.

Bug: T231636
Depends-On: I82a279e1f7b0fdefd3bb712e46c7d0665429d065
Change-Id: I5c251e9584a1ae9fb1577afcafb5001e0dcd41c7
2019-09-04 08:20:53 +00:00
Daimona Eaytoy
c659bc6308 Unsuppress another phan issue (part 7)
Bug: T231636
Depends-On: I2cd24e73726394e3200a570c45d5e86b6849bfa9
Depends-On: I4fa3e6aad872434ca397325ed7a83f94973661d0
Change-Id: Ie6233561de78457cae5e4e44e220feec2d1272d8
2019-09-03 17:19:21 +00:00