Index: branches/REL1_17/extensions/NoBogusUserpages/NoBogusUserpages.php |
— | — | @@ -0,0 +1,63 @@ |
| 2 | +<?php |
| 3 | + /** |
| 4 | + * NoBogusUserpages |
| 5 | + * @package NoBogusUserpages |
| 6 | + * @author Daniel Friesen (http://www.mediawiki.org/wiki/User:Dantman) <mediawiki@danielfriesen.name> |
| 7 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 8 | + * |
| 9 | + * This library is free software; you can redistribute it and/or |
| 10 | + * modify it under the terms of the GNU General Public |
| 11 | + * License as published by the Free Software Foundation; either |
| 12 | + * version 2.1 of the License, or (at your option) any later version. |
| 13 | + * |
| 14 | + * This library is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | + * General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU General Public |
| 20 | + * License along with this library; if not, write to the Free Software |
| 21 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
| 22 | + */ |
| 23 | + |
| 24 | +if( !defined( 'MEDIAWIKI' ) ) die( "This is an extension to the MediaWiki package and cannot be run standalone." ); |
| 25 | + |
| 26 | +$wgExtensionCredits['other'][] = array ( |
| 27 | + "name" => "NoBogusUserpages", |
| 28 | + "url" => "http://www.mediawiki.org/wiki/Extension:NoBogusUserpages", |
| 29 | + "author" => "[http://www.mediawiki.org/wiki/User:Dantman Daniel Friesen] [mailto:Daniel%20Friesen%20%3Cmediawiki@danielfriesen.name%3E <mediawiki@danielfriesen.name>]", |
| 30 | + "descriptionmsg" => 'nobogususerpages-desc', |
| 31 | +); |
| 32 | + |
| 33 | +$wgAvailableRights[] = 'createbogususerpage'; |
| 34 | +$wgGroupPermissions['*' ]['createbogususerpage'] = false; |
| 35 | +$wgGroupPermissions['sysop']['createbogususerpage'] = true; |
| 36 | +$wgExtensionMessagesFiles['NoBogusUserpages'] = dirname(__FILE__) . '/NoBogusUserpages.i18n.php'; |
| 37 | +$wgHooks['getUserPermissionsErrors'][] = 'efNoBogusUserpagesUserCan'; |
| 38 | + |
| 39 | +function efNoBogusUserpagesUserCan( $title, $user, $action, &$result ) { |
| 40 | + // If we're not in the user namespace, |
| 41 | + // or we're not trying to edit, |
| 42 | + // or the page already exists, |
| 43 | + // or we are allowed to create bogus userpages |
| 44 | + // then just let MediaWiki continue. |
| 45 | + if ( $title->getNamespace() != NS_USER |
| 46 | + || $action != 'create' |
| 47 | + || $user->isAllowed('createbogususerpage') ) return true; |
| 48 | + |
| 49 | + $userTitle = explode( '/', $title->getText(), 2 ); |
| 50 | + $userName = $userTitle[0]; |
| 51 | + |
| 52 | + // Don't block the creation of IP userpages if the page is for a IPv4 or IPv6 page. |
| 53 | + if ( User::isIP( $userName ) ) return true; |
| 54 | + |
| 55 | + // Check if the user exists, if it says the user is anon, |
| 56 | + // but we know we're not on an ip page, then the user does not exist. |
| 57 | + // And therefore, we block creation. |
| 58 | + $user = User::newFromName( $userName ); |
| 59 | + if ( $user->isAnon() ) { |
| 60 | + $result = 'badaccess-bogususerpage'; |
| 61 | + return false; |
| 62 | + } |
| 63 | + return true; |
| 64 | +} |
Index: branches/REL1_17/extensions/NoBogusUserpages/NoBogusUserpages.i18n.php |
— | — | @@ -0,0 +1,28 @@ |
| 2 | +<?php |
| 3 | + /** |
| 4 | + * NoBogusUserpages |
| 5 | + * @package NoBogusUserpages |
| 6 | + * @author Daniel Friesen (http://www.mediawiki.org/wiki/User:Dantman) <mediawiki@danielfriesen.name> |
| 7 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 8 | + * |
| 9 | + * This library is free software; you can redistribute it and/or |
| 10 | + * modify it under the terms of the GNU General Public |
| 11 | + * License as published by the Free Software Foundation; either |
| 12 | + * version 2.1 of the License, or (at your option) any later version. |
| 13 | + * |
| 14 | + * This library is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | + * General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU General Public |
| 20 | + * License along with this library; if not, write to the Free Software |
| 21 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
| 22 | + */ |
| 23 | + |
| 24 | +if( !defined( 'MEDIAWIKI' ) ) die( "This is an extension to the MediaWiki package and cannot be run standalone." ); |
| 25 | + |
| 26 | +$messages['en'] = array( |
| 27 | + 'nobogususerpages-desc' => "Restricts creation of userpages for which a user does not exist by those without rights to do so.", |
| 28 | + 'badaccess-bogususerpage' => 'The user this userpage is meant for does not exist. You do not have the rights to be able to create a bogus userpage.', |
| 29 | +); |
\ No newline at end of file |
Index: branches/REL1_18/extensions/NoBogusUserpages/NoBogusUserpages.i18n.php |
— | — | @@ -0,0 +1,28 @@ |
| 2 | +<?php |
| 3 | + /** |
| 4 | + * NoBogusUserpages |
| 5 | + * @package NoBogusUserpages |
| 6 | + * @author Daniel Friesen (http://www.mediawiki.org/wiki/User:Dantman) <mediawiki@danielfriesen.name> |
| 7 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 8 | + * |
| 9 | + * This library is free software; you can redistribute it and/or |
| 10 | + * modify it under the terms of the GNU General Public |
| 11 | + * License as published by the Free Software Foundation; either |
| 12 | + * version 2.1 of the License, or (at your option) any later version. |
| 13 | + * |
| 14 | + * This library is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | + * General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU General Public |
| 20 | + * License along with this library; if not, write to the Free Software |
| 21 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
| 22 | + */ |
| 23 | + |
| 24 | +if( !defined( 'MEDIAWIKI' ) ) die( "This is an extension to the MediaWiki package and cannot be run standalone." ); |
| 25 | + |
| 26 | +$messages['en'] = array( |
| 27 | + 'nobogususerpages-desc' => "Restricts creation of userpages for which a user does not exist by those without rights to do so.", |
| 28 | + 'badaccess-bogususerpage' => 'The user this userpage is meant for does not exist. You do not have the rights to be able to create a bogus userpage.', |
| 29 | +); |
\ No newline at end of file |
Index: branches/REL1_18/extensions/NoBogusUserpages/NoBogusUserpages.php |
— | — | @@ -0,0 +1,63 @@ |
| 2 | +<?php |
| 3 | + /** |
| 4 | + * NoBogusUserpages |
| 5 | + * @package NoBogusUserpages |
| 6 | + * @author Daniel Friesen (http://www.mediawiki.org/wiki/User:Dantman) <mediawiki@danielfriesen.name> |
| 7 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 8 | + * |
| 9 | + * This library is free software; you can redistribute it and/or |
| 10 | + * modify it under the terms of the GNU General Public |
| 11 | + * License as published by the Free Software Foundation; either |
| 12 | + * version 2.1 of the License, or (at your option) any later version. |
| 13 | + * |
| 14 | + * This library is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | + * General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU General Public |
| 20 | + * License along with this library; if not, write to the Free Software |
| 21 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
| 22 | + */ |
| 23 | + |
| 24 | +if( !defined( 'MEDIAWIKI' ) ) die( "This is an extension to the MediaWiki package and cannot be run standalone." ); |
| 25 | + |
| 26 | +$wgExtensionCredits['other'][] = array ( |
| 27 | + "name" => "NoBogusUserpages", |
| 28 | + "url" => "http://www.mediawiki.org/wiki/Extension:NoBogusUserpages", |
| 29 | + "author" => "[http://www.mediawiki.org/wiki/User:Dantman Daniel Friesen] [mailto:Daniel%20Friesen%20%3Cmediawiki@danielfriesen.name%3E <mediawiki@danielfriesen.name>]", |
| 30 | + "descriptionmsg" => 'nobogususerpages-desc', |
| 31 | +); |
| 32 | + |
| 33 | +$wgAvailableRights[] = 'createbogususerpage'; |
| 34 | +$wgGroupPermissions['*' ]['createbogususerpage'] = false; |
| 35 | +$wgGroupPermissions['sysop']['createbogususerpage'] = true; |
| 36 | +$wgExtensionMessagesFiles['NoBogusUserpages'] = dirname(__FILE__) . '/NoBogusUserpages.i18n.php'; |
| 37 | +$wgHooks['getUserPermissionsErrors'][] = 'efNoBogusUserpagesUserCan'; |
| 38 | + |
| 39 | +function efNoBogusUserpagesUserCan( $title, $user, $action, &$result ) { |
| 40 | + // If we're not in the user namespace, |
| 41 | + // or we're not trying to edit, |
| 42 | + // or the page already exists, |
| 43 | + // or we are allowed to create bogus userpages |
| 44 | + // then just let MediaWiki continue. |
| 45 | + if ( $title->getNamespace() != NS_USER |
| 46 | + || $action != 'create' |
| 47 | + || $user->isAllowed('createbogususerpage') ) return true; |
| 48 | + |
| 49 | + $userTitle = explode( '/', $title->getText(), 2 ); |
| 50 | + $userName = $userTitle[0]; |
| 51 | + |
| 52 | + // Don't block the creation of IP userpages if the page is for a IPv4 or IPv6 page. |
| 53 | + if ( User::isIP( $userName ) ) return true; |
| 54 | + |
| 55 | + // Check if the user exists, if it says the user is anon, |
| 56 | + // but we know we're not on an ip page, then the user does not exist. |
| 57 | + // And therefore, we block creation. |
| 58 | + $user = User::newFromName( $userName ); |
| 59 | + if ( $user->isAnon() ) { |
| 60 | + $result = 'badaccess-bogususerpage'; |
| 61 | + return false; |
| 62 | + } |
| 63 | + return true; |
| 64 | +} |