0

How can I find the date/time of the last edit to my entire wiki? I would like to write this date/time to a text file and then present it as info on one of my wiki pages as described here using the ExternalData extension.

thank you, russ

Note 1: Error message I'm getting (using ExternalData 2.3) after editing LocalSettings.php

enter image description here

Note 2: The error message I'm getting after upgrading to ExternalData 3.0

enter image description here

Note 3: After replacing {{#get_external_data: with {{#get_db_data: I get this result (using either 2.3 or 3.0):

enter image description here

Note 4: Relevant lines from LocalSettings.php

$wgScriptPath = "/mediawiki-1.35.1";
$wgServer = WebRequest::detectServer();

## Database settings
$wgDBtype = "mysql";
$wgDBserver = "localhost";
$wgDBname = "mywikidbname";
$wgDBuser = "mywikidbuser";
$wgDBpassword = "*********";

# MySQL specific settings
$wgDBprefix = "";

# MySQL table options to use during installation or update
$wgDBTableOptions = "ENGINE=InnoDB, DEFAULT CHARSET=binary";

$wgShellLocale = "C.UTF-8";

# Enabled extensions. Most of the extensions are enabled by adding
# wfLoadExtension( 'ExtensionName' );
# to LocalSettings.php. Check specific extension documentation for more details.
# The following extensions were automatically enabled:
wfLoadExtension( 'ConfirmEdit' );
wfLoadExtension( 'PdfHandler' );
wfLoadExtension( 'SpamBlacklist' );
wfLoadExtension( 'TitleBlacklist' );
#wfLoadExtension( 'VisualEditor' );
wfLoadExtension( 'WikiEditor' );
wfLoadExtension( 'MathJax' );
wfLoadExtension( 'ImageMap' );
wfLoadExtension( 'Quiz' );
wfLoadExtension( 'TextScroller' );

wfLoadExtension( 'ExternalData' );
$edgCacheExpireTime=10;
$edgFilePath['inject'] = '/home/rwp/shares/share_wiki/rwp_external_data.txt';

$wgExternalDataSources['MW DB'] = [
    'type'      => 'mysql',
    'server'    => $wgDBserver,
    'user'      => $wgDBuser,
    'password'  => $wgDBpassword,
    'name'      => $wgDBname,
    'prepared'  => [
        'last revision' => 'SELECT rev_timestamp AS last FROM revision ORDER BY rev_timestamp DESC LIMIT 1;'
    ]
];
relayman357
  • 793
  • 1
  • 6
  • 30

1 Answers1

1

Using External Data, you can insert the time of the last revision to the wiki without a file. Add to LocalSettings.php:

$wgExternalDataSources['MW DB'] = [
    'type'      => 'mysql',
    'server'    => $wgDBserver,
    'user'      => $wgDBuser,
    'password'  => $wgDBpassword,
    'name'      => $wgDBname,
    'prepared'  => [
        'last revision' => 'SELECT MAX(rev_timestamp) AS last FROM revision;'
    ]
];

Then get the required time with {{#get_external_data: db = MW DB | query = last revision | data = last = last}}{{#time: r | {{#external_value: last}} }} .

If you want to use a file, create it with the following bash script:

mysql -h ($wgDBserver) -u ($wgDBuser) -p($wgDBpassword) ($wgDBname) -e "SELECT MAX(rev_timestamp) AS last FROM revision;" > last_revision.txt
Alexander Mashin
  • 3,892
  • 1
  • 9
  • 15
  • Thank you Alexander. I tried it and I'm getting an "Error: Invalid time." I edited my question to show you the error message – relayman357 Mar 11 '22 at 21:11
  • I can see that `{{#get_external_data:}}` is not recognized. Therefore, your ExternalData version is obsolete. I recommend to upgrade it. – Alexander Mashin Mar 12 '22 at 06:00
  • Thank you Alexander. I downloaded and replaced my ExternalData folder with the new version 3.0 and ran 'php update.php'. Now I'm getting an error with the extension saying a class name must be a valid object or a string. I've added the error message as Note 2 to my post above. – relayman357 Mar 13 '22 at 16:56
  • If you used git, checkout master. Your version is not the current one, because in the current version the line 158 is a comment. Also, run `composer update` in the extension. Also, make sure you have restarted php after the upgrade, and that you haven't overridden `$wgExternalDataSources` as a whole in `LocalSettings.php`. If all this doesn't help, replace `{{#get_external_data:` with `{{#get_db_data:`. – Alexander Mashin Mar 14 '22 at 04:12
  • I downloaded a zip of 3.0 from [here](https://www.mediawiki.org/wiki/Extension:External_Data/Download_and_installation). Maybe the zip is not updated like git? The Readme file says it is version 3.0. I'm still getting the error message about line 158. Line 158 in EDConnectorBase.php has, " return new $class( $supplemented, $title );". I have rebooted as well. – relayman357 Mar 15 '22 at 14:18
  • I retrieved the extension using git and am getting same result. I also tried replacing `{{#get_external_data:` with `{{#get_db_data:` and am getting a new error message. I added it to my post as Note 3. – relayman357 Mar 15 '22 at 14:34
  • I have checked the zip file; it's up to date. What path have you `git clone`d? Are you sure that your MediaWiki installation loads External Data from the cloned repository and not from some other old directory? For these messages show that your copy of External Data hasn't got `{{#get_external_data:}}`, ignores `$wgExternalDataSources` and doesn't work with prepared statements; i.e., it's not 3.0 and far behind master branch (older than July 2021). You can also check out the Special:Version wiki page and extensions `extension.json`. – Alexander Mashin Mar 15 '22 at 16:27
  • I used the git command [here](https://www.mediawiki.org/wiki/Extension:External_Data/Download_and_installation) to clone the folder to my desktop. Then i copied it to the wiki extensions folder (after renaming the original ExternalData folder) and ran the updates & rebooted. Special:Version reports version: 3.0 (ef671fb) 03:13, 14 March 2022 – relayman357 Mar 15 '22 at 17:54
  • Does the directory `ExternalData` contain the file `includes/connectors/EDConnectorPreparedMysql.php`? – Alexander Mashin Mar 15 '22 at 18:25
  • Yes sir, `EDConnectorPreparedMysql.php` is in that folder. Size is 2.0kB (4.1kB on disk). File has 79 lines in it. – relayman357 Mar 15 '22 at 18:45
  • Can you list all External Data settings from `LocalSettings.php`? Mask the sensitive information. – Alexander Mashin Mar 16 '22 at 02:17
  • Yes sir, i have added the relevant lines from `LocalSettings.php` as Note 4 in my post. I have been using ExternalData (2.3) for a while now to display information from a text file as you can see. – relayman357 Mar 16 '22 at 02:40
  • I have just reproduced your settings relevant to External Data, as they are, in my installation, and the query works as expected, producing `Sun, 13 Mar 2022 07:08:56 +0000`. – Alexander Mashin Mar 16 '22 at 03:06
  • Ok, thank you. I’ll keep tinkering with it. Appreciate your time and help. – relayman357 Mar 16 '22 at 12:49