Hello,
I' want to user userCan hook on every page, so I made an extension which then calls this hook. I don't really know much about this hook so I need some information.
How can I prevent access to users who are not logged in?
I tried with code bellow, but I get an empty page (wiki doesn't show):
# If user is logged in
if( !$wgUser->isLoggedIn() ) {
$wgOut->loginToUse();
return;
}
How is that with $action parameter? I only find 'edit', 'move'. What about 'read' word, does it exist.
Everything must be done with this extension cos I don't want to change mediaWiki files.
function efAdminPagesRestrictionsHook() {
global $wgHooks;
$wgHooks['userCan'][] = 'RestrictHookUserCan';
}
function RestrictHookUserCan( &$title, &$user, $action, &$result ) {
if( $action == 'edit' ) {
#code
}
if( $action == 'read' ) {
#code
}
if( $action == 'create' ) {
#code
}
}
Lp
Hi,
the logic of processing your hook function is:
- if your function returns false other hooks will not be processed (those with a greater index in $wgHooks['userCan']) and the result will be found in $result (passed by reference), default logic (standard permissions like createtalk, move,...) is not used - if your function returns true hooks with a greater index will be processed; if there are no more hooks or all of them return true then the default logic is used
$result can be only true or false - the purpose of this hook is to determine if a user can perform an action. It is not meant for generating any output. This hook is called before constructing a page. If $result is false, Wiki.php calls $wgOut->loginToUse() on its own.
What is more important, you never know what this hook was called for: to display a page or to see if 'edit' or 'move' tabs should be available to a user.
So you must not print any output in your hook function.
So it goes, as far as I can see. -- Petr
http://meta.wikimedia.org/wiki/NamespacePermissions_Extension
2006/7/19, Borut Tomažin debijan@gmail.com:
Hello,
I' want to user userCan hook on every page, so I made an extension which then calls this hook. I don't really know much about this hook so I need some information.
How can I prevent access to users who are not logged in?
I tried with code bellow, but I get an empty page (wiki doesn't show):
# If user is logged in
if( !$wgUser->isLoggedIn() ) {
$wgOut->loginToUse();
return;
}
How is that with $action parameter? I only find 'edit', 'move'. What about 'read' word, does it exist.
Everything must be done with this extension cos I don't want to change mediaWiki files.
function efAdminPagesRestrictionsHook() {
global $wgHooks; $wgHooks['userCan'][] = 'RestrictHookUserCan';
}
function RestrictHookUserCan( &$title, &$user, $action, &$result ) {
if( $action == 'edit' ) { #code } if( $action == 'read' ) { #code } if( $action == 'create' ) { #code }
}
Lp
MediaWiki-l mailing list MediaWiki-l@Wikimedia.org http://mail.wikipedia.org/mailman/listinfo/mediawiki-l
mediawiki-l@lists.wikimedia.org