r101305 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101304‎ | r101305 | r101306 >
Date:16:42, 30 October 2011
Author:krinkle
Status:reverted (Comments)
Tags:
Comment:
[RL2] Use Strangs instead of booleans for GadgetRepo::getAllGadgets_internal
* Follow-up r100884
Modified paths:
  • /branches/RL2/extensions/Gadgets/backend/GadgetRepo.php (modified) (history)

Diff [purge]

Index: branches/RL2/extensions/Gadgets/backend/GadgetRepo.php
@@ -113,28 +113,28 @@
114114
115115 /**
116116 * Helper function for getAllGadgets(), getAllGadgetIDs(), getAllRemoteGadgets() and getAllRemoteGadgetIDs()
117 - * @param $includeLocal boolean Whether gadgets from the local repo should be included
118 - * @param $getObjects boolean Whether Gadget objects should be constructed. If false, IDs (strings) will be returned
 117+ * @param $source String: one of 'local', 'remote', 'all'.
 118+ * @param $retType String: Whether to return an array of IDs ('ids'), or Gadget objects ('objects').
119119 * @return array of Gadget objects or strings
120120 */
121 - private static function getAllGadgets_internal( $includeLocal, $getObjects ) {
122 - $retval = array();
 121+ private static function getAllGadgets_internal( $source = 'all', $retType = 'ids' ) {
 122+ $retVal = array();
123123 $repos = GadgetRepo::getAllRepos();
124124 foreach ( $repos as $repo ) {
125 - if ( !$includeLocal && $repo->isLocal() ) {
 125+ if ( $source == 'remote' && $repo->isLocal() ) {
126126 continue;
127127 }
128128
129129 $gadgets = $repo->getGadgetIds();
130 - if ( $getObjects ) {
 130+ if ( $retType = 'objects' ) {
131131 foreach ( $gadgets as $id ) {
132 - $retval[] = $repo->getGadget( $id );
 132+ $retVal[] = $repo->getGadget( $id );
133133 }
134134 } else {
135 - $retval = array_merge( $retval, $gadgets );
 135+ $retVal = array_merge( $retVal, $gadgets );
136136 }
137137 }
138 - return $retval;
 138+ return $retVal;
139139 }
140140
141141 /**
@@ -142,7 +142,7 @@
143143 * @return array of Gadget objects
144144 */
145145 public static function getAllGadgets() {
146 - return self::getAllGadgets_internal( true, true );
 146+ return self::getAllGadgets_internal( 'all', 'objects' );
147147 }
148148
149149 /**
@@ -150,7 +150,7 @@
151151 * @return array of gadget IDs (strings)
152152 */
153153 public static function getAllGadgetIDs() {
154 - return self::getAllGadgets_internal( true, false );
 154+ return self::getAllGadgets_internal( 'all', 'ids' );
155155 }
156156
157157 /**
@@ -158,7 +158,7 @@
159159 * @return array of Gadget objects
160160 */
161161 public static function getAllRemoteGadgets() {
162 - return self::getAllGadgets_internal( false, true );
 162+ return self::getAllGadgets_internal( 'remote', 'objects' );
163163 }
164164
165165 /**
@@ -166,6 +166,6 @@
167167 * @return array of gadget IDs (strings)
168168 */
169169 public static function getAllRemoteGadgetIDs() {
170 - return self::getAllGadgets_internal( false, false );
 170+ return self::getAllGadgets_internal( 'remote', 'ids' );
171171 }
172172 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r101344[RL2] Revert r101305, broken. Warning: Illegal offset type in /home/catrope/m...catrope09:27, 31 October 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r100884[RL2] Turn getAllGadgets() into a versatile helper function that supports get...catrope21:48, 26 October 2011

Comments

#Comment by Catrope (talk | contribs)   16:43, 30 October 2011

Why? It's a private function, not meant to be called (and impossible to be called) by anything else than the four wrapper functions.

#Comment by Krinkle (talk | contribs)   18:32, 31 October 2011

Broken:
- if ( $retType = 'objects' ) {

Reverted in r101344.

Status & tagging log