I'd like to create a button on a menu bar that can generate a link to a random article from my blog posts (much like Wikipedia has). It's for a client, and they'd like to have this functionality on the site. I'm not familiar with PHP so I'd like to find a way around that, especially since I don't have access to the root user on my server host's mySQL installation (if this is relevant).
I had a theoretical solution: have a .txt or .xml file containing a list of all the URLs to each of the posts, with a "key" assigned to each of them. Then, when the user clicks the random article button, the current time (ex. 1:45) is hashed and mapped to a specific URL. I am fairly new to Drupal, however, I was wondering if there was some way to have the random article button use a .c file to execute these steps. The site is being hosted on a server that uses Apache 2, and I looked through some modules that were implemented in C code. I'm pretty new to all of this (although proficient in C), and spent many fruitless hours searching for solutions.
In a pure Drupal fashion (don't know if you are interested by this kind of solution), you could create a view (create a block) which retrieve blog posts, use a random sort criteria and limit results to 1 item. Then configure this view to display fields, and add only one field : post title, and check "link to content" in this field parameters window. You'll get one random blog post title which will be rendered as a link to this blog post.
Finally in Structure->Block assign your new block in a region to see it.
It's a pure Drupal / Views / no-code-just-clicks :) way, but it will be far more maintainable and easy to setup than introducing C for such a simple feature.
Views module
Let me know if you try this and have problems configuring your view or anything else.
Good luck
Related
Hello Stack Overflow Community!
I am making a directory of many thousand custom mods for a game using HTML tables. When I started this project, I thought one HTML page would be slow, but adequate for the ~4k files I was expecting. As I progressed, I realized there are tens of thousands of files I need to have in these tables, and let the user search though to find what they are missing to load up a new scenario. Each entry has about 20 text entries and a small image (~3KB). I only need to be able to search through one column.
I'm thinking of dividing the tables across several pages on my website to help loading speeds and improve overall organization. But then a user would have to navigate to each page, and perform a search there. This could take a while and be very cumbersome.
I'm not great at website programming. Can someone advise a way to allow the user to search through several web pages and tables from one location? Ideally this would jump to the location in the table on the new webpage, or maybe highlight the entry like the browser's search function does.
You can see my current setup here : https://www.loco-dat-directory.site/
Hopefully someone can point me in the right direction, as I'm quite confused now :-)
This would be my steps,
Copy all my info into an excel spredsheet, then convert that to json, then make that an array for javascript (myarray), then can make an input field, and on click an if statement if input == myarray[0].propertyName
if you want something more than an exact match, you'd need https://lodash.com/
in your project.
Hacky Solution
There is a browser tool, called TableCapture, to capture data from html tables and load into excel/spreadsheets - where you are basically deferring to spreadsheet software to manage the searching.
You would have to see if:
This type of tool would solve your problem - maybe you can pull each HTML page's contents manually, then merge these pages into a document with multiple "sheets", and then let people download the "spreadsheet" from your website.
If you do not take on the labor above and just tell other people to do it, then you'd have to see if you can teach the people how to perform the search and do this method on their own. eg. "download this plugin, use it on these pages, search"
Why your question is difficult to answer
The reason why it will be hard for people to answer you in stackoverflow.com (usually code solutions) is that you need a more complicated solution (in my opinion) than hard coded tables and html/css/javascript.
This type of situation is exactly why people use databases and APIs to accept requests ("term": "something") for information and deliver responses ( "results": [...] ).
Thank you everyone for your great advice. I wasn't aware most of these potential solutions existed, and it was good to see how other people were tackling problems of similar scope.
I've decided to go with DataTables for their built-in sorting and filtering : https://datatables.net/
I'm also going to use a javascript array with an input field on the main page to allow users to search for which pack their mod is in. This will lead them to separate pages on my site, each with a unique datatable for a mod pack. Separate pages will load up much quicker than one gigantic page trying to show everything.
I have searched StackOverflow for an answer to this question, and I've been surprised to find very little information for what seems to be a very common task
Let's say I have an app that allows users to make posts. These posts can contain text, of course, but I also want the users to be able to insert images, and possibly videos.
So here's the dilemma. The first idea that comes to mind for storing these posts would be making a table like this:
CREATE TABLE posts(id INTEGER PRIMARY KEY AUTO_INCREMENT, owner VARCHAR(36) NOT NULL, message VARCHAR(MAX), _timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
id is an identifier for the post itself.
owner is an identifier for the person who created the post.
message contains the message, as text.
_timestamp represents the time created.
However, since SQL wasn't really made for storing images and other files, the images are being stored off-database. For sake of example, let's say they're stored using a product similar to Google Cloud Storage.
So, the question is, how should the message be formatted in such a way that they contain data (for example, a link) that would point to the images, without having to do too much work on the frontend code? (And without letting the user know that they're doing anything other than inserting an image).
From experience with GitHub and StackOverflow, Markdown is obviously nice, but not as user-friendly as I'd want, and doesn't work with images exactly the way I want.
I've thought about using HTML to format the message, but that brings up to main problems:
How should I store HTML in such a way that prevents XSS (Cross-site Scripting)? Should I just escape everything in such a way that it can still be read as HTML on the frontend?
Let's say this app is a mobile app. This means I would either have to make my own HTML parser or find an existing library for it.
So what is the best practice for this?
I see this type of functionality all the time, so what are those people (such as Facebook, Google, etc.) using?
Not only have I encountered this problem, but I feel like there should be a good answer for this on StackOverflow for others who encounter this problem.
Specifically, I want to know whether HTML is a good option, or if I should consider something else. As far as right now, I'm planning to use plain HTML, and make public URIs for Cloud Storage objects
Not speaking about specific implementation I would say you never want to insert the image/video data into the post.
These should always be either an attachment or a link.
So either you let the user to insert links into the post or you let them add attachments which are then uploaded to the server and link to them is placed into the post.
Let's say you have a situation where a user drops the image/video/audio/whatever data into the post. In that case you would fire an event that uploads the data to your storage and places the link into the post when it's done. That's what happens when you CTRL-C CTRL-V an image into GitHub message for example.
Regarding XSS, you should strip the inserted data off any javascript and stuff that you don't like and you should be fine. There are many libraries that can do this for you.
I know it’s possible to create a template and have parameters, which can be used to customize another page. What I need to satisfy my colleagues, without the use of extensions, is to define variables in page1, such as end date, classification which i can use the variables on page 2. Similar as the use of template {{:page1|ParameterX|ParameterY}}.
My colleagues want to edit page1 (which consists all the details of a project)
Upon updating page1, they want page 2(which consists of an overview of many projects) to update with the information from the updated page1 data.
For example the project - end date has changed.
So the end date in page 2 of that specified project has changed too.
Thanks in advance.
As far as I know, this is not possible within traditional MediaWiki. One way to get the same effect would be to do as you suggested and work with templates. If multiple pages had the same information, you could use the common template, Template:2018 Project X - End Date as an example. Of course, with many variables, this could quickly become a messy approach. You could also create a template that has all the common information filled in and only requires input of differing information.
The alternative would be to simply have all the information verified by users across several pages.
A final potential option I am less familiar with, but which I believe may have a solution to your problem is using Semantic MediaWiki. It is a big extension, but a powerful one that may solve this and other problems down the line.
I'm a newbie in semantic wiki.
I want to do something database and overview computer component for my
organization.
I read about semantic wiki language but cant understand Is I can do like
this in semantic wiki or not. Help me or give me please directions for
find.
For example, I have a HDD.
Each of these have:
- status used or unused
- if used then the computer (parent) or if the unused - storage room
- serial number
- specification
- and etc.
I also have storage room end etc hierarchy.
How can do it in semantic wiki?
Each hdd will have own page?
I found that it can be done by subobject but subobject cant show in are
page.
How I can describe it and do visible it describing or it can be shown
only with ask?
Maybe it can be done by something else subobject?
Thanks for your time
I found some answer but it's not that I want.
Using subobject accept write some data like a page. BUT it cant be present in a page. It can be show only in query.
It wall be double work for me if I will be the first wrote in object and after show it in some format.
It will be great if I will be can write some data (like the object) and some of wrote data will be show in same page.
it's a pity
I administer my own company internal wiki using MediaWiki. I like MediaWiki because many people are already familiar with it having used Wikipedia. Also, it was a joy to configure and I didn't run into a lot of issues, not being that familiar with PHP. (So I'm not necessarily looking for another solution, like DokuWiki...)
My requirement is that the opening page be a listing of all pages, broken down alphabetically by category - much like a Table of Contents for the entire wiki. It would look like this (on the "Main Page"):
Category 1
Page A
Page B
Page C
Category 2
Page E
Page N
Page X
Page Z
Category 3
Page Q
Page V
Each page gets the category assigned to it. I know about the Special:Categories page, but that only shows the categories, and one must drill down (follow the link) to see the pages within that category - therefore, I cannot see multiple pages/multiple categories.
I have seen Extension:Hierarchy, but this does not fit my needs because the "Table of Contents" has to be edited rather than being auto generated by declaring the "parent" or "category" on each page itself.
Is there already existing functionality for this for MediaWiki? (I understand that as the wiki grows, so too will this Table of Contents page, but that is okay.)
Alternatively, I know about the MediaWiki API. I can create a server-side process that:
Does a MySQL lookup for all pages and their categories
Sorts them
Uses the MediaWiki API to generate this Table of Contents on the Main Page
And I can run this process periodically. I am up for the challenge, because I am a programmer and it is an interesting exercise, but why reinvent the wheel if I don't have to?
CategoryTree is an option. Now, a challenge here is that MediaWiki categories are not hierarchical. In other word, you can have category loops (A>B>C>A). Also, one article can show up in any number of categories, and articles can be without categories. The only thing that has to be done manually is to put <categorytree>Category Name</categorytree> for each category on the home "Table of Contents" page. Granted that new categories are not likely going to pop up a lot, this will not be a terrible issue. However, one solution for this inconvenience is to just put all your (top-level) categories into Category:Categories and then display that category via the extension (see the depth and hideroot parameters).
Hard to use, but wikistats produces an HTML representation from an XML dump, see e.g. MediaWiki.org categories.
CatGraph is another analysis tool, even more complex it would seem (but I've not tried setting it up for a wiki of mine, unlike wikistats).