Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
28 | class DeletedContributionsPage extends SpecialPage { |
||
29 | function __construct() { |
||
33 | |||
34 | /** |
||
35 | * Special page "deleted user contributions". |
||
36 | * Shows a list of the deleted contributions of a user. |
||
37 | * |
||
38 | * @param string $par (optional) user name of the user for which to show the contributions |
||
39 | */ |
||
40 | function execute( $par ) { |
||
127 | |||
128 | /** |
||
129 | * Generates the subheading with links |
||
130 | * @param User $userObj User object for the target |
||
131 | * @return string Appropriately-escaped HTML to be output literally |
||
132 | */ |
||
133 | function getSubTitle( $userObj ) { |
||
134 | $linkRenderer = $this->getLinkRenderer(); |
||
135 | if ( $userObj->isAnon() ) { |
||
136 | $user = htmlspecialchars( $userObj->getName() ); |
||
137 | } else { |
||
138 | $user = $linkRenderer->makeLink( $userObj->getUserPage(), $userObj->getName() ); |
||
139 | } |
||
140 | $links = ''; |
||
141 | $nt = $userObj->getUserPage(); |
||
142 | $talk = $nt->getTalkPage(); |
||
143 | if ( $talk ) { |
||
144 | $tools = SpecialContributions::getUserLinks( $this, $userObj ); |
||
145 | |||
146 | # Link to contributions |
||
147 | $insert['contribs'] = $linkRenderer->makeKnownLink( |
||
148 | SpecialPage::getTitleFor( 'Contributions', $nt->getDBkey() ), |
||
149 | $this->msg( 'sp-deletedcontributions-contribs' )->text() |
||
150 | ); |
||
151 | |||
152 | // Swap out the deletedcontribs link for our contribs one |
||
153 | $tools = wfArrayInsertAfter( $tools, $insert, 'deletedcontribs' ); |
||
154 | unset( $tools['deletedcontribs'] ); |
||
155 | |||
156 | $links = $this->getLanguage()->pipeList( $tools ); |
||
157 | |||
158 | // Show a note if the user is blocked and display the last block log entry. |
||
159 | $block = Block::newFromTarget( $userObj, $userObj ); |
||
160 | View Code Duplication | if ( !is_null( $block ) && $block->getType() != Block::TYPE_AUTO ) { |
|
161 | if ( $block->getType() == Block::TYPE_RANGE ) { |
||
162 | $nt = MWNamespace::getCanonicalName( NS_USER ) . ':' . $block->getTarget(); |
||
163 | } |
||
164 | |||
165 | // LogEventsList::showLogExtract() wants the first parameter by ref |
||
166 | $out = $this->getOutput(); |
||
167 | LogEventsList::showLogExtract( |
||
168 | $out, |
||
169 | 'block', |
||
170 | $nt, |
||
171 | '', |
||
172 | [ |
||
173 | 'lim' => 1, |
||
174 | 'showIfEmpty' => false, |
||
175 | 'msgKey' => [ |
||
176 | 'sp-contributions-blocked-notice', |
||
177 | $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice' |
||
178 | ], |
||
179 | 'offset' => '' # don't use $this->getRequest() parameter offset |
||
180 | ] |
||
181 | ); |
||
182 | } |
||
183 | } |
||
184 | |||
185 | return $this->msg( 'contribsub2' )->rawParams( $user, $links )->params( $userObj->getName() ); |
||
186 | } |
||
187 | |||
188 | /** |
||
189 | * Generates the namespace selector form with hidden attributes. |
||
190 | * @param array $options The options to be included. |
||
191 | * @return string |
||
192 | */ |
||
193 | function getForm( $options ) { |
||
194 | $options['title'] = $this->getPageTitle()->getPrefixedText(); |
||
195 | if ( !isset( $options['target'] ) ) { |
||
196 | $options['target'] = ''; |
||
197 | } else { |
||
198 | $options['target'] = str_replace( '_', ' ', $options['target'] ); |
||
199 | } |
||
200 | |||
201 | if ( !isset( $options['namespace'] ) ) { |
||
202 | $options['namespace'] = ''; |
||
203 | } |
||
204 | |||
205 | if ( !isset( $options['contribs'] ) ) { |
||
206 | $options['contribs'] = 'user'; |
||
207 | } |
||
208 | |||
209 | if ( $options['contribs'] == 'newbie' ) { |
||
210 | $options['target'] = ''; |
||
211 | } |
||
212 | |||
213 | $f = Xml::openElement( 'form', [ 'method' => 'get', 'action' => wfScript() ] ); |
||
214 | |||
215 | foreach ( $options as $name => $value ) { |
||
216 | if ( in_array( $name, [ 'namespace', 'target', 'contribs' ] ) ) { |
||
217 | continue; |
||
218 | } |
||
219 | $f .= "\t" . Html::hidden( $name, $value ) . "\n"; |
||
220 | } |
||
221 | |||
222 | $this->getOutput()->addModules( 'mediawiki.userSuggest' ); |
||
223 | |||
224 | $f .= Xml::openElement( 'fieldset' ); |
||
225 | $f .= Xml::element( 'legend', [], $this->msg( 'sp-contributions-search' )->text() ); |
||
226 | $f .= Xml::tags( |
||
227 | 'label', |
||
228 | [ 'for' => 'target' ], |
||
229 | $this->msg( 'sp-contributions-username' )->parse() |
||
230 | ) . ' '; |
||
231 | $f .= Html::input( |
||
232 | 'target', |
||
233 | $options['target'], |
||
234 | 'text', |
||
235 | [ |
||
236 | 'size' => '20', |
||
237 | 'required' => '', |
||
238 | 'class' => [ |
||
239 | 'mw-autocomplete-user', // used by mediawiki.userSuggest |
||
240 | ], |
||
241 | ] + ( $options['target'] ? [] : [ 'autofocus' ] ) |
||
242 | ) . ' '; |
||
243 | $f .= Html::namespaceSelector( |
||
244 | [ |
||
245 | 'selected' => $options['namespace'], |
||
246 | 'all' => '', |
||
247 | 'label' => $this->msg( 'namespace' )->text() |
||
248 | ], |
||
249 | [ |
||
250 | 'name' => 'namespace', |
||
251 | 'id' => 'namespace', |
||
252 | 'class' => 'namespaceselector', |
||
253 | ] |
||
254 | ) . ' '; |
||
255 | $f .= Xml::submitButton( $this->msg( 'sp-contributions-submit' )->text() ); |
||
256 | $f .= Xml::closeElement( 'fieldset' ); |
||
257 | $f .= Xml::closeElement( 'form' ); |
||
258 | |||
259 | return $f; |
||
260 | } |
||
261 | |||
262 | /** |
||
263 | * Return an array of subpages beginning with $search that this special page will accept. |
||
264 | * |
||
265 | * @param string $search Prefix to search for |
||
266 | * @param int $limit Maximum number of results to return (usually 10) |
||
267 | * @param int $offset Number of results to skip (usually 0) |
||
268 | * @return string[] Matching subpages |
||
269 | */ |
||
270 | View Code Duplication | public function prefixSearchSubpages( $search, $limit, $offset ) { |
|
279 | |||
280 | protected function getGroupName() { |
||
283 | } |
||
284 |
This function has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.