コード例 #1
0
 function genParserOptions()
 {
     global $wgUser;
     $this->mParserOptions = ParserOptions::newFromUser($wgUser);
     $this->mParserOptions->setDateFormat('default');
     $this->mParserOptions->setEditSection(false);
 }
コード例 #2
0
ファイル: Installer.php プロジェクト: GodelDesign/Godel
 /**
  * Constructor, always call this from child classes.
  */
 public function __construct()
 {
     global $wgExtensionMessagesFiles, $wgUser, $wgHooks;
     // Disable the i18n cache and LoadBalancer
     Language::getLocalisationCache()->disableBackend();
     LBFactory::disableBackend();
     // Load the installer's i18n file.
     $wgExtensionMessagesFiles['MediawikiInstaller'] = dirname(__FILE__) . '/Installer.i18n.php';
     // Having a user with id = 0 safeguards us from DB access via User::loadOptions().
     $wgUser = User::newFromId(0);
     $this->settings = $this->internalDefaults;
     foreach ($this->defaultVarNames as $var) {
         $this->settings[$var] = $GLOBALS[$var];
     }
     foreach (self::getDBTypes() as $type) {
         $installer = $this->getDBInstaller($type);
         if (!$installer->isCompiled()) {
             continue;
         }
         $defaults = $installer->getGlobalDefaults();
         foreach ($installer->getGlobalNames() as $var) {
             if (isset($defaults[$var])) {
                 $this->settings[$var] = $defaults[$var];
             } else {
                 $this->settings[$var] = $GLOBALS[$var];
             }
         }
     }
     $this->parserTitle = Title::newFromText('Installer');
     $this->parserOptions = new ParserOptions();
     // language will  be wrong :(
     $this->parserOptions->setEditSection(false);
 }
コード例 #3
0
 function genParserOptions()
 {
     global $wgUser;
     $this->mParserOptions = ParserOptions::newFromUser($wgUser);
     $this->mParserOptions->setDateFormat(MW_DATE_DEFAULT);
     $this->mParserOptions->setEditSection(false);
 }
コード例 #4
0
ファイル: Installer.php プロジェクト: spring/spring-website
 /**
  * Constructor, always call this from child classes.
  */
 public function __construct()
 {
     global $wgMessagesDirs, $wgUser;
     // Disable the i18n cache and LoadBalancer
     Language::getLocalisationCache()->disableBackend();
     LBFactory::disableBackend();
     // Load the installer's i18n.
     $wgMessagesDirs['MediawikiInstaller'] = __DIR__ . '/i18n';
     // Having a user with id = 0 safeguards us from DB access via User::loadOptions().
     $wgUser = User::newFromId(0);
     $this->settings = $this->internalDefaults;
     foreach ($this->defaultVarNames as $var) {
         $this->settings[$var] = $GLOBALS[$var];
     }
     $this->compiledDBs = array();
     foreach (self::getDBTypes() as $type) {
         $installer = $this->getDBInstaller($type);
         if (!$installer->isCompiled()) {
             continue;
         }
         $this->compiledDBs[] = $type;
     }
     $this->parserTitle = Title::newFromText('Installer');
     $this->parserOptions = new ParserOptions();
     // language will  be wrong :(
     $this->parserOptions->setEditSection(false);
 }
コード例 #5
0
ファイル: Installer.php プロジェクト: D66Ha/mediawiki
 /**
  * Constructor, always call this from child classes.
  */
 public function __construct()
 {
     global $wgMessagesDirs, $wgUser;
     // Disable the i18n cache
     Language::getLocalisationCache()->disableBackend();
     // Disable LoadBalancer and wfGetDB etc.
     LBFactory::disableBackend();
     // Disable object cache (otherwise CACHE_ANYTHING will try CACHE_DB and
     // SqlBagOStuff will then throw since we just disabled wfGetDB)
     $GLOBALS['wgMemc'] = new EmptyBagOStuff();
     ObjectCache::clear();
     $emptyCache = array('class' => 'EmptyBagOStuff');
     $GLOBALS['wgObjectCaches'] = array(CACHE_NONE => $emptyCache, CACHE_DB => $emptyCache, CACHE_ANYTHING => $emptyCache, CACHE_MEMCACHED => $emptyCache);
     // Load the installer's i18n.
     $wgMessagesDirs['MediawikiInstaller'] = __DIR__ . '/i18n';
     // Having a user with id = 0 safeguards us from DB access via User::loadOptions().
     $wgUser = User::newFromId(0);
     $this->settings = $this->internalDefaults;
     foreach ($this->defaultVarNames as $var) {
         $this->settings[$var] = $GLOBALS[$var];
     }
     $this->doEnvironmentPreps();
     $this->compiledDBs = array();
     foreach (self::getDBTypes() as $type) {
         $installer = $this->getDBInstaller($type);
         if (!$installer->isCompiled()) {
             continue;
         }
         $this->compiledDBs[] = $type;
     }
     $this->parserTitle = Title::newFromText('Installer');
     $this->parserOptions = new ParserOptions();
     // language will be wrong :(
     $this->parserOptions->setEditSection(false);
 }
