+ function preSaveTransform( $text, &$title, &$user, $options, $clearState = true )
+ {
+ $this->mOptions = $options;
+ $this->mTitle = $title;
+ if ( $clearState ) {
+ $this->clearState;
+ }
+
+ $stripState = false;
+ $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;
+
+ # 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( "/~~~~/", "[[" . $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 );
+ }
+
+ # {{SUBST:xxx}} variables
+ #
+ $mw =& MagicWord::get( MAG_SUBST );
+ $text = $mw->substituteCallback( $text, "wfReplaceSubstVar" );
+
+ # 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 );
+
+ return $text;
+ }
+