diff options
author | Wushin <pasekei@gmail.com> | 2014-11-16 22:27:32 -0600 |
---|---|---|
committer | Wushin <pasekei@gmail.com> | 2014-11-16 22:27:32 -0600 |
commit | 6f37a79665408c3531842851fc6c3efabfe50a07 (patch) | |
tree | 6e8dc2a26e61bfe6ba61af731208fc07a8b2536e /extensions/tmwa/frontend | |
parent | e41baa4c3aeb5f2b05fb928c1bf13e6a9bb130a7 (diff) | |
parent | 294e5d28e70d1709520c3fbb78464edb557f638b (diff) | |
download | website-6f37a79665408c3531842851fc6c3efabfe50a07.tar.gz website-6f37a79665408c3531842851fc6c3efabfe50a07.tar.bz2 website-6f37a79665408c3531842851fc6c3efabfe50a07.tar.xz website-6f37a79665408c3531842851fc6c3efabfe50a07.zip |
Merge pull request #9 from wushin/www-to-wiki
Www to wiki
Diffstat (limited to 'extensions/tmwa/frontend')
-rw-r--r-- | extensions/tmwa/frontend/TMWAccountUI.hooks.php | 60 | ||||
-rw-r--r-- | extensions/tmwa/frontend/TMWAccountUI.setup.php | 35 | ||||
-rw-r--r-- | extensions/tmwa/frontend/language/TMWAccount.alias.php | 15 | ||||
-rw-r--r-- | extensions/tmwa/frontend/language/TMWAccount.i18n.php | 15 | ||||
-rw-r--r-- | extensions/tmwa/frontend/news.php | 41 | ||||
-rw-r--r-- | extensions/tmwa/frontend/registration.php | 106 |
6 files changed, 272 insertions, 0 deletions
diff --git a/extensions/tmwa/frontend/TMWAccountUI.hooks.php b/extensions/tmwa/frontend/TMWAccountUI.hooks.php new file mode 100644 index 0000000..0081a9a --- /dev/null +++ b/extensions/tmwa/frontend/TMWAccountUI.hooks.php @@ -0,0 +1,60 @@ +<?php +/** + * Class containing hooked functions for a TMWAccount environment + */ +class TMWAccountUIHooks { + /** + * @param $template + * @return bool + */ + public static function addRequestLoginText( &$template ) { + $context = RequestContext::getMain(); + # Add a link to GameAccount from UserLogin + if ( !$context->getUser()->isAllowed( 'createaccount' ) ) { + $template->set( 'header', wfMsgExt( 'gameaccount-loginnotice', 'parse' ) ); + } + return true; + } + + /** + * @param $personal_urls + * @param $title + * @return bool + */ + public static function setRequestLoginLinks( array &$personal_urls, &$title ) { + if ( isset( $personal_urls['anonlogin'] ) ) { + $personal_urls['anonlogin']['text'] = wfMsg( 'nav-login-createaccount' ); + } elseif ( isset( $personal_urls['login'] ) ) { + $personal_urls['login']['text'] = wfMsg( 'nav-login-createaccount' ); + } + return true; + } + + /** + * Add "x email-tmwed open account requests" notice + * @param $notice + * @return bool + */ + public static function tmwAccountsNotice( OutputPage &$out, Skin &$skin ) { + global $wgTMWAccountNotice; + + $context = $out->getContext(); + if ( !$wgTMWAccountNotice || !$context->getUser()->isAllowed( 'tmwaccount' ) ) { + return true; + } + # Only show on some special pages + $title = $context->getTitle(); + if ( !$title->isSpecial( 'Recentchanges' ) && !$title->isSpecial( 'Watchlist' ) ) { + return true; + } + $count = TMWAccount::getOpenEmailTMWedCount( '*' ); + if ( $count > 0 ) { + $out->prependHtml( // parsemag for PLURAL + '<div id="mw-tmwaccount-msg" class="plainlinks mw-tmwaccount-bar">' . + $out->parse( wfMsgExt( 'tmwaccount-newrequests', 'parsemag', $count ), false ) . + '</div>' + ); + } + return true; + } +} diff --git a/extensions/tmwa/frontend/TMWAccountUI.setup.php b/extensions/tmwa/frontend/TMWAccountUI.setup.php new file mode 100644 index 0000000..9ff8800 --- /dev/null +++ b/extensions/tmwa/frontend/TMWAccountUI.setup.php @@ -0,0 +1,35 @@ +<?php +/** + * Class containing hooked functions for a TMWAccount environment + */ +class TMWAccountUISetup { + /** + * Register TMWAccount hooks. + * @param $hooks Array $wgHooks (assoc array of hooks and handlers) + * @return void + */ + public static function defineHookHandlers( array &$hooks ) { + # Make sure "login / create account" notice still as "create account" + $hooks['PersonalUrls'][] = 'TMWAccountUIHooks::setRequestLoginLinks'; + # Add notice of where to request an account at UserLogin + $hooks['UserCreateForm'][] = 'TMWAccountUIHooks::addRequestLoginText'; + $hooks['UserLoginForm'][] = 'TMWAccountUIHooks::addRequestLoginText'; + # Status header like "new messages" bar + $hooks['BeforePageDisplay'][] = 'TMWAccountUIHooks::tmwAccountsNotice'; + # Register admin pages for AdminLinks extension. + $hooks['AdminLinks'][] = 'TMWAccountUIHooks::tmwAccountAdminLinks'; + } + + /** + * Register TMWAccount special pages as needed. + * @param $pages Array $wgSpecialPages (list of special pages) + * @param $groups Array $wgSpecialPageGroups (assoc array of special page groups) + * @return void + */ + public static function defineSpecialPages( array &$pages, array &$groups ) { + $pages['GameAccount'] = 'GameAccountPage'; + $groups['GameAccount'] = 'login'; + $pages['GameNews'] = 'GameNewsPage'; + $groups['GameNews'] = 'changes'; + } +} diff --git a/extensions/tmwa/frontend/language/TMWAccount.alias.php b/extensions/tmwa/frontend/language/TMWAccount.alias.php new file mode 100644 index 0000000..7d6e624 --- /dev/null +++ b/extensions/tmwa/frontend/language/TMWAccount.alias.php @@ -0,0 +1,15 @@ +<?php +/** + * Aliases for extension ConfirmAccount + * + * @file + * @ingroup Extensions + */ + +$specialPageAliases = array(); + +/** English (English) */ +$specialPageAliases['en'] = array( + 'GameAccountPage' => array( 'The Mana World Account' ), + 'GameNewsPage' => array( 'The Mana World News' ) +); diff --git a/extensions/tmwa/frontend/language/TMWAccount.i18n.php b/extensions/tmwa/frontend/language/TMWAccount.i18n.php new file mode 100644 index 0000000..637a7f0 --- /dev/null +++ b/extensions/tmwa/frontend/language/TMWAccount.i18n.php @@ -0,0 +1,15 @@ +<?php +/** + * Internationalisation file for RequestAccount special page. + * + * @file + * @ingroup Extensions + */ + +$messages = array(); + +$messages['en'] = array( + 'gameaccount' => 'The Mana World Game Account', + 'gamenews' => 'The Mana World Game News', + 'gameaccount-loginnotice' => 'To obtain a game account, you must register here: \'\'\'[[Special:GameAccount|Game Account]]\'\'\'.<br/> To obtain a wiki account, you must register here: \'\'\'[[Special:RequestAccount|Wiki Account]]\'\'\'.', +); diff --git a/extensions/tmwa/frontend/news.php b/extensions/tmwa/frontend/news.php new file mode 100644 index 0000000..a214ea2 --- /dev/null +++ b/extensions/tmwa/frontend/news.php @@ -0,0 +1,41 @@ +<?php +class GameNewsPage extends SpecialPage { + + public function __construct() { + parent::__construct('GameNews'); + } + + public function execute( $par ) { + $request = $this->getRequest(); + $output = $this->getOutput(); + $this->setHeaders(); + + $wikitext = self::printNews(); + + $output->addWikiText( $wikitext ); + } + // Parses news.html + // displays feed + public function printNews($num='all') { + global $wgTMWNews; + $count = 0; + $content = ""; + $handle = @fopen($wgTMWNews, "r"); + if ($handle) { + while (($buffer = fgets($handle, 4096)) !== false) { + $content .= $buffer; + if (preg_match('/<\/div>/',$buffer)) { + $count++; + } + if ($count == $num && $num != 'all') { + $content .= '<div class="read-more"><a class="more" href="/news-feed.php">More News >></a></div>'; + break 1; + } + } + } + $output = $this->getOutput(); + $output->addHTML($content); + fclose($handle); + } +} +?> diff --git a/extensions/tmwa/frontend/registration.php b/extensions/tmwa/frontend/registration.php new file mode 100644 index 0000000..d66b701 --- /dev/null +++ b/extensions/tmwa/frontend/registration.php @@ -0,0 +1,106 @@ +<?php +class GameAccountPage extends SpecialPage { + + public function __construct() { + $this->err = array(); + parent::__construct('GameAccount'); + } + + public function execute( $par ) { + $request = $this->getRequest(); + $output = $this->getOutput(); + $this->setHeaders(); + global $wgTMWAccountLib; + $check_ladmin = new $wgTMWAccountLib(); + if($check_ladmin->socket) { + $check_ladmin->close(); + if(!self::processForm($request)) { + $wikitext = self::showForm(); + $output->addWikiText($wikitext); + } + } else { + $wikitext = self::accountsOffline(); + $output->addWikiText($wikitext); + } + } + + public function processForm($request) { + if ($request->getText('register') == "true") { + $acc = new TMWAccount(); + $acc->setUsername($request->getText('username')); + $acc->setPassword1($request->getText('password1')); + $acc->setPassword2($request->getText('password2')); + $acc->setEMail($request->getText('email')); + $acc->setGender($request->getText('gender')); + + $this->err = $acc->validate(); + global $wgCaptchaClass; + global $wgCaptchaClass, $wgConfirmAccountCaptchas; + if ($wgConfirmAccountCaptchas) { + $captcha = new $wgCaptchaClass; + if (!$captcha->passCaptcha()) { + $this->err[] = "The captcha was incorrect!"; + } + } + if (count($this->err) > 0) { + return false; + } + // create the account + if (!$acc->createAccount()) { + $this->err[] = "The was an unknown error while creating the account"; + return false; + } else { + self::showSuccess(); + return true; + } + } + return false; + } + + public function showForm() { + $output = $this->getOutput(); + $form = ('<p>With this form you can register for a new account. <i>We will never give your email to someone else or send you spam! Its only purpose is to be able to send you back whether account creation succeeded.</i></p><p style="background-color: #ede2da; padding: 5px; border: 1px solid #9f9894; border-radius: 10px;"><i>Security warning:</i> Do not use the same username and password on two different servers. It happened a lot in the past that users of the official server got "hacked" because they ignored this important precaution.</p>'); + $form .= '<form method="post" name="gameaccount" action="'.$this->getTitle()->getLocalUrl().'">'; + $form .= '<input type="hidden" name="register" value="true" /><table>'; + foreach($this->err as $message) { + $form .= "<tr><td colspan=\"2\" style=\"border: 1px solid red; color: red;\">".$message."</td></tr>"; + } + $form .= '<tr><td>Username:</td><td><input type="text" size="20" name="username" /></td></tr> + <tr><td>Password:</td><td><input type="password" size="20" name="password1" /></td></tr> + <tr><td>Retype password:</td><td><input type="password" size="20" name="password2" /></td></tr> + <tr><td>EMail:</td><td><input type="text" size="30" name="email" /></td></tr> + <tr><td>Gender:</td> + <td> + <select name="gender"> + <option value="0" selected></option> + <option value="M">Male</option> + <option value="F">Female</option> + </select> + </td> + </tr><tr><td colspan="2">'; + global $wgCaptchaClass, $wgConfirmAccountCaptchas; + if ($wgConfirmAccountCaptchas) { + $captcha = new $wgCaptchaClass; + $form .= $captcha->getForm(); + } + $form .= '</td></tr><tr> + <td colspan="2" style="text-align:right"> + <input type="submit" value="Register" /> + </td></tr></table></form>'; + $output->addHTML($form); + } + + public function showSuccess() { + $thank_you = "<p>Your account was created! In a few minutes you should receive an email with verification of your new account.</p> + <p><em>If the account doesn't work, please ask for help on the <a href='https://forums.themanaworld.org/viewforum.php?f=3'>Forums</a> or <a href='https://webchat.freenode.net/?channels=#themanaworld'>Support (IRC)</a>.</em></p>"; + $output = $this->getOutput(); + $output->addHTML($thank_you); + } + + public function accountsOffline() { + $output = $this->getOutput(); + $offline_msg = "<p>The Mana World Account service is currently offline<em>please ask for help on the <a href='https://forums.themanaworld.org/viewforum.php?f=3'>Forums</a> or <a href='https://webchat.freenode.net/?channels=#themanaworld'>Support (IRC)</a>.</em></p>"; + $output->addHTML($offline_msg); + } +} +?> |