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

Change subject: Version 1.4.0
......................................................................


Version 1.4.0

* extension.json added
* old, deprecated PHP i18n file removed
* changed "errorbox" to "successbox" in SpecialPrivateDomains.php because the 
message shown is more of a success than an error message
* moved hooks to their own file & wrapped 'em in a class
* set the correct page title(s) in PrivateDomainsHooks::onAlternateEdit()

Change-Id: Iae01f1662fb67e1cb2d1f1c33db11eac50e12fec
---
D PrivateDomains.i18n.php
M PrivateDomains.php
A PrivateDomainsHooks.php
M SpecialPrivateDomains.php
A extension.json
5 files changed, 167 insertions(+), 105 deletions(-)

Approvals:
  Jack Phoenix: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/PrivateDomains.i18n.php b/PrivateDomains.i18n.php
deleted file mode 100644
index fcab85b..0000000
--- a/PrivateDomains.i18n.php
+++ /dev/null
@@ -1,35 +0,0 @@
-<?php
-/**
- * This is a backwards-compatibility shim, generated by:
- * 
https://git.wikimedia.org/blob/mediawiki%2Fcore.git/HEAD/maintenance%2FgenerateJsonI18n.php
- *
- * Beginning with MediaWiki 1.23, translation strings are stored in json files,
- * and the EXTENSION.i18n.php file only exists to provide compatibility with
- * older releases of MediaWiki. For more information about this migration, see:
- * https://www.mediawiki.org/wiki/Requests_for_comment/Localisation_format
- *
- * This shim maintains compatibility back to MediaWiki 1.17.
- */
-$messages = array();
-if ( !function_exists( 'wfJsonI18nShimb40a1f8a7d128c2e' ) ) {
-       function wfJsonI18nShimb40a1f8a7d128c2e( $cache, $code, &$cachedData ) {
-               $codeSequence = array_merge( array( $code ), 
$cachedData['fallbackSequence'] );
-               foreach ( $codeSequence as $csCode ) {
-                       $fileName = dirname( __FILE__ ) . "/i18n/$csCode.json";
-                       if ( is_readable( $fileName ) ) {
-                               $data = FormatJson::decode( file_get_contents( 
$fileName ), true );
-                               foreach ( array_keys( $data ) as $key ) {
-                                       if ( $key === '' || $key[0] === '@' ) {
-                                               unset( $data[$key] );
-                                       }
-                               }
-                               $cachedData['messages'] = array_merge( $data, 
$cachedData['messages'] );
-                       }
-
-                       $cachedData['deps'][] = new FileDependency( $fileName );
-               }
-               return true;
-       }
-
-       $GLOBALS['wgHooks']['LocalisationCacheRecache'][] = 
'wfJsonI18nShimb40a1f8a7d128c2e';
-}
diff --git a/PrivateDomains.php b/PrivateDomains.php
index 4ae5135..3607538 100644
--- a/PrivateDomains.php
+++ b/PrivateDomains.php
@@ -7,18 +7,14 @@
  * @ingroup Extensions
  * @author Inez Korczyński <korczyn...@gmail.com>
  * @author Jack Phoenix <j...@countervandalism.net>
- * @link http://www.mediawiki.org/wiki/Extension:PrivateDomains Documentation
+ * @link https://www.mediawiki.org/wiki/Extension:PrivateDomains Documentation
  * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 
2.0 or later
  */
-
-if ( !defined( 'MEDIAWIKI' ) ) {
-       die( "This is not a valid entry point.\n" );
-}
 
 // Extension credits that will show up on Special:Version
 $wgExtensionCredits['specialpage'][] = array(
        'name' => 'PrivateDomains',
-       'version' => '1.3.0',
+       'version' => '1.4.0',
        'author' => array( 'Inez Korczyński', 'Jack Phoenix' ),
        'description' => 'Allows to restrict editing to users with a certain 
e-mail address',
        'url' => 'https://www.mediawiki.org/wiki/Extension:PrivateDomains',
@@ -26,15 +22,14 @@
 );
 
 // Set up the new special page
