Commit graph

134 commits

Author SHA1 Message Date
Petr Pchelko
46db19ecdf Factor out rollback logic from WikiPage
Change-Id: I95da91875fcf2f53143c315560e35ccd5ffbf4b3
2021-04-14 11:49:07 -07:00
Tim Starling
e9a12612d3 SECURITY: Non-admin deleted enwiki page in fast double move
Bug: T272386
Change-Id: I8bf163e9dd056bccdbe9ad39537c46eb115da01a
2021-04-08 20:55:46 +01:00
DannyS712
a57b4c813e MovePage: fetch $wgMaximumMovedPages from config
Instead of using the global...

Change-Id: Idf563e8d9fbf828121bd468ae56ec9ceb9a53ee0
2021-03-29 23:42:16 +00:00
Petr Pchelko
7955db4d8d Convert MovePage to Authority
Change-Id: I7d4503711ab1b739ca88b5fd0aa9e336cbac06aa
2021-03-17 19:43:46 -06: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
Ammar Abdulhamid
f1b9408e53 Chain MutableRevisionRecord method calls
Now that we can do this. Use shorter variable names too for simplicity

Change-Id: I6f2fef5de4eba616d34be95976321f8dfb5fa9aa
2021-01-20 20:52:22 +00:00
Umherirrender
3f1c5d0eea Document list of change tags as string[]
Change-Id: I0ce2a8154af82a363fef126033b5819c4ee84842
2020-11-20 14:12:54 +01:00
Kosta Harlan
8f46f71e05 phpunit: Use a closure for services to enable unit testing
See also I2aba02560c41b

Bug: T266441
Change-Id: I2f6fec3e9ec1c63572bdc9fd626a457f8e7da630
2020-11-19 12:59:37 +01:00
Umherirrender
1273d68032 Inject WikiPageFactory into MergeHistory/MovePage
Via PageCommandFactory

Change-Id: Id4f247b9983cb22b8deb9d030ddeffed4ae1c956
2020-11-11 22:10:47 +01:00
jenkins-bot
f80d420949 Merge "MovePage: Handle target page deletion failure gracefully." 2020-10-22 13:53:57 +00:00
Ammar Abdulhamid
db20453b0a MovePage: Handle target page deletion failure gracefully.
Throwing exception is not appropriate here and will prevent proper usage
of ArticleDeleteHook, which is ostensibly meant to allow extensions to
cleanly abort the deletion if they need to.

When the target page deletion fails, instead of blowing everything up
with exception, just cancel the open atomic section and return the
user-friendly deletion error back to the user.

Bug: T265779
Change-Id: I66b4458a103f1274715e22a784344c55a62a59ac
2020-10-21 01:07:36 +00:00
Umherirrender
384938fba3 Use READ_LATEST when checking for exists on page move
This is the last check before moving and update the title on the page
table. Be sure to delete the page too avoid duplicate entry on the
index.

