Jump to content
Wikimedia Meta-Wiki

FCKeditor/function parse

From Meta, a Wikimedia project coordination wiki
	function parse( $text, &$title, $options, $linestart = true, $clearState = true, $revid = null ) {
		/**
		 * First pass--just handle <nowiki> sections, pass the rest off
		 * to internalParse() which does all the real work.
		 */
		global $wgUseTidy, $wgAlwaysUseTidy, $wgContLang;
		$fname = 'Parser::parse';
		wfProfileIn( $fname );
		if ( $clearState ) {
			$this->clearState();
		}
		$this->mOptions = $options;
		$this->mTitle =& $title;
		$this->mRevisionId = $revid;
		$this->mOutputType = OT_HTML;
		$this->mStripState = NULL;
		//$text = $this->strip( $text, $this->mStripState );
		// VOODOO MAGIC FIX! Sometimes the above segfaults in PHP5.
		$x =& $this->mStripState;
		# patch fck editor
		global $wgUseEditor, $wgEditorToken;
 if (eregi($wgEditorToken, $text, $eregi_result)) {
			$wgUseEditor = true;
		}
		wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$x ) );
		$text = $this->strip( $text, $x );
		wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$x ) );
		if ($wgUseEditor == true) $text = preg_replace("|$wgEditorToken|i", "", $text);
		# Hook to suspend the parser in this state
		if ( !wfRunHooks( 'ParserBeforeInternalParse', array( &$this, &$text, &$x ) ) ) {
			wfProfileOut( $fname );
			return $text ;
		}
		$text = $this->internalParse( $text );
		$text = $this->unstrip( $text, $this->mStripState );
		# Clean up special characters, only run once, next-to-last before doBlockLevels
		$fixtags = array(
			# french spaces, last one Guillemet-left
			# only if there is something before the space
			'/(.) (?=\\?|:|;|!|\302円\273円)/' => '\1円 \2円',
			# french spaces, Guillemet-right
			'/(\302円\253円) /' => '\1円 ',
			'/<center *>(.*)<\\/center *>/i' => '<div class="center">\1円</div>',
		);
		$text = preg_replace( array_keys($fixtags), array_values($fixtags), $text );
		# only once and last
		if (!$wgUseEditor) $text = $this->doBlockLevels( $text, $linestart ); # patch editor
		$this->replaceLinkHolders( $text );
		# the position of the parserConvert() call should not be changed. it
		# assumes that the links are all replaced and the only thing left
		# is the <nowiki> mark.
		# Side-effects: this calls $this->mOutput->setTitleText()
		$text = $wgContLang->parserConvert( $text, $this );
		$text = $this->unstripNoWiki( $text, $this->mStripState );
		wfRunHooks( 'ParserBeforeTidy', array( &$this, &$text ) );
		$text = Sanitizer::normalizeCharReferences( $text );
		if (($wgUseTidy and $this->mOptions->mTidy) or $wgAlwaysUseTidy) {
			$text = Parser::tidy($text);
		} else {
			# attempt to sanitize at least some nesting problems
			# (bug #2702 and quite a few others)
			$tidyregs = array(	
				# ''Something [http://www.cool.com cool''] --> 
				# <i>Something</i><a href="http://www.cool.com"..><i>cool></i></a>
				'/(<([bi])>)(<([bi])>)?([^<]*)(<\/?a[^<]*>)([^<]*)(<\/\4円>)?(<\/\2円>)/' =>
				'\1円\3円\5円\8円\9円\6円\1円\3円\7円\8円\9円',
				# fix up an anchor inside another anchor, only
				# at least for a single single nested link (bug 3695)
				'/(<a[^>]+>)([^<]*)(<a[^>]+>[^<]*)<\/a>(.*)<\/a>/' =>
				'\1円\2円</a>\3円</a>\1円\4円</a>',
				# fix div inside inline elements- doBlockLevels won't wrap a line which
				# contains a div, so fix it up here; replace
				# div with escaped text
				'/(<([aib]) [^>]+>)([^<]*)(<div([^>]*)>)(.*)(<\/div>)([^<]*)(<\/\2円>)/' =>
				'\1円\3円<div\5円>\6円</div>\8円\9円',
				# remove empty italic or bold tag pairs, some
				# introduced by rules above
				'/<([bi])><\/\1円>/' => '' 
			);
			$text = preg_replace( 
				array_keys( $tidyregs ),
				array_values( $tidyregs ),
				$text );
		}
		wfRunHooks( 'ParserAfterTidy', array( &$this, &$text ) );
		$this->mOutput->setText( $text );
		wfProfileOut( $fname );
		return $this->mOutput;
	}

</nowiki>

AltStyle によって変換されたページ (->オリジナル) /