Commit graph

54 commits

Author SHA1 Message Date
Amir Sarabadani 530c13120b Try to use EditStash before re-rendering
Bug: T288639
Change-Id: Ia2b41f1b5da0ed4f938b92d04f661d8b869fce01
2021-08-16 15:26:45 +02:00
Amir Sarabadani e7a37be1c8 Don't generate HTML when asking for ParserOutput
It doesn't need it and it's really expensive to produce.

Bug: T288639
Change-Id: I5f3ec6c38aec2cf4b5c648e00691272a3941d9ce
2021-08-12 11:29:55 +02:00
Amir Sarabadani 5d90e38616 Avoid using deprecated WikiPage::prepareContentForEdit
Which would prevent every edit attempt rendering the content twice.

Bug: T288639
Change-Id: I802ed3685b7f2bea3616399fd92a9720f204f134
2021-08-11 19:51:58 +00:00
Roman Stolar bbb4bec7e4 Replace depricating method IContextSource::getWikiPage to WikiPageFactory usage
Bug: T275710
Change-Id: I3a762c4c097e4b3e89e82e5d0e62e9eecc2486d3
2021-06-28 17:04:10 +03:00
jenkins-bot eb38eb13dc Merge "Handle EditFilterMergedContent hook properly to break hook chains and display error message" 2021-06-26 12:57:19 +00:00
DannyS712 55399c4938 Pass a user to WikiPage::prepareContentForEdit()
Bug: T285447
Change-Id: I745a7c185e35295e578fdb1d36a6841bb4a1e126
2021-06-24 03:29:13 +00:00
libraryupgrader bca1a61958 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 35.0.0 → 36.0.0
* php-parallel-lint/php-parallel-lint: 1.2.0 → 1.3.0

npm:
* grunt: 1.3.0 → 1.4.0
* lodash: 4.17.19 → 4.17.21
  * https://npmjs.com/advisories/1673 (CVE-2021-23337)

Change-Id: If7fce8d1738a011f37a9fcbfacbb52cf214d9bea
2021-05-13 21:44:31 +00:00
Func d4dd5a9408 Handle EditFilterMergedContent hook properly to break hook chains and display error message
Extensions are supposed to return false to break hook chains when failed, which can avoid unnecessary call of later handlers in other extensions and work around with problems caused by difference betwen multiple triggers.

On mediawiki version 1.36 and before, just returning false in this hook can't display error message by default.
Set $status->value manually still to provide backward compatibility.

Bug: T280312
Change-Id: I456a40ce676c486b4ae12f00a7024a4c070448cd
2021-04-24 02:06:59 +00:00
Umherirrender 32ea1e7596 Use HookHandlers for core hooks
Bug: T271028
Depends-On: If7930a196272f782a6541fb0bc301e04e2d56f38
Change-Id: I7b5b6da058360bb60057f275234f972305ec0ea1
2021-04-15 21:02:35 +00:00
Reedy 4cbdb4fbc2 Add grepability comments
Collapse one nested if

Change-Id: I0d01239bc9ca3999688df2bb6d6360ccf563d956
2021-03-01 17:38:38 +00:00
Reedy c2e57657f4 Use updated CheckUser Hooks class
Depends-On: I3f66b660f9d59c0e88b182c9b06ee8cec994348e
Change-Id: I79e12fcd328bda203013a438b7f9a472b351dd48
2021-02-11 19:31:42 +00:00
Daimona Eaytoy 6ad12a26dc Make User parameter required in BaseBlacklist::filter
Depends-On: Idf346b7d5952c1af1547d178a3634d1116d4f85b
Depends-On: I7fe28c67e5a95de870ac98b4f2571733f4a7d302
Change-Id: I62478bec3a284b7aa56ea94f49be30199a6be3e4
2020-11-24 06:16:42 +00:00
Daimona Eaytoy da1af447e2 Always pass a User object to SpamBlacklist::filter
There are some usages outside of SpamBlacklist that must be fixed. After
doing that, the signature should be updated to make the user
non-optional.

Note: I've changed the signature because external callers only pass the
first two parameters. Hence, it's easier to change it now, add a
User parameter to the callers and then make it non-optional, than having
to pass $preserveLog and $mode in all callers and then swapping the
order (as that would break the world).

