Makke_ Posted March 26, 2013 Share Posted March 26, 2013 Hi everyone! What I am going to ask is for me a wery big thing.I have tried for weeks to get this thing working, but I have no PHP coding skills so I can´t fix this myself.I´m trying to decline login to our MediaWiki if an admin not approved the account.What I was thing was that I created a new column in user table in the database called approved_account.I configured the field so that when a new user is created they will get value "0".I then want to in login process check if that field for that user contains a "0" (zero), if it do they should not be allowed to logg in.IF (approved_account = '0') then deny logg in. Is there someone out there that knows how to create this kind of extension?I have looked for already existing extensions like ConfirmAccount but they require email functionallity which our Wiki doesn´t support.Would appreciate If someone would lika to be kind to help me with this request. Quote Link to comment Share on other sites More sharing options...
DaveyK Posted March 26, 2013 Share Posted March 26, 2013 the logic you describe works out and is used a lot. What is the difficulty you are facing then? Quote Link to comment Share on other sites More sharing options...
Makke_ Posted March 26, 2013 Author Share Posted March 26, 2013 I don´t have any coding skills to preform the task.I created the column and named it approved_account.I don´t know how to get the username from the session and then verify if the approved_Account value is "0" or not.I copy pasted some information from different extensions givenn me below code snipp.It doesn´t work but this is how my mind thinks, don´t know if this is on the way or not? include("$IP/includes/SpecialUserlogout.php"); function Auth_remote_user_hook() { global $wgUser; $wgUser = User::loadFromSession(); $username = strtolower($wgUser->getName()); $dbr = wfGetDB( DB_SLAVE ); $res = $dbr->select(user_name, approved_account FROM user WHERE user_name = $wgUser); if( approved_account = '0' ) { wfSpecialUserLogout(); } } Quote Link to comment Share on other sites More sharing options...
DaveyK Posted March 26, 2013 Share Posted March 26, 2013 (edited) The only thing I can say is: if( approved_account = '0' ) { needs a dollar sign at the variable and two equal signs for comparing. so if( $approved_account == '0' ) { ONE equal sign is for SETTING a variable TWO equal signs are for comparing THREE are also for comparing, but more strict than 2. Other than that, I have no experience with the PHP class you are using to handle SQL queries so I really couldnt tell. Edited March 26, 2013 by DaveyK Quote Link to comment Share on other sites More sharing options...
Makke_ Posted March 26, 2013 Author Share Posted March 26, 2013 I don´t know if anything of the code iss correct.How can I write the SQL query in I way you would have done it?It´s better to use query´s you would use so that it is easier to see if it is correct. Quote Link to comment Share on other sites More sharing options...
DaveyK Posted March 26, 2013 Share Posted March 26, 2013 I imagine you have some sort of login file? You could post the relevant code here. Quote Link to comment Share on other sites More sharing options...
Makke_ Posted March 26, 2013 Author Share Posted March 26, 2013 (edited) It is MediaWiki´s original.I suspect is is withing this file:https://doc.wikimedia.org/mediawiki-core/master/php/html/User_8php_source.htmlAlltough I´ve heared they don´t recommend changing in MediaWiki's files but creating extensions instead (even though I don´t know how to do it). Edited March 26, 2013 by Makke_ Quote Link to comment Share on other sites More sharing options...
DaveyK Posted March 26, 2013 Share Posted March 26, 2013 Neither do I buddy, I am very sorry but I cant help you with that... Quote Link to comment Share on other sites More sharing options...
Makke_ Posted March 26, 2013 Author Share Posted March 26, 2013 Well thank´s for trying! Quote Link to comment Share on other sites More sharing options...
Makke_ Posted March 27, 2013 Author Share Posted March 27, 2013 I have tried to read about extensions and hooks.I´ve created below (as an extension I think).Allthough it´s not working, giving me a blank page when implementing it to my MediaWiki.Anyone famillier with MediaWiki Extension coding? <?php $wgExtensionCredits['validextensionclass'][] = array( 'path' => __FILE__, 'name' => 'Approve Account', 'author' =>'Markus', 'url' => 'https://www.mediawiki.org/wiki/Extension:Approve_Account', 'description' => 'This extension require admin to allow recently registered users to login', 'version' => 0.1, ); $wgHooks['AddNewAccount'][] = 'approve_accountHooks::onAddNewAccount'; $user = User::loadFromSession(); $dbr = wfGetDB( DB_SLAVE ); $res = $dbr->select(user_name, approved_account FROM user WHERE user_name = $user); if( approved_account == '0' { } } Quote Link to comment Share on other sites More sharing options...
Makke_ Posted March 27, 2013 Author Share Posted March 27, 2013 I´m currently working on below code.Would appreciate feedback and help.I don´t know if it fetches the values from the database.I am not able to print it. <?php /** * Prevent a user from accessing this file directly and provide a helpful * message explaining how to install this extension. */ if ( !defined( 'MEDIAWIKI' ) ) { echo <<<EOT To install the Test extension, put the following line in your LocalSettings.php file: require_once( "\$IP/extensions/Test.php" ); EOT; exit( 1 ); } // Extension credits that will show up on Special:Version $wgExtensionCredits[ 'other' ][] = array( 'path' => __FILE__, 'name' => 'Test', 'author' =>'Your Name Here', 'url' => 'https://www.mediawiki.org/wiki/Extension:Test', 'description' => 'This extension is an Test extension', 'version' => 1.0, ); // Find the full directory path of this extension $current_dir = dirname( __FILE__ ) . DIRECTORY_SEPARATOR; // Tell MediaWiki about the special page $wgSpecialPages[ 'Test' ] = 'SpecialTest'; global $wgRequest; class SpecialTest extends SpecialPage { function __construct() { parent::__construct( 'Test' ); } /** * Make your magic happen! */ function execute( $par ) { global $wgOut, $wgUser; $wgUser->getName(); $dbr = wfGetDB( DB_SLAVE ); $res = $dbr->select( 'user', // $table array( 'user_name', 'approved_account' ), // $vars (columns of the table) 'user_name = ".$wgUser."', // $conds __METHOD__, // $fname = 'Database::select', array( 'ORDER BY' => 'user_name ASC' ) // $options = array() ); $output = ''; foreach( $res as $row ) { $output .= 'Catgeory ' . $row->user_name . ' contains ' . $row->approved_account . " entries.\n"; } $wgOut->addHTML('Hej '.$wgUser.'.'); } } Quote Link to comment Share on other sites More sharing options...
annaharris Posted April 1, 2013 Share Posted April 1, 2013 It seems like your code is alright and I don't think that there is any type of glitch in your code. If it is not working then may be MediaWiki has made some changes in its extension coding. Quote Link to comment Share on other sites More sharing options...
Makke_ Posted April 2, 2013 Author Share Posted April 2, 2013 How should I write to be able to write user_name & approved_account?I´m not sure how to fomulate that sentence/code string? Quote Link to comment Share on other sites More sharing options...
Solution Makke_ Posted April 3, 2013 Author Solution Share Posted April 3, 2013 Seems like following part of the code isn´t working.'user_name = ".$wgUser."',If a write a specific user like 'user_name = "admin". It will fetch the information for Admin user.How should above code be written? i now $wgUser conatines value. I managed to print that information before.$wgOut->addHTML(''.$wgUser.'.');I can then write it by using below code : <?php /** * Prevent a user from accessing this file directly and provide a helpful * message explaining how to install this extension. */ if ( !defined( 'MEDIAWIKI' ) ) { echo <<<EOT To install the Test extension, put the following line in your LocalSettings.php file: require_once( "\$IP/extensions/Test.php" ); EOT; exit( 1 ); } // Extension credits that will show up on Special:Version $wgExtensionCredits[ 'other' ][] = array( 'path' => __FILE__, 'name' => 'Test', 'author' =>'Your Name Here', 'url' => 'https://www.mediawiki.org/wiki/Extension:Test', 'description' => 'This extension is an Test extension', 'version' => 1.0, ); // Find the full directory path of this extension $current_dir = dirname( __FILE__ ) . DIRECTORY_SEPARATOR; // Tell MediaWiki about the special page $wgSpecialPages[ 'Test' ] = 'SpecialTest'; global $wgRequest; class SpecialTest extends SpecialPage { function __construct() { parent::__construct( 'Test' ); } /** * Make your magic happen! */ function execute( $par ) { global $wgOut, $wgUser; $wgUser->getName(); $dbr = wfGetDB( DB_SLAVE ); $res = $dbr->select( 'user', // $table array( 'user_name', 'approved_account' ), // $vars (columns of the table) 'user_name = ".$wgUser."', // $conds __METHOD__, // $fname = 'Database::select', array( 'ORDER BY' => 'user_name ASC' ) // $options = array() ); $output = ''; foreach( $res as $row ) { $output .= 'Catgeory ' . $row->user_name . ' contains ' . $row->approved_account . " entries.\n"; } $wgOut->addHTML(''.$output.'.'); } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.