Index: trunk/extensions/Patroller/Patroller.i18n.php |
— | — | @@ -0,0 +1,21 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Internationalisation file for the Patroller extension |
| 6 | + * |
| 7 | + * @package MediaWiki |
| 8 | + * @subpackage Extensions |
| 9 | + * @author Rob Church <robchur@gmail.com> |
| 10 | + * @copyright © 2006 Rob Church |
| 11 | + * @licence GNU General Public Licence 2.0 |
| 12 | + */ |
| 13 | + |
| 14 | +function efPatrollerAddMessages( &$cache ) { |
| 15 | + $messages = array( |
| 16 | + 'patrol' => 'Patrol edits', |
| 17 | + 'patrol-instructions' => 'Use this page to do evil patrolling stuff.', |
| 18 | + ); |
| 19 | + $cache->addMessages( $messages ); |
| 20 | +} |
| 21 | + |
| 22 | +?> |
\ No newline at end of file |
Property changes on: trunk/extensions/Patroller/Patroller.i18n.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 23 | + native |
Index: trunk/extensions/Patroller/Patroller.php |
— | — | @@ -0,0 +1,144 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Extension adds improved patrolling interface |
| 6 | + * |
| 7 | + * THIS IS INCOMPLETE AT THE PRESENT TIME, SO DON'T GO OFF INSTALLING |
| 8 | + * IT AND THEN WHINING BECAUSE IT DOESN'T WORK |
| 9 | + * |
| 10 | + * @package MediaWiki |
| 11 | + * @subpackage Extensions |
| 12 | + * @author Rob Church <robchur@gmail.com> |
| 13 | + * @copyright © 2006 Rob Church |
| 14 | + * @licence GNU General Public Licence 2.0 |
| 15 | + */ |
| 16 | + |
| 17 | +if( defined( 'MEDIAWIKI' ) ) { |
| 18 | + |
| 19 | + require_once( 'SpecialPage.php' ); |
| 20 | + require_once( 'Patroller.i18n.php' ); |
| 21 | + |
| 22 | + $wgExtensionFunctions[] = 'efPatroller'; |
| 23 | + $wgExtensionCredits['specialpage'][] = array( 'name' => 'Patrol', 'author' => 'Rob Church' ); |
| 24 | + |
| 25 | + $wgAvailableRights[] = 'patroller'; |
| 26 | + $wgGroupPermissions['*']['patroller'] = true; |
| 27 | + |
| 28 | + function efPatroller() { |
| 29 | + global $wgMessageCache, $wgHooks; |
| 30 | + efPatrollerAddMessages( $wgMessageCache ); |
| 31 | + SpecialPage::addPage( new Patroller() ); |
| 32 | + efPatrollerPrune(); |
| 33 | + } |
| 34 | + |
| 35 | + function efPatrollerPrune() { |
| 36 | + wfSeedRandom(); |
| 37 | + if( 0 == mt_rand( 0, 499 ) ) # Might need to bump this |
| 38 | + Patroller::pruneAssignments(); |
| 39 | + } |
| 40 | + |
| 41 | + class Patroller extends SpecialPage { |
| 42 | + |
| 43 | + function Patroller() { |
| 44 | + SpecialPage::SpecialPage( 'Patrol', 'patroller' ); |
| 45 | + } |
| 46 | + |
| 47 | + function execute() { |
| 48 | + global $wgUser, $wgRequest, $wgOut; |
| 49 | + $this->setHeaders(); |
| 50 | + |
| 51 | + # Check permissions |
| 52 | + if( !$wgUser->isAllowed( 'patroller' ) ) { |
| 53 | + $wgOut->permissionRequired( 'patroller' ); |
| 54 | + return; |
| 55 | + } |
| 56 | + |
| 57 | + # Pop an edit off recentchanges |
| 58 | + $haveEdit = false; |
| 59 | + while( !$haveEdit ) { |
| 60 | + $edit = $this->fetchChange( $wgUser ); |
| 61 | + if( $edit ) { |
| 62 | + # Attempt to assign it |
| 63 | + if( $this->assignChange( $edit ) ) { |
| 64 | + $haveEdit = true; |
| 65 | + # Show a stub changes list giving all the usual tools links |
| 66 | + # For the purposes of formatting, pretend that the change is patrolled |
| 67 | + $edit->counter = 1; |
| 68 | + $edit->mAttribs['rc_patrolled'] = 1; |
| 69 | + $list = ChangesList::newFromUser( $wgUser ); |
| 70 | + $html = $list->beginRecentChangesList(); |
| 71 | + $html .= $list->recentChangesLine( $edit ); |
| 72 | + $html .= $list->endRecentChangesList(); |
| 73 | + $wgOut->addHtml( $html ); |
| 74 | + # Now produce a diff. and show that |
| 75 | + $title = $edit->getTitle(); |
| 76 | + $diff = new DifferenceEngine( $title, $edit->mAttribs['rc_last_oldid'], $edit->mAttribs['rc_this_oldid'] ); |
| 77 | + $wgOut->addHtml( '<br /><hr />' ); |
| 78 | + $diff->showDiff( '', '' ); |
| 79 | + } |
| 80 | + } else { |
| 81 | + # Can't find a suitable edit |
| 82 | + $haveEdit = true; # Don't keep going, there's nothing to find |
| 83 | + $wgOut->addWikiText( wfMsg( 'patrol-nonefound' ) ); |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * Fetch a recent change which |
| 91 | + * - the user doing the patrolling didn't cause |
| 92 | + * - wasn't due to a bot |
| 93 | + * - hasn't been patrolled |
| 94 | + * - isn't assigned to a user |
| 95 | + */ |
| 96 | + function fetchChange( &$user ) { |
| 97 | + $dbr =& wfGetDB( DB_SLAVE ); |
| 98 | + $uid = $user->getId(); |
| 99 | + extract( $dbr->tableNames( 'recentchanges', 'patrollers' ) ); |
| 100 | + $sql = "SELECT * FROM $recentchanges LEFT JOIN $patrollers ON rc_id = ptr_change |
| 101 | + WHERE rc_bot = 0 AND rc_patrolled = 0 AND rc_type = 0 AND rc_user != $uid |
| 102 | + AND ptr_timestamp IS NULL LIMIT 0,1"; |
| 103 | + $res = $dbr->query( $sql, 'Patroller::fetchChange' ); |
| 104 | + if( $dbr->numRows( $res ) > 0 ) { |
| 105 | + $row = $dbr->fetchObject( $res ); |
| 106 | + $dbr->freeResult( $res ); |
| 107 | + return RecentChange::newFromRow( $row, $row->rc_last_oldid ); |
| 108 | + } else { |
| 109 | + $dbr->freeResult( $res ); |
| 110 | + return false; |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * Assign the patrolling of a particular change, so |
| 116 | + * other users don't pull it up, duplicating effort |
| 117 | + * |
| 118 | + * @param $edit RecentChange item to assign |
| 119 | + * @return bool |
| 120 | + */ |
| 121 | + function assignChange( &$edit ) { |
| 122 | + $dbw =& wfGetDB( DB_MASTER ); |
| 123 | + $val = array( 'ptr_change' => $edit->mAttribs['rc_id'], 'ptr_timestamp' => $dbw->timestamp() ); |
| 124 | + $res = $dbw->insert( 'patrollers', $val, 'Patroller::assignChange', 'IGNORE' ); |
| 125 | + return (bool)$dbw->affectedRows(); |
| 126 | + } |
| 127 | + |
| 128 | + /** |
| 129 | + * Prune old assignments from the table so edits aren't |
| 130 | + * hidden forever because a user wandered off, and to |
| 131 | + * keep the table size down as regards old assignments |
| 132 | + */ |
| 133 | + function pruneAssignments() { |
| 134 | + $dbw =& wfGetDB( DB_MASTER ); |
| 135 | + $dbw->delete( 'patrollers', array( 'ptr_timestamp > ' . $dbw->timestamp( time() - 120 ) ), 'Patroller::pruneAssignments' ); |
| 136 | + } |
| 137 | + |
| 138 | + } |
| 139 | + |
| 140 | +} else { |
| 141 | + echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" ); |
| 142 | + die( 1 ); |
| 143 | +} |
| 144 | + |
| 145 | +?> |
\ No newline at end of file |
Property changes on: trunk/extensions/Patroller/Patroller.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 146 | + native |