r78192 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78191‎ | r78192 | r78193 >
Date:15:15, 10 December 2010
Author:demon
Status:ok (Comments)
Tags:
Comment:
Fix for r71961 (moved SpecialPage constructor from named to __construct()). Intercept calls to parent::SpecialPage() with __call() so we don't break people still using the old constructor.
Modified paths:
  • /trunk/phase3/includes/SpecialPage.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialActiveusers.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialActiveusers.php
@@ -165,7 +165,7 @@
166166 * Constructor
167167 */
168168 public function __construct() {
169 - parent::__construct( 'Activeusers' );
 169+ SpecialPage::SpecialPage( 'Activeusers' );
170170 }
171171
172172 /**
Index: trunk/phase3/includes/SpecialPage.php
@@ -702,7 +702,16 @@
703703 * @param $file String: file which is included by execute(). It is also constructed from $name by default
704704 * @param $includable Boolean: whether the page can be included in normal pages
705705 */
706 - function __construct( $name = '', $restriction = '', $listed = true, $function = false, $file = 'default', $includable = false ) {
 706+ public function __construct( $name = '', $restriction = '', $listed = true, $function = false, $file = 'default', $includable = false ) {
 707+ $this->init( $name, $restriction, $listed, $function, $file, $includable );
 708+ }
 709+
 710+ /**
 711+ * Do the real work for the constructor, mainly so __call() can intercept
 712+ * calls to SpecialPage()
 713+ * @see __construct() for param docs
 714+ */
 715+ private function init( $name, $restriction, $listed, $function, $file, $includable ) {
707716 $this->mName = $name;
708717 $this->mRestriction = $restriction;
709718 $this->mListed = $listed;
@@ -719,6 +728,29 @@
720729 }
721730 }
722731
 732+ /**
 733+ * Use PHP's magic __call handler to get calls to the old PHP4 constructor
 734+ * because PHP E_STRICT yells at you for having __construct() and SpecialPage()
 735+ *
 736+ * @param $name String Name of called method
 737+ * @param $a Array Arguments to the method
 738+ * @deprecated Call isn't deprecated, but SpecialPage::SpecialPage() is
 739+ */
 740+ public function __call( $fName, $a ) {
 741+ // Sometimes $fName is SpecialPage, sometimes it's specialpage. <3 PHP
 742+ if( strtolower( $fName ) == 'specialpage' ) {
 743+ // Debug messages now, warnings in 1.19 or 1.20?
 744+ wfDebug( "Deprecated SpecialPage::SpecialPage() called, use __construct();\n" );
 745+ $name = isset( $a[0] ) ? $a[0] : '';
 746+ $restriction = isset( $a[1] ) ? $a[1] : '';
 747+ $listed = isset( $a[2] ) ? $a[2] : true;
 748+ $function = isset( $a[3] ) ? $a[3] : false;
 749+ $file = isset( $a[4] ) ? $a[4] : 'default';
 750+ $includable = isset( $a[5] ) ? $a[5] : false;
 751+ $this->init( $name, $restriction, $listed, $function, $file, $includable );
 752+ }
 753+ }
 754+
723755 /**#@+
724756 * Accessor
725757 *

Follow-up revisions

RevisionCommit summaryAuthorDate
r78204Fix for r78192, forgot to revert a testdemon19:38, 10 December 2010
r78299Fix variable name in doc comment added in r78192catrope12:44, 13 December 2010
r784371.17: Merge tagged revisions from trunk: r77878, r77981, r77982, r77994, r780...catrope14:14, 15 December 2010
r78695Followup r78192: rather than silently ignoring calls to undefined SpecialPage...catrope17:15, 21 December 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r71961Get rid of PHP4-style constructorsdemon16:52, 30 August 2010

Comments

#Comment by Bryan (talk | contribs)   10:14, 8 February 2011

Breaks classes derived from UnlistedSpecialPage and other classes that derive SpecialPage indirectly. if( strtolower( $fName ) == strtolower( get_parent_class( $this ) ) ) would fix it, but people suggest that we should not care and just fix the constructors.

Status & tagging log