r106603 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106602‎ | r106603 | r106604 >
Date:21:43, 18 December 2011
Author:jeroendedauw
Status:resolved (Comments)
Tags:
Comment:
restore compat w/ mw 1.18
Modified paths:
  • /trunk/extensions/Contest/specials/SpecialContestPage.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialEditContest.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Contest/specials/SpecialContestPage.php
@@ -182,5 +182,17 @@
183183
184184 $this->getOutput()->addHTML( self::getNavigation( $subPage, $this->getUser(), $this->getLanguage(), $this->getName() ) );
185185 }
 186+
 187+ /**
 188+ * Get the Language being used for this instance.
 189+ * getLang was deprecated in 1.19, getLanguage was introduces in the same version.
 190+ *
 191+ * @since 0.2
 192+ *
 193+ * @return Language
 194+ */
 195+ public function getLanguage() {
 196+ return method_exists( $this, 'getLanguage' ) ? $this->getLanguage() : $this->getLang();
 197+ }
186198
187199 }
Index: trunk/extensions/Contest/specials/SpecialEditContest.php
@@ -395,6 +395,18 @@
396396 . '<hr style="display: block; clear: both; visibility: hidden;" />'
397397 );
398398 }
 399+
 400+ /**
 401+ * Get the Language being used for this instance.
 402+ * getLang was deprecated in 1.19, getLanguage was introduces in the same version.
 403+ *
 404+ * @since 0.2
 405+ *
 406+ * @return Language
 407+ */
 408+ public function getLanguage() {
 409+ return method_exists( $this, 'getLanguage' ) ? $this->getLanguage() : $this->getLang();
 410+ }
399411
400412 }
401413

Follow-up revisions

RevisionCommit summaryAuthorDate
r106708fix inf recursion failjeroendedauw22:20, 19 December 2011
r106709fix inf recursion failjeroendedauw22:22, 19 December 2011
r106838MFT r106452, r106603, r106708, r106709, r106713, r106714reedy19:15, 20 December 2011

Comments

#Comment by Nikerabbit (talk | contribs)   07:46, 19 December 2011

I thought someone merged the getLanguage change into 1.18...

#Comment by Nikerabbit (talk | contribs)   11:34, 19 December 2011

Hence the three dots...

#Comment by Johnduhart (talk | contribs)   07:14, 2 January 2012
[02:13] <Alphos> is it me or is that a method that checks if it exists itself, and return its own return value, or the return value of another method if it doesn't ?

uh

#Comment by Alphos (talk | contribs)   07:21, 2 January 2012

Just saying guys : method_exists( $this, 'getLanguage' ) will always return true, since the name of that method is "getLanguage".

Thus that function will always return the middle operand of the ternary ($this->getLanguage()).

However, $this->getLanguage() is the method itself. Which means that method will always call itself. And that internal call to itself will again check if that method exists, and since it does (because it's declared right there) it will, in turn, call itself. From now on, read that comment from the top, ad libitum.

Recursive functions are fine to play with, recursive (non-static) methods trigger some rather black magic one should avoid as much as possible…

#Comment by Jeroen De Dauw (talk | contribs)   07:27, 2 January 2012

Since this caused infinite recursion, I sort of noticed, and fixed it in some commit two weeks back or so. Since this was marked ok, I'm just moving it back, to not have a pointless "new" rev.

#Comment by Nikerabbit (talk | contribs)   07:34, 2 January 2012

The some commit was r106709. It took a minute or so for me to find. It took much more than a minute for other people to wonder if that has been fixed or not.

#Comment by Jeroen De Dauw (talk | contribs)   07:36, 2 January 2012

Yeah sure. This is why I normally do the follow up link thing, which I apparently forgot to do here.

#Comment by Jeroen De Dauw (talk | contribs)   07:27, 2 January 2012

Which I apparently cannot do. Sigh.

Status & tagging log