Index: branches/RL2/extensions/Gadgets/backend/LocalGadgetRepo.php |
— | — | @@ -179,6 +179,10 @@ |
180 | 180 | return wfGetDB( DB_SLAVE ); |
181 | 181 | } |
182 | 182 | |
| 183 | + public function isLocal() { |
| 184 | + return true; |
| 185 | + } |
| 186 | + |
183 | 187 | /*** Public methods ***/ |
184 | 188 | |
185 | 189 | /** |
Index: branches/RL2/extensions/Gadgets/backend/ForeignDBGadgetRepo.php |
— | — | @@ -46,6 +46,10 @@ |
47 | 47 | return $this->getMasterDB(); |
48 | 48 | } |
49 | 49 | |
| 50 | + public function isLocal() { |
| 51 | + return false; |
| 52 | + } |
| 53 | + |
50 | 54 | /*** Overridden protected methods from LocalGadgetRepo ***/ |
51 | 55 | protected function getMasterDB() { |
52 | 56 | if ( $this->db === null ) { |
Index: branches/RL2/extensions/Gadgets/backend/GadgetRepo.php |
— | — | @@ -75,6 +75,12 @@ |
76 | 76 | */ |
77 | 77 | abstract public function deleteGadget( $id ); |
78 | 78 | |
| 79 | + /** |
| 80 | + * Whether this repository is the local repository |
| 81 | + * @return boolean |
| 82 | + */ |
| 83 | + abstract public function isLocal(); |
| 84 | + |
79 | 85 | /**** Public methods ****/ |
80 | 86 | |
81 | 87 | public function getGadgetsByCategory() { |
— | — | @@ -106,18 +112,60 @@ |
107 | 113 | } |
108 | 114 | |
109 | 115 | /** |
110 | | - * Get all gadgets from all repositories. |
111 | | - * @return array of Gadget objects |
| 116 | + * 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 |
| 119 | + * @return array of Gadget objects or strings |
112 | 120 | */ |
113 | | - public static function getAllGadgets() { |
| 121 | + private static function getAllGadgets_internal( $includeLocal, $getObjects ) { |
114 | 122 | $retval = array(); |
115 | 123 | $repos = GadgetRepo::getAllRepos(); |
116 | 124 | foreach ( $repos as $repo ) { |
| 125 | + if ( !$includeLocal && $repo->isLocal() ) { |
| 126 | + continue; |
| 127 | + } |
| 128 | + |
117 | 129 | $gadgets = $repo->getGadgetIds(); |
118 | | - foreach ( $gadgets as $id ) { |
119 | | - $retval[] = $repo->getGadget( $id ); |
| 130 | + if ( $getObjects ) { |
| 131 | + foreach ( $gadgets as $id ) { |
| 132 | + $retval[] = $repo->getGadget( $id ); |
| 133 | + } |
| 134 | + } else { |
| 135 | + $retval = array_merge( $retval, $gadgets ); |
120 | 136 | } |
121 | 137 | } |
122 | 138 | return $retval; |
123 | 139 | } |
| 140 | + |
| 141 | + /** |
| 142 | + * Get all gadgets from all repositories |
| 143 | + * @return array of Gadget objects |
| 144 | + */ |
| 145 | + public static function getAllGadgets() { |
| 146 | + return self::getAllGadgets_internal( true, true ); |
| 147 | + } |
| 148 | + |
| 149 | + /** |
| 150 | + * Get all gadget IDs from all repositories |
| 151 | + * @return array of gadget IDs (strings) |
| 152 | + */ |
| 153 | + public static function getAllGadgetIDs() { |
| 154 | + return self::getAllGadgets_internal( true, false ); |
| 155 | + } |
| 156 | + |
| 157 | + /** |
| 158 | + * Get all gadgets from all remote repositories (i.e. all repositories except the local repository) |
| 159 | + * @return array of Gadget objects |
| 160 | + */ |
| 161 | + public static function getAllRemoteGadgets() { |
| 162 | + return self::getAllGadgets_internal( false, true ); |
| 163 | + } |
| 164 | + |
| 165 | + /** |
| 166 | + * Get all gadget IDs from all remote repositories (i.e. all repositories except the local repository) |
| 167 | + * @return array of gadget IDs (strings) |
| 168 | + */ |
| 169 | + public static function getAllRemoteGadgetIDs() { |
| 170 | + return self::getAllGadgets_internal( false, false ); |
| 171 | + } |
124 | 172 | } |