r106410 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106409‎ | r106410 | r106411 >
Date:04:02, 16 December 2011
Author:dantman
Status:ok
Tags:
Comment:
Update the NoBogusUserpages extension to use proper i18n files and ditch the extra file and pre-1.12 compat.
Modified paths:
  • /trunk/extensions/NoBogusUserpages/NoBogusUserpages.body.php (deleted) (history)
  • /trunk/extensions/NoBogusUserpages/NoBogusUserpages.i18n.php (modified) (history)
  • /trunk/extensions/NoBogusUserpages/NoBogusUserpages.php (modified) (history)

Diff [purge]

Index: trunk/extensions/NoBogusUserpages/NoBogusUserpages.body.php
@@ -1,51 +0,0 @@
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
Index: trunk/extensions/NoBogusUserpages/NoBogusUserpages.i18n.php
@@ -22,8 +22,7 @@
2323
2424 if( !defined( 'MEDIAWIKI' ) ) die( "This is an extension to the MediaWiki package and cannot be run standalone." );
2525
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 - )
 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.',
3029 );
\ No newline at end of file
Index: trunk/extensions/NoBogusUserpages/NoBogusUserpages.php
@@ -26,28 +26,38 @@
2727 "name" => "NoBogusUserpages",
2828 "url" => "http://www.mediawiki.org/wiki/Extension:NoBogusUserpages",
2929 "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."
 30+ "descriptionmsg" => 'nobogususerpages-desc',
3131 );
3232
3333 $wgAvailableRights[] = 'createbogususerpage';
3434 $wgGroupPermissions['*' ]['createbogususerpage'] = false;
3535 $wgGroupPermissions['sysop']['createbogususerpage'] = true;
 36+$wgExtensionMessagesFiles['NoBogusUserpages'] = dirname(__FILE__) . '/NoBogusUserpages.i18n.php';
 37+$wgHooks['getUserPermissionsErrors'][] = 'efNoBogusUserpagesUserCan';
3638
37 -require_once( dirname(__FILE__).'/NoBogusUserpages.body.php' );
38 -$wgExtensionFunctions[] = 'efNoBogusUserpagesSetup';
39 -
40 -function efNoBogusUserpagesSetup() {
41 - global $wgMessageCache, $wgVersion;
 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;
4248
43 - require_once( dirname(__FILE__).'/NoBogusUserpages.i18n.php' );
44 - $wgMessageCache->addMessagesByLang($messages);
 49+ $userTitle = explode( '/', $title->getText(), 2 );
 50+ $userName = $userTitle[0];
4551
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
 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+}

Follow-up revisions

RevisionCommit summaryAuthorDate
r106953r106410: Consistency tweaks in preparation for adding extension to translatew...raymond16:09, 21 December 2011

Status & tagging log