Index: trunk/extensions/WikiLove/WikiLove.hooks.php |
— | — | @@ -161,26 +161,43 @@ |
162 | 162 | */ |
163 | 163 | public static function getUserTalkPage( $title ) { |
164 | 164 | global $wgUser; |
| 165 | + |
| 166 | + // Exit early if the sending user isn't logged in |
165 | 167 | if ( !$wgUser->isLoggedIn() ) { |
166 | 168 | return null; |
167 | 169 | } |
168 | 170 | |
| 171 | + // Exit early if we're in the wrong namespace |
169 | 172 | $ns = $title->getNamespace(); |
170 | | - // return quickly if we're in the wrong namespace anyway |
171 | 173 | if ( $ns != NS_USER && $ns != NS_USER_TALK ) { |
172 | 174 | return null; |
173 | 175 | } |
174 | 176 | |
| 177 | + // If we're on a subpage, get the base page title |
175 | 178 | $baseTitle = Title::newFromText( $title->getBaseText(), $ns ); |
176 | | - |
177 | | - if ( $ns == NS_USER_TALK && $baseTitle->quickUserCan( 'edit' ) ) { |
178 | | - return $baseTitle; |
| 179 | + |
| 180 | + // Get the user talk page |
| 181 | + if ( $ns == NS_USER_TALK ) { |
| 182 | + // We're already on the user talk page |
| 183 | + $talkTitle = $baseTitle; |
179 | 184 | } elseif ( $ns == NS_USER ) { |
180 | | - $talk = $baseTitle->getTalkPage(); |
181 | | - if ( $talk->quickUserCan( 'edit' ) ) { |
182 | | - return $talk; |
183 | | - } |
| 185 | + // We're on the user page, so retrieve the user talk page instead |
| 186 | + $talkTitle = $baseTitle->getTalkPage(); |
184 | 187 | } |
185 | | - return null; |
| 188 | + |
| 189 | + // If it's a redirect, exit. We don't follow redirects since it might confuse the user or |
| 190 | + // lead to an endless loop (like if the talk page redirects to the user page or a subpage). |
| 191 | + // This means that the WikiLove tab will not appear on user pages or user talk pages if |
| 192 | + // the user talk page is a redirect. |
| 193 | + if ( $talkTitle->isRedirect() ) { |
| 194 | + return null; |
| 195 | + } |
| 196 | + |
| 197 | + // Make sure we can edit the page |
| 198 | + if ( $talkTitle->quickUserCan( 'edit' ) ) { |
| 199 | + return $talkTitle; |
| 200 | + } else { |
| 201 | + return null; |
| 202 | + } |
186 | 203 | } |
187 | 204 | } |