jenkins-bot has submitted this change and it was merged.
Change subject: Create a user page when granting translator rights
......................................................................
Create a user page when granting translator rights
Added integration test
Bug: 58710
Change-Id: I133526d250fa93f19a632244c5a4955362133790
---
M api/ApiTranslateSandbox.php
M i18n/sandbox/en.json
M i18n/sandbox/qqq.json
M tests/browser/features/manage_translator_sandbox.feature
M tests/browser/features/step_definitions/manage_translator_sandbox_steps.rb
A tests/browser/features/support/pages/user_page.rb
M utils/TranslateSandbox.php
7 files changed, 73 insertions(+), 3 deletions(-)
Approvals:
Amire80: Looks good to me, approved
jenkins-bot: Verified
diff --git a/api/ApiTranslateSandbox.php b/api/ApiTranslateSandbox.php
index 2237015..ba30d1b 100644
--- a/api/ApiTranslateSandbox.php
+++ b/api/ApiTranslateSandbox.php
@@ -12,7 +12,6 @@
* @ingroup API TranslateAPI
*/
class ApiTranslateSandbox extends ApiBase {
-
public function execute() {
global $wgTranslateUseSandbox;
if ( !$wgTranslateUseSandbox ) {
@@ -133,6 +132,7 @@
$logEntry->publish( $logid );
$user->addNewUserLogEntry( 'create', $this->msg(
'tsb-promoted-from-sandbox' )->text() );
+ $this->createUserPage( $user );
}
}
@@ -150,6 +150,34 @@
}
}
+ /**
+ * Create a user page for a user with a babel template based on the
signup
+ * preferences.
+ *
+ * @param User $user
+ * @return Status|bool False when a user page already existed, or the
Status
+ * of the user page creation from WikiPage::doEditContent().
+ */
+ protected function createUserPage( User $user ) {
+ $userpage = $user->getUserPage();
+
+ if( $userpage->exists() ) {
+ return false;
+ }
+
+ $languagePrefs = FormatJson::decode( $user->getOption(
'translate-sandbox' ) );
+ $languages = implode( '|', $languagePrefs->languages );
+ $babeltext = "{{#babel:$languages}}";
+ $summary = $this->msg( 'tsb-create-user-page'
)->inContentLanguage()->text();
+
+ $page = WikiPage::factory( $userpage );
+ $content = ContentHandler::makeContent( $babeltext, $userpage );
+
+ $editResult = $page->doEditContent( $content, $summary,
EDIT_NEW, false, $user );
+
+ return $editResult;
+ }
+
public function mustBePosted() {
return true;
}
diff --git a/i18n/sandbox/en.json b/i18n/sandbox/en.json
index cd8a055..cafe244 100644
--- a/i18n/sandbox/en.json
+++ b/i18n/sandbox/en.json
@@ -34,6 +34,7 @@
"tsb-translations-source": "Source",
"tsb-translations-user": "User translations",
"tsb-translations-current": "Existing translations",
+ "tsb-delete-userpage-summary": "Deleting the user page of a sandbox user",
"translationstash": "Welcome",
"translate-translationstash-welcome": "Welcome {{GENDER:$1|$1}}, you are a
new translator",
"translate-translationstash-welcome-note": "Become familiar with the
translation tools. Translate some messages and get full-translator rights to
participate in your favorite projects.",
@@ -44,8 +45,9 @@
"tsb-limit-reached-body": "You reached the translation limit for new
translators.\nOur team will verify and upgrade your account soon.\nThen you
will be able to translate without limits.",
"tsb-no-requests-from-new-users": "No requests from new users",
"tsb-promoted-from-sandbox": "User has been promoted to translator",
+ "tsb-create-user-page": "Create basic user page",
"log-name-translatorsandbox": "Translation sandbox",
"log-description-translatorsandbox": "A log of actions on translation
sandbox users",
"logentry-translatorsandbox-promoted": "$1 {{GENDER:$2|promoted}} $3 to
{{GENDER:$4|translator}}",
"logentry-translatorsandbox-rejected": "$1 {{GENDER:$2|rejected}} the
request from \"$3\" to become a translator"
-}
\ No newline at end of file
+}
diff --git a/i18n/sandbox/qqq.json b/i18n/sandbox/qqq.json
index e680e9d..b5096b8 100644
--- a/i18n/sandbox/qqq.json
+++ b/i18n/sandbox/qqq.json
@@ -35,6 +35,7 @@
"tsb-translations-source": "Table header label for source messages of user
translations in [[Special:TranslateSandbox]].\n{{Identical|Source}}",
"tsb-translations-user": "Table header label for user translations in
[[Special:TranslateSandbox]].",
"tsb-translations-current": "Table header label for existing translations
in [[Special:TranslateSandbox]].",
+ "tsb-delete-userpage-summary": "Edit summary for deleting the user page of
a sandboxed user.",
"translationstash": "Page title for
[[Special:TranslationStash]].\n{{Identical|Welcome}}",
"translate-translationstash-welcome": "Title text shown for the
[[Special:TranslationStash]]. Parameters:\n* $1 - user name of the new
translator",
"translate-translationstash-welcome-note": "Title note for the
[[Special:TranslationStash]].",
@@ -45,8 +46,9 @@
"tsb-limit-reached-body": "Text shown below translations when the user has
reached the limit for number of translations.",
"tsb-no-requests-from-new-users": "Shown on [[Special:TranslateSandbox]]
when there are no requests for approval from new users.",
"tsb-promoted-from-sandbox": "{{logentry}}\nAdditional parameters:\n* $4 -
(Unused) user ID",
+ "tsb-create-user-page": "Edit summary for user page creation once approved
as translator. Will be in content language.",
"log-name-translatorsandbox": "{{doc-logpage}}",
"log-description-translatorsandbox": "Log page description",
"logentry-translatorsandbox-promoted": "{{logentry}}\n* $4 - The name of
the user that was promoted, can be used for GENDER.",
"logentry-translatorsandbox-rejected": "{{logentry}}"
-}
\ No newline at end of file
+}
diff --git a/tests/browser/features/manage_translator_sandbox.feature
b/tests/browser/features/manage_translator_sandbox.feature
index 50e6d1a..ce8e053 100644
--- a/tests/browser/features/manage_translator_sandbox.feature
+++ b/tests/browser/features/manage_translator_sandbox.feature
@@ -277,3 +277,10 @@
And I should see the checkbox next to the request from "Pupu3" disabled
And I should see "1 user selected" at the bottom of the first column
And I should see "4 requests" at the top of the first column
+
+ Scenario: Accepting a user creates a user page
+ Given I am on the Translator sandbox management page with users in the
sandbox
+ When I click on "Kissa" in the first column
+ And I click the "Accept" button
+ And I go to the userpage of user "Kissa"
+ Then I should see a babel box with languages "bn, he, uk, nl, fi"
diff --git
a/tests/browser/features/step_definitions/manage_translator_sandbox_steps.rb
b/tests/browser/features/step_definitions/manage_translator_sandbox_steps.rb
index 4273055..6fb2999 100644
--- a/tests/browser/features/step_definitions/manage_translator_sandbox_steps.rb
+++ b/tests/browser/features/step_definitions/manage_translator_sandbox_steps.rb
@@ -52,6 +52,14 @@
on(ManageTranslatorSandboxPage).older_requests_indicator_element.click
end
+When(/^I go to the userpage of user "(.*?)"$/) do |username|
+ visit(UserPage, :using_params => {:extra => username})
+end
+
+Then(/^I should see a babel box with languages "(.*?)"$/) do |languages|
+ on(UserPage).babel_box_has_languages?(languages).should be_true
+end
+
Then(/^I should not see the older requests link at the bottom of the first
column$/) do
on(ManageTranslatorSandboxPage).older_requests_indicator_element.should_not
be_visible
end
diff --git a/tests/browser/features/support/pages/user_page.rb
b/tests/browser/features/support/pages/user_page.rb
new file mode 100644
index 0000000..b6a7a03
--- /dev/null
+++ b/tests/browser/features/support/pages/user_page.rb
@@ -0,0 +1,13 @@
+class UserPage
+ include PageObject
+
+ include URL
+ page_url URL.url("User:<%=params[:extra]%>")
+
+ def babel_box_has_languages?(languages)
+ languages.split(/, /).all? do |language|
+ @browser.element(css: ".mw-babel-box
td[lang=#{language}]").visible?
+ end
+ end
+
+end
diff --git a/utils/TranslateSandbox.php b/utils/TranslateSandbox.php
index 2edff2c..5d7f098 100644
--- a/utils/TranslateSandbox.php
+++ b/utils/TranslateSandbox.php
@@ -54,6 +54,16 @@
throw new MWException( "Not a sandboxed user" );
}
+ // Delete the user page.
+ // This is needed especially when deleting sandbox users
+ // that were created as part of the integration tests.
+ $userpage = WikiPage::factory( $user->getUserPage() );
+ if ( $userpage->exists() ) {
+ $userpage->doDeleteArticleReal(
+ wfMessage( 'tsb-delete-userpage-summary'
)->inContentLanguage()->text()
+ );
+ }
+
// Delete from database
$dbw = wfGetDB( DB_MASTER );
$dbw->delete( 'user', array( 'user_id' => $uid ), __METHOD__ );
--
To view, visit https://gerrit.wikimedia.org/r/103511
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I133526d250fa93f19a632244c5a4955362133790
Gerrit-PatchSet: 12
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Siebrand <[email protected]>
Gerrit-Reviewer: Amire80 <[email protected]>
Gerrit-Reviewer: KartikMistry <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits