[MediaWiki-commits] [Gerrit] mediawiki...HAWelcome[master]: Rework and improve HAWelcome

2017-10-25 Thread Jack Phoenix (Code Review)
Jack Phoenix has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/385805 )

Change subject: Rework and improve HAWelcome
..


Rework and improve HAWelcome

As noted by Jack Phoenix in ca43438211d194749715fc541334ed9c030f098c,
there are still some outstanding TODO's. This patch attempts to
address those.
* The hardcoded welcomer name has been changed to use a configuration
variable, $wgHAWelcomeUserName, with the previously hardcoded value
as default.
* The global_user_groups table will only be queried if the
GlobalUserrights extension is installed, and the dependency on that
extension has been dropped.
* Expiring user rights are now taken in account for both local and
global user rights, which means only users with a valid group
membership will be used as welcomer.
* Two patches to HAWelcome from the Wikia codebase have been
incorporated:
** If the last active sysop has their groups changed, they will be
removed from cache. This has been adjusted to only remove the user
from cache when the sysop group is removed.
** Instead of checking against a list of hardcoded groups whose
members should never be welcomed, a user right welcomeexempt has
been introduced. Granted to the groups bureaucrat, sysop, staff
and bot, users with this right will not have their user page created
nor will a message be left on their talk page.

Other improvements include the removal of deprecated globals such as
$wgUser, $wgTitle and $wgRequest, i18n of the extension name and
description adding message documentation, adding a LICENSE file and
dedicated selection of staff users when the fallback has been activated.

Bug: T178605
Change-Id: Iea20bad42abf2e1f966b835c6965aa1fd67fa92d
---
M HAWelcome.class.php
A HAWelcome.hooks.php
A LICENSE
A README
M extension.json
M i18n/en.json
A i18n/qqq.json
7 files changed, 732 insertions(+), 272 deletions(-)

Approvals:
  Jack Phoenix: Verified; Looks good to me, approved



diff --git a/HAWelcome.class.php b/HAWelcome.class.php
index fbf7478..7b6d428 100644
--- a/HAWelcome.class.php
+++ b/HAWelcome.class.php
@@ -21,17 +21,14 @@
$mAnon,
$mSysop;
 
-   const WELCOMEUSER = 'ShoutWiki';
-
/**
 * Construct a job
 *
 * @param Title $title The title linked to
 * @param array $params Job parameters (table, start and end page_ids)
-* @param int $id job_id, 0 by default
 */
