I'm a new user for mediawiki. I have installed and configured the semantic mediawiki correctly. Now I want to display a external database table in a wiki page. I tried External Data extension, but I didn't know how to display them correctly. Are there some tutorials available? Could you help me? Thanks!
http://www.mediawiki.org/wiki/Extension:External_Data#.23get_db_data_-_retrieve_data_from_a_database
shows the basic steps. I have personally not found a good tutorial yet.
To try the feature out you might want to start with a query to your own Mediawiki.
Create an extenal data server entry "mediawiki" in you LocalSettings.php that
simply reuses your Mediawikis database configuration:
# external data configuration
$edgDBServer['mediawiki'] = $wgDBserver;
$edgDBServerType['mediawiki'] = $wgDBtype;
$edgDBName['mediawiki'] = $wgDBname;
$edgDBUser['mediawiki'] = $wgDBuser;
$edgDBPass['mediawiki'] = $wgDBpassword;
Then add a macro to fetch some data from the user table (which is a standard Mediawiki table) in
some page of your choice:
{{#get_db_data:
|server=mediawiki
|from=user
|where=not user_name ='Wikiroot'
|data=id=user_id,login=user_name,name=user_real_name
}}
To display the data you might want to use #for_external_table:
{| class="wikitable"
! id
! login
! name{{#for_external_table:<nowiki/>
{{!}}-
{{!}} {{{id}}}
{{!}} {{{login}}}
{{!}} {{{name}}}
}}
|}
You should get a table with id, login and name of your mediawiki users except wikiroot.
Related
I would like to update the Main_Page of our wiki from a script run by cron.
Apart from the page content itself, in pagecontent.old_text, what else do I need to update?
If I only update the "old_text" field, the new content is not displayed. I get the previous content, presumably from a cache somewhere. In LocalSettings.php I have $wgMainCacheType = CACHE_NONE;. So I guess that I need to also update something else in the Mediawiki database?
(In case it matters, this is with Mediawiki 1.31.10 on Debian 10 with Apache and PostgreSQL)
Use maintenance/edit.php, the edit API, Pywikibot etc. Trying to do changes via direct DB manipulation is a rather bad idea.
Updating the timestamp in page.page_touched works to have the wiki show the new content.
This example is using a PostgreSQL database, so it might need some adjustments if used with the more common MySQL DB.
To update the text of a page identified by it's name, it is necessary to join the page, revision and pagecontent tables. This example updates a page named "Drafts":
UPDATE pagecontent
SET old_text = 'New page content'
FROM page, revision
WHERE page.page_title='Drafts'
AND pagecontent.old_id=revision.rev_text_id
AND page.page_latest=revision.rev_id;
And to update the page timestamp so that the wiki shows the new content:
UPDATE "page"
SET page_touched = now()
WHERE page_namespace = '0'
AND page_title = 'Drafts';
An alternative which avoids tinkering with the database directly, is to use an extension like External Data. There are examples here to embed a text file in a page, and here to embed the output of a database query.
Currently I have 3 categories, Application, Application Instance and Vendor.
Right now Application has a link (via property Made By) to Vendor. Application instances need to link back to Vendor via a property. I have the query I can use to return the application name and vendor is
{{#ask:
[[Category:Program]][[{{{Program}}}]]
|?Made By
}}
however
{{#set:Made By={{#ask:
[[Category:Program]][[{{{Program}}}]]
|?Made By
}}}}
doesn't work to set the property to the value of vendor which is returned by the ask query.
Are there other ways to do this?
Maybe a bit late but you could probably do this using a template to set the property. Something like this?
In the Application Instance template (or manually on each Application Instance page) add the following ask query:
{{#ask:[[Category:Program]][[{{{Program}}}]]
|?Made By
|link=none
|format=template
|template=Set made by
}}
Then create the template "wiki/Template:Set made by" with the following:
includeonly>
{{#set:
Made By={{{2}}}
}}
</includeonly>
Notes
Parameter {{{1}}} is the subject which is the page name and {{{2}}} will be the result for 'Made By'.
Stripping the link from the query results prevents the extra text being passed to the set command which would confuse things.
You can also use the inverse of properties in queries by adding a minus sign in front of them. (e.g. '-Made By')
I have been playing with the paginator function in Bolt CMS, it is easy to use.
Now I need to know if there is a way to implement the pagination in the contenttype yaml.
I think, is it possible something like this?
entries:
name: Entries
singular_name: Entry
fields:
...
taxonomy: [ categories ]
allowpaging: true
I only have found that you need explicity write the allowpaging flag when you fetch the content via setcontent:
{% setcontent entries = "entries/latest/4" allowpaging %}
But what if you want to use the same template for displaying the related taxonomy records? The problem is that you always will be fetching the last 4 entries regardless the taxonomy.
If there's no way to do this, there would be a way to implementing it?
Paging will also be automatically set if you use listing records setting
listing_records: 10
But your template still needs a pager that will use this setting - the listing templates in the theme/base-2014 will work and can be used as an example
The docs have more information https://docs.bolt.cm/contenttypes-and-records#defining-contenttypes
In config.yml set listing_records: xx or the number of records you want to show
then set in your .twix template {% setcontent entries = "entries/latest/xx" allowpaging %}with the same number
and add at the end of .twix file put this code {{ pager('pages') }} to show pages
You can see the official bolt docs for further informations
https://docs.bolt.cm/3.1/templating/content-paging
So I already have a database setup with a few columns and a few rows already inserted in. I'm trying to create a view that you would just input information into a form and press Submit, then a row would be added to the MySQL database with the information you just typed in.
I believe you can do this with admin, but I would like to try without admin and I'm not sure if this is possible? I've been using the MySQL commandline to add rows as of now..
Of coures this is possible this is a building block for data driven websites. You can use a ModelForm as Daniel suggested (they offer built in validation and HTML markup for FREE) to easily map your model to a front end form. It would probably be beneficial to start with django tutorial or documentation first.
At the the very basic, all you have to do is instantiate your model
new_entry = YourModel(name='me', age='222', about='stackoverflow')
then save it
new_entry.save()
This adds it as a new row to your db.
https://docs.djangoproject.com/en/dev/topics/db/models/
Why would it not be possible?
You probably want a modelform (but see the general form introduction first).
Try out this example of Generic Views: http://postneo.com/2005/08/17/django-generic-views-crud (assumes a model named Task)
With Generic Views you get Insert, Update and Delete for free without any real work. give it a try and let me know what you think.
from django.conf.urls.defaults import *
info_dict = {
'app_label': 'tasks',
'module_name': 'tasks',
}
urlpatterns = patterns('',
(r'^tasks/create/?$', 'django.views.generic.create_update.create_object', info_dict ),
(r'^tasks/update/(?P<object_id>\d+)/?$', 'django.views.generic.create_update.update_object', info_dict),
(r'^tasks/delete/(?P<object_id>\d+)/?$', 'django.views.generic.create_update.delete_object', info_dict ),
)
Django Docs: https://docs.djangoproject.com/en/1.2/ref/generic-views/#create-update-delete-generic-views
I am a complete and total newbie with MediaWiki. I would like to find a way to include Recent Changes directly on the Main Page, without having to have the user navigate to the recent changes page. What are my options for this?
Thanks!
One way would be to put
{{Special:RecentChanges}}
in [[Main_Page]].
The News extension (available at http://www.mediawiki.org/wiki/Extension:News ) is a way to do this very simply, and can be customized so that the entire recent changes page is not displayed. Just install the extension and then adding the
<news/>
tag will include the 10 most recent changes. Parameters to change the number of items shown, exclude minor changes, or format how they are displayed are available on the website linked above.
There is also an extension : Dynamic Article List - which allows you more control over what to display in your list of recent changes.
http://meta.wikimedia.org/wiki/User:Socoljam/DynamicArticleList_%28enhanced%29
This is an enhanced version of a MediaWiki extension of the same name. It also provides slightly clearer instructions to install it and get it working.
I wanted the same thing, but in a much simpler list than the full output of {{Special:RecentChanges}}. The following database query gives just the page names of the changes in the last 30 days, without the recently deleted pages:
SELECT DISTINCT rc_title
FROM recentchanges
WHERE rc_timestamp > (CURRENT_DATE - INTERVAL '30 days')
AND rc_new_len > 0
ORDER BY rc_title
(This is with PostgreSQL. It might be slightly different with MySQL)
To put that on the Main page, I used the ExternalData extension with it's #get_db_data function.
In LocalSettings.php:
wfLoadExtension( 'ExternalData' );
$wgExternalDataSources['mydb'] = [
'server' => '127.0.0.1', // or 'yourwiki.example.com',
'type' => 'postgres', // mysql, postgres, sqlite, ...
'name' => 'wikidb', // wiki DB name
'user' => 'backup_bot', // user with only "SELECT" rights
'password' => ''
];
Then, in the Main_page:
{{#get_db_data:
db=mydb
|from=recentchanges
|where=rc_timestamp > (CURRENT_DATE - INTERVAL '30 days') AND rc_new_len > 0
|order by=rc_title
|group by=rc_title
|data= title=rc_title
|suppress error
}}
Changes in the last 30 days:
{| class="wikitable"
! title
{{#for_external_table:<nowiki/>
{{!}}-
{{!}} {{{title}}}
}}
|}
Or as a simple list:
{{#for_external_table:
* [[{{{title}}}]]
}}