r92344 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92343‎ | r92344 | r92345 >
Date:02:14, 16 July 2011
Author:kaldari
Status:ok
Tags:
Comment:
dont show WikiLove tab if user talk page is a redirect
Modified paths:
  • /trunk/extensions/WikiLove/WikiLove.hooks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/WikiLove/WikiLove.hooks.php
@@ -161,26 +161,43 @@
162162 */
163163 public static function getUserTalkPage( $title ) {
164164 global $wgUser;
 165+
 166+ // Exit early if the sending user isn't logged in
165167 if ( !$wgUser->isLoggedIn() ) {
166168 return null;
167169 }
168170
 171+ // Exit early if we're in the wrong namespace
169172 $ns = $title->getNamespace();
170 - // return quickly if we're in the wrong namespace anyway
171173 if ( $ns != NS_USER && $ns != NS_USER_TALK ) {
172174 return null;
173175 }
174176
 177+ // If we're on a subpage, get the base page title
175178 $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;
179184 } 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();
184187 }
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+ }
186203 }
187204 }

Status & tagging log