コード例 #6
0
ファイル: wr_parser_sa.php プロジェクト: akoehn/wikireader
function wfSetParserOptions()
{
    global $wgParserOptions, $wgParser;
    $wgParserOptions = new ParserOptions(null);
    $wgParserOptions->setEditSection(false);
    $wgParser->Options($wgParserOptions);
    return $wgParserOptions;
}
コード例 #7
0
ファイル: Erudite.skin.php プロジェクト: CMDM-Lab/lab_website
 /**
  * Like msgWiki() but it ensures edit section links are never shown.
  *
  * Needed for Mediawiki 1.19 & 1.20 due to bug 36975:
  * https://bugzilla.wikimedia.org/show_bug.cgi?id=36975
  *
  * @param $message Name of wikitext message to return
  */
 function msgWikiNoEdit($message)
 {
     global $wgOut;
     global $wgParser;
     $popts = new ParserOptions();
     $popts->setEditSection(false);
     $text = wfMessage($message)->text();
     return $wgParser->parse($text, $wgOut->getTitle(), $popts)->getText();
 }
コード例 #8
0
ファイル: RTEAjax.class.php プロジェクト: Tjorriemorrie/app
 /**
  * Parse provided wikitext to HTML using RTE parser
  */
 public static function rteparse()
 {
     global $wgTitle, $wgRequest, $wgUser;
     wfProfileIn(__METHOD__);
     $wikitext = $wgRequest->getVal('wikitext', '');
     $parserOptions = new ParserOptions();
     // don't show [edit] link for sections
     $parserOptions->setEditSection(false);
     // disable headings numbering
     $parserOptions->setNumberHeadings(false);
     $parser = new RTEParser();
     // call preSaveTransform so signatures, {{subst:foo}}, etc. will work
     $wikitext = $parser->preSaveTransform($wikitext, $wgTitle, $wgUser, $parserOptions);
     // parse wikitext using RTE parser
     $html = $parser->parse($wikitext, $wgTitle, $parserOptions)->getText();
     $res = array('html' => $html);
     wfProfileOut(__METHOD__);
     return $res;
 }
コード例 #9
0
 public static function embedWiki($input, $argv)
 {
     //		if(!ETParserFunctions::$inlineParser) {
     //			global $wgParserConf;
     //			ETParserFunctions::$inlineParser = wfCreateObject( $wgParserConf['class'], array( $wgParserConf ) );
     //		}
     global $wgParser;
     if ($wgParser->getTitle() instanceof Title && $wgParser->getOptions() instanceof ParserOptions) {
         $result = $wgParser->recursiveTagParse($input);
     } else {
         global $wgTitle;
         $popt = new ParserOptions();
         $popt->setEditSection(false);
         $pout = $wgParser->parse($input . '__NOTOC__', $wgTitle, $popt);
         // / NOTE: as of MW 1.14SVN, there is apparently no better way to hide the TOC
         SMWOutputs::requireFromParserOutput($pout);
         $result = $pout->getText();
     }
     return $result;
 }
コード例 #10
0
ファイル: Installer.php プロジェクト: paladox/mediawiki
 /**
  * Constructor, always call this from child classes.
  */
 public function __construct()
 {
     global $wgMemc, $wgUser, $wgObjectCaches;
     $defaultConfig = new GlobalVarConfig();
     // all the stuff from DefaultSettings.php
     $installerConfig = self::getInstallerConfig($defaultConfig);
     // Reset all services and inject config overrides
     MediaWiki\MediaWikiServices::resetGlobalInstance($installerConfig);
     // Don't attempt to load user language options (T126177)
     // This will be overridden in the web installer with the user-specified language
     RequestContext::getMain()->setLanguage('en');
     // Disable the i18n cache
     // TODO: manage LocalisationCache singleton in MediaWikiServices
     Language::getLocalisationCache()->disableBackend();
     // Disable all global services, since we don't have any configuration yet!
     MediaWiki\MediaWikiServices::disableStorageBackend();
     // Disable object cache (otherwise CACHE_ANYTHING will try CACHE_DB and
     // SqlBagOStuff will then throw since we just disabled wfGetDB)
     $wgObjectCaches = MediaWikiServices::getInstance()->getMainConfig()->get('ObjectCaches');
     $wgMemc = ObjectCache::getInstance(CACHE_NONE);
     // Having a user with id = 0 safeguards us from DB access via User::loadOptions().
     $wgUser = User::newFromId(0);
     RequestContext::getMain()->setUser($wgUser);
     $this->settings = $this->internalDefaults;
     foreach ($this->defaultVarNames as $var) {
         $this->settings[$var] = $GLOBALS[$var];
     }
     $this->doEnvironmentPreps();
     $this->compiledDBs = [];
     foreach (self::getDBTypes() as $type) {
         $installer = $this->getDBInstaller($type);
         if (!$installer->isCompiled()) {
             continue;
         }
         $this->compiledDBs[] = $type;
     }
     $this->parserTitle = Title::newFromText('Installer');
     $this->parserOptions = new ParserOptions($wgUser);
     // language will be wrong :(
     $this->parserOptions->setEditSection(false);
 }
