| Conditions | 16 |
| Paths | 6145 |
| Total Lines | 100 |
| Code Lines | 71 |
| 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 |
||
| 40 | public function execute( $par ) { |
||
| 41 | $this->setHeaders(); |
||
| 42 | $this->outputHeader(); |
||
| 43 | |||
| 44 | $out = $this->getOutput(); |
||
| 45 | $out->addModuleStyles( 'mediawiki.special' ); |
||
| 46 | |||
| 47 | $out->wrapWikiMsg( "<div class=\"mw-listgrouprights-key\">\n$1\n</div>", 'listgrouprights-key' ); |
||
| 48 | |||
| 49 | $out->addHTML( |
||
| 50 | Xml::openElement( 'table', [ 'class' => 'wikitable mw-listgrouprights-table' ] ) . |
||
| 51 | '<tr>' . |
||
| 52 | Xml::element( 'th', null, $this->msg( 'listgrouprights-group' )->text() ) . |
||
| 53 | Xml::element( 'th', null, $this->msg( 'listgrouprights-rights' )->text() ) . |
||
| 54 | '</tr>' |
||
| 55 | ); |
||
| 56 | |||
| 57 | $config = $this->getConfig(); |
||
| 58 | $groupPermissions = $config->get( 'GroupPermissions' ); |
||
| 59 | $revokePermissions = $config->get( 'RevokePermissions' ); |
||
| 60 | $addGroups = $config->get( 'AddGroups' ); |
||
| 61 | $removeGroups = $config->get( 'RemoveGroups' ); |
||
| 62 | $groupsAddToSelf = $config->get( 'GroupsAddToSelf' ); |
||
| 63 | $groupsRemoveFromSelf = $config->get( 'GroupsRemoveFromSelf' ); |
||
| 64 | $allGroups = array_unique( array_merge( |
||
| 65 | array_keys( $groupPermissions ), |
||
| 66 | array_keys( $revokePermissions ), |
||
| 67 | array_keys( $addGroups ), |
||
| 68 | array_keys( $removeGroups ), |
||
| 69 | array_keys( $groupsAddToSelf ), |
||
| 70 | array_keys( $groupsRemoveFromSelf ) |
||
| 71 | ) ); |
||
| 72 | asort( $allGroups ); |
||
| 73 | |||
| 74 | foreach ( $allGroups as $group ) { |
||
| 75 | $permissions = isset( $groupPermissions[$group] ) |
||
| 76 | ? $groupPermissions[$group] |
||
| 77 | : []; |
||
| 78 | $groupname = ( $group == '*' ) // Replace * with a more descriptive groupname |
||
| 79 | ? 'all' |
||
| 80 | : $group; |
||
| 81 | |||
| 82 | $msg = $this->msg( 'group-' . $groupname ); |
||
| 83 | $groupnameLocalized = !$msg->isBlank() ? $msg->text() : $groupname; |
||
| 84 | |||
| 85 | $msg = $this->msg( 'grouppage-' . $groupname )->inContentLanguage(); |
||
| 86 | $grouppageLocalized = !$msg->isBlank() ? |
||
| 87 | $msg->text() : |
||
| 88 | MWNamespace::getCanonicalName( NS_PROJECT ) . ':' . $groupname; |
||
| 89 | $grouppageLocalizedTitle = Title::newFromText( $grouppageLocalized ); |
||
| 90 | |||
| 91 | if ( $group == '*' || !$grouppageLocalizedTitle ) { |
||
| 92 | // Do not make a link for the generic * group or group with invalid group page |
||
| 93 | $grouppage = htmlspecialchars( $groupnameLocalized ); |
||
| 94 | } else { |
||
| 95 | $grouppage = Linker::link( |
||
| 96 | $grouppageLocalizedTitle, |
||
| 97 | htmlspecialchars( $groupnameLocalized ) |
||
| 98 | ); |
||
| 99 | } |
||
| 100 | |||
| 101 | if ( $group === 'user' ) { |
||
| 102 | // Link to Special:listusers for implicit group 'user' |
||
| 103 | $grouplink = '<br />' . Linker::linkKnown( |
||
| 104 | SpecialPage::getTitleFor( 'Listusers' ), |
||
| 105 | $this->msg( 'listgrouprights-members' )->escaped() |
||
| 106 | ); |
||
| 107 | } elseif ( !in_array( $group, $config->get( 'ImplicitGroups' ) ) ) { |
||
| 108 | $grouplink = '<br />' . Linker::linkKnown( |
||
| 109 | SpecialPage::getTitleFor( 'Listusers' ), |
||
| 110 | $this->msg( 'listgrouprights-members' )->escaped(), |
||
| 111 | [], |
||
| 112 | [ 'group' => $group ] |
||
| 113 | ); |
||
| 114 | } else { |
||
| 115 | // No link to Special:listusers for other implicit groups as they are unlistable |
||
| 116 | $grouplink = ''; |
||
| 117 | } |
||
| 118 | |||
| 119 | $revoke = isset( $revokePermissions[$group] ) ? $revokePermissions[$group] : []; |
||
| 120 | $addgroups = isset( $addGroups[$group] ) ? $addGroups[$group] : []; |
||
| 121 | $removegroups = isset( $removeGroups[$group] ) ? $removeGroups[$group] : []; |
||
| 122 | $addgroupsSelf = isset( $groupsAddToSelf[$group] ) ? $groupsAddToSelf[$group] : []; |
||
| 123 | $removegroupsSelf = isset( $groupsRemoveFromSelf[$group] ) |
||
| 124 | ? $groupsRemoveFromSelf[$group] |
||
| 125 | : []; |
||
| 126 | |||
| 127 | $id = $group == '*' ? false : Sanitizer::escapeId( $group ); |
||
| 128 | $out->addHTML( Html::rawElement( 'tr', [ 'id' => $id ], " |
||
| 129 | <td>$grouppage$grouplink</td> |
||
| 130 | <td>" . |
||
| 131 | $this->formatPermissions( $permissions, $revoke, $addgroups, $removegroups, |
||
| 132 | $addgroupsSelf, $removegroupsSelf ) . |
||
| 133 | '</td> |
||
| 134 | ' |
||
| 135 | ) ); |
||
| 136 | } |
||
| 137 | $out->addHTML( Xml::closeElement( 'table' ) ); |
||
| 138 | $this->outputNamespaceProtectionInfo(); |
||
| 139 | } |
||
| 140 | |||
| 295 |