r16967 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r16966‎ | r16967 | 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:
  • /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->getFullURL('',$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/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/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->getLocalURL('',$code)
770770 );
771771 $vcount ++;
772772 }
Index: trunk/phase3/includes/Title.php
@@ -769,14 +769,15 @@
770770 *
771771 * @param string $query an optional query string, not used
772772 * for interwiki links
 773+ * @param string $variant language variant of url (for sr, zh..)
773774 * @return string the URL
774775 * @access public
775776 */
776 - function getFullURL( $query = '' ) {
 777+ function getFullURL( $query = '', $variant = false ) {
777778 global $wgContLang, $wgServer, $wgRequest;
778779
779780 if ( '' == $this->mInterwiki ) {
780 - $url = $this->getLocalUrl( $query );
 781+ $url = $this->getLocalUrl( $query, $variant );
781782
782783 // Ugly quick hack to avoid duplicate prefixes (bug 4571 etc)
783784 // Correct fix would be to move the prepending elsewhere.
@@ -816,12 +817,21 @@
817818 * with action=render, $wgServer is prepended.
818819 * @param string $query an optional query string; if not specified,
819820 * $wgArticlePath will be used.
 821+ * @param string $variant language variant of url (for sr, zh..)
820822 * @return string the URL
821823 * @access public
822824 */
823 - function getLocalURL( $query = '' ) {
 825+ function getLocalURL( $query = '', $variant = false ) {
824826 global $wgArticlePath, $wgScript, $wgServer, $wgRequest;
 827+ global $wgVariantArticlePath, $wgContLang, $wgUser;
825828
 829+ // internal links should point to same variant as current page (only anonymous users)
 830+ if($variant == false && $wgContLang->hasVariants() && !$wgUser->isLoggedIn()){
 831+ $pref = $wgContLang->getPreferredVariant(false);
 832+ if($pref != $wgContLang->getCode())
 833+ $variant = $pref;
 834+ }
 835+
826836 if ( $this->isExternal() ) {
827837 $url = $this->getFullURL();
828838 if ( $query ) {
@@ -834,7 +844,17 @@
835845 } else {
836846 $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
837847 if ( $query == '' ) {
838 - $url = str_replace( '$1', $dbkey, $wgArticlePath );
 848+ if($variant!=false && $wgContLang->hasVariants()){
 849+ if($wgVariantArticlePath==false)
 850+ $variantArticlePath = "$wgScript?title=$1&variant=$2"; // default
 851+ else
 852+ $variantArticlePath = $wgVariantArticlePath;
 853+
 854+ $url = str_replace( '$1', $dbkey, $variantArticlePath );
 855+ $url = str_replace( '$2', urlencode( $variant ), $url );
 856+ }
 857+ else
 858+ $url = str_replace( '$1', $dbkey, $wgArticlePath );
839859 } else {
840860 global $wgActionPaths;
841861 $url = false;
@@ -896,12 +916,13 @@
897917 * internal hostname for the server from the exposed one.
898918 *
899919 * @param string $query an optional query string
 920+ * @param string $variant language variant of url (for sr, zh..)
900921 * @return string the URL
901922 * @access public
902923 */
903 - function getInternalURL( $query = '' ) {
 924+ function getInternalURL( $query = '', $variant = false ) {
904925 global $wgInternalServer;
905 - $url = $wgInternalServer . $this->getLocalURL( $query );
 926+ $url = $wgInternalServer . $this->getLocalURL( $query, $variant );
906927 wfRunHooks( 'GetInternalURL', array( &$this, &$url, $query ) );
907928 return $url;
908929 }
@@ -1698,10 +1719,23 @@
16991720 * @access public
17001721 */
17011722 function getSquidURLs() {
1702 - return array(
 1723+ global $wgContLang;
 1724+
 1725+ $urls = array(
17031726 $this->getInternalURL(),
17041727 $this->getInternalURL( 'action=history' )
17051728 );
 1729+
 1730+ // purge variant urls as well
 1731+ if($wgContLang->hasVariants()){
 1732+ $variants = $wgContLang->getVariants();
 1733+ foreach($variants as $vCode){
 1734+ if($vCode==$wgContLang->getCode()) continue; // we don't want default variant
 1735+ $urls[] = $this->getInternalURL('',$vCode);
 1736+ }
 1737+ }
 1738+
 1739+ return $urls;
17061740 }
17071741
17081742 function purgeSquid() {
Index: trunk/phase3/languages/LanguageConverter.php
@@ -96,6 +96,13 @@
9797 return $req;
9898 }
9999
 100+ // check the syntax /code/ArticleTitle
 101+ $scriptBase = basename( $_SERVER['SCRIPT_NAME'] );
 102+ if(in_array($scriptBase,$this->mVariants)){
 103+ $this->mPreferredVariant = $scriptBase;
 104+ return $this->mPreferredVariant;
 105+ }
 106+
100107 // get language variant preference from logged in users
101108 // Don't call this on stub objects because that causes infinite
102109 // 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 😂 (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