-   public function __construct( $title, $params, $id = 0 ) {
-   parent::__construct( 'HAWelcome', $title, $params, $id );
+   public function __construct( $title, $params ) {
+   parent::__construct( 'HAWelcome', $title, $params );
 
$this->mUserId   = $params['user_id'];
$this->mUserIP   = $params['user_ip'];
@@ -45,9 +42,7 @@
$this->mUser = User::newFromId( $this->mUserId );
}
 
-   /**
-* fallback
-*/
+   // Fallback
if ( !$this->mUser ) {
$this->mUser = User::newFromName( $this->mUserName );
}
@@ -57,91 +52,88 @@
 * Main entry point
 */
public function run() {
-   global $wgUser, $wgTitle, $wgLanguageCode;
+   global $wgLanguageCode, $wgHAWelcomeWelcomeUsername;
 
-   /**
-* overwrite $wgUser for  expanding
-*/
$sysop = trim( wfMessage( 'welcome-user' )->plain() );
-   if ( !in_array( $sysop, [ '@disabled', '-' ] ) ) {
-   $tmpUser = $wgUser;
-   $wgUser = User::newFromName( self::WELCOMEUSER );
-   $flags = 0;
-   if ( $wgUser && $wgUser->isBot() ) {
-   $flags = EDIT_FORCE_BOT;
-   }
+   if ( in_array( $sysop, [ '@disabled', '-' ] ) ) {
+   return true;
+   }
 
-   if ( $this->mUser && $this->mUser->getName() !== 
self::WELCOMEUSER && !$wgUser->isBlocked() ) {
-   /**
-* check again if talk page exists
-*/
-   $talkPage = 
$this->mUser->getUserPage()->getTalkPage();
+   $welcomeUser = User::newFromName( $wgHAWelcomeWelcomeUsername );
+   $flags = 0;
+   if ( $welcomeUser && $welcomeUser->isBot() ) {
+   $flags = EDIT_FORCE_BOT;
+   }
 
-   if ( $talkPage ) {
-   $this->mSysop = $this->getLastSysop();
-   $tmpTitle = $wgTitle;
-   $sysopPage= 
$this->mSysop->getUserPage()->getTalkPage();
-   

[MediaWiki-commits] [Gerrit] mediawiki...HAWelcome[master]: Rework and improve HAWelcome

2017-10-21 Thread Mainframe98 (Code Review)
Mainframe98 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/385805 )

Change subject: Rework and improve HAWelcome
..

Rework and improve HAWelcome

As noted by Jack Phoenix in ca43438211d194749715fc541334ed9c030f098c,
there are still some outstanding TODO's. This patch attempts to
address those.
* The hardcoded welcomer name has been changed to use a configuration
variable, $wgHAWelcomeUserName, with the previously hardcoded value
as default.
* The global_user_groups table will only be queried if the
GlobalUserrights extension is installed, and the dependency on that
extension has been dropped.
* Expiring user rights are now taken in account for both local and
global user rights, which means only users with a valid group
membership will be used as welcomer.
* Two patches to HAWelcome from the Wikia codebase have been
incorporated:
** If the last active sysop has their groups changed, they will be
removed from cache. This has been adjusted to only remove the user
from cache when the sysop group is removed.
** Instead of checking against a list of hardcoded groups whose
members should never be welcomed, a user right welcomeexempt has
been introduced. Granted to the groups bureaucrat, sysop, staff
and bot, users with this right will not have their user page created
nor will a message be left on their talk page.

Other improvements include the removal of deprecated globals such as
$wgUser, $wgTitle and $wgRequest, i18n of the extension name and
description adding message documentation, adding a LICENSE file and
dedicated selection of staff users when the fallback has been activated.

Bug: T178605
Change-Id: Iea20bad42abf2e1f966b835c6965aa1fd67fa92d
---
M HAWelcome.class.php
A HAWelcome.hooks.php
A LICENSE
A README
M extension.json
M i18n/en.json
A i18n/qqq.json
7 files changed, 712 insertions(+), 272 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/HAWelcome 
refs/changes/05/385805/1

diff --git a/HAWelcome.class.php b/HAWelcome.class.php
index fbf7478..ef3d344 100644
--- a/HAWelcome.class.php
+++ b/HAWelcome.class.php
@@ -21,17 +21,14 @@
$mAnon,
$mSysop;
 
-   const WELCOMEUSER = 'ShoutWiki';
-
/**
 * Construct a job
 *
 * @param Title $title The title linked to
 * @param array $params Job parameters (table, start and end page_ids)
-* @param int $id job_id, 0 by default
 */
-   public function __construct( $title, $params, $id = 0 ) {
-   parent::__construct( 'HAWelcome', $title, $params, $id );
+   public function __construct( $title, $params ) {
+   parent::__construct( 'HAWelcome', $title, $params );
 
$this->mUserId   = $params['user_id'];
$this->mUserIP   = $params['user_ip'];
@@ -45,9 +42,7 @@
$this->mUser = User::newFromId( $this->mUserId );
}
 
-   /**
-* fallback
-*/
+   // Fallback
if ( !$this->mUser ) {
$this->mUser = User::newFromName( $this->mUserName );
}
@@ -57,91 +52,88 @@
 * Main entry point
 */
public function run() {
-   global $wgUser, $wgTitle, $wgLanguageCode;
+   global $wgLanguageCode, $wgHAWelcomeWelcomeUsername;
 
-   /**
-* overwrite $wgUser for  expanding
-*/
$sysop = trim( wfMessage( 'welcome-user' )->plain() );
-   if ( !in_array( $sysop, [ '@disabled', '-' ] ) ) {
-   $tmpUser = $wgUser;
-   $wgUser = User::newFromName( self::WELCOMEUSER );
-   $flags = 0;
-   if ( $wgUser && $wgUser->isBot() ) {
-   $flags = EDIT_FORCE_BOT;
-   }
+   if ( in_array( $sysop, [ '@disabled', '-' ] ) ) {
+   return true;
+   }
 
-   if ( $this->mUser && $this->mUser->getName() !== 
self::WELCOMEUSER && !$wgUser->isBlocked() ) {
-   /**
-* check again if talk page exists
-*/
-   $talkPage = 
$this->mUser->getUserPage()->getTalkPage();
+   $welcomeUser = User::newFromName( $wgHAWelcomeWelcomeUsername );
+   $flags = 0;
+   if ( $welcomeUser && $welcomeUser->isBot() ) {
+   $flags = EDIT_FORCE_BOT;
+   }
 
-   if ( $talkPage ) {
-   $this->mSysop = $this->getLastSysop();
-   $tmpTitle = $wgTitle;
-   $sysopPage=