https://www.mediawiki.org/wiki/Special:Code/MediaWiki/106383

Revision: 106383
Author:   dantman
Date:     2011-12-15 22:10:09 +0000 (Thu, 15 Dec 2011)
Log Message:
-----------
Commit my old NoBogusUserpages extension as-is.

Added Paths:
-----------
    trunk/extensions/NoBogusUserpages/
    trunk/extensions/NoBogusUserpages/NoBogusUserpages.body.php
    trunk/extensions/NoBogusUserpages/NoBogusUserpages.i18n.php
    trunk/extensions/NoBogusUserpages/NoBogusUserpages.php

Added: trunk/extensions/NoBogusUserpages/NoBogusUserpages.body.php
===================================================================
--- trunk/extensions/NoBogusUserpages/NoBogusUserpages.body.php                 
        (rev 0)
+++ trunk/extensions/NoBogusUserpages/NoBogusUserpages.body.php 2011-12-15 
22:10:09 UTC (rev 106383)
@@ -0,0 +1,51 @@
+<?php
+ /**
+ * NoBogusUserpages
+ * @package NoBogusUserpages
+ * @author Daniel Friesen (http://www.mediawiki.org/wiki/User:Dantman) 
<[email protected]>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 
2.0 or later
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
USA
+ */
+
+if( !defined( 'MEDIAWIKI' ) ) die( "This is an extension to the MediaWiki 
package and cannot be run standalone." );
+
+function efNoBogusUserpagesUserCan( $title, $user, $action, $result ) {
+       global $wgVersion;
+       // If we're not in the user namespace,
+       // or we're not trying to edit,
+       // or the page already exists,
+       // or we are allowed to create bogus userpages
+       // then just let MediaWiki continue. 
+       if( $title->getNamespace() != NS_USER
+        || $action != 'create'
+        || $user->isAllowed('createbogususerpage') ) return true;
+       $userTitle = explode( '/', $title->getText(), 2 );
+       $userName = $userTitle[0];
+       // Don't block the creation of IP userpages if the page is for a IPv4 
or IPv6 page.
+       if( User::isIP($userName) || User::isIPv6($userName) ) return true;
+       // Check if the user exists, if it says the user is anon,
+       // but we know we're not on an ip page, then the user does not exist.
+       // And therefore, we block creation.
+       $user = User::newFromName( $userName );
+       if( $user->isAnon() ) {
+               // Output a value proper for the version of MW we're on.
+               $result = version_compare( $wgVersion, '1.12a', '<' )
+                       ? false
+                       : 'badaccess-bogususerpage';
+               return false;
+       }
+       return true;
+}
\ No newline at end of file

Added: trunk/extensions/NoBogusUserpages/NoBogusUserpages.i18n.php
===================================================================
--- trunk/extensions/NoBogusUserpages/NoBogusUserpages.i18n.php                 
        (rev 0)
+++ trunk/extensions/NoBogusUserpages/NoBogusUserpages.i18n.php 2011-12-15 
22:10:09 UTC (rev 106383)
@@ -0,0 +1,29 @@
+<?php
+ /**
+ * NoBogusUserpages
+ * @package NoBogusUserpages
+ * @author Daniel Friesen (http://www.mediawiki.org/wiki/User:Dantman) 
<[email protected]>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 
2.0 or later
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
USA
+ */
+
+if( !defined( 'MEDIAWIKI' ) ) die( "This is an extension to the MediaWiki 
package and cannot be run standalone." );
+
+$messages = array(
+       'en' => array(
+               '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.'
+       )
+);
\ No newline at end of file

Added: trunk/extensions/NoBogusUserpages/NoBogusUserpages.php
===================================================================
--- trunk/extensions/NoBogusUserpages/NoBogusUserpages.php                      
        (rev 0)
+++ trunk/extensions/NoBogusUserpages/NoBogusUserpages.php      2011-12-15 
22:10:09 UTC (rev 106383)
@@ -0,0 +1,53 @@
+<?php
+ /**
+ * NoBogusUserpages
+ * @package NoBogusUserpages
+ * @author Daniel Friesen (http://www.mediawiki.org/wiki/User:Dantman) 
<[email protected]>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 
2.0 or later
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
USA
+ */
+
+if( !defined( 'MEDIAWIKI' ) ) die( "This is an extension to the MediaWiki 
package and cannot be run standalone." );
+
+$wgExtensionCredits['other'][] = array (
+       "name" => "NoBogusUserpages",
+       "url" => "http://www.mediawiki.org/wiki/Extension:NoBogusUserpages";,
+       "author" => "[http://www.mediawiki.org/wiki/User:Dantman Daniel 
Friesen] [mailto:daniel%20friesen%20%[email protected]%3E 
<[email protected]>]",
+       "description" => "Restricts creation of userpages for which a user does 
not exist by those without rights to do so."
+);
+
+$wgAvailableRights[] = 'createbogususerpage';
+$wgGroupPermissions['*'    ]['createbogususerpage'] = false;
+$wgGroupPermissions['sysop']['createbogususerpage'] = true;
+
+require_once( dirname(__FILE__).'/NoBogusUserpages.body.php' );
+$wgExtensionFunctions[] = 'efNoBogusUserpagesSetup';
+
+function efNoBogusUserpagesSetup() {
+       global $wgMessageCache, $wgVersion;
+       
+       require_once( dirname(__FILE__).'/NoBogusUserpages.i18n.php' );
+       $wgMessageCache->addMessagesByLang($messages);
+       
+       // Anything older than 1.6 wont' work.
+       wfUseMW( '1.6' );
+       if( version_compare( $wgVersion, '1.12a', '<' ) )
+               // We are in pre 1.12, use the old hook.
+               $wgHooks['userCan'][] = 'efNoBogusUserpagesUserCan';
+       else
+               // We are in 1.12, use the new hook which allows for a custom 
message.
+               $wgHooks['getUserPermissionsErrors'][] = 
'efNoBogusUserpagesUserCan';
+}
\ No newline at end of file


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to