Index: trunk/extensions/NoBogusUserpages/NoBogusUserpages.i18n.php |
— | — | @@ -0,0 +1,29 @@ |
| 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 = array( |
| 27 | + 'en' => array( |
| 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 | + ) |
| 30 | +); |
\ No newline at end of file |
Index: trunk/extensions/NoBogusUserpages/NoBogusUserpages.php |
— | — | @@ -0,0 +1,53 @@ |
| 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 | + "description" => "Restricts creation of userpages for which a user does not exist by those without rights to do so." |
| 31 | +); |
| 32 | + |
| 33 | +$wgAvailableRights[] = 'createbogususerpage'; |
| 34 | +$wgGroupPermissions['*' ]['createbogususerpage'] = false; |
| 35 | +$wgGroupPermissions['sysop']['createbogususerpage'] = true; |
| 36 | + |
| 37 | +require_once( dirname(__FILE__).'/NoBogusUserpages.body.php' ); |
| 38 | +$wgExtensionFunctions[] = 'efNoBogusUserpagesSetup'; |
| 39 | + |
| 40 | +function efNoBogusUserpagesSetup() { |
| 41 | + global $wgMessageCache, $wgVersion; |
| 42 | + |
| 43 | + require_once( dirname(__FILE__).'/NoBogusUserpages.i18n.php' ); |
| 44 | + $wgMessageCache->addMessagesByLang($messages); |
| 45 | + |
| 46 | + // Anything older than 1.6 wont' work. |
| 47 | + wfUseMW( '1.6' ); |
| 48 | + if( version_compare( $wgVersion, '1.12a', '<' ) ) |
| 49 | + // We are in pre 1.12, use the old hook. |
| 50 | + $wgHooks['userCan'][] = 'efNoBogusUserpagesUserCan'; |
| 51 | + else |
| 52 | + // We are in 1.12, use the new hook which allows for a custom message. |
| 53 | + $wgHooks['getUserPermissionsErrors'][] = 'efNoBogusUserpagesUserCan'; |
| 54 | +} |
\ No newline at end of file |
Index: trunk/extensions/NoBogusUserpages/NoBogusUserpages.body.php |
— | — | @@ -0,0 +1,51 @@ |
| 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 | +function efNoBogusUserpagesUserCan( $title, $user, $action, $result ) { |
| 27 | + global $wgVersion; |
| 28 | + // If we're not in the user namespace, |
| 29 | + // or we're not trying to edit, |
| 30 | + // or the page already exists, |
| 31 | + // or we are allowed to create bogus userpages |
| 32 | + // then just let MediaWiki continue. |
| 33 | + if( $title->getNamespace() != NS_USER |
| 34 | + || $action != 'create' |
| 35 | + || $user->isAllowed('createbogususerpage') ) return true; |
| 36 | + $userTitle = explode( '/', $title->getText(), 2 ); |
| 37 | + $userName = $userTitle[0]; |
| 38 | + // Don't block the creation of IP userpages if the page is for a IPv4 or IPv6 page. |
| 39 | + if( User::isIP($userName) || User::isIPv6($userName) ) return true; |
| 40 | + // Check if the user exists, if it says the user is anon, |
| 41 | + // but we know we're not on an ip page, then the user does not exist. |
| 42 | + // And therefore, we block creation. |
| 43 | + $user = User::newFromName( $userName ); |
| 44 | + if( $user->isAnon() ) { |
| 45 | + // Output a value proper for the version of MW we're on. |
| 46 | + $result = version_compare( $wgVersion, '1.12a', '<' ) |
| 47 | + ? false |
| 48 | + : 'badaccess-bogususerpage'; |
| 49 | + return false; |
| 50 | + } |
| 51 | + return true; |
| 52 | +} |
\ No newline at end of file |