Ejemplo n.º 1
0
 /**
  * Method for handling the declare parser function.
  * 
  * @since 1.5.3
  * 
  * @param Parser $parser
  * @param PPFrame $frame
  * @param array $args
  */
 public static function render(Parser &$parser, PPFrame $frame, array $args)
 {
     if ($frame->isTemplate()) {
         foreach ($args as $arg) {
             if (trim($arg) !== '') {
                 $expanded = trim($frame->expand($arg));
                 $parts = explode('=', $expanded, 2);
                 if (count($parts) == 1) {
                     $propertystring = $expanded;
                     $argumentname = $expanded;
                 } else {
                     $propertystring = $parts[0];
                     $argumentname = $parts[1];
                 }
                 $property = SMWPropertyValue::makeUserProperty($propertystring);
                 $argument = $frame->getArgument($argumentname);
                 $valuestring = $frame->expand($argument);
                 if ($property->isValid()) {
                     $type = $property->getPropertyTypeID();
                     if ($type == '_wpg') {
                         $matches = array();
                         preg_match_all('/\\[\\[([^\\[\\]]*)\\]\\]/u', $valuestring, $matches);
                         $objects = $matches[1];
                         if (count($objects) == 0) {
                             if (trim($valuestring) !== '') {
                                 SMWParseData::addProperty($propertystring, $valuestring, false, $parser, true);
                             }
                         } else {
                             foreach ($objects as $object) {
                                 SMWParseData::addProperty($propertystring, $object, false, $parser, true);
                             }
                         }
                     } elseif (trim($valuestring) !== '') {
                         SMWParseData::addProperty($propertystring, $valuestring, false, $parser, true);
                     }
                     // $value = SMWDataValueFactory::newPropertyObjectValue( $property->getDataItem(), $valuestring );
                     // if (!$value->isValid()) continue;
                 }
             }
         }
     } else {
         // @todo Save as metadata
     }
     global $wgTitle;
     if (!is_null($wgTitle) && $wgTitle->isSpecialPage()) {
         global $wgOut;
         SMWOutputs::commitToOutputPage($wgOut);
     } else {
         SMWOutputs::commitToParser($parser);
     }
     return '';
 }
Ejemplo n.º 2
0
 /**
  * Triple brace replacement -- used for template arguments
  * @private
  *
  * @param array $piece
  * @param PPFrame $frame
  *
  * @return array
  */
 public function argSubstitution($piece, $frame)
 {
     $error = false;
     $parts = $piece['parts'];
     $nameWithSpaces = $frame->expand($piece['title']);
     $argName = trim($nameWithSpaces);
     $object = false;
     $text = $frame->getArgument($argName);
     if ($text === false && $parts->getLength() > 0 && ($this->ot['html'] || $this->ot['pre'] || $this->ot['wiki'] && $frame->isTemplate())) {
         # No match in frame, use the supplied default
         $object = $parts->item(0)->getChildren();
     }
     if (!$this->incrementIncludeSize('arg', strlen($text))) {
         $error = '<!-- WARNING: argument omitted, expansion size too large -->';
         $this->limitationWarn('post-expand-template-argument');
     }
     if ($text === false && $object === false) {
         # No match anywhere
         $object = $frame->virtualBracketedImplode('{{{', '|', '}}}', $nameWithSpaces, $parts);
     }
     if ($error !== false) {
         $text .= $error;
     }
     if ($object !== false) {
         $ret = array('object' => $object);
     } else {
         $ret = array('text' => $text);
     }
     return $ret;
 }
 private function getThemeWithDefault($params, PPFrame $frame)
 {
     $value = isset($params['theme-source']) ? $frame->getArgument($params['theme-source']) : false;
     $themeName = $this->getThemeName($params, $value);
     //make sure no whitespaces, prevents side effects
     return Sanitizer::escapeClass(self::INFOBOX_THEME_PREFIX . preg_replace('|\\s+|s', '-', $themeName));
 }