diff --git a/TalkRight.body.php b/TalkRight.body.php new file mode 100644 index 0000000..e7d8924 --- /dev/null +++ b/TalkRight.body.php @@ -0,0 +1,43 @@ +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; + } + +} \ No newline at end of file diff --git a/TalkRight.php b/TalkRight.php index fcddcc7..d618051 100644 --- a/TalkRight.php +++ b/TalkRight.php @@ -9,61 +9,22 @@ * the editing of articles, to create finer permissions by adding the 'talk' right. * */ - if ( !defined( 'MEDIAWIKI' ) ) { - echo << 'TalkRight', - 'version' => '1.4.1', + 'version' => '1.5.1', 'author' => array('P.Levêque', 'Marc Noirot', 'James Montalvo'), 'description' => 'Adds a talk 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; - } - -} \ No newline at end of file +$GLOBALS['wgAvailableRights'][] = 'talk'; \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..ca1ec12 --- /dev/null +++ b/composer.json @@ -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ê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"] + } +}