Change-Id: I0714eb9dbc6af3c775ab7a81cb4b59e687183f77
2020-11-10 19:13:01 +00:00
Ammar Abdulhamid 4c8c7bbb51 Remove manual passing of $this to closures
For a long time (since PHP 5.4.0) this indirection is unnecessary.

Change-Id: I1bf83f24e9b8762e929520bc94845b77ead511e6
2020-10-26 06:58:12 +00:00
daniel 5b0da2baf3 Ensure instance cache does not interfere with tests.
Tests need a way to rest BaseBlacklist::instances, so they can be sure
they operate on a clean slate. This is also needed to ensure they do not
operate on real settings, targetting a real remote host.

Bug: T262443
Change-Id: Ic320f7a72da7f26e0931ce3d393fc5a61d43d4fc
2020-09-29 17:20:44 +00:00
DannyS712 ad2f4fbc43 Update hooks to use PageSaveComplete
Update extension to require MW 1.35+, so the hook is available

Bug: T250566
Change-Id: I8dda65f1dcdeff68b884e83dafe9843d974bd3c4
2020-06-23 19:26:10 +00:00
Umherirrender 1f70c7ce00 Pass function name to HttpRequestFactory::get
Useful for logging
Replace deprecated Http::get with service (since 1.34)

Change-Id: I84382c37295e3b09a660983b206b526f19334568
2020-06-07 13:04:51 +02:00
Reedy e0b4d0bcc4 Fix PSR12.Properties.ConstantVisibility.NotFound
Bug: T253169
Change-Id: Ibf6e74907477febe44bbaf8aac0f2bd59914675d
2020-05-20 01:05:42 +01:00
Timo Tijhof 423a6983bd Remove use of internal $messageMemc variable
Same as I04a0e578d7 in TitleBlacklist extension.

Bug: T189966
Bug: T243175
Change-Id: Ifc14f2ee1f176d025d6d1c6158405277f20a1ac1
2020-03-18 17:14:41 +00:00
libraryupgrader 4d1029117e build: Updating composer dependencies
* jakub-onderka/php-console-highlighter: 0.3.2 → 0.4.0
* mediawiki/minus-x: 0.3.2 → 1.0.0
* mediawiki/mediawiki-phan-config: 0.9.0 → 0.9.1

Change-Id: I2930f838e914f9b3f7917e773038c197af019851
2020-01-30 12:24:37 +00:00
DannyS712 0e17b75bc9 Remove use of global $wgUser and a use of global $wgRequest
Bug: T241704
Change-Id: I816b94558156bb9fea314047702d18cd3f1dd3e9
2020-01-04 09:27:22 +00:00
libraryupgrader 2d3b9f1d61 build: Updating mediawiki/mediawiki-phan-config to 0.9.0
Change-Id: I56fbe7470e6dbc7ee2a2e381dc9e811db4b79224
2019-12-29 00:01:51 +00:00
Bartosz Dziewoński 17313f9738 EmailBlacklist: Suppress warnings from invalid user-supplied regexes
They are suppressed identically in SpamBlacklist.php.

Bug: T64864
Change-Id: I808aa87a8c59ec63f7335236cab1fad6e5d8b86a
2019-11-07 23:08:16 +01:00
Umherirrender f287bf7950 build: Updating mediawiki/mediawiki-phan-config to 0.8.0
Bug: T235049
Change-Id: I326457e7779882bcc945753b9406605e76302e8a
2019-11-04 20:04:48 +01:00
James D. Forrester 5a78869772 build: Upgrade mediawiki-codesniffer to v28.0.0
Change-Id: I2e639461d789d0b293d0f97da30a2fcf160804a6
2019-10-11 11:58:00 -07:00
daniel 9d55ccf86c Remove backwards compatible code.
Per Krinkle's comment at
<https://gerrit.wikimedia.org/r/c/mediawiki/extensions/SpamBlacklist/+/504797/1#message-fb539927b0a2241080960229b9dc2453f6fcd78f>, no backwards compatibility is needed.

Change-Id: Icbf005840d734c7d14a380197f2239a07ba53dbf
2019-09-27 10:52:33 +02:00
daniel 6d559a12fe Support MCR database schema.
This maintains backwards compatibility with MW 1.31.

Cross-wiki loading functionality verified manually.

