r35832 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r35831‎ | r35832 | r35833 >
Date:00:04, 4 June 2008
Author:siebrand
Status:old
Tags:
Comment:
* add hook code to class file
* move 3 globals into class method. Could get rid of another ($wgNewUserMinorEdit) if renamed and default false. Would break backward compatibility, though
* fix big in 'description' in credits (page would never exist)
* bump version and date
Modified paths:
  • /trunk/extensions/NewUserMessage/NewUserMessage.class.php (added) (history)
  • /trunk/extensions/NewUserMessage/NewUserMessage.class.php (added) (history)
  • /trunk/extensions/NewUserMessage/NewUserMessage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/NewUserMessage/NewUserMessage.php
@@ -12,70 +12,35 @@
1313 if (!defined('MEDIAWIKI'))
1414 die('Not an entry point.');
1515
16 -define('NEWUSERMESSAGE_VERSION','1.1.2, 2008-05-13');
 16+define('NEWUSERMESSAGE_VERSION','1.2, 2008-06-04');
1717
1818 // Specify a template to wrap the new user message within
1919 $wgNewUserMessageTemplate = 'MediaWiki:NewUserMessage';
2020
 21+// Should the new user message creation be a minor edit?
 22+$wgNewUserMinorEdit = true;
 23+
2124 // Set the username of the user that makes the edit on user talk pages. If
2225 // this user does not exist, the new user will show up as editing user.
23 -$wgNewUserMessageEditor = 'Admin';
 26+// default: $wgNewUserMessageEditor = 'Admin';
2427
2528 // Edit summary for the recent changes entry of a new users message
26 -$wgNewUserEditSummary = "Adding [[$wgNewUserMessageTemplate|welcome message]] to new user's talk page";
 29+// default: $wgNewUserEditSummary = "Adding [[$wgNewUserMessageTemplate|welcome message]] to new user's talk page";
2730
2831 // Specify whether or not the new user message creation should show up in recent changes
29 -$wgNewUserSupressRC = false;
 32+// default: $wgNewUserSupressRC = false;
3033
31 -// Should the new user message creation be a minor edit?
32 -$wgNewUserMinorEdit = true;
 34+$dir = dirname(__FILE__) . '/';
 35+$wgExtensionMessagesFiles['NewUserMessage'] = $dir . 'NewUserMessage.i18n.php';
 36+$wgAutoloadClasses['NewUserMessage'] = $dir . 'NewUserMessage.class.php';
3337
 38+$wgHooks['AddNewAccount'][] = 'NewUserMessage::createNewUserMessage';
