Index: trunk/extensions/FlaggedRevs/FRUserCounters.php |
— | — | @@ -0,0 +1,108 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Class containing utility functions for per-user stats |
| 5 | + */ |
| 6 | +class FRUserCounters { |
| 7 | + /** |
| 8 | + * Get params for a user |
| 9 | + * @param int $uid |
| 10 | + * @param string $DBName, optional wiki name |
| 11 | + * @returns array $params |
| 12 | + */ |
| 13 | + public static function getUserParams( $uid, $DBName = false ) { |
| 14 | + $dbw = wfGetDB( DB_MASTER, array(), $DBName ); |
| 15 | + $row = $dbw->selectRow( 'flaggedrevs_promote', |
| 16 | + 'frp_user_params', |
| 17 | + array( 'frp_user_id' => $uid ), |
| 18 | + __METHOD__ |
| 19 | + ); |
| 20 | + # Parse params |
| 21 | + $p = array(); // init |
| 22 | + if ( $row ) { |
| 23 | + $flatPars = explode( "\n", trim( $row->frp_user_params ) ); |
| 24 | + foreach ( $flatPars as $pair ) { |
| 25 | + $m = explode( '=', trim( $pair ), 2 ); |
| 26 | + $key = $m[0]; |
| 27 | + $value = isset( $m[1] ) ? $m[1] : null; |
| 28 | + $p[$key] = $value; |
| 29 | + } |
| 30 | + } |
| 31 | + # Initialize fields as needed... |
| 32 | + if ( !isset( $p['uniqueContentPages'] ) ) { |
| 33 | + $p['uniqueContentPages'] = ''; |
| 34 | + } |
| 35 | + if ( !isset( $p['totalContentEdits'] ) ) { |
| 36 | + $p['totalContentEdits'] = 0; |
| 37 | + } |
| 38 | + if ( !isset( $p['editComments'] ) ) { |
| 39 | + $p['editComments'] = 0; |
| 40 | + } |
| 41 | + if ( !isset( $p['revertedEdits'] ) ) { |
| 42 | + $p['revertedEdits'] = 0; |
| 43 | + } |
| 44 | + return $p; |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Save params for a user |
| 49 | + * @param int $uid |
| 50 | + * @param array $params |
| 51 | + * @param string $DBName, optional wiki name |
| 52 | + * @returns bool success |
| 53 | + */ |
| 54 | + public static function saveUserParams( $uid, array $params, $DBName = false ) { |
| 55 | + $flatParams = ''; |
| 56 | + foreach ( $params as $key => $value ) { |
| 57 | + $flatParams .= "{$key}={$value}\n"; |
| 58 | + } |
| 59 | + $dbw = wfGetDB( DB_MASTER, array(), $DBName ); |
| 60 | + $row = $dbw->replace( 'flaggedrevs_promote', |
| 61 | + array( 'frp_user_id' ), |
| 62 | + array( 'frp_user_id' => $uid, 'frp_user_params' => trim( $flatParams ) ), |
| 63 | + __METHOD__ |
| 64 | + ); |
| 65 | + return ( $dbw->affectedRows() > 0 ); |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * Update users params array for a user on edit |
| 70 | + * @param &array $params |
| 71 | + * @param Article $article the article just edited |
| 72 | + * @param string $summary edit summary |
| 73 | + * @returns bool anything changed |
| 74 | + */ |
| 75 | + public static function updateUserParams( array &$p, Article $article, $summary ) { |
| 76 | + global $wgFlaggedRevsAutoconfirm, $wgFlaggedRevsAutopromote; |
| 77 | + # Update any special counters for non-null revisions |
| 78 | + $changed = false; |
| 79 | + if ( $article->getTitle()->isContentPage() ) { |
| 80 | + $pages = explode( ',', trim( $p['uniqueContentPages'] ) ); // page IDs |
| 81 | + # Don't let this get bloated for no reason |
| 82 | + $maxUniquePages = 50; // some flexibility |
| 83 | + if ( is_array( $wgFlaggedRevsAutoconfirm ) && |
| 84 | + $wgFlaggedRevsAutoconfirm['uniqueContentPages'] > $maxUniquePages ) |
| 85 | + { |
| 86 | + $maxUniquePages = $wgFlaggedRevsAutoconfirm['uniqueContentPages']; |
| 87 | + } |
| 88 | + if ( is_array( $wgFlaggedRevsAutopromote ) && |
| 89 | + $wgFlaggedRevsAutopromote['uniqueContentPages'] > $maxUniquePages ) |
| 90 | + { |
| 91 | + $maxUniquePages = $wgFlaggedRevsAutopromote['uniqueContentPages']; |
| 92 | + } |
| 93 | + if ( count( $pages ) < $maxUniquePages // limit the size of this |
| 94 | + && !in_array( $article->getId(), $pages ) ) |
| 95 | + { |
| 96 | + $pages[] = $article->getId(); |
| 97 | + // Clear out any formatting garbage |
| 98 | + $p['uniqueContentPages'] = preg_replace( '/^,/', '', implode( ',', $pages ) ); |
| 99 | + } |
| 100 | + $p['totalContentEdits'] += 1; |
| 101 | + $changed = true; |
| 102 | + } |
| 103 | + if ( $summary != '' ) { |
| 104 | + $p['editComments'] += 1; |
| 105 | + $changed = true; |
| 106 | + } |
| 107 | + return $changed; |
| 108 | + } |
| 109 | +} |
Property changes on: trunk/extensions/FlaggedRevs/FRUserCounters.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 110 | + native |
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php |
— | — | @@ -301,6 +301,7 @@ |
302 | 302 | $wgPHPlotDir = $dir . 'phplot-5.0.5'; |
303 | 303 | |
304 | 304 | $wgAutoloadClasses['FlaggedRevs'] = $dir . 'FlaggedRevs.class.php'; |
| 305 | +$wgAutoloadClasses['FRUserCounters'] = $dir . 'FRUserCounters.php'; |
305 | 306 | $wgAutoloadClasses['FlaggedRevsHooks'] = $dir . 'FlaggedRevs.hooks.php'; |
306 | 307 | $wgAutoloadClasses['FlaggedRevsLogs'] = $dir . 'FlaggedRevsLogs.php'; |
307 | 308 | $wgAutoloadClasses['FRCacheUpdate'] = $dir . 'FRCacheUpdate.php'; |
Index: trunk/extensions/FlaggedRevs/maintenance/updateAutoPromote.inc |
— | — | @@ -23,7 +23,7 @@ |
24 | 24 | # Go through and clean up missing items, as well as correct fr_quality... |
25 | 25 | foreach( $res as $row ) { |
26 | 26 | $user = User::newFromRow( $row ); |
27 | | - $p = FlaggedRevs::getUserParams( $user->getId() ); |
| 27 | + $p = FRUserCounters::getUserParams( $user->getId() ); |
28 | 28 | $oldp = $p; |
29 | 29 | # Get edit comments used |
30 | 30 | $sres = $db->select( 'revision', '1', |
— | — | @@ -57,7 +57,7 @@ |
58 | 58 | $p['uniqueContentPages'] = implode($uniquePages,','); |
59 | 59 | |
60 | 60 | if( $oldp != $p ) { |
61 | | - FlaggedRevs::saveUserParams( $user->getId(), $p ); |
| 61 | + FRUserCounters::saveUserParams( $user->getId(), $p ); |
62 | 62 | $changed++; |
63 | 63 | } |
64 | 64 | |
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php |
— | — | @@ -1383,106 +1383,6 @@ |
1384 | 1384 | $dbw->delete( 'flaggedpage_pending', array( 'fpp_page_id' => $pageId ), __METHOD__ ); |
1385 | 1385 | } |
1386 | 1386 | |
1387 | | - /** |
1388 | | - * Get params for a user |
1389 | | - * @param int $uid |
1390 | | - * @param string $DBName, optional wiki name |
1391 | | - * @returns array $params |
1392 | | - */ |
1393 | | - public static function getUserParams( $uid, $DBName = false ) { |
1394 | | - $dbw = wfGetDB( DB_MASTER, array(), $DBName ); |
1395 | | - $row = $dbw->selectRow( 'flaggedrevs_promote', |
1396 | | - 'frp_user_params', |
1397 | | - array( 'frp_user_id' => $uid ), |
1398 | | - __METHOD__ |
1399 | | - ); |
1400 | | - # Parse params |
1401 | | - $p = array(); // init |
1402 | | - if ( $row ) { |
1403 | | - $flatPars = explode( "\n", trim( $row->frp_user_params ) ); |
1404 | | - foreach ( $flatPars as $pair ) { |
1405 | | - $m = explode( '=', trim( $pair ), 2 ); |
1406 | | - $key = $m[0]; |
1407 | | - $value = isset( $m[1] ) ? $m[1] : null; |
1408 | | - $p[$key] = $value; |
1409 | | - } |
1410 | | - } |
1411 | | - # Initialize fields as needed... |
1412 | | - if ( !isset( $p['uniqueContentPages'] ) ) |
1413 | | - $p['uniqueContentPages'] = ''; |
1414 | | - if ( !isset( $p['totalContentEdits'] ) ) |
1415 | | - $p['totalContentEdits'] = 0; |
1416 | | - if ( !isset( $p['editComments'] ) ) |
1417 | | - $p['editComments'] = 0; |
1418 | | - if ( !isset( $p['revertedEdits'] ) ) |
1419 | | - $p['revertedEdits'] = 0; |
1420 | | - |
1421 | | - return $p; |
1422 | | - } |
1423 | | - |
1424 | | - /** |
1425 | | - * Save params for a user |
1426 | | - * @param int $uid |
1427 | | - * @param array $params |
1428 | | - * @param string $DBName, optional wiki name |
1429 | | - * @returns bool success |
1430 | | - */ |
1431 | | - public static function saveUserParams( $uid, array $params, $DBName = false ) { |
1432 | | - $flatParams = ''; |
1433 | | - foreach ( $params as $key => $value ) { |
1434 | | - $flatParams .= "{$key}={$value}\n"; |
1435 | | - } |
1436 | | - $dbw = wfGetDB( DB_MASTER, array(), $DBName ); |
1437 | | - $row = $dbw->replace( 'flaggedrevs_promote', |
1438 | | - array( 'frp_user_id' ), |
1439 | | - array( 'frp_user_id' => $uid, 'frp_user_params' => trim( $flatParams ) ), |
1440 | | - __METHOD__ |
1441 | | - ); |
1442 | | - return ( $dbw->affectedRows() > 0 ); |
1443 | | - } |
1444 | | - |
1445 | | - /** |
1446 | | - * Update users params array for a user on edit |
1447 | | - * @param &array $params |
1448 | | - * @param Article $article the article just edited |
1449 | | - * @param string $summary edit summary |
1450 | | - * @returns bool anything changed |
1451 | | - */ |
1452 | | - public static function updateUserParams( array &$p, Article $article, $summary ) { |
1453 | | - global $wgFlaggedRevsAutoconfirm, $wgFlaggedRevsAutopromote; |
1454 | | - # Update any special counters for non-null revisions |
1455 | | - $changed = false; |
1456 | | - if ( $article->getTitle()->isContentPage() ) { |
1457 | | - $pages = explode( ',', trim( $p['uniqueContentPages'] ) ); // page IDs |
1458 | | - # Don't let this get bloated for no reason |
1459 | | - $maxUniquePages = 50; // some flexibility |
1460 | | - if ( is_array( $wgFlaggedRevsAutoconfirm ) && |
1461 | | - $wgFlaggedRevsAutoconfirm['uniqueContentPages'] > $maxUniquePages ) |
1462 | | - { |
1463 | | - $maxUniquePages = $wgFlaggedRevsAutoconfirm['uniqueContentPages']; |
1464 | | - } |
1465 | | - if ( is_array( $wgFlaggedRevsAutopromote ) && |
1466 | | - $wgFlaggedRevsAutopromote['uniqueContentPages'] > $maxUniquePages ) |
1467 | | - { |
1468 | | - $maxUniquePages = $wgFlaggedRevsAutopromote['uniqueContentPages']; |
1469 | | - } |
1470 | | - if ( count( $pages ) < $maxUniquePages // limit the size of this |
1471 | | - && !in_array( $article->getId(), $pages ) ) |
1472 | | - { |
1473 | | - $pages[] = $article->getId(); |
1474 | | - // Clear out any formatting garbage |
1475 | | - $p['uniqueContentPages'] = preg_replace( '/^,/', '', implode( ',', $pages ) ); |
1476 | | - } |
1477 | | - $p['totalContentEdits'] += 1; |
1478 | | - $changed = true; |
1479 | | - } |
1480 | | - if ( $summary != '' ) { |
1481 | | - $p['editComments'] += 1; |
1482 | | - $changed = true; |
1483 | | - } |
1484 | | - return $changed; |
1485 | | - } |
1486 | | - |
1487 | 1387 | # ################ Auto-review function ################# |
1488 | 1388 | |
1489 | 1389 | /** |
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php |
— | — | @@ -1117,12 +1117,12 @@ |
1118 | 1118 | # Mark when a user reverts another user, but not self-reverts |
1119 | 1119 | $badUserId = $badRev->getRawUser(); |
1120 | 1120 | if ( $badUserId && $user->getId() != $badUserId ) { |
1121 | | - $p = FlaggedRevs::getUserParams( $badUserId ); |
| 1121 | + $p = FRUserCounters::getUserParams( $badUserId ); |
1122 | 1122 | if ( !isset( $p['revertedEdits'] ) ) { |
1123 | 1123 | $p['revertedEdits'] = 0; |
1124 | 1124 | } |
1125 | 1125 | $p['revertedEdits']++; |
1126 | | - FlaggedRevs::saveUserParams( $badUserId, $p ); |
| 1126 | + FRUserCounters::saveUserParams( $badUserId, $p ); |
1127 | 1127 | } |
1128 | 1128 | return true; |
1129 | 1129 | } |
— | — | @@ -1140,12 +1140,12 @@ |
1141 | 1141 | if ( $badRev && $badRev->getRawUser() |
1142 | 1142 | && $badRev->getRawUser() != $rev->getRawUser() ) |
1143 | 1143 | { |
1144 | | - $p = FlaggedRevs::getUserParams( $badRev->getRawUser() ); |
| 1144 | + $p = FRUserCounters::getUserParams( $badRev->getRawUser() ); |
1145 | 1145 | if ( !isset( $p['revertedEdits'] ) ) { |
1146 | 1146 | $p['revertedEdits'] = 0; |
1147 | 1147 | } |
1148 | 1148 | $p['revertedEdits']++; |
1149 | | - FlaggedRevs::saveUserParams( $badRev->getRawUser(), $p ); |
| 1149 | + FRUserCounters::saveUserParams( $badRev->getRawUser(), $p ); |
1150 | 1150 | } |
1151 | 1151 | } |
1152 | 1152 | return true; |
— | — | @@ -1234,7 +1234,7 @@ |
1235 | 1235 | $userage = $userCreation |
1236 | 1236 | ? floor( ( $now - $userCreation ) / 86400 ) |
1237 | 1237 | : null; |
1238 | | - $p = FlaggedRevs::getUserParams( $user->getId() ); |
| 1238 | + $p = FRUserCounters::getUserParams( $user->getId() ); |
1239 | 1239 | # Check if user edited enough content pages |
1240 | 1240 | $totalCheckedEditsNeeded = false; |
1241 | 1241 | if ( $wgFlaggedRevsAutoconfirm['totalContentEdits'] > $p['totalContentEdits'] ) { |
— | — | @@ -1335,11 +1335,11 @@ |
1336 | 1336 | } elseif ( !$wgFlaggedRevsAutopromote && !$wgFlaggedRevsAutoconfirm ) { |
1337 | 1337 | return true; |
1338 | 1338 | } |
1339 | | - $p = FlaggedRevs::getUserParams( $user->getId() ); |
1340 | | - $changed = FlaggedRevs::updateUserParams( $p, $article, $summary ); |
| 1339 | + $p = FRUserCounters::getUserParams( $user->getId() ); |
| 1340 | + $changed = FRUserCounters::updateUserParams( $p, $article, $summary ); |
1341 | 1341 | # Save any updates to user params |
1342 | 1342 | if ( $changed ) { |
1343 | | - FlaggedRevs::saveUserParams( $user->getId(), $p ); |
| 1343 | + FRUserCounters::saveUserParams( $user->getId(), $p ); |
1344 | 1344 | } |
1345 | 1345 | if ( !is_array( $wgFlaggedRevsAutopromote ) ) { |
1346 | 1346 | return true; // nothing to do |
— | — | @@ -1531,14 +1531,14 @@ |
1532 | 1532 | if ( $removegroup && in_array( 'editor', $removegroup ) ) { |
1533 | 1533 | // Cross-wiki rights change |
1534 | 1534 | if ( $u instanceof UserRightsProxy ) { |
1535 | | - $params = FlaggedRevs::getUserParams( $u->getId(), $u->getDBName() ); |
| 1535 | + $params = FRUserCounters::getUserParams( $u->getId(), $u->getDBName() ); |
1536 | 1536 | $params['demoted'] = 1; |
1537 | | - FlaggedRevs::saveUserParams( $u->getId(), $params, $u->getDBName() ); |
| 1537 | + FRUserCounters::saveUserParams( $u->getId(), $params, $u->getDBName() ); |
1538 | 1538 | // On-wiki rights change |
1539 | 1539 | } else { |
1540 | | - $params = FlaggedRevs::getUserParams( $u->getId() ); |
| 1540 | + $params = FRUserCounters::getUserParams( $u->getId() ); |
1541 | 1541 | $params['demoted'] = 1; |
1542 | | - FlaggedRevs::saveUserParams( $u->getId(), $params ); |
| 1542 | + FRUserCounters::saveUserParams( $u->getId(), $params ); |
1543 | 1543 | } |
1544 | 1544 | } |
1545 | 1545 | return true; |