Example #1
0
    /**
     * TODO: Add an option to disallow this extension to access your Facebook
     * information. This option could simply point you to your Facebook privacy
     * settings. This is necessary in case the user wants to perpetually browse
     * the wiki anonymously, while still being logged in to Facebook.
     *
     * NOTE: The above might be done now that we have checkboxes for which options
     * to update from fb. Haven't tested it though.
     */
    private function chooseNameForm($messagekey = 'fbconnect-chooseinstructions')
    {
        // Permissions restrictions.
        global $wgUser, $wgOut;
        $titleObj = SpecialPage::getTitleFor('Connect');
        if (wfReadOnly()) {
            $wgOut->readOnlyPage();
            return false;
        } elseif ($wgUser->isBlockedFromCreateAccount()) {
            LoginForm::userBlockedMessage();
            //this is not an explicitly static method but doesn't use $this and can be called like static (fixes RT#75589)
            return false;
        } elseif (count($permErrors = $titleObj->getUserPermissionsErrors('createaccount', $wgUser, true)) > 0) {
            $wgOut->showPermissionsErrorPage($permErrors, 'createaccount');
            return false;
        }
        // Allow other code to have a custom form here (so that this extension can be integrated with existing custom login screens).
        if (!wfRunHooks('SpecialConnect::chooseNameForm', array(&$this, &$messagekey))) {
            return false;
        }
        global $wgOut, $fbConnectOnly;
        // Connect to the Facebook API
        $fb = new FBConnectAPI();
        $fb_user = $fb->user();
        $userinfo = $fb->getUserInfo($fb_user);
        // Keep track of when the first option visible to the user is checked
        $checked = false;
        // Outputs the canonical name of the special page at the top of the page
        $this->outputHeader();
        // If a different $messagekey was passed (like 'wrongpassword'), use it instead
        $wgOut->addWikiMsg($messagekey);
        // TODO: Format the html a little nicer
        $wgOut->addHTML('
		<form action="' . $this->getTitle('ChooseName')->getLocalUrl() . '" method="POST">
			<fieldset id="mw-fbconnect-choosename">
				<legend>' . wfMsg('fbconnect-chooselegend') . '</legend>
				<table>');
        // Let them attach to an existing user if $fbConnectOnly allows it
        if (!$fbConnectOnly) {
            // Grab the UserName from the cookie if it exists
            global $wgCookiePrefix;
            $name = isset($_COOKIE[$wgCookiePrefix . 'UserName']) ? trim($_COOKIE[$wgCookiePrefix . 'UserName']) : '';
            // Build an array of attributes to update
            $updateOptions = array();
            foreach (self::$availableUserUpdateOptions as $option) {
                // Translate the MW parameter into a FB parameter
                $value = FBConnectUser::getOptionFromInfo($option, $userinfo);
                // If no corresponding value was received from Facebook, then continue
                if (!$value) {
                    continue;
                }
                // Build the list item for the update option
                $updateOptions[] = "<li><input name=\"wpUpdateUserInfo{$option}\" type=\"checkbox\" " . "value=\"1\" id=\"wpUpdateUserInfo{$option}\" /><label for=\"wpUpdateUserInfo{$option}\">" . wfMsgHtml("fbconnect-{$option}") . wfMsgExt('colon-separator', array('escapenoentities')) . " <i>{$value}</i></label></li>";
            }
            // Implode the update options into an unordered list
            $updateChoices = count($updateOptions) > 0 ? "<br />\n" . wfMsgHtml('fbconnect-updateuserinfo') . "\n<ul>\n" . implode("\n", $updateOptions) . "\n</ul>\n" : '';
            // Create the HTML for the "existing account" option
            $html = '<tr><td class="wm-label"><input name="wpNameChoice" type="radio" ' . 'value="existing" id="wpNameChoiceExisting"/></td><td class="mw-input">' . '<label for="wnNameChoiceExisting">' . wfMsg('fbconnect-chooseexisting') . '<br/>' . wfMsgHtml('fbconnect-chooseusername') . '<input name="wpExistingName" size="16" value="' . $name . '" id="wpExistingName"/>' . wfMsgHtml('fbconnect-choosepassword') . '<input name="wpExistingPassword" ' . 'size="" value="" type="password"/>' . $updateChoices . '</td></tr>';
            $wgOut->addHTML($html);
        }
        // Add the options for nick name, first name and full name if we can get them
        // TODO: Wikify the usernames (i.e. Full name should have an _ )
        foreach (array('nick', 'first', 'full') as $option) {
            $nickname = FBConnectUser::getOptionFromInfo($option . 'name', $userinfo);
            if ($nickname && $this->userNameOK($nickname)) {
                $wgOut->addHTML('<tr><td class="mw-label"><input name="wpNameChoice" type="radio" value="' . $option . ($checked ? '' : '" checked="checked') . '" id="wpNameChoice' . $option . '"/></td><td class="mw-input"><label for="wpNameChoice' . $option . '">' . wfMsg('fbconnect-choose' . $option, $nickname) . '</label></td></tr>');
                // When the first radio is checked, this flag is set and subsequent options aren't checked
                $checked = true;
            }
        }
        // The options for auto and manual usernames are always available
        $wgOut->addHTML('<tr><td class="mw-label"><input name="wpNameChoice" type="radio" value="auto" ' . ($checked ? '' : 'checked="checked" ') . 'id="wpNameChoiceAuto"/></td><td class="mw-input">' . '<label for="wpNameChoiceAuto">' . wfMsg('fbconnect-chooseauto', $this->generateUserName()) . '</label></td></tr><tr><td class="mw-label"><input name="wpNameChoice" type="radio" ' . 'value="manual" id="wpNameChoiceManual"/></td><td class="mw-input"><label ' . 'for="wpNameChoiceManual">' . wfMsg('fbconnect-choosemanual') . '</label>&nbsp;' . '<input name="wpName2" size="16" value="" id="wpName2"/></td></tr>' . '<tr><td></td><td class="mw-submit"><input type="submit" value="Log in" name="wpOK"/>' . '<input type="submit" value="Cancel" name="wpCancel"/></td></tr></table></fieldset></form>');
    }
 function mainLoginForm(&$specialConnect, $msg, $msgtype = 'error')
 {
     global $wgUser, $wgOut, $wgHiddenPrefs, $wgEnableEmail;
     global $wgCookiePrefix, $wgLoginLanguageSelector;
     global $wgAuth, $wgEmailConfirmToEdit, $wgCookieExpiration, $wgRequest;
     $this->msg = $msg;
     $this->msgtype = $msgtype;
     $tmpl = new ChooseNameTemplate();
     $tmpl->addInputItem('wpMarketingOptIn', 1, 'checkbox', 'tog-marketingallowed');
     $returnto = "";
     if (!empty($this->mReturnTo)) {
         $returnto = '&returnto=' . wfUrlencode($this->mReturnTo);
         if (!empty($this->mReturnToQuery)) {
             $returnto .= '&returntoquery=' . wfUrlencode($this->mReturnToQuery);
         }
     }
     $tmpl->set('actioncreate', $specialConnect->getTitle('ChooseName')->getLocalUrl($returnto));
     $tmpl->set('link', '');
     $tmpl->set('header', '');
     //$tmpl->set( 'name', $this->mUsername ); // intelligently defaulted below
     $tmpl->set('password', $this->mPassword);
     $tmpl->set('retype', $this->mRetype);
     $tmpl->set('actiontype', $this->mActionType);
     $tmpl->set('realname', $this->mRealName);
     $tmpl->set('domain', $this->mDomain);
     $tmpl->set('message', $msg);
     $tmpl->set('messagetype', $msgtype);
     $tmpl->set('createemail', $wgEnableEmail && $wgUser->isLoggedIn());
     $tmpl->set('userealname', !in_array('realname', $wgHiddenPrefs));
     $tmpl->set('useemail', $wgEnableEmail);
     $tmpl->set('emailrequired', $wgEmailConfirmToEdit);
     $tmpl->set('canreset', $wgAuth->allowPasswordChange());
     $tmpl->set('canremember', $wgCookieExpiration > 0);
     $tmpl->set('remember', $wgUser->getOption('rememberpassword') or $this->mRemember);
     $tmpl->set('birthyear', $this->wpBirthYear);
     $tmpl->set('birthmonth', $this->wpBirthMonth);
     $tmpl->set('birthday', $this->wpBirthDay);
     # Prepare language selection links as needed
     if ($wgLoginLanguageSelector) {
         $tmpl->set('languages', $this->makeLanguageSelector());
         if ($this->mLanguage) {
             $tmpl->set('uselang', $this->mLanguage);
         }
     }
     // Facebook-specific customizations below.
     global $fbConnectOnly;
     // Connect to the Facebook API
     $fb = new FBConnectAPI();
     $fb_user = $fb->user();
     $userinfo = $fb->getUserInfo($fb_user);
     // If no email was set yet, then use the value from facebook (which is quite likely also empty, but probably not always).
     if (!$this->mEmail) {
         $this->mEmail = FBConnectUser::getOptionFromInfo('email', $userinfo);
     }
     $tmpl->set('email', $this->mEmail);
     // If the langue isn't set already and there is a setting for it from facebook, apply that.
     if (!$this->mLanguage) {
         $this->mLanguage = FBConnectUser::getOptionFromInfo('language', $userinfo);
     }
     if ($this->mLanguage) {
         $tmpl->set('uselang', $this->mLanguage);
     }
     // Make this an intelligent guess at a good username (based off of their nickname, real name, etc.).
     if (!$this->mUsername) {
         if ($wgUser->isLoggedIn()) {
             $this->mUsername = $wgUser->getName();
         } else {
             $nickname = FBConnectUser::getOptionFromInfo('nickname', $userinfo);
             if (self::userNameOK($nickname)) {
                 $this->mUsername = $nickname;
             } else {
                 $fullname = FBConnectUser::getOptionFromInfo('fullname', $userinfo);
                 if (self::userNameOK($fullname)) {
                     $this->mUsername = $fullname;
                 } else {
                     if (empty($nickname)) {
                         $nickname = $fullname;
                     }
                     // Their nickname and full name were taken, so generate a username based on the nickname.
                     $specialConnect->setUserNamePrefix($nickname);
                     $this->mUsername = $specialConnect->generateUserName();
                 }
             }
         }
     }
     $tmpl->set('name', $this->mUsername);
     /*
     // NOTE: We're not using this at the moment because it seems that there is no need to show these boxes... we'll just default to updating nothing on login (to avoid confusion & to make signup quicker).
     // Create the checkboxes for the user options.
     global $wgCookiePrefix;
     $name = isset($_COOKIE[$wgCookiePrefix . 'UserName']) ?
     			trim($_COOKIE[$wgCookiePrefix . 'UserName']) : '';
     // Build an array of attributes to update
     $updateOptions = array();
     foreach ($specialConnect->getAvailableUserUpdateOptions() as $option) {
     	// Translate the MW parameter into a FB parameter
     	$value = FBConnectUser::getOptionFromInfo($option, $userinfo);
     	// If no corresponding value was received from Facebook, then continue
     	if (!$value) {
     		continue;
     	}
     	// Build the list item for the update option
     	$updateOptions[] = "<li><input name=\"wpUpdateUserInfo$option\" type=\"checkbox\" " .
     		"value=\"1\" id=\"wpUpdateUserInfo$option\" /><label for=\"wpUpdateUserInfo$option\">" .
     		wfMsgHtml("fbconnect-$option") . wfMsgExt('colon-separator', array('escapenoentities')) .
     		" <i>$value</i></label></li>";
     }
     // Implode the update options into an unordered list
     $updateChoices = count($updateOptions) > 0 ? "\n" . wfMsgHtml('fbconnect-updateuserinfo') . "\n<ul>\n" . implode("\n", $updateOptions) . "\n</ul>\n" : '';
     $html = "<tr style='display:none'><td>$updateChoices</td></tr>";
     $tmpl->set( 'updateOptions', $html);
     */
     $tmpl->set('updateOptions', '');
     // Give authentication and captcha plugins a chance to modify the form
     // NOTE: We don't do this for fbconnect.
     //$wgAuth->modifyUITemplate( $template );
     //wfRunHooks( 'UserCreateForm', array( &$template ) );
     $this->ajaxTemplate = $tmpl;
 }