r102199 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102198‎ | r102199 | r102200 >
Date:21:38, 6 November 2011
Author:cryptocoryne
Status:deferred
Tags:
Comment:
Followup r102139 -- some improves and fixes according to ashley's review
Modified paths:
  • /trunk/extensions/Premoderation/Premoderation.class.php (modified) (history)
  • /trunk/extensions/Premoderation/Premoderation.php (modified) (history)
  • /trunk/extensions/Premoderation/SpecialPremoderation.php (modified) (history)
  • /trunk/extensions/Premoderation/SpecialPremoderationWhiteList.php (modified) (history)
  • /trunk/extensions/Premoderation/db_tables.sql (modified) (history)
  • /trunk/extensions/Premoderation/install.php (deleted) (history)

Diff [purge]

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 @@
2323 if( !$wgUser->isAllowed( 'premoderation' ) ) {
2424 $this->displayRestrictionError();
2525 return;
 26+ } elseif( wfReadOnly() ) {
 27+ $wgOut->readOnlyPage();
 28+ return;
 29+ } elseif( $wgUser->isBlocked() ) {
 30+ $wgOut->blockedPage();
 31+ return;
2632 }
2733
28 - $allowedActions = array( '', 'list', 'status' );
29 -
3034 $params = array_values( explode( '/', $subpage ) );
3135 $action = array_shift( &$params );
3236
33 - if( !in_array( $action, $allowedActions ) ) {
34 - $wgOut->setPageTitle( wfMsg( 'premoderation-manager-invalidaction' ) );
35 - $wgOut->addWikiMsg( 'premoderation-invalidaction' );
36 - return;
37 - }
38 -
3937 if( $action == '' ) {
4038 $action = 'list';
4139 } elseif( isset( $params ) ) {
@@ -49,6 +47,10 @@
5048 case 'status':
5149 ( $this->mPosted ) ? $this->performChanges() : $this->statusInterface();
5250 break;
 51+
 52+ default:
 53+ $wgOut->setPageTitle( wfMsg( 'premoderation-manager-invalidaction' ) );
 54+ $wgOut->addWikiMsg( 'premoderation-invalidaction' );
5355 }
5456 }
5557
@@ -61,9 +63,13 @@
6264 $dbr = wfGetDB( DB_SLAVE );
6365 $res = $dbr->select(
6466 '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__,
6874 array( 'ORDER BY' => 'pmq_timestamp DESC', 'LIMIT' => 100 )
6975 );
7076
@@ -101,7 +107,8 @@
102108 }
103109
104110 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%' ) ) .
106113 '<tr><th>' . wfMsg( 'premoderation-table-list-time' ) . '</th>' .
107114 '<th>' . wfMsg( 'premoderation-table-list-user' ) . '</th>' .
108115 '<th colspan="2">' . wfMsg( 'premoderation-table-list-title' ) . '</th>' .
@@ -119,7 +126,8 @@
120127 '</td><td>' . ( $row['pmq_minor'] == 0 ? '' : ' ' . wfMsg( 'minoreditletter' ) ) . '</td>' .
121128 '<td>' . $row['pmq_summary'] . '</td><td>' . '<a href="' . $articlePath .
122129 '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' ),
124132 array( $row['pmq_updated_user_text'] ) ) .
125133 '</a></td></tr>';
126134 }
@@ -139,7 +147,8 @@
140148 $res = $dbr->select(
141149 'pm_queue',
142150 '*',
143 - "pmq_id = '$id'", __METHOD__,
 151+ "pmq_id = '$id'",
 152+ __METHOD__,
144153 array( 'LIMIT' => 1 )
145154 );
146155 $row = $dbr->fetchRow( $res );
@@ -153,7 +162,8 @@
154163 $wgOut->addWikiMsg( 'premoderation-status-intro' );
155164
156165 $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' ) );
158168
159169 if( $wgUser->isAllowed( 'premoderation-viewip' ) ) {
160170 $wgOut->addHTML( wfMsg( 'premoderation-private-ip' ) . ' ' . $row['pmq_ip'] );
@@ -162,7 +172,9 @@
163173 $rev = Revision::newFromID( $row['pmq_page_last_id'] );
164174 $diff = new DifferenceEngine();
165175 $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+ );
167179
168180 $wgOut->addHTML( '<h2>' . wfMsg( 'premoderation-diff-h2' ) . '</h2>' .
169181 "<table class='mw-abusefilter-diff-multiline'><col class='diff-marker' />" .
@@ -188,7 +200,8 @@
189201
190202 $final = Xml::fieldset( wfMsg( 'premoderation-status-fieldset' ) ) .
191203 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 . '" />' .
193206 Xml::closeElement( 'form' ) . Xml::closeElement( 'fieldset' );
194207
195208 $wgOut->addHTML( $final );
@@ -208,7 +221,15 @@
209222 $db->addQuotes( $page ) . ' AND pmq_id != ' . $id . ' AND pmq_status != "approved"';
210223
211224 $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__,
213234 array( 'ORDER BY' => 'pmq_timestamp DESC', 'LIMIT' => 20 )
214235 );
215236
@@ -294,7 +315,9 @@
295316
296317 protected function approveRevision( $id ) {
297318 $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+ );
299322
300323 $title = Title::newFromText( $res['pmq_page_title'], $res['pmq_page_ns'] );
301324 $user = User::newFromName( $res['pmq_user_text'] );
@@ -321,44 +344,59 @@
322345 $pageId = $wikipage->insertOn( $dbw );
323346 $cond = array( 'page_id' => $pageId );
324347 $actionType = 'create';
 348+
 349+ $dbw->update(
 350+ 'revision',
 351+ array( 'rev_page' => $pageId ),
 352+ array( 'rev_id' => $revId ),
 353+ __METHOD__
 354+ );