コード例 #11
0
ファイル: ApiIncludeWP.php プロジェクト: schwarer2006/wikia
 public function execute()
 {
     global $egPushLoginUser, $egPushLoginPass, $egPushLoginUsers, $egPushLoginPasswords;
     $params = $this->extractRequestParams();
     if (!isset($params['text'])) {
         $this->dieUsageMsg(array('missingparam', 'text'));
     }
     if (!isset($params['pagename'])) {
         $this->dieUsageMsg(array('missingparam', 'pagename'));
     }
     $plaintext = $params['text'];
     // Remove comments.
     $plaintext = preg_replace('/\\<!--([^(--\\>)]*)--\\>/', '', $plaintext);
     // Remove ref tags.
     $plaintext = preg_replace('/<ref[^>]*\\>(.*?)<\\/ref>/si', '', $plaintext);
     // Replace both internal and external wiki links with their plain text.
     $plaintext = preg_replace('/\\[http(?:s)?:\\/\\/\\S*\\s([^\\]]*)]/', '$1', $plaintext);
     $plaintext = preg_replace('/http(?:s)?:\\/\\/\\S*/', '$1', $plaintext);
     $plaintext = preg_replace('/\\[\\[(?!(Category|Image|File|[^\\s]{2,5}:))[^\\|\\]]*\\|([^\\]]*)\\]\\]/', '$2', $plaintext);
     $plaintext = preg_replace('/\\[\\[((?!(Category|Image|File|[^\\s]{2,5}:))[^\\]]*)\\]\\]/', '$1', $plaintext);
     // Remove categories and files (images).
     $plaintext = preg_replace('/\\[\\[(Category|File|Image|):[^\\]]+\\]\\]/', '', $plaintext);
     // Remove inter language links.
     $plaintext = preg_replace('/\\[\\[[^\\s]{2,5}:[^\\s][^\\]]+\\]\\]/', '', $plaintext);
     for ($i = 3; $i > 0; $i--) {
         $plaintext = preg_replace("/\\{\\{(?:[^\\}\\{]*)?\\}\\}/", '', $plaintext);
     }
     // Render the wikitext
     $parser = new Parser();
     $options = new ParserOptions();
     $options->setEditSection(false);
     $plaintext = $parser->parse(trim($plaintext), Title::newFromText($params['pagename']), $options)->getText();
     // Remove excess whitespace
     $plaintext = preg_replace('/\\s\\s+/', ' ', $plaintext);
     $plaintext = str_replace("<p><br />\n</p>", '', $plaintext);
     $this->getResult()->addValue(null, null, $plaintext);
 }
コード例 #12
0
ファイル: SMW_QP_RSSlink.php プロジェクト: Tjorriemorrie/app
 /**
  * Creates the RSS output for the single item.
  */
 public function text()
 {
     global $wgServer, $wgParser, $smwgShowFactbox, $smwgRSSWithPages;
     static $parser_options = null;
     $smwgShowFactbox = SMW_FACTBOX_HIDDEN;
     // just hide factbox; no need to restore this setting, I hope that nothing comes after FILE outputs
     $text = "\t<item rdf:about=\"{$this->uri}\">\n";
     $text .= "\t\t<title>" . smwfXMLContentEncode($this->label) . "</title>\n";
     $text .= "\t\t<link>" . smwfXMLContentEncode($this->uri) . "</link>\n";
     foreach ($this->date as $date) {
         $text .= "\t\t<dc:date>{$date}</dc:date>\n";
     }
     foreach ($this->creator as $creator) {
         $text .= "\t\t<dc:creator>" . smwfXMLContentEncode($creator) . "</dc:creator>\n";
     }
     if ($smwgRSSWithPages) {
         $parser_options = new ParserOptions();
         $parser_options->setEditSection(false);
         // embedded sections should not have edit links
         $parserOutput = $wgParser->parse('{{' . $this->articlename . '}}', $this->title, $parser_options);
         $content = $parserOutput->getText();
         // Make absolute URLs out of the local ones:
         ///TODO is there maybe a way in the parser options to make the URLs absolute?
         $content = str_replace('<a href="/', '<a href="' . $wgServer . '/', $content);
         $text .= "\t\t<description>" . smwfXMLContentEncode($content) . "</description>\n";
         $text .= "\t\t<content:encoded  rdf:datatype=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral\"><![CDATA[{$content}]]></content:encoded>\n";
     }
     $text .= "\t</item>\n";
     return $text;
 }
コード例 #13
0
 public function __construct($name, $options, $lang)
 {
     global $wgContLang;
     if (!self::$parserOptions) {
         self::$parserOptions = new ParserOptions();
         self::$parserOptions->setEditSection(false);
         self::$parser = new Parser();
     }
     $this->name = $name;
     $this->options = $options;
     if ($options['inUserLanguage']) {
         $this->language = $lang;
     } else {
         $this->language = $wgContLang;
     }
 }
コード例 #14
0
ファイル: OutputPage.php プロジェクト: OrBin/mediawiki
 /**
  * Get/set the ParserOptions object to use for wikitext parsing
  *
  * @param ParserOptions|null $options Either the ParserOption to use or null to only get the
  *   current ParserOption object
  * @return ParserOptions
  */
 public function parserOptions($options = null)
 {
     if ($options !== null && !empty($options->isBogus)) {
         // Someone is trying to set a bogus pre-$wgUser PO. Check if it has
         // been changed somehow, and keep it if so.
         $anonPO = ParserOptions::newFromAnon();
         $anonPO->setEditSection(false);
         if (!$options->matches($anonPO)) {
             wfLogWarning(__METHOD__ . ': Setting a changed bogus ParserOptions: ' . wfGetAllCallers(5));
             $options->isBogus = false;
         }
     }
     if (!$this->mParserOptions) {
         if (!$this->getContext()->getUser()->isSafeToLoad()) {
             // $wgUser isn't unstubbable yet, so don't try to get a
             // ParserOptions for it. And don't cache this ParserOptions
             // either.
             $po = ParserOptions::newFromAnon();
             $po->setEditSection(false);
             $po->isBogus = true;
             if ($options !== null) {
                 $this->mParserOptions = empty($options->isBogus) ? $options : null;
             }
             return $po;
         }
         $this->mParserOptions = ParserOptions::newFromContext($this->getContext());
         $this->mParserOptions->setEditSection(false);
     }
     if ($options !== null && !empty($options->isBogus)) {
         // They're trying to restore the bogus pre-$wgUser PO. Do the right
         // thing.
         return wfSetVar($this->mParserOptions, null, true);
     } else {
         return wfSetVar($this->mParserOptions, $options);
     }
 }
