Example #1
0
 public function build()
 {
     $article = $this->Agent->getArticle();
     $text = $article->getContent(true);
     # Strip comments and <nowiki>
     $text = preg_replace("/<!--.*?-->/s", "", $text);
     $text = preg_replace("@<nowiki>.*?</nowiki>@s", "", $text);
     # change template usage to substitution; note that this is WRONG
     #$tchars = Title::legalChars();
     #$text = preg_replace("/(?<!{){{([$tchars]+)(\|.*?)?}}(?!})/", "{{subst:$1$2}}", $text);
     $parser = new Parser();
     # so the magic variables work out right
     $parser->mOptions = new ParserOptions();
     $parser->mTitle = $this->Agent->getTitle();
     $parser->mOutputType = OT_WIKI;
     $parser->initialiseVariables();
     $parser->clearState();
     $text = $parser->replaceVariables($text);
     preg_match_all("@<rdf>(.*?)</rdf>@s", $text, $matches, PREG_PATTERN_ORDER);
     $content = $matches[1];
     $rdf = implode(' ', array_values($content));
     $model = MwRdf::Model();
     if (strlen($rdf) > 0) {
         $parser->mOutputType = OT_HTML;
         $rdf = $parser->replaceVariables($rdf);
         $turtle_parser = MwRdf::Parser('turtle');
         $base_uri = $this->Agent->getTitle()->getFullUrl();
         $prelude = MwRdf::getNamespacePrelude();
         $model->loadStatementsFromString($turtle_parser, $prelude . $rdf);
     }
     return $model;
 }
 public static function render($input, $args, Parser $parser)
 {
     // Create InputBox
     $inputBox = new InputBox($parser);
     // Configure InputBox
     $inputBox->extractOptions($parser->replaceVariables($input));
     // Return output
     return $inputBox->render();
 }
 /**
  * Parser hook for the <opengraph> tag.
  * 
  * This tag is dual-purpose. By specifying the "type" attribute, the type
  * of Open Graph object represented by the wiki page can be set. The
  * additional attributes set the <meta> properties for the object. Even
  * if "type" isn't specified, the other attributes can still be used to
  * override the default properties.
  * 
  * If the "action" attribute is given, this tag will render a link that,
  * when clicked, adds an action to the Facebook user's Timeline with the
  * wiki page as the target object. If no action is given, $innertext is
  * discarded.
  */
 public static function parserHook($innertext, array $args, Parser $parser, PPFrame $frame)
 {
     global $wgFbOpenGraph, $wgFbOpenGraphCustomObjects;
     if (empty($wgFbOpenGraph) || empty($wgFbOpenGraphCustomObjects)) {
         return '';
         // Open Graph is disabled for this wiki
     }
     if (isset($args['action'])) {
         $action = $args['action'];
         unset($args['action']);
     } else {
         $action = '';
     }
     if (count($args)) {
         foreach ($args as $key => $value) {
             // Expand template arguments
             $value = trim($parser->replaceVariables($value, $frame));
             // Check if $value is a wiki link
             if (substr($value, 0, 2) == '[[') {
                 $resolved = $parser->replaceInternalLinks($value);
                 $parser->replaceLinkHolders($resolved);
                 preg_match('/^<a\\b[^<>]*?\\bhref=("[^"]*"|\'[^\']*\')/', $resolved, $matches);
                 if (count($matches) >= 2) {
                     global $wgServer;
                     // strip quotes
                     $matches[1] = substr($matches[1], 1, strlen($matches[1]) - 2);
                     $url = $wgServer . $matches[1];
                 }
             }
             $value = !empty($url) ? $url : $parser->recursiveTagParse($value, $frame);
             $args[$key] = htmlspecialchars($value);
         }
         self::registerProperties($parser->getTitle(), $args);
     }
     // TODO: Insert a placeholder so that actions can be placed above type definitions on the page
     if ($action != '') {
         // See if the action is available for the object type
         $object = self::newObjectFromTitle($parser->getTitle());
         $actions = $object->getCustomActions();
         if (count($actions) && in_array($action, $actions)) {
             // Let the page know it should load the actions module
             global $wgVersion;
             if (version_compare($wgVersion, '1.17', '>=')) {
                 global $wgOut;
                 $wgOut->addModules('ext.facebook.actions');
             }
             $innertext = htmlspecialchars($parser->replaceVariables($innertext, $frame));
             return '<a href="#" class="mw-facebook-logo opengraph-action opengraph-action-' . $action . '">' . $innertext . '</a>';
         }
     }
     return '';
 }
