Пример #1
0
 function execute($subpage)
 {
     global $wgRequest, $wgParser, $wgOut;
     $this->setHeaders();
     $this->isNewParser = is_callable(array($wgParser, 'preprocessToDom'));
     $titleStr = $wgRequest->getText('contexttitle');
     $title = Title::newFromText($titleStr);
     $selfTitle = $this->getTitle();
     if (!$title) {
         $title = $selfTitle;
     }
     $input = $wgRequest->getText('input');
     $this->generateXML = $this->isNewParser ? $wgRequest->getBool('generate_xml') : false;
     if (strlen($input)) {
         $this->removeComments = $wgRequest->getBool('removecomments', false);
         $this->removeNowiki = $wgRequest->getBool('removenowiki', false);
         $options = new ParserOptions();
         $options->setRemoveComments($this->removeComments);
         $options->setTidy(true);
         $options->setMaxIncludeSize(self::MAX_INCLUDE_SIZE);
         if ($this->generateXML) {
             $wgParser->startExternalParse($title, $options, OT_PREPROCESS);
             $dom = $wgParser->preprocessToDom($input);
             if (is_callable(array($dom, 'saveXML'))) {
                 $xml = $dom->saveXML();
             } else {
                 $xml = $dom->__toString();
             }
         }
         $output = $wgParser->preprocess($input, $title, $options);
     } else {
         $this->removeComments = $wgRequest->getBool('removecomments', true);
         $this->removeNowiki = $wgRequest->getBool('removenowiki', false);
         $output = false;
     }
     $wgOut->addWikiText(wfMsg('expand_templates_intro'));
     $wgOut->addHTML($this->makeForm($titleStr, $input));
     if ($output !== false) {
         global $wgUseTidy, $wgAlwaysUseTidy;
         if ($this->generateXML) {
             $wgOut->addHTML($this->makeOutput($xml, 'expand_templates_xml_output'));
         }
         $tmp = $this->makeOutput($output);
         if ($this->removeNowiki) {
             $tmp = preg_replace(array('_<nowiki>_', '_</nowiki>_', '_<nowiki */>_'), '', $tmp);
         }
         if ($wgUseTidy && $options->getTidy() || $wgAlwaysUseTidy) {
             $tmp = MWTidy::tidy($tmp);
         }
         $wgOut->addHTML($tmp);
         $this->showHtmlPreview($title, $output, $wgOut);
     }
 }