コード例 #15
0
function smwf_nm_NotifyAccess( $method, $params ) {
	$p_array = explode( ",", $params );
	global $smwgQEnabled;

	$result = "Query disabled.";
	if ( $method == "updateMail" ) {
		global $wgUser;
		$wgUser->setOption( 'enotifyme', $params );
		$wgUser->saveSettings();
		return wfMsg( 'smw_nm_ajax_mailupdate' );
	}
	elseif ( $method == "addNotify" ) {
		if ( $smwgQEnabled ) {
			$result = SMWNotifyProcessor::addNotify( str_replace( '&amp;', '&', str_replace( '&comma;', ',', $p_array[0] ) ),
				str_replace( '&amp;', '&', str_replace( '&comma;', ',', $p_array[3] ) ),
				$p_array[1], $p_array[2], implode( ",", array_slice( $p_array, 4 ) ) );
		}
		return $result;
	}
	elseif ( $method == "getQueryResult" ) {
		if ( $smwgQEnabled ) {
			$params .= '
| format=table
| link=all';

			// parse params and answer query
			SMWQueryProcessor::processFunctionParams( SMWNotifyProcessor::getQueryRawParams( $params ), $querystring, $params, $printouts );

			$result = SMWQueryProcessor::getResultFromQueryString( $querystring, $params, $printouts, SMW_OUTPUT_WIKI );
			switch ( $params->format ) {
				case 'timeline':
					return $result;
					break;
				case 'eventline':
					return $result;
					break;
				case 'googlepie':
					return $result[0];
					break;
				case 'googlebar':
					return $result[0];
					break;
				case 'exhibit':
					return $result;
					break;
				default:
			}
			global $wgParser;

		   	if ( ( $wgParser->getTitle() instanceof Title ) && ( $wgParser->getOptions() instanceof ParserOptions ) ) {
				$result = $wgParser->recursiveTagParse( $result );
			} else {
				global $wgTitle;
				$popt = new ParserOptions();
				$popt->setEditSection( false );
				$pout = $wgParser->parse( $result . '__NOTOC__', $wgTitle, $popt );
				// / NOTE: as of MW 1.14SVN, there is apparently no better way to hide the TOC
				SMWOutputs::requireFromParserOutput( $pout );
				$result = $pout->getText();
			}

			// add target="_new" for all links
			$pattern = "|<a|i";
			$result = preg_replace( $pattern, '<a target="_new"', $result );
		}
		return $result;
	}
	elseif ( $method == "updateStates" ) {
		if ( $smwgQEnabled ) {
			$result = SMWNotifyProcessor::updateStates( $p_array );
		}
		return $result;
	}
	elseif ( $method == "updateReportAll" ) {
		if ( $smwgQEnabled ) {
			$result = SMWNotifyProcessor::updateReportAll( $p_array );
		}
		return $result;
	}
	elseif ( $method == "updateShowAll" ) {
		if ( $smwgQEnabled ) {
			$result = SMWNotifyProcessor::updateShowAll( $p_array );
		}
		return $result;
	}
	elseif ( $method == "updateDelegates" ) {
		if ( $smwgQEnabled ) {
			$result = SMWNotifyProcessor::updateDelegates( explode( "|", $params ) );
		}
		return $result;
	}
	elseif ( $method == "delNotify" ) {
		if ( $smwgQEnabled ) {
			$result = SMWNotifyProcessor::delNotify( $p_array );
		}
		return $result;
	}
	else {
		return wfMsg( 'smw_nm_ajax_fail' );
	}
}
コード例 #16
0
 /**
  * Convert from/to wikitext/html using Parser.
  *
  * This only supports wikitext to HTML.
  *
  * @param string $from Format of content to convert: wikitext
  * @param string $to Format to convert to: html
  * @param string $content
  * @param Title $title
  * @return string
  * @throws WikitextException When the conversion is unsupported
  */
 protected static function parser($from, $to, $content, Title $title)
 {
     if ($from !== 'wikitext' && $to !== 'html') {
         throw new WikitextException("Conversion from '{$from}' to '{$to}' was requested, but core's Parser only supports 'wikitext' to 'html' conversion", 'process-wikitext');
     }
     global $wgParser;
     $options = new \ParserOptions();
     $options->setTidy(true);
     $options->setEditSection(false);
     $output = $wgParser->parse($content, $title, $options);
     return $output->getText();
 }
