Skip to content
This repository was archived by the owner on May 25, 2021. It is now read-only.

Commit 6039cb2

Browse files
committed
Initial commit
+ Added SpecialReport.php to report a revision + Added SpecialHandleReports.php to handle reports + Added Report.class.php for hooks + Added LICENSE and README.md for obvious reasons + Added i18n directory for i18n + Added sql directory for the one SQL file + Added resources directory for the one CSS file + Added extension.json for extension registration
0 parents  commit 6039cb2

File tree

11 files changed

+1315
-0
lines changed

11 files changed

+1315
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.py
2+

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Report
2+
3+
Report is an extension that, very simply, allows reporting revisions, hence the name.
4+
5+
## Installation
6+
7+
Run the following commands:
8+
```
9+
cd extensions
10+
git clone https://github.com/Kenny2github/Report.git
11+
```
12+
Then add the following line to your LocalSettings.php:
13+
```php
14+
wfLoadExtension( 'Report' );
15+
```
16+
17+
## Usage
18+
19+
Once it's installed, it's in use! The extension adds links next to every revision for reporting them, all of which lead to Special:Report.
20+
21+
For admins, simply navigate to Special:HandleReports to view reports that need handling.

Report.class.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
class ReportHooks {
4+
5+
function onLoadExtensionSchemaUpdates( $updater ) {
6+
$updater->addExtensionTable( 'report_reports',
7+
__DIR__ . '/sql/table.sql' );
8+
return true;
9+
}
10+
11+
public static function insertReportLink( $rev, &$links, $oldRev, $user ) {
12+
if ( $user->isAllowed( 'report' ) && !$user->isBlocked() ) {
13+
$links[] = self::generateReportElement( $rev->getID() );
14+
}
15+
}
16+
17+
protected static function generateReportElement( $id ) {
18+
global $wgUser;
19+
$dbr = wfGetDB( DB_REPLICA );
20+
if ($dbr->selectRow( 'report_reports', [ 'report_id' ], [
21+
'report_revid' => $id,
22+
'report_user' => $wgUser->getId()
23+
], __METHOD__ )) {
24+
return Html::element( 'span', [ 'class' => 'mw-report-reported' ],
25+
wfMessage( 'report-reported' )->escaped()
26+
);
27+
} else {
28+
return Html::element( 'a', [
29+
'class' => 'mw-report-report-link',
30+
'href' => SpecialPage::getTitleFor( 'Report', $id )->getLocalURL(),
31+
], wfMessage( 'report-report' )->escaped() );
32+
}
33+
}
34+
35+
public static function reportsAwaitingNotice( &$out, &$skin ) {
36+
$context = $out->getContext();
37+
if ( !$context->getUser()->isAllowed( 'handle-reports' ) ) {
38+
return true;
39+
}
40+
$title = $context->getTitle();
41+
if ( !($title->isSpecial( 'Recentchanges' ) || $title->isSpecial( 'Watchlist' )) ) {
42+
return true;
43+
}
44+
$dbr = wfGetDB( DB_REPLICA );
45+
if (($count = $dbr->selectRowCount( 'report_reports', '*', [
46+
'report_handled != 1',
47+
], __METHOD__)) > 0) {
48+
$out->prependHtml(Html::rawElement('div', [ 'id' => 'mw-report-reports-awaiting' ],
49+
wfMessage( 'report-reports-awaiting', Html::rawElement('a', [
50+
'href' => SpecialPage::getTitleFor( 'HandleReports' )->getLocalURL()
51+
], wfMessage( 'report-reports-awaiting-linktext', $count )->escaped()), $count )->text()));
52+
$out->addModules( 'ext.report' );
53+
}
54+
return true;
55+
}
56+
57+
}

SpecialHandleReports.php

Lines changed: 262 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
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

Comments
 (0)