r107773 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107772‎ | r107773 | r107774 >
Date:14:01, 1 January 2012
Author:ialex
Status:reverted (Comments)
Tags:
Comment:
* (bug 32686) Tooltip on links to non-existing pages are now always in user's language

Fixed this by "abusing" of the $options parameter of Linker::link() to pass the Language object (as we did for wfMsgExt()), has the two following advantages:
* The tooltip is displayed in the requested language instead of depending on $wgLang
* The usage of the Language object is detected in the ParserOptions, thus the parser cache key will not have "*" for the language
Modified paths:
  • /trunk/phase3/RELEASE-NOTES-1.19 (modified) (history)
  • /trunk/phase3/includes/Linker.php (modified) (history)
  • /trunk/phase3/includes/parser/LinkHolderArray.php (modified) (history)

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES-1.19
@@ -206,7 +206,8 @@
207207 {{NAMESPACE}} relative to correct title.
208208 * (bug 30485 and bug 33434) Style rules for wikitable are now more specific and
209209 prevent inheritance to nested tables which caused various issues
210 -
 210+* (bug 32686) Tooltip on links to non-existing pages are now always in user's
 211+ language
211212
212213 === API changes in 1.19 ===
213214 * (bug 19838) siprop=interwikimap can now use the interwiki cache.
Index: trunk/phase3/includes/parser/LinkHolderArray.php
@@ -363,7 +363,8 @@
364364 if ( $colours[$pdbk] == 'new' ) {
365365 $linkCache->addBadLinkObj( $title );
366366 $output->addLink( $title, 0 );
367 - $type = array( 'broken' );
 367+ $type = array( 'broken',
 368+ 'language' => $this->parent->getOptions()->getUserLangObj() );
368369 } else {
369370 if ( $colours[$pdbk] != '' ) {
370371 $attribs['class'] = $colours[$pdbk];
Index: trunk/phase3/includes/Linker.php
@@ -154,15 +154,20 @@
155155 * @param $query array The query string to append to the URL
156156 * you're linking to, in key => value array form. Query keys and values
157157 * will be URL-encoded.
158 - * @param $options string|array String or array of strings:
159 - * 'known': Page is known to exist, so don't check if it does.
160 - * 'broken': Page is known not to exist, so don't check if it does.
161 - * 'noclasses': Don't add any classes automatically (includes "new",
 158+ * @param $options string|array String or array:
 159+ * - Either with numerical index and following values:
 160+ * - 'known': Page is known to exist, so don't check if it does.
 161+ * - 'broken': Page is known not to exist, so don't check if it does.
 162+ * - 'noclasses': Don't add any classes automatically (includes "new",
162163 * "stub", "mw-redirect", "extiw"). Only use the class attribute
163164 * provided, if any, so you get a simple blue link with no funny i-
164165 * cons.
165 - * 'forcearticlepath': Use the article path always, even with a querystring.
 166+ * - 'forcearticlepath': Use the article path always, even with a querystring.
166167 * Has compatibility issues on some setups, so avoid wherever possible.
 168+ * - Or with following indexes:
 169+ * - 'language': the value of that index is the language to use; currently
 170+ * only used for the tooltip when linking to a page that doesn't exist
 171+ * (since 1.19)
167172 * @return string HTML <a> attribute
168173 */
169174 public static function link(
@@ -189,7 +194,7 @@
190195
191196 # If we don't know whether the page exists, let's find out.
192197 wfProfileIn( __METHOD__ . '-checkPageExistence' );
193 - if ( !in_array( 'known', $options ) and !in_array( 'broken', $options ) ) {
 198+ if ( !in_array( 'known', $options, true ) && !in_array( 'broken', $options, true ) ) {
194199 if ( $target->isKnown() ) {
195200 $options[] = 'known';
196201 } else {
@@ -199,14 +204,14 @@
200205 wfProfileOut( __METHOD__ . '-checkPageExistence' );
201206
202207 $oldquery = array();
203 - if ( in_array( "forcearticlepath", $options ) && $query ) {
 208+ if ( in_array( 'forcearticlepath', $options, true ) && $query ) {
204209 $oldquery = $query;
205210 $query = array();
206211 }
207212
208213 # Note: we want the href attribute first, for prettiness.
209214 $attribs = array( 'href' => self::linkUrl( $target, $query, $options ) );
210 - if ( in_array( 'forcearticlepath', $options ) && $oldquery ) {
 215+ if ( in_array( 'forcearticlepath', $options, true ) && $oldquery ) {
211216 $attribs['href'] = wfAppendQuery( $attribs['href'], wfArrayToCgi( $oldquery ) );
212217 }
213218
@@ -246,7 +251,7 @@
247252 wfProfileIn( __METHOD__ );
248253 # We don't want to include fragments for broken links, because they
249254 # generally make no sense.
250 - if ( in_array( 'broken', $options ) && $target->mFragment !== '' ) {
 255+ if ( in_array( 'broken', $options, true ) && $target->mFragment !== '' ) {
251256 $target = clone $target;
252257 $target->mFragment = '';
253258 }
@@ -254,7 +259,7 @@
255260 # If it's a broken link, add the appropriate query pieces, unless
256261 # there's already an action specified, or unless 'edit' makes no sense
257262 # (i.e., for a nonexistent special page).
258 - if ( in_array( 'broken', $options ) && empty( $query['action'] )
 263+ if ( in_array( 'broken', $options, true ) && empty( $query['action'] )
259264 && !$target->isSpecialPage() ) {
260265 $query['action'] = 'edit';
261266 $query['redlink'] = '1';
@@ -274,24 +279,22 @@
275280 * @return array
276281 */
277282 private static function linkAttribs( $target, $attribs, $options ) {
 283+ global $wgUser;
 284+
278285 wfProfileIn( __METHOD__ );
279 - global $wgUser;
 286+
280287 $defaults = array();
281288
282 - if ( !in_array( 'noclasses', $options ) ) {
 289+ if ( !in_array( 'noclasses', $options, true ) ) {
283290 wfProfileIn( __METHOD__ . '-getClasses' );
284291 # Now build the classes.
285292 $classes = array();
286293
287 - if ( in_array( 'broken', $options ) ) {
288 - $classes[] = 'new';
289 - }
290 -
291294 if ( $target->isExternal() ) {
292295 $classes[] = 'extiw';
293 - }
294 -
295 - if ( !in_array( 'broken', $options ) ) { # Avoid useless calls to LinkCache (see r50387)
 296+ } elseif ( in_array( 'broken', $options, true ) ) {
 297+ $classes[] = 'new';
 298+ } else { # Avoid useless calls to LinkCache (see r50387)
296299 $colour = self::getLinkColour( $target, $wgUser->getStubThreshold() );
297300 if ( $colour !== '' ) {
298301 $classes[] = $colour; # mw-redirect or stub
@@ -307,10 +310,14 @@
308311 if ( $target->getPrefixedText() == '' ) {
309312 # A link like [[#Foo]]. This used to mean an empty title
310313 # attribute, but that's silly. Just don't output a title.
311 - } elseif ( in_array( 'known', $options ) ) {
 314+ } elseif ( in_array( 'known', $options, true ) ) {
312315 $defaults['title'] = $target->getPrefixedText();
313316 } else {
314 - $defaults['title'] = wfMsg( 'red-link-title', $target->getPrefixedText() );
 317+ $msg = wfMessage( 'red-link-title', $target->getPrefixedText() );
 318+ if ( isset( $options['language'] ) ) {
 319+ $msg->inLanguage( $options['language'] );
 320+ }
 321+ $defaults['title'] = $msg->text();
315322 }
316323
317324 # Finally, merge the custom attribs with the default ones, and iterate

Follow-up revisions

RevisionCommit summaryAuthorDate
r107941Revert r107773 - increases parsercache fragmentation without clear benefitbrion21:20, 3 January 2012

Comments

#Comment by Nikerabbit (talk | contribs)   20:05, 1 January 2012

Do we actually want to fragment the parser cache for this?

#Comment by IAlex (talk | contribs)   20:27, 1 January 2012

If there's something else depending on requested language (like a TOC or {{int:}}), the parser cache will not be more fragmented; and the only other solution would be to always show this in page's language.

#Comment by Platonides (talk | contribs)   21:07, 1 January 2012

Unless you did it in a postprocessing step.

#Comment by Hashar (talk | contribs)   09:09, 3 January 2012

Why have you changed the strictness of in_array() ? If that is not related, that should have been made a different commit. If related, would be great to add a comment about it.

#Comment by Brion VIBBER (talk | contribs)   21:21, 3 January 2012

Reverted in r107941. Offhand I agree with above; this increases parsercache fragmentation and there are some questions about some of how it works internally which looks odd.

#Comment by Nikerabbit (talk | contribs)   09:13, 4 January 2012

There is one clear benefit though, the users don't see the tooltip in random languages. There are other solutions to fix that too.

Status & tagging log