コード例 #17
0
ファイル: Skin.php プロジェクト: GodelDesign/Godel
 /**
  * Add content from plain text
  * @since 1.17
  * @param &$bar array
  * @param $text string
  */
 function addToSidebarPlain(&$bar, $text)
 {
     $lines = explode("\n", $text);
     $wikiBar = array();
     # We need to handle the wikitext on a different variable, to avoid trying to do an array operation on text, which would be a fatal error.
     $heading = '';
     foreach ($lines as $line) {
         if (strpos($line, '*') !== 0) {
             continue;
         }
         if (strpos($line, '**') !== 0) {
             $heading = trim($line, '* ');
             if (!array_key_exists($heading, $bar)) {
                 $bar[$heading] = array();
             }
         } else {
             $line = trim($line, '* ');
             if (strpos($line, '|') !== false) {
                 // sanity check
                 $line = array_map('trim', explode('|', $line, 2));
                 $link = wfMsgForContent($line[0]);
                 if ($link == '-') {
                     continue;
                 }
                 $text = wfMsgExt($line[1], 'parsemag');
                 if (wfEmptyMsg($line[1], $text)) {
                     $text = $line[1];
                 }
                 if (wfEmptyMsg($line[0], $link)) {
                     $link = $line[0];
                 }
                 if (preg_match('/^(?:' . wfUrlProtocols() . ')/', $link)) {
                     $href = $link;
                 } else {
                     $title = Title::newFromText($link);
                     if ($title) {
                         $title = $title->fixSpecialName();
                         $href = $title->getLocalURL();
                     } else {
                         $href = 'INVALID-TITLE';
                     }
                 }
                 $bar[$heading][] = array('text' => $text, 'href' => $href, 'id' => 'n-' . strtr($line[1], ' ', '-'), 'active' => false);
             } else {
                 if (substr($line, 0, 2) == '{{' && substr($line, -2) == '}}') {
                     global $wgParser, $wgTitle;
                     $line = substr($line, 2, strlen($line) - 4);
                     $options = new ParserOptions();
                     $options->setEditSection(false);
                     $options->setInterfaceMessage(true);
                     $wikiBar[$heading] = $wgParser->parse(wfMsgForContentNoTrans($line), $wgTitle, $options)->getText();
                 } else {
                     continue;
                 }
             }
         }
     }
     if (count($wikiBar) > 0) {
         $bar = array_merge($bar, $wikiBar);
     }
     return $bar;
 }
コード例 #18
0
 /**
  * Get/set the ParserOptions object to use for wikitext parsing
  *
  * @param ParserOptions|null $options Either the ParserOption to use or null to only get the
  *   current ParserOption object
  * @return ParserOptions
  */
 public function parserOptions($options = null)
 {
     if (!$this->mParserOptions) {
         $this->mParserOptions = ParserOptions::newFromContext($this->getContext());
         $this->mParserOptions->setEditSection(false);
     }
     return wfSetVar($this->mParserOptions, $options);
 }
コード例 #19
0
 function parse_format_text(&$text, &$mvdTile, &$mvd_page = '', $absolute_links = false)
 {
     global $wgOut, $mvgScriptPath;
     global $wgParser, $wgUser, $wgTitle, $wgContLang;
     $template_key = '';
     if (is_object($mvdTile)) {
         $template_key = strtolower($mvdTile->getMvdTypeKey());
     }
     // $wgOut->addHTML('looking at: ' . strtolower($template_key));
     $sk =& $wgUser->getSkin();
     $pre_text_html = $post_text_html = '';
     $added_play_link = false;
     $smw_text_html = '';
     switch ($template_key) {
         case 'ht_en':
         case 'anno_en':
             $play_link_o = '<a href="javascript:mv_do_play(' . htmlspecialchars($mvd_page->id) . ')">';
             $play_link_img_close = '<img border="0" src="' . htmlspecialchars($mvgScriptPath) . '/skins/images/button_play.png">' . '</a>';
             $smw_attr = $this->get_and_strip_semantic_tags($text);
             foreach ($smw_attr as $smw_key => $smw_attr_val) {
                 // do special display for given values:
                 switch ($smw_key) {
                     case 'speech_by':
                     case 'spoken_by':
                         $pTitle = Title::newFromText($smw_attr_val);
                         if ($pTitle->exists()) {
                             $pimg = mv_get_person_img($smw_attr_val);
                             $pre_text_html .= '<p class="mvd_page_image">';
                             if ($mvd_page != '') {
                                 $pre_text_html .= $play_link_o;
                                 $added_play_link = true;
                             }
                             $pre_text_html .= '<img width="44" alt="' . $pTitle->getText() . '" ' . 'src="' . htmlspecialchars($pimg->getURL()) . '">';
                             if ($mvd_page != '') {
                                 $pre_text_html .= $play_link_img_close;
                             }
                             $pre_text_html .= '</p>';
                         }
                         break;
                 }
                 // @@todo we should just use semantic mediaWikis info box with some custom style .
                 $smwKeyTitle = Title::newFromText($smw_key);
                 $valueTitle = Title::newFromText($smw_attr_val);
                 if ($template_key == 'anno_en') {
                     $smw_text_html .= ucwords($smwKeyTitle->getText()) . ': ' . $sk->makeLinkObj($valueTitle) . '<br />';
                 }
             }
             if (!$added_play_link && $mvd_page != '') {
                 $pre_text_html .= '<p class="mvd_page_image">' . $play_link_o . $play_link_img_close . '</p>';
                 // print "SHOULD HAVE PUT IN pre_text:$pre_text_html";
             }
             $pre_text_html .= '<p class="text">';
             if ($mvd_page != '') {
                 $pre_text_html .= '<span class="mvd_menu_header">' . $this->get_mvd_menu($mvd_page) . '</span>';
             }
             // if absolute links clear out links:
             if ($absolute_links) {
                 $pre_text_html = '';
             }
             $pre_text_html .= '<span class="description">';
             $pre_text_html .= $smw_text_html;
             // for ht_en add spoken by add name to start of text:
             if ($template_key == 'ht_en') {
                 // if we have the person title add them to start of the text output:
                 if (isset($pTitle)) {
                     // have to prepend it cuz of <p> insertion for first paragraph
                     $text = '[[' . $pTitle->getText() . ']]: ' . trim($text);
                 }
             }
             $post_text_html .= '</span></p>';
             break;
         default:
             break;
     }
     // now add the text with categories if present:
     $sk =& $wgUser->getSkin();
     // run via parser to add in Category info:
     // $parserOptions = ParserOptions::newFromUser( $wgUser );
     $parserOptions = new ParserOptions();
     $parserOptions->setEditSection(false);
     $parserOptions->setTidy(true);
     $parserOutput = $wgParser->parse($text, $mvdTile, $parserOptions, true, true);
     $wgOut->addCategoryLinks($parserOutput->getCategories());
     $parserOutput->mText .= $sk->getCategories();
     $parserOutput->mText = $pre_text_html . $parserOutput->mText . $post_text_html;
     // empty out the categories (should work)
     $wgOut->mCategoryLinks = array();
     $parserOutput->mCategories = null;
     return $parserOutput;
 }