Change-Id: I75582a13bd1feedc072ea8d044470e445a9f6730
2020-10-18 20:36:20 +02:00
Mark A. Hershberger
b0595944e9
Use Title::getArticleID instead of Title::exists for internal check
Bug: T265665
Change-Id: Ifdbbd09709807f2ca0e776b2e9364f4d76cb4a49
2020-10-15 16:57:26 -04:00
jenkins-bot
091895ccd2 Merge "Add delete-redirect for deleting single-rev redirects during moves" 2020-09-04 14:04:35 +00:00
jenkins-bot
2cd59140ec Merge "Add extra details to error log to debug why null revision creation is failing" 2020-09-04 10:14:13 +00:00
DannyS712
77781b08c7 Add delete-redirect for deleting single-rev redirects during moves
A new user right, `delete-redirect`, is added (not given to anyone
by default). At Special:MovePage, if attempting to move to a single
revision redirect that would otherwise be an invalid target (i.e.
doesn't point to the source page), the user is able to delete the
target.

Deletions are logged as `delete/delete_redir2`, and the move is
then logged normally as `move/move`, mirroring current delete and
move logging.

To allow for separate handling by Special:MovePage,
MovePage::isValidMove now returns a fatal status `redirectexists` if
the target isn't valid but passes Title::isSingleRevRedirect.
Otherwise, `articleexists` is returned (as previously). Other callers
that don't intend to treat single revision redirects differently
should treat `redirectexists` the same as `articleexists`.

Currently, this deletion (like normal delete and move) cannot be
done through the move api. Since the deletion is only valid when
moving a page, unlike for normal deletion, deleting redirects with
this right cannot be done via the delete api either.

Bug: T239277
Change-Id: I36c8df0a12d326ae07018046541bd00103936144
2020-09-04 03:50:17 +00:00
Aryeh Gregor
a24e8a06b5 Mark CONSTRUCTOR_OPTIONS as internal
These were never meant to be part of the public interface and should not
ever have been marked with @since. They're only useful for constructing
the respective objects, which no outside users should be doing.

Change-Id: I86e01272d46fc72af32172d8a12b9180971d4613
2020-08-21 00:18:45 -04:00
Ammar Abdulhamid
a6284cc69c Add extra details to error log to debug why null revision creation is failing
Bug: T235589
Change-Id: Icae5cdc5b010e23d4956269f64069c0271217af7
2020-08-17 01:14:56 +00:00
Ed Sanders
7683f7d839 Use strict (in)equality with namespaces constants when LHS is definitely an integer
Change-Id: I8fede00dfe1270d93c5d78d3c36e788cddfc8a99
2020-07-31 18:03:28 +01:00
DannyS712
debaa34b0d MovePage: Don't use MediaWikiServices for services already available
Change-Id: I51ffb62b35fb6c934d0aafb9763dd4cbec288e2f
2020-07-13 06:53:25 +00:00
DannyS712
fe201ad436 Don't create Revisions for deprecated hooks if hook is not registered
Once the Revision class is hard deprecated, we will still need to
run hooks that use Revision objects; even though the hooks will be
deprecated, Revision objects still need to be created for them.

To ensure that deprecation warnings aren't triggered by creating
Revision objects in deployed code, for deprecated hooks only
create the Revision object if the hook is registered.

All hooks that pass Revision objects have already been hard deprecated.

Bug: T246284
Change-Id: I7e718551822825cd390662bb201dd13e2e527e8b
2020-07-01 03:44:36 +00:00
DannyS712
52051a996b Hard deprecate the TitleMoveComplete and PageContent(Insert|Save)Complete hooks
Bug: T250023
Bug: T250566
Change-Id: I7e701e0aac0b09acae448df3a7c72f2047bc2118
2020-07-01 00:22:56 +00: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
DannyS712
1b0f9e07e1 Hard deprecate the TitleMoveCompleting hook
Bug: T250023
Change-Id: I9b3351885e1c26b4caef5719d23d8d335516d867
2020-06-25 23:06:00 +00:00
jenkins-bot
be8dbab716 Merge "Add PageMoveCompleting hook, to replace TitleMoveCompleting" 2020-06-24 02:21:06 +00:00
Roan Kattouw
c8b9d849fc Add PageMoveCompleting hook, to replace TitleMoveCompleting
We intially thought we wouldn't need this and would only need
PageMoveComplete, but it turns out Flow does need it.

Bug: T250023
Bug: T255608
Change-Id: I8e7308541d2fe6d02b9dad63e1c86c89f6e7cf53
2020-06-16 22:27:28 -07:00
Catrope
6fc783ad2b Revert "Hard deprecate the TitleMoveCompleting hook"
This reverts commit 8f7f133ccf.

Per I8cdef229bf0a3, we still need this in Flow for now, to fix a UBN.

Bug: T255608
Change-Id: Id414c98161b9f560b14d4eaec8aedeec4659df27
2020-06-17 04:09:34 +00:00
DannyS712
538cfa4010 WikiPage::doEditUpdates - accept a RevisionRecord object
Passing a Revision is hard deprecated

Bug: T249563
Change-Id: Ic3f8fe9ed05820174b9cc3e9d2f4d17718947da0
2020-06-16 02:06:25 +00:00
DannyS712
8f7f133ccf Hard deprecate the TitleMoveCompleting hook
No remaining uses in deployed code

Bug: T250023
Change-Id: I5392d54a74c4ff19b977833bf5f8329c487afb19
2020-06-15 21:54:17 +00:00
jenkins-bot
87e9f467ff Merge "Replace TitleMoveCompleting and TitleMoveComplete hooks" 2020-06-10 20:56:42 +00:00
DannyS712
1594282ad0 Replace TitleMoveCompleting and TitleMoveComplete hooks
Bug: T250023
Change-Id: Iceb0aebb51769c413bf560d1c5b70a7213cb8b91
2020-06-10 20:03:31 +00:00
DannyS712
a6d16bd03d Remove unneeded creation of revision objects
Clean up some technical debt; use MutableRevisionRecord instead of
manually constructing a Revision from an array, remove last uses of
RevisionStoreDbTestBase::revisionToRow and remove the method.

Each file can be reviewed separately (except that the removal of
revisionToRow depends on replacing its usage)

Bug: T246284
Change-Id: I0bdc069b21a5c41ef8f9e972c5b17ff189d4a741
2020-06-10 09:09:55 +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
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
jenkins-bot
8cbf108de7 Merge "immobile-source-namespace: use blanknamespace for main namespace" 2020-05-28 21:32:09 +00:00
DannyS712
35c0518959 Inject SpamChecker where needed, hard deprecate EditPage static methods
Bug: T251015
Change-Id: I2df950d5ac9a7fc342409f778d7f9c2418cdd7af
2020-05-26 03:17:29 -07:00
jenkins-bot
6ca9c1f252 Merge "Replace NewRevisionFromEditComplete with RevisionFromEditComplete" 2020-05-14 00:22:57 +00:00
DannyS712
29aa36c06e Add MergeHistoryFactory interface, implemented by PageCommandFactory
Bug: T249446
Change-Id: I94676e065a8aed5cad2fe2d5cf16ca586adce97d
2020-05-13 19:08:09 +00:00
DannyS712
77e2dd7169 Replace NewRevisionFromEditComplete with RevisionFromEditComplete
Bug: T250338
Change-Id: I4ef249d013d1a9bc33d1d0f380c41963635012ab
2020-05-11 15:09:25 +00:00
DannyS712
1e2e9851ef MovePage::moveToInternal - remove use of Revision::insertOn
Construct a MutableRevisionRecord instead of creating a Revision object
with an array

Bug: T251856
Change-Id: Ia322a2a1faef53522a47974043e8d69a7290ce49
2020-05-05 04:03:46 +00:00
DannyS712
8a88d51536 WikiPage::updateRevisionOn - replace uses, hard deprecate Revision use
See codesearch - only deployed call outside of core is in flaggedrevs,
and already passes a RevisionRecord:
https://codesearch.wmflabs.org/deployed/?q=-%3EupdateRevisionOn%5C(&i=nope&files=&repos=

Also fixed a use of Revision::newFromId in orphans.php

Bug: T249561
Bug: T249021
Change-Id: I5933a278de8645b7005c11026c87ae27c0373770
2020-05-01 04:54:37 +00:00
DannyS712
b14965e75e Convert MovePageFactory to interface, implement in PageHandlerFactory
Bug: T249446
Change-Id: I1335d976b992f44c8609c298f0ec19d81afa7b84
2020-04-27 23:26:28 +00:00
DannyS712
77bcb3a1b1 immobile-source-namespace: use blanknamespace for main namespace
Also for target-namespace

Bug: T224350
Change-Id: I878b5f7ea1d2cebfc295bf08de372726a580cc28
2020-04-11 01:08:31 +00:00
Brad Jorsch
68e0ff3f64 MovePage: Don't fail to delete a nonexistent file
If there's no file to be moved (e.g. it's a redirect in the File
namespace), don't fail with an error about being unable to delete the
nonexistent file. Just let it work.

