Merge "Replace easy usages of User for UserIdentity/Authority"
This commit is contained in:
commit
3d487a3b89
6 changed files with 62 additions and 57 deletions
|
|
@ -25,9 +25,9 @@
|
|||
namespace MediaWiki\EditPage;
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\User\UserIdentity;
|
||||
use Sanitizer;
|
||||
use Title;
|
||||
use User;
|
||||
|
||||
/**
|
||||
* Helps EditPage build textboxes
|
||||
|
|
@ -97,11 +97,11 @@ class TextboxBuilder {
|
|||
/**
|
||||
* @param string $name
|
||||
* @param mixed[] $customAttribs
|
||||
* @param User $user
|
||||
* @param UserIdentity $user
|
||||
* @param Title $title
|
||||
* @return mixed[]
|
||||
*/
|
||||
public function buildTextboxAttribs( $name, array $customAttribs, User $user, Title $title ) {
|
||||
public function buildTextboxAttribs( $name, array $customAttribs, UserIdentity $user, Title $title ) {
|
||||
$attribs = $customAttribs + [
|
||||
'accesskey' => ',',
|
||||
'id' => $name,
|
||||
|
|
@ -116,7 +116,8 @@ class TextboxBuilder {
|
|||
// * mw-editfont-monospace
|
||||
// * mw-editfont-sans-serif
|
||||
// * mw-editfont-serif
|
||||
$class = 'mw-editfont-' . $user->getOption( 'editfont' );
|
||||
$userOptionsLookup = MediaWikiServices::getInstance()->getUserOptionsLookup();
|
||||
$class = 'mw-editfont-' . $userOptionsLookup->getOption( $user, 'editfont' );
|
||||
|
||||
if ( isset( $attribs['class'] ) ) {
|
||||
if ( is_string( $attribs['class'] ) ) {
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
|
|||
use MediaWiki\Linker\LinkRenderer;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Page\ParserOutputAccess;
|
||||
use MediaWiki\Permissions\Authority;
|
||||
use MediaWiki\Permissions\PermissionStatus;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
use MediaWiki\Revision\RevisionStore;
|
||||
|
|
@ -597,7 +598,7 @@ class Article implements Page {
|
|||
/**
|
||||
* Determines the desired ParserOutput and passes it to $outputPage.
|
||||
*
|
||||
* @param User $user
|
||||
* @param Authority $performer
|
||||
* @param ParserOptions $parserOptions
|
||||
* @param int $oldid
|
||||
* @param OutputPage $outputPage
|
||||
|
|
@ -607,7 +608,7 @@ class Article implements Page {
|
|||
* false to skip further processing.
|
||||
*/
|
||||
private function generateContentOutput(
|
||||
User $user,
|
||||
Authority $performer,
|
||||
ParserOptions $parserOptions,
|
||||
int $oldid,
|
||||
OutputPage $outputPage,
|
||||
|
|
@ -635,7 +636,7 @@ class Article implements Page {
|
|||
if ( !$this->mPage->exists() ) {
|
||||
wfDebug( __METHOD__ . ": showing missing article" );
|
||||
$this->showMissingArticle();
|
||||
$this->mPage->doViewUpdates( $user );
|
||||
$this->mPage->doViewUpdates( $performer );
|
||||
return false; // skip all further output to OutputPage
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1043,7 +1043,7 @@ EOT
|
|||
* @since 1.21
|
||||
* @deprecated Since 1.35 Use static function MediaFileTrait::getImageLimitsFromOption
|
||||
*/
|
||||
public function getImageLimitsFromOption( $user, $optionName ) {
|
||||
public function getImageLimitsFromOption( UserIdentity $user, $optionName ) {
|
||||
return MediaFileTrait::getImageLimitsFromOption( $user, $optionName );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ use MediaWiki\Page\WikiPageFactory;
|
|||
use MediaWiki\Revision\RevisionRecord;
|
||||
use MediaWiki\Revision\RevisionStore;
|
||||
use MediaWiki\User\UserFactory;
|
||||
use MediaWiki\User\UserIdentity;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Wikimedia\Rdbms\IDatabase;
|
||||
use Wikimedia\Rdbms\ILoadBalancer;
|
||||
|
|
@ -444,7 +445,7 @@ class PageArchive {
|
|||
*
|
||||
* @param array $timestamps Pass an empty array to restore all revisions,
|
||||
* otherwise list the ones to undelete.
|
||||
* @param User $user
|
||||
* @param UserIdentity $user
|
||||
* @param string $comment
|
||||
* @param array $fileVersions
|
||||
* @param bool $unsuppress
|
||||
|
|
@ -455,7 +456,7 @@ class PageArchive {
|
|||
*/
|
||||
public function undeleteAsUser(
|
||||
$timestamps,
|
||||
User $user,
|
||||
UserIdentity $user,
|
||||
$comment = '',
|
||||
$fileVersions = [],
|
||||
$unsuppress = false,
|
||||
|
|
@ -512,7 +513,8 @@ class PageArchive {
|
|||
],
|
||||
] );
|
||||
|
||||
$this->hookRunner->onArticleUndeleteLogEntry( $this, $logEntry, $user );
|
||||
$legacyUser = $this->userFactory->newFromUserIdentity( $user );
|
||||
$this->hookRunner->onArticleUndeleteLogEntry( $this, $logEntry, $legacyUser );
|
||||
|
||||
$logid = $logEntry->insert();
|
||||
$logEntry->publish( $logid );
|
||||
|
|
|
|||
|
|
@ -20,7 +20,10 @@
|
|||
|
||||
namespace MediaWiki\Tests\EditPage;
|
||||
|
||||
use Language;
|
||||
use MediaWiki\EditPage\TextboxBuilder;
|
||||
use MediaWiki\User\StaticUserOptionsLookup;
|
||||
use MediaWiki\User\UserIdentityValue;
|
||||
use MediaWikiIntegrationTestCase;
|
||||
use Title;
|
||||
|
||||
|
|
@ -89,4 +92,48 @@ class TextboxBuilderTest extends MediaWikiIntegrationTestCase {
|
|||
$builder = new TextboxBuilder();
|
||||
$this->assertSame( $expected, $builder->getTextboxProtectionCSSClasses( $title ) );
|
||||
}
|
||||
|
||||
public function testBuildTextboxAttribs() {
|
||||
$user = UserIdentityValue::newRegistered( 42, 'Test' );
|
||||
$mockUserOptionsLookup = new StaticUserOptionsLookup( [
|
||||
'Test' => [ 'editfont' => 'monospace' ],
|
||||
] );
|
||||
$this->setService( 'UserOptionsLookup', $mockUserOptionsLookup );
|
||||
|
||||
$enLanguage = $this->createMock( Language::class );
|
||||
$enLanguage->method( 'getHtmlCode' )->willReturn( 'en' );
|
||||
$enLanguage->method( 'getDir' )->willReturn( 'ltr' );
|
||||
|
||||
$title = $this->createMock( Title::class );
|
||||
$title->method( 'getPageLanguage' )->willReturn( $enLanguage );
|
||||
|
||||
$builder = new TextboxBuilder();
|
||||
$attribs = $builder->buildTextboxAttribs(
|
||||
'mw-textbox1',
|
||||
[ 'class' => 'foo bar', 'data-foo' => '123', 'rows' => 30 ],
|
||||
$user,
|
||||
$title
|
||||
);
|
||||
|
||||
$this->assertIsArray( $attribs );
|
||||
// custom attrib showed up
|
||||
$this->assertArrayHasKey( 'data-foo', $attribs );
|
||||
// classes merged properly (string)
|
||||
$this->assertSame( 'foo bar mw-editfont-monospace', $attribs['class'] );
|
||||
// overrides in custom attrib worked
|
||||
$this->assertSame( 30, $attribs['rows'] );
|
||||
$this->assertSame( 'en', $attribs['lang'] );
|
||||
|
||||
$attribs2 = $builder->buildTextboxAttribs(
|
||||
'mw-textbox2', [ 'class' => [ 'foo', 'bar' ] ], $user, $title
|
||||
);
|
||||
// classes merged properly (array)
|
||||
$this->assertSame( [ 'foo', 'bar', 'mw-editfont-monospace' ], $attribs2['class'] );
|
||||
|
||||
$attribs3 = $builder->buildTextboxAttribs(
|
||||
'mw-textbox3', [], $user, $title
|
||||
);
|
||||
// classes ok when nothing to be merged
|
||||
$this->assertSame( 'mw-editfont-monospace', $attribs3['class'] );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,11 +20,8 @@
|
|||
|
||||
namespace MediaWiki\Tests\Unit\EditPage;
|
||||
|
||||
use Language;
|
||||
use MediaWiki\EditPage\TextboxBuilder;
|
||||
use MediaWikiUnitTestCase;
|
||||
use Title;
|
||||
use User;
|
||||
|
||||
/**
|
||||
* Split from \MediaWiki\Tests\EditPage\TextboxBuilderTest integration tests
|
||||
|
|
@ -48,49 +45,6 @@ class TextboxBuilderTest extends MediaWikiUnitTestCase {
|
|||
$this->assertSame( $expected, $builder->addNewLineAtEnd( $input ) );
|
||||
}
|
||||
|
||||
public function testBuildTextboxAttribs() {
|
||||
$user = $this->createMock( User::class );
|
||||
$user->method( 'getOption' )
|
||||
->with( 'editfont' )
|
||||
->willReturn( 'monospace' );
|
||||
|
||||
$enLanguage = $this->createMock( Language::class );
|
||||
$enLanguage->method( 'getHtmlCode' )->willReturn( 'en' );
|
||||
$enLanguage->method( 'getDir' )->willReturn( 'ltr' );
|
||||
|
||||
$title = $this->createMock( Title::class );
|
||||
$title->method( 'getPageLanguage' )->willReturn( $enLanguage );
|
||||
|
||||
$builder = new TextboxBuilder();
|
||||
$attribs = $builder->buildTextboxAttribs(
|
||||
'mw-textbox1',
|
||||
[ 'class' => 'foo bar', 'data-foo' => '123', 'rows' => 30 ],
|
||||
$user,
|
||||
$title
|
||||
);
|
||||
|
||||
$this->assertIsArray( $attribs );
|
||||
// custom attrib showed up
|
||||
$this->assertArrayHasKey( 'data-foo', $attribs );
|
||||
// classes merged properly (string)
|
||||
$this->assertSame( 'foo bar mw-editfont-monospace', $attribs['class'] );
|
||||
// overrides in custom attrib worked
|
||||
$this->assertSame( 30, $attribs['rows'] );
|
||||
$this->assertSame( 'en', $attribs['lang'] );
|
||||
|
||||
$attribs2 = $builder->buildTextboxAttribs(
|
||||
'mw-textbox2', [ 'class' => [ 'foo', 'bar' ] ], $user, $title
|
||||
);
|
||||
// classes merged properly (array)
|
||||
$this->assertSame( [ 'foo', 'bar', 'mw-editfont-monospace' ], $attribs2['class'] );
|
||||
|
||||
$attribs3 = $builder->buildTextboxAttribs(
|
||||
'mw-textbox3', [], $user, $title
|
||||
);
|
||||
// classes ok when nothing to be merged
|
||||
$this->assertSame( 'mw-editfont-monospace', $attribs3['class'] );
|
||||
}
|
||||
|
||||
public function provideMergeClassesIntoAttributes() {
|
||||
return [
|
||||
[
|
||||
|
|
|
|||
Loading…
Reference in a new issue