3439
35 -
36 -$wgExtensionMessagesFiles['NewUserMessage'] = dirname(__FILE__) . '/NewUserMessage.i18n.php';
37 -$wgHooks['AddNewAccount'][] = 'wfCreateNewUserMessage';
38 -
3940 $wgExtensionCredits['other'][] = array(
4041 'name' => 'NewUserMessage',
4142 'version' => NEWUSERMESSAGE_VERSION,
4243 'author' => "[http://www.organicdesign.co.nz/User:Nad Nad]",
43 - 'description' => "Add a [[$wgNewUserMessageTemplate|message]] to newly created user's talk pages",
 44+ 'description' => "Add a [[MediaWiki:NewUserMessage|message]] to newly created user's talk pages",
4445 'descriptionmsg' => 'newusermessage-desc',
4546 'url' => 'http://www.mediawiki.org/wiki/Extension:NewUserMessage',
4647 );
47 -
48 -/*
49 - * Add the template message if the users talk page doesn't already exist
50 - */
51 -function wfCreateNewUserMessage($user) {
52 - global $wgNewUserMessageTemplate, $wgNewUserMinorEdit, $wgNewUserSupressRC, $wgNewUserEditSummary;
53 -
54 - $name = $user->getName();
55 - $talk = $user->getTalkPage();
56 -
57 - if (!$talk->exists()) {
58 - global $wgUser, $wgNewUserMessageEditor;
59 -
60 - $article = new Article($talk);
61 -
62 - // Need to make the edit on the user talk page in another
63 - // user's context. Park the current user object and create
64 - // a user object for $wgNewUserMessageEditor. If that user
65 - // does not exist, make the edit with as the new user
66 - // anyway.
67 - $parkedWgUser = $wgUser;
68 - $wgUser = User::newFromName( $wgNewUserMessageEditor );
69 - if ( !$wgUser->idForName() ) {
70 - $wgUser = $parkedWgUser;
71 - }
72 -
73 - $flags = 0;
74 - if ($wgNewUserMinorEdit) $flags = $flags | EDIT_MINOR;
75 - if ($wgNewUserSupressRC) $flags = $flags | EDIT_SUPPRESS_RC;
76 -
77 - $article->doEdit('{'.'{'."$wgNewUserMessageTemplate|$name}}", $wgNewUserEditSummary, $flags);
78 - $wgUser = $parkedWgUser;
79 - }
80 -
81 - return true;
82 -}
Index: trunk/extensions/NewUserMessage/NewUserMessage.class.php
@@ -0,0 +1,52 @@
 2+<?php
 3+/** Extension:NewUserMessage
 4+ *
 5+ * @package MediaWiki
 6+ * @subpackage Extensions
 7+ *
 8+ * @author [http://www.organicdesign.co.nz/nad User:Nad]
 9+ * @license LGPL (http://www.gnu.org/copyleft/lesser.html)
 10+ * @copyright 2007-10-15 [http://www.organicdesign.co.nz/nad User:Nad]
 11+ */
 12+
 13+if (!defined('MEDIAWIKI'))
 14+ die('Not an entry point.');
 15+
 16+class NewUserMessage {
 17+ /*
 18+ * Add the template message if the users talk page doesn't already exist
 19+ */
 20+ static function createNewUserMessage($user) {
 21+ $name = $user->getName();
 22+ $talk = $user->getTalkPage();
 23+
 24+ if (!$talk->exists()) {
 25+ global $wgUser, $wgNewUserMessageEditor, $wgNewUserMessageTemplate,
 26+ $wgNewUserMinorEdit, $wgNewUserSupressRC, $wgNewUserEditSummary;
 27+
 28+ $article = new Article($talk);
 29+
 30+ // Need to make the edit on the user talk page in another
 31+ // user's context. Park the current user object and create
 32+ // a user object for $wgNewUserMessageEditor. If that user
 33+ // does not exist, make the edit with as the new user
 34+ // anyway.
 35+ $parkedWgUser = $wgUser;
 36+ $wgUser = User::newFromName( $wgNewUserMessageEditor );
 37+ if ( !$wgUser->idForName() ) {
 38+ $wgUser = $parkedWgUser;
 39+ }
 40+
 41+ $flags = 0;
 42+ if ($wgNewUserMinorEdit) $flags = $flags | EDIT_MINOR;
 43+ if ($wgNewUserSupressRC) $flags = $flags | EDIT_SUPPRESS_RC;
 44+ if (!$wgNewUserMessageEditor) $wgNewUserMessageEditor = 'Admin';
 45+ if (!$wgNewUserMessageTemplate) $wgNewUserMessageTemplate = 'MediaWiki:NewUserMessage';
 46+ if (!$wgNewUserEditSummary) $wgNewUserEditSummary = "Adding [[$wgNewUserMessageTemplate|welcome message]] to new user's talk page";
 47+
 48+ $article->doEdit('{'.'{'."$wgNewUserMessageTemplate|$name}}", $wgNewUserEditSummary, $flags);
 49+ $wgUser = $parkedWgUser;
 50+ }
 51+ return true;
 52+ }
 53+}
Property changes on: trunk/extensions/NewUserMessage/NewUserMessage.class.php
___________________________________________________________________
Added: svn:eol-style
154 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r35835Fix on r35832. Re-add pre-set of globals to prevent register_globals exploits...siebrand00:20, 4 June 2008

Status & tagging log