Example #4
0
function wfCOQuestionBoxRender($input, $argv, Parser $parser)
{
    global $wgUser;
    if (wfReadOnly() || !$wgUser->isAllowed('edit') || $wgUser->isBlocked()) {
        return '';
    }
    $submit = SpecialPage::getTitleFor("NewCommentsOnlyQuestion")->getLocalURL();
    $text = '';
    $width = 100;
    //TODO read params from input
    $label = wfMsgHtml('comments-only-new-thread');
    $output = <<<ENDFORM
<div class="questionbox">
<form name="questionbox" action="{$submit}" method="get" class="questionboxForm">
<input class="questionboxInput" name="question" type="text" value="{$text}" size="{$width}"/>
<input type='submit' name="create" class="questionboxButton" value="{$label}"/>
</form></div>
ENDFORM;
    return $parser->replaceVariables($output);
}
Example #5
0
 function parseArticleText($text)
 {
     if ($text === '') {
         return '';
     } else {
         if ($this->mExpandTemplates) {
             global $wgTitle;
             $parser = new Parser();
             $parser->Options(new ParserOptions());
             // We don't want this to be user-specific
             $parser->Title($wgTitle);
             $parser->OutputType(OT_HTML);
             return $parser->replaceVariables($text);
         } else {
             return $text;
         }
     }
 }
 protected function parse($wikitext, $params, $newline = false)
 {
     $withVars = $this->parser->replaceVariables($wikitext, $this->parser->getPreprocessor()->newCustomFrame($params));
     $parserOutput = $this->parser->parse($withVars, $this->parser->getTitle(), $this->parser->getOptions(), $newline);
     return preg_replace('|{{{.*}}}|Us', '', preg_replace('|[\\n\\r]|Us', '', $parserOutput->getText()));
 }
Example #7
0
 function MwRdfInPage($article)
 {
     $text = $article->getContent(true);
     $parser = new Parser();
     $text = $parser->preprocess($text, $article->mTitle, new ParserOptions());
     preg_match_all("@<rdf>(.*?)</rdf>@s", $text, $matches, PREG_PATTERN_ORDER);
     $content = $matches[1];
     $rdf = implode(' ', array_values($content));
     $model = null;
     if (strlen($rdf) > 0) {
         $parser->mOutputType = OT_HTML;
         $rdf = $parser->replaceVariables($rdf);
         global $default_prefixes, $wgRdfNamespaces;
         require_once RDFAPI_INCLUDE_DIR . PACKAGE_SYNTAX_N3;
         $parser = new N3Parser();
         $parser->baseURI = $article->mTitle->getFullURL();
         $prefixes = array_merge($default_prefixes, $wgRdfNamespaces, MwRdfNamespacePrefixes());
         $prelude = "";
         foreach ($prefixes as $prefix => $uri) {
             $prelude .= "@prefix {$prefix}: <{$uri}> .\n";
         }
         # XXX: set correct properties
         $model = $parser->parse2model($prelude . $rdf);
         if ($model === false) {
             global $RDFS_comment;
             $model = ModelFactory::getDefaultModel();
             $model->add(new Statement(MwRdfArticleResource($article), $RDFS_comment, MwRdfLiteral("Error parsing in-page RDF: " . $parser->errors[0] . "\n code here: \n '" . $prelude . $rdf . "'", null, "en")));
         } else {
             # To make it unique, we unite with an empty model
             $fake = new MemModel();
             $model =& $fake->unite($model);
         }
     }
     return $model;
 }