コード例 #20
0
ファイル: MessageCache.php プロジェクト: admonkey/mediawiki
 /**
  * ParserOptions is lazy initialised.
  *
  * @return ParserOptions
  */
 function getParserOptions()
 {
     global $wgFullyInitialised, $wgContLang;
     if (!$this->mParserOptions) {
         if (!$wgFullyInitialised) {
             // $wgUser isn't unstubbable yet, so don't try to get a
             // ParserOptions for it. And don't cache this ParserOptions
             // either.
             $po = new ParserOptions(new User(), $wgContLang);
             $po->setEditSection(false);
             return $po;
         }
         $this->mParserOptions = new ParserOptions();
         $this->mParserOptions->setEditSection(false);
     }
     return $this->mParserOptions;
 }
コード例 #21
0
/**
 * function content copied from SMWResultPrinter::getResult(). Using the constant
 * SMW_OUTPUT_HTML doesn't always work. Details see bug #10494
 * 
 * @param string  wikitext
 * @return string html
 */
function parseWikiText($text)
{
    global $wgParser;
    if ($wgParser->getTitle() instanceof Title && $wgParser->getOptions() instanceof ParserOptions) {
        $result = $wgParser->recursiveTagParse($text);
    } else {
        global $wgTitle;
        $popt = new ParserOptions();
        $popt->setEditSection(false);
        $pout = $wgParser->parse($text . '__NOTOC__', $wgTitle, $popt);
        /// NOTE: as of MW 1.14SVN, there is apparently no better way to hide the TOC
        SMWOutputs::requireFromParserOutput($pout);
        $result = $pout->getText();
    }
    return $result;
}
コード例 #22
0
 /**
  * Continuation of getResult that only gets executed for non file outputs.
  * 
  * @since 1.6
  * 
  * @param string $result
  * @param SMWQueryResult $results
  * @param integer $outputmode
  * 
  * @return string
  */
 protected function handleNonFileResult($result, SMWQueryResult $results, $outputmode)
 {
     global $wgParser;
     $result .= $this->getErrorString($results);
     // append errors
     if (!$this->isHTML && $this->hasTemplates) {
         // preprocess embedded templates if needed
         if ($wgParser->getTitle() instanceof Title && $wgParser->getOptions() instanceof ParserOptions) {
             SMWResultPrinter::$mRecursionDepth++;
             if (SMWResultPrinter::$mRecursionDepth <= SMWResultPrinter::$maxRecursionDepth) {
                 // restrict recursion
                 $result = '[[SMW::off]]' . $wgParser->replaceVariables($result) . '[[SMW::on]]';
             } else {
                 $result = '';
                 /// TODO: explain problem (too much recursive parses)
             }
             SMWResultPrinter::$mRecursionDepth--;
         } else {
             // not during parsing, no preprocessing needed, still protect the result
             $result = '[[SMW::off]]' . $result . '[[SMW::on]]';
         }
     }
     if ($this->isHTML && $outputmode == SMW_OUTPUT_WIKI) {
         $result = array($result, 'isHTML' => true);
     } elseif (!$this->isHTML && $outputmode == SMW_OUTPUT_HTML) {
         SMWResultPrinter::$mRecursionDepth++;
         // check whether we are in an existing parse, or if we should start a new parse for $wgTitle
         if (SMWResultPrinter::$mRecursionDepth <= SMWResultPrinter::$maxRecursionDepth) {
             // retrict recursion
             if ($wgParser->getTitle() instanceof Title && $wgParser->getOptions() instanceof ParserOptions) {
                 $result = $wgParser->recursiveTagParse($result);
             } else {
                 global $wgTitle;
                 $popt = new ParserOptions();
                 $popt->setEditSection(false);
                 $pout = $wgParser->parse($result . '__NOTOC__', $wgTitle, $popt);
                 /// NOTE: as of MW 1.14SVN, there is apparently no better way to hide the TOC
                 SMWOutputs::requireFromParserOutput($pout);
                 $result = $pout->getText();
             }
         } else {
             $result = '';
             /// TODO: explain problem (too much recursive parses)
         }
         SMWResultPrinter::$mRecursionDepth--;
     }
     if ($this->mIntro && $results->getCount() > 0) {
         if ($outputmode == SMW_OUTPUT_HTML) {
             global $wgParser;
             $result = $wgParser->recursiveTagParse($this->mIntro) . $result;
         } else {
             $result = $this->mIntro . $result;
         }
     }
     if ($this->mOutro && $results->getCount() > 0) {
         if ($outputmode == SMW_OUTPUT_HTML) {
             global $wgParser;
             $result = $result . $wgParser->recursiveTagParse($this->mOutro);
         } else {
             $result = $result . $this->mOutro;
         }
     }
     return $result;
 }
