r86015 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86014‎ | r86015 | r86016 >
Date:23:57, 13 April 2011
Author:nimishg
Status:deferred (Comments)
Tags:
Comment:
Added code for CustomUserSignup, extension to allow custom user signup flows
Modified paths:
  • /trunk/extensions/CustomUserSignup/CustomUserSignup.hooks.php (added) (history)
  • /trunk/extensions/CustomUserSignup/CustomUserSignup.i18n.php (added) (history)
  • /trunk/extensions/CustomUserSignup/CustomUserSignup.php (added) (history)
  • /trunk/extensions/CustomUserSignup/CustomUserTemplate.php (added) (history)
  • /trunk/extensions/CustomUserSignup/README (added) (history)

Diff [purge]

Index: trunk/extensions/CustomUserSignup/CustomUserSignup.i18n.php
@@ -0,0 +1,10 @@
 2+<?php
 3+$messages = array();
 4+
 5+/** English
 6+ * @author Nimish Gautam
 7+ */
 8+$messages['en'] = array(
 9+ 'customusersignup' => 'Custom User Signup',
 10+ 'customusersignup-desc' => 'Allows for customizable messages during the account creation process',
 11+);
\ No newline at end of file
Property changes on: trunk/extensions/CustomUserSignup/CustomUserSignup.i18n.php
___________________________________________________________________
Added: svn:eol-style
112 + native
Index: trunk/extensions/CustomUserSignup/CustomUserSignup.php
@@ -0,0 +1,23 @@
 2+<?php
 3+$wgExtensionCredits['other'][] = array(
 4+ 'path' => __FILE__,
 5+ 'name' => 'CustomUserSignup',
 6+ 'author' => array(
 7+ 'Nimish Gautam',
 8+ ),
 9+ 'version' => '0.1.0',
 10+ 'descriptionmsg' => 'customusersignup-desc',
 11+ 'url' => 'http://www.mediawiki.org/wiki/Extension:CustomUserSignup'
 12+);
 13+
 14+// Autoloading
 15+$dir = dirname( __FILE__ ) . '/';
 16+$wgAutoloadClasses['CustomUserSignupHooks'] = $dir . 'CustomUserSignup.hooks.php';
 17+$wgAutoloadClasses['CustomUserloginTemplate'] = $dir . 'CustomUserTemplate.php';
 18+$wgAutoloadClasses['CustomUsercreateTemplate'] = $dir . 'CustomUserTemplate.php';
 19+$wgExtensionMessagesFiles['CustomUserSignup'] = $dir . 'CustomUserSignup.i18n.php';
 20+
 21+// Hooks
 22+$wgHooks['UserCreateForm'][] = 'CustomUserSignupHooks::userCreateForm';
 23+$wgHooks['UserLoginForm'][] = 'CustomUserSignupHooks::userCreateForm';
 24+$wgHooks['BeforeWelcomeCreation'][] = 'CustomUserSignupHooks::welcomeScreen';
Property changes on: trunk/extensions/CustomUserSignup/CustomUserSignup.php
___________________________________________________________________
Added: svn:eol-style
125 + native
Index: trunk/extensions/CustomUserSignup/CustomUserSignup.hooks.php
@@ -0,0 +1,48 @@
 2+<?php
 3+/**
 4+ * Hooks for CustomUserSignup
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ */
 9+
 10+class CustomUserSignupHooks {
 11+
 12+ public static function userCreateForm(&$template){
 13+ if(isset($_GET["campaign"])){
 14+ $campaign = $_GET["campaign"];
 15+ $newTemplate;
 16+ if(get_class($template) == "UserloginTemplate"){
 17+ $newTemplate = new CustomUserloginTemplate();
 18+ $template->data["action"] = "{$template->data["action"]}&campaign=$campaign";
 19+ $template->data["link"] =
 20+ preg_replace("/type\=signup/", "campaign=$campaign&amp;type=signup", $template->data["link"]);
 21+ }
 22+ else if(get_class($template) == "UsercreateTemplate"){
 23+ $newTemplate = new CustomUsercreateTemplate();
 24+ $template->data["action"] = "{$template->data["action"]}&campaign=$campaign";
 25+ $template->data["link"] =
 26+ preg_replace("/type\=login\&amp;/", "type=login&amp;campaign=$campaign&amp;", $template->data["link"]);
 27+ }
 28+ else return true;
 29+
 30+ $newTemplate->data = $template->data;
 31+ $newTemplate->translator = $template->translator;
 32+ $template = $newTemplate;
 33+ }
 34+
 35+ return true;
 36+ }
 37+
 38+ public static function welcomeScreen(&$welcome_creation_msg, &$injected_html){
 39+ if(isset($_GET["campaign"])){
 40+ $campaign = $_GET["campaign"];
 41+
 42+ if(wfMsg( "customusertemplate-$campaign-welcomecreation") != "&lt;customusertemplate-$campaign-welcomecreation&gt;"){
 43+ $welcome_creation_msg = "customusertemplate-$campaign-welcomecreation";
 44+ }
 45+ }
 46+ return true;
 47+ }
 48+
 49+}
