r58387 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r58386‎ | r58387 | r58388 >
Date:10:00, 31 October 2009
Author:ialex
Status:deferred
Tags:
Comment:
* Allow to use "/ContLang" suffix to link to page in the content language in addition of "/"
* Render those links as blue if the page whitout the suffix exists
Modified paths:
  • /trunk/extensions/Polyglot/Polyglot.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Polyglot/Polyglot.php
@@ -63,6 +63,7 @@
6464
6565 ///// hook it up /////////////////////////////////////////////////////
6666 $wgHooks['ArticleFromTitle'][] = 'wfPolyglotArticleFromTitle';
 67+$wgHooks['LinkBegin'][] = 'wfPolyglotLinkBegin';
6768 $wgHooks['ParserAfterTidy'][] = 'wfPolyglotParserAfterTidy';
6869 $wgHooks['SkinTemplateOutputPageBeforeExec'][] = 'wfPolyglotSkinTemplateOutputPageBeforeExec';
6970
@@ -82,7 +83,7 @@
8384
8485 function wfPolyglotArticleFromTitle( &$title, &$article ) {
8586 global $wfPolyglotExcemptNamespaces, $wfPolyglotExcemptTalkPages, $wfPolyglotFollowRedirects;
86 - global $wgLang, $wgRequest;
 87+ global $wgLang, $wgContLang, $wgRequest;
8788
8889 if ($wgRequest->getVal( 'redirect' ) == 'no') {
8990 return true;
@@ -98,17 +99,27 @@
99100
100101 $n = $title->getDBkey();
101102 $nofollow = false;
 103+ $force = false;
102104
103105 //TODO: when user-defined language links start working (see below),
104106 // we need to look at the langlinks table here.
 107+ if ( !$title->exists() && strlen( $n ) > 1 ) {
 108+ $escContLang = preg_quote( $wgContLang->getCode(), '!' );
 109+ if ( preg_match( '!/$!', $n ) ) {
 110+ $force = true;
 111+ $remove = 1;
 112+ } elseif ( preg_match( "!/{$escContLang}$!", $n ) ) {
 113+ $force = true;
 114+ $remove = strlen( $wgContLang->getCode() ) + 1;
 115+ }
 116+ }
105117
106 - if (!$title->exists() && strlen($n)>1 && preg_match('!/$!', $n)) {
107 - $t = Title::makeTitle($ns, substr($n, 0, strlen($n)-1));
 118+ if ( $force ) {
 119+ $t = Title::makeTitle( $ns, substr( $n, 0, strlen( $n ) - $remove ) );
108120 $nofollow = true;
109 - }
110 - else {
 121+ } else {
111122 $lang = $wgLang->getCode();
112 - $t = Title::makeTitle($ns, $n . '/' . $lang);
 123+ $t = Title::makeTitle( $ns, $n . '/' . $lang );
113124 }
114125
115126 if (!$t->exists()) {
@@ -158,6 +169,42 @@
159170 return true;
160171 }
161172
 173+function wfPolyglotLinkBegin( $linker, $target, &$text, &$customAttribs, &$query, &$options, &$ret ) {
 174+ global $wfPolyglotExcemptNamespaces, $wfPolyglotExcemptTalkPages, $wgContLang;
 175+
 176+ $ns = $target->getNamespace();
 177+
 178+ if ( $ns < 0
 179+ || in_array( $ns, $wfPolyglotExcemptNamespaces )
 180+ || ( $wfPolyglotExcemptTalkPages && MWNamespace::isTalk( $ns ) ) ) {
 181+ return true;
 182+ }
 183+
 184+ $dbKey = $target->getDBkey();
 185+
 186+ if ( !$target->exists() && strlen( $dbKey ) > 1 ) {
 187+ $escContLang = preg_quote( $wgContLang->getCode(), '!' );
 188+ if ( preg_match( '!/$!', $dbKey ) ) {
 189+ $remove = 1;
 190+ } elseif ( preg_match( "!/{$escContLang}$!", $dbKey ) ) {
 191+ $remove = strlen( $wgContLang->getCode() ) + 1;
 192+ } else {
 193+ return true;
 194+ }
 195+ } else {
 196+ return true;
 197+ }
 198+
 199+ $t = Title::makeTitle( $ns, substr( $dbKey, 0, strlen( $dbKey ) - $remove ) );
 200+
 201+ if ( $t->exists() ) {
 202+ $options = array_diff( $options, array( 'broken' ) );
 203+ $options []= 'known';
 204+ }
 205+
 206+ return true;
 207+}
 208+
162209 function wfPolyglotGetLanguages( $title ) {
163210 global $wgPolyglotLanguages;
164211 if (!$wgPolyglotLanguages) return NULL;

Status & tagging log