|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2008 Garrett Brown <http://www.mediawiki.org/wiki/User:Gbruin> |
| 4 | + * This program is free software; you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation; either version 2 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License along |
| 15 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + * |
| 17 | + * @author Garrett Bruin |
| 18 | + * @copyright Copyright © 2008 Garrett Brown |
| 19 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 20 | + * @addtogroup Extensions |
| 21 | + * |
| 22 | + * |
| 23 | + * FBConnect plugin. Integrates Facebook Connect into MediaWiki. |
| 24 | + * |
| 25 | + * Facebook Connect single sign on (SSO) experience and XFBML are currently available. |
| 26 | + * Please rename config.sample.php to config.php, follow the instructions inside and |
| 27 | + * customize variables as you like to set up your Facebook Connect extension. |
| 28 | + * |
| 29 | + * Info is available at http://www.mediawiki.org/wiki/Extension:FBConnect |
| 30 | + * and at http://wiki.developers.facebook.com/index.php/MediaWiki |
| 31 | + * |
| 32 | + * Limited support is available at http://www.mediawiki.org/wiki/Extension_talk:FBConnect |
| 33 | + * and at http://wiki.developers.facebook.com/index.php/Talk:MediaWiki |
| 34 | + * |
| 35 | + */ |
| 36 | + |
| 37 | + |
| 38 | +/** |
| 39 | + * Not a valid entry point, skip unless MEDIAWIKI is defined. |
| 40 | + */ |
| 41 | +if ( !defined( 'MEDIAWIKI' )) { |
| 42 | + die( 'This file is a MediaWiki extension, it is not a valid entry point' ); |
| 43 | +} |
| 44 | + |
| 45 | +/** |
| 46 | + * FBConnect version. Note: this is not necessarily the most recent SVN revision number. |
| 47 | + */ |
| 48 | +define( 'MEDIAWIKI_FBCONNECT_VERSION', 'r71, January 25, 2009' ); |
| 49 | + |
| 50 | +/** |
| 51 | + * Add information about this extension to Special:Version. |
| 52 | + */ |
| 53 | +$wgExtensionCredits['specialpage'][] = array( |
| 54 | + 'name' => 'Facebook Connect Plugin', |
| 55 | + 'author' => 'Garrett Brown', |
| 56 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:FBConnect', |
| 57 | + 'descriptionmsg' => 'fbconnect-desc', |
| 58 | + 'version' => MEDIAWIKI_FBCONNECT_VERSION, |
| 59 | +); |
| 60 | + |
| 61 | +/** |
| 62 | + * Initialization of the autoloaders and special extension pages. |
| 63 | + */ |
| 64 | +$dir = dirname(__FILE__) . '/'; |
| 65 | +require_once $dir . 'config.php'; |
| 66 | +require_once $dir . 'facebook-client/facebook.php'; |
| 67 | + |
| 68 | +$wgExtensionMessagesFiles['FBConnect'] = $dir . 'FBConnect.i18n.php'; |
| 69 | +$wgExtensionAliasesFiles['FBConnect'] = $dir . 'FBConnect.alias.php'; |
| 70 | + |
| 71 | +$wgAutoloadClasses['FBConnectAPI'] = $dir . 'FBConnectAPI.php'; |
| 72 | +$wgAutoloadClasses['FBConnectAuthPlugin'] = $dir . 'FBConnectAuthPlugin.php'; |
| 73 | +$wgAutoloadClasses['FBConnectHooks'] = $dir . 'FBConnectHooks.php'; |
| 74 | +$wgAutoloadClasses['FBConnectXFBML'] = $dir . 'FBConnectXFBML.php'; |
| 75 | +$wgAutoloadClasses['SpecialConnect'] = $dir . 'SpecialConnect.php'; |
| 76 | + |
| 77 | +$wgSpecialPages['Connect'] = 'SpecialConnect'; |
| 78 | +#$wgSpecialPages['NewsFeed'] = 'SpecialNewsFeed'; |
| 79 | + |
| 80 | +$wgExtensionFunctions[] = 'FBConnect::init'; |
| 81 | + |
| 82 | +// If we are configured to pull group info from Facebook, then create the group permissions |
| 83 | +$wgGroupPermissions['fb-user'] = $wgGroupPermissions['user']; |
| 84 | +if( $fbUserRightsFromGroup ) { |
| 85 | + $wgGroupPermissions['fb-groupie'] = $wgGroupPermissions['user']; |
| 86 | + $wgGroupPermissions['fb-officer'] = $wgGroupPermissions['bureaucrat']; |
| 87 | + $wgGroupPermissions['fb-admin'] = $wgGroupPermissions['sysop']; |
| 88 | + $wgGroupPermissions['fb-officer']['goodlooking'] = true; |
| 89 | + $wgImplictGroups[] = 'fb-groupie'; |
| 90 | + $wgImplictGroups[] = 'fb-officer'; |
| 91 | + $wgImplictGroups[] = 'fb-admin'; |
| 92 | +} |
| 93 | + |
| 94 | +/**/ |
| 95 | +// Define new autopromote condition (use quoted text, numbers can cause collisions) |
| 96 | +define( 'APCOND_FB_INGROUP', 'fb*g' ); |
| 97 | +define( 'APCOND_FB_ISOFFICER', 'fb*o' ); |
| 98 | +define( 'APCOND_FB_ISADMIN', 'fb*a' ); |
| 99 | + |
| 100 | +$wgAutopromote['fb-groupie'] = APCOND_FB_INGROUP; |
| 101 | +$wgAutopromote['fb-officer'] = APCOND_FB_ISOFFICER; |
| 102 | +$wgAutopromote['fb-admin'] = APCOND_FB_ISADMIN; |
| 103 | + |
| 104 | +/** |
| 105 | +$wgAutopromote['autoconfirmed'] = array( '&', array( APCOND_EDITCOUNT, &$wgAutoConfirmCount ), |
| 106 | + array( APCOND_AGE, &$wgAutoConfirmAge ), |
| 107 | + array( APCOND_FB_INGROUP )); |
| 108 | +/**/ |
| 109 | + |
| 110 | +$wgImplicitGroups[] = 'fb-groupie'; |
| 111 | +$wgImplicitGroups[] = 'fb-officer'; |
| 112 | +$wgImplicitGroups[] = 'fb-admin'; |
| 113 | + |
| 114 | + |
| 115 | +/** |
| 116 | + * Class FBConnect |
| 117 | + * |
| 118 | + * This class initializes the extension, and contains the core non-hook, |
| 119 | + * non-authentification code. |
| 120 | + */ |
| 121 | +class FBConnect { |
| 122 | + // Instance of our Facebook API class |
| 123 | + public static $api; |
| 124 | + // Whether we are rendering the Special:Connect page |
| 125 | + public static $special_connect; |
| 126 | + |
| 127 | + /** |
| 128 | + * Initializes and configures the extension. |
| 129 | + */ |
| 130 | + public static function init() { |
| 131 | + global $wgXhtmlNamespaces, $wgAuth, $wgHooks; |
| 132 | + |
| 133 | + self::$special_connect = false; |
| 134 | + self::$api = new FBConnectAPI(); |
| 135 | + |
| 136 | + // The xmlns:fb attribute is required for proper rendering on IE |
| 137 | + $wgXhtmlNamespaces['fb'] = 'http://www.facebook.com/2008/fbml'; |
| 138 | + |
| 139 | + // Set the global variable $wgAuth to our custom authentification plugin. |
| 140 | + // The AuthPluginSetup hook is called right before init(), so we can't use this hook |
| 141 | + $wgAuth = new StubObject( 'wgAuth', 'FBConnectAuthPlugin' ); |
| 142 | + |
| 143 | + // Install all public static functions in class FBConnectHooks as MediaWiki hooks |
| 144 | + $hooks = self::enumMethods('FBConnectHooks'); |
| 145 | + foreach( $hooks as $hookName ) { |
| 146 | + $wgHooks[$hookName][] = "FBConnectHooks::$hookName"; |
| 147 | + } |
| 148 | + |
| 149 | + // ParserFirstCallInit was introduced in modern (1.12+) MW versions so as to |
| 150 | + // avoid unstubbing $wgParser on setHook() too early, as per r35980 |
| 151 | + if (!defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' )) { |
| 152 | + global $wgParser; |
| 153 | + wfRunHooks( 'ParserFirstCallInit', $wgParser ); |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + /** |
| 158 | + * Returns an array with the names of all public static functions |
| 159 | + * in the specified class. |
| 160 | + */ |
| 161 | + public static function enumMethods( $className ) { |
| 162 | + $hooks = array(); |
| 163 | + try { |
| 164 | + $class = new ReflectionClass( $className ); |
| 165 | + foreach( $class->getMethods( ReflectionMethod::IS_PUBLIC ) as $method ) { |
| 166 | + if ( $method->isStatic() ) { |
| 167 | + $hooks[] = $method->getName(); |
| 168 | + } |
| 169 | + } |
| 170 | + } catch( Exception $e ) { |
| 171 | + // If PHP's version doesn't support the Reflection API, then exit |
| 172 | + die( 'PHP version (' . phpversion() . ') must be great enough to support the Reflection API' ); |
| 173 | + // or... |
| 174 | + $hooks = array('AuthPluginSetup', 'UserLoadFromSession', |
| 175 | + 'RenderPreferencesForm', 'PersonalUrls', |
| 176 | + 'ParserAfterTidy', 'BeforePageDisplay'); |
| 177 | + } |
| 178 | + return $hooks; |
| 179 | + } |
| 180 | +} |
0 commit comments