Example #8
0
 /**
  * Renrder the spark div.
  *
  * @since 0.1
  *
  * @param Parser $parser
  *
  * @return string
  */
 public function render(Parser $parser, $frame)
 {
     global $wgVersion;
     global $wgOut;
     global $egSparkScriptPath;
     global $wgResourceModules;
     // What is loaded already?
     static $loadedJsses = array();
     wfDebugLog('myextension', 'Parameters alright? ' . print_r($this->parameters, true));
     if (array_key_exists(egSparkQuery, $this->parameters)) {
         $query = htmlspecialchars($this->parameters[egSparkQuery]);
         // Before that, shall we allow internal parse, at least for the query?
         // We replace variables, templates etc.
         $query = $parser->replaceVariables($query, $frame);
         //$query = $parser->recursiveTagParse( $query );
         // Replace special characters
         $query = str_replace(array('&lt;', '&gt;'), array('<', '>'), $query);
         unset($this->parameters[egSparkQuery]);
         // Depending on the format, we possibly need to add modules
         if (array_key_exists(egSparkFormat, $this->parameters)) {
             $format = htmlspecialchars($this->parameters[egSparkFormat]);
             // Remove everything before "spark.XXX"
             $format = substr($format, strpos($format, "spark."));
             // Remove .js at the end
             $format = str_replace(array('.js'), array(''), $format);
             $module = 'ext.' . $format;
             // for older versions of MW, different
             if (version_compare($wgVersion, '1.17', '<')) {
                 if (isset($wgResourceModules) && array_key_exists($module, $wgResourceModules)) {
                     // only if not already loaded
                     if (!isset($loadedJsses[$module])) {
                         // scripts
                         foreach ($wgResourceModules[$module]['scripts'] as $script) {
                             $wgOut->addScript('<script src="' . $egSparkScriptPath . "/" . $script . '" type="text/javascript"></script>');
                             wfDebugLog('spark', "AddScript:" . ' <script src="' . $egSparkScriptPath . "/" . $script . '" type="text/javascript"></script>');
                         }
                         // css
                         foreach ($wgResourceModules[$module]['styles'] as $style) {
                             $wgOut->addScript('<link rel="stylesheet" href="' . $egSparkScriptPath . "/" . $style . '" type="text/css" />');
                             wfDebugLog('spark', "AddLink:" . ' <link rel="stylesheet" href="' . $egSparkScriptPath . "/" . $style . '" type="text/css" />');
                         }
                         $loadedJsses[$module] = true;
                     }
                 }
             } else {
                 // $wgResourceModules might not exist
                 if (isset($wgResourceModules) && array_key_exists($module, $wgResourceModules)) {
                     // TODO: Do we need to check, whether module has been added already?
                     $parser->getOutput()->addModules($module);
                 }
             }
         }
         $html = '<div class="spark" data-spark-query="' . $query . '" ' . Html::expandAttributes($this->parameters) . ' >' . (is_null($this->contents) ? '' : htmlspecialchars($this->contents)) . '</div>';
         // In MW 1.17 there seems to be the problem that ? after an empty space is replaced by a non-breaking space (&#160;) Therefore we remove all spaces before ? which should still make the SPARQL query work
         $html = preg_replace('/[ \\t]+(\\?)/', '$1', $html);
         // for older versions of MW, different
         if (version_compare($wgVersion, '1.17', '<')) {
             $parser->disableCache();
             return $html;
         } else {
             return array($parser->insertStripItem($html, $parser->mStripState), 'noparse' => true, 'isHTML' => true);
         }
     } else {
         return Html::element('i', array(), wfMsg('spark-missing-query'));
     }
 }