예제 #1
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']);
}
예제 #2
0
function WidgetSlideshowGetImagesFromSpecialPage()
{
    wfProfileIn(__METHOD__);
    $images = array();
    // format: "*File_name.ext description goes here\n" (no spaces in the filename; no \newlines inside the description)
    $content = WidgetFramework::getArticle('WidgetSlideshowImages', NS_MEDIAWIKI);
    if (empty($content)) {
        wfProfileOut(__METHOD__);
        return array();
    }
    $list = explode("\n*", trim($content, "\n *"));
    // format data and get image thumb src
    foreach ($list as $row) {
        list($imageName, $description) = explode(' ', trim($row, '* '), 2);
        $img = wfFindFile($imageName);
        if (is_object($img)) {
            $url = Title::newFromText($imageName, NS_IMAGE);
            $thumb = $img->createThumb(250, 125);
            if (!empty($thumb)) {
                $images[] = array('thumb' => $thumb, 'alt' => $description, 'url' => is_object($url) ? $url->getLocalURL() : '');
            }
        }
    }
    wfProfileOut(__METHOD__);
    return $images;
}