Index: trunk/phase3/docs/hooks.txt |
— | — | @@ -914,7 +914,6 @@ |
915 | 915 | $title: Title object of page |
916 | 916 | $url: string value as output (out parameter, can modify) |
917 | 917 | $query: query options passed to Title::getCanonicalURL() |
918 | | -$variant: variant passed to Title::getCanonicalURL() |
919 | 918 | |
920 | 919 | 'GetDefaultSortkey': Override the default sortkey for a page. |
921 | 920 | $title: Title object that we need to get a sortkey for |
— | — | @@ -924,13 +923,11 @@ |
925 | 924 | $title: Title object of page |
926 | 925 | $url: string value as output (out parameter, can modify) |
927 | 926 | $query: query options passed to Title::getFullURL() |
928 | | -$variant: variant passed to Title::getFullURL() |
929 | 927 | |
930 | 928 | 'GetInternalURL': modify fully-qualified URLs used for squid cache purging |
931 | 929 | $title: Title object of page |
932 | 930 | $url: string value as output (out parameter, can modify) |
933 | 931 | $query: query options passed to Title::getInternalURL() |
934 | | -$variant: variant passed to Title::getFullURL() |
935 | 932 | |
936 | 933 | 'GetIP': modify the ip of the current user (called only once) |
937 | 934 | &$ip: string holding the ip as determined so far |
— | — | @@ -949,13 +946,11 @@ |
950 | 947 | $title: Title object of page |
951 | 948 | &$url: string value as output (out parameter, can modify) |
952 | 949 | $query: query options passed to Title::getLocalURL() |
953 | | -$variant: variant passed to Title::getLocalURL() |
954 | 950 | |
955 | 951 | 'GetLocalURL::Internal': modify local URLs to internal pages. |
956 | 952 | $title: Title object of page |
957 | 953 | &$url: string value as output (out parameter, can modify) |
958 | 954 | $query: query options passed to Title::getLocalURL() |
959 | | -$variant: variant passed to Title::getLocalURL() |
960 | 955 | |
961 | 956 | 'GetLocalURL::Article': modify local URLs specifically pointing to article paths |
962 | 957 | without any fancy queries or variants. |
Index: trunk/phase3/includes/OutputPage.php |
— | — | @@ -3009,7 +3009,7 @@ |
3010 | 3010 | $tags[] = Html::element( 'link', array( |
3011 | 3011 | 'rel' => 'alternate', |
3012 | 3012 | 'hreflang' => $_v, |
3013 | | - 'href' => $this->getTitle()->getLocalURL( '', $_v ) ) |
| 3013 | + 'href' => $this->getTitle()->getLocalURL( array( 'variant' => $_v ) ) ) |
3014 | 3014 | ); |
3015 | 3015 | } |
3016 | 3016 | } else { |
Index: trunk/phase3/includes/Title.php |
— | — | @@ -1230,6 +1230,31 @@ |
1231 | 1231 | } |
1232 | 1232 | |
1233 | 1233 | /** |
| 1234 | + * Helper to fix up the get{Local,Full,Link,Canonical}URL args |
| 1235 | + */ |
| 1236 | + private static function fixUrlQueryArgs( $query, $query2 ) { |
| 1237 | + if ( is_array( $query ) ) { |
| 1238 | + $query = wfArrayToCGI( $query ); |
| 1239 | + } |
| 1240 | + if ( $query2 ) { |
| 1241 | + if ( is_string( $query2 ) ) { |
| 1242 | + // $query2 is a string, we will consider this to be |
| 1243 | + // a deprecated $variant argument and add it to the query |
| 1244 | + $query2 = wfArrayToCGI( array( 'variant' => $query2 ) ); |
| 1245 | + } else { |
| 1246 | + $query2 = wfArrayToCGI( $query2 ); |
| 1247 | + } |
| 1248 | + // If we have $query content add a & to it first |
| 1249 | + if ( $query ) { |
| 1250 | + $query .= '&'; |
| 1251 | + } |
| 1252 | + // Now append the queries together |
| 1253 | + $query .= $query2; |
| 1254 | + } |
| 1255 | + return $query; |
| 1256 | + } |
| 1257 | + |
| 1258 | + /** |
1234 | 1259 | * Get a real URL referring to this title, with interwiki link and |
1235 | 1260 | * fragment |
1236 | 1261 | * |
— | — | @@ -1239,9 +1264,11 @@ |
1240 | 1265 | * @param $variant String language variant of url (for sr, zh..) |
1241 | 1266 | * @return String the URL |
1242 | 1267 | */ |
1243 | | - public function getFullURL( $query = '', $variant = false ) { |
| 1268 | + public function getFullURL( $query = '', $query2 = false ) { |
| 1269 | + $query = self::fixUrlQueryArgs( $query, $query2 ); |
| 1270 | + |
1244 | 1271 | # Hand off all the decisions on urls to getLocalURL |
1245 | | - $url = $this->getLocalURL( $query, $variant ); |
| 1272 | + $url = $this->getLocalURL( $query ); |
1246 | 1273 | |
1247 | 1274 | # Expand the url to make it a full url. Note that getLocalURL has the |
1248 | 1275 | # potential to output full urls for a variety of reasons, so we use |
— | — | @@ -1251,7 +1278,7 @@ |
1252 | 1279 | # Finally, add the fragment. |
1253 | 1280 | $url .= $this->getFragmentForURL(); |
1254 | 1281 | |
1255 | | - wfRunHooks( 'GetFullURL', array( &$this, &$url, $query, $variant ) ); |
| 1282 | + wfRunHooks( 'GetFullURL', array( &$this, &$url, $query ) ); |
1256 | 1283 | return $url; |
1257 | 1284 | } |
1258 | 1285 | |
— | — | @@ -1266,13 +1293,10 @@ |
1267 | 1294 | * @param $variant String language variant of url (for sr, zh..) |
1268 | 1295 | * @return String the URL |
1269 | 1296 | */ |
1270 | | - public function getLocalURL( $query = '', $variant = false ) { |
| 1297 | + public function getLocalURL( $query = '', $query2 = false ) { |
1271 | 1298 | global $wgArticlePath, $wgScript, $wgServer, $wgRequest; |
1272 | | - global $wgVariantArticlePath; |
1273 | 1299 | |
1274 | | - if ( is_array( $query ) ) { |
1275 | | - $query = wfArrayToCGI( $query ); |
1276 | | - } |
| 1300 | + $query = self::fixUrlQueryArgs( $query, $query2 ); |
1277 | 1301 | |
1278 | 1302 | $interwiki = Interwiki::fetch( $this->mInterwiki ); |
1279 | 1303 | if ( $interwiki ) { |
— | — | @@ -1287,22 +1311,13 @@ |
1288 | 1312 | } else { |
1289 | 1313 | $dbkey = wfUrlencode( $this->getPrefixedDBkey() ); |
1290 | 1314 | if ( $query == '' ) { |
1291 | | - if ( $variant != false && $this->getPageLanguage()->hasVariants() ) { |
1292 | | - if ( !$wgVariantArticlePath ) { |
1293 | | - $variantArticlePath = "$wgScript?title=$1&variant=$2"; // default |
1294 | | - } else { |
1295 | | - $variantArticlePath = $wgVariantArticlePath; |
1296 | | - } |
1297 | | - $url = str_replace( '$2', urlencode( $variant ), $variantArticlePath ); |
1298 | | - $url = str_replace( '$1', $dbkey, $url ); |
1299 | | - } else { |
1300 | | - $url = str_replace( '$1', $dbkey, $wgArticlePath ); |
1301 | | - wfRunHooks( 'GetLocalURL::Article', array( &$this, &$url ) ); |
1302 | | - } |
| 1315 | + $url = str_replace( '$1', $dbkey, $wgArticlePath ); |
| 1316 | + wfRunHooks( 'GetLocalURL::Article', array( &$this, &$url ) ); |
1303 | 1317 | } else { |
1304 | | - global $wgActionPaths; |
| 1318 | + global $wgVariantArticlePath, $wgActionPaths; |
1305 | 1319 | $url = false; |
1306 | 1320 | $matches = array(); |
| 1321 | + |
1307 | 1322 | if ( !empty( $wgActionPaths ) && |
1308 | 1323 | preg_match( '/^(.*&|)action=([^&]*)(&(.*)|)$/', $query, $matches ) ) |
1309 | 1324 | { |
— | — | @@ -1319,6 +1334,20 @@ |
1320 | 1335 | } |
1321 | 1336 | } |
1322 | 1337 | |
| 1338 | + if ( $url === false && |
| 1339 | + $wgVariantArticlePath && |
| 1340 | + $this->getPageLanguage()->hasVariants() && |
| 1341 | + preg_match( '/^variant=([^&]*)$/', $query, $matches ) ) |
| 1342 | + { |
| 1343 | + $variant = urldecode( $matches[1] ); |
| 1344 | + if ( $this->getPageLanguage()->hasVariant( $variant ) ) { |
| 1345 | + // Only do the variant replacement if the given variant is a valid |
| 1346 | + // variant for the page's language. |
| 1347 | + $url = str_replace( '$2', urlencode( $variant ), $wgVariantArticlePath ); |
| 1348 | + $url = str_replace( '$1', $dbkey, $url ); |
| 1349 | + } |
| 1350 | + } |
| 1351 | + |
1323 | 1352 | if ( $url === false ) { |
1324 | 1353 | if ( $query == '-' ) { |
1325 | 1354 | $query = ''; |
— | — | @@ -1327,7 +1356,7 @@ |
1328 | 1357 | } |
1329 | 1358 | } |
1330 | 1359 | |
1331 | | - wfRunHooks( 'GetLocalURL::Internal', array( &$this, &$url, $query, $variant ) ); |
| 1360 | + wfRunHooks( 'GetLocalURL::Internal', array( &$this, &$url, $query ) ); |
1332 | 1361 | |
1333 | 1362 | // @todo FIXME: This causes breakage in various places when we |
1334 | 1363 | // actually expected a local URL and end up with dupe prefixes. |
— | — | @@ -1335,7 +1364,7 @@ |
1336 | 1365 | $url = $wgServer . $url; |
1337 | 1366 | } |
1338 | 1367 | } |
1339 | | - wfRunHooks( 'GetLocalURL', array( &$this, &$url, $query, $variant ) ); |
| 1368 | + wfRunHooks( 'GetLocalURL', array( &$this, &$url, $query ) ); |
1340 | 1369 | return $url; |
1341 | 1370 | } |
1342 | 1371 | |
— | — | @@ -1356,14 +1385,14 @@ |
1357 | 1386 | * for anonymous users). |
1358 | 1387 | * @return String the URL |
1359 | 1388 | */ |
1360 | | - public function getLinkURL( $query = array(), $variant = false ) { |
| 1389 | + public function getLinkURL( $query = '', $query2 = false ) { |
1361 | 1390 | wfProfileIn( __METHOD__ ); |
1362 | 1391 | if ( $this->isExternal() ) { |
1363 | | - $ret = $this->getFullURL( $query ); |
| 1392 | + $ret = $this->getFullURL( $query, $query2 ); |
1364 | 1393 | } elseif ( $this->getPrefixedText() === '' && $this->getFragment() !== '' ) { |
1365 | 1394 | $ret = $this->getFragmentForURL(); |
1366 | 1395 | } else { |
1367 | | - $ret = $this->getLocalURL( $query, $variant ) . $this->getFragmentForURL(); |
| 1396 | + $ret = $this->getLocalURL( $query, $query2 ) . $this->getFragmentForURL(); |
1368 | 1397 | } |
1369 | 1398 | wfProfileOut( __METHOD__ ); |
1370 | 1399 | return $ret; |
— | — | @@ -1376,8 +1405,8 @@ |
1377 | 1406 | * @param $query String an optional query string |
1378 | 1407 | * @return String the URL |
1379 | 1408 | */ |
1380 | | - public function escapeLocalURL( $query = '' ) { |
1381 | | - return htmlspecialchars( $this->getLocalURL( $query ) ); |
| 1409 | + public function escapeLocalURL( $query = '', $query2 = false ) { |
| 1410 | + return htmlspecialchars( $this->getLocalURL( $query, $query2 ) ); |
1382 | 1411 | } |
1383 | 1412 | |
1384 | 1413 | /** |
— | — | @@ -1387,8 +1416,8 @@ |
1388 | 1417 | * @param $query String an optional query string |
1389 | 1418 | * @return String the URL |
1390 | 1419 | */ |
1391 | | - public function escapeFullURL( $query = '' ) { |
1392 | | - return htmlspecialchars( $this->getFullURL( $query ) ); |
| 1420 | + public function escapeFullURL( $query = '', $query2 = false ) { |
| 1421 | + return htmlspecialchars( $this->getFullURL( $query, $query2 ) ); |
1393 | 1422 | } |
1394 | 1423 | |
1395 | 1424 | /** |
— | — | @@ -1404,11 +1433,12 @@ |
1405 | 1434 | * @param $variant String language variant of url (for sr, zh..) |
1406 | 1435 | * @return String the URL |
1407 | 1436 | */ |
1408 | | - public function getInternalURL( $query = '', $variant = false ) { |
| 1437 | + public function getInternalURL( $query = '', $query2 = false ) { |
1409 | 1438 | global $wgInternalServer, $wgServer; |
| 1439 | + $query = self::fixUrlQueryArgs( $query, $query2 ); |
1410 | 1440 | $server = $wgInternalServer !== false ? $wgInternalServer : $wgServer; |
1411 | | - $url = wfExpandUrl( $server . $this->getLocalURL( $query, $variant ), PROTO_HTTP ); |
1412 | | - wfRunHooks( 'GetInternalURL', array( &$this, &$url, $query, $variant ) ); |
| 1441 | + $url = wfExpandUrl( $server . $this->getLocalURL( $query ), PROTO_HTTP ); |
| 1442 | + wfRunHooks( 'GetInternalURL', array( &$this, &$url, $query ) ); |
1413 | 1443 | return $url; |
1414 | 1444 | } |
1415 | 1445 | |
— | — | @@ -1424,9 +1454,10 @@ |
1425 | 1455 | * @return string The URL |
1426 | 1456 | * @since 1.18 |
1427 | 1457 | */ |
1428 | | - public function getCanonicalURL( $query = '', $variant = false ) { |
| 1458 | + public function getCanonicalURL( $query = '', $query2 = false ) { |
| 1459 | + $query = self::fixUrlQueryArgs( $query, $query2 ); |
1429 | 1460 | $url = wfExpandUrl( $this->getLocalURL( $query, $variant ) . $this->getFragmentForURL(), PROTO_CANONICAL ); |
1430 | | - wfRunHooks( 'GetCanonicalURL', array( &$this, &$url, $query, $variant ) ); |
| 1461 | + wfRunHooks( 'GetCanonicalURL', array( &$this, &$url, $query ) ); |
1431 | 1462 | return $url; |
1432 | 1463 | } |
1433 | 1464 | |
— | — | @@ -1434,8 +1465,9 @@ |
1435 | 1466 | * HTML-escaped version of getCanonicalURL() |
1436 | 1467 | * @since 1.18 |
1437 | 1468 | */ |
1438 | | - public function escapeCanonicalURL( $query = '', $variant = false ) { |
1439 | | - return htmlspecialchars( $this->getCanonicalURL( $query, $variant ) ); |
| 1469 | + public function escapeCanonicalURL( $query = '', $query2 = false ) { |
| 1470 | + wfDeprecated( __METHOD__, '1.19' ); |
| 1471 | + return htmlspecialchars( $this->getCanonicalURL( $query, $query2 ) ); |
1440 | 1472 | } |
1441 | 1473 | |
1442 | 1474 | /** |
Index: trunk/phase3/includes/SkinTemplate.php |
— | — | @@ -1009,7 +1009,7 @@ |
1010 | 1010 | $content_navigation['variants'][] = array( |
1011 | 1011 | 'class' => ( $code == $preferred ) ? 'selected' : false, |
1012 | 1012 | 'text' => $varname, |
1013 | | - 'href' => $title->getLocalURL( '', $code ) |
| 1013 | + 'href' => $title->getLocalURL( array( 'variant' => $code ) ) |
1014 | 1014 | ); |
1015 | 1015 | } |
1016 | 1016 | } |
Index: trunk/phase3/languages/LanguageConverter.php |
— | — | @@ -189,7 +189,7 @@ |
190 | 190 | * @param $variant String: the variant to validate |
191 | 191 | * @return Mixed: returns the variant if it is valid, null otherwise |
192 | 192 | */ |
193 | | - protected function validateVariant( $variant = null ) { |
| 193 | + public function validateVariant( $variant = null ) { |
194 | 194 | if ( $variant !== null && in_array( $variant, $this->mVariants ) ) { |
195 | 195 | return $variant; |
196 | 196 | } |
Index: trunk/phase3/languages/Language.php |
— | — | @@ -3260,6 +3260,14 @@ |
3261 | 3261 | } |
3262 | 3262 | |
3263 | 3263 | /** |
| 3264 | + * Return the LanguageConverter used in the Language |
| 3265 | + * @return LanguageConverter |
| 3266 | + */ |
| 3267 | + function getConverter() { |
| 3268 | + return $this->mConverter; |
| 3269 | + } |
| 3270 | + |
| 3271 | + /** |
3264 | 3272 | * convert text to all supported variants |
3265 | 3273 | * |
3266 | 3274 | * @param $text string |
— | — | @@ -3300,6 +3308,14 @@ |
3301 | 3309 | } |
3302 | 3310 | |
3303 | 3311 | /** |
| 3312 | + * Check if the language has the specific variant |
| 3313 | + * @return bool |
| 3314 | + */ |
| 3315 | + function hasVariant( $variant ) { |
| 3316 | + return (bool)$this->mConverter->validateVariant( $variant ); |
| 3317 | + } |
| 3318 | + |
| 3319 | + /** |
3304 | 3320 | * Put custom tags (e.g. -{ }-) around math to prevent conversion |
3305 | 3321 | * |
3306 | 3322 | * @param $text string |