lilalo

annotate l3pre.php @ 158:d775ffd49dbf

minifix: bsd/darwin in uname
author Igor Chubin <igor@chub.in>
date Wed Feb 01 17:14:54 2012 +0200 (2012-02-01)
parents 51a232faeb27
children
rev   line source
igor@142 1 <?
igor@150 2 $wgHooks['ParserAfterTidy'][] = 'wfLiLaLoParserAfterTidy';
igor@142 3 $wgExtensionFunctions[] = "wfLiLaLoExtension";
igor@142 4
igor@150 5 /*
igor@150 6
igor@150 7 More on this technic:
igor@150 8 http://www.mediawiki.org/wiki/Manual:Tag_extensions#How_can_I_avoid_modification_of_my_extension.27s_HTML_output.3F
igor@150 9
igor@150 10
igor@150 11 HTML tooltips from:
igor@150 12 http://www.walterzorn.com/tooltip/tooltip_e.htm#download
igor@150 13
igor@150 14 Also:
igor@150 15 http://sixrevisions.com/tutorials/javascript_tutorial/create_lightweight_javascript_tooltip/
igor@150 16
igor@150 17 */
igor@150 18
igor@142 19 function wfLiLaLoExtension() {
igor@142 20 global $wgParser;
igor@142 21 $wgParser->setHook( "lilalo", "renderLiLaLoPRE" );
igor@150 22 global $wgOut;
igor@150 23 $wgOut->addHTML('<script src="/js/wz_tooltip.js"></script>');
igor@142 24 }
igor@142 25
igor@150 26 $markerList = array();
igor@150 27
igor@142 28 function renderLiLaLoPRE( $input ) {
igor@150 29 global $markerList;
igor@143 30 preg_match('/[^\n]*l3: local_session_id=([0-9-]*)[^\n]*[\n]/', $input, $matches);
igor@143 31 $session_id=$matches[1];
igor@150 32 if ($session_id) {
igor@143 33 preg_match('/([0-9]*)-([0-9]*)/', $session_id, $matches);
igor@143 34 $session_start_time = intval($matches[2]);
igor@143 35 $hour=intval(date('G', $session_start_time));
igor@143 36 $min=intval(date('i', $session_start_time));
igor@143 37 $sec=intval(date('s', $session_start_time));
igor@143 38 $input = preg_replace('/[^\n]*l3: local_session_id=([0-9-]*)[^\n]*[\n]/', '', $input);
igor@143 39 $input = preg_replace('/((..):(..):(...)(#[^\n]*))/e',
igor@143 40 '\'$2:$3:$4<b><a href="http://xgu.ru/l3?page='.$session_id.'&id='
igor@143 41 .'\'.strval($session_start_time+3600*(intval("$2")-$hour)+60*(intval("$3")-$min)+1*(intval("$4")-$sec)).\''
igor@143 42 .'">$5</a></b>\'',
igor@143 43 $input);
igor@143 44 # .strval($session_start_time+3600*(intval($2)-$hour)+60*(intval($3)-$min)+(intval($4)-$sec))
igor@150 45 $time_prefix="$hour:$min:$sec ";
igor@150 46 }
igor@150 47 else
igor@150 48 {
igor@150 49 $tip_text='<table><tr><td>-n</td><td>show numerical addresses instead of trying to determine symbolic host names.<br/> This is useful if you are trying to determine why the route to your nameserver has vanished.</td></tr></table>';
igor@150 50 #$tip_text='<dv>1</dv>';
igor@150 51 $tip=" onmouseover=\"Tip('".$tip_text."')\" onmouseout=\"UnTip()\"";
igor@150 52 $input = preg_replace('/(%#.*)/', '<span style="font-weight:bold"'.$tip.'>$1</span>', $input);
igor@150 53 }
igor@150 54 $output = "<pre>$time_prefix$input</pre>";
igor@150 55 $markercount = count($markerList);
igor@150 56 $marker = "xx-lilalo-marker".$markercount."-xx";
igor@150 57 $markerList[$markercount] = $output;
igor@150 58 return $marker;
igor@150 59
igor@142 60 }
igor@142 61
igor@150 62 function wfLiLaLoParserAfterTidy(&$parser, &$text) {
igor@150 63 // find markers in $text
igor@150 64 // replace markers with actual output
igor@150 65 global $markerList;
igor@150 66 $keys = array();
igor@150 67 $marker_count = count($markerList);
igor@150 68
igor@150 69 for ($i = 0; $i < $marker_count; $i++) {
igor@150 70 $keys[$i] = 'xx-lilalo-marker' . $i . '-xx';
igor@150 71 }
igor@150 72
igor@150 73 $text = str_replace($keys, $markerList, $text);
igor@150 74 #$text = $marker_count;
igor@150 75 return true;
igor@150 76 }
igor@142 77 ?>