|
| 1 | +<?php |
| 2 | + |
| 3 | +class SpecialHandleReports extends SpecialPage { |
| 4 | + |
| 5 | + public function __construct() { |
| 6 | + parent::__construct( 'HandleReports', 'handle-reports' ); |
| 7 | + } |
| 8 | + |
| 9 | + public function execute( $par ) { |
| 10 | + global $wgScriptPath; |
| 11 | + $out = $this->getOutput(); |
| 12 | + $out->addModuleStyles( 'ext.report' ); |
| 13 | + $out->setPageTitle( wfMessage('report-handling-title')->escaped() ); |
| 14 | + $out->setIndexPolicy( 'noindex' ); |
| 15 | + $user = $this->getUser(); |
| 16 | + if ( !$this->userCanExecute( $user ) ) { |
| 17 | + $this->displayRestrictionError(); |
| 18 | + return; |
| 19 | + } |
| 20 | + $dbr = wfGetDB( DB_REPLICA ); |
| 21 | + if (!ctype_digit( $par )) { |
| 22 | + if ( strtolower( $par ) !== strtolower( wfMessage( 'report-handled' )->text() ) ) { |
| 23 | + $out->addHTML(Html::rawElement('a', |
| 24 | + [ 'href' => SpecialPage::getTitleFor( 'HandleReports', wfMessage('report-handled')->text() )->getLocalURL() ], |
| 25 | + wfMessage( 'report-handling-view-handled' )->escaped() |
| 26 | + )); |
| 27 | + } else { |
| 28 | + $out->addHTML(Html::rawElement('a', |
| 29 | + [ 'href' => SpecialPage::getTitleFor( 'HandleReports' )->getLocalURL() ], |
| 30 | + wfMessage( 'report-handling-view-nothandled' )->escaped() |
| 31 | + )); |
| 32 | + } |
| 33 | + $out->addHTML(Html::openElement( |
| 34 | + 'table', |
| 35 | + [ 'class' => 'mw-report-handling-list', 'width' => '100%' ] |
| 36 | + )); |
| 37 | + $out->addHTML(Html::openElement('tr')); |
| 38 | + $out->addHTML(Html::rawElement( |
| 39 | + 'th', [], |
| 40 | + wfMessage( 'report-handling-th-timestamp' )->escaped() |
| 41 | + )); |
| 42 | + $out->addHTML(Html::rawElement( |
| 43 | + 'th', [], |
| 44 | + wfMessage( 'report-handling-th-reason' )->escaped() |
| 45 | + )); |
| 46 | + $out->addHTML(Html::rawElement( |
| 47 | + 'th', [], |
| 48 | + wfMessage( 'report-handling-th-user' )->escaped() |
| 49 | + )); |
| 50 | + $out->addHTML(Html::rawElement( |
| 51 | + 'th', [], |
| 52 | + wfMessage( 'report-handling-th-revid' )->escaped() |
| 53 | + )); |
| 54 | + $out->addHTML(Html::rawElement('th', [], |
| 55 | + wfMessage( 'report-handling-view-report' )->escaped() |
| 56 | + )); |
| 57 | + $out->addHTML(Html::closeElement('tr')); |
| 58 | + if ( strtolower( $par ) === strtolower( wfMessage( 'report-handled' )->text() ) ) { |
| 59 | + $conds = [ 'report_handled' => 1 ]; |
| 60 | + } else { |
| 61 | + $conds = [ 'report_handled != 1' ]; |
| 62 | + } |
| 63 | + foreach ($dbr->select( 'report_reports', [ |
| 64 | + 'report_id', |
| 65 | + 'report_reason', |
| 66 | + 'report_user', |
| 67 | + 'report_revid', |
| 68 | + 'report_timestamp', |
| 69 | + ], $conds, __METHOD__) |
| 70 | + as $row) { |
| 71 | + $out->addHTML(Html::openElement('tr')); |
| 72 | + $out->addHTML(Html::rawElement('td', [], |
| 73 | + wfTimestamp( TS_ISO_8601, $row->report_timestamp ) |
| 74 | + )); |
| 75 | + $out->addHTML(Html::rawElement('td', [], Html::rawElement( |
| 76 | + 'textarea', |
| 77 | + [ 'readonly' => '', |
| 78 | + 'class' => 'mw-report-handling-textarea' ], |
| 79 | + htmlspecialchars($row->report_reason) |
| 80 | + ))); |
| 81 | + $user = User::newFromId($row->report_user); |
| 82 | + $out->addHTML(Html::rawElement('td', [], Html::rawElement('a', |
| 83 | + [ 'href' => $user->getUserPage()->getLocalURL() ], |
| 84 | + htmlspecialchars($user->getName()) |
| 85 | + ))); |
| 86 | + $out->addHTML(Html::rawElement('td', [], Html::rawElement('a', |
| 87 | + [ 'href' => $wgScriptPath . '/index.php?oldid=' . $row->report_revid ], |
| 88 | + htmlspecialchars($row->report_revid) |
| 89 | + ))); |
| 90 | + $out->addHTML(Html::rawElement('td', [], Html::rawElement('a', |
| 91 | + [ 'href' => SpecialPage::getTitleFor( 'HandleReports', $row->report_id )->getLocalURL() ], |
| 92 | + wfMessage( 'report-handling-view-report' )->escaped() |
| 93 | + ))); |
| 94 | + $out->addHTML(Html::closeElement('tr')); |
| 95 | + } |
| 96 | + $out->addHTML(Html::closeElement('table')); |
| 97 | + } else { |
| 98 | + if ($this->getRequest()->wasPosted()) { |
| 99 | + return $this->onPost( $par, $out, $user ); |
| 100 | + } |
| 101 | + $dbr = wfGetDB( DB_REPLICA ); |
| 102 | + if ($query = $dbr->selectRow( 'report_reports', [ |
| 103 | + 'report_reason', |
| 104 | + 'report_user', |
| 105 | + 'report_revid', |
| 106 | + 'report_handled', |
| 107 | + 'report_handled_by' |
| 108 | + ], [ 'report_id' => (int)$par ], |
| 109 | + __METHOD__)) { |
| 110 | + $out->addHTML(Html::openElement('fieldset')); |
| 111 | + $out->addHTML(Html::rawElement('legend', [], |
| 112 | + wfMessage( 'report-handling-th-reason' )->escaped() |
| 113 | + )); |
| 114 | + $out->addHTML(Html::rawElement( |
| 115 | + 'textarea', |
| 116 | + [ 'readonly' => '', 'class' => 'mw-report-handling-textarea' ], |
| 117 | + htmlspecialchars($query->report_reason) |
| 118 | + )); |
| 119 | + $user = User::newFromId($query->report_user); |
| 120 | + $out->addHTML(Html::closeElement('fieldset')); |
| 121 | + $out->addHTML(Html::openElement('fieldset')); |
| 122 | + $out->addHTML(Html::rawElement('legend', [], |
| 123 | + wfMessage( 'report-handling-info' )->escaped() |
| 124 | + )); |
| 125 | + $out->addHTML(Html::rawElement('b', [], |
| 126 | + wfMessage( 'report-handling-username' )->escaped() |
| 127 | + )); |
| 128 | + $out->addHTML(Html::rawElement('a', |
| 129 | + [ 'href' => $user->getUserPage()->getLocalURL() ], |
| 130 | + $user->getName() |
| 131 | + )); |
| 132 | + $out->addHTML(Html::rawElement('br')); |
| 133 | + $out->addHTML(Html::rawElement('b', [], |
| 134 | + wfMessage( 'report-handling-revid' )->escaped() |
| 135 | + )); |
| 136 | + $out->addHTML(Html::rawElement('td', [], Html::rawElement('a', |
| 137 | + [ 'href' => $wgScriptPath . '/index.php?oldid=' . $query->report_revid ], |
| 138 | + htmlspecialchars($query->report_revid) |
| 139 | + ))); |
| 140 | + $out->addHTML(Html::closeElement('fieldset')); |
| 141 | + $out->addHTML(Html::openElement('fieldset')); |
| 142 | + $out->addHTML(Html::rawElement('legend', [], |
| 143 | + wfMessage( 'report-handling' )->escaped() |
| 144 | + )); |
| 145 | + // <table width="100%"> |
| 146 | + $out->addHTML(Html::openElement('table', [ 'width' => '100%' ])); |
| 147 | + // <tr> |
| 148 | + $out->addHTML(Html::openElement('tr')); |
| 149 | + // <th>...</th> |
| 150 | + $out->addHTML(Html::rawElement('th', [], |
| 151 | + wfMessage( 'report-handling-mark-handled' )->escaped() |
| 152 | + )); |
| 153 | + // <th>...</th> |
| 154 | + $out->addHTML(Html::rawElement('th', [], |
| 155 | + wfMessage( 'report-handling-handledq' )->escaped() |
| 156 | + )); |
| 157 | + // <th>...</th> |
| 158 | + $out->addHTML(Html::rawElement('th', [], |
| 159 | + wfMessage( 'report-handling-handled-by' )->escaped() |
| 160 | + )); |
| 161 | + // <th>...</th> |
| 162 | + $out->addHTML(Html::rawElement('th', [], |
| 163 | + wfMessage( 'report-handling-th-timestamp' )->escaped() |
| 164 | + )); |
| 165 | + // </tr> |
| 166 | + $out->addHTML(Html::closeElement('tr')); |
| 167 | + // <tr> |
| 168 | + $out->addHTML(Html::openElement('tr')); |
| 169 | + // <td> |
| 170 | + $out->addHTML(Html::openElement('td')); |
| 171 | + // <form method="POST"> |
| 172 | + $out->addHTML(Html::openElement('form', [ 'method' => 'POST' ])); |
| 173 | + // <input type="hidden" name="handled" value="1" /> |
| 174 | + $out->addHTML(Html::rawElement( |
| 175 | + 'input', |
| 176 | + [ 'type' => 'hidden', 'name' => 'handled', 'value' => '1' ] |
| 177 | + )); |
| 178 | + // <input type="hidden" name="token" value="..." /> |
| 179 | + $out->addHTML(Html::rawElement( |
| 180 | + 'input', |
| 181 | + [ 'type' => 'hidden', 'name' => 'token', 'value' => $user->getEditToken() ] |
| 182 | + )); |
| 183 | + // <input type="submit" value="..." /> |
| 184 | + $out->addHTML(Html::rawElement( |
| 185 | + 'input', |
| 186 | + [ 'type' => 'submit', 'value' => wfMessage( 'report-handling-mark-handled' )->escaped() ] |
| 187 | + )); |
| 188 | + // </form> |
| 189 | + $out->addHTML(Html::closeElement('form')); |
| 190 | + // </td> |
| 191 | + $out->addHTML(Html::closeElement('td')); |
| 192 | + // <td>...</td> |
| 193 | + $msgkey = 'report-handling-' . |
| 194 | + ($query->report_handled ? |
| 195 | + '' : |
| 196 | + 'not') . |
| 197 | + 'handled'; |
| 198 | + $out->addHTML(Html::rawElement('td', [], |
| 199 | + wfMessage( $msgkey )->escaped() |
| 200 | + )); |
| 201 | + // <td> |
| 202 | + $out->addHTML(Html::openElement('td')); |
| 203 | + if ($query->report_handled) { |
| 204 | + $handledby = User::newFromId($query->report_handled_by); |
| 205 | + // <a href="...">...</a> |
| 206 | + $out->addHTML(Html::rawElement('a', |
| 207 | + [ 'href' => $handledby->getUserPage() ], |
| 208 | + $handledby->getName() |
| 209 | + )); |
| 210 | + } else { |
| 211 | + // <span>...</span> |
| 212 | + $out->addHTML(Html::rawElement('span', [], |
| 213 | + wfMessage( 'report-handling-nothandled' )->escaped() |
| 214 | + )); |
| 215 | + } |
| 216 | + // </td> |
| 217 | + $out->addHTML(Html::closeElement('td')); |
| 218 | + // <td>...</td> |
| 219 | + $out->addHTML(Html::rawElement('td', [], |
| 220 | + ($query->report_handled ? |
| 221 | + wfTimestamp( TS_ISO_8601, $query->report_handled_timestamp ) : |
| 222 | + wfMessage( 'report-handling-nothandled' )->escaped()) |
| 223 | + )); |
| 224 | + // </tr> |
| 225 | + $out->addHTML(Html::closeElement('tr')); |
| 226 | + // </table> |
| 227 | + $out->addHTML(Html::closeElement('table')); |
| 228 | + } else { |
| 229 | + $out->addHTML(Html::rawElement( |
| 230 | + 'div', |
| 231 | + [ 'class' => 'error' ], |
| 232 | + wfMessage( 'report-error-invalid-repid' )->escaped() |
| 233 | + )); |
| 234 | + } |
| 235 | + } |
| 236 | + } |
| 237 | + |
| 238 | + public function onPost( $par, $out, $user ) { |
| 239 | + if ($user->matchEditToken($this->getRequest()->getText( 'token' ))) { |
| 240 | + $dbw = wfGetDB( DB_MASTER ); |
| 241 | + $dbw->begin(); |
| 242 | + $dbw->update( 'report_reports', [ |
| 243 | + 'report_handled' => 1, |
| 244 | + 'report_handled_by' => $user->getId(), |
| 245 | + 'report_handled_by_text' => $user->getName(), |
| 246 | + 'report_handled_timestamp' => wfTimestampNow() |
| 247 | + ], [ 'report_id' => (int)$par ], __METHOD__ ); |
| 248 | + $dbw->commit(); |
| 249 | + $out->addHTML(Html::rawElement('div', [], |
| 250 | + wfMessage( 'report-has-been-handled' )->escaped() |
| 251 | + )); |
| 252 | + $out->addWikiMsg( 'returnto', '[[' . SpecialPage::getTitleFor( 'HandleReports' )->getPrefixedText() . ']]' ); |
| 253 | + } else { |
| 254 | + $out->addWikiMsg( 'sessionfailure' ); |
| 255 | + } |
| 256 | + } |
| 257 | + |
| 258 | + public function getGroupName() { |
| 259 | + return 'wiki'; |
| 260 | + } |
| 261 | + |
| 262 | +} |
0 commit comments