\ No newline at end of file
Property changes on: trunk/extensions/CustomUserSignup/CustomUserSignup.hooks.php
___________________________________________________________________
Added: svn:eol-style
150 + native
Index: trunk/extensions/CustomUserSignup/CustomUserTemplate.php
@@ -0,0 +1,86 @@
 2+<?php
 3+
 4+class CustomUserloginTemplate extends UserloginTemplate{
 5+
 6+ protected $campaign = null;
 7+
 8+ function __construct(){
 9+ parent::__construct();
 10+ if(isset($_GET["campaign"])){
 11+ preg_match("/[A-Za-z0-9]+/", $_GET["campaign"], $matches);
 12+ $this->campaign = $matches[0];
 13+ }
 14+ }
 15+
 16+ function msg( $str ) {
 17+ //doesn't exist
 18+ if($this->campaign && (wfMsg( "customusertemplate-{$this->campaign}-$str" ) == "&lt;customusertemplate-{$this->campaign}-$str&gt;") ){
 19+ parent::msg( $str );
 20+ }
 21+ else{
 22+ $this->msgWikiCustom( "customusertemplate-{$this->campaign}-$str" );
 23+ }
 24+ }
 25+
 26+ function msgWiki( $str ) {
 27+ //doesn't exist
 28+ if($this->campaign && (wfMsg( "customusertemplate-{$this->campaign}-$str" ) == "&lt;customusertemplate-{$this->campaign}-$str&gt;") ){
 29+ parent::msgWiki( $str );
 30+ }
 31+ else{
 32+ $this->msgWikiCustom( "customusertemplate-{$this->campaign}-$str" );
 33+ }
 34+ }
 35+
 36+ function msgWikiCustom( $str ) {
 37+ global $wgParser, $wgOut;
 38+
 39+ $text = $this->translator->translate( $str );
 40+ $parserOutput = $wgParser->parse( $text, $wgOut->getTitle(),
 41+ $wgOut->parserOptions(), true );
 42+ echo $parserOutput->getText();
 43+ }
 44+
 45+}
 46+
 47+
 48+class CustomUsercreateTemplate extends UsercreateTemplate{
 49+protected $campaign = null;
 50+
 51+ function __construct(){
 52+ parent::__construct();
 53+ if(isset($_GET["campaign"])){
 54+ preg_match("/[A-Za-z0-9]+/", $_GET["campaign"], $matches);
 55+ $this->campaign = $matches[0];
 56+ }
 57+ }
 58+
 59+ function msg( $str ) {
 60+ //doesn't exist
 61+ if($this->campaign && (wfMsg( "customusertemplate-{$this->campaign}-$str" ) == "&lt;customusertemplate-{$this->campaign}-$str&gt;") ){
 62+ parent::msg( $str );
 63+ }
 64+ else{
 65+ $this->msgWikiCustom( "customusertemplate-{$this->campaign}-$str" );
 66+ }
 67+ }
 68+
 69+ function msgWiki( $str ) {
 70+ //doesn't exist
 71+ if($this->campaign && (wfMsg( "customusertemplate-{$this->campaign}-$str" ) == "&lt;customusertemplate-{$this->campaign}-$str&gt;") ){
 72+ parent::msgWiki( $str );
 73+ }
 74+ else{
 75+ $this->msgWikiCustom( "customusertemplate-{$this->campaign}-$str" );
 76+ }
 77+ }
 78+
 79+ function msgWikiCustom( $str ) {
 80+ global $wgParser, $wgOut;
 81+
 82+ $text = $this->translator->translate( $str );
 83+ $parserOutput = $wgParser->parse( $text, $wgOut->getTitle(),
 84+ $wgOut->parserOptions(), true );
 85+ echo $parserOutput->getText();
 86+ }
 87+}
\ No newline at end of file
Property changes on: trunk/extensions/CustomUserSignup/CustomUserTemplate.php
___________________________________________________________________
Added: svn:eol-style
188 + native
Index: trunk/extensions/CustomUserSignup/README
@@ -0,0 +1,8 @@
 2+This extension lets you customize the messages seen in the user login process based on passing a "campaign" variable
 3+in to the Special:UserLogin page.
 4+
 5+So, if you append "&campaign={campaign}" to the user login process, any message created in includes/templates/Userlogin.php can be
 6+overridden with MediaWiki:customusertemplate-{campaign}-{message}.
 7+
 8+ex: If you wanted to change the text seen at the end of the signup page (a message called 'signupend') for users signing up from
 9+the "foo" campaign, you would edit MediaWiki:customusertemplate-foo-signupend page, and this would be substituted
\ No newline at end of file

Follow-up revisions

RevisionCommit summaryAuthorDate
r86036CustomUserSignup: initial cleanupashley09:47, 14 April 2011
r86037CustomUserSignup: swap $_GET to $wgRequestashley09:52, 14 April 2011
r86102fixed wgRequest checks, used wfMessage->exists where appropriate, added custo...nimishg00:05, 15 April 2011

Comments

#Comment by Reedy (talk | contribs)   00:00, 14 April 2011

You shouldn't ever be using $_GET or $_POST directly

It also has mixed indenting, mixed code style (which isn't the MW style)

More often than not, using echo is the wrong thing to do

#Comment by Nikerabbit (talk | contribs)   07:44, 14 April 2011

If you are going to work on this, wfMessage->exists() could be useful.

#Comment by Nimish Gautam (talk | contribs)   00:12, 15 April 2011

Changes fixed in r86102; unfortunately, the parent classes (UsercreateTemplate and UserloginTemplate) echo things out directly, in order to overload their functions properly, it has to echo out at that point

Status & tagging log