Conditions | 4 |
Paths | 2 |
Total Lines | 72 |
Code Lines | 53 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
43 | public function execute( $par ) { |
||
44 | $this->setHeaders(); |
||
45 | $this->outputHeader(); |
||
46 | $out = $this->getOutput(); |
||
47 | $lang = $this->getLanguage(); |
||
48 | $out->setPageTitle( $this->msg( 'ipblocklist' ) ); |
||
49 | $out->addModuleStyles( [ 'mediawiki.special' ] ); |
||
50 | |||
51 | $request = $this->getRequest(); |
||
52 | $par = $request->getVal( 'ip', $par ); |
||
53 | $this->target = trim( $request->getVal( 'wpTarget', $par ) ); |
||
54 | |||
55 | $this->options = $request->getArray( 'wpOptions', [] ); |
||
56 | |||
57 | $action = $request->getText( 'action' ); |
||
58 | |||
59 | if ( $action == 'unblock' || $action == 'submit' && $request->wasPosted() ) { |
||
60 | # B/C @since 1.18: Unblock interface is now at Special:Unblock |
||
61 | $title = SpecialPage::getTitleFor( 'Unblock', $this->target ); |
||
62 | $out->redirect( $title->getFullURL() ); |
||
63 | |||
64 | return; |
||
65 | } |
||
66 | |||
67 | # setup BlockListPager here to get the actual default Limit |
||
68 | $pager = $this->getBlockListPager(); |
||
69 | |||
70 | # Just show the block list |
||
71 | $fields = [ |
||
72 | 'Target' => [ |
||
73 | 'type' => 'user', |
||
74 | 'label-message' => 'ipaddressorusername', |
||
75 | 'tabindex' => '1', |
||
76 | 'size' => '45', |
||
77 | 'default' => $this->target, |
||
78 | ], |
||
79 | 'Options' => [ |
||
80 | 'type' => 'multiselect', |
||
81 | 'options-messages' => [ |
||
82 | 'blocklist-userblocks' => 'userblocks', |
||
83 | 'blocklist-tempblocks' => 'tempblocks', |
||
84 | 'blocklist-addressblocks' => 'addressblocks', |
||
85 | 'blocklist-rangeblocks' => 'rangeblocks', |
||
86 | ], |
||
87 | 'flatlist' => true, |
||
88 | ], |
||
89 | 'Limit' => [ |
||
90 | 'type' => 'limitselect', |
||
91 | 'label-message' => 'table_pager_limit_label', |
||
92 | 'options' => [ |
||
93 | $lang->formatNum( 20 ) => 20, |
||
94 | $lang->formatNum( 50 ) => 50, |
||
95 | $lang->formatNum( 100 ) => 100, |
||
96 | $lang->formatNum( 250 ) => 250, |
||
97 | $lang->formatNum( 500 ) => 500, |
||
98 | ], |
||
99 | 'name' => 'limit', |
||
100 | 'default' => $pager->getLimit(), |
||
101 | ], |
||
102 | ]; |
||
103 | $context = new DerivativeContext( $this->getContext() ); |
||
104 | $context->setTitle( $this->getPageTitle() ); // Remove subpage |
||
105 | $form = HTMLForm::factory( 'ooui', $fields, $context ); |
||
106 | $form->setMethod( 'get' ); |
||
107 | $form->setWrapperLegendMsg( 'ipblocklist-legend' ); |
||
108 | $form->setSubmitTextMsg( 'ipblocklist-submit' ); |
||
109 | $form->setSubmitProgressive(); |
||
110 | $form->prepareForm(); |
||
111 | |||
112 | $form->displayForm( '' ); |
||
113 | $this->showList( $pager ); |
||
114 | } |
||
115 | |||
224 |