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