I am trying to initialize a new Mediawiki family. I use this guide, of course. In the Upgrading section of the guide, it is mentioned:
As of MediaWiki 1.21, when upgrading MediaWiki from the web installer, $wgSharedTables must be temporarily cleared during upgrade. Otherwise, the shared tables are not touched at all (neither tables with $wgSharedPrefix, nor those with $wgDBprefix), which may lead to a failed upgrade.
It is right, because using this setting:
$wgSharedDB = 'wiki_shared';
$wgSharedTables[] = array('user','user_groups','actor');
$wgSharedPrefix = '';
I had no success in setting the db up; no shared tables are created in the wiki_shared db (it remains an empty db).
How should I "clear $wgSharedTables" to avoid facing this issue?
(Even though this is old, just in case someone will get here...)
First of all, this is how to clear $wgSharedTables:
$wgSharedTables = [];
All the other options just added a new empty array into the array.
Also, This is not the way you set $wgSharedTables. You essentially added an array inside the array; however, each table is supposed to be its own item. Either use array_merge():
$wgSharedTables = array_merge( $wgSharedTables, [ user','user_groups','actor' ] );
Or set each one separately:
$wgSharedTables[] = 'user';
$wgSharedTables[] = 'user_groups';
$wgSharedTables[] = 'actor';
So Ive a code where in user uploads a video file from a certain directory.
-Now as soon as the user uploads the file, I want a table to be created with the name of the file as the name of table and exactly three columns named
ID(primary),type(varchar20), timestamp(float)
-Secondly, the page should show the table name created and there should be an option to delete the table if the user wants to.
My video upload and play code goes as below
<h1>HTML5 local video file player example</h1>
<div id="message_"></div>
<input type="file" accept="video/*"/>
<video controls autoplay></video>
<script>
(function localFileVideoPlayer() {
'use strict'
var URL = window.URL || window.webkitURL
var displayMessage = function (message, isError) {
var element = document.querySelector('#message_')
element.innerHTML = message
element.className = isError ? 'error' : 'info'
}
var playSelectedFile = function (event) {
var file = this.files[0]
var type = file.type
var videoNode = document.querySelector('video')
var canPlay = videoNode.canPlayType(type)
if (canPlay === '') canPlay = 'no'
var message = 'Can play type "' + type + '": ' + canPlay
var isError = canPlay === 'no'
displayMessage(message, isError)
if (isError) {
return
}
var fileURL = URL.createObjectURL(file)
videoNode.src = fileURL
}
var inputNode = document.querySelector('input')
inputNode.addEventListener('change', playSelectedFile, false)
})()
</script>
(Mercilessly stolen from php.net https://php.net/manual/en/features.file-upload.post-method.php)
<?php
$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile) && $_FILES['userfile']['type'] === 'image/jpeg') {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Possible file upload attack!\n";
}
/*for creating table, which I don't recommend*/
$sql_query = "CREATE TABLE ".$_FILES['userfile']['name']." INT(6) AUTO_INCREMENT PRIMARY KEY,
type VARCHAR(20) NOT NULL,
timestamp FLOAT
)";
$mysqli->query($sql_query);
?>
/First half of the code, but something came up, I will be back in an hour.../
<?php
print '<form action="delete.php" method="post">
'.$_FILES['userfile']['name'].' <input type="submit" value="'.$_FILES['userfile']['name'].'" name="delete" />
</form>';
?>
<?php
$sql_query = "DROP TABLE ".$_POST['delete'];
$mysqli->query($sql_query);
?>
Instead of creating new tables for each file, I would recommend creating the table once, and insert the files like this:
<?php
$stmt = $mysqli->prepare("INSERT INTO table (name, type, timestamp) VALUES (?,?,?)");
$stmt->bind_param("ssf", $_FILES['userfile']['name'], $_FILES['userfile']['name'], strtotime(date("Y-m-d H:i:s")));
$stmt->execute();
?>
Similarly, if you want to delete:
<?php
$stmt = $mysqli->prepare("DELETE FROM table WHERE name = ?");
$stmt->bind_param("s",$_POST['delete']);
$stmt->execute();
?>
Or if you know the id, you can delete it by it instead (is safer, because multiple files can own the same name, but id must be unique).
Here is the big-picture overview of what you might wish to do.
1. Identifying who uploaded what
You may want each uploader to be able to request a list of his uploaded files and, optionally, to remove one or more. Or, you might want to be able to list all uploaded videos, grouping them by the uploader.
For this, you want a login system. Here is a post that links to a couple of videos that take you through that process.
2. Providing an upload system (client side)
You can write this from scratch, as you are doing, or you can use an already-invented wheel (rather than re-inventing it yourself). This jQuery plugin is awesome - looks world-class and works perfectly. I have used it on dozens of projects. Plus, it comes with example code for both server-side and client-side. Take a look.
3. Managing the uploaded files (server side)
On the server side, you might want to organize the uploaded files to some degree. There is no need to create much of a folder structure on the server since you have a database table to keep track of things, but at the least you might want to put them into a folder called "uploads" or "videos" or etc - just so that they are not stored in with the HTML files.
4. Adding each uploaded video to a MySQL (now called MariaDB) table
If you use the jQuery File Upload plugin, you will already have a file that handles that back-end receipt of the uploaded file. It is in this file that you write the code to also post the data into the database.
Look at this spot the docs for the jQuery file upload plugin. The plugin allows you to go fetch some additional data from the page (for example, you might have fields that ask the user for a tag, or a drop-down that lets users select a category) and you want to also insert those selections into the database when you upload the file. This is how you do that.
5. Getting the list of videos from the MySQL table and listing them on a webpage
This is a simple matter of querying the database, creating some HTML code in a PHP variable, and then later outputting the PHP variable containing that HTML at the appropriate place in the web page. Personally, I prefer to keep as much of my PHP as possible at the top of the page - create the strings containing any PHP output - and then echo the HTML code at the appropriate place. Keeps the file tidy and easy to read.
This youtube video will help you to grasp how to do that. Also see this post and this one.
Some notes to keep in mind:
a. You must name all of your web page files to end in .php instead of .html. There is almost no difference in how the pages will work - the sole difference is that any pages ending in .php can now process PHP code. Otherwise, they are identical. In fact, you can rename them now - try it - and they will work the same.
b. PHP code can be inserted anywhere in your web page -- you just place the PHP code between PHP_Start and PHP_END tags - it looks like this:
<?php
$myvar = 'Bob';
?>
c. PHP is very unforgiving about missing end-of-statement semi-colons. If you forget one, the PHP script will abort at that spot with no notification This makes it a bit tricky to work with PHP. See this answer for a couple of suggestions.
d. All PHP variables begin with a dollar sign. Weird, but true. Use the echo command to output PHP strings to the screen (for example, a PHP string containing HTML will display that HTML on the screen).
e. The PHP $_SESSION is super-useful. It is not difficult - it is just a way to store variables on the server. Very useful for things like remembering if someone has logged in, remembering data about that user that is stored in a MySQL table, etc.
Good luck with your project.
I have user named MyNiCkNaMe in my MediaWiki and in table user I see user_name=MyNiCkNaMe but on MediaWiki pages I see it as Mynickname is there any way to display it same as in db?
In LocalSettings.php include the line
$wgRestrictDisplayTitle = false;
Then on the user page use the magic word/parser function DISPLAYTITLE
{{DISPLAYTITLE:User:MyNiCkNaMe}}
I'm trying to create new content with:
// Get suggestions template and update with values
$content = $this->app['storage']->getEmptyContent('suggestions');
$content->values['title'] = $title;
$content->values['description'] = $description;
// Save to db
$save = $this->app['storage']->saveContent($content);
status is set as publish in data returned from getEmptyContent.
When I visit the backend, I can see that the save status is None. How can I actually create it so that it is published?.
This sounds like it could be a bug since as far as I can remember some value should make it through to status by default. One thing to check, in your contenttypes.yml file for suggestions you can also add a default_status eg:
default_status: publish
If you still have no luck then raise an issue on Github.
I'm currently trying to override Wordpress' wp_authenticate function (without modifying the core files, mainly pluggable.php), however I'm not sure if I'm going about it the correct way. There are two great references (see below), but they don't explicitly state what to do in order to prevent the login provided certain criteria are met.
In short, I'm trying to prevent registered users who have not activated their account. I've already implemented creating a user with a md5 unique id in the usermeta table (attached to their user id). I'm basically trying to check for that "activation_key' value in the usermeta table on login, if a value exists, I want to prevent the login from occurring.
The authenticate filter seems to be exactly what I need but after modifying it and placing it into my functions.php file, it doesn't seem to work! Login occurs per usual.
References:
How do I hook into the Wordpress login system to stop some users programmatically?
http://willnorris.com/2009/03/authentication-in-wordpress-28
I actually found a work around.
Using a custom form you can log into Wordpress using the wp_signon function.
var $creds = array();
$creds['user_login'] = 'example';
$creds['user_password'] = 'plaintextpw';
$creds['remember'] = true;
//check if user has an activation key in the usermeta table
$user = get_userdatabylogin($creds['user_login']);
if(get_usermeta($user->ID,'activation_key')) {
} else {
$procLogin = wp_signon( $creds, false );
if ( is_wp_error($procLogin) ) {
echo $user->get_error_message();
}
echo 'success!';
}
hope this helps someone out there