Extension:Makepatrol

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
Makepatrol

Release status: beta

Makepatrol.png
Implementation Special page, User rights
Description Adds a special page which allows sysops to grant and revoke patrol and autopatrol rights from user accounts.
Author(s) Stig Meireles Johansen
MediaWiki >=1.9.0
License No license specified
Download No link
Added rights

makepatrol, removepatrol, patrol, autopatrol

Check usage (experimental)

Makepatrol is an extension which allows sysops to grant and revoke patrol and autopatrol status from user accounts. You'll need a newer (or equal) MediaWiki than 1.9.0 to be able to use the autopatrol-feature. NOTE: This extension is deprecated as it's now possible to use the built-in user permission special-page for assigning any rights and using LocalSettings.php to assign which subset of permissions a subset of users can assign/remove to other users. This extension is now here as a legacy-fallback.

[edit] Usage

Select User 
Enter a username in the field indicated and click Go
Grant Autopatrol Status 
Enter a comment and click the appropriate Grant button
Revoke AutoPatrol Status 
Enter a comment and click the appropriate Revoke button
Grant Patrol Status 
Enter a comment and click the appropriate Grant button
Revoke Patrol Status 
Enter a comment and click the appropriate Revoke button

This extension has been deprecated by the following code in LocalSettings.php as of r23410:

/**
 * This will add the patrol group
**/
$wgGroupPermissions['patrol']['patrol']          = true;
$wgGroupPermissions['patrol']['rollback']        = true;
$wgGroupPermissions['patrol']['autopatrol']      = true;
/**
 * This will add the autopatrol group
**/
$wgGroupPermissions['autopatrol']['autopatrol']  = true;
/**
 * This will give sysops access to the Special:Userrights page
**/
$wgGroupPermissions['sysop']['userrights']       = true;
/**
 * This will restrict sysops to add/remove only the specified groups in the Special:Userrights page
**/
$wgAddGroups['sysop'] = array( 'patrol', 'autopatrol' );
$wgRemoveGroups['sysop'] = array( 'patrol', 'autopatrol' );

[edit] Download instructions

Please cut and paste the code found below and place it in $IP/extension/Makepatrol/Makepatrol.php. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.

[edit] Installation

To install this extension, add the following to LocalSettings.php:

#add configuration parameters here
#setup user rights here
require_once("$IP/extensions/Makepatrol/Makepatrol.php");

[edit] Configuration parameters

[edit] User rights

makepatrol

This is the group of users who can assign patrol and autopatrol-status to other user accounts. This is by default set to the sysop-group.

removepatrol

This is the group of users who can remove patrol and autopatrol-status from other user accounts. This is by default set to the sysop-group. This function requires the makepatrol right as well.

patrol

Users in this group will get the rights to approve edits as well as do rollbacks in the history. Users in this group will automatically get the autopatrol rights as well.

autopatrol

Users in this group will have their edits automatically approved.

[edit] Code

[edit] Makepatrol.php

<?php
 
/**
 * Special page to allow local sysops to grant/revoke the patrol flags
 * for a particular user
 *
 * @addtogroup Extensions
 * Tiny modifications by Stig Meireles Johansen to MakeBot and FlaggedRevs
 * FlaggedRevs extension:
 ** @author Aaron Schulz, Joerg Baach
 * MakeBot extension:
 ** @author Rob Church <robchur@gmail.com>
 ** @copyright © 2006 Rob Church
 ** @licence GNU General Public Licence 2.0 or later
 */
 
