| Conditions | 16 |
| Paths | 22 |
| Total Lines | 104 |
| Code Lines | 56 |
| 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 |
||
| 107 | public static function formatDiffRow( $title, $oldid, $newid, $timestamp, |
||
| 108 | $comment, $actiontext = '' |
||
| 109 | ) { |
||
| 110 | global $wgFeedDiffCutoff, $wgLang; |
||
| 111 | |||
| 112 | // log entries |
||
| 113 | $completeText = '<p>' . implode( ' ', |
||
| 114 | array_filter( |
||
| 115 | [ |
||
| 116 | $actiontext, |
||
| 117 | Linker::formatComment( $comment ) ] ) ) . "</p>\n"; |
||
| 118 | |||
| 119 | // NOTE: Check permissions for anonymous users, not current user. |
||
| 120 | // No "privileged" version should end up in the cache. |
||
| 121 | // Most feed readers will not log in anyway. |
||
| 122 | $anon = new User(); |
||
| 123 | $accErrors = $title->getUserPermissionsErrors( 'read', $anon, true ); |
||
| 124 | |||
| 125 | // Can't diff special pages, unreadable pages or pages with no new revision |
||
| 126 | // to compare against: just return the text. |
||
| 127 | if ( $title->getNamespace() < 0 || $accErrors || !$newid ) { |
||
| 128 | return $completeText; |
||
| 129 | } |
||
| 130 | |||
| 131 | if ( $oldid ) { |
||
| 132 | |||
| 133 | # $diffText = $de->getDiff( wfMessage( 'revisionasof', |
||
| 134 | # $wgLang->timeanddate( $timestamp ), |
||
| 135 | # $wgLang->date( $timestamp ), |
||
| 136 | # $wgLang->time( $timestamp ) )->text(), |
||
| 137 | # wfMessage( 'currentrev' )->text() ); |
||
| 138 | |||
| 139 | $diffText = ''; |
||
| 140 | // Don't bother generating the diff if we won't be able to show it |
||
| 141 | if ( $wgFeedDiffCutoff > 0 ) { |
||
| 142 | $rev = Revision::newFromId( $oldid ); |
||
| 143 | |||
| 144 | if ( !$rev ) { |
||
| 145 | $diffText = false; |
||
| 146 | } else { |
||
| 147 | $context = clone RequestContext::getMain(); |
||
| 148 | $context->setTitle( $title ); |
||
| 149 | |||
| 150 | $contentHandler = $rev->getContentHandler(); |
||
| 151 | $de = $contentHandler->createDifferenceEngine( $context, $oldid, $newid ); |
||
| 152 | $diffText = $de->getDiff( |
||
| 153 | wfMessage( 'previousrevision' )->text(), // hack |
||
| 154 | wfMessage( 'revisionasof', |
||
| 155 | $wgLang->timeanddate( $timestamp ), |
||
| 156 | $wgLang->date( $timestamp ), |
||
| 157 | $wgLang->time( $timestamp ) )->text() ); |
||
| 158 | } |
||
| 159 | } |
||
| 160 | |||
| 161 | if ( $wgFeedDiffCutoff <= 0 || ( strlen( $diffText ) > $wgFeedDiffCutoff ) ) { |
||
| 162 | // Omit large diffs |
||
| 163 | $diffText = self::getDiffLink( $title, $newid, $oldid ); |
||
| 164 | } elseif ( $diffText === false ) { |
||
| 165 | // Error in diff engine, probably a missing revision |
||
| 166 | $diffText = "<p>Can't load revision $newid</p>"; |
||
| 167 | } else { |
||
| 168 | // Diff output fine, clean up any illegal UTF-8 |
||
| 169 | $diffText = UtfNormal\Validator::cleanUp( $diffText ); |
||
| 170 | $diffText = self::applyDiffStyle( $diffText ); |
||
| 171 | } |
||
| 172 | } else { |
||
| 173 | $rev = Revision::newFromId( $newid ); |
||
| 174 | if ( $wgFeedDiffCutoff <= 0 || is_null( $rev ) ) { |
||
| 175 | $newContent = ContentHandler::getForTitle( $title )->makeEmptyContent(); |
||
| 176 | } else { |
||
| 177 | $newContent = $rev->getContent(); |
||
| 178 | } |
||
| 179 | |||
| 180 | if ( $newContent instanceof TextContent ) { |
||
| 181 | // only textual content has a "source view". |
||
| 182 | $text = $newContent->getNativeData(); |
||
| 183 | |||
| 184 | if ( $wgFeedDiffCutoff <= 0 || strlen( $text ) > $wgFeedDiffCutoff ) { |
||
| 185 | $html = null; |
||
| 186 | } else { |
||
| 187 | $html = nl2br( htmlspecialchars( $text ) ); |
||
| 188 | } |
||
| 189 | } else { |
||
| 190 | // XXX: we could get an HTML representation of the content via getParserOutput, but that may |
||
| 191 | // contain JS magic and generally may not be suitable for inclusion in a feed. |
||
| 192 | // Perhaps Content should have a getDescriptiveHtml method and/or a getSourceText method. |
||
| 193 | // Compare also ApiFeedContributions::feedItemDesc |
||
| 194 | $html = null; |
||
| 195 | } |
||
| 196 | |||
| 197 | if ( $html === null ) { |
||
| 198 | |||
| 199 | // Omit large new page diffs, bug 29110 |
||
| 200 | // Also use diff link for non-textual content |
||
| 201 | $diffText = self::getDiffLink( $title, $newid ); |
||
| 202 | } else { |
||
| 203 | $diffText = '<p><b>' . wfMessage( 'newpage' )->text() . '</b></p>' . |
||
| 204 | '<div>' . $html . '</div>'; |
||
| 205 | } |
||
| 206 | } |
||
| 207 | $completeText .= $diffText; |
||
| 208 | |||
| 209 | return $completeText; |
||
| 210 | } |
||
| 211 | |||
| 268 |