Make PageEditStash::checkCache() accept an UserIdentity
This allows using the already into PageEditStash injected UserFactory instead of falling back to global state in DerivedPageDataUpdater. Change-Id: I18f198d323c3ca001c6a0de91bc669180cd1d11c
This commit is contained in:
parent
3cf6ab6e52
commit
5aa1bf33f6
3 changed files with 8 additions and 23 deletions
|
|
@ -371,15 +371,6 @@ class DerivedPageDataUpdater implements IDBAccessObject, LoggerAwareInterface {
|
|||
$this->logger = new NullLogger();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UserIdentity $user
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
private static function toLegacyUser( UserIdentity $user ) {
|
||||
return User::newFromIdentity( $user );
|
||||
}
|
||||
|
||||
public function setLogger( LoggerInterface $logger ) {
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
|
@ -834,14 +825,12 @@ class DerivedPageDataUpdater implements IDBAccessObject, LoggerAwareInterface {
|
|||
// The edit may have already been prepared via api.php?action=stashedit
|
||||
$stashedEdit = false;
|
||||
|
||||
$legacyUser = self::toLegacyUser( $user );
|
||||
|
||||
// TODO: MCR: allow output for all slots to be stashed.
|
||||
if ( $useStash && $slotsUpdate->isModifiedSlot( SlotRecord::MAIN ) ) {
|
||||
$stashedEdit = $this->pageEditStash->checkCache(
|
||||
$title,
|
||||
$slotsUpdate->getModifiedSlot( SlotRecord::MAIN )->getContent(),
|
||||
$legacyUser
|
||||
$user
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -1581,18 +1570,13 @@ class DerivedPageDataUpdater implements IDBAccessObject, LoggerAwareInterface {
|
|||
DeferredUpdates::addUpdate( new SearchUpdate( $id, $title, $mainSlot->getContent() ) );
|
||||
}
|
||||
|
||||
$legacyUser = self::toLegacyUser( $this->user );
|
||||
|
||||
// If this is another user's talk page, update newtalk.
|
||||
// Don't do this if $options['changed'] = false (null-edits) nor if
|
||||
// it's a minor edit and the user making the edit doesn't generate notifications for those.
|
||||
// TODO: the permission check should be performed by the callers, see T276181.
|
||||
if ( $this->options['changed']
|
||||
&& $title->getNamespace() === NS_USER_TALK
|
||||
|
||||
// TODO User::getTitleKey is just a string manipulation of the user name,
|
||||
// duplicate it here and use $this->user (a UserIdentity) instead
|
||||
&& $shortTitle != $legacyUser->getTitleKey()
|
||||
&& $title->getText() != $this->user->getName()
|
||||
&& !( $this->revision->isMinor() && $this->permissionManager
|
||||
->userHasRight( $this->user, 'nominornewtalk' )
|
||||
)
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ use MediaWiki\User\UserIdentity;
|
|||
use ParserOutput;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use stdClass;
|
||||
use User;
|
||||
use Wikimedia\Rdbms\ILoadBalancer;
|
||||
use Wikimedia\ScopedCallback;
|
||||
use WikiPage;
|
||||
|
|
@ -213,10 +212,11 @@ class PageEditStash {
|
|||
*
|
||||
* @param PageIdentity $page
|
||||
* @param Content $content
|
||||
* @param User $user to get parser options from
|
||||
* @param UserIdentity $useridentity to get parser options from
|
||||
* @return stdClass|bool Returns edit stash object or false on cache miss
|
||||
*/
|
||||
public function checkCache( PageIdentity $page, Content $content, User $user ) {
|
||||
public function checkCache( PageIdentity $page, Content $content, UserIdentity $useridentity ) {
|
||||
$user = $this->userFactory->newFromUserIdentity( $useridentity );
|
||||
if (
|
||||
// The context is not an HTTP POST request
|
||||
!$user->getRequest()->wasPosted() ||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Storage\PageEditStash;
|
||||
use MediaWiki\User\UserIdentity;
|
||||
use Psr\Log\NullLogger;
|
||||
use Wikimedia\TestingAccessWrapper;
|
||||
|
||||
|
|
@ -304,11 +305,11 @@ class ApiStashEditTest extends ApiTestCase {
|
|||
* Shortcut for calling PageStashEdit::checkCache() without
|
||||
* having to create Titles and Contents in every test.
|
||||
*
|
||||
* @param User $user
|
||||
* @param UserIdentity $user
|
||||
* @param string $text The text of the article
|
||||
* @return stdClass|bool Return value of PageStashEdit::checkCache(), false if not in cache
|
||||
*/
|
||||
protected function doCheckCache( User $user, $text = 'Content' ) {
|
||||
protected function doCheckCache( UserIdentity $user, $text = 'Content' ) {
|
||||
return MediaWikiServices::getInstance()->getPageEditStash()->checkCache(
|
||||
Title::newFromText( __CLASS__ ),
|
||||
new WikitextContent( $text ),
|
||||
|
|
|
|||
Loading…
Reference in a new issue