if( defined( 'MEDIAWIKI' ) ) {
 
        define( 'MW_MAKEPATROL_GRANT_PATROL', 1 );
        define( 'MW_MAKEPATROL_REVOKE_PATROL', 2 );
        define( 'MW_MAKEPATROL_REVOKE_AUTOPATROL', 3 );
 
        $wgExtensionFunctions[] = 'efMakepatrol';
        $wgAvailableRights[] = 'makepatrol';
        $wgAvailableRights[] = 'removepatrol';
 
        /**
         * Setup the necessary groups
         */
        $wgGroupPermissions['patrol']['patrol']          = true;
        $wgGroupPermissions['patrol']['autopatrol']      = true;
        $wgGroupPermissions['patrol']['rollback']        = true;
        $wgGroupPermissions['autopatrol']['autopatrol']  = true;
 
        /**
         * Determines who can use the extension; as a default, sysops are permitted
         */
        # Basic rights for Sysops
        $wgGroupPermissions['sysop']['makepatrol'] = true;
        $wgGroupPermissions['sysop']['removepatrol'] = true;
 
        /**
         * Register the special page
         */
        $wgAutoloadClasses['Makepatrol'] = dirname( __FILE__ ) . '/Makepatrol.class.php';
        $wgSpecialPages['Makepatrol'] = 'Makepatrol';
 
        /**
         * Populate the message cache and set up the auditing
         */
        function efMakePatrol() {
                global $wgMessageCache;
                require_once( dirname( __FILE__ ) . '/Makepatrol.i18n.php' );
                foreach( efMakePatrolMessages() as $lang => $messages )
                        $wgMessageCache->addMessages( $messages, $lang );
        }
 
} else {
        echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" );
        exit( 1 );
}

[edit] Makepatrol.i18n.php

<?php
/**
 * Internationalisation file for makepatrol extension.
 *
 * @package MediaWiki
 * @subpackage Extensions
*/
 
function efMakePatrolMessages() {
        $messages = array();
 
/* English (Stig Meireles Johansen) */
$messages['en'] = array(
        'makepatrol'       => 'Promote/demote patrollers',
        'makepatrol-header'   => '<strong>This form is used by sysops to promote users to patrollers
        </strong><br> Type the name of the user in the box and press the button to set the user\'s rights.
        Granting users patroller status will automatically grant them autopatrol status. Revoking autopatrol status will
        automatically revoke patrol status.',
        'makepatrol-username'  => 'Name of the user:',
        'makepatrol-search' => 'Go',
        'makepatrol-isautopatrolled' => '[[User:$1|$1]] has autopatrol status.',
        'makepatrol-notautopatrolled' => '[[User:$1|$1]] does not have autopatrol status.',
        'makepatrol-ispatroller' => '[[User:$1|$1]] has patrol status.',
        'makepatrol-notpatroller' => '[[User:$1|$1]] does not have patrol status.',
        'makepatrol-legend' => 'Change patrol-rights:',
        'makepatrol-change-a' => 'Autopatrol status:',
        'makepatrol-change-p' => 'Patrol status:',
        'makepatrol-grant1' => 'Grant',
        'makepatrol-revoke1' => 'Revoke',
        'makepatrol-grant2' => 'Grant',
        'makepatrol-revoke2' => 'Revoke',
        'makepatrol-comment' => 'Comment:',
        'makepatrol-granted-a' => '[[User:$1|$1]] now has autopatrol status.',
        'makepatrol-revoked-a' => '[[User:$1|$1]] no longer has autopatrol status.',
        'makepatrol-granted-p' => '[[User:$1|$1]] now has patrol status.',
        'makepatrol-revoked-p' => '[[User:$1|$1]] no longer has patrol status.',
);
 
/* Norwegian (Stig Meireles Johansen) */
$messages['no'] = array(
        'makepatrol'                  => 'Sett patruljerettigheter for brukere',
        'makepatrol-header'           => '<strong>Dette skjemaet brukes av administratorer for å sette godkjenningsrettigheter (RC-Patrol) til brukere.</strong><br />Skriv inn navnet på brukeren i boksen og trykk knappen for å sette godkjenningsrettigheter. En bruker kan være følgende: uten automatiske godkjenninger eller tilgang til å godkjenne, kun automatiske godkjenninger eller både automatiske godkjenninger og rettigheter til å godkjenne endringer.',
        'makepatrol-username'         => 'Brukernavn:',
        'makepatrol-search'           => 'Gå',
        'makepatrol-isautopatrolled'  => '[[User:$1|$1]] sine redigeringer blir automatisk godkjent.',
        'makepatrol-notautopatrolled' => '[[User:$1|$1]] sine redigeringer blir ikke automatisk godkjent.',
        'makepatrol-ispatroller'      => '[[User:$1|$1]] har patruljeringsmuligheter.',
        'makepatrol-notpatroller'     => '[[User:$1|$1]] har ikke patruljeringsmuligheter.',
        'makepatrol-legend'           => 'Endre patruljerettigheter:',
        'makepatrol-change-a'         => 'Automatisk godkjente redigeringer:',
        'makepatrol-change-p'         => 'Kan godkjenne redigeringer:',
        'makepatrol-grant1'           => 'Gi',
        'makepatrol-revoke1'          => 'Fjern',
        'makepatrol-grant2'           => 'Gi',
        'makepatrol-revoke2'          => 'Fjern',
        'makepatrol-comment'          => 'Kommentar:',
        'makepatrol-granted-a'        => '[[User:$1|$1]] sine redigeringer blir nå automatisk godkjente.',
        'makepatrol-revoked-a'        => '[[User:$1|$1]] sine redigeringer blir ikke lenger automatisk godkjente.',
        'makepatrol-granted-p'        => '[[User:$1|$1]] kan nå godkjenne redigeringer.',
        'makepatrol-revoked-p'        => '[[User:$1|$1]] kan ikke lenger godkjenne redigeringer.',
);
 
return $messages;
}

