I am trying to autopromote users to the "superuser" group on login, but it is not working
LocalSettings.php
// Super user group
$wgAddGroups['superuser'] = true;
$wgGroupPermissions['superuser']['read'] = true;
$wgGroupPermissions['superuser']['edit'] = true;
Login plugin
$wgAutopromote = array('superuser');
You want all logged in users to have "superuser" privileges? Simplest approach would be to add additional user rights to the existing user user group, rather than creating a new user group.
$wgGroupPermissions['user']['some_user_right'] = true;
See http://www.mediawiki.org/wiki/Manual:User_rights.
According to the MediaWiki manual on $wgAutopromote, $wgAutopromote is an associative array.
You could try one of the following:
$wgAutopromote = array('superuser' => array( APCOND_EDITCOUNT, 0 ));
Or
$wgAutopromote = array(
'superuser' => array( '&',
array( APCOND_EDITCOUNT, 0 ),
),
);
I don't have a live copy of MediaWiki with me right now, so I don't know which one is going to work, though I have a hunch that the second will likely work.
Auto promote is deceptive and does not work in my experience. I ended up having to add the user to the group in my auth plugin extension. I believe I used the add group method from the User object, I'll have to double-check that.
Related
I'd like to write a wordpress-plugin, where you can add a page.
If you submit the page it should also create a submenu under the menu "Teams".
Until now I can create a page through my code, but not the submenu.
I tried different functions I found on google, but nothing will work.
Does anyone know a function or a script that will help?
Yes sure, use the following as a sample to get you going. The clause to check if you are in the right menu may need altering or deleting if you don't have multiple menu objects defined.
menu_item_parent is vital and that is the parent item uid. find that by viewing your front end source code. You should find that each menu item inserted via WP menu creating functions inserts the unique items id.
// add a sub menu dynamically via code!
function aj_add_menu_item( $items, $args ) {
// check we are in the right menu
if( $args -> theme_location =="primary" ) {
$new_links = array();
// Create a nav_menu_item object
$newItem = array(
'title' => "Offers",
'menu_item_parent' => 71,
'ID' => 'loginout',
'db_id' => '12312332', // something random
'url' => "offers",
'classes' => array( 'menu-item' )
);
$items[] = (object) $newItem; // add to end of existing object.
menu_item_parent value will ensure it goes in right place
return $items;
}else{
return $items;
}
}
add_filter( 'wp_nav_menu_objects', 'aj_add_menu_item', 10, 2 );
I've been reading through the documentation, but I can't seem to get it right.
I'm trying to implement a custom conditional hook by wrapping some supplied hooks. It should restrict access to a service (the method doesn't matter) by:
1) First checking if the user has the admin or super-admin roles using:
auth.restrictToRoles({
roles: ['admin', 'super-admin']
}),
If the user has the required roles, the hook should allow access. Otherwise..
2) Restrict access to owner using:
auth.restrictToOwner({ ownerField: 'id' }),
What I can't figure out is how to get and check the result of auth.restrictToRoles so I can run auth.restrictToOwner if needed.
Any help would be greatly appreciated!
There are two options. The easier on is to not use the pre-built hooks. Almost every pre-built hook can be implemented on your own in just a couple of lines of code. It could look like this:
app.service('myservice').before({
find(hook) {
const { user } = hook.params;
const {roles } = user;
if(roles.indexOf('admin') !== -1 && roles.indexOf('super-admin') !== -1) {
hook.params.query.userId = user._id;
}
}
});
The other way would be to create a wrapper hook that first calls restrictToRoles and then catches any error (notice that it is basically more code than implementing it entirely on your own):
const restrictToRoles = auth.restrictToRoles({
roles: ['admin', 'super-admin']
});
const restrictToOwner = auth.restrictToOwner({ ownerField: 'id' });
app.service('myservice').before({
find(hook) {
return restrictToRoles(hook).catch(() => restrictToOwner(hook));
}
});
I have inherited a piece of code from a Laravel 5 codebase that essentially takes an svg symbol, allows you to add effects and text, and saves it as an SVG that gets linked to a user's account. The system works, but every once and a while you will see that 2 customers will end up with the same "newAvatar->id" linked to their account. I have been scratching my brain as to why but can't seem to figure it out.
Would this be caused by some sort of race condition? Do I need to put a semaphore or mutex of some sort around this code?
public function createAvatar()
{
$status = 400;
$_data = array('error' => 'Unknown Error');
if (Input::has('avatar_svg'))
{
$svg = Input::get('avatar_svg');
$newAvatar = Avatar::create([
'svg_content' => $svg,
]);
if ($newAvatar) {
$status = 200;
$_data = array('avatarID' => $newAvatar->id);
}
}
//data is sent back as JSON to be processed by AngularJS
return Response::json([
'data' => $_data,
], $status, array(), JSON_PRETTY_PRINT);
}
Thanks to all for the help, but the answer was that users managed to find a path through the software that was never intended to be taken or possible.
It's amazing the things that people find when code goes live
Is it possible to have a wiki page with two tables reflecting the data from two different 3rd party sites?
If so, how to get it done? Will page templates be of any help here?
Short answer is no, there's no easy, built-in way to pull external content into a MediaWiki site. Allowing a third party to inject arbitrary content would be massive security risk.
Long answer is that anything is possible with extensions, either existing ones or ones you write yourself. The MediaWiki site has an entire category of listings for "Remote content extensions" that do this kind of thing in one form or another, with External Data looking particularly useful. You will need admin rights to install any of these, and you'll need to trust both the extension code and the data you pull in.
I already wrote exactly what you describe. Might be helpful for you.
# Define a setup function
$wgHooks['ParserFirstCallInit'][] = 'efStackOverflow_Setup';
# Add a hook to initialise the magic word
$wgHooks['LanguageGetMagic'][] = 'efStackOverflow_Magic';
function efStackOverflow_Setup( &$parser ) {
# Set a function hook associating the "example" magic word with our function
$parser->setFunctionHook( 'stag', 'efStackOverflow_Render' );
return true;
}
function efStackOverflow_Magic( &$magicWords, $langCode ) {
# Add the magic word
# The first array element is whether to be case sensitive, in this case (0) it is not case sensitive, 1 would be sensitive
# All remaining elements are synonyms for our parser function
$magicWords['stag'] = array(1, 'stag');
# unless we return true, other parser functions extensions won't get loaded.
return true;
}
function efStackOverflow_Render( $parser, $param1 = '', $param2 = '' ) {
// there was filtering
$modif = 0;
$cache_file_path = "cache/".$param1."_".$param2;
if (file_exists($cache_file_path))
$modif = time() - #filemtime ($cache_file_path);
if (file_exists($cache_file_path) and $modif < 60*60*24) {
return file_get_contents($cache_file_path);
}
$page = file_get_contents("http://www.google.com/rss/".$param1);
$xml = new SimpleXMLElement($page);
foreach ($xml as $key => $value) {
// do some
}
if (!empty($output))
file_put_contents($cache_file_path, $output);
return $output;
}
Mediawiki version was 1.16.
I want to get the last query CakePHP ran. I can't turn debug on in core.php and I can't run the code locally. I need a way to get the last sql query and log it to the error log without effecting the live site. This query is failing but is being run.
something like this would be great:
$this->log($this->ModelName->lastQuery);
Thanks in advance.
For Cake 2.0, the query log is protected so this will work
function getLastQuery() {
$dbo = $this->getDatasource();
$logs = $dbo->getLog();
$lastLog = end($logs['log']);
return $lastLog['query'];
}
Tested in CakePHP v2.3.2
$log = $this->Model->getDataSource()->getLog(false, false);
debug($log);
In CakePHP 1.x, the data you want is accessible in DataSource::_queriesLog. Cake doesn't really provide a getter method for this member, but the underlying language being PHP, nothing stops you from doing the following:
In app/app_model.php:
function getLastQuery()
{
$dbo = $this->getDatasource();
$logs = $dbo->_queriesLog;
return end($logs);
}
You can use this inline.
$dbo = $this->Model->getDatasource();
// store old state
$oldStateFullDebug = $dbo->fullDebug;
// turn fullDebug on
$dbo->fullDebug = true;
// Your code here! eg.
$this->Model->find('all');
// write to logfile
// use print_r with second argument to return a dump of the array
Debugger::log(print_r($dbo->_queriesLog, true));
// restore fullDebug
$dbo->fullDebug = $oldStateFullDebug;
Simple you can use showLog() function
var_dump($this->YourModel->getDataSource()->showLog());
This is a very late answer, i know, but for whoever needs this in the future, you can always restrict setting debug to your IP, For example:
Configure::write('debug', 0);
if($_SERVER["REMOTE_ADDR"] == '192.168.0.100'){
Configure::write('debug', 2); //Enables debugging only for your IP.
}
Combination of Matt's and blavia's solution (works when debug is not 2):
$dbo = $this->Model->getDatasource();
$oldStateFullDebug = $dbo->fullDebug;
$dbo->fullDebug = true;
// find or whatever...
$this->Model->find("all");
$logs = $dbo->getLog();
$lastLog = end($logs['log']);
CakeLog::write("DBLog", $lastLog['query']);
$dbo->fullDebug = $oldStateFullDebug;
Having a quick skim of the book, cakephp api getLog you could turn on logTransaction. Although having not used it, I'm not sure how it will perform.
Otherwise you could experiment with FirePHP and here is the a guide for it,
You might try DebugKit, although off the top of my head I think you do still need debug 2 to get it to work.
Hopefully something might give you a lead. :)
You can use this:
$log = $this->Model->getDataSource()->getLog(false, false);
pr($log);die;
There are two methods to view the query in CakePHP.
Both methods you have to add the below one line in app/Config/core.php
Configure::write('debug', 2);
First methods :
debug($this->getLastQuery());
where you want to get the query add above line and call this function getLastQuery() on same controller using below code
public function getLastQuery() {
$dbo = $this->TModel->getDatasource(); //Here TModel is a model.what table you want to print
$logs = $dbo->getLog();
$lastLog = end($logs['log']);
return $lastLog['query'];
}
second method :
add the below line in the any Elements files.
<?php echo $this->element('sql_dump'); ?>
This will help you.
echo '<pre>';
$log = $this->YOUR_MODEL->getDataSource();
print_r($log);
exit;