-$dir = dirname( __FILE__ ) . '/';
-$wgAutoloadClasses['PrivateDomains'] = $dir . 'SpecialPrivateDomains.php';
+$wgAutoloadClasses['PrivateDomains'] = __DIR__ . '/SpecialPrivateDomains.php';
 $wgMessagesDirs['PrivateDomains'] = __DIR__ . '/i18n';
-$wgExtensionMessagesFiles['PrivateDomains'] = $dir . 'PrivateDomains.i18n.php';
 $wgSpecialPages['PrivateDomains'] = 'PrivateDomains';
 
-$wgHooks['AlternateEdit'][] = 'pd_AlternateEdit'; // Occurs whenever 
action=edit is called
-$wgHooks['UserLoginComplete'][] = 'pd_UserLoginComplete'; // Occurs after a 
user has successfully logged in
-$wgHooks['ConfirmEmailComplete'][] = 'pd_UserLoginComplete'; // Occurs after a 
user has successfully confirm email
+$wgAutoloadClasses['PrivateDomainsHooks'] = __DIR__ . 
'/PrivateDomainsHooks.php';
+$wgHooks['AlternateEdit'][] = 'PrivateDomainsHooks::onAlternateEdit';
+$wgHooks['UserLoginComplete'][] = 'PrivateDomainsHooks::onUserLoginComplete';
+$wgHooks['ConfirmEmailComplete'][] = 
'PrivateDomainsHooks::onUserLoginComplete';
 
 # set 'privatedomains' right to users in staff or bureaucrat group
 $wgAvailableRights[] = 'privatedomains';
@@ -70,52 +65,4 @@
 
 $wgGroupPermissions['user']['minoredit'] = false;
 $wgGroupPermissions['*']['minoredit'] = false;