コード例 #23
0
ファイル: RTEAjax.class.php プロジェクト: schwarer2006/wikia
 /**
  * Get info about given wikitext with double brackets syntax (templates, magic words, parser functions)
  */
 public static function resolveDoubleBrackets()
 {
     global $wgRequest, $wgTitle, $wgRDBEnabled, $wgRDBData, $wgParser;
     // initialization of required objects and settings
     $wgParser->getstriplist();
     //we need to create (unstub) this object, because of in_array($tagName, $stripList) in parser
     $parser = new Parser();
     //$parser->mDefaultStripList = $parser->mStripList = array();
     $parser->mTagHooks =& $wgParser->mTagHooks;
     $parser->mStripList =& $wgParser->mStripList;
     $parserOptions = new ParserOptions();
     $parserOptions->setEditSection(false);
     // parsing wikitext in RDB (resolve double backets) mode
     $wgRDBEnabled = true;
     $wikitext = $wgRequest->getVal('wikitext', '');
     $html = $parser->parse($wikitext, $wgTitle, $parserOptions)->getText();
     // processing data from RDB mode
     if (!is_array($wgRDBData) || !isset($wgRDBData['type']) || $wgRDBData['type'] == 'error') {
         $out = array('type' => 'unknown');
     } else {
         if ($wgRDBData['type'] == 'tpl') {
             $out = array();
             $out['title'] = $wgRDBData['title']->getPrefixedDBkey();
             $out['exists'] = $wgRDBData['title']->exists() ? true : false;
             if ($out['exists']) {
                 $out['availableParams'] = RTE::getTemplateParams($wgRDBData['title'], $parser);
             }
             for ($i = 0; $i < $wgRDBData['args']->node->length; $i++) {
                 $arg = new PPNode_DOM($wgRDBData['args']->node->item($i));
                 $argSplited = $arg->splitArg();
                 $key = !empty($argSplited['index']) ? $argSplited['index'] : $argSplited['name']->node->textContent;
                 $value = $argSplited['value']->node->textContent;
                 $out['passedParams'][trim($key)] = trim($value);
             }
         }
         $out['type'] = $wgRDBData['type'];
         $out['html'] = $html;
     }
     return $out;
 }
コード例 #24
0
ファイル: API.php プロジェクト: moegirlwiki/MW-FlowThread
 public function execute()
 {
     $action = $this->getMain()->getVal('type');
     $page = $this->getMain()->getVal('pageid');
     try {
         // If post is set, get the post object by id
         // By fetching the post object, we also validate the id
         $postList = $this->getMain()->getVal('postid');
         $postList = $this->parsePostList($postList);
         switch ($action) {
             case 'list':
                 if (!$page) {
                     $this->dieNoParam('pageid');
                 }
                 $this->getResult()->addValue(null, $this->getModuleName(), $this->fetchPosts($page));
                 break;
             case 'like':
                 if (!$postList) {
                     $this->dieNoParam('postid');
                 }
                 foreach ($postList as $post) {
                     $post->setUserAttitude($this->getUser(), Post::ATTITUDE_LIKE);
                 }
                 $this->getResult()->addValue(null, $this->getModuleName(), '');
                 break;
             case 'dislike':
                 if (!$postList) {
                     $this->dieNoParam('postid');
                 }
                 foreach ($postList as $post) {
                     $post->setUserAttitude($this->getUser(), Post::ATTITUDE_NORMAL);
                 }
                 $this->getResult()->addValue(null, $this->getModuleName(), '');
                 break;
             case 'report':
                 if (!$postList) {
                     $this->dieNoParam('postid');
                 }
                 foreach ($postList as $post) {
                     $post->setUserAttitude($this->getUser(), Post::ATTITUDE_REPORT);
                 }
                 $this->getResult()->addValue(null, $this->getModuleName(), '');
                 break;
             case 'delete':
                 if (!$postList) {
                     $this->dieNoParam('postid');
                 }
                 foreach ($postList as $post) {
                     $post->delete($this->getUser());
                 }
                 $this->getResult()->addValue(null, $this->getModuleName(), '');
                 break;
             case 'recover':
                 if (!$postList) {
                     $this->dieNoParam('postid');
                 }
                 foreach ($postList as $post) {
                     $post->recover($this->getUser());
                 }
                 $this->getResult()->addValue(null, $this->getModuleName(), '');
                 break;
             case 'erase':
                 if (!$postList) {
                     $this->dieNoParam('postid');
                 }
                 foreach ($postList as $post) {
                     $post->erase($this->getUser());
                 }
                 $this->getResult()->addValue(null, $this->getModuleName(), '');
                 break;
             case 'post':
                 if (!$page) {
                     $this->dieNoParam('pageid');
                 }
                 $text = $this->getMain()->getVal('content');
                 if (!$text) {
                     $this->dieNoParam('content');
                 }
                 // Permission check
                 Post::checkIfCanPost($this->getUser());
                 $spam = !SpamFilter::validate($text);
                 // Parse as wikitext if specified
                 if ($this->getMain()->getCheck('wikitext')) {
                     $parser = new \Parser();
                     $opt = new \ParserOptions($this->getUser());
                     $opt->setEditSection(false);
                     $output = $parser->parse($text, \Title::newFromId($page), $opt);
                     $text = $output->getText();
                     unset($parser);
                     unset($opt);
                     unset($output);
                 }
                 $data = array('id' => null, 'pageid' => $page, 'userid' => $this->getUser()->getId(), 'username' => $this->getUser()->getName(), 'text' => $text, 'parentid' => count($postList) ? $postList[0]->id : null, 'status' => $spam ? Post::STATUS_SPAM : Post::STATUS_NORMAL, 'like' => 0, 'report' => 0);
                 $postObject = new Post($data);
                 global $wgMaxNestLevel;
                 // Restrict max nest level
                 if ($postObject->getNestLevel() > $wgMaxNestLevel) {
                     $postObject->parentid = $postObject->getParent()->parentid;
                     $postObject->parent = $postObject->getParent()->parent;
                 }
                 $postObject->post();
                 if ($spam) {
                     global $wgTriggerFlowThreadHooks;
                     if ($wgTriggerFlowThreadHooks) {
                         \Hooks::run('FlowThreadSpammed', array($postObject));
                     }
                 }
                 $this->getResult()->addValue(null, $this->getModuleName(), '');
                 break;
             default:
                 $this->dieUsage("Unrecognized value for parameter 'type': {$action}", 'unknown_type');
         }
     } catch (\UsageException $e) {
         throw $e;
     } catch (\Exception $e) {
         $this->getResult()->addValue("error", 'code', 'unknown_error');
         $this->getResult()->addValue("error", 'info', $e->getMessage());
     }
     return true;
 }
