r52991 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r52990‎ | r52991 | r52992 >
Date:17:41, 9 July 2009
Author:tparscal
Status:deferred
Tags:
Comment:
Refactored a bit to allow use of certain functions from other hooks, and also to limit access to others.
Modified paths:
  • /trunk/extensions/UsabilityInitiative/OptIn/SpecialOptIn.php (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/OptIn/SpecialOptIn.php
@@ -7,29 +7,62 @@
88 */
99
1010 class SpecialOptIn extends SpecialPage {
11 - function __construct() {
 11+
 12+ /* Static Functions */
 13+
 14+ public static function isOptedIn( $user ) {
 15+ global $wgOptInPrefs;
 16+
 17+ foreach ( $wgOptInPrefs as $pref => $value ) {
 18+ if ( $user->getOption( $pref ) != $value ) {
 19+ return false;
 20+ }
 21+ }
 22+ return true;
 23+ }
 24+
 25+ public static function optIn( $user ) {
 26+ global $wgOptInPrefs;
 27+
 28+ foreach ( $wgOptInPrefs as $pref => $value ) {
 29+ $user->setOption( $pref, $value );
 30+ }
 31+ $user->saveSettings();
 32+ }
 33+
 34+ public static function optOut( $user ) {
 35+ global $wgOptInPrefs;
 36+
 37+ foreach ( $wgOptInPrefs as $pref => $value ) {
 38+ $user->setOption( $pref, null );
 39+ }
 40+ $user->saveSettings();
 41+ }
 42+
 43+ /* Functions */
 44+
 45+ public function __construct() {
1246 parent::__construct( 'OptIn' );
1347 wfLoadExtensionMessages( 'OptIn' );
1448 }
15 -
16 - function execute( $par ) {
 49+
 50+ public function execute( $par ) {
1751 global $wgRequest, $wgOut, $wgUser;
 52+
1853 $this->setHeaders();
1954 $wgOut->setPageTitle( wfMsg( 'optin-title' ) );
20 -
2155 if ( $wgUser->isAnon() ) {
2256 $url = SpecialPage::getTitleFor( 'Userlogin' )->getFullURL(
2357 array( 'returnto' => $this->getTitle()->getPrefixedUrl() ) );
2458 $wgOut->wrapWikiMsg( "<div class='plainlinks'>\n$1\n</div>", array( 'optin-needlogin', $url ) );
2559 return;
2660 }
27 -
2861 if ( $wgRequest->wasPosted() ) {
2962 if ( $wgRequest->getVal( 'opt' ) === 'in' ) {
30 - $this->optIn( $wgUser );
 63+ self::optIn( $wgUser );
3164 $wgOut->addWikiMsg( 'optin-success-in' );
3265 } else {
33 - $this->optOut( $wgUser );
 66+ self::optOut( $wgUser );
3467 $this->saveSurvey();
3568 $wgOut->addWikiMsg( 'optin-success-out' );
3669 }
@@ -37,13 +70,16 @@
3871 $this->showForm();
3972 }
4073
41 - function showForm() {
 74+ /* Private Functions */
 75+
 76+ private function showForm() {
4277 global $wgUser, $wgOut;
 78+
4379 $wgOut->addHTML( Xml::openElement( 'form', array(
4480 'method' => 'post',
4581 'action' => $this->getTitle()->getLinkURL()
4682 ) ) );
47 - $opt = ( $this->isOptedIn( $wgUser ) ? 'out' : 'in' );
 83+ $opt = ( self::isOptedIn( $wgUser ) ? 'out' : 'in' );
4884 if ( $opt == 'out' ) {
4985 $wgOut->addWikiMsg( 'optin-survey-intro' );
5086 $this->showSurvey();
@@ -61,8 +97,9 @@
6298 $wgOut->addWikiMsg( 'optin-improvements' );
6399 }
64100
65 - function showOptInButtons() {
 101+ private function showOptInButtons() {
66102 global $wgOut, $wgOptInStyleVersion;
 103+
67104 UsabilityInitiativeHooks::initialize();
68105 UsabilityInitiativeHooks::addStyle( 'OptIn/OptIn.css',
69106 $wgOptInStyleVersion );
@@ -107,38 +144,12 @@
108145 );
109146 }
110147
111 - function isOptedIn( $user ) {
112 - global $wgOptInPrefs;
113 - foreach ( $wgOptInPrefs as $pref => $value ) {
114 - if ( $user->getOption( $pref ) != $value ) {
115 - return false;
116 - }
117 - }
118 - return true;
119 - }
120 -
121 - function optIn( $user ) {
122 - global $wgOptInPrefs;
123 - foreach ( $wgOptInPrefs as $pref => $value ) {
124 - $user->setOption( $pref, $value );
125 - }
126 - $user->saveSettings();
127 - }
128 -
129 - function optOut( $user ) {
130 - global $wgOptInPrefs;
131 - foreach ( $wgOptInPrefs as $pref => $value ) {
132 - $user->setOption( $pref, null );
133 - }
134 - $user->saveSettings();
135 - }
136 -
137 - function showSurvey() {
 148+ private function showSurvey() {
138149 global $wgOptInSurvey, $wgOut, $wgOptInStyleVersion;
 150+
139151 UsabilityInitiativeHooks::initialize();
140152 UsabilityInitiativeHooks::addScript( 'OptIn/OptIn.js',
141153 $wgOptInStyleVersion );
142 -
143154 $retval = Xml::openElement( 'table' );
144155 foreach ( $wgOptInSurvey as $id => $question ) {
145156 switch ( $question['type'] ) {
@@ -236,8 +247,9 @@
237248 $wgOut->addHTML( $retval );
238249 }
239250
240 - function saveSurvey() {
 251+ private function saveSurvey() {
241252 global $wgRequest, $wgUser, $wgOptInSurvey;
 253+
242254 $dbw = wfGetDb( DB_MASTER );
243255 $now = $dbw->timestamp( wfTimestamp() );
244256 // var_dump($wgRequest->data); die();

Status & tagging log