4 * MediaWikiPlugin Class
7 * This file is part of GForge.
9 * GForge is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * GForge is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with GForge; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 class MediaWikiPlugin extends Plugin {
25 function MediaWikiPlugin () {
27 $this->name = "mediawiki" ;
28 $this->text = "Mediawiki" ; // To show in the tabs, use...
29 $this->hooks[] = "user_personal_links";//to make a link to the user's personal part of the plugin
30 $this->hooks[] = "usermenu" ;
31 // $this->hooks[] = "outermenu" ;
32 $this->hooks[] = "groupmenu" ; // To put into the project tabs
33 $this->hooks[] = "groupisactivecheckbox" ; // The "use ..." checkbox in editgroupinfo
34 $this->hooks[] = "groupisactivecheckboxpost" ; //
35 $this->hooks[] = "userisactivecheckbox" ; // The "use ..." checkbox in user account
36 $this->hooks[] = "userisactivecheckboxpost" ; //
37 $this->hooks[] = "project_admin_plugins"; // to show up in the admin page for group
38 $this->hooks[] = "session_before_login" ; // to register GF users in the MW database
41 function CallHook ($hookname, $params) {
42 global $use_mediawikiplugin,$G_SESSION,$HTML;
44 if (isset($params['group_id'])) {
45 $group_id=$params['group_id'];
46 } elseif (isset($params['group'])) {
47 $group_id=$params['group'];
51 if ($hookname == "outermenu") {
52 $params['TITLES'][] = 'MediaWiki';
53 $params['DIRS'][] = '/mediawiki';
54 } elseif ($hookname == "usermenu") {
55 $text = $this->text; // this is what shows in the tab
56 if ($G_SESSION->usesPlugin("mediawiki")) {
57 echo ' | ' . $HTML->PrintSubMenu (array ($text),
58 array ('/mediawiki/index.php?title=User:' . $G_SESSION->getUnixName() ));
60 } elseif ($hookname == "groupmenu") {
61 $project = &group_get_object($group_id);
62 if (!$project || !is_object($project)) {
65 if ($project->isError()) {
68 if (!$project->isProject()) {
71 if ( $project->usesPlugin ( $this->name ) ) {
72 $params['TITLES'][]=$this->text;
73 $params['DIRS'][]='/plugins/mediawiki/index.php?group_id=' . $project->getID();
75 (($params['toptab'] == $this->name) ? $params['selected']=(count($params['TITLES'])-1) : '' );
76 } elseif ($hookname == "groupisactivecheckbox") {
77 //Check if the group is active
78 // this code creates the checkbox in the project edit public info page to activate/deactivate the plugin
79 $group = &group_get_object($group_id);
82 echo ' <input type="CHECKBOX" name="use_mediawikiplugin" value="1" ';
83 // CHECKED OR UNCHECKED?
84 if ( $group->usesPlugin ( $this->name ) ) {
90 echo "<strong>Use ".$this->text." Plugin</strong>";
93 } elseif ($hookname == "groupisactivecheckboxpost") {
94 // this code actually activates/deactivates the plugin after the form was submitted in the project edit public info page
95 $group = &group_get_object($group_id);
96 $use_mediawikiplugin = getStringFromRequest('use_mediawikiplugin');
97 if ( $use_mediawikiplugin == 1 ) {
98 $group->setPluginUse ( $this->name );
100 $group->setPluginUse ( $this->name, false );
102 } elseif ($hookname == "userisactivecheckbox") {
103 //check if user is active
104 // this code creates the checkbox in the user account manteinance page to activate/deactivate the plugin
105 $user = $params['user'];
108 echo ' <input type="CHECKBOX" name="use_mediawikiplugin" value="1" ';
109 // CHECKED OR UNCHECKED?
110 if ( $user->usesPlugin ( $this->name ) ) {
113 echo "> Use ".$this->text." Plugin";
116 } elseif ($hookname == "userisactivecheckboxpost") {
117 // this code actually activates/deactivates the plugin after the form was submitted in the user account manteinance page
118 $user = $params['user'];
119 $use_mediawikiplugin = getStringFromRequest('use_mediawikiplugin');
120 if ( $use_mediawikiplugin == 1 ) {
121 $user->setPluginUse ( $this->name );
123 $user->setPluginUse ( $this->name, false );
127 echo ' <input type="CHECKBOX" name="use_mediawikiplugin" value="1" ';
128 // CHECKED OR UNCHECKED?
129 if ( $user->usesPlugin ( $this->name ) ) {
132 echo "> Use ".$this->text." Plugin";
135 } elseif ($hookname == "user_personal_links") {
136 // this displays the link in the user's profile page to it's personal MediaWiki (if you want other sto access it, youll have to change the permissions in the index.php
137 $userid = $params['user_id'];
138 $user = user_get_object($userid);
139 $text = $params['text'];
140 //check if the user has the plugin activated
141 if ($user->usesPlugin($this->name)) {
143 echo util_make_link ("/plugins/helloworld/index.php?id=$userid&type=user&pluginname=".$this->name,
144 _('View Personal MediaWiki')
148 } elseif ($hookname == "project_admin_plugins") {
149 // this displays the link in the project admin options page to it's MediaWiki administration
150 $group_id = $params['group_id'];
151 $group = &group_get_object($group_id);
152 if ( $group->usesPlugin ( $this->name ) ) {
153 echo util_make_link ("/plugins/projects_hierarchy/index.php?id=".$group->getID().'&type=admin&pluginname='.$this->name,
154 _('View the MediaWiki Administration')
158 elseif ($hookname == "session_before_login") {
159 $loginname = $params['loginname'] ;
160 $passwd = $params['passwd'] ;
161 if (! session_login_valid_dbonly ($loginname, $passwd, false)) {
164 $u = user_get_object_by_name ($loginname) ;
166 define ('MEDIAWIKI', true);
167 if (is_file('/var/lib/mediawiki/LocalSettings.php')){
168 require_once ('/var/lib/mediawiki/LocalSettings.php');
169 } elseif (is_file('/var/lib/mediawiki1.10/LocalSettings.php')){
170 require_once ('/var/lib/mediawiki1.10/LocalSettings.php');
174 if (is_dir('/usr/share/mediawiki')){
175 $mw_share_path="/usr/share/mediawiki";
176 } elseif (is_dir('/usr/share/mediawiki1.10')){
177 $mw_share_path="/usr/share/mediawiki1.10";
181 require_once ($mw_share_path.'/includes/Defines.php');
182 require_once ($mw_share_path.'/includes/Exception.php');
183 require_once ($mw_share_path.'/includes/GlobalFunctions.php');
184 require_once ($mw_share_path.'/StartProfiler.php');
185 require_once ($mw_share_path.'/includes/Database.php');
187 $mwdb = new Database() ;
188 $mwdb->open($wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname) ;
189 $sql = "select count(*) from user where user_name=?";
190 $res = $mwdb->safeQuery ($sql, ucfirst($loginname));
191 $row = $mwdb->fetchRow ($res) ;
193 $sql = "update user set user_password=?, user_email=?, user_real_name=? where user_name=?" ;
194 $res = $mwdb->safeQuery ($sql, md5($passwd), $u->getEmail(), $u->getRealName(), array(ucfirst($loginname))) ;
196 $sql = "insert into user (user_name, user_real_name, user_password, user_email, user_options) values (?, ?, ?, ?, ?)" ;
197 $res = $mwdb->safeQuery ($sql, array(ucfirst($loginname), $u->getRealName(), md5($passwd), $u->getEmail(), "skin=gforge\ncols=80\nrows=25")) ;
201 elseif ($hookname == "blahblahblah") {
209 // c-file-style: "bsd"