I am using a $wgHooks to insert some meta information in the <HEAD> section of the page.
How can I access the page's title and URL from within LocalSettings.php?
I am using a $wgHooks to insert some meta information in the <HEAD> section of the page.
How can I access the page's title and URL from within LocalSettings.php?
It can vary depending on hook but generally:
RequestContext::getMain()->getTitle()->getFullUrl()
RequestContext::getMain()->getTitle()->getPrefixedText()
(In a future version you might have to use \MediaWiki\Context\RequestContext::getMain()->getTitle()->getFullUrl() instead)
That's amazing, it worked! Many thanks :-)
How about getting the revision timestamp, in the same way?
Its more complicated... you'd have to do something like MediaWiki\MediawikiServices->getRevisionLookop()->getRevisionByTitle( RequestContext::getMain()->getTitle() )->getTimestamp();
The timestamp would be in machine format so you would need to format it with RequestContext::getMain()->getLanguage()->timeanddate() if you want it based on user preference, or wfTimestamp() if you need a specific format.
I didn't test any of this, so it might be slightly off, but should be roughly right.
There are docs for mediawiki classes at https://doc.wikimedia.org/mediawiki-core/master/php/ the classes i have mentioned are RequestContext, Title, RevisionRecord, RevisionLookup, Language