Bug: T233358
Change-Id: I53e218d8d268060b0b81c5c9bab24b7f5a37917a
2019-09-23 14:49:13 +02:00
Niklas Laxström e74a0120a0 Random cleanups
Change-Id: I0748d1b2062cc8f81175e07c4785eb11e784fe28
2019-09-12 16:19:13 +02:00
Bartosz Dziewoński 5ddc45b62c Actually return errors for action=edit API
Setting 'apiHookResult' results in a "successful" response; if we want
to report an error, we need to use ApiMessage. We already were doing
this for action=upload. Now our action=edit API responses will be
consistent with MediaWiki and other extensions, and will be able to
take advantage of errorformat=html.

Additionally, remove incorrect 'message' value from action=upload
output. It was anyway redundant to the normal error information.

To avoid user interface regressions in VisualEditor, the changes
I3b9c4fef (in VE) and I106dbd3c (in MediaWiki) should be merged first.

Before:
    {
        "edit": {
            "spamblacklist": "example.com/test|example.net/test",
            "result": "Failure"
        }
    }

After:
    {
        "errors": [
            {
                "code": "spamblacklist",
                "data": {
                    "spamblacklist": {
                        "matches": [
                            "example.com/test",
                            "example.net/test"
                        ]
                    }
                },
                "module": "edit",
                "*": "The text you wanted to save was blocked ..."
            }
        ],
        "*": "See http://localhost:3080/w/api.php for API usage. ..."
    }

For comparison, a 'readonly' error:
    {
        "errors": [
            {
                "code": "readonly",
                "data": {
                    "readonlyreason": "foo bar"
                },
                "module": "main",
                "*": "The wiki is currently in read-only mode."
            }
        ],
        "*": "See http://localhost:3080/w/api.php for API usage. ..."
    }

Bug: T229539
Depends-On: I106dbd3cbdbf7082b1d1f1c1106ece6b19c22a86
Depends-On: I3b9c4fefc0869ef7999c21cef754434febd852ec
Change-Id: Id36aa6bdb8f873fe7deb8123a7fc774103721c01
2019-09-10 20:44:35 +00:00
Bartosz Dziewoński 2f1456c4e9 Remove backwards compatibility code for Revision::getQueryInfo()
Revision::getQueryInfo() was added in MediaWiki 1.31. We already
require that or later in our extension.json, so we can safely drop it.

The deprecated methods called by this code have been recently removed
(Id35544b879af1cd708f3efd303fce8d9a1b9eb02) and calling them is
causing Phan failures.

Change-Id: I474367d00c6d3917f1416023901132c0649b3163
2019-09-10 22:41:34 +02:00
Derick Alangi b9c0f0709b Avoid usage of deprecated $wgContLang global (dep in 1.32)
Change-Id: Ia87a464c22be764deacd699fb66f96a663ccfe7c
2019-09-02 09:49:39 +01:00
Bartosz Dziewoński 19c69f4158 Improve edit/upload error message integration
Compared to other extensions like AbuseFilter, SpamBlacklist's
integration with MediaWiki's error reporting was weird.

* When dealing with page editing, we returned two (or more)
  separate messages, which would then be rendered in a list.
  This looks weird, especially if the messages have fancy wrapper
  boxes etc.
* When dealing with file upload, we returned incomplete
  error message, not reporting the blacklisted link.

Now, in both cases, we return a single error message
containing all the details.

Change-Id: I4ca8e67e03726696a428093cc9fb547a6daa1492
2019-08-29 09:23:58 +00:00
Umherirrender 8ab128b44a Remove entry point check for files only contain classes
See https://www.mediawiki.org/w/index.php?title=Register_globals&oldid=3063934#Make_sure_code_is_only_executed_in_the_right_context
for more information

Bug: T230026
Change-Id: I937b002d7fa7469aa1b90a413900b9649e524e18
2019-08-07 17:16:41 +02:00
libraryupgrader a0e6c32f29 build: Updating mediawiki/mediawiki-codesniffer to 26.0.0
The following sniffs now pass and were enabled:
* MediaWiki.Commenting.FunctionComment.MissingDocumentationProtected

Additional changes:
* Committed package-lock.json (T179229) too.

