Index: trunk/extensions/Premoderation/install.php |
— | — | @@ -1,10 +0,0 @@ |
2 | | -<?php |
3 | | -/* |
4 | | - * Script for creating new database tables |
5 | | - */ |
6 | | - |
7 | | -$dir = dirname( __FILE__ ); |
8 | | -require_once ( $dir . '/../../maintenance/commandLine.inc' ); |
9 | | - |
10 | | -$dbw = wfGetDB( DB_MASTER ); |
11 | | -$dbw->sourceFile( $dir . '/db_tables.sql' ); |
\ No newline at end of file |
Index: trunk/extensions/Premoderation/SpecialPremoderation.php |
— | — | @@ -22,19 +22,17 @@ |
23 | 23 | if( !$wgUser->isAllowed( 'premoderation' ) ) { |
24 | 24 | $this->displayRestrictionError(); |
25 | 25 | return; |
| 26 | + } elseif( wfReadOnly() ) { |
| 27 | + $wgOut->readOnlyPage(); |
| 28 | + return; |
| 29 | + } elseif( $wgUser->isBlocked() ) { |
| 30 | + $wgOut->blockedPage(); |
| 31 | + return; |
26 | 32 | } |
27 | 33 | |
28 | | - $allowedActions = array( '', 'list', 'status' ); |
29 | | - |
30 | 34 | $params = array_values( explode( '/', $subpage ) ); |
31 | 35 | $action = array_shift( &$params ); |
32 | 36 | |
33 | | - if( !in_array( $action, $allowedActions ) ) { |
34 | | - $wgOut->setPageTitle( wfMsg( 'premoderation-manager-invalidaction' ) ); |
35 | | - $wgOut->addWikiMsg( 'premoderation-invalidaction' ); |
36 | | - return; |
37 | | - } |
38 | | - |
39 | 37 | if( $action == '' ) { |
40 | 38 | $action = 'list'; |
41 | 39 | } elseif( isset( $params ) ) { |
— | — | @@ -49,6 +47,10 @@ |
50 | 48 | case 'status': |
51 | 49 | ( $this->mPosted ) ? $this->performChanges() : $this->statusInterface(); |
52 | 50 | break; |
| 51 | + |
| 52 | + default: |
| 53 | + $wgOut->setPageTitle( wfMsg( 'premoderation-manager-invalidaction' ) ); |
| 54 | + $wgOut->addWikiMsg( 'premoderation-invalidaction' ); |
53 | 55 | } |
54 | 56 | } |
55 | 57 | |
— | — | @@ -61,9 +63,13 @@ |
62 | 64 | $dbr = wfGetDB( DB_SLAVE ); |
63 | 65 | $res = $dbr->select( |
64 | 66 | 'pm_queue', |
65 | | - array( 'pmq_id', 'pmq_page_ns', 'pmq_page_title', 'pmq_user', 'pmq_user_text', 'pmq_timestamp', |
66 | | - 'pmq_minor', 'pmq_summary', 'pmq_len', 'pmq_status', 'pmq_updated', 'pmq_updated_user_text' ), |
67 | | - '', __METHOD__, |
| 67 | + array( |
| 68 | + 'pmq_id', 'pmq_page_ns', 'pmq_page_title', 'pmq_user', 'pmq_user_text', |
| 69 | + 'pmq_timestamp', 'pmq_minor', 'pmq_summary', 'pmq_len', 'pmq_status', |
| 70 | + 'pmq_updated', 'pmq_updated_user_text' |
| 71 | + ), |
| 72 | + '', |
| 73 | + __METHOD__, |
68 | 74 | array( 'ORDER BY' => 'pmq_timestamp DESC', 'LIMIT' => 100 ) |
69 | 75 | ); |
70 | 76 | |
— | — | @@ -101,7 +107,8 @@ |
102 | 108 | } |
103 | 109 | |
104 | 110 | protected function getListTableHeader( $type ) { |
105 | | - return Xml::openElement( 'table', array( 'id' => 'prem-table-' . $type, 'class' => 'wikitable', 'style' => 'width: 90%' ) ) . |
| 111 | + return Xml::openElement( 'table', array( 'id' => 'prem-table-' . $type, |
| 112 | + 'class' => 'wikitable', 'style' => 'width: 90%' ) ) . |
106 | 113 | '<tr><th>' . wfMsg( 'premoderation-table-list-time' ) . '</th>' . |
107 | 114 | '<th>' . wfMsg( 'premoderation-table-list-user' ) . '</th>' . |
108 | 115 | '<th colspan="2">' . wfMsg( 'premoderation-table-list-title' ) . '</th>' . |
— | — | @@ -119,7 +126,8 @@ |
120 | 127 | '</td><td>' . ( $row['pmq_minor'] == 0 ? '' : ' ' . wfMsg( 'minoreditletter' ) ) . '</td>' . |
121 | 128 | '<td>' . $row['pmq_summary'] . '</td><td>' . '<a href="' . $articlePath . |
122 | 129 | 'Special:Premoderation/status/id/' . $row['pmq_id'] . '">' . |
123 | | - wfMessage( 'premoderation-status-' . $row['pmq_status'] . ( $row['pmq_updated_user_text'] ? '-changed' : '-added' ), |
| 130 | + wfMessage( 'premoderation-status-' . $row['pmq_status'] . |
| 131 | + ( $row['pmq_updated_user_text'] ? '-changed' : '-added' ), |
124 | 132 | array( $row['pmq_updated_user_text'] ) ) . |
125 | 133 | '</a></td></tr>'; |
126 | 134 | } |
— | — | @@ -139,7 +147,8 @@ |
140 | 148 | $res = $dbr->select( |
141 | 149 | 'pm_queue', |
142 | 150 | '*', |
143 | | - "pmq_id = '$id'", __METHOD__, |
| 151 | + "pmq_id = '$id'", |
| 152 | + __METHOD__, |
144 | 153 | array( 'LIMIT' => 1 ) |
145 | 154 | ); |
146 | 155 | $row = $dbr->fetchRow( $res ); |
— | — | @@ -153,7 +162,8 @@ |
154 | 163 | $wgOut->addWikiMsg( 'premoderation-status-intro' ); |
155 | 164 | |
156 | 165 | $wgOut->addHTML( '<h2>' . wfMsg( 'premoderation-status-info' ) . '</h2>' . |
157 | | - $this->getListTableHeader( 'status' ) . $this->formatListTableRow( $row ) . Xml::closeElement( 'table' ) ); |
| 166 | + $this->getListTableHeader( 'status' ) . $this->formatListTableRow( $row ) . |
| 167 | + Xml::closeElement( 'table' ) ); |
158 | 168 | |
159 | 169 | if( $wgUser->isAllowed( 'premoderation-viewip' ) ) { |
160 | 170 | $wgOut->addHTML( wfMsg( 'premoderation-private-ip' ) . ' ' . $row['pmq_ip'] ); |
— | — | @@ -162,7 +172,9 @@ |
163 | 173 | $rev = Revision::newFromID( $row['pmq_page_last_id'] ); |
164 | 174 | $diff = new DifferenceEngine(); |
165 | 175 | $diff->showDiffStyle(); |
166 | | - $formattedDiff = $diff->generateDiffBody( isset( $rev ) ? $rev->getText() : '', $row['pmq_text'] ); |
| 176 | + $formattedDiff = $diff->generateDiffBody( |
| 177 | + isset( $rev ) ? $rev->getText() : '', $row['pmq_text'] |
| 178 | + ); |
167 | 179 | |
168 | 180 | $wgOut->addHTML( '<h2>' . wfMsg( 'premoderation-diff-h2' ) . '</h2>' . |
169 | 181 | "<table class='mw-abusefilter-diff-multiline'><col class='diff-marker' />" . |
— | — | @@ -188,7 +200,8 @@ |
189 | 201 | |
190 | 202 | $final = Xml::fieldset( wfMsg( 'premoderation-status-fieldset' ) ) . |
191 | 203 | Xml::openElement( 'form', array( 'id' => 'prem-status-form', 'method' => 'post' ) ) . |
192 | | - $this->getStatusForm( $row['pmq_status'] ) . '<input type="hidden" name="id" value="' . $id . '" />' . |
| 204 | + $this->getStatusForm( $row['pmq_status'] ) . |
| 205 | + '<input type="hidden" name="id" value="' . $id . '" />' . |
193 | 206 | Xml::closeElement( 'form' ) . Xml::closeElement( 'fieldset' ); |
194 | 207 | |
195 | 208 | $wgOut->addHTML( $final ); |
— | — | @@ -208,7 +221,15 @@ |
209 | 222 | $db->addQuotes( $page ) . ' AND pmq_id != ' . $id . ' AND pmq_status != "approved"'; |
210 | 223 | |
211 | 224 | $res = $db->select( |
212 | | - 'pm_queue', '*', $conds, __METHOD__, |
| 225 | + 'pm_queue', |
| 226 | + '*', |
| 227 | + array( |
| 228 | + 'pmq_page_ns' => $ns, |
| 229 | + 'pmq_page_title' => $page, |
| 230 | + "pmq_id <> $id", |
| 231 | + 'pmq_status <> "approved"' |
| 232 | + ), |
| 233 | + __METHOD__, |
213 | 234 | array( 'ORDER BY' => 'pmq_timestamp DESC', 'LIMIT' => 20 ) |
214 | 235 | ); |
215 | 236 | |
— | — | @@ -294,7 +315,9 @@ |
295 | 316 | |
296 | 317 | protected function approveRevision( $id ) { |
297 | 318 | $dbw = wfGetDB( DB_MASTER ); |
298 | | - $res = $dbw->fetchRow( $dbw->select( 'pm_queue', '*', "pmq_id = '$id'", __METHOD__ ) ); |
| 319 | + $res = $dbw->fetchRow( |
| 320 | + $dbw->select( 'pm_queue', '*', "pmq_id = '$id'", __METHOD__ ) |
| 321 | + ); |
299 | 322 | |
300 | 323 | $title = Title::newFromText( $res['pmq_page_title'], $res['pmq_page_ns'] ); |
301 | 324 | $user = User::newFromName( $res['pmq_user_text'] ); |
— | — | @@ -321,44 +344,59 @@ |
322 | 345 | $pageId = $wikipage->insertOn( $dbw ); |
323 | 346 | $cond = array( 'page_id' => $pageId ); |
324 | 347 | $actionType = 'create'; |
| 348 | + |
| 349 | + $dbw->update( |
| 350 | + 'revision', |
| 351 | + array( 'rev_page' => $pageId ), |
| 352 | + array( 'rev_id' => $revId ), |
| 353 | + __METHOD__ |
| 354 | + ); |
325 | 355 | } else { |
326 | 356 | $wikipage->updateRevisionOn( $dbw, $rev ); |
327 | 357 | $cond = array( 'page_latest' => $res['pmq_page_last_id'] ); |
328 | 358 | $actionType = 'update'; |
329 | 359 | |
330 | 360 | $dbw->update( |
331 | | - 'revision', array( 'rev_page' => $title->getArticleID(), 'rev_parent_id' => $title->getLatestRevID() ), |
| 361 | + 'revision', |
| 362 | + array( |
| 363 | + 'rev_page' => $title->getArticleID(), |
| 364 | + 'rev_parent_id' => $title->getLatestRevID() |
| 365 | + ), |
332 | 366 | array( 'rev_id' => $revId ), __METHOD__ |
333 | 367 | ); |
334 | 368 | } |
335 | 369 | |
336 | 370 | $dbw->update( |
337 | | - 'page', array( 'page_latest' => $revId, 'page_len' => $rev->getSize() ), |
338 | | - $cond, __METHOD__ |
| 371 | + 'page', |
| 372 | + array( 'page_latest' => $revId, 'page_len' => $rev->getSize() ), |
| 373 | + $cond, |
| 374 | + __METHOD__ |
339 | 375 | ); |
340 | 376 | } else { |
341 | 377 | $actionType = 'updateold'; |
342 | 378 | |
343 | 379 | $latestRevId = intval( $title->getLatestRevID() ); |
344 | | - $res = $dbw->fetchRow( $dbw->select( 'revision', 'rev_parent_id', "rev_id = '$latestRevId'", __METHOD__ ) ); |
| 380 | + $res = $dbw->fetchRow( |
| 381 | + $dbw->select( 'revision', 'rev_parent_id', "rev_id = '$latestRevId'", __METHOD__ ) |
| 382 | + ); |
345 | 383 | |
346 | 384 | $dbw->update( |
347 | | - 'revision', array( 'rev_page' => $title->getArticleID(), 'rev_parent_id' => $res['rev_parent_id'] ), |
348 | | - array( 'rev_id' => $revId ), __METHOD__ |
| 385 | + 'revision', |
| 386 | + array( |
| 387 | + 'rev_page' => $title->getArticleID(), |
| 388 | + 'rev_parent_id' => $res['rev_parent_id'] |
| 389 | + ), |
| 390 | + array( 'rev_id' => $revId ), |
| 391 | + __METHOD__ |
349 | 392 | ); |
350 | 393 | $dbw->update( |
351 | | - 'revision', array( 'rev_parent_id' => $revId ), |
352 | | - array( 'rev_id' => $latestRevId ), __METHOD__ |
| 394 | + 'revision', |
| 395 | + array( 'rev_parent_id' => $revId ), |
| 396 | + array( 'rev_id' => $latestRevId ), |
| 397 | + __METHOD__ |
353 | 398 | ); |
354 | 399 | } |
355 | 400 | |
356 | | - if( isset( $pageId ) ) { |
357 | | - $dbw->update( |
358 | | - 'revision', array( 'rev_page' => $pageId ), |
359 | | - array( 'rev_id' => $revId ), __METHOD__ |
360 | | - ); |
361 | | - } |
362 | | - |
363 | 401 | $dbw->commit(); |
364 | 402 | $ok = $this->addLogEntry( $actionType, array( $title->getDBkey(), $revId ), 'public' ); |
365 | 403 | |
Index: trunk/extensions/Premoderation/Premoderation.class.php |
— | — | @@ -23,6 +23,7 @@ |
24 | 24 | } |
25 | 25 | |
26 | 26 | $wgHooks['ArticleEditUpdatesDeleteFromRecentchanges'][] = 'Premoderation::deleteOldQueueEntries'; |
| 27 | + $wgHooks['LoadExtensionSchemaUpdates'][] = 'Premoderation::updateDBSchema'; |
27 | 28 | |
28 | 29 | return true; |
29 | 30 | } |
— | — | @@ -172,4 +173,10 @@ |
173 | 174 | } |
174 | 175 | return true; |
175 | 176 | } |
| 177 | + |
| 178 | + public static function updateDBSchema( $updater ) { |
| 179 | + $updater->addExtensionUpdate( array( 'addTable', 'pm_queue', |
| 180 | + dirname( __FILE__ ) . '/db_tables.sql', true ) ); |
| 181 | + return true; |
| 182 | + } |
176 | 183 | } |
\ No newline at end of file |
Index: trunk/extensions/Premoderation/SpecialPremoderationWhiteList.php |
— | — | @@ -20,6 +20,12 @@ |
21 | 21 | if( !$wgUser->isAllowed( 'premoderation-wlist' ) ) { |
22 | 22 | $this->displayRestrictionError(); |
23 | 23 | return; |
| 24 | + } elseif( wfReadOnly() ) { |
| 25 | + $wgOut->readOnlyPage(); |
| 26 | + return; |
| 27 | + } elseif( $wgUser->isBlocked() ) { |
| 28 | + $wgOut->blockedPage(); |
| 29 | + return; |
24 | 30 | } |
25 | 31 | |
26 | 32 | $wgOut->setPageTitle( wfMsg( 'premoderationwhitelist' ) ); |
— | — | @@ -50,7 +56,8 @@ |
51 | 57 | $output = '<table class="wikitable"><tr><th>' . wfMsg( 'premoderation-table-list-ip' ) . |
52 | 58 | '</th><th>' . wfMsg( 'premoderation-table-list-delete' ) . '</th></tr>'; |
53 | 59 | foreach( $whiteList as $ip ) { |
54 | | - $output .= '<tr><td>' . $ip . '</td><td>' . $this->getDeletionButton( $ip ) . '</td></tr>'; |
| 60 | + $output .= '<tr><td>' . $ip . '</td>' . |
| 61 | + '<td>' . $this->getDeletionButton( $ip ) . '</td></tr>'; |
55 | 62 | } |
56 | 63 | $output .= '</table>'; |
57 | 64 | $wgOut->addHTML( $output ); |
— | — | @@ -61,18 +68,21 @@ |
62 | 69 | |
63 | 70 | protected function getAddForm() { |
64 | 71 | return Xml::fieldset( wfMsg( 'premoderation-wl-addip-fieldset' ) ) . |
65 | | - Xml::openElement( 'form', array( 'id' => 'prem-wl-form', 'method' => 'post' ) ) . '<table><tr><td>' . |
66 | | - wfMsg( 'premoderation-private-ip' ) . '</td><td>' . Xml::input( 'ip', 50, '', array( 'id' => 'prem-whitelist-addip' ) ) . |
67 | | - '</td></tr><tr><td>' . wfMsg( 'summary' ) . '</td><td>' . Xml::input( 'summary', 50, '', |
68 | | - array( 'id' => 'prem-summary' ) ) . '</td></tr><tr>' . '<td>' . Xml::submitButton( wfMsg( 'htmlform-submit' ), |
69 | | - array( 'id' => 'prem-wl-submit' ) ) . '<input type="hidden" name="action" value="add" />' . |
70 | | - '</td></tr></table>' . Xml::closeElement( 'form' ) . Xml::closeElement( 'fieldset' ); |
| 72 | + Xml::openElement( 'form', array( 'id' => 'prem-wl-form', 'method' => 'post' ) ) . |
| 73 | + '<table><tr><td>' . wfMsg( 'premoderation-private-ip' ) . '</td><td>' . |
| 74 | + Xml::input( 'ip', 50, '', array( 'id' => 'prem-whitelist-addip' ) ) . '</td></tr>' . |
| 75 | + '<tr><td>' . wfMsg( 'summary' ) . '</td><td>' . Xml::input( 'summary', 50, '', |
| 76 | + array( 'id' => 'prem-summary' ) ) . '</td></tr><tr>' . '<td>' . |
| 77 | + Xml::submitButton( wfMsg( 'htmlform-submit' ), array( 'id' => 'prem-wl-submit' ) ) . |
| 78 | + '<input type="hidden" name="action" value="add" /></td></tr></table>' . |
| 79 | + Xml::closeElement( 'form' ) . Xml::closeElement( 'fieldset' ); |
71 | 80 | } |
72 | 81 | |
73 | 82 | protected function getDeletionButton( $ip ) { |
74 | 83 | return Xml::openElement( 'form', array( 'id' => 'prem-wl-delete' . $ip, 'method' => 'post' ) ) . |
75 | 84 | Xml::submitButton( wfMsg( 'premoderation-table-list-delete' ) ) . |
76 | | - '<input type="hidden" name="action" value="delete" /><input type="hidden" name="ip" value="' . $ip . '" />' . |
| 85 | + '<input type="hidden" name="action" value="delete" />' . |
| 86 | + '<input type="hidden" name="ip" value="' . $ip . '" />' . |
77 | 87 | Xml::closeElement( 'form' ); |
78 | 88 | } |
79 | 89 | |
Index: trunk/extensions/Premoderation/db_tables.sql |
— | — | @@ -1,5 +1,5 @@ |
2 | | -CREATE TABLE /*$wgDBprefix*/pm_queue ( |
3 | | - pmq_id BIGINT unsigned NOT NULL AUTO_INCREMENT, |
| 2 | +CREATE TABLE /*_*/pm_queue ( |
| 3 | + pmq_id BIGINT unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT, |
4 | 4 | pmq_page_last_id INT unsigned NOT NULL, |
5 | 5 | pmq_page_ns INT NOT NULL, |
6 | 6 | pmq_page_title VARCHAR(255) BINARY NOT NULL, |
— | — | @@ -15,14 +15,10 @@ |
16 | 16 | pmq_updated BINARY(14) DEFAULT NULL, |
17 | 17 | pmq_updated_user INT unsigned DEFAULT NULL, |
18 | 18 | pmq_updated_user_text VARCHAR(255) BINARY DEFAULT NULL, |
19 | | - pmq_status VARBINARY(40) NOT NULL DEFAULT '', |
20 | | - |
21 | | - PRIMARY KEY (pmq_id), |
22 | | - KEY (pmq_user) |
| 19 | + pmq_status VARBINARY(40) NOT NULL DEFAULT '' |
23 | 20 | ) /*$wgDBTableOptions*/; |
| 21 | +CREATE INDEX /*i*/pmq_user ON /*_*/pm_queue (pmq_user); |
24 | 22 | |
25 | | -CREATE TABLE /*$wgDBprefix*/pm_whitelist ( |
26 | | - pmw_ip VARBINARY(40) NOT NULL DEFAULT '', |
27 | | - |
28 | | - PRIMARY KEY (pmw_ip) |
| 23 | +CREATE TABLE /*_*/pm_whitelist ( |
| 24 | + pmw_ip VARBINARY(40) NOT NULL PRIMARY KEY DEFAULT '', |
29 | 25 | ) /*$wgDBTableOptions*/; |
\ No newline at end of file |
Index: trunk/extensions/Premoderation/Premoderation.php |
— | — | @@ -47,10 +47,16 @@ |
48 | 48 | $wgLogRestrictions['prem-private'] = 'premoderation-log'; |
49 | 49 | $wgLogRestrictions['prem-whitelist'] = 'premoderation-wlist'; |
50 | 50 | |
51 | | -// 'all' or 'abusefilter' |
| 51 | +// Handler: 'all' or 'abusefilter' |
52 | 52 | $wgPremoderationType = 'all'; |
| 53 | + |
| 54 | +// Disable approved revision in pages with new published revisions |
53 | 55 | $wgPremoderationStrict = false; |
| 56 | + |
| 57 | +// Disable editing of pages with unapproved revisions in moderation queue |
54 | 58 | $wgPremoderationLockPages = false; |
| 59 | + |
| 60 | +// Lifetime of revisions in moderation queue |
55 | 61 | $wgPremoderationDeclinedPurge = 86400 * 3; |
56 | 62 | $wgPremoderationNewPurge = 86400 * 14; |
57 | 63 | |