325355 } else {
326356 $wikipage->updateRevisionOn( $dbw, $rev );
327357 $cond = array( 'page_latest' => $res['pmq_page_last_id'] );
328358 $actionType = 'update';
329359
330360 $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+ ),
332366 array( 'rev_id' => $revId ), __METHOD__
333367 );
334368 }
335369
336370 $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__
339375 );
340376 } else {
341377 $actionType = 'updateold';
342378
343379 $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+ );
345383
346384 $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__
349392 );
350393 $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__
353398 );
354399 }
355400
356 - if( isset( $pageId ) ) {
357 - $dbw->update(
358 - 'revision', array( 'rev_page' => $pageId ),
359 - array( 'rev_id' => $revId ), __METHOD__
360 - );
361 - }
362 -
363401 $dbw->commit();
364402 $ok = $this->addLogEntry( $actionType, array( $title->getDBkey(), $revId ), 'public' );
365403
Index: trunk/extensions/Premoderation/Premoderation.class.php
@@ -23,6 +23,7 @@
2424 }
2525
2626 $wgHooks['ArticleEditUpdatesDeleteFromRecentchanges'][] = 'Premoderation::deleteOldQueueEntries';
 27+ $wgHooks['LoadExtensionSchemaUpdates'][] = 'Premoderation::updateDBSchema';
2728
2829 return true;
2930 }
@@ -172,4 +173,10 @@
173174 }
174175 return true;
175176 }
 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+ }
176183 }
\ No newline at end of file
Index: trunk/extensions/Premoderation/SpecialPremoderationWhiteList.php
@@ -20,6 +20,12 @@
2121 if( !$wgUser->isAllowed( 'premoderation-wlist' ) ) {
2222 $this->displayRestrictionError();
2323 return;
 24+ } elseif( wfReadOnly() ) {
 25+ $wgOut->readOnlyPage();
 26+ return;
 27+ } elseif( $wgUser->isBlocked() ) {
 28+ $wgOut->blockedPage();
 29+ return;
2430 }
2531
2632 $wgOut->setPageTitle( wfMsg( 'premoderationwhitelist' ) );
@@ -50,7 +56,8 @@
5157 $output = '<table class="wikitable"><tr><th>' . wfMsg( 'premoderation-table-list-ip' ) .
5258 '</th><th>' . wfMsg( 'premoderation-table-list-delete' ) . '</th></tr>';
5359 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>';
5562 }
5663 $output .= '</table>';
5764 $wgOut->addHTML( $output );
@@ -61,18 +68,21 @@
6269
6370 protected function getAddForm() {
6471 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' );
7180 }
7281
7382 protected function getDeletionButton( $ip ) {
7483 return Xml::openElement( 'form', array( 'id' => 'prem-wl-delete' . $ip, 'method' => 'post' ) ) .
7584 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 . '" />' .
7787 Xml::closeElement( 'form' );
7888 }
7989
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,
44 pmq_page_last_id INT unsigned NOT NULL,
55 pmq_page_ns INT NOT NULL,
66 pmq_page_title VARCHAR(255) BINARY NOT NULL,
@@ -15,14 +15,10 @@
1616 pmq_updated BINARY(14) DEFAULT NULL,
1717 pmq_updated_user INT unsigned DEFAULT NULL,
1818 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 ''
2320 ) /*$wgDBTableOptions*/;
 21+CREATE INDEX /*i*/pmq_user ON /*_*/pm_queue (pmq_user);
2422
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 '',
2925 ) /*$wgDBTableOptions*/;
\ No newline at end of file
Index: trunk/extensions/Premoderation/Premoderation.php
@@ -47,10 +47,16 @@
4848 $wgLogRestrictions['prem-private'] = 'premoderation-log';
4949 $wgLogRestrictions['prem-whitelist'] = 'premoderation-wlist';
5050
51 -// 'all' or 'abusefilter'
 51+// Handler: 'all' or 'abusefilter'
5252 $wgPremoderationType = 'all';
 53+
 54+// Disable approved revision in pages with new published revisions
5355 $wgPremoderationStrict = false;
 56+
 57+// Disable editing of pages with unapproved revisions in moderation queue
5458 $wgPremoderationLockPages = false;
 59+
 60+// Lifetime of revisions in moderation queue
5561 $wgPremoderationDeclinedPurge = 86400 * 3;
5662 $wgPremoderationNewPurge = 86400 * 14;
5763

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r102139Added experimental version of new extensioncryptocoryne01:17, 6 November 2011

Status & tagging log