Bug: T249550
Change-Id: I605b0e4b39e7863bddbebf339994c819528e3a4c
2020-04-07 13:58:39 +00:00
Brad Jorsch
3309ead776 MovePage: Use correct Title when creating the null revision
Prior to I4a5fe41fe, the call to Revision::newNullRevision() would load
the Title from the database and use that to create the null revision.

I4a5fe41fe, in removing uses of the deprecated Revision, changed that to
call RevisionStore::newNullRevision() directly. Instead of loading the
Title, that takes one as a parameter. $this->oldTitle was being passed,
which at this point in the execution contains the correct page_id but
the *old* page_namespace/page_title. Passing $nt would also not work,
since that contains the target page's old page_id (likely 0).

The solution is to reset the ID in $nt (so it contains both the correct
ID and name), so we can then pass it to RevisionStore::newNullRevision().

Bug: T248789
Change-Id: I8e0ae616006c0cebde60cfa53c0a842bd2cc1545
2020-04-02 11:59:08 -04:00
Brad Jorsch
c81f992387 MovePage: Remove pre-MCR code
The code path updating rev_content_model on a page move wasn't flagged
with $wgMultiContentRevisionSchemaMigrationStage, so removing it was
missed in I1d9f5465.

Bug: T198557
Change-Id: Ibf3fe35112136393c69091fd02f8b433f53f6eb8
2020-03-26 10:23:20 -04:00
daniel
495323c063 Remove compat code for pre-MCR schema.
NOTE: This was manually tested to ensure it does not
break updates, see T242764.

Bug: T198557
Change-Id: I1d9f5465018bae10124514bc38169e23e0e613e6
2020-03-24 19:45:47 +01:00
jenkins-bot
f39160300a Merge "Pass a user to WikiPage::doDeleteArticleReal, use new signature" 2020-03-19 14:42:51 +00:00
DannyS712
7380aba100 Pass a user to WikiPage::doDeleteArticleReal, use new signature
Don't need to worry about supporting prior versions, since its core

Bug: T247869
Change-Id: Iad9397327731817b8c276d0b9786c3bc5ecf6476
2020-03-19 00:54:29 +00:00
Petr Pchelko
f6f1c41992 Remove usages of deprecated Revision from MovePage
Still have to wrap into the Revision object for hooks.

Bug: T246284
Change-Id: I4a5fe41fe4ba42defab7ecefd942f13ec5711538
2020-03-18 16:46:05 -07:00