+ $this->mOptions = $options;
+ $this->mTitle =& $title;
+ $this->mOutputType = OT_WIKI;
+
+ if ( $clearState ) {
+ $this->clearState();
+ }
+
+ $stripState = false;
+ $text = str_replace("\r\n", "\n", $text);
+ $text = $this->strip( $text, $stripState, false );
+ $text = $this->pstPass2( $text, $user );
+ $text = $this->unstrip( $text, $stripState );
+ return $text;
+ }
+
+ /* private */ function pstPass2( $text, &$user )
+ {
+ global $wgLang, $wgLocaltimezone, $wgCurParser;
+
+ # Variable replacement
+ # Because mOutputType is OT_WIKI, this will only process {{subst:xxx}} type tags
+ $text = $this->replaceVariables( $text );
+
+ # Signatures
+ #
+ $n = $user->getName();
+ $k = $user->getOption( "nickname" );
+ if ( "" == $k ) { $k = $n; }
+ if(isset($wgLocaltimezone)) {
+ $oldtz = getenv("TZ"); putenv("TZ=$wgLocaltimezone");
+ }
+ /* Note: this is an ugly timezone hack for the European wikis */
+ $d = $wgLang->timeanddate( date( "YmdHis" ), false ) .
+ " (" . date( "T" ) . ")";
+ if(isset($wgLocaltimezone)) putenv("TZ=$oldtz");
+
+ $text = preg_replace( "/~~~~~/", $d, $text );
+ $text = preg_replace( "/~~~~/", "[[" . $wgLang->getNsText(
+ Namespace::getUser() ) . ":$n|$k]] $d", $text );
+ $text = preg_replace( "/~~~/", "[[" . $wgLang->getNsText(
+ Namespace::getUser() ) . ":$n|$k]]", $text );
+
+ # Context links: [[|name]] and [[name (context)|]]
+ #
+ $tc = "[&;%\\-,.\\(\\)' _0-9A-Za-z\\/:\\x80-\\xff]";
+ $np = "[&;%\\-,.' _0-9A-Za-z\\/:\\x80-\\xff]"; # No parens
+ $namespacechar = '[ _0-9A-Za-z\x80-\xff]'; # Namespaces can use non-ascii!
+ $conpat = "/^({$np}+) \\(({$tc}+)\\)$/";
+
+ $p1 = "/\[\[({$np}+) \\(({$np}+)\\)\\|]]/"; # [[page (context)|]]
+ $p2 = "/\[\[\\|({$tc}+)]]/"; # [[|page]]
+ $p3 = "/\[\[($namespacechar+):({$np}+)\\|]]/"; # [[namespace:page|]]
+ $p4 = "/\[\[($namespacechar+):({$np}+) \\(({$np}+)\\)\\|]]/";
+ # [[ns:page (cont)|]]
+ $context = "";
+ $t = $this->mTitle->getText();
+ if ( preg_match( $conpat, $t, $m ) ) {
+ $context = $m[2];
+ }
+ $text = preg_replace( $p4, "[[\\1:\\2 (\\3)|\\2]]", $text );
+ $text = preg_replace( $p1, "[[\\1 (\\2)|\\1]]", $text );
+ $text = preg_replace( $p3, "[[\\1:\\2|\\2]]", $text );
+
+ if ( "" == $context ) {
+ $text = preg_replace( $p2, "[[\\1]]", $text );
+ } else {
+ $text = preg_replace( $p2, "[[\\1 ({$context})|\\1]]", $text );
+ }
+
+ /*
+ $mw =& MagicWord::get( MAG_SUBST );
+ $wgCurParser = $this->fork();
+ $text = $mw->substituteCallback( $text, "wfBraceSubstitution" );
+ $this->merge( $wgCurParser );
+ */
+
+ # Trim trailing whitespace
+ # MAG_END (__END__) tag allows for trailing
+ # whitespace to be deliberately included
+ $text = rtrim( $text );
+ $mw =& MagicWord::get( MAG_END );
+ $mw->matchAndRemove( $text );
+