Change-Id: Ic5edf46789ab191b59aaae0921b3038381e704b7
2019-07-16 01:27:19 +00:00
Dan Andreescu a72c0f339a Abandon EventLogging instrumentation
The instrumentation attempted here has been implemented more correctly
by https://phabricator.wikimedia.org/T214706.  This change removes
instrumentation from this extension.  It should not affect much,
because emitting events was already disabled.

Bug: T162365
Change-Id: I8f02c62d41260a62b37a7738d69c039d2ce7562f
2019-07-15 16:52:17 -04:00
James D. Forrester 3f6da90ccf build: Upgrade phan-taint-check-plugin from 1.5.x to 2.0.1
Change-Id: I7ec790eb9e3867c37eef8bc2a13687306f446f30
2019-07-11 07:25:20 +00:00
Derick Alangi 4d939a399a Avoid usage of deprecated ObjectCache::getMainWANInstance()
Replacement with services made available in 1.28 and this extension
requires 1.31. So, the replacement is good.

Change-Id: I1960a36541c9578abc3178a3a5ddcac7c32b8292
2019-07-03 13:53:41 +01:00
jenkins-bot 81ae3d404d Merge "Remove deprecation note in comment" 2019-05-31 20:33:34 +00:00
Thiemo Kreuz 25e4813363 Remove not needed array type hint from hook handler
This parameter is not used anyway. It's possible it is null, as
demonstrated in Id2caa44. Because this code does not need it anyway,
it should not do any harm to remove this type hint.

Change-Id: Id107501e6d62e567354c90e5d3aeec47dbf57298
2019-05-15 20:37:20 +02:00
libraryupgrader 896b9942a8 build: Updating mediawiki/mediawiki-phan-config to 0.5.0
Change-Id: I3de08f7b42583450b46ecbbcc687af7bdc1442a3
2019-03-10 22:31:52 -07:00
Daimona Eaytoy 25b65a40fe Migrate to new Phan
Bug: T216942
Change-Id: I92c55f8af579a92baa02d9bd1b25b8290f0cd196
2019-03-09 12:42:42 +00:00
Umherirrender f3ff95ce08 Use ExtensionRegistry rather than class_exists
Change-Id: I0b23b5c7338f9f0376cfa8c66a765021054d2dfd
2019-03-03 02:22:02 +01:00
Reedy 24804b14c9 Update MediaWiki namespaced AtEase global functions
Change-Id: Ie1816dc2c73e284f412e479cf1345984093050d5
2019-02-13 00:25:53 +00:00
Adam Wight 1c9b42b619 Remove deprecation note in comment
The method is alive and well, used by the pageSaveContent hook.

Change-Id: I0764cbfc090b634b30ffe15c77dc303874c87ae2
2019-01-02 11:15:49 -08:00
Umherirrender 2f715fdf33 Add method scope visibility
Change-Id: I405c27b802000155609e8d32efc5016d8b2fba60
2018-11-02 12:54:59 +01:00
Umherirrender 57ad1703e7 Fix caller name in SpamBlacklist::getCurrentLinks
Seeing {closure} in the logs as caller is not helpful

Change-Id: I1c874317bb44792c4104c2e722179d37ed66f99d
2018-09-30 13:24:28 +02:00
libraryupgrader 06c6c73ef4 build: Updating mediawiki/mediawiki-codesniffer to 22.0.0
Change-Id: I075a20dc74586318abae470758f3583597692ad3
2018-09-03 19:29:35 +00:00
libraryupgrader 54ac4af184 build: Updating mediawiki/mediawiki-codesniffer to 21.0.0
Change-Id: Ic30d624822b5228f201e6b4183075bd591e3e675
2018-07-27 19:06:44 +00:00
Brad Jorsch 1bdc9aa6bb Replace deprecated ContentHandler::makeParserOptions()
Having a different ParserOptions for each content model isn't feasible
in an MCR world. And the only thing using this was Wikibase, which has
been fixed to do what it needs in a different way.

Bug: T194263
Change-Id: Ib8ed827012c7bd73fcdaa6c0c6edd44869c79f14
Depends-On: I01373b29ee25fa9346c6b0317155be4ccdc8c515
2018-07-11 12:34:25 -04:00
Aaron Schulz f8b957167e Hash the title in "blacklist" cache keys
This avoids "Key contains invalid characters" in some cases.

Change-Id: I720c5e89e38b7da69c87134d1ff51787b4fa5c0c
2018-07-10 12:38:53 +01:00