-$wgGroupPermissions['privatedomains']['minoredit'] = true;
-
-/**
- * If user isn't in group privatedomains/staff/bureaucrat then
- * deny access to edit page and show information box.
- */
-function pd_AlternateEdit( $editpage ) {
-       global $wgUser;
-       $groups = $wgUser->getEffectiveGroups();
-       if (
-               $wgUser->isLoggedIn() && !in_array( 'privatedomains', $groups ) 
&&
-               !in_array( 'staff', $groups ) && !in_array( 'bureaucrat', 
$groups )
-       )
-       {
-               global $wgOut;
-               $affiliateName = PrivateDomains::getParam( 
'privatedomains-affiliatename' );
-               $wgOut->addHTML( '<div class="errorbox" 
style="width:92%;"><strong>' );
-               $wgOut->addWikiMsg( 'privatedomains-invalidemail', 
$affiliateName );
-               $wgOut->addHTML( '</strong></div><br /><br /><br />' );
-               return false;
-       }
-       return true;
-}
-
-/**
- * If user has confirmed and allowed address email
- * then add him/her to privatedomains user group.
- */
-function pd_UserLoginComplete( $user ) {
-       if( $user->isEmailConfirmed() ) {
-               $domainsStr = PrivateDomains::getParam( 
'privatedomains-domains' );
-               if( $domainsStr != '' ) {
-                       $email = strtolower( $user->mEmail );
-                       // get suffix domain name
-                       preg_match( "/([^@]+)@(.+)$/i", $email, $matches );
-                       $emailDomain = $matches[2];
-                       $domainsArr = explode( "\n", $domainsStr );
-                       foreach ( $domainsArr as $allowedDomain ) {
-                               $allowedDomain = strtolower( $allowedDomain );
-                               if ( preg_match( "/.*?$allowedDomain$/", 
$emailDomain ) ) {
-                                       $user->addGroup( 'privatedomains' );
-                                       return true;
-                               }
-                       }
-               }
-       }
-       $user->removeGroup( 'privatedomains' );
-       return true;
-}
+$wgGroupPermissions['privatedomains']['minoredit'] = true;
\ No newline at end of file
diff --git a/PrivateDomainsHooks.php b/PrivateDomainsHooks.php
new file mode 100644
index 0000000..7978536
--- /dev/null
+++ b/PrivateDomainsHooks.php
@@ -0,0 +1,68 @@
+<?php
+/**
+ * Hooked functions used by the PrivateDomains extension.
+ *
+ * @file
+ */
+class PrivateDomainsHooks {
+
+       /**
+        * If user isn't a member of any of the allowed user groups, then deny
+        * access to edit page and show information box.
+        *
+        * @param EditPage $editpage
+        * @return bool
+        */
+       public static function onAlternateEdit( $editpage ) {
+               global $wgUser;
+               $groups = $wgUser->getEffectiveGroups();
+               if (
+                       $wgUser->isLoggedIn() && !in_array( 'privatedomains', 
$groups ) &&
+                       !in_array( 'staff', $groups ) && !in_array( 
'bureaucrat', $groups )
+               )
+               {
+                       global $wgOut;
+                       $wgOut->setPageTitle( wfMessage( 'badaccess' )->text() 
);
+                       $wgOut->setHTMLTitle( wfMessage( 'errorpagetitle' 
)->text() );
+                       $affiliateName = PrivateDomains::getParam( 
'privatedomains-affiliatename' );
+                       $wgOut->addHTML( '<div class="errorbox" 
style="width:92%;"><strong>' );
+                       $wgOut->addWikiMsg( 'privatedomains-invalidemail', 
$affiliateName );
+                       $wgOut->addHTML( '</strong></div><br /><br /><br />' );
+                       return false;
+               }
+               return true;
+       }
+
+       /**
+        * If user has confirmed and allowed email address then add them to the
+        * privatedomains user group.
+        *
+        * This is called both after a user has successfully logged into the 
wiki
+        * and also after the user has successfully confirmed their e-mail 
address.
+        *
+        * @param User $user
+        * @return bool
+        */
+       public static function onUserLoginComplete( $user ) {
+               if ( $user->isEmailConfirmed() ) {
+                       $domainsStr = PrivateDomains::getParam( 
'privatedomains-domains' );
+                       if ( $domainsStr != '' ) {
+                               $email = strtolower( $user->mEmail );
+                               // get suffix domain name
+                               preg_match( "/([^@]+)@(.+)$/i", $email, 
$matches );
+                               $emailDomain = $matches[2];
+                               $domainsArr = explode( "\n", $domainsStr );
+                               foreach ( $domainsArr as $allowedDomain ) {
+                                       $allowedDomain = strtolower( 
$allowedDomain );
+                                       if ( preg_match( 
"/.*?$allowedDomain$/", $emailDomain ) ) {
+                                               $user->addGroup( 
'privatedomains' );
+                                               return true;
+                                       }
+                               }
+                       }
+               }
+               $user->removeGroup( 'privatedomains' );
+               return true;
+       }
+
+}
\ No newline at end of file
diff --git a/SpecialPrivateDomains.php b/SpecialPrivateDomains.php
index 1a9b703..265e5c2 100644
--- a/SpecialPrivateDomains.php
+++ b/SpecialPrivateDomains.php
@@ -1,14 +1,19 @@
 <?php
 /**
- * Body file for PrivateDomains extension
- * Defines the new special page, Special:PrivateDomains
+ * PrivateDomains extension - allows to restrict editing to users with a
+ * certain e-mail address
  *
  * @file
  * @ingroup Extensions
+ * @author Inez Korczyński <korczyn...@gmail.com>
+ * @author Jack Phoenix <j...@countervandalism.net>
+ * @link https://www.mediawiki.org/wiki/Extension:PrivateDomains Documentation
+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 
2.0 or later
  */
 
 /**
  * Main extension class
+ * Defines the new special page, Special:PrivateDomains
  */
 class PrivateDomains extends SpecialPage {
 
@@ -22,8 +27,8 @@
        /**
         * Saves a message in the MediaWiki: namespace.
         *
-        * @param $name String: name of the MediaWiki message
-        * @param $value Mixed: value of the message
+        * @param string $name Name of the MediaWiki message
+        * @param mixed $value Value of the message
         */
        function saveParam( $name, $value ) {
                $nameTitle = Title::newFromText( $name, NS_MEDIAWIKI );
@@ -35,8 +40,8 @@
        /**
         * Fetches the content of a defined MediaWiki message.
         *
-        * @param $name String: name of the MediaWiki message
-        * @return string or nothing
+        * @param string $name Name of the MediaWiki message
+        * @return string Page content if the supplied page exists or an empty 
string
         */
        static function getParam( $name ) {
                $nameTitle = Title::newFromText( $name, NS_MEDIAWIKI );
@@ -51,7 +56,7 @@
        /**
         * Show the special page
         *
-        * @param $par Mixed: parameter passed to the page or null
+        * @param mixed|null $par Parameter passed to the page
         */
        public function execute( $par ) {
                $request = $this->getRequest();
@@ -101,10 +106,10 @@
                        return;
                }
 
-               // If there was an error message, display it.
+               // If there was a message, display it.
                if ( $msg != '' ) {
                        $out->addHTML(
-                               '<div class="errorbox" style="width:92%;"><h2>' 
. $msg .
+                               '<div class="successbox" 
style="width:92%;"><h2>' . $msg .
                                '</h2></div><br /><br /><br />'
                        );
                }
diff --git a/extension.json b/extension.json
new file mode 100644
index 0000000..d84cafc
--- /dev/null
+++ b/extension.json
@@ -0,0 +1,77 @@
+{
+       "name": "PrivateDomains",
+       "version": "1.4.0",
+       "author": [
+               "Inez Korczyński",
+               "Jack Phoenix"
+       ],
+       "license-name": "GPL-2.0+",
+       "url": "https://www.mediawiki.org/wiki/Extension:PrivateDomains";,
+       "description": "Allows to restrict editing to users with a certain 
e-mail address",
+       "type": "specialpage",
+       "SpecialPages": {
+               "PrivateDomains": "PrivateDomains"
+       },
+       "MessagesDirs": {
+               "PrivateDomains": [
+                       "i18n"
+               ]
+       },
+       "AutoloadClasses": {
+               "PrivateDomains": "SpecialPrivateDomains.php",
+               "PrivateDomainsHooks": "PrivateDomainsHooks.php"
+       },
+       "Hooks": {
+               "AlternateEdit": [
+                       "PrivateDomainsHooks::onAlternateEdit"
+               ],
+               "UserLoginComplete": [
+                       "PrivateDomainsHooks::onUserLoginComplete"
+               ],
+               "ConfirmEmailComplete": [
+                       "PrivateDomainsHooks::onUserLoginComplete"
+               ]
+       },
+       "AvailableRights": [
+               "privatedomains"
+       ],
+       "GroupPermissions": {
+               "*": {
+                       "edit": false,
+                       "minoredit": false,
+                       "move": false,
+                       "reupload": false,
+                       "reupload-shared": false,
+                       "upload": false
+               },
+               "bureaucrat": {
+                       "edit": true,
+                       "move": true,
+                       "upload": true,
+                       "privatedomains": true
+               },
+               "privatedomains": {
+                       "edit": true,
+                       "minoredit": true,
+                       "move": true,
+                       "reupload": true,
+                       "reupload-shared": true,
+                       "upload": true
+               },
+               "staff": {
+                       "edit": true,
+                       "move": true,
+                       "upload": true,
+                       "privatedomains": true
+               },
+               "user": {
+                       "edit": false,
+                       "minoredit": false,
+                       "move": false,
+                       "reupload": false,
+                       "reupload-shared": false,
+                       "upload": false
+               }
+       },
+       "manifest_version": 1
+}

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Iae01f1662fb67e1cb2d1f1c33db11eac50e12fec
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PrivateDomains
Gerrit-Branch: master
Gerrit-Owner: Jack Phoenix <j...@countervandalism.net>
Gerrit-Reviewer: Jack Phoenix <j...@countervandalism.net>
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