[edit] Makepatrol.class.php

<?php
 
global $IP;
require_once( "$IP/includes/LogPage.php" );
require_once( "$IP/includes/SpecialLog.php" );
 
class MakePatrol extends SpecialPage {
 
        var $target = '';
 
        /**
         * Constructor
         */
        function MakePatrol() {
                SpecialPage::SpecialPage( 'Makepatrol', 'makepatrol' );
        }
 
        /**
         * Main execution function
         * @param $par Parameters passed to the page
         */
        function execute( $par ) {
                global $wgRequest, $wgOut, $wgmakevalidatePrivileged, $wgUser;
 
                if( !$wgUser->isAllowed( 'makepatrol' ) ) {
                        $wgOut->permissionRequired( 'makepatrol' );
                        return;
                }
 
                $this->setHeaders();
 
                $this->target = $par ? $par : $wgRequest->getText( 'username', '' );
 
                $wgOut->addWikiText( wfMsgNoTrans( 'makepatrol-header' ) );
                $wgOut->addHtml( $this->makeSearchForm() );
 
                if( $this->target != '' ) {
                        $wgOut->addHtml( wfElement( 'p', NULL, NULL ) );
                        $user = User::newFromName( $this->target );
                        if( is_object( $user ) && !is_null( $user ) ) {
                                global $wgVersion;
                                if( version_compare( $wgVersion, '1.9alpha' ) < 0 ) {
                                        $user->loadFromDatabase();
                                } else {
                                        $user->load();
                                }
                                # Valid username, check existence
                                if( $user->getID() ) {
                                                $oldgroups = $user->getGroups();
                                                if( $wgRequest->getCheck( 'dosearch' ) || !$wgRequest->wasPosted() || !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ), 'makepatrol' ) ) {
                                                        # Exists, check autopatrol & patrol status
                                                        # We never assign patrol status alone
                                                        if( in_array( 'patrol', $user->mGroups ) && in_array( 'autopatrol', $user->mGroups ) ) {
                                                                # Has a patrol as well as a autopatrol flag
                                                                $wgOut->addWikiText( wfMsg( 'makepatrol-ispatroller', $user->getName() ) );
                                                                $wgOut->addWikiText( wfMsg( 'makepatrol-isautopatrolled', $user->getName() ) );
                                                                $wgOut->addHtml( $this->makeGrantForm( MW_MAKEPATROL_REVOKE_PATROL ) );
                                                        } else if( in_array( 'autopatrol', $user->mGroups ) ) {
                                                                # Has a autopatrol flag
                                                                $wgOut->addWikiText( wfMsg( 'makepatrol-isautopatrolled', $user->getName() ) );
                                                                $wgOut->addHtml( $this->makeGrantForm( MW_MAKEPATROL_REVOKE_AUTOPATROL ) );
                                                        } else if( in_array( 'patrol', $user->mGroups ) ) {
                                                                # This shouldn't happen... (just a patrol flag)
                                                                $wgOut->addHtml( $this->makeGrantForm( MW_MAKEPATROL_REVOKE_PATROL ) );
                                                        } else {
                                                                # Not a patroller; show the grant form
                                                                $wgOut->addHtml( $this->makeGrantForm( MW_MAKEPATROL_GRANT_PATROL ) );
                                                        }
                                                } elseif( $wgRequest->getCheck( 'grant2' ) ) {
                                                        # Grant the flag
                                                        if( !in_array( 'patrol', $user->mGroups ) )
                                                                $user->addGroup( 'patrol' );
                                                        # All patrollers are autopatrolled too
                                                        if( !in_array( 'autopatrol', $user->mGroups ) )
                                                                $user->addGroup( 'autopatrol' );
                                                        $this->addLogItem( $user, trim( $wgRequest->getText( 'comment' ) ), $oldgroups);
                                                        $wgOut->addWikiText( wfMsg( 'makepatrol-granted-p', $user->getName() ) );
                                                } elseif( $wgRequest->getCheck( 'revoke2' ) ) {
                                                        # Permission check
                                                        if( !$wgUser->isAllowed( 'removepatrol' ) ) {
                                                                $wgOut->permissionRequired( 'removepatrol' );
                                                                return;
                                                        }
                                                        # Revoke the flag
                                                        if ( in_array( 'patrol', $user->mGroups ) )
                                                                $user->removeGroup( 'patrol' );
                                                        $this->addLogItem( $user, trim( $wgRequest->getText( 'comment' ) ), $oldgroups );
                                                        $wgOut->addWikiText( wfMsg( 'makepatrol-revoked-p', $user->getName() ) );
                                                } elseif( $wgRequest->getCheck( 'grant1' ) ) {
                                                        # Grant the flag
                                                        if( !in_array( 'autopatrol', $user->mGroups ) )
                                                                $user->addGroup( 'autopatrol' );
                                                        $this->addLogItem( $user, trim( $wgRequest->getText( 'comment' ) ), $oldgroups );
                                                        $wgOut->addWikiText( wfMsg( 'makepatrol-granted-a', $user->getName() ) );
                                                } elseif( $wgRequest->getCheck( 'revoke1' ) ) {
                                                        # Permission check
                                                        if( !$wgUser->isAllowed( 'removepatrol' ) ) {
                                                                $wgOut->permissionRequired( 'removepatrol' );
                                                                return;
                                                        } 
                                                        if( in_array( 'patrol', $user->mGroups ) ) {
                                                                $user->removeGroup( 'autopatrol' ); 
                                                                # Patrol flag falls off too
                                                                $user->removeGroup( 'patrol' );
                                                        } else if( in_array( 'autopatrol', $user->mGroups ) ) {
                                                                # Revoke the flag
                                                                $user->removeGroup( 'autopatrol' );
                                                        }
                                                        $this->addLogItem( $user, trim( $wgRequest->getText( 'comment' ) ), $oldgroups );
                                                        $wgOut->addWikiText( wfMsg( 'makepatrol-revoked-a', $user->getName() ) );
                                                }
                                                # Show log entries
                                                $this->showLogEntries( $user );
                                } else {
                                        # Doesn't exist
                                        $wgOut->addWikiText( wfMsg( 'nosuchusershort', htmlspecialchars( $this->target ) ) );
                                }
                        } else {
                                # Invalid username
                                $wgOut->addWikiText( wfMsg( 'noname' ) );
                        }
                }
 
        }
 
        /**
         * Produce a form to allow for entering a username
         * @return string
         */
        function makeSearchForm() {
                $thisTitle = Title::makeTitle( NS_SPECIAL, $this->getName() );
                $form  = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $thisTitle->getLocalUrl() ) );
                $form .= wfElement( 'label', array( 'for' => 'username' ), wfMsg( 'makepatrol-username' ) ) . ' ';
                $form .= wfElement( 'input', array( 'type' => 'text', 'name' => 'username', 'id' => 'username', 'value' => $this->target ) ) . ' ';
                $form .= wfElement( 'input', array( 'type' => 'submit', 'name' => 'dosearch', 'value' => wfMsg( 'makepatrol-search' ) ) );
                $form .= wfCloseElement( 'form' );
                return $form;
        }
 
        /**
         * Produce a form to allow granting or revocation of the flag
         * @param $type Either MW_MAKEPATROL_GRANT or MW_MAKEPATROL_REVOKE
         *                              where the trailing name refers to what's enabled
         * @return string
         */
        function makeGrantForm( $type ) {
                global $wgUser;
                $thisTitle = Title::makeTitle( NS_SPECIAL, $this->getName() );
                if( $type == MW_MAKEPATROL_GRANT_PATROL ) {
                        $grant1 = true; $revoke1 = false;
                        $grant2 = true; $revoke2 = false;
                } else if ( $type == MW_MAKEPATROL_REVOKE_AUTOPATROL ) {
                        $grant1 = false; $revoke1 = true;
                        $grant2 = true; $revoke2 = false;
                } else if ( $type == MW_MAKEPATROL_REVOKE_PATROL ) {
                        $grant1 = false; $revoke1 = true;
                        $grant2 = false; $revoke2 = true;
                } else {
                // OK, this one should never happen
                        $grant1 = true; $revoke1 = true;
                        $grant2 = false; $revoke2 = true;
                }
 
                # Start the table
                $form  = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $thisTitle->getLocalUrl() ) );
                $form .= '<fieldset><legend>' . wfMsg('makepatrol-legend') . '</legend>';
                $form .= wfOpenElement( 'table' ) . wfOpenElement( 'tr' );
                # Grant/revoke buttons
                $form .= wfElement( 'td', array( 'align' => 'right' ), wfMsg( 'makepatrol-change-a' ) );
                $form .= wfOpenElement( 'td' );
                foreach( array( 'grant1', 'revoke1' ) as $button ) {
                        $attribs = array( 'type' => 'submit', 'name' => $button, 'value' => wfMsg( 'makepatrol-' . $button ) );
                        if( !$$button )
                                $attribs['disabled'] = 'disabled';
                        $form .= wfElement( 'input', $attribs );
                }
                $form .= wfCloseElement( 'td' ) . wfCloseElement( 'tr' );
                $form .= wfElement( 'td', array( 'align' => 'right' ), wfMsg( 'makepatrol-change-p' ) );
                $form .= wfOpenElement( 'td' );
                foreach( array( 'grant2', 'revoke2' ) as $button ) {
                        $attribs = array( 'type' => 'submit', 'name' => $button, 'value' => wfMsg( 'makepatrol-' . $button ) );
                        if( !$$button )
                                $attribs['disabled'] = 'disabled';
                        $form .= wfElement( 'input', $attribs );
                }
                $form .= wfCloseElement( 'td' ) . wfCloseElement( 'tr' );
                # Comment field
                $form .= wfOpenElement( 'td', array( 'align' => 'right' ) );
                $form .= wfElement( 'label', array( 'for' => 'comment' ), wfMsg( 'makepatrol-comment' ) );
                $form .= wfOpenElement( 'td' );
                $form .= wfElement( 'input', array( 'type' => 'text', 'name' => 'comment', 'id' => 'comment', 'size' => 45 ) );
                $form .= wfCloseElement( 'td' ) . wfCloseElement( 'tr' );
                # End table
                $form .= wfCloseElement( 'table' );
                # Username
                $form .= wfElement( 'input', array( 'type' => 'hidden', 'name' => 'username', 'value' => $this->target ) );
                # Edit token 
                $form .= wfElement( 'input', array( 'type' => 'hidden', 'name' => 'token', 'value' => $wgUser->editToken( 'makepatrol' ) ) );
                $form .= '</fieldset>'; 
                $form .= wfCloseElement( 'form' ); 
                return $form;
        }
 
        /**
         * Add logging entries for the specified action
         * @param $user User receiving the action 
         * @param $comment Comment for the log item
         */
        function addLogItem( &$user, $comment = '', $oldgroups ) {
                global $wgUser; 
 
                $log = new LogPage( 'rights' );
                $newgroups = $user->getGroups();
                $log->addEntry( 'rights', Title::makeTitle( NS_USER, $user->getName() ), $comment, 
                        array( implode( ', ',$oldgroups ), implode( ', ',$newgroups ) ) );
        }
 
        /**
         * Show the bot status log entries for the specified user
         * @param $user User to show the log for
         */
        function showLogEntries( &$user ) {
                global $wgOut;
                $title = $user->getUserPage();
                $wgOut->addHtml( wfElement( 'h2', NULL, htmlspecialchars( LogPage::logName( 'rights' ) ) ) );
                $logViewer = new LogViewer( new LogReader( new FauxRequest( array( 'page' => $title->getPrefixedText(), 'type' => 'rights' ) ) ) );
                $logViewer->showList( $wgOut );
        }
 
}

[edit] See also

[edit] Licensing

© GPL, Stig Meireles Johansen, 2007

Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox