Reedy has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/279721

Change subject: Move SecurePoll Hooks to seperate file
......................................................................

Move SecurePoll Hooks to seperate file

Change-Id: I87125a67de42ef8859701ff4aa44397bde0ff7e6
---
M SecurePoll.php
A includes/SecurePollHooks.php
2 files changed, 87 insertions(+), 59 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SecurePoll 
refs/changes/21/279721/1

diff --git a/SecurePoll.php b/SecurePoll.php
index df5d85a..8588743 100644
--- a/SecurePoll.php
+++ b/SecurePoll.php
@@ -164,6 +164,7 @@
        'SecurePoll_HTMLDateField' => 
"$dir/includes/htmlform/HTMLDateField.php",
        'SecurePoll_HTMLDateRangeField' => 
"$dir/includes/htmlform/HTMLDateRangeField.php",
        'SecurePoll_HTMLFormRadioRangeColumnLabels' => 
"$dir/includes/htmlform/HTMLFormRadioRangeColumnLabels.php",
+       'SecurePollHooks' => "$dir/includes/SecurePollHooks.php",
 );
 
 $wgAPIModules['strikevote'] = 'ApiStrikeVote';
@@ -179,7 +180,11 @@
        'styles' => 'ext.securepoll.css',
 );
 
-$wgHooks['UserLogout'][] = 'wfSecurePollLogout';
+$wgHooks['UserLogout'][] = 'SecurePoll::onUserLogout';
+$wgHooks['LoadExtensionSchemaUpdates'][] = 
'SecurePollHooks::onLoadExtensionSchemaUpdates';
+$wgHooks['CanonicalNamespaces'][] = 'SecurePollHooks::onCanonicalNamespaces';
+$wgHooks['TitleQuickPermissions'][] = 
'SecurePollHooks::onTitleQuickPermissions';
+$wgHooks['ContentHandlerDefaultModelFor'][] = 
'SecurePollHooks::onContentHandlerDefaultModelFor';
 
 $wgJobClasses['securePollPopulateVoterList'] = 
'SecurePoll_PopulateVoterListJob';
 
@@ -187,65 +192,7 @@
 
 $wgAvailableRights[] = 'securepoll-create-poll';
 
-function wfSecurePollLogout( $user ) {
-       $_SESSION['securepoll_voter'] = null;
-       return true;
-}
-
-$wgHooks['LoadExtensionSchemaUpdates'][] = 'efSecurePollSchemaUpdates';
-
-/**
- * @param $updater DatabaseUpdater
- * @return bool
- */
-function efSecurePollSchemaUpdates( $updater ) {
-       $base = dirname( __FILE__ );
-       switch ( $updater->getDB()->getType() ) {
-               case 'mysql':
-                       $updater->addExtensionTable( 'securepoll_entity', 
"$base/SecurePoll.sql" );
-                       $updater->modifyField( 'securepoll_votes', 'vote_ip',
-                               "$base/patches/patch-vote_ip-extend.sql", true 
);
-                       $updater->addExtensionIndex( 'securepoll_options', 
'spop_election',
-                               "$base/patches/patch-op_election-index.sql"
-                       );
-                       break;
-               case 'postgres':
-                       $updater->addExtensionTable( 'securepoll_entity', 
"$base/SecurePoll.pg.sql" );
-                       break;
-       }
-       return true;
-}
-
 define( 'NS_SECUREPOLL', 830 );
 define( 'NS_SECUREPOLL_TALK', 831 );
 $wgNamespacesWithSubpages[NS_SECUREPOLL] = true;
 $wgNamespacesWithSubpages[NS_SECUREPOLL_TALK] = true;
