Index: trunk/extensions/UsabilityInitiative/OptIn/SpecialOptIn.php |
— | — | @@ -7,29 +7,62 @@ |
8 | 8 | */ |
9 | 9 | |
10 | 10 | 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() { |
12 | 46 | parent::__construct( 'OptIn' ); |
13 | 47 | wfLoadExtensionMessages( 'OptIn' ); |
14 | 48 | } |
15 | | - |
16 | | - function execute( $par ) { |
| 49 | + |
| 50 | + public function execute( $par ) { |
17 | 51 | global $wgRequest, $wgOut, $wgUser; |
| 52 | + |
18 | 53 | $this->setHeaders(); |
19 | 54 | $wgOut->setPageTitle( wfMsg( 'optin-title' ) ); |
20 | | - |
21 | 55 | if ( $wgUser->isAnon() ) { |
22 | 56 | $url = SpecialPage::getTitleFor( 'Userlogin' )->getFullURL( |
23 | 57 | array( 'returnto' => $this->getTitle()->getPrefixedUrl() ) ); |
24 | 58 | $wgOut->wrapWikiMsg( "<div class='plainlinks'>\n$1\n</div>", array( 'optin-needlogin', $url ) ); |
25 | 59 | return; |
26 | 60 | } |
27 | | - |
28 | 61 | if ( $wgRequest->wasPosted() ) { |
29 | 62 | if ( $wgRequest->getVal( 'opt' ) === 'in' ) { |
30 | | - $this->optIn( $wgUser ); |
| 63 | + self::optIn( $wgUser ); |
31 | 64 | $wgOut->addWikiMsg( 'optin-success-in' ); |
32 | 65 | } else { |
33 | | - $this->optOut( $wgUser ); |
| 66 | + self::optOut( $wgUser ); |
34 | 67 | $this->saveSurvey(); |
35 | 68 | $wgOut->addWikiMsg( 'optin-success-out' ); |
36 | 69 | } |
— | — | @@ -37,13 +70,16 @@ |
38 | 71 | $this->showForm(); |
39 | 72 | } |
40 | 73 | |
41 | | - function showForm() { |
| 74 | + /* Private Functions */ |
| 75 | + |
| 76 | + private function showForm() { |
42 | 77 | global $wgUser, $wgOut; |
| 78 | + |
43 | 79 | $wgOut->addHTML( Xml::openElement( 'form', array( |
44 | 80 | 'method' => 'post', |
45 | 81 | 'action' => $this->getTitle()->getLinkURL() |
46 | 82 | ) ) ); |
47 | | - $opt = ( $this->isOptedIn( $wgUser ) ? 'out' : 'in' ); |
| 83 | + $opt = ( self::isOptedIn( $wgUser ) ? 'out' : 'in' ); |
48 | 84 | if ( $opt == 'out' ) { |
49 | 85 | $wgOut->addWikiMsg( 'optin-survey-intro' ); |
50 | 86 | $this->showSurvey(); |
— | — | @@ -61,8 +97,9 @@ |
62 | 98 | $wgOut->addWikiMsg( 'optin-improvements' ); |
63 | 99 | } |
64 | 100 | |
65 | | - function showOptInButtons() { |
| 101 | + private function showOptInButtons() { |
66 | 102 | global $wgOut, $wgOptInStyleVersion; |
| 103 | + |
67 | 104 | UsabilityInitiativeHooks::initialize(); |
68 | 105 | UsabilityInitiativeHooks::addStyle( 'OptIn/OptIn.css', |
69 | 106 | $wgOptInStyleVersion ); |
— | — | @@ -107,38 +144,12 @@ |
108 | 145 | ); |
109 | 146 | } |
110 | 147 | |
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() { |
138 | 149 | global $wgOptInSurvey, $wgOut, $wgOptInStyleVersion; |
| 150 | + |
139 | 151 | UsabilityInitiativeHooks::initialize(); |
140 | 152 | UsabilityInitiativeHooks::addScript( 'OptIn/OptIn.js', |
141 | 153 | $wgOptInStyleVersion ); |
142 | | - |
143 | 154 | $retval = Xml::openElement( 'table' ); |
144 | 155 | foreach ( $wgOptInSurvey as $id => $question ) { |
145 | 156 | switch ( $question['type'] ) { |
— | — | @@ -236,8 +247,9 @@ |
237 | 248 | $wgOut->addHTML( $retval ); |
238 | 249 | } |
239 | 250 | |
240 | | - function saveSurvey() { |
| 251 | + private function saveSurvey() { |
241 | 252 | global $wgRequest, $wgUser, $wgOptInSurvey; |
| 253 | + |
242 | 254 | $dbw = wfGetDb( DB_MASTER ); |
243 | 255 | $now = $dbw->timestamp( wfTimestamp() ); |
244 | 256 | // var_dump($wgRequest->data); die(); |