| Conditions | 27 |
| Paths | > 20000 |
| Total Lines | 232 |
| 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 |
||
| 42 | public function show() |
||
| 43 | { |
||
| 44 | global $conf; |
||
| 45 | global $lang; |
||
| 46 | global $ID; |
||
| 47 | |||
| 48 | $first = $this->first; |
||
| 49 | $show_changes = $this->show_changes; |
||
| 50 | |||
| 51 | /* we need to get one additionally log entry to be able to |
||
| 52 | * decide if this is the last page or is there another one. |
||
| 53 | * This is the cheapest solution to get this information. |
||
| 54 | */ |
||
| 55 | $flags = 0; |
||
| 56 | if ($show_changes == 'mediafiles' && $conf['mediarevisions']) { |
||
| 57 | $flags = RECENTS_MEDIA_CHANGES; |
||
| 58 | } elseif ($show_changes == 'pages') { |
||
| 59 | $flags = 0; |
||
| 60 | } elseif ($conf['mediarevisions']) { |
||
| 61 | $show_changes = 'both'; |
||
| 62 | $flags = RECENTS_MEDIA_PAGES_MIXED; |
||
| 63 | } |
||
| 64 | |||
| 65 | $recents = getRecents($first, $conf['recent'] + 1, getNS($ID), $flags); |
||
|
|
|||
| 66 | if (count($recents) == 0 && $first != 0) { |
||
| 67 | $first = 0; |
||
| 68 | $recents = getRecents($first, $conf['recent'] + 1, getNS($ID), $flags); |
||
| 69 | } |
||
| 70 | |||
| 71 | $hasNext = false; |
||
| 72 | if (count($recents) > $conf['recent']) { |
||
| 73 | $hasNext = true; |
||
| 74 | array_pop($recents); // remove extra log entry |
||
| 75 | } |
||
| 76 | |||
| 77 | // print intro |
||
| 78 | print p_locale_xhtml('recent'); |
||
| 79 | |||
| 80 | if (getNS($ID) != '') { |
||
| 81 | print '<div class="level1"><p>' |
||
| 82 | . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) |
||
| 83 | .'</p></div>'; |
||
| 84 | } |
||
| 85 | |||
| 86 | // create the form |
||
| 87 | $form = new Form(['id' => 'dw__recent', 'method' => 'GET', 'action'=>wl($ID)]); |
||
| 88 | $form->addClass('changes'); |
||
| 89 | $form->addTagOpen('div')->addClass('no'); |
||
| 90 | $form->setHiddenField('sectok', null); |
||
| 91 | $form->setHiddenField('do', 'recent'); |
||
| 92 | $form->setHiddenField('id', $ID); |
||
| 93 | |||
| 94 | // show dropdown selector, whether include not only recent pages but also recent media files? |
||
| 95 | if ($conf['mediarevisions']) { |
||
| 96 | $form->addTagOpen('div')->addClass('changeType'); |
||
| 97 | $options = array( |
||
| 98 | 'pages' => $lang['pages_changes'], |
||
| 99 | 'mediafiles' => $lang['media_changes'], |
||
| 100 | 'both' => $lang['both_changes'], |
||
| 101 | ); |
||
| 102 | $form->addDropdown('show_changes', $options, $lang['changes_type']) |
||
| 103 | ->val($show_changes)->addClass('quickselect'); |
||
| 104 | $form->addButton('do[recent]', $lang['btn_apply'])->attr('type','submit'); |
||
| 105 | $form->addTagClose('div'); |
||
| 106 | } |
||
| 107 | |||
| 108 | // start listing |
||
| 109 | $form->addTagOpen('ul'); |
||
| 110 | |||
| 111 | foreach ($recents as $recent) { |
||
| 112 | $date = dformat($recent['date']); |
||
| 113 | $class = ($recent['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) ? 'minor': ''; |
||
| 114 | |||
| 115 | $form->addTagOpen('li')->addClass($class); |
||
| 116 | $form->addTagOpen('div')->addClass('li'); |
||
| 117 | |||
| 118 | if (!empty($recent['media'])) { |
||
| 119 | $form->addHTML(media_printicon($recent['id'])); |
||
| 120 | } else { |
||
| 121 | $form->addTag('img')->attrs([ |
||
| 122 | 'src' => DOKU_BASE .'lib/images/fileicons/file.png', |
||
| 123 | 'alt' => $recent['id'] |
||
| 124 | ])->addClass('icon'); |
||
| 125 | } |
||
| 126 | $form->addHTML(' '); |
||
| 127 | |||
| 128 | $form->addTagOpen('span')->addClass('date'); |
||
| 129 | $form->addHTML($date); |
||
| 130 | $form->addTagClose('span'); |
||
| 131 | $form->addHTML(' '); |
||
| 132 | |||
| 133 | $diff = false; |
||
| 134 | $href = ''; |
||
| 135 | |||
| 136 | if (!empty($recent['media'])) { |
||
| 137 | $changelog = new MediaChangeLog($recent['id']); |
||
| 138 | $revs = $changelog->getRevisions(0, 1); |
||
| 139 | $diff = (count($revs) && file_exists(mediaFN($recent['id']))); |
||
| 140 | if ($diff) { |
||
| 141 | $href = media_managerURL( |
||
| 142 | array( |
||
| 143 | 'tab_details' => 'history', |
||
| 144 | 'mediado' => 'diff', |
||
| 145 | 'image' => $recent['id'], |
||
| 146 | 'ns' => getNS($recent['id']) |
||
| 147 | ), '&' |
||
| 148 | ); |
||
| 149 | } |
||
| 150 | } else { |
||
| 151 | $href = wl($recent['id'], "do=diff", false, '&'); |
||
| 152 | } |
||
| 153 | |||
| 154 | if (!empty($recent['media']) && !$diff) { |
||
| 155 | $form->addTag('img')->attrs([ |
||
| 156 | 'src' => DOKU_BASE .'lib/images/blank.gif', |
||
| 157 | 'width' => 15, |
||
| 158 | 'height' => 11, |
||
| 159 | 'alt' => '', |
||
| 160 | ]); |
||
| 161 | } else { |
||
| 162 | $form->addTagOpen('a')->attr('href', $href)->addClass('diff_link'); |
||
| 163 | $form->addTag('img')->attrs([ |
||
| 164 | 'src' => DOKU_BASE .'lib/images/diff.png', |
||
| 165 | 'width' => 15, |
||
| 166 | 'height' => 11, |
||
| 167 | 'title' => $lang['diff'], |
||
| 168 | 'alt' => $lang['diff'], |
||
| 169 | ]); |
||
| 170 | $form->addTagClose('a'); |
||
| 171 | } |
||
| 172 | $form->addHTML(' '); |
||
| 173 | |||
| 174 | if (!empty($recent['media'])) { |
||
| 175 | $href = media_managerURL( |
||
| 176 | array( |
||
| 177 | 'tab_details' => 'history', |
||
| 178 | 'image' => $recent['id'], |
||
| 179 | 'ns' => getNS($recent['id']) |
||
| 180 | ), '&' |
||
| 181 | ); |
||
| 182 | } else { |
||
| 183 | $href = wl($recent['id'], "do=revisions", false, '&'); |
||
| 184 | } |
||
| 185 | $form->addTagOpen('a')->attr('href', $href)->addClass('revisions_link'); |
||
| 186 | $form->addTag('img')->attrs([ |
||
| 187 | 'src' => DOKU_BASE .'lib/images/history.png', |
||
| 188 | 'width' => 12, |
||
| 189 | 'height' => 14, |
||
| 190 | 'title' => $lang['btn_revs'], |
||
| 191 | 'alt' => $lang['btn_revs'] |
||
| 192 | ]); |
||
| 193 | $form->addTagClose('a'); |
||
| 194 | $form->addHTML(' '); |
||
| 195 | |||
| 196 | if (!empty($recent['media'])) { |
||
| 197 | $href = media_managerURL( |
||
| 198 | array( |
||
| 199 | 'tab_details' => 'view', |
||
| 200 | 'image' => $recent['id'], |
||
| 201 | 'ns' => getNS($recent['id']) |
||
| 202 | ), '&' |
||
| 203 | ); |
||
| 204 | $class = file_exists(mediaFN($recent['id'])) ? 'wikilink1' : 'wikilink2'; |
||
| 205 | $form->addTagOpen('a')->attr('href', $href)->addClass($class); |
||
| 206 | $form->addHTML($recent['id']); |
||
| 207 | $form->addTagClose('a'); |
||
| 208 | } else { |
||
| 209 | $form->addHTML(html_wikilink(':'. $recent['id'], useHeading('navigation') ? null : $recent['id'])); |
||
| 210 | } |
||
| 211 | $form->addTagOpen('span')->addClass('sum'); |
||
| 212 | $form->addHTML(' – '. hsc($recent['sum'])); |
||
| 213 | $form->addTagClose('span'); |
||
| 214 | |||
| 215 | $form->addTagOPen('span')->addClass('user'); |
||
| 216 | if ($recent['user']) { |
||
| 217 | $form->addHTML('<bdi>'. editorinfo($recent['user']) .'</bdi>'); |
||
| 218 | if (auth_ismanager()) { |
||
| 219 | $form->addHTML(' <bdo dir="ltr">('. $recent['ip'] .')</bdo>'); |
||
| 220 | } |
||
| 221 | } else { |
||
| 222 | $form->addHTML('<bdo dir="ltr">'. $recent['ip'] .'</bdo>'); |
||
| 223 | } |
||
| 224 | $form->addTagClose('span'); |
||
| 225 | $form->addHTML(' '); |
||
| 226 | |||
| 227 | $form->addHTML(html_sizechange($recent['sizechange'])); |
||
| 228 | |||
| 229 | $form->addTagClose('div'); |
||
| 230 | $form->addTagClose('li'); |
||
| 231 | } |
||
| 232 | |||
| 233 | $form->addTagClose('ul'); |
||
| 234 | |||
| 235 | // provide navigation for pagenated cecent list (of pages and/or media files) |
||
| 236 | $form->addTagOpen('div')->addClass('pagenav'); |
||
| 237 | $last = $first + $conf['recent']; |
||
| 238 | if ($first > 0) { |
||
| 239 | $first = $first - $conf['recent']; |
||
| 240 | if ($first < 0) $first = 0; |
||
| 241 | $form->addTagOpen('div')->addClass('pagenav-prev'); |
||
| 242 | $form->addTagOpen('button')->attrs([ |
||
| 243 | 'type' => 'submit', |
||
| 244 | 'name' => 'first['. $first .']', |
||
| 245 | 'accesskey' => 'n', |
||
| 246 | 'title' => $lang['btn_newer'] .' [N]', |
||
| 247 | ])->addClass('button show'); |
||
| 248 | $form->addHTML($lang['btn_newer']); |
||
| 249 | $form->addTagClose('button'); |
||
| 250 | $form->addTagClose('div'); |
||
| 251 | } |
||
| 252 | if ($hasNext) { |
||
| 253 | $form->addTagOpen('div')->addClass('pagenav-next'); |
||
| 254 | $form->addTagOpen('button')->attrs([ |
||
| 255 | 'type' => 'submit', |
||
| 256 | 'name' => 'first['. $last .']', |
||
| 257 | 'accesskey' => 'p', |
||
| 258 | 'title' => $lang['btn_older'] .' [P]', |
||
| 259 | ])->addClass('button show'); |
||
| 260 | $form->addHTML($lang['btn_older']); |
||
| 261 | $form->addTagClose('button'); |
||
| 262 | $form->addTagClose('div'); |
||
| 263 | } |
||
| 264 | $form->addTagClose('div'); |
||
| 265 | |||
| 266 | $form->addTagClose('div'); // close div class=no |
||
| 267 | |||
| 268 | // emit HTML_CRECENTFORM_OUTPUT event |
||
| 269 | Event::createAndTrigger('HTML_RECENTFORM_OUTPUT', $form, null, false); |
||
| 270 | print $form->toHTML(); |
||
| 271 | |||
| 272 | print DOKU_LF; |
||
| 273 | } |
||
| 274 | |||
| 276 |