Skip to content

Commit

Permalink
Prep for Composer support
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmontalvo3 committed Jun 6, 2014
1 parent 5e7dd67 commit a736bbf
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 48 deletions.
43 changes: 43 additions & 0 deletions TalkRight.body.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Main class for the Talkright MediaWiki extension
* @author Marc Noirot - marc dot noirot at gmail
* @author P.Levêque - User:Phillev
* @author James Montalvo - User:Jamesmontalvo3
*
*
*/
class TalkRight {

/**
* Bypass edit restriction when EDITING pages if user has 'talk' right and page is a talk (discussion) page.
* @param $&editPage the page edition object
* @return true to resume edition to normal operation
*/
static function alternateEdit( $editPage ) {
global $wgOut, $wgUser, $wgRequest, $wgTitle;
if ( $wgTitle->isTalkPage() && $wgUser->isAllowed( 'talk' ) ) {
array_push( $wgUser->mRights, 'edit' );
}
return true;
}

/**
* Bypass edit restriction when VIEWING pages if user has 'talk' right and page is a talk (discussion) page.
* This is probably not the ideal hook to use. I just needed one earlier than creation of section links, edit tab and add topic tab
* @param &$parser parser object, used to gain access to User and Title objects
* @param &$text unused
* @param &$strip_state unused
* @return true and false both seemed to work. [[Manual:Hooks/ParserBeforeStrip]] doesn't indicate what return value affects
*/
static function giveEditRightsWhenViewingTalkPages ( &$parser, &$test, &$test ) {

$user = $parser->getUser();
if ( $parser->getTitle()->isTalkPage() && $user->isAllowed( 'talk' ) ) {
array_push( $user->mRights, 'edit' );
}

return true;
}

}
57 changes: 9 additions & 48 deletions TalkRight.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,61 +9,22 @@
* the editing of articles, to create finer permissions by adding the 'talk' right.
*
*/

if ( !defined( 'MEDIAWIKI' ) ) {
echo <<<EOT
To install the TalkRight extension, put the following line in LocalSettings.php:
require_once( "\$IP/extensions/TalkRight/TalkRight.php" );
EOT;
exit( 1 );
die( 'Invalid entry point.' );
}

$wgExtensionCredits['other'][] = array(

# Extension credits
$GLOBALS['wgExtensionCredits']['other'][] = array(
'name' => 'TalkRight',
'version' => '1.4.1',
'version' => '1.5.1',
'author' => array('P.Lev&ecirc;que', 'Marc Noirot', 'James Montalvo'),
'description' => 'Adds a <tt>talk</tt> permission independent from article edition',
'url' => 'http://www.mediawiki.org/wiki/Extension:Talkright',
);

# Register hooks
$wgHooks['AlternateEdit'][] = 'TalkRight::alternateEdit';
$wgHooks['ParserBeforeStrip'][] = 'TalkRight::giveEditRightsWhenViewingTalkPages';
$GLOBALS['wgHooks']['AlternateEdit'][] = 'TalkRight::alternateEdit';
$GLOBALS['wgHooks']['ParserBeforeStrip'][] = 'TalkRight::giveEditRightsWhenViewingTalkPages';

# Global 'talk' right
$wgAvailableRights[] = 'talk';

class TalkRight {

/**
* Bypass edit restriction when EDITING pages if user has 'talk' right and page is a talk (discussion) page.
* @param $&editPage the page edition object
* @return true to resume edition to normal operation
*/
static function alternateEdit( $editPage ) {
global $wgOut, $wgUser, $wgRequest, $wgTitle;
if ( $wgTitle->isTalkPage() && $wgUser->isAllowed( 'talk' ) ) {
array_push( $wgUser->mRights, 'edit' );
}
return true;
}

/**
* Bypass edit restriction when VIEWING pages if user has 'talk' right and page is a talk (discussion) page.
* This is probably not the ideal hook to use. I just needed one earlier than creation of section links, edit tab and add topic tab
* @param &$parser parser object, used to gain access to User and Title objects
* @param &$text unused
* @param &$strip_state unused
* @return true and false both seemed to work. [[Manual:Hooks/ParserBeforeStrip]] doesn't indicate what return value affects
*/
static function giveEditRightsWhenViewingTalkPages ( &$parser, &$test, &$test ) {

$user = $parser->getUser();
if ( $parser->getTitle()->isTalkPage() && $user->isAllowed( 'talk' ) ) {
array_push( $user->mRights, 'edit' );
}

return true;
}

}
$GLOBALS['wgAvailableRights'][] = 'talk';
35 changes: 35 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "enterprisemediawiki/talk-right",
"type": "mediawiki-extension",
"description": "Makes editing MediaWiki talk pages a distinct action from editing articles",
"keywords": [
"MediaWiki",
"Discussion"
],
"homepage": "https://www.mediawiki.org/wiki/Extension:TalkRight",
"license": "GPL-2.0+",
"authors": [
{
"name": "P.Lev&ecirc;que",
"role": "Original developer"
},
{
"name": "Marc Noirot",
"role": "Developer"
},
{
"name": "James Montalvo",
"role": "Current developer"
}
],
"support": {
"issues": "https://bugzilla.wikimedia.org/",
"github": "https://github.com/enterprisemediawiki/TalkRight/issues"
},
"require": {
"composer/installers": ">=1.0.1"
},
"autoload": {
"files": ["TalkRight.php"]
}
}

0 comments on commit a736bbf

Please sign in to comment.