jenkins-bot has submitted this change and it was merged.

Change subject: Remove publishHere
......................................................................


Remove publishHere

Use the same code path for both local and remote wikis. Makes
maintenance of this code easier and avoid having to create accounts
via code. Now even the local user account must have been created
manually.

Bug: T110766
Change-Id: If2d1430f905410727e20527c505ca295c8c887d3
(cherry picked from commit 167f80029ea5ea9d9c790a4e2794e6303ebb8fde)
---
M TranslationNotificationJob.php
1 file changed, 11 insertions(+), 56 deletions(-)

Approvals:
  Gergő Tisza: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/TranslationNotificationJob.php b/TranslationNotificationJob.php
index 4033b94..62b69f3 100644
--- a/TranslationNotificationJob.php
+++ b/TranslationNotificationJob.php
@@ -15,11 +15,7 @@
         * @return bool
         */
        public function run() {
-               if ( isset( $this->params['otherwiki'] ) ) {
-                       $status = $this->publishInOtherWiki();
-               } else {
-                       $status = $this->publishHere();
-               }
+               $status = $this->publishInWiki();
 
                if ( $status !== true ) {
                        $this->setLastError( $status );
@@ -45,59 +41,18 @@
                );
        }
 
-       private function publishHere() {
-               $text = '== ' . $this->params['editSummary'] . " ==\n\n" . 
$this->textDiv();
-
-               $talkPage = WikiPage::factory( $this->title );
-               $flags = $talkPage->checkFlags( 0 );
-               if ( $flags & EDIT_UPDATE ) {
-                       $content = $talkPage->getContent( Revision::RAW );
-                       if ( $content instanceof TextContent ) {
-                               $textContent = $content->getNativeData();
-                       } else {
-                               // Cannot do anything with non-TextContent 
pages. Shouldn't happen.
-                               return true;
-                       }
-
-                       $text = $textContent . "\n" . $text;
-               }
-
-               global $wgNotificationUsername, $wgNotificationUserPassword;
-               $user = User::newFromName( $wgNotificationUsername );
-               if ( $user->isAllowed( 'bot' ) ) {
-                       $flags = $flags | EDIT_FORCE_BOT; // If the user has 
the bot right, mark edit as bot
-               }
-
-               // If user doesn't exist
-               if ( !$user->getId() ) {
-                       $user->addToDatabase();
-                       $user->setPassword( $wgNotificationUserPassword );
-                       $user->saveSettings();
-                       // Increment site_stats.ss_users
-                       $ssu = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
-                       $ssu->doUpdate();
-               }
-
-               $status = $talkPage->doEditContent(
-                       ContentHandler::makeContent( $text, $this->title ),
-                       $this->params['editSummary'],
-                       $flags,
-                       false,
-                       $user
-               );
-
-               return $status->isGood();
-       }
-
-       private function publishInOtherWiki() {
+       private function publishInWiki() {
                global $wgNotificationUsername, $wgNotificationUserPassword;
 
-               $wiki = WikiMap::getWiki( $this->params['otherwiki'] );
-               $otherWikiBaseUrl = $wiki->getCanonicalServer() . wfScript( 
'api' );
+               if ( isset( $this->params['otherwiki'] ) ) {
+                       $wiki = WikiMap::getWiki( $this->params['otherwiki'] );
+                       $baseUrl = $wiki->getCanonicalServer() . wfScript( 
'api' );
+               } else {
+                       $baseUrl = wfExpandUrl( wfScript( 'api' ), 
PROTO_CANONICAL );
+               }
 
                // API: Get login token
-
-               $loginUrl = wfAppendQuery( $otherWikiBaseUrl, [
+               $loginUrl = wfAppendQuery( $baseUrl, [
                        'action' => 'login',
                        'format' => 'json',
                ] );
@@ -154,7 +109,7 @@
                // API: Get an edit token
 
                $userTalkPage = $this->title->getFullText();
-               $editTokenUrl = wfAppendQuery( $otherWikiBaseUrl, [
+               $editTokenUrl = wfAppendQuery( $baseUrl, [
                        'action' => 'query',
                        'format' => 'json',
                ] );
@@ -185,7 +140,7 @@
 
                // API: Edit the talk page
 
-               $editUrl = wfAppendQuery( $otherWikiBaseUrl, [
+               $editUrl = wfAppendQuery( $baseUrl, [
                        'action' => 'edit',
                        'format' => 'json',
                ] );

-- 
To view, visit https://gerrit.wikimedia.org/r/296509
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: If2d1430f905410727e20527c505ca295c8c887d3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TranslationNotifications
Gerrit-Branch: REL1_27
Gerrit-Owner: Gergő Tisza <gti...@wikimedia.org>
Gerrit-Reviewer: Gergő Tisza <gti...@wikimedia.org>
Gerrit-Reviewer: Nikerabbit <niklas.laxst...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to