From 840dee3ad43a33d5b97b2e1dee64d5c04e255227 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sat, 6 Mar 2004 01:49:16 +0000 Subject: [PATCH] * Fixed magic quotes in $_REQUEST, in Setup.php * Converted many instances of globals from the query to $_REQUEST * Renamed near-useless Title::getURL() to Title::getPartialURL() * Created new Title::getURL(), to replace wfLocalUrl, wfLocalUrlE, wfFullUrl and wfFullUrlE. Replaced most instances throughout the code * In Parser.php, generalised stripping of ,
 and  to allow more general use such as nesting * Moved
 body of Article::preSaveTransform to Parser.php * Put lots of comments in
 Title.php

---
 includes/Article.php              | 102 ++---------
 includes/Database.php             |   4 +-
 includes/EditPage.php             |   5 +-
 includes/GlobalFunctions.php      |  26 ++-
 includes/MagicWord.php            |   6 +-
 includes/Namespace.php            |   4 +
 includes/OutputPage.php           |   4 +-
 includes/PageHistory.php          |   2 +-
 includes/Parser.php               | 235 +++++++++++++++++++------
 includes/SearchEngine.php         |  19 ++-
 includes/Setup.php                |   9 +
 includes/Skin.php                 |  30 ++--
 includes/SkinCologneBlue.php      |   5 +-
 includes/SkinSmarty.php           |   7 +-
 includes/SpecialAsksql.php        |   6 +-
 includes/SpecialBlockip.php       |   9 +-
 includes/SpecialEmailuser.php     |   9 +-
 includes/SpecialExport.php        |   3 +-
 includes/SpecialImagelist.php     |   4 +-
 includes/SpecialIpblocklist.php   |  17 +-
 includes/SpecialLockdb.php        |   9 +-
 includes/SpecialMakesysop.php     |   4 +-
 includes/SpecialMovepage.php      |  61 ++++---
 includes/SpecialPreferences.php   |   3 +-
 includes/SpecialUndelete.php      |   3 +-
 includes/SpecialUnlockdb.php      |   8 +-
 includes/SpecialUpload.php        |   7 +-
 includes/SpecialUserlogin.php     | 112 ++++++------
 includes/SpecialWatchlist.php     |   7 +-
 includes/SpecialWhatlinkshere.php |   2 +-
 includes/SquidUpdate.php          |   2 +-
 includes/Title.php                | 273 ++++++++++++++++++++++--------
 index.php                         |  19 ++-
 33 files changed, 610 insertions(+), 406 deletions(-)

diff --git a/includes/Article.php b/includes/Article.php
index 74b8b0c4ad..778d3aa640 100644
--- a/includes/Article.php
+++ b/includes/Article.php
@@ -154,8 +154,7 @@ class Article {
 							return;
 						}
 						if ( $rt->getNamespace() == Namespace::getSpecial() ) {
-							$wgOut->redirect( wfLocalUrl(
-							  $rt->getPrefixedURL() ) );
+							$wgOut->redirect( $rt->getURL() );
 							return;
 						}
 						$rid = $rt->getArticleID();