コード例 #25
0
 /**
  * Examines a wikitext string and finds users that were mentioned
  * @param  string $wikitext
  * @return array Array of User objects
  */
 protected function getMentionedUsersFromWikitext($wikitext)
 {
     global $wgParser;
     $title = Title::newMainPage();
     // Bogus title used for parser
     $options = new \ParserOptions();
     $options->setTidy(true);
     $options->setEditSection(false);
     $output = $wgParser->parse($wikitext, $title, $options);
     $links = $output->getLinks();
     if (!isset($links[NS_USER]) || !is_array($links[NS_USER])) {
         // Nothing
         return array();
     }
     $users = array();
     foreach ($links[NS_USER] as $dbk => $page_id) {
         $user = User::newFromName($dbk);
         if (!$user || $user->isAnon()) {
             continue;
         }
         $users[$user->getId()] = $user;
         // If more than 20 users are being notified this is probably a spam/attack vector.
         // Don't send any mention notifications
         if (count($users) > 20) {
             return array();
         }
     }
     return $users;
 }
コード例 #26
0
ファイル: RTE.class.php プロジェクト: schwarer2006/wikia
 /**
  * Parse given wikitext to HTML for CK
  */
 public static function WikitextToHtml($wikitext)
 {
     global $wgTitle;
     wfProfileIn(__METHOD__);
     $options = new ParserOptions();
     // don't show [edit] link for sections
     $options->setEditSection(false);
     // disable headings numbering
     $options->setNumberHeadings(false);
     RTE::$parser = new RTEParser();
     $html = RTE::$parser->parse($wikitext, $wgTitle, $options)->getText();
     wfProfileOut(__METHOD__);
     return $html;
 }
コード例 #27
0
ファイル: SMW_QP_Feed.php プロジェクト: Tjorriemorrie/app
 /**
  * Returns page content
  *
  * @since 1.8
  *
  * @param WikiPage $wikiPage
  *
  * @return string
  */
 protected function getPageContent(WikiPage $wikiPage)
 {
     if (in_array($this->params['page'], array('abstract', 'full'))) {
         $parserOptions = new ParserOptions();
         $parserOptions->setEditSection(false);
         if ($this->params['page'] === 'abstract') {
             // Abstract of the first 30 words
             // preg_match( '/^([^.!?\s]*[\.!?\s]+){0,30}/', $wikiPage->getText(), $abstract );
             // $text = $abstract[0] . ' ...';
         } else {
             if (method_exists($wikiPage, 'getContent')) {
                 $content = $wikiPage->getContent();
                 if ($content instanceof TextContent) {
                     $text = $content->getNativeData();
                 } else {
                     return '';
                 }
             } else {
                 $text = $wikiPage->getText();
             }
         }
         return $GLOBALS['wgParser']->parse($text, $wikiPage->getTitle(), $parserOptions)->getText();
     } else {
         return '';
     }
 }
コード例 #28
0
<?php

# Initialise common code
$preIP = dirname(__FILE__);
require_once "{$preIP}/includes/WebStart.php";
# Initialize MediaWiki base class
require_once "{$preIP}/includes/Wiki.php";
$mediaWiki = new MediaWiki();
include "includes/parser/ParserOptions.php";
include "includes/parser/Parser.php";
$option = new ParserOptions();
$option->setEditSection(false);
$title = Title::newFromText("set me to something");
$text = $wgParser->parse(file_get_contents('php://input'), $title, $option);
print $text->getText();
コード例 #29
0
ファイル: wr_parser.php プロジェクト: josephdye/wikireader
function wfSetParserOptions()
{
    global $wgParserOptions, $wgParser;
    $wgParserOptions = new ParserOptions(null);
    $wgParserOptions->setEditSection(false);
    $wgParserOptions->setTemplateCallback(array('ParserOffline', 'fetchTemplate'));
    $wgParser->Options($wgParserOptions);
    #$wgParser->disableCache();
    return $wgParserOptions;
}