r16932 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r16931‎ | r16932 | r16933 >
Date:13:30, 11 October 2006
Author:rainman
Status:old
Tags:
Comment:

Tidy of variant code in Title.php, implemented mapping
sr->sr, sr-el->sr-el, sr-ec->sr-ec for internal links for
anonymous users
Modified paths:
  • /branches/SerbianVariants/phase3/includes/SkinTemplate.php (modified) (history)
  • /branches/SerbianVariants/phase3/includes/Title.php (modified) (history)
  • /branches/SerbianVariants/phase3/maintenance/generateSitemap.php (modified) (history)

Diff [purge]

Index: branches/SerbianVariants/phase3/maintenance/generateSitemap.php
@@ -269,7 +269,7 @@
270270 $variants = $wgContLang->getVariants();
271271 foreach($variants as $vCode){
272272 if($vCode==$wgContLang->getCode()) continue; // we don't want default variant
273 - $entry = $this->fileEntry( $title->getFullVariantURL($vCode), $date, $this->priority( $namespace ) );
 273+ $entry = $this->fileEntry( $title->getFullURL('',$vCode), $date, $this->priority( $namespace ) );
274274 $length += strlen( $entry );
275275 $this->write( $this->file, $entry );
276276 }
Index: branches/SerbianVariants/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.
@@ -812,40 +813,25 @@
813814 }
814815
815816 /**
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 = ''; // 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 - return $url;
836 - }
837 -
838 -
839 - /**
840817 * Get a URL with no fragment or server name. If this page is generated
841818 * with action=render, $wgServer is prepended.
842819 * @param string $query an optional query string; if not specified,
843820 * $wgArticlePath will be used.
 821+ * @param string $variant language variant of url (for sr, zh..)
844822 * @return string the URL
845823 * @access public
846824 */
847 - function getLocalURL( $query = '' ) {
 825+ function getLocalURL( $query = '', $variant = false ) {
848826 global $wgArticlePath, $wgScript, $wgServer, $wgRequest;
 827+ global $wgVariantArticlePath, $wgContLang, $wgUser;
849828
 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+
850836 if ( $this->isExternal() ) {
851837 $url = $this->getFullURL();
852838 if ( $query ) {
@@ -858,7 +844,17 @@
859845 } else {
860846 $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
861847 if ( $query == '' ) {
862 - $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 );
863859 } else {
864860 global $wgActionPaths;
865861 $url = false;
@@ -892,32 +888,6 @@
893889 }
894890
895891 /**
896 - * Similar to getLocalURL, except it uses $wgVariantArticlePath
897 - * and gets the URL with no fragment or server name, but in a
898 - * certain language variant (relevant only to languages with variants)
899 - * @param string $variant caption of variant
900 - * @return string the URL
901 - * @access public
902 - */
903 - function getLocalVariantURL( $variant='' ) {
904 - global $wgVariantArticlePath,$wgScript;
905 - if($variant=='') return $this->getLocalURL();
906 -
907 - if($wgVariantArticlePath==false)
908 - $vArticlePath = "$wgScript?title=$1&variant=$2"; // default
909 - else
910 - $vArticlePath = $wgVariantArticlePath;
911 -
912 - $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
913 - $url = str_replace( '$1', $dbkey, $vArticlePath );
914 - $code = urlencode( $variant );
915 - $url = str_replace( '$2', $code, $url );
916 -
917 - return $url;
918 -
919 - }
920 -
921 - /**
922892 * Get an HTML-escaped version of the URL form, suitable for
923893 * using in a link, without a server name or fragment
924894 * @param string $query an optional query string
@@ -946,34 +916,18 @@
947917 * internal hostname for the server from the exposed one.
948918 *
949919 * @param string $query an optional query string
 920+ * @param string $variant language variant of url (for sr, zh..)
950921 * @return string the URL
951922 * @access public
952923 */
953 - function getInternalURL( $query = '' ) {
 924+ function getInternalURL( $query = '', $variant = false ) {
954925 global $wgInternalServer;
955 - $url = $wgInternalServer . $this->getLocalURL( $query );
 926+ $url = $wgInternalServer . $this->getLocalURL( $query, $variant );
956927 wfRunHooks( 'GetInternalURL', array( &$this, &$url, $query ) );
957928 return $url;
958929 }
959930
960931 /**
961 - * Get the URL form for an internal variant link.
962 - * - Used in various Squid-related code, in case we have a different
963 - * internal hostname for the server from the exposed one.
964 - *
965 - * @param string $variant an optional query string
966 - * @return string the URL
967 - * @access public
968 - */
969 - function getInternalVariantURL( $variant = '' ) {
970 - global $wgInternalServer;
971 - $url = $wgInternalServer . $this->getLocalVariantURL( $variant );
972 - // not sure: wfRunHooks( 'GetInternalURL', array( &$this, &$url, $query ) );
973 - return $url;
974 - }
975 -
976 -
977 - /**
978932 * Get the edit URL for this Title
979933 * @return string the URL, or a null string if this is an
980934 * interwiki link
@@ -1765,19 +1719,19 @@
17661720 * @access public
17671721 */
17681722 function getSquidURLs() {
1769 - global $wgContLang,$wgVariantArticlePath;
 1723+ global $wgContLang;
17701724
17711725 $urls = array(
17721726 $this->getInternalURL(),
17731727 $this->getInternalURL( 'action=history' )
17741728 );
17751729
1776 - // purge variant url's as well (when using aliases)
1777 - if($wgContLang->hasVariants() && $wgVariantArticlePath!=false){
 1730+ // purge variant urls as well
 1731+ if($wgContLang->hasVariants()){
17781732 $variants = $wgContLang->getVariants();
17791733 foreach($variants as $vCode){
17801734 if($vCode==$wgContLang->getCode()) continue; // we don't want default variant
1781 - $urls[] = $this->getInternalVariantURL($vCode);
 1735+ $urls[] = $this->getInternalURL('',$vCode);
17821736 }
17831737 }
17841738
Index: branches/SerbianVariants/phase3/includes/SkinTemplate.php
@@ -765,7 +765,7 @@
766766 $content_actions['varlang-' . $vcount] = array(
767767 'class' => $selected,
768768 'text' => $varname,
769 - 'href' => $this->mTitle->getLocalVariantURL($code)
 769+ 'href' => $this->mTitle->getLocalURL('',$code)
770770 );
771771 $vcount ++;
772772 }