@@ -431,7 +430,7 @@ class Article {
 		# Squid purging
 		if ( $wgUseSquid ) {
 			$urlArr = Array( 
-				$wgInternalServer.wfLocalUrl( $this->mTitle->getPrefixedURL())
+				$wgInternalServer.$this->mTitle->getURL()
 			);			
 			wfPurgeSquidServers($urlArr);
 			/* this needs to be done after LinksUpdate */
@@ -547,7 +546,7 @@ class Article {
 		
 		if ( $wgUseSquid ) {
 			$urlArr = Array( 
-				$wgInternalServer.wfLocalUrl( $this->mTitle->getPrefixedURL())
+				$wgInternalServer.$this->mTitle->getURL()
 			);			
 			wfPurgeSquidServers($urlArr);
 		}
@@ -578,7 +577,7 @@ class Article {
 			$r = "redirect=no";
 		else
 			$r = "";
-		$wgOut->redirect( wfLocalUrl( $this->mTitle->getPrefixedURL(), $r ) );
+		$wgOut->redirect( $this->mTitle->getURL( $r ) );
 	}
 
 	# Add this page to my watchlist
@@ -651,7 +650,7 @@ class Article {
 		} else {
 			$log->addEntry( wfMsg( "protectedarticle", $this->mTitle->getPrefixedText() ), "" );
 		}
-		$wgOut->redirect( wfLocalUrl( $this->mTitle->getPrefixedURL() ) );
+		$wgOut->redirect( $this->mTitle->getURL() );
 	}
 
 	function unprotect()
@@ -767,9 +766,8 @@ class Article {
 		$wgOut->setRobotpolicy( "noindex,nofollow" );
 		$wgOut->addWikiText( wfMsg( "confirmdeletetext" ) );
 
-		$t = $this->mTitle->getPrefixedURL();
-
-		$formaction = wfEscapeHTML( wfLocalUrl( $t, "action=delete" . $par ) );
+		$formaction = $this->mTitle->getURL( $this->mTitle, "action=delete" . $par, true );
+		
 		$confirm = wfMsg( "confirm" );
 		$check = wfMsg( "confirmcheck" );
 		$delcom = wfMsg( "deletecomment" );
@@ -837,7 +835,7 @@ class Article {
 		# Squid purging
 		if ( $wgUseSquid ) {
 			$urlArr = Array(
-				$wgInternalServer.wfLocalUrl( $this->mTitle->getPrefixedURL())
+				$wgInternalServer.$this->mTitle->getURL()
 			);
 			wfPurgeSquidServers($urlArr);
 
@@ -847,7 +845,7 @@ class Article {
 			while ( $BL = wfFetchObject ( $res ) )
 			{
 				$tobj = Title::newFromDBkey( $BL->l_from) ; 
-				$blurlArr[] = $wgInternalServer.wfLocalUrl( $tobj->getPrefixedURL() );
+				$blurlArr[] = $wgInternalServer.$tobj->getURL();
 			}
 			wfFreeResult ( $res ) ;
 			$u = new SquidUpdate( $this->mTitle, $blurlArr );
@@ -1092,86 +1090,10 @@ class Article {
 
 	function preSaveTransform( $text )
 	{
-		$s = "";
-		while ( "" != $text ) {
-			$p = preg_split( "/<\\s*nowiki\\s*>/i", $text, 2 );
-			$s .= $this->pstPass2( $p[0] );
-
-			if ( ( count( $p ) < 2 ) || ( "" == $p[1] ) ) { $text = ""; }
-			else {
-				$q = preg_split( "/<\\/\\s*nowiki\\s*>/i", $p[1], 2 );
-				$s .= "{$q[0]}";
-				$text = $q[1];
-			}
-		}
-		return rtrim( $s );
+		global $wgParser, $wgUser;
+		return $wgParser->preSaveTransform( $text, $this->mTitle, $wgUser, ParserOptions::newFromUser( $wgUser ) );
 	}
-
-	/* private */ function pstPass2( $text )
-	{
-		global $wgUser, $wgLang, $wgLocaltimezone;
-
-		# Signatures
-		#
-		$n = $wgUser->getName();
-		$k = $wgUser->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" );
-
-/* Experimental:
-		# 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;
-	}
-
+	
 	/* Caching functions */
 
 	# checkLastModified returns true iff it has taken care of all
diff --git a/includes/Database.php b/includes/Database.php
index 6e295e3261..568f87a39f 100644
--- a/includes/Database.php
+++ b/includes/Database.php
@@ -106,8 +106,8 @@ class Database {
 				$success = false;
 			}
 		} else {
-			# Delay USE
-			$success = true;
+			# Delay USE query
+			$success = !!$this->mConn;
 		}
 		
 		if ( !$success ) {
diff --git a/includes/EditPage.php b/includes/EditPage.php
index 288cb256a5..bc59468028 100644
--- a/includes/EditPage.php
+++ b/includes/EditPage.php
@@ -129,8 +129,7 @@ class EditPage {
 				# append them and the string comparison fails
 				if ( ( "" == $wpTextbox1 ) ||
 				  ( wfMsg( "newarticletext" ) == rtrim( preg_replace("/\r/","",$wpTextbox1) ) ) ) {
-					$wgOut->redirect(  wfLocalUrl(
-					  $this->mTitle->getPrefixedURL() ) );
+					$wgOut->redirect( $this->mTitle->getURL() );
 					return;
 				}
 				$this->mArticle->insertNewArticle( $wpTextbox1, $wpSummary, $wpMinoredit, $wpWatchthis );
@@ -228,7 +227,7 @@ class EditPage {
 
 		$q = "action=submit";
 		if ( "no" == $redirect ) { $q .= "&redirect=no"; }
-		$action = wfEscapeHTML( wfLocalUrl( $this->mTitle->getPrefixedURL(), $q ) );
+		$action = $this->mTitle->getURL( $q, true );
 
 		$summary = wfMsg( "summary" );
 		$subject = wfMsg("subject");
diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php
index 5491fbaf3f..bf95d2a83e 100644
--- a/includes/GlobalFunctions.php
+++ b/includes/GlobalFunctions.php
@@ -49,12 +49,14 @@ function wfSeedRandom()
 	}
 }
 
+# Generates a URL from a URL-encoded title and a query string
+# Title::getURL() is preferred in most cases
+#
 function wfLocalUrl( $a, $q = "" )
 {
 	global $wgServer, $wgScript, $wgArticlePath;
 
 	$a = str_replace( " ", "_", $a );
-	#$a = wfUrlencode( $a ); # This stuff is _already_ URL-encoded.
 
 	if ( "" == $a ) {
 		if( "" == $q ) {
@@ -78,12 +80,14 @@ function wfLocalUrlE( $a, $q = "" )
 }
 
 function wfFullUrl( $a, $q = "" ) {
-	global $wgServer;
-	return $wgServer . wfLocalUrl( $a, $q );
+	$titleObj = Title::newFromURL( $a );
+	return $titleObj->getURL( $q, false, true );
 }
 
 function wfFullUrlE( $a, $q = "" ) {
-	return wfEscapeHTML( wfFullUrl( $a, $q ) );
+	$titleObj = Title::newFromURL( $a );
+	return $titleObj->getURL( $q, true, true );
+
 }
 
 function wfImageUrl( $img )
@@ -154,10 +158,11 @@ function wfImageArchiveUrl( $name )
 
 function wfUrlencode ( $s )
 {
-	$ulink = urlencode( $s );
-	$ulink = preg_replace( "/%3[Aa]/", ":", $ulink );
-	$ulink = preg_replace( "/%2[Ff]/", "/", $ulink );
-	return $ulink;
+	$s = urlencode( $s );
+	$s = preg_replace( "/%3[Aa]/", ":", $s );
+	$s = preg_replace( "/%2[Ff]/", "/", $s );
+
+	return $s;
 }
 
 function wfUtf8Sequence($codepoint) {
@@ -604,6 +609,7 @@ function wfViewPrevNext( $offset, $limit, $link, $query = "", $atend = false )
 	global $wgUser;
 	$prev = wfMsg( "prevn", $limit );
 	$next = wfMsg( "nextn", $limit );
+	$link = wfUrlencode( $link );
 
 	$sk = $wgUser->getSkin();
 	if ( 0 != $offset ) {
@@ -725,6 +731,7 @@ function wfHtmlEscapeFirst( $text ) {
 	return "&#$ord;$newText";
 }
 
+# Sets dest to source and returns the original value of dest
 function wfSetVar( &$dest, $source )
 {
 	$temp = $dest;
@@ -732,7 +739,8 @@ function wfSetVar( &$dest, $source )
 	return $temp;
 }
 
-function &wfSetRef( &$dest, $source )
+# Sets dest to a reference to source and returns the original dest
+function &wfSetRef( &$dest, &$source )
 {
 	$temp =& $dest;
 	$dest =& $source;
diff --git a/includes/MagicWord.php b/includes/MagicWord.php
index b5ee3e9eb9..506046981e 100644
--- a/includes/MagicWord.php
+++ b/includes/MagicWord.php
@@ -54,14 +54,14 @@ class MagicWord {
 	# Preliminary initialisation
 	/* private */ function initRegex()
 	{
-		$variableClass = "A-Za-z0-9_\-\x80-\xff";
+		$variableClass = Title::legalChars();
 		$escSyn = array_map( "preg_quote", $this->mSynonyms );
 		$this->mBaseRegex = implode( "|", $escSyn );
 		$case = $this->mCaseSensitive ? "" : "i";
 		$this->mRegex = "/{$this->mBaseRegex}/{$case}";
 		$this->mRegexStart = "/^{$this->mBaseRegex}/{$case}";
-		$this->mVariableRegex = str_replace( "\\$1", "([$variableClass]*)", $this->mRegex );
-		$this->mVariableStartToEndRegex = str_replace( "\\$1", "([$variableClass]*)", 
+		$this->mVariableRegex = str_replace( "\\$1", "([$variableClass]*?)", $this->mRegex );
+		$this->mVariableStartToEndRegex = str_replace( "\\$1", "([$variableClass]*?)", 
 			"/^{$this->mBaseRegex}$/{$case}" );
 	}
 	
diff --git a/includes/Namespace.php b/includes/Namespace.php
index b482080d39..3b5c428a11 100644
--- a/includes/Namespace.php
+++ b/includes/Namespace.php
@@ -20,6 +20,10 @@ define("NS_IMAGE_TALK", 7);
 define("NS_MEDIAWIKI", 8);
 define("NS_MEDIAWIKI_TALK", 9);
 
+# Reserved:
+define("NS_TEMPLATE", 10);
+define("NS_TEMPLATE_TALK", 11);
+
 class Namespace {
 
 	/* These functions are deprecated */
diff --git a/includes/OutputPage.php b/includes/OutputPage.php
index b11203479f..eaea95c969 100644
--- a/includes/OutputPage.php
+++ b/includes/OutputPage.php
@@ -534,8 +534,8 @@ class OutputPage {
 
 		$r = wfMsg( "returnto", $link );
 		if ( $auto ) {
-			$wgOut->addMeta( "http:Refresh", "10;url=" .
-			  wfLocalUrlE( wfUrlencode( $returnto ) ) );
+			$titleObj = Title::newFromText( $returnto );
+			$wgOut->addMeta( "http:Refresh", "10;url=" . $titleObj->getUrl( "", true, true ));
 		}
 		$wgOut->addHTML( "\n

$r\n" ); } diff --git a/includes/PageHistory.php b/includes/PageHistory.php index e3a3be70dd..bfae24ea7c 100644 --- a/includes/PageHistory.php +++ b/includes/PageHistory.php @@ -106,7 +106,7 @@ class PageHistory { global $wgTitle; $this->lastdate = $this->lastline = ""; $s = "\n

" . wfMsg( "histlegend" ) . "\n

    "; - $url = wfLocalUrl( $wgTitle->getPrefixedText(), "dummy=1"); + $url = $wgTitle->getURL("-"); $s .= "