| Conditions | 19 |
| Paths | 1728 |
| Total Lines | 177 |
| 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 |
||
| 56 | public function show() |
||
| 57 | { |
||
| 58 | global $ID; |
||
| 59 | global $REV; |
||
| 60 | global $lang; |
||
| 61 | global $INPUT; |
||
| 62 | global $INFO; |
||
| 63 | $pagelog = new PageChangeLog($ID); |
||
| 64 | |||
| 65 | /* |
||
| 66 | * Determine requested revision(s) |
||
| 67 | */ |
||
| 68 | // we're trying to be clever here, revisions to compare can be either |
||
| 69 | // given as rev and rev2 parameters, with rev2 being optional. Or in an |
||
| 70 | // array in rev2. |
||
| 71 | $rev1 = $REV; |
||
| 72 | |||
| 73 | $rev2 = $INPUT->ref('rev2'); |
||
| 74 | if (is_array($rev2)) { |
||
| 75 | $rev1 = (int) $rev2[0]; |
||
| 76 | $rev2 = (int) $rev2[1]; |
||
| 77 | |||
| 78 | if (!$rev1) { |
||
| 79 | $rev1 = $rev2; |
||
| 80 | unset($rev2); |
||
| 81 | } |
||
| 82 | } else { |
||
| 83 | $rev2 = $INPUT->int('rev2'); |
||
| 84 | } |
||
| 85 | |||
| 86 | /* |
||
| 87 | * Determine left and right revision, its texts and the header |
||
| 88 | */ |
||
| 89 | $r_minor = ''; |
||
| 90 | $l_minor = ''; |
||
| 91 | |||
| 92 | if ($this->text) { // compare text to the most current revision |
||
| 93 | $l_rev = ''; |
||
| 94 | $l_text = rawWiki($ID, ''); |
||
| 95 | $l_head = '<a class="wikilink1" href="'. wl($ID) .'">' |
||
| 96 | . $ID .' '. dformat((int) @filemtime(wikiFN($ID))) .'</a> ' |
||
| 97 | . $lang['current']; |
||
| 98 | |||
| 99 | $r_rev = ''; |
||
| 100 | $r_text = cleanText($this->text); |
||
| 101 | $r_head = $lang['yours']; |
||
| 102 | } else { |
||
| 103 | if ($rev1 && isset($rev2) && $rev2) { // two specific revisions wanted |
||
| 104 | // make sure order is correct (older on the left) |
||
| 105 | if ($rev1 < $rev2) { |
||
| 106 | $l_rev = $rev1; |
||
| 107 | $r_rev = $rev2; |
||
| 108 | } else { |
||
| 109 | $l_rev = $rev2; |
||
| 110 | $r_rev = $rev1; |
||
| 111 | } |
||
| 112 | } elseif ($rev1) { // single revision given, compare to current |
||
| 113 | $r_rev = ''; |
||
| 114 | $l_rev = $rev1; |
||
| 115 | } else { // no revision was given, compare previous to current |
||
| 116 | $r_rev = ''; |
||
| 117 | $revs = $pagelog->getRevisions(0, 1); |
||
| 118 | $l_rev = $revs[0]; |
||
| 119 | $REV = $l_rev; // store revision back in $REV |
||
| 120 | } |
||
| 121 | |||
| 122 | // when both revisions are empty then the page was created just now |
||
| 123 | if (!$l_rev && !$r_rev) { |
||
| 124 | $l_text = ''; |
||
| 125 | } else { |
||
| 126 | $l_text = rawWiki($ID, $l_rev); |
||
| 127 | } |
||
| 128 | $r_text = rawWiki($ID, $r_rev); |
||
| 129 | |||
| 130 | list($l_head, $r_head, $l_minor, $r_minor) = $this->diffHead( |
||
| 131 | $l_rev, $r_rev, null, false, ($this->difftype == 'inline') |
||
| 132 | ); |
||
| 133 | } |
||
| 134 | |||
| 135 | /* |
||
| 136 | * Build navigation |
||
| 137 | */ |
||
| 138 | $l_nav = ''; |
||
| 139 | $r_nav = ''; |
||
| 140 | if (!$this->text) { |
||
| 141 | list($l_nav, $r_nav) = $this->diffNavigation($pagelog, $l_rev, $r_rev); |
||
| 142 | } |
||
| 143 | /* |
||
| 144 | * Create diff object and the formatter |
||
| 145 | */ |
||
| 146 | $diff = new \Diff(explode("\n", $l_text), explode("\n", $r_text)); |
||
| 147 | |||
| 148 | if ($this->difftype == 'inline') { |
||
| 149 | $diffformatter = new \InlineDiffFormatter(); |
||
| 150 | } else { |
||
| 151 | $diffformatter = new \TableDiffFormatter(); |
||
| 152 | } |
||
| 153 | /* |
||
| 154 | * Display intro |
||
| 155 | */ |
||
| 156 | if ($this->showIntro) print p_locale_xhtml('diff'); |
||
| 157 | |||
| 158 | /* |
||
| 159 | * Display type and exact reference |
||
| 160 | */ |
||
| 161 | if (!$this->text) { |
||
| 162 | print '<div class="diffoptions group">'; |
||
| 163 | |||
| 164 | // create the form to select difftype |
||
| 165 | $form = new Form(['action' => wl()]); |
||
| 166 | $form->setHiddenField('id', $ID); |
||
| 167 | $form->setHiddenField('rev2[0]', $l_rev); |
||
| 168 | $form->setHiddenField('rev2[1]', $r_rev); |
||
| 169 | $form->setHiddenField('do', 'diff'); |
||
| 170 | $options = array( |
||
| 171 | 'sidebyside' => $lang['diff_side'], |
||
| 172 | 'inline' => $lang['diff_inline'] |
||
| 173 | ); |
||
| 174 | $input = $form->addDropdown('difftype', $options, $lang['diff_type']) |
||
| 175 | ->val($this->difftype)->addClass('quickselect'); |
||
| 176 | $input->useInput(false); // inhibit prefillInput() during toHTML() process |
||
| 177 | $form->addButton('do[diff]', 'Go')->attr('type','submit'); |
||
| 178 | print $form->toHTML(); |
||
| 179 | |||
| 180 | print '<p>'; |
||
| 181 | // link to exactly this view FS#2835 |
||
| 182 | print $this->diffViewlink('difflink', $l_rev, ($r_rev ?: $INFO['currentrev'])); |
||
| 183 | print '</p>'; |
||
| 184 | |||
| 185 | print '</div>'; // .diffoptions |
||
| 186 | } |
||
| 187 | |||
| 188 | /* |
||
| 189 | * Display diff view table |
||
| 190 | */ |
||
| 191 | print '<div class="table">'; |
||
| 192 | print '<table class="diff diff_'. $this->difftype .'">'; |
||
| 193 | |||
| 194 | //navigation and header |
||
| 195 | if ($this->difftype == 'inline') { |
||
| 196 | if (!$this->text) { |
||
| 197 | print '<tr>' |
||
| 198 | . '<td class="diff-lineheader">-</td>' |
||
| 199 | . '<td class="diffnav">'. $l_nav .'</td>' |
||
| 200 | . '</tr>'; |
||
| 201 | print '<tr>' |
||
| 202 | . '<th class="diff-lineheader">-</th>' |
||
| 203 | . '<th '. $l_minor .'>'. $l_head .'</th>' |
||
| 204 | .'</tr>'; |
||
| 205 | } |
||
| 206 | print '<tr>' |
||
| 207 | . '<td class="diff-lineheader">+</td>' |
||
| 208 | . '<td class="diffnav">'. $r_nav .'</td>' |
||
| 209 | .'</tr>'; |
||
| 210 | print '<tr>' |
||
| 211 | . '<th class="diff-lineheader">+</th>' |
||
| 212 | . '<th '. $r_minor .'>'. $r_head .'</th>' |
||
| 213 | . '</tr>'; |
||
| 214 | } else { |
||
| 215 | if (!$this->text) { |
||
| 216 | print '<tr>' |
||
| 217 | . '<td colspan="2" class="diffnav">'. $l_nav .'</td>' |
||
| 218 | . '<td colspan="2" class="diffnav">'. $r_nav .'</td>' |
||
| 219 | . '</tr>'; |
||
| 220 | } |
||
| 221 | print '<tr>' |
||
| 222 | . '<th colspan="2" '. $l_minor .'>'. $l_head .'</th>' |
||
| 223 | . '<th colspan="2" '. $r_minor .'>'. $r_head .'</th>' |
||
| 224 | . '</tr>'; |
||
| 225 | } |
||
| 226 | |||
| 227 | //diff view |
||
| 228 | print $this->insertSoftbreaks($diffformatter->format($diff)); |
||
| 229 | |||
| 230 | print '</table>'; |
||
| 231 | print '</div>'; |
||
| 232 | } |
||
| 233 | |||
| 504 |