r51998 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51997‎ | r51998 | r51999 >
Date:20:18, 16 June 2009
Author:catrope
Status:deferred
Tags:
Comment:
UsabilityInitiative: Add OptIn extension and include PrefStats in UsabilityInitiative.php
Modified paths:
  • /trunk/extensions/UsabilityInitiative/OptIn (added) (history)
  • /trunk/extensions/UsabilityInitiative/OptIn/OptIn.i18n.php (added) (history)
  • /trunk/extensions/UsabilityInitiative/OptIn/OptIn.php (added) (history)
  • /trunk/extensions/UsabilityInitiative/OptIn/SpecialOptIn.php (added) (history)
  • /trunk/extensions/UsabilityInitiative/UsabilityInitiative.php (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.php
@@ -45,6 +45,8 @@
4646 // Includes sub-extensions
4747 require_once( dirname( __FILE__ ) . "/EditToolbar/EditToolbar.php" );
4848 require_once( dirname( __FILE__ ) . "/EditWarning/EditWarning.php" );
 49+require_once( dirname( __FILE__ ) . "/PrefStats/PrefStats.php" );
 50+require_once( dirname( __FILE__ ) . "/OptIn/OptIn.php" );
4951
5052 // Registers Hooks
5153 $wgHooks['AjaxAddScript'][] = 'UsabilityInitiativeHooks::addJs';
Index: trunk/extensions/UsabilityInitiative/OptIn/OptIn.php
@@ -0,0 +1,44 @@
 2+<?php
 3+/**
 4+ * Usability Initiative OptIn extension
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ *
 9+ * This file contains the include file for the OptIn portion of the
 10+ * UsabilityInitiative extension of MediaWiki.
 11+ *
 12+ * Usage: This file is included automatically by ../UsabilityInitiative.php
 13+ *
 14+ * @author Roan Kattouw <roan.kattouw@gmail.com>
 15+ * @license GPL v2 or later
 16+ * @version 0.1.1
 17+ */
 18+
 19+/* Configuration */
 20+
 21+// Preferences to set when users opt in
 22+// array( prefname => value )
 23+$wgOptInPrefs = array( 'skin' => 'vector', 'usebetatoolbar' => 1 );
 24+
 25+/* Setup */
 26+
 27+// Credits
 28+$wgExtensionCredits['other'][] = array(
 29+ 'path' => __FILE__,
 30+ 'name' => 'OptIn',
 31+ 'author' => 'Roan Kattouw',
 32+ 'version' => '0.1.1',
 33+ 'url' => 'http://www.mediawiki.org/wiki/Extension:UsabilityInitiative',
 34+ 'descriptionmsg' => 'optin-desc',
 35+);
 36+
 37+// Adds Autoload Classes
 38+$wgAutoloadClasses['SpecialOptIn'] =
 39+ dirname( __FILE__ ) . '/SpecialOptIn.php';
 40+
 41+// Adds Internationalized Messages
 42+$wgExtensionMessagesFiles['OptIn'] =
 43+ dirname( __FILE__ ) . '/OptIn.i18n.php';
 44+
 45+$wgSpecialPages['OptIn'] = 'SpecialOptIn';
Property changes on: trunk/extensions/UsabilityInitiative/OptIn/OptIn.php
___________________________________________________________________
Name: svn:eol-style
146 + native
Index: trunk/extensions/UsabilityInitiative/OptIn/SpecialOptIn.php
@@ -0,0 +1,84 @@
 2+<?php
 3+/**
 4+ * Special:OptIn
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ */
 9+
 10+class SpecialOptIn extends SpecialPage {
 11+ function __construct() {
 12+ parent::__construct( 'OptIn' );
 13+ wfLoadExtensionMessages( 'OptIn' );
 14+ }
 15+
 16+ function execute( $par ) {
 17+ global $wgRequest, $wgOut, $wgUser;
 18+ $this->setHeaders();
 19+ $wgOut->setPageTitle( wfMsg( 'optin-title' ) );
 20+
 21+ if ( $wgUser->isAnon() ) {
 22+ $llink = $wgUser->getSkin()->link(
 23+ SpecialPage::getTitleFor( 'Userlogin' ),
 24+ wfMsgHtml( 'loginreqlink' ),
 25+ array(),
 26+ array( 'returnto' => $this->getTitle()->getPrefixedUrl() )
 27+ );
 28+ $wgOut->addHTML( wfMsgWikiHtml( 'optin-needlogin', $llink ) );
 29+ return;
 30+ }
 31+
 32+ if ( $wgRequest->wasPosted() ) {
 33+ if ( $wgRequest->getVal( 'opt' ) == 'in' ) {
 34+ $this->optIn( $wgUser );
 35+ $wgOut->addWikiText( wfMsg( 'optin-success-in' ) );
 36+ } else {
 37+ $this->optOut( $wgUser );
 38+ $wgOut->addWikiText( wfMsg( 'optin-success-out' ) );
 39+ }
 40+ } else {
 41+ $wgOut->addWikiText( wfMsg( 'optin-intro' ) );
 42+ }
 43+ $this->showForm();
 44+ }
 45+
 46+ function showForm() {
 47+ global $wgUser, $wgOut;
 48+ $retval = Xml::openElement( 'form', array(
 49+ 'method' => 'POST',
 50+ 'action' => $this->getTitle()->getLinkURL()
 51+ ) );
 52+ $opt = ( $this->isOptedIn( $wgUser ) ? 'out' : 'in' );
 53+ $retval .= Xml::hidden( 'opt', $opt );
 54+ // Uses the optin-submit-in or optin-submit-out message
 55+ $retval .= Xml::submitButton( wfMsg( "optin-submit-$opt" ) );
 56+ $retval .= Xml::closeElement( 'form' );
 57+ $wgOut->addHTML( $retval );
 58+ }
 59+
 60+ function isOptedIn( $user ) {
 61+ global $wgOptInPrefs;
 62+ foreach ( $wgOptInPrefs as $pref => $value ) {
 63+ if ( $user->getOption( $pref ) != $value ) {
 64+ return false;
 65+ }
 66+ }
 67+ return true;
 68+ }
 69+
 70+ function optIn( $user ) {
 71+ global $wgOptInPrefs;
 72+ foreach( $wgOptInPrefs as $pref => $value ) {
 73+ $user->setOption( $pref, $value );
 74+ }
 75+ $user->saveSettings();
 76+ }
 77+
 78+ function optOut( $user ) {
 79+ global $wgOptInPrefs;
 80+ foreach( $wgOptInPrefs as $pref => $value ) {
 81+ $user->setOption( $pref, null );
 82+ }
 83+ $user->saveSettings();
 84+ }
 85+}
Property changes on: trunk/extensions/UsabilityInitiative/OptIn/SpecialOptIn.php
___________________________________________________________________
Name: svn:eol-style
186 + native
Index: trunk/extensions/UsabilityInitiative/OptIn/OptIn.i18n.php
@@ -0,0 +1,24 @@
 2+<?php
 3+/**
 4+ * Internationalisation for Usability Initiative OptIn extension
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ */
 9+
 10+$messages = array();
 11+
 12+/** English
 13+ * @author Roan Kattouw
 14+ */
 15+$messages['en'] = array(
 16+ 'optin' => 'OptIn',
 17+ 'optin-desc' => 'Allow users to opt-in to the Usability Initiative\'s usability enhancements',
 18+ 'optin-title' => 'Usability Intitiative enhancements',
 19+ 'optin-needlogin' => 'You need to $1 to opt-in to the Usability Initiative\'s usability enhancements.',
 20+ 'optin-intro' => 'The Wikipedia Usability Initiative has developed a new skin and a new edit toolbar intended to enhance the usability of Wikipedia. These enhancements have not been enabled for all users yet, but you can opt-in to them by clicking the button below.',
 21+ 'optin-success-in' => 'You have successfully opted in to the Usability Initiative\'s usability enhancements. You can opt back out at any time by clicking the button below.',
 22+ 'optin-success-out' => 'You have successfully opted out of the Usability Initiative\'s usability enhancements. You can opt back in at any time by clicking the button below.',
 23+ 'optin-submit-in' => 'Opt in',
 24+ 'optin-submit-out' => 'Opt out',
 25+);
Property changes on: trunk/extensions/UsabilityInitiative/OptIn/OptIn.i18n.php
___________________________________________________________________
Name: svn:eol-style
126 + native

Status & tagging log