r16860 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r16859‎ | r16860 | r16861 >
Date:13:37, 8 October 2006
Author:rainman
Status:old
Tags:
Comment:

Merged r16826-16858 of branches/SerbianVariants.
Enabled aliased variants e.g. ?title=Article&variant=sr-ec => /sr-ec/Article
and added variants to google sitemap.
To enable aliases put: $wgVariantArticlePath = "$wgScriptPath/$2/$1";
to LocalSettings.php, and make aliases from /$variants/ to index.php
Modified paths:
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/SkinTemplate.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/languages/LanguageConverter.php (modified) (history)
  • /trunk/phase3/maintenance/generateSitemap.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/generateSitemap.php
@@ -264,6 +264,16 @@
265265 $entry = $this->fileEntry( $title->getFullURL(), $date, $this->priority( $namespace ) );
266266 $length += strlen( $entry );
267267 $this->write( $this->file, $entry );
 268+ // generate pages for language variants
 269+ if($wgContLang->hasVariants()){
 270+ $variants = $wgContLang->getVariants();
 271+ foreach($variants as $vCode){
 272+ if($vCode==$wgContLang->getCode()) continue; // we don't want default variant
 273+ $entry = $this->fileEntry( $title->getFullVariantURL($vCode), $date, $this->priority( $namespace ) );
 274+ $length += strlen( $entry );
 275+ $this->write( $this->file, $entry );
 276+ }
 277+ }
268278 }
269279 if ( $this->file ) {
270280 $this->write( $this->file, $this->closeFile() );
Index: trunk/phase3/includes/Title.php
@@ -812,6 +812,35 @@
813813 }
814814
815815 /**
 816+ * Get a real URL referring to this title in some of the variant
 817+ *
 818+ * @param string $variant variant name
 819+ * @return string the URL
 820+ * @access public
 821+ */
 822+ function getFullVariantURL( $variant = '' ) {
 823+ global $wgServer, $wgRequest;
 824+
 825+ $url=''; // this function should not be called for interwiki
 826+
 827+ if ( '' == $this->mInterwiki ) {
 828+ $url = $this->getLocalVariantURL( $variant );
 829+
 830+ if ($wgRequest->getVal('action') != 'render') {
 831+ $url = $wgServer . $url;
 832+ }
 833+ }
 834+
 835+ # Finally, add the fragment.
 836+ if ( '' != $this->mFragment ) {
 837+ $url .= '#' . $this->mFragment;
 838+ }
 839+
 840+ return $url;
 841+ }
 842+
 843+
 844+ /**
816845 * Get a URL with no fragment or server name. If this page is generated
817846 * with action=render, $wgServer is prepended.
818847 * @param string $query an optional query string; if not specified,
@@ -868,6 +897,30 @@
869898 }
870899
871900 /**
 901+ * Similar to getLocalURL, except it uses $wgVariantArticlePath
 902+ * and gets the URL with no fragment or server name, but in a
 903+ * certain language variant (relevant only to languages with variants)
 904+ * @param string $variant caption of variant
 905+ * @return string the URL
 906+ * @access public
 907+ */
 908+ function getLocalVariantURL( $variant='' ) {
 909+ global $wgVariantArticlePath,$wgScript;
 910+ if($variant=='') return $this->getLocalURL();
 911+
 912+ if($wgVariantArticlePath==false)
 913+ $wgVariantArticlePath = "$wgScript?title=$1&variant=$2";
 914+
 915+ $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
 916+ $url = str_replace( '$1', $dbkey, $wgVariantArticlePath );
 917+ $code = urlencode( $variant );
 918+ $url = str_replace( '$2', $code, $url );
 919+
 920+ return $url;
 921+
 922+ }
 923+
 924+ /**
872925 * Get an HTML-escaped version of the URL form, suitable for
873926 * using in a link, without a server name or fragment
874927 * @param string $query an optional query string
Index: trunk/phase3/includes/SkinTemplate.php
@@ -765,7 +765,7 @@
766766 $content_actions['varlang-' . $vcount] = array(
767767 'class' => $selected,
768768 'text' => $varname,
769 - 'href' => $this->mTitle->getLocalUrl( $actstr . 'variant=' . urlencode( $code ) )
 769+ 'href' => $this->mTitle->getLocalVariantURL($code)
770770 );
771771 $vcount ++;
772772 }
Index: trunk/phase3/includes/DefaultSettings.php
@@ -124,6 +124,7 @@
125125 $wgStyleDirectory = "{$IP}/skins";
126126 $wgStyleSheetPath = &$wgStylePath;
127127 $wgArticlePath = "{$wgScript}?title=$1";
 128+$wgVariantArticlePath = false;
128129 $wgUploadPath = "{$wgScriptPath}/images";
129130 $wgUploadDirectory = "{$IP}/images";
130131 $wgHashedUploadDirectory = true;
Index: trunk/phase3/languages/LanguageConverter.php
@@ -96,6 +96,14 @@
9797 return $req;
9898 }
9999
 100+ // check the syntax /code/ArticleTitle
 101+ $script = $_SERVER['SCRIPT_NAME'];
 102+ $variants = implode('|',$this->mVariants);
 103+ if(preg_match("/($variants)$/",$script,$matches)){
 104+ $this->mPreferredVariant = $matches[1];
 105+ return $this->mPreferredVariant;
 106+ }
 107+
100108 // get language variant preference from logged in users
101109 // Don't call this on stub objects because that causes infinite
102110 // recursion during initialisation

Follow-up revisions

RevisionCommit summaryAuthorDate
r16878Revert r16860...brion00:28, 9 October 2006

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r16826Sync of Serbian Variants branch to r16825 of trunk.rainman02:44, 7 October 2006