MediaWiki r16967 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r16966‎ | r16967 (on ViewVC)‎ | r16968 >
Date:10:34, 12 October 2006
Author:rainman
Status:old (Comments)
Tags:
Comment:

Commiting diff -r 16826:16966 of serbianvariants.
Enable engine for aliases like /sr-ec/Article_title
Put variants into google sitemap.
Modified paths:

Diff [purge]

Index: trunk/phase3/maintenance/generateSitemap.php
===================================================================
--- trunk/phase3/maintenance/generateSitemap.php	(revision 16966)
+++ trunk/phase3/maintenance/generateSitemap.php	(revision 16967)
@@ -264,6 +264,16 @@
 				$entry = $this->fileEntry( $title->getFullURL(), $date, $this->priority( $namespace ) );
 				$length += strlen( $entry );
 				$this->write( $this->file, $entry );
+				// generate pages for language variants
+				if($wgContLang->hasVariants()){
+					$variants = $wgContLang->getVariants();
+					foreach($variants as $vCode){
+						if($vCode==$wgContLang->getCode()) continue; // we don't want default variant
+						$entry = $this->fileEntry( $title->getFullURL('',$vCode), $date, $this->priority( $namespace ) );
+						$length += strlen( $entry );
+						$this->write( $this->file, $entry );
+					}
+				}
 			}
 			if ( $this->file ) {
 				$this->write( $this->file, $this->closeFile() );
Index: trunk/phase3/includes/Title.php
===================================================================
--- trunk/phase3/includes/Title.php	(revision 16966)
+++ trunk/phase3/includes/Title.php	(revision 16967)
@@ -769,14 +769,15 @@
 	 *
 	 * @param string $query an optional query string, not used
 	 * 	for interwiki links
+	 * @param string $variant language variant of url (for sr, zh..)
 	 * @return string the URL
 	 * @access public
 	 */
-	function getFullURL( $query = '' ) {
+	function getFullURL( $query = '', $variant = false ) {
 		global $wgContLang, $wgServer, $wgRequest;
 
 		if ( '' == $this->mInterwiki ) {
-			$url = $this->getLocalUrl( $query );
+			$url = $this->getLocalUrl( $query, $variant );
 
 			// Ugly quick hack to avoid duplicate prefixes (bug 4571 etc)
 			// Correct fix would be to move the prepending elsewhere.
@@ -816,12 +817,21 @@
 	 * with action=render, $wgServer is prepended.
 	 * @param string $query an optional query string; if not specified,
 	 * 	$wgArticlePath will be used.
+	 * @param string $variant language variant of url (for sr, zh..)
 	 * @return string the URL
 	 * @access public
 	 */
-	function getLocalURL( $query = '' ) {
+	function getLocalURL( $query = '', $variant = false ) {
 		global $wgArticlePath, $wgScript, $wgServer, $wgRequest;
+		global $wgVariantArticlePath, $wgContLang, $wgUser;
 
+		// internal links should point to same variant as current page (only anonymous users)
+		if($variant == false && $wgContLang->hasVariants() && !$wgUser->isLoggedIn()){
+			$pref = $wgContLang->getPreferredVariant(false);
+			if($pref != $wgContLang->getCode())
+				$variant = $pref;
+		}
+
 		if ( $this->isExternal() ) {
 			$url = $this->getFullURL();
 			if ( $query ) {
@@ -834,7 +844,17 @@
 		} else {
 			$dbkey = wfUrlencode( $this->getPrefixedDBkey() );
 			if ( $query == '' ) {
-				$url = str_replace( '$1', $dbkey, $wgArticlePath );
+				if($variant!=false && $wgContLang->hasVariants()){
+					if($wgVariantArticlePath==false)
+						$variantArticlePath =  "$wgScript?title=$1&variant=$2"; // default
+					else 
+						$variantArticlePath = $wgVariantArticlePath;
+					
+					$url = str_replace( '$1', $dbkey, $variantArticlePath );
+					$url = str_replace( '$2', urlencode( $variant ), $url );					
+				}
+				else 
+					$url = str_replace( '$1', $dbkey, $wgArticlePath );
 			} else {
 				global $wgActionPaths;
 				$url = false;
@@ -896,12 +916,13 @@
 	 * internal hostname for the server from the exposed one.
 	 *
 	 * @param string $query an optional query string
+	 * @param string $variant language variant of url (for sr, zh..)
 	 * @return string the URL
 	 * @access public
 	 */
-	function getInternalURL( $query = '' ) {
+	function getInternalURL( $query = '', $variant = false ) {
 		global $wgInternalServer;
-		$url = $wgInternalServer . $this->getLocalURL( $query );
+		$url = $wgInternalServer . $this->getLocalURL( $query, $variant );
 		wfRunHooks( 'GetInternalURL', array( &$this, &$url, $query ) );
 		return $url;
 	}
@@ -1698,10 +1719,23 @@
 	 * @access public
 	 */
 	function getSquidURLs() {
-		return array(
+		global $wgContLang;
+
+		$urls = array(
 			$this->getInternalURL(),
 			$this->getInternalURL( 'action=history' )
 		);
+
+		// purge variant urls as well
+		if($wgContLang->hasVariants()){
+			$variants = $wgContLang->getVariants();
+			foreach($variants as $vCode){
+				if($vCode==$wgContLang->getCode()) continue; // we don't want default variant
+				$urls[] = $this->getInternalURL('',$vCode);
+			}
+		}
+
+		return $urls;
 	}
 
 	function purgeSquid() {
Index: trunk/phase3/includes/SkinTemplate.php
===================================================================
--- trunk/phase3/includes/SkinTemplate.php	(revision 16966)
+++ trunk/phase3/includes/SkinTemplate.php	(revision 16967)
@@ -765,7 +765,7 @@
 				$content_actions['varlang-' . $vcount] = array(
 						'class' => $selected,
 						'text' => $varname,
-						'href' => $this->mTitle->getLocalUrl( $actstr . 'variant=' . urlencode( $code ) )
+						'href' => $this->mTitle->getLocalURL('',$code)
 					);
 				$vcount ++;
 			}
Index: trunk/phase3/includes/DefaultSettings.php
===================================================================
--- trunk/phase3/includes/DefaultSettings.php	(revision 16966)
+++ trunk/phase3/includes/DefaultSettings.php	(revision 16967)
@@ -124,6 +124,7 @@
 $wgStyleDirectory = "{$IP}/skins";
 $wgStyleSheetPath = &$wgStylePath;
 $wgArticlePath      = "{$wgScript}?title=$1";
+$wgVariantArticlePath = false;
 $wgUploadPath       = "{$wgScriptPath}/images";
 $wgUploadDirectory	= "{$IP}/images";
 $wgHashedUploadDirectory	= true;
Index: trunk/phase3/languages/LanguageConverter.php
===================================================================
--- trunk/phase3/languages/LanguageConverter.php	(revision 16966)
+++ trunk/phase3/languages/LanguageConverter.php	(revision 16967)
@@ -96,6 +96,13 @@
 			return $req;
 		}
 
+		// check the syntax /code/ArticleTitle
+		$scriptBase = basename( $_SERVER['SCRIPT_NAME'] );
+		if(in_array($scriptBase,$this->mVariants)){
+			$this->mPreferredVariant = $scriptBase;
+			return $this->mPreferredVariant;
+		}
+
 		// get language variant preference from logged in users
 		// Don't call this on stub objects because that causes infinite 
 		// recursion during initialisation

Comments

#Comment by Liangent (Talk | contribs)   13:01, 18 June 2010

The line "if($vCode==$wgContLang->getCode()) continue; // we don't want default variant" doesn't work correctly on zhwiki (and other wikis with $wgLanguageCode = 'zh'), where the language code 'zh' is also used as a variant name (which means 'no conversion'; technically it's a variant). Omitting zh variant causes /zh/Page_Name urls (when $wgArticlePath = '/$2/$1') not to be purged.

#Comment by Liangent (Talk | contribs)   13:44, 18 June 2010
#Comment by Reedy (Talk | contribs)   19:15, 20 June 2010

[https://bugzilla.wikimedia.org/show_bug.cgi?id=24027 bug 24027] will link to bugzilla :)

#Comment by ^demon (Talk | contribs)   12:34, 10 August 2010

Reported as fixed in r69085. Can this fixme be resolved now?

#Comment by Catrope (Talk | contribs)   22:24, 4 December 2010

Setting to old per this comment.

Status & tagging log

  • 22:24, 4 December 2010 Reedy (Talk | contribs) changed the status of r16967 [removed: resolved added: old]
  • 22:24, 4 December 2010 Reedy (Talk | contribs) changed the status of r16967 [removed: old added: resolved]
  • 22:24, 4 December 2010 Catrope (Talk | contribs) changed the status of r16967 [removed: fixme added: old]
  • 13:01, 18 June 2010 Liangent (Talk | contribs) changed the status of r16967 [removed: new added: fixme]
Personal tools
Namespaces
Variants
Views
Actions
Site
Support
Download
Development
Communication
Toolbox