示例#1
0
function wfRenderVideoGallery($input, $argv, $parser)
{
    global $wgTitle;
    $vg = new VideoGallery();
    $vg->setContextTitle($wgTitle->getText());
    $vg->setShowFilename(true);
    $vg->setParsing();
    if (isset($argv['perrow'])) {
        $vg->setPerRow($argv['perrow']);
    }
    if (isset($params['widths'])) {
        $vg->setWidths($argv['widths']);
    }
    if (isset($params['heights'])) {
        $vg->setHeights($argv['heights']);
    }
    $lines = explode("\n", $input);
    foreach ($lines as $line) {
        // match lines like these:
        // Video:Some video name|This is some video
        $matches = array();
        preg_match("/^([^|]+)(\\|(.*))?\$/", $line, $matches);
        // Skip empty lines
        if (count($matches) == 0) {
            continue;
        }
        $tp = Title::newFromText($matches[1]);
        $nt =& $tp;
        if (is_null($nt)) {
            // Bogus title. Ignore these so we don't bomb out later.
            continue;
        }
        if (isset($matches[3])) {
            $label = $matches[3];
        } else {
            $label = '';
        }
        $html = '';
        /*
        $pout = $this->parse( $label,
        	$this->mTitle,
        	$this->mOptions,
        	false, // Strip whitespace...?
        	false  // Don't clear state!
        );
        $html = $pout->getText();
        */
        // Gah, there should be a better way to get context here
        $vg->add(new Video($nt, RequestContext::getMain()), $html);
    }
    return $vg->toHTML();
}
function VideoGalleryPopulate($input, $args, $parser)
{
    $parser->disableCache();
    $category = isset($args['category']) ? $args['category'] : '';
    $limit = isset($args['limit']) ? intval($args['limit']) : 10;
    if (empty($category)) {
        return '';
    }
    // Use Parser::recursivePreprocess() if available instead of creating another Parser instance
    if (is_callable(array($parser, 'recursivePreprocess'))) {
        $category = $parser->recursivePreprocess($category);
    } else {
        $newParser = new Parser();
        $category = $newParser->preprocess($category, $parser->getTitle(), $parser->getOptions());
    }
    $category_title = Title::newFromText($category);
    if (!$category_title instanceof Title) {
        return '';
    }
    // @todo FIXME: not overly i18n-friendly here...
    $category_title_secondary = Title::newFromText($category . ' Videos');
    if (!$category_title_secondary instanceof Title) {
        return '';
    }
    $params['ORDER BY'] = 'page_id';
    if ($limit) {
        $params['LIMIT'] = $limit;
    }
    $dbr = wfGetDB(DB_SLAVE);
    $res = $dbr->select(array('page', 'categorylinks'), 'page_title', array('cl_to' => array($category_title->getDBkey(), $category_title_secondary->getDBkey()), 'page_namespace' => NS_VIDEO), __METHOD__, $params, array('categorylinks' => array('INNER JOIN', 'cl_from = page_id')));
    $gallery = new VideoGallery();
    $gallery->setParsing(true);
    $gallery->setShowFilename(true);
    foreach ($res as $row) {
        $video = Video::newFromName($row->page_title, RequestContext::getMain());
        $gallery->add($video);
    }
    return $gallery->toHtml();
}