-
-$wgHooks['CanonicalNamespaces'][] = function ( &$namespaces ) {
-       global $wgSecurePollUseNamespace;
-       if ( $wgSecurePollUseNamespace ) {
-               $namespaces[NS_SECUREPOLL] = 'SecurePoll';
-               $namespaces[NS_SECUREPOLL_TALK] = 'SecurePoll_talk';
-       }
-};
-
-$wgHooks['TitleQuickPermissions'][] = function ( $title, $user, $action, 
&$errors, $doExpensiveQueries, $short ) {
-       global $wgSecurePollUseNamespace;
-       if ( $wgSecurePollUseNamespace && $title->getNamespace() === 
NS_SECUREPOLL &&
-               $action !== 'read'
-       ) {
-               $errors[] = array( 'securepoll-ns-readonly' );
-               return false;
-       }
-
-       return true;
-};
-
-$wgHooks['ContentHandlerDefaultModelFor'][] = function ( $title, &$model ) {
-       global $wgSecurePollUseNamespace;
-       if( $wgSecurePollUseNamespace && $title->getNamespace() == 
NS_SECUREPOLL ) {
-               $model = 'SecurePoll';
-               return false;
-       }
-       return true;
-};
diff --git a/includes/SecurePollHooks.php b/includes/SecurePollHooks.php
new file mode 100644
index 0000000..a727309
--- /dev/null
+++ b/includes/SecurePollHooks.php
@@ -0,0 +1,81 @@
+<?php
+
+class SecurePollHooks {
+
+       /**
+        * @param $user User
+        * @return bool
+        */
+       public static function onUserLogout( $user ) {
+               $_SESSION['securepoll_voter'] = null;
+               return true;
+       }
+
+       /**
+        * @param $updater DatabaseUpdater
+        * @return bool
+        */
+       public static function onLoadExtensionSchemaUpdates( $updater ) {
+               $base = dirname( __FILE__ );
+               switch ( $updater->getDB()->getType() ) {
+                       case 'mysql':
+                               $updater->addExtensionTable( 
'securepoll_entity', "$base/SecurePoll.sql" );
+                               $updater->modifyField( 'securepoll_votes', 
'vote_ip',
+                                       
"$base/patches/patch-vote_ip-extend.sql", true );
+                               $updater->addExtensionIndex( 
'securepoll_options', 'spop_election',
+                                       
"$base/patches/patch-op_election-index.sql"
+                               );
+                               break;
+                       case 'postgres':
+                               $updater->addExtensionTable( 
'securepoll_entity', "$base/SecurePoll.pg.sql" );
+                               break;
+               }
+               return true;
+       }
+
+       /**
+        * @param $namespaces array
+        */
+       public static function onCanonicalNamespaces( &$namespaces ) {
+               global $wgSecurePollUseNamespace;
+               if ( $wgSecurePollUseNamespace ) {
+                       $namespaces[NS_SECUREPOLL] = 'SecurePoll';
+                       $namespaces[NS_SECUREPOLL_TALK] = 'SecurePoll_talk';
+               }
+       }
+
+       /**
+        * @param $title Title
+        * @param $user User
+        * @param $action string
+        * @param $errors array
+        * @param $doExpensiveQueries bool
+        * @param $short
+        * @return bool
+        */
+       public static function onTitleQuickPermissions( $title, $user, $action, 
&$errors, $doExpensiveQueries, $short ) {
+               global $wgSecurePollUseNamespace;
+               if ( $wgSecurePollUseNamespace && $title->getNamespace() === 
NS_SECUREPOLL &&
+                       $action !== 'read'
+               ) {
+                       $errors[] = [ 'securepoll-ns-readonly' ];
+                       return false;
+               }
+
+               return true;
+       }
+
+       /**
+        * @param $title Title
+        * @param $model string
+        * @return bool
+        */
+       public static function ContentHandlerDefaultModelFor( $title, &$model ) 
{
+               global $wgSecurePollUseNamespace;
+               if( $wgSecurePollUseNamespace && $title->getNamespace() == 
NS_SECUREPOLL ) {
+                       $model = 'SecurePoll';
+                       return false;
+               }
+               return true;
+       }
+}
\ No newline at end of file

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I87125a67de42ef8859701ff4aa44397bde0ff7e6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SecurePoll
Gerrit-Branch: master
Gerrit-Owner: Reedy <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to