Difference between revisions of "Talk:MediaWiki code snippets"
(Logging to file failing) |
|||
(3 intermediate revisions by 2 users not shown) | |||
Line 14: | Line 14: | ||
It is failing on this line <code>$ts = $GLOBALS['wgLang']->timeanddate(wfTimestampNow(),true);</code>. Where is the timeanddate set within the MediaWiki classes? --[[User:Sven|Sven]] 13:33, 10 December 2007 (NZDT) | It is failing on this line <code>$ts = $GLOBALS['wgLang']->timeanddate(wfTimestampNow(),true);</code>. Where is the timeanddate set within the MediaWiki classes? --[[User:Sven|Sven]] 13:33, 10 December 2007 (NZDT) | ||
+ | : Looks like $GLOBALS['wgLang'] doesn't exist anymore in <code>print_r($GLOBALS); </code> either --[[User:Sven|Sven]] 13:36, 10 December 2007 (NZDT) | ||
+ | :: I used the backtick to get a timestamp in the meantime | ||
+ | <php> | ||
+ | logFile("/tmp/FOO","this is a test message..."); | ||
+ | |||
+ | # Logging to a file | ||
+ | function logFile($file, $msg) { | ||
+ | $fh = fopen($file,'w'); | ||
+ | # $ts = $GLOBALS['wgLang']->timeanddate(wfTimestampNow(),true); | ||
+ | $ts = `date`; | ||
+ | if(is_array($msg)) $msg = print_r($msg, true); | ||
+ | fwrite($fh, "\n$ts: $msg"); | ||
+ | } | ||
+ | </php> --[[User:Sven|Sven]] 14:57, 10 December 2007 (NZDT) | ||
+ | |||
+ | == 8 Wikitext in Sidebar == | ||
+ | |||
+ | Had a bit of trouble getting this example to work. This gave me the result in the end: | ||
+ | <pre> | ||
+ | <div id='p-page-nav' class="portlet"> | ||
+ | <? | ||
+ | $title = Title::newFromText("Nav"); | ||
+ | $article = new Article($title); | ||
+ | $parser = new Parser; | ||
+ | print $parser->parse($article->fetchContent(),$title,new ParserOptions,true,true)->getText(); | ||
+ | ?> | ||
+ | </div> | ||
+ | </pre> | ||
+ | --[[User:Rob|Rob]] 12:17, 13 December 2007 (NZDT) | ||
+ | |||
+ | === Add a new tab === | ||
+ | |||
+ | The new Vector code snippet adds a tab to the existing visible row, it should be possible to get a new tab into the drop down list also. |
Latest revision as of 00:19, 25 July 2010
This function failed for me when put at the beginning of an extension;
<php> logFile("FOO","FODDA");
- Logging to a file
function logFile($file, $msg) { $fh = fopen($file,'a'); $ts = $GLOBALS['wgLang']->timeanddate(wfTimestampNow(),true); if(is_array($msg)) $msg = print_r($msg, true); fwrite($fh, "\n$ts: $msg"); } </php>
It is failing on this line $ts = $GLOBALS['wgLang']->timeanddate(wfTimestampNow(),true);
. Where is the timeanddate set within the MediaWiki classes? --Sven 13:33, 10 December 2007 (NZDT)
- Looks like $GLOBALS['wgLang'] doesn't exist anymore in
print_r($GLOBALS);
either --Sven 13:36, 10 December 2007 (NZDT)- I used the backtick to get a timestamp in the meantime
<php> logFile("/tmp/FOO","this is a test message...");
- Logging to a file
function logFile($file, $msg) { $fh = fopen($file,'w');
- $ts = $GLOBALS['wgLang']->timeanddate(wfTimestampNow(),true);
$ts = `date`;
if(is_array($msg)) $msg = print_r($msg, true); fwrite($fh, "\n$ts: $msg"); } </php> --Sven 14:57, 10 December 2007 (NZDT)
8 Wikitext in Sidebar
Had a bit of trouble getting this example to work. This gave me the result in the end:
<div id='p-page-nav' class="portlet"> <? $title = Title::newFromText("Nav"); $article = new Article($title); $parser = new Parser; print $parser->parse($article->fetchContent(),$title,new ParserOptions,true,true)->getText(); ?> </div>
--Rob 12:17, 13 December 2007 (NZDT)
Add a new tab
The new Vector code snippet adds a tab to the existing visible row, it should be possible to get a new tab into the drop down list also.