r105184 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105183‎ | r105184 | r105185 >
Date:15:54, 5 December 2011
Author:reedy
Status:deferred
Tags:
Comment:
Fix indenting/whitespace

Fix bug 32808, with refactoring of patch by Olaf Lenz

Invert some conditionals to remove empty blocks

Fix register_globals issue
Modified paths:
  • /trunk/extensions/NetworkAuth/NetworkAuth.php (modified) (history)

Diff [purge]

Index: trunk/extensions/NetworkAuth/NetworkAuth.php
@@ -10,6 +10,7 @@
1111 }
1212
1313 $wgNetworkAuthUsers[] = array();
 14+$wgNetworkAuthUser = 'HelpdeskComputer';
1415
1516 $wgExtensionCredits['other'][] = array(
1617 'path' => __FILE__,
@@ -24,29 +25,29 @@
2526 $wgExtensionMessagesFiles['NetworkAuth'] = dirname(__FILE__) . '/NetworkAuth.i18n.php';
2627
2728 function efNetworkAuth_Setup() {
28 - global $wgRequest;
 29+ global $wgRequest;
2930
30 - # $wgTitle isn't initalized yet - but we need to know where we are
31 - $pageTitle = Title::newFromURL( $wgRequest->getVal('title') );
32 -
33 - if (is_object($pageTitle)) {
34 - # Doesn't apply to Userlogin and Userlogout pages - that breaks stuff
35 - if ($pageTitle->isSpecial('Userlogin') || $pageTitle->isSpecial('Userlogout')) {
36 - # bail!
37 - return true;
38 - }
 31+ # $wgTitle isn't initalized yet - but we need to know where we are
 32+ $pageTitle = Title::newFromURL( $wgRequest->getVal('title') );
 33+
 34+ if (is_object($pageTitle)) {
 35+ # Doesn't apply to Userlogin and Userlogout pages - that breaks stuff
 36+ if ($pageTitle->isSpecial('Userlogin') || $pageTitle->isSpecial('Userlogout')) {
 37+ # bail!
 38+ return true;
3939 }
40 -
41 - efNetworkAuth_Authenticate();
42 -
43 - return true;
 40+ }
 41+
 42+ efNetworkAuth_Authenticate();
 43+
 44+ return true;
4445 }
4546
4647 function efNetworkAuth_checkForNetworkAuthUser() {
4748 global $wgNetworkAuthUsers;
48 -
 49+
4950 $ip = wfGetIP();
50 -
 51+
5152 foreach ($wgNetworkAuthUsers as $networkAuthUser) {
5253 if ( isset( $networkAuthUser['user'] ) ) {
5354 if ( isset( $networkAuthUser['iprange'] ) ) {
@@ -54,7 +55,7 @@
5556 $ranges = $networkAuthUser['iprange'];
5657 else
5758 $ranges = explode("\n", $networkAuthUser['iprange']);
58 -
 59+
5960 $hex = IP::toHex( $ip );
6061 foreach ( $ranges as $range ) {
6162 $parsedRange = IP::parseRange( $range );
@@ -65,13 +66,13 @@
6667 }
6768 }
6869 }
69 -
 70+
7071 if ( isset( $networkAuthUser['ippattern'] ) ) {
7172 if ( is_array( $networkAuthUser['ippattern'] ) )
7273 $patterns = $networkAuthUser['ippattern'];
7374 else
7475 $patterns = explode("\n", $networkAuthUser['ippattern']);
75 -
 76+
7677 foreach ( $patterns as $pattern ) {
7778 if ( preg_match( $pattern, $ip) ) {
7879 global $wgNetworkAuthHost;
@@ -86,7 +87,7 @@
8788 $patterns = $networkAuthUser['hostpattern'];
8889 else
8990 $patterns = explode("\n", $networkAuthUser['hostpattern']);
90 -
 91+
9192 $host = gethostbyaddr( $ip );
9293 foreach ( $patterns as $pattern ) {
9394 if ( preg_match( $pattern, $host) ) {
@@ -100,76 +101,66 @@
101102 # No user for range - useless.
102103 }
103104 }
104 -
 105+
105106 return '';
106107 }
107108
108109 function efNetworkAuth_Authenticate() {
109110 global $wgUser;
110 -
111 - $wgNetworkAuthUser = 'HelpdeskComputer';
112 -
113111 if (!$wgUser->isLoggedIn()) {
114112 //echo 'Logged out: ' . $wgUser->getName();
115 -
 113+
 114+ $u = null;
116115 $networkAuthUser = efNetworkAuth_checkForNetworkAuthUser();
117116 if ( $networkAuthUser != '' ) {
118117 global $wgNetworkAuthUser;
119118 $wgNetworkAuthUser = $networkAuthUser;
120119
121 - $u = User::newFromName( $wgNetworkAuthUser );
 120+ $u = User::newFromName( $wgNetworkAuthUser );
122121 }
123 -
124 - if( is_null( $u ) || !User::isUsableName( $u->getName() ) ) {
125 - # Not cool. Bad config
126 - } else {
127 - if ( 0 == $u->getID() ) {
128 - # Not cool. Bad username
129 - } else {
 122+
 123+ if( is_null( $u ) && !User::isUsableName( $u->getName() ) ) {
 124+ if ( !$u->isAnon() ) {
130125 # Finally.
131126 $u->load();
132127 $wgUser = $u;
133 -
 128+
134129 # Since we're not really logged in, just pretending - force a logout
135130 # before the page gets displayed.
136131 global $wgHooks;
137132 $wgHooks['BeforePageDisplay'][] = 'efNetworkAuth_ForceLogout';
138 -
 133+
139134 # Add a display message to the personal URLs
140135 $wgHooks['PersonalUrls'][] = 'efNetworkAuth_PersonalUrls';
141136 }
142137 }
143 - } else {
144 - # Already logged in, do nothing.
145138 }
146139 return true;
147140 }
148141
149142 function ar_gethostbyaddr($ip) {
150 - $output = `host -W 1 $ip`;
151 - if (ereg('.*pointer ([A-Za-z0-9.-]+)\..*',$output,$regs)) {
152 - return $regs[1];
153 - }
154 - return $ip;
 143+ $output = `host -W 1 $ip`;
 144+ if (ereg('.*pointer ([A-Za-z0-9.-]+)\..*',$output,$regs)) {
 145+ return $regs[1];
 146+ }
 147+ return $ip;
155148 }
156149
157 -function efNetworkAuth_PersonalUrls($personal_urls, $title) {
 150+function efNetworkAuth_PersonalUrls(&$personal_urls, &$title) {
158151 global $wgNetworkAuthUser, $wgNetworkAuthHost;
159 -
 152+
160153 // Lazy load the i18n stuff here
161 -
162 -
 154+
163155 if (isset($personal_urls['anonuserpage'])) {
164156 $personal_urls['anonuserpage']['text'] =
165157 wfMsg('networkauth-purltext', $wgNetworkAuthUser, $wgNetworkAuthHost);
166158 } else {
167 - global $wgUser;
168159 $newUrls['anonuserpage'] = array(
169160 'text' => wfMsg('networkauth-purltext', $wgNetworkAuthUser, $wgNetworkAuthHost),
170161 'href' => null,
171162 'active' => true
172163 );
173 -
 164+
174165 foreach($personal_urls as $key => $value) {
175166 if ( $key == 'login' )
176167 $newUrls['anonlogin'] = $value;
@@ -185,6 +176,6 @@
186177 # Force logout after most of the permission checks
187178 global $wgUser;
188179 $wgUser->logout();
189 -
 180+
190181 return true;
191182 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r105185Rarrgh, missed a ! in r105184reedy16:09, 5 December 2011

Status & tagging log