Пример #2
0
function WidgetWikiPage($id, $params)
{
    global $wgTitle, $wgParser;
    wfProfileIn(__METHOD__);
    if (!is_object($wgTitle)) {
        $wgTitle = new Title();
    }
    // clean up inputs
    $params['source'] = trim($params['source']);
    $params['name'] = trim($params['name']);
    //stopgap for 67038
    $source = Title::newFromText($params['source']);
    if (is_object($source) && !$source->userCan('read')) {
        wfProfileOut(__METHOD__);
        return array('body' => '', 'title' => $params['name']);
    }
    //
    // parse message and clean it up
    //
    // fixes #2774
    if (isset($params['_widgetTag'])) {
        // work-around for WidgetTag
        $parser = new Parser();
    } else {
        $parser =& $wgParser;
    }
    $options = new ParserOptions();
    $options->setMaxIncludeSize(2048);
    if (empty($params['source'])) {
        // blank source pagename, use default message
        $ret = $parser->parse(wfMsg('widgetwikipage', $params['source']), $wgTitle, $options)->getText();
    } else {
        // has a source value
        // get contents
        $article = WidgetFramework::getArticle($params['source']);
        if ($article == false) {
            // failed to get text, show error message, failed pagename is in $1
            $ret = $parser->parse('<span class="widget-error-wikipage-missing">' . wfMsg('widgetwikipagemissing', $params['source']) . '</span>', $wgTitle, $options)->getText();
            // TODO: change title if page missing?
        } else {
            // got text, parse it!
            $ret = $parser->parse($article, $wgTitle, $options)->getText();
        }
    }
    wfProfileOut(__METHOD__);
    return array('body' => $ret, 'title' => $params['name']);
}
Пример #3
0
function WidgetShoutBox($id, $params)
{
    global $wgUser, $wgTitle, $wgRequest, $wgSitename, $wgLang, $wgEnableWidgetShoutbox;
    wfProfileIn(__METHOD__);
    // check if widget is enabled for this wiki and quit early if not
    if (isset($wgEnableWidgetShoutbox) && !$wgEnableWidgetShoutbox) {
        return wfMsg('widget-shoutbox-disabled');
    }
    // maybe user is trying to add a message to chat
    if ($wgRequest->getVal('message') && $wgRequest->getVal('rs') == 'WidgetFrameworkAjax') {
        $showChat = WidgetShoutBoxAddMessage($wgRequest->getVal('message'));
    } elseif ($wgRequest->getVal('msgid') && $wgRequest->getVal('rs') == 'WidgetFrameworkAjax') {
        //remove a message
        WidgetShoutBoxRemoveMessage($wgRequest->getVal('msgid'));
    }
    $ret = '';
    // should we show "chat" part of widget?
    $showChat = isset($showChat) || isset($_COOKIE[$id . '_showChat']) && intval($_COOKIE[$id . '_showChat']) == 1;
    $online = WidgetShoutBoxGetOnline();
    //WhosOnline is turned on
    if (is_array($online)) {
        // generate HTML for "who's online" part of widget
        $ret .= '<div id="' . $id . '_online"' . ($showChat ? ' style="display:none"' : '') . '>';
        $ret .= '<h5>' . wfMsg('monaco-whos-online') . ' (<a onclick="WidgetShoutboxTabToogle(\'' . $id . '\', 0)" style="cursor: pointer">chat! &raquo;</a>)</h5>' . '<p style="margin:8px 0">Guests: ' . $online['anons'] . ' <span style="margin-left: 10px">Users: ' . $online['users'] . '</span></p>';
        $list = array();
        foreach ($online['whosonline'] as $user) {
            $url = Title::newFromText($user['user'], NS_USER);
            $list[] = array('href' => $url->getLocalURL(), 'name' => $user['user']);
        }
        $more = Title::newFromText('WhosOnline', NS_SPECIAL);
        $ret .= WidgetFramework::wrapLinks($list) . WidgetFramework::moreLink($more->getLocalURL());
        unset($list, $more);
        $ret .= '</div>';
    } else {
        // fallback when WhosOnline is turned off
        $showChat = true;
    }
    // generate HTML for "chat" part of widget
    $ret .= '<div id="' . $id . '_chat" class="WidgetShoutBoxChat"' . (!$showChat ? ' style="display:none"' : '') . '>';
    #temp disable header. (remove hardcoded 'Chat' text + WhosOnline has been disabled forever, and not coming back?)
    #$ret .= '<h5>Chat' . ($online !== false ? ' (<a onclick="WidgetShoutboxTabToogle(\''.$id.'\', 1)" style="cursor: pointer">'.
    #	wfMsg('monaco-whos-online').'? &raquo;</a>)' : '') . '</h5>';
    $msgs = WidgetShoutBoxGetMessages();
    // date limiter - dates after that timestamp will be outputed in HH:mm (9:38) format, before in d M (8 Sep)
    $midnight = strtotime('today 00:00');
    // time offset (set by user in his preferences)
    $time_offset = $wgUser->getOption('timecorrection') ? (int) $wgUser->getOption('timecorrection') * 3600 : 0;
    $count = 0;
    // limit amount of messages
    $limit = intval($params['limit']);
    $limit = $limit <= 0 || $limit > 50 ? 15 : $limit;
    $msgs = array_slice($msgs, 0, $limit);
    // last message author
    $last_msg_author = '';
    $last_msg_time = 0;
    $ret .= '<ul>';
    $id = intval(substr($id, 7));
    if (count($msgs) == 0) {
        $ret .= '<li>&lt;' . htmlspecialchars($wgSitename) . '&gt; ' . wfMsg('wt_shoutbox_initial_message') . '</li>';
    } else {
        // create parser instance
        $options = new ParserOptions();
        $options->setMaxIncludeSize(100);
        // refs #1939
        $parser = new Parser();
        // display messages
        foreach (array_reverse($msgs) as $msg) {
            // trim message
            $msg['message'] = trim($msg['message']);
            // include offset in timestamp
            $msg['time'] += $time_offset;
            //add remove link for privlidged users
            $removeLink = '';
            if (!isset($params['_widgetTag']) && $wgUser->isAllowed('shoutboxremove')) {
                $removeLink = '<a href="#" onclick="WidgetShoutBoxRemoveMsg(' . $id . ', ' . $msg['id'] . '); return false;">x</a> ';
            }
            // time
            //adjust user's timezone
            $msg['time'] = intval($wgLang->sprintfDate('U', $wgLang->userAdjust(wfTimestamp(TS_MW, $msg['time']))));
            $ret .= '<li' . ($count++ % 2 ? ' class="msgOdd"' : '') . '>' . $removeLink . htmlspecialchars('[' . date($msg['time'] < $midnight ? 'j M' : 'G:i', $msg['time']) . ']') . '&nbsp;';
            // user page link
            $userPage = Title::newFromText($msg['user'], NS_USER);
            $userLink = '<a href="' . $userPage->getLocalURL() . '">' . htmlspecialchars($msg['user']) . '</a>';
            // interprete IRC-like command (e.g. /me is going away for a while)
            //
            // @see www.ircbeginner.com/ircinfo/ircc-commands.html
            //
            if (substr($msg['message'], 0, 1) == '/') {
                $cmd = substr($msg['message'], 1, strpos($msg['message'], ' ') - 1);
                $msg['message'] = substr($msg['message'], 2 + strlen($cmd));
            } else {
                $cmd = '';
            }
            // parse message
            $parsedMsg = $parser->parse($msg['message'], $wgTitle, $options)->getText();
            // remove unwanted HTML tags
            $parsedMsg = strip_tags($parsedMsg, '<i><b><a>');
            // remove wrapping <p></p> tags
            $parsedMsg = trim(str_replace(array('<p>', '</p>'), '', $parsedMsg));
            // interpret irc-like command
            switch ($cmd) {
                case 'me':
                    // macbre: that's the only one that might me useful for us - ideas?
                    $ret .= '<strong>* ' . $userLink . ' <span class="shoutBoxMsg">' . $parsedMsg . '</span></strong>';
                    $last_msg_author = '';
                    $last_msg_time = 0;
                    break;
                default:
                    // repeating authors folding (Skype a'like ;)
                    $ret .= ($last_msg_author == $msg['user'] && $msg['time'] - $last_msg_time < 1200 ? '<strong>...</strong> ' : '&lt;' . $userLink . '&gt; ') . '<span class="shoutBoxMsg">' . $parsedMsg . '</span>';
                    $last_msg_author = $msg['user'];
                    $last_msg_time = $msg['time'];
            }
            // close message
            $ret .= '</li>';
        }
    }
    $ret .= '</ul>';
    // show form only for non-blocked and logged in users
    if ($wgUser->isLoggedIn() && !$wgUser->isBlocked() && !isset($params['_widgetTag'])) {
        $ret .= '<form onsubmit="WidgetShoutBoxSend(' . $id . '); return false;" action="">' . "\n";
        $ret .= '<input type="text" name="message" autocomplete="off" id="widget_' . $id . '_message" maxlength="100" />' . "\n";
        $ret .= '<input type="submit" value="' . wfMsg('send') . '" />' . "\n";
        $ret .= '</form>';
    }
    $ret .= '</div>';
    // close chat div
    wfProfileOut(__METHOD__);
    return $ret;
}