Remove addExtraSQL
[lhc/web/wiklou.git] / includes / Linker.php
1 <?php
2 /**
3 * Some internal bits split of from Skin.php. These functions are used
4 * for primarily page content: links, embedded images, table of contents. Links
5 * are also used in the skin.
6 *
7 * @ingroup Skins
8 */
9 class Linker {
10
11 /**
12 * Flags for userToolLinks()
13 */
14 const TOOL_LINKS_NOBLOCK = 1;
15
16 /**
17 * Get the appropriate HTML attributes to add to the "a" element of an ex-
18 * ternal link, as created by [wikisyntax].
19 *
20 * @param $class String: the contents of the class attribute; if an empty
21 * string is passed, which is the default value, defaults to 'external'.
22 * @deprecated since 1.18 Just pass the external class directly to something using Html::expandAttributes
23 */
24 static function getExternalLinkAttributes( $class = 'external' ) {
25 wfDeprecated( __METHOD__ );
26 return self::getLinkAttributesInternal( '', $class );
27 }
28
29 /**
30 * Get the appropriate HTML attributes to add to the "a" element of an in-
31 * terwiki link.
32 *
33 * @param $title String: the title text for the link, URL-encoded (???) but
34 * not HTML-escaped
35 * @param $unused String: unused
36 * @param $class String: the contents of the class attribute; if an empty
37 * string is passed, which is the default value, defaults to 'external'.
38 */
39 static function getInterwikiLinkAttributes( $title, $unused = null, $class = 'external' ) {
40 global $wgContLang;
41
42 # FIXME: We have a whole bunch of handling here that doesn't happen in
43 # getExternalLinkAttributes, why?
44 $title = urldecode( $title );
45 $title = $wgContLang->checkTitleEncoding( $title );
46 $title = preg_replace( '/[\\x00-\\x1f]/', ' ', $title );
47
48 return self::getLinkAttributesInternal( $title, $class );
49 }
50
51 /**
52 * Get the appropriate HTML attributes to add to the "a" element of an in-
53 * ternal link.
54 *
55 * @param $title String: the title text for the link, URL-encoded (???) but
56 * not HTML-escaped
57 * @param $unused String: unused
58 * @param $class String: the contents of the class attribute, default none
59 */
60 static function getInternalLinkAttributes( $title, $unused = null, $class = '' ) {
61 $title = urldecode( $title );
62 $title = str_replace( '_', ' ', $title );
63 return self::getLinkAttributesInternal( $title, $class );
64 }
65
66 /**
67 * Get the appropriate HTML attributes to add to the "a" element of an in-
68 * ternal link, given the Title object for the page we want to link to.
69 *
70 * @param $nt Title
71 * @param $unused String: unused
72 * @param $class String: the contents of the class attribute, default none
73 * @param $title Mixed: optional (unescaped) string to use in the title
74 * attribute; if false, default to the name of the page we're linking to
75 */
76 static function getInternalLinkAttributesObj( $nt, $unused = null, $class = '', $title = false ) {
77 if ( $title === false ) {
78 $title = $nt->getPrefixedText();
79 }
80 return self::getLinkAttributesInternal( $title, $class );
81 }
82
83 /**
84 * Common code for getLinkAttributesX functions
85 */
86 private static function getLinkAttributesInternal( $title, $class ) {
87 $title = htmlspecialchars( $title );
88 $class = htmlspecialchars( $class );
89 $r = '';
90 if ( $class != '' ) {
91 $r .= " class=\"$class\"";
92 }
93 if ( $title != '' ) {
94 $r .= " title=\"$title\"";
95 }
96 return $r;
97 }
98
99 /**
100 * Return the CSS colour of a known link
101 *
102 * @param $t Title object
103 * @param $threshold Integer: user defined threshold
104 * @return String: CSS class
105 */
106 static function getLinkColour( $t, $threshold ) {
107 $colour = '';
108 if ( $t->isRedirect() ) {
109 # Page is a redirect
110 $colour = 'mw-redirect';
111 } elseif ( $threshold > 0 &&
112 $t->exists() && $t->getLength() < $threshold &&
113 $t->isContentPage() ) {
114 # Page is a stub
115 $colour = 'stub';
116 }
117 return $colour;
118 }
119
120 /**
121 * This function returns an HTML link to the given target. It serves a few
122 * purposes:
123 * 1) If $target is a Title, the correct URL to link to will be figured
124 * out automatically.
125 * 2) It automatically adds the usual classes for various types of link
126 * targets: "new" for red links, "stub" for short articles, etc.
127 * 3) It escapes all attribute values safely so there's no risk of XSS.
128 * 4) It provides a default tooltip if the target is a Title (the page
129 * name of the target).
130 * link() replaces the old functions in the makeLink() family.
131 *
132 * @param $target Title Can currently only be a Title, but this may
133 * change to support Images, literal URLs, etc.
134 * @param $text string The HTML contents of the <a> element, i.e.,
135 * the link text. This is raw HTML and will not be escaped. If null,
136 * defaults to the prefixed text of the Title; or if the Title is just a
137 * fragment, the contents of the fragment.
138 * @param $customAttribs array A key => value array of extra HTML attri-
139 * butes, such as title and class. (href is ignored.) Classes will be
140 * merged with the default classes, while other attributes will replace
141 * default attributes. All passed attribute values will be HTML-escaped.
142 * A false attribute value means to suppress that attribute.
143 * @param $query array The query string to append to the URL
144 * you're linking to, in key => value array form. Query keys and values
145 * will be URL-encoded.
146 * @param $options mixed String or array of strings:
147 * 'known': Page is known to exist, so don't check if it does.
148 * 'broken': Page is known not to exist, so don't check if it does.
149 * 'noclasses': Don't add any classes automatically (includes "new",
150 * "stub", "mw-redirect", "extiw"). Only use the class attribute
151 * provided, if any, so you get a simple blue link with no funny i-
152 * cons.
153 * 'forcearticlepath': Use the article path always, even with a querystring.
154 * Has compatibility issues on some setups, so avoid wherever possible.
155 * @return string HTML <a> attribute
156 */
157 public static function link(
158 $target, $text = null, $customAttribs = array(), $query = array(), $options = array()
159 ) {
160 wfProfileIn( __METHOD__ );
161 if ( !$target instanceof Title ) {
162 wfProfileOut( __METHOD__ );
163 return "<!-- ERROR -->$text";
164 }
165 $options = (array)$options;
166
167 $dummy = new DummyLinker; // dummy linker instance for bc on the hooks
168
169 $ret = null;
170 if ( !wfRunHooks( 'LinkBegin', array( $dummy, $target, &$text,
171 &$customAttribs, &$query, &$options, &$ret ) ) ) {
172 wfProfileOut( __METHOD__ );
173 return $ret;
174 }
175
176 # Normalize the Title if it's a special page
177 $target = self::normaliseSpecialPage( $target );
178
179 # If we don't know whether the page exists, let's find out.
180 wfProfileIn( __METHOD__ . '-checkPageExistence' );
181 if ( !in_array( 'known', $options ) and !in_array( 'broken', $options ) ) {
182 if ( $target->isKnown() ) {
183 $options[] = 'known';
184 } else {
185 $options[] = 'broken';
186 }
187 }
188 wfProfileOut( __METHOD__ . '-checkPageExistence' );
189
190 $oldquery = array();
191 if ( in_array( "forcearticlepath", $options ) && $query ) {
192 $oldquery = $query;
193 $query = array();
194 }
195
196 # Note: we want the href attribute first, for prettiness.
197 $attribs = array( 'href' => self::linkUrl( $target, $query, $options ) );
198 if ( in_array( 'forcearticlepath', $options ) && $oldquery ) {
199 $attribs['href'] = wfAppendQuery( $attribs['href'], wfArrayToCgi( $oldquery ) );
200 }
201
202 $attribs = array_merge(
203 $attribs,
204 self::linkAttribs( $target, $customAttribs, $options )
205 );
206 if ( is_null( $text ) ) {
207 $text = self::linkText( $target );
208 }
209
210 $ret = null;
211 if ( wfRunHooks( 'LinkEnd', array( $dummy, $target, $options, &$text, &$attribs, &$ret ) ) ) {
212 $ret = Html::rawElement( 'a', $attribs, $text );
213 }
214
215 wfProfileOut( __METHOD__ );
216 return $ret;
217 }
218
219 /**
220 * Identical to link(), except $options defaults to 'known'.
221 */
222 public static function linkKnown(
223 $target, $text = null, $customAttribs = array(),
224 $query = array(), $options = array( 'known', 'noclasses' ) )
225 {
226 return self::link( $target, $text, $customAttribs, $query, $options );
227 }
228
229 /**
230 * Returns the Url used to link to a Title
231 *
232 * @param $target Title
233 */
234 private static function linkUrl( $target, $query, $options ) {
235 wfProfileIn( __METHOD__ );
236 # We don't want to include fragments for broken links, because they
237 # generally make no sense.
238 if ( in_array( 'broken', $options ) && $target->mFragment !== '' ) {
239 $target = clone $target;
240 $target->mFragment = '';
241 }
242
243 # If it's a broken link, add the appropriate query pieces, unless
244 # there's already an action specified, or unless 'edit' makes no sense
245 # (i.e., for a nonexistent special page).
246 if ( in_array( 'broken', $options ) && empty( $query['action'] )
247 && $target->getNamespace() != NS_SPECIAL ) {
248 $query['action'] = 'edit';
249 $query['redlink'] = '1';
250 }
251 $ret = $target->getLinkUrl( $query );
252 wfProfileOut( __METHOD__ );
253 return $ret;
254 }
255
256 /**
257 * Returns the array of attributes used when linking to the Title $target
258 *
259 * @param $target Title
260 */
261 private static function linkAttribs( $target, $attribs, $options ) {
262 wfProfileIn( __METHOD__ );
263 global $wgUser;
264 $defaults = array();
265
266 if ( !in_array( 'noclasses', $options ) ) {
267 wfProfileIn( __METHOD__ . '-getClasses' );
268 # Now build the classes.
269 $classes = array();
270
271 if ( in_array( 'broken', $options ) ) {
272 $classes[] = 'new';
273 }
274
275 if ( $target->isExternal() ) {
276 $classes[] = 'extiw';
277 }
278
279 if ( !in_array( 'broken', $options ) ) { # Avoid useless calls to LinkCache (see r50387)
280 $colour = self::getLinkColour( $target, $wgUser->getStubThreshold() );
281 if ( $colour !== '' ) {
282 $classes[] = $colour; # mw-redirect or stub
283 }
284 }
285 if ( $classes != array() ) {
286 $defaults['class'] = implode( ' ', $classes );
287 }
288 wfProfileOut( __METHOD__ . '-getClasses' );
289 }
290
291 # Get a default title attribute.
292 if ( $target->getPrefixedText() == '' ) {
293 # A link like [[#Foo]]. This used to mean an empty title
294 # attribute, but that's silly. Just don't output a title.
295 } elseif ( in_array( 'known', $options ) ) {
296 $defaults['title'] = $target->getPrefixedText();
297 } else {
298 $defaults['title'] = wfMsg( 'red-link-title', $target->getPrefixedText() );
299 }
300
301 # Finally, merge the custom attribs with the default ones, and iterate
302 # over that, deleting all "false" attributes.
303 $ret = array();
304 $merged = Sanitizer::mergeAttributes( $defaults, $attribs );
305 foreach ( $merged as $key => $val ) {
306 # A false value suppresses the attribute, and we don't want the
307 # href attribute to be overridden.
308 if ( $key != 'href' and $val !== false ) {
309 $ret[$key] = $val;
310 }
311 }
312 wfProfileOut( __METHOD__ );
313 return $ret;
314 }
315
316 /**
317 * Default text of the links to the Title $target
318 *
319 * @param $target Title
320 *
321 * @return string
322 */
323 private static function linkText( $target ) {
324 # We might be passed a non-Title by make*LinkObj(). Fail gracefully.
325 if ( !$target instanceof Title ) {
326 return '';
327 }
328
329 # If the target is just a fragment, with no title, we return the frag-
330 # ment text. Otherwise, we return the title text itself.
331 if ( $target->getPrefixedText() === '' && $target->getFragment() !== '' ) {
332 return htmlspecialchars( $target->getFragment() );
333 }
334 return htmlspecialchars( $target->getPrefixedText() );
335 }
336
337 /**
338 * Generate either a normal exists-style link or a stub link, depending
339 * on the given page size.
340 *
341 * @param $size Integer
342 * @param $nt Title object.
343 * @param $text String
344 * @param $query String
345 * @param $trail String
346 * @param $prefix String
347 * @return string HTML of link
348 * @deprecated since 1.17
349 */
350 static function makeSizeLinkObj( $size, $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
351 global $wgUser;
352 wfDeprecated( __METHOD__ );
353
354 $threshold = $wgUser->getStubThreshold();
355 $colour = ( $size < $threshold ) ? 'stub' : '';
356 // FIXME: replace deprecated makeColouredLinkObj by link()
357 return self::makeColouredLinkObj( $nt, $colour, $text, $query, $trail, $prefix );
358 }
359
360 /**
361 * Make appropriate markup for a link to the current article. This is currently rendered
362 * as the bold link text. The calling sequence is the same as the other make*LinkObj static functions,
363 * despite $query not being used.
364 *
365 * @param $nt Title
366 *
367 * @return string
368 */
369 static function makeSelfLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
370 if ( $text == '' ) {
371 $text = htmlspecialchars( $nt->getPrefixedText() );
372 }
373 list( $inside, $trail ) = self::splitTrail( $trail );
374 return "<strong class=\"selflink\">{$prefix}{$text}{$inside}</strong>{$trail}";
375 }
376
377 /**
378 * @param $title Title
379 * @return Title
380 */
381 static function normaliseSpecialPage( Title $title ) {
382 if ( $title->getNamespace() == NS_SPECIAL ) {
383 list( $name, $subpage ) = SpecialPageFactory::resolveAlias( $title->getDBkey() );
384 if ( !$name ) {
385 return $title;
386 }
387 $ret = SpecialPage::getTitleFor( $name, $subpage );
388 $ret->mFragment = $title->getFragment();
389 return $ret;
390 } else {
391 return $title;
392 }
393 }
394
395 /**
396 * Returns the filename part of an url.
397 * Used as alternative text for external images.
398 *
399 * @param $url string
400 *
401 * @return string
402 */
403 static function fnamePart( $url ) {
404 $basename = strrchr( $url, '/' );
405 if ( false === $basename ) {
406 $basename = $url;
407 } else {
408 $basename = substr( $basename, 1 );
409 }
410 return $basename;
411 }
412
413 /**
414 * Return the code for images which were added via external links,
415 * via Parser::maybeMakeExternalImage().
416 *
417 * @param $url
418 * @param $alt
419 *
420 * @return string
421 */
422 static function makeExternalImage( $url, $alt = '' ) {
423 if ( $alt == '' ) {
424 $alt = self::fnamePart( $url );
425 }
426 $img = '';
427 $success = wfRunHooks( 'LinkerMakeExternalImage', array( &$url, &$alt, &$img ) );
428 if ( !$success ) {
429 wfDebug( "Hook LinkerMakeExternalImage changed the output of external image with url {$url} and alt text {$alt} to {$img}\n", true );
430 return $img;
431 }
432 return Html::element( 'img',
433 array(
434 'src' => $url,
435 'alt' => $alt ) );
436 }
437
438 /**
439 * Given parameters derived from [[Image:Foo|options...]], generate the
440 * HTML that that syntax inserts in the page.
441 *
442 * @param $title Title object
443 * @param $file File object, or false if it doesn't exist
444 * @param $frameParams Array: associative array of parameters external to the media handler.
445 * Boolean parameters are indicated by presence or absence, the value is arbitrary and
446 * will often be false.
447 * thumbnail If present, downscale and frame
448 * manualthumb Image name to use as a thumbnail, instead of automatic scaling
449 * framed Shows image in original size in a frame
450 * frameless Downscale but don't frame
451 * upright If present, tweak default sizes for portrait orientation
452 * upright_factor Fudge factor for "upright" tweak (default 0.75)
453 * border If present, show a border around the image
454 * align Horizontal alignment (left, right, center, none)
455 * valign Vertical alignment (baseline, sub, super, top, text-top, middle,
456 * bottom, text-bottom)
457 * alt Alternate text for image (i.e. alt attribute). Plain text.
458 * caption HTML for image caption.
459 * link-url URL to link to
460 * link-title Title object to link to
461 * link-target Value for the target attribue, only with link-url
462 * no-link Boolean, suppress description link
463 *
464 * @param $handlerParams Array: associative array of media handler parameters, to be passed
465 * to transform(). Typical keys are "width" and "page".
466 * @param $time String: timestamp of the file, set as false for current
467 * @param $query String: query params for desc url
468 * @param $widthOption: Used by the parser to remember the user preference thumbnailsize
469 * @return String: HTML for an image, with links, wrappers, etc.
470 */
471 static function makeImageLink2( Title $title, $file, $frameParams = array(),
472 $handlerParams = array(), $time = false, $query = "", $widthOption = null )
473 {
474 $res = null;
475 $dummy = new DummyLinker;
476 if ( !wfRunHooks( 'ImageBeforeProduceHTML', array( &$dummy, &$title,
477 &$file, &$frameParams, &$handlerParams, &$time, &$res ) ) ) {
478 return $res;
479 }
480
481 if ( $file && !$file->allowInlineDisplay() ) {
482 wfDebug( __METHOD__ . ': ' . $title->getPrefixedDBkey() . " does not allow inline display\n" );
483 return self::link( $title );
484 }
485
486 // Shortcuts
487 $fp =& $frameParams;
488 $hp =& $handlerParams;
489
490 // Clean up parameters
491 $page = isset( $hp['page'] ) ? $hp['page'] : false;
492 if ( !isset( $fp['align'] ) ) {
493 $fp['align'] = '';
494 }
495 if ( !isset( $fp['alt'] ) ) {
496 $fp['alt'] = '';
497 }
498 if ( !isset( $fp['title'] ) ) {
499 $fp['title'] = '';
500 }
501
502 $prefix = $postfix = '';
503
504 if ( 'center' == $fp['align'] ) {
505 $prefix = '<div class="center">';
506 $postfix = '</div>';
507 $fp['align'] = 'none';
508 }
509 if ( $file && !isset( $hp['width'] ) ) {
510 $hp['width'] = $file->getWidth( $page );
511
512 if ( isset( $fp['thumbnail'] ) || isset( $fp['framed'] ) || isset( $fp['frameless'] ) || !$hp['width'] ) {
513 global $wgThumbLimits, $wgThumbUpright;
514 if ( !isset( $widthOption ) || !isset( $wgThumbLimits[$widthOption] ) ) {
515 $widthOption = User::getDefaultOption( 'thumbsize' );
516 }
517
518 // Reduce width for upright images when parameter 'upright' is used
519 if ( isset( $fp['upright'] ) && $fp['upright'] == 0 ) {
520 $fp['upright'] = $wgThumbUpright;
521 }
522 // For caching health: If width scaled down due to upright parameter, round to full __0 pixel to avoid the creation of a lot of odd thumbs
523 $prefWidth = isset( $fp['upright'] ) ?
524 round( $wgThumbLimits[$widthOption] * $fp['upright'], -1 ) :
525 $wgThumbLimits[$widthOption];
526
527 // Use width which is smaller: real image width or user preference width
528 // Unless image is scalable vector.
529 if ( !isset( $hp['height'] ) && ( $hp['width'] <= 0 ||
530 $prefWidth < $hp['width'] || $file->isVectorized() ) ) {
531 $hp['width'] = $prefWidth;
532 }
533 }
534 }
535
536 if ( isset( $fp['thumbnail'] ) || isset( $fp['manualthumb'] ) || isset( $fp['framed'] ) ) {
537 global $wgContLang;
538 # Create a thumbnail. Alignment depends on language
539 # writing direction, # right aligned for left-to-right-
540 # languages ("Western languages"), left-aligned
541 # for right-to-left-languages ("Semitic languages")
542 #
543 # If thumbnail width has not been provided, it is set
544 # to the default user option as specified in Language*.php
545 if ( $fp['align'] == '' ) {
546 $fp['align'] = $wgContLang->alignEnd();
547 }
548 return $prefix . self::makeThumbLink2( $title, $file, $fp, $hp, $time, $query ) . $postfix;
549 }
550
551 if ( $file && isset( $fp['frameless'] ) ) {
552 $srcWidth = $file->getWidth( $page );
553 # For "frameless" option: do not present an image bigger than the source (for bitmap-style images)
554 # This is the same behaviour as the "thumb" option does it already.
555 if ( $srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth ) {
556 $hp['width'] = $srcWidth;
557 }
558 }
559
560 if ( $file && isset( $hp['width'] ) ) {
561 # Create a resized image, without the additional thumbnail features
562 $thumb = $file->transform( $hp );
563 } else {
564 $thumb = false;
565 }
566
567 if ( !$thumb ) {
568 $s = self::makeBrokenImageLinkObj( $title, $fp['title'], '', '', '', $time == true );
569 } else {
570 $params = array(
571 'alt' => $fp['alt'],
572 'title' => $fp['title'],
573 'valign' => isset( $fp['valign'] ) ? $fp['valign'] : false ,
574 'img-class' => isset( $fp['border'] ) ? 'thumbborder' : false );
575 $params = self::getImageLinkMTOParams( $fp, $query ) + $params;
576
577 $s = $thumb->toHtml( $params );
578 }
579 if ( $fp['align'] != '' ) {
580 $s = "<div class=\"float{$fp['align']}\">{$s}</div>";
581 }
582 return str_replace( "\n", ' ', $prefix . $s . $postfix );
583 }
584
585 /**
586 * Get the link parameters for MediaTransformOutput::toHtml() from given
587 * frame parameters supplied by the Parser.
588 * @param $frameParams The frame parameters
589 * @param $query An optional query string to add to description page links
590 */
591 static function getImageLinkMTOParams( $frameParams, $query = '' ) {
592 $mtoParams = array();
593 if ( isset( $frameParams['link-url'] ) && $frameParams['link-url'] !== '' ) {
594 $mtoParams['custom-url-link'] = $frameParams['link-url'];
595 if ( isset( $frameParams['link-target'] ) ) {
596 $mtoParams['custom-target-link'] = $frameParams['link-target'];
597 }
598 } elseif ( isset( $frameParams['link-title'] ) && $frameParams['link-title'] !== '' ) {
599 $mtoParams['custom-title-link'] = self::normaliseSpecialPage( $frameParams['link-title'] );
600 } elseif ( !empty( $frameParams['no-link'] ) ) {
601 // No link
602 } else {
603 $mtoParams['desc-link'] = true;
604 $mtoParams['desc-query'] = $query;
605 }
606 return $mtoParams;
607 }
608
609 /**
610 * Make HTML for a thumbnail including image, border and caption
611 * @param $title Title object
612 * @param $file File object or false if it doesn't exist
613 * @param $label String
614 * @param $alt String
615 * @param $align String
616 * @param $params Array
617 * @param $framed Boolean
618 * @param $manualthumb String
619 */
620 static function makeThumbLinkObj( Title $title, $file, $label = '', $alt,
621 $align = 'right', $params = array(), $framed = false , $manualthumb = "" )
622 {
623 $frameParams = array(
624 'alt' => $alt,
625 'caption' => $label,
626 'align' => $align
627 );
628 if ( $framed ) {
629 $frameParams['framed'] = true;
630 }
631 if ( $manualthumb ) {
632 $frameParams['manualthumb'] = $manualthumb;
633 }
634 return self::makeThumbLink2( $title, $file, $frameParams, $params );
635 }
636
637 /**
638 * @param $title Title
639 * @param $file File
640 * @param array $frameParams
641 * @param array $handlerParams
642 * @param bool $time
643 * @param string $query
644 * @return mixed
645 */
646 static function makeThumbLink2( Title $title, $file, $frameParams = array(),
647 $handlerParams = array(), $time = false, $query = "" )
648 {
649 global $wgStylePath, $wgContLang;
650 $exists = $file && $file->exists();
651
652 # Shortcuts
653 $fp =& $frameParams;
654 $hp =& $handlerParams;
655
656 $page = isset( $hp['page'] ) ? $hp['page'] : false;
657 if ( !isset( $fp['align'] ) ) $fp['align'] = 'right';
658 if ( !isset( $fp['alt'] ) ) $fp['alt'] = '';
659 if ( !isset( $fp['title'] ) ) $fp['title'] = '';
660 if ( !isset( $fp['caption'] ) ) $fp['caption'] = '';
661
662 if ( empty( $hp['width'] ) ) {
663 // Reduce width for upright images when parameter 'upright' is used
664 $hp['width'] = isset( $fp['upright'] ) ? 130 : 180;
665 }
666 $thumb = false;
667
668 if ( !$exists ) {
669 $outerWidth = $hp['width'] + 2;
670 } else {
671 if ( isset( $fp['manualthumb'] ) ) {
672 # Use manually specified thumbnail
673 $manual_title = Title::makeTitleSafe( NS_FILE, $fp['manualthumb'] );
674 if ( $manual_title ) {
675 $manual_img = wfFindFile( $manual_title );
676 if ( $manual_img ) {
677 $thumb = $manual_img->getUnscaledThumb( $hp );
678 } else {
679 $exists = false;
680 }
681 }
682 } elseif ( isset( $fp['framed'] ) ) {
683 // Use image dimensions, don't scale
684 $thumb = $file->getUnscaledThumb( $hp );
685 } else {
686 # Do not present an image bigger than the source, for bitmap-style images
687 # This is a hack to maintain compatibility with arbitrary pre-1.10 behaviour
688 $srcWidth = $file->getWidth( $page );
689 if ( $srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth ) {
690 $hp['width'] = $srcWidth;
691 }
692 $thumb = $file->transform( $hp );
693 }
694
695 if ( $thumb ) {
696 $outerWidth = $thumb->getWidth() + 2;
697 } else {
698 $outerWidth = $hp['width'] + 2;
699 }
700 }
701
702 # ThumbnailImage::toHtml() already adds page= onto the end of DjVu URLs
703 # So we don't need to pass it here in $query. However, the URL for the
704 # zoom icon still needs it, so we make a unique query for it. See bug 14771
705 $url = $title->getLocalURL( $query );
706 if ( $page ) {
707 $url = wfAppendQuery( $url, 'page=' . urlencode( $page ) );
708 }
709
710 $s = "<div class=\"thumb t{$fp['align']}\"><div class=\"thumbinner\" style=\"width:{$outerWidth}px;\">";
711 if ( !$exists ) {
712 $s .= self::makeBrokenImageLinkObj( $title, $fp['title'], '', '', '', $time == true );
713 $zoomIcon = '';
714 } elseif ( !$thumb ) {
715 $s .= htmlspecialchars( wfMsg( 'thumbnail_error', '' ) );
716 $zoomIcon = '';
717 } else {
718 $params = array(
719 'alt' => $fp['alt'],
720 'title' => $fp['title'],
721 'img-class' => 'thumbimage' );
722 $params = self::getImageLinkMTOParams( $fp, $query ) + $params;
723 $s .= $thumb->toHtml( $params );
724 if ( isset( $fp['framed'] ) ) {
725 $zoomIcon = "";
726 } else {
727 $zoomIcon = Html::rawElement( 'div', array( 'class' => 'magnify' ),
728 Html::rawElement( 'a', array(
729 'href' => $url,
730 'class' => 'internal',
731 'title' => wfMsg( 'thumbnail-more' ) ),
732 Html::element( 'img', array(
733 'src' => $wgStylePath . '/common/images/magnify-clip' . ( $wgContLang->isRTL() ? '-rtl' : '' ) . '.png',
734 'width' => 15,
735 'height' => 11,
736 'alt' => "" ) ) ) );
737 }
738 }
739 $s .= ' <div class="thumbcaption">' . $zoomIcon . $fp['caption'] . "</div></div></div>";
740 return str_replace( "\n", ' ', $s );
741 }
742
743 /**
744 * Make a "broken" link to an image
745 *
746 * @param $title Title object
747 * @param $text String: link label in unescaped text form
748 * @param $query String: query string
749 * @param $trail String: link trail (HTML fragment)
750 * @param $prefix String: link prefix (HTML fragment)
751 * @param $time Boolean: a file of a certain timestamp was requested
752 * @return String
753 */
754 public static function makeBrokenImageLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '', $time = false ) {
755 global $wgEnableUploads, $wgUploadMissingFileUrl;
756 if ( $title instanceof Title ) {
757 wfProfileIn( __METHOD__ );
758 $currentExists = $time ? ( wfFindFile( $title ) != false ) : false;
759
760 list( $inside, $trail ) = self::splitTrail( $trail );
761 if ( $text == '' )
762 $text = htmlspecialchars( $title->getPrefixedText() );
763
764 if ( ( $wgUploadMissingFileUrl || $wgEnableUploads ) && !$currentExists ) {
765 $redir = RepoGroup::singleton()->getLocalRepo()->checkRedirect( $title );
766
767 if ( $redir ) {
768 wfProfileOut( __METHOD__ );
769 return self::linkKnown( $title, "$prefix$text$inside", array(), $query ) . $trail;
770 }
771
772 $href = self::getUploadUrl( $title, $query );
773
774 wfProfileOut( __METHOD__ );
775 return '<a href="' . htmlspecialchars( $href ) . '" class="new" title="' .
776 htmlspecialchars( $title->getPrefixedText(), ENT_QUOTES ) . '">' .
777 "$prefix$text$inside</a>$trail";
778 } else {
779 wfProfileOut( __METHOD__ );
780 return self::linkKnown( $title, "$prefix$text$inside", array(), $query ) . $trail;
781 }
782 } else {
783 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
784 }
785 }
786
787 /**
788 * Get the URL to upload a certain file
789 *
790 * @param $destFile Title object of the file to upload
791 * @param $query String: urlencoded query string to prepend
792 * @return String: urlencoded URL
793 */
794 protected static function getUploadUrl( $destFile, $query = '' ) {
795 global $wgUploadMissingFileUrl;
796 $q = 'wpDestFile=' . $destFile->getPartialUrl();
797 if ( $query != '' )
798 $q .= '&' . $query;
799
800 if ( $wgUploadMissingFileUrl ) {
801 return wfAppendQuery( $wgUploadMissingFileUrl, $q );
802 } else {
803 $upload = SpecialPage::getTitleFor( 'Upload' );
804 return $upload->getLocalUrl( $q );
805 }
806 }
807
808 /**
809 * Create a direct link to a given uploaded file.
810 *
811 * @param $title Title object.
812 * @param $text String: pre-sanitized HTML
813 * @param $time string: MW timestamp of file creation time
814 * @return String: HTML
815 */
816 public static function makeMediaLinkObj( $title, $text = '', $time = false ) {
817 $img = wfFindFile( $title, array( 'time' => $time ) );
818 return self::makeMediaLinkFile( $title, $img, $text );
819 }
820
821 /**
822 * Create a direct link to a given uploaded file.
823 * This will make a broken link if $file is false.
824 *
825 * @param $title Title object.
826 * @param $file mixed File object or false
827 * @param $text String: pre-sanitized HTML
828 * @return String: HTML
829 *
830 * @todo Handle invalid or missing images better.
831 */
832 public static function makeMediaLinkFile( Title $title, $file, $text = '' ) {
833 if ( $file && $file->exists() ) {
834 $url = $file->getURL();
835 $class = 'internal';
836 } else {
837 $url = self::getUploadUrl( $title );
838 $class = 'new';
839 }
840 $alt = htmlspecialchars( $title->getText(), ENT_QUOTES );
841 if ( $text == '' ) {
842 $text = $alt;
843 }
844 $u = htmlspecialchars( $url );
845 return "<a href=\"{$u}\" class=\"$class\" title=\"{$alt}\">{$text}</a>";
846 }
847
848 /**
849 * Make a link to a special page given its name and, optionally,
850 * a message key from the link text.
851 * Usage example: $skin->specialLink( 'recentchanges' )
852 */
853 static function specialLink( $name, $key = '' ) {
854 if ( $key == '' ) { $key = strtolower( $name ); }
855
856 return self::linkKnown( SpecialPage::getTitleFor( $name ) , wfMsg( $key ) );
857 }
858
859 /**
860 * Make an external link
861 * @param $url String: URL to link to
862 * @param $text String: text of link
863 * @param $escape Boolean: do we escape the link text?
864 * @param $linktype String: type of external link. Gets added to the classes
865 * @param $attribs Array of extra attributes to <a>
866 */
867 static function makeExternalLink( $url, $text, $escape = true, $linktype = '', $attribs = array() ) {
868 $class = "external";
869 if ( isset($linktype) && $linktype ) {
870 $class .= " $linktype";
871 }
872 if ( isset($attribs['class']) && $attribs['class'] ) {
873 $class .= " {$attribs['class']}";
874 }
875 $attribs['class'] = $class;
876
877 if ( $escape ) {
878 $text = htmlspecialchars( $text );
879 }
880 $link = '';
881 $success = wfRunHooks( 'LinkerMakeExternalLink',
882 array( &$url, &$text, &$link, &$attribs, $linktype ) );
883 if ( !$success ) {
884 wfDebug( "Hook LinkerMakeExternalLink changed the output of link with url {$url} and text {$text} to {$link}\n", true );
885 return $link;
886 }
887 $attribs['href'] = $url;
888 return Html::rawElement( 'a', $attribs, $text );
889 }
890
891 /**
892 * Make user link (or user contributions for unregistered users)
893 * @param $userId Integer: user id in database.
894 * @param $userText String: user name in database
895 * @return String: HTML fragment
896 * @private
897 */
898 static function userLink( $userId, $userText ) {
899 if ( $userId == 0 ) {
900 $page = SpecialPage::getTitleFor( 'Contributions', $userText );
901 } else {
902 $page = Title::makeTitle( NS_USER, $userText );
903 }
904 return self::link( $page, htmlspecialchars( $userText ), array( 'class' => 'mw-userlink' ) );
905 }
906
907 /**
908 * Generate standard user tool links (talk, contributions, block link, etc.)
909 *
910 * @param $userId Integer: user identifier
911 * @param $userText String: user name or IP address
912 * @param $redContribsWhenNoEdits Boolean: should the contributions link be
913 * red if the user has no edits?
914 * @param $flags Integer: customisation flags (e.g. Linker::TOOL_LINKS_NOBLOCK)
915 * @param $edits Integer: user edit count (optional, for performance)
916 * @return String: HTML fragment
917 */
918 public static function userToolLinks(
919 $userId, $userText, $redContribsWhenNoEdits = false, $flags = 0, $edits = null
920 ) {
921 global $wgUser, $wgDisableAnonTalk, $wgLang;
922 $talkable = !( $wgDisableAnonTalk && 0 == $userId );
923 $blockable = !$flags & self::TOOL_LINKS_NOBLOCK;
924
925 $items = array();
926 if ( $talkable ) {
927 $items[] = self::userTalkLink( $userId, $userText );
928 }
929 if ( $userId ) {
930 // check if the user has an edit
931 $attribs = array();
932 if ( $redContribsWhenNoEdits ) {
933 $count = !is_null( $edits ) ? $edits : User::edits( $userId );
934 if ( $count == 0 ) {
935 $attribs['class'] = 'new';
936 }
937 }
938 $contribsPage = SpecialPage::getTitleFor( 'Contributions', $userText );
939
940 $items[] = self::link( $contribsPage, wfMsgHtml( 'contribslink' ), $attribs );
941 }
942 if ( $blockable && $wgUser->isAllowed( 'block' ) ) {
943 $items[] = self::blockLink( $userId, $userText );
944 }
945
946 if ( $items ) {
947 return ' <span class="mw-usertoollinks">(' . $wgLang->pipeList( $items ) . ')</span>';
948 } else {
949 return '';
950 }
951 }
952
953 /**
954 * Alias for userToolLinks( $userId, $userText, true );
955 * @param $userId Integer: user identifier
956 * @param $userText String: user name or IP address
957 * @param $edits Integer: user edit count (optional, for performance)
958 */
959 public static function userToolLinksRedContribs( $userId, $userText, $edits = null ) {
960 return self::userToolLinks( $userId, $userText, true, 0, $edits );
961 }
962
963
964 /**
965 * @param $userId Integer: user id in database.
966 * @param $userText String: user name in database.
967 * @return String: HTML fragment with user talk link
968 * @private
969 */
970 static function userTalkLink( $userId, $userText ) {
971 $userTalkPage = Title::makeTitle( NS_USER_TALK, $userText );
972 $userTalkLink = self::link( $userTalkPage, wfMsgHtml( 'talkpagelinktext' ) );
973 return $userTalkLink;
974 }
975
976 /**
977 * @param $userId Integer: userid
978 * @param $userText String: user name in database.
979 * @return String: HTML fragment with block link
980 * @private
981 */
982 static function blockLink( $userId, $userText ) {
983 $blockPage = SpecialPage::getTitleFor( 'Block', $userText );
984 $blockLink = self::link( $blockPage, wfMsgHtml( 'blocklink' ) );
985 return $blockLink;
986 }
987
988 /**
989 * Generate a user link if the current user is allowed to view it
990 * @param $rev Revision object.
991 * @param $isPublic Boolean: show only if all users can see it
992 * @return String: HTML fragment
993 */
994 static function revUserLink( $rev, $isPublic = false ) {
995 if ( $rev->isDeleted( Revision::DELETED_USER ) && $isPublic ) {
996 $link = wfMsgHtml( 'rev-deleted-user' );
997 } else if ( $rev->userCan( Revision::DELETED_USER ) ) {
998 $link = self::userLink( $rev->getUser( Revision::FOR_THIS_USER ),
999 $rev->getUserText( Revision::FOR_THIS_USER ) );
1000 } else {
1001 $link = wfMsgHtml( 'rev-deleted-user' );
1002 }
1003 if ( $rev->isDeleted( Revision::DELETED_USER ) ) {
1004 return '<span class="history-deleted">' . $link . '</span>';
1005 }
1006 return $link;
1007 }
1008
1009 /**
1010 * Generate a user tool link cluster if the current user is allowed to view it
1011 * @param $rev Revision object.
1012 * @param $isPublic Boolean: show only if all users can see it
1013 * @return string HTML
1014 */
1015 static function revUserTools( $rev, $isPublic = false ) {
1016 if ( $rev->isDeleted( Revision::DELETED_USER ) && $isPublic ) {
1017 $link = wfMsgHtml( 'rev-deleted-user' );
1018 } else if ( $rev->userCan( Revision::DELETED_USER ) ) {
1019 $userId = $rev->getUser( Revision::FOR_THIS_USER );
1020 $userText = $rev->getUserText( Revision::FOR_THIS_USER );
1021 $link = self::userLink( $userId, $userText ) .
1022 ' ' . self::userToolLinks( $userId, $userText );
1023 } else {
1024 $link = wfMsgHtml( 'rev-deleted-user' );
1025 }
1026 if ( $rev->isDeleted( Revision::DELETED_USER ) ) {
1027 return ' <span class="history-deleted">' . $link . '</span>';
1028 }
1029 return $link;
1030 }
1031
1032 /**
1033 * This function is called by all recent changes variants, by the page history,
1034 * and by the user contributions list. It is responsible for formatting edit
1035 * comments. It escapes any HTML in the comment, but adds some CSS to format
1036 * auto-generated comments (from section editing) and formats [[wikilinks]].
1037 *
1038 * @author Erik Moeller <moeller@scireview.de>
1039 *
1040 * Note: there's not always a title to pass to this function.
1041 * Since you can't set a default parameter for a reference, I've turned it
1042 * temporarily to a value pass. Should be adjusted further. --brion
1043 *
1044 * @param $comment String
1045 * @param $title Mixed: Title object (to generate link to the section in autocomment) or null
1046 * @param $local Boolean: whether section links should refer to local page
1047 */
1048 static function formatComment( $comment, $title = null, $local = false ) {
1049 wfProfileIn( __METHOD__ );
1050
1051 # Sanitize text a bit:
1052 $comment = str_replace( "\n", " ", $comment );
1053 # Allow HTML entities (for bug 13815)
1054 $comment = Sanitizer::escapeHtmlAllowEntities( $comment );
1055
1056 # Render autocomments and make links:
1057 $comment = self::formatAutocomments( $comment, $title, $local );
1058 $comment = self::formatLinksInComment( $comment, $title, $local );
1059
1060 wfProfileOut( __METHOD__ );
1061 return $comment;
1062 }
1063
1064 static $autocommentTitle;
1065 static $autocommentLocal;
1066
1067 /**
1068 * The pattern for autogen comments is / * foo * /, which makes for
1069 * some nasty regex.
1070 * We look for all comments, match any text before and after the comment,
1071 * add a separator where needed and format the comment itself with CSS
1072 * Called by Linker::formatComment.
1073 *
1074 * @param $comment String: comment text
1075 * @param $title An optional title object used to links to sections
1076 * @param $local Boolean: whether section links should refer to local page
1077 * @return String: formatted comment
1078 */
1079 private static function formatAutocomments( $comment, $title = null, $local = false ) {
1080 // Bah!
1081 self::$autocommentTitle = $title;
1082 self::$autocommentLocal = $local;
1083 $comment = preg_replace_callback(
1084 '!(.*)/\*\s*(.*?)\s*\*/(.*)!',
1085 array( 'Linker', 'formatAutocommentsCallback' ),
1086 $comment );
1087 self::$autocommentTitle = null;
1088 self::$autocommentLocal = null;
1089 return $comment;
1090 }
1091
1092 private static function formatAutocommentsCallback( $match ) {
1093 $title = self::$autocommentTitle;
1094 $local = self::$autocommentLocal;
1095
1096 $pre = $match[1];
1097 $auto = $match[2];
1098 $post = $match[3];
1099 $link = '';
1100 if ( $title ) {
1101 $section = $auto;
1102
1103 # Remove links that a user may have manually put in the autosummary
1104 # This could be improved by copying as much of Parser::stripSectionName as desired.
1105 $section = str_replace( '[[:', '', $section );
1106 $section = str_replace( '[[', '', $section );
1107 $section = str_replace( ']]', '', $section );
1108
1109 $section = Sanitizer::normalizeSectionNameWhitespace( $section ); # bug 22784
1110 if ( $local ) {
1111 $sectionTitle = Title::newFromText( '#' . $section );
1112 } else {
1113 $sectionTitle = Title::makeTitleSafe( $title->getNamespace(),
1114 $title->getDBkey(), $section );
1115 }
1116 if ( $sectionTitle ) {
1117 $link = self::link( $sectionTitle,
1118 htmlspecialchars( wfMsgForContent( 'sectionlink' ) ), array(), array(),
1119 'noclasses' );
1120 } else {
1121 $link = '';
1122 }
1123 }
1124 $auto = "$link$auto";
1125 if ( $pre ) {
1126 # written summary $presep autocomment (summary /* section */)
1127 $auto = wfMsgExt( 'autocomment-prefix', array( 'escapenoentities', 'content' ) ) . $auto;
1128 }
1129 if ( $post ) {
1130 # autocomment $postsep written summary (/* section */ summary)
1131 $auto .= wfMsgExt( 'colon-separator', array( 'escapenoentities', 'content' ) );
1132 }
1133 $auto = '<span class="autocomment">' . $auto . '</span>';
1134 $comment = $pre . $auto . $post;
1135 return $comment;
1136 }
1137
1138 static $commentContextTitle;
1139 static $commentLocal;
1140
1141 /**
1142 * Formats wiki links and media links in text; all other wiki formatting
1143 * is ignored
1144 *
1145 * @todo Fixme: doesn't handle sub-links as in image thumb texts like the main parser
1146 * @param $comment String: text to format links in
1147 * @param $title An optional title object used to links to sections
1148 * @param $local Boolean: whether section links should refer to local page
1149 * @return String
1150 */
1151 public static function formatLinksInComment( $comment, $title = null, $local = false ) {
1152 self::$commentContextTitle = $title;
1153 self::$commentLocal = $local;
1154 $html = preg_replace_callback(
1155 '/\[\[:?(.*?)(\|(.*?))*\]\]([^[]*)/',
1156 array( 'Linker', 'formatLinksInCommentCallback' ),
1157 $comment );
1158 self::$commentContextTitle = null;
1159 self::$commentLocal = null;
1160 return $html;
1161 }
1162
1163 protected static function formatLinksInCommentCallback( $match ) {
1164 global $wgContLang;
1165
1166 $medians = '(?:' . preg_quote( MWNamespace::getCanonicalName( NS_MEDIA ), '/' ) . '|';
1167 $medians .= preg_quote( $wgContLang->getNsText( NS_MEDIA ), '/' ) . '):';
1168
1169 $comment = $match[0];
1170
1171 # fix up urlencoded title texts (copied from Parser::replaceInternalLinks)
1172 if ( strpos( $match[1], '%' ) !== false ) {
1173 $match[1] = str_replace( array( '<', '>' ), array( '&lt;', '&gt;' ), rawurldecode( $match[1] ) );
1174 }
1175
1176 # Handle link renaming [[foo|text]] will show link as "text"
1177 if ( $match[3] != "" ) {
1178 $text = $match[3];
1179 } else {
1180 $text = $match[1];
1181 }
1182 $submatch = array();
1183 $thelink = null;
1184 if ( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
1185 # Media link; trail not supported.
1186 $linkRegexp = '/\[\[(.*?)\]\]/';
1187 $title = Title::makeTitleSafe( NS_FILE, $submatch[1] );
1188 $thelink = self::makeMediaLinkObj( $title, $text );
1189 } else {
1190 # Other kind of link
1191 if ( preg_match( $wgContLang->linkTrail(), $match[4], $submatch ) ) {
1192 $trail = $submatch[1];
1193 } else {
1194 $trail = "";
1195 }
1196 $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
1197 if ( isset( $match[1][0] ) && $match[1][0] == ':' )
1198 $match[1] = substr( $match[1], 1 );
1199 list( $inside, $trail ) = self::splitTrail( $trail );
1200
1201 $linkText = $text;
1202 $linkTarget = self::normalizeSubpageLink( self::$commentContextTitle,
1203 $match[1], $linkText );
1204
1205 $target = Title::newFromText( $linkTarget );
1206 if ( $target ) {
1207 if ( $target->getText() == '' && $target->getInterwiki() === ''
1208 && !self::$commentLocal && self::$commentContextTitle )
1209 {
1210 $newTarget = clone ( self::$commentContextTitle );
1211 $newTarget->setFragment( '#' . $target->getFragment() );
1212 $target = $newTarget;
1213 }
1214 $thelink = self::link(
1215 $target,
1216 $linkText . $inside
1217 ) . $trail;
1218 }
1219 }
1220 if ( $thelink ) {
1221 // If the link is still valid, go ahead and replace it in!
1222 $comment = preg_replace( $linkRegexp, StringUtils::escapeRegexReplacement( $thelink ), $comment, 1 );
1223 }
1224
1225 return $comment;
1226 }
1227
1228 /**
1229 * @param $contextTitle Title
1230 * @param $target
1231 * @param $text
1232 * @return string
1233 */
1234 static function normalizeSubpageLink( $contextTitle, $target, &$text ) {
1235 # Valid link forms:
1236 # Foobar -- normal
1237 # :Foobar -- override special treatment of prefix (images, language links)
1238 # /Foobar -- convert to CurrentPage/Foobar
1239 # /Foobar/ -- convert to CurrentPage/Foobar, strip the initial / from text
1240 # ../ -- convert to CurrentPage, from CurrentPage/CurrentSubPage
1241 # ../Foobar -- convert to CurrentPage/Foobar, from CurrentPage/CurrentSubPage
1242
1243 wfProfileIn( __METHOD__ );
1244 $ret = $target; # default return value is no change
1245
1246 # Some namespaces don't allow subpages,
1247 # so only perform processing if subpages are allowed
1248 if ( $contextTitle && MWNamespace::hasSubpages( $contextTitle->getNamespace() ) ) {
1249 $hash = strpos( $target, '#' );
1250 if ( $hash !== false ) {
1251 $suffix = substr( $target, $hash );
1252 $target = substr( $target, 0, $hash );
1253 } else {
1254 $suffix = '';
1255 }
1256 # bug 7425
1257 $target = trim( $target );
1258 # Look at the first character
1259 if ( $target != '' && $target { 0 } === '/' ) {
1260 # / at end means we don't want the slash to be shown
1261 $m = array();
1262 $trailingSlashes = preg_match_all( '%(/+)$%', $target, $m );
1263 if ( $trailingSlashes ) {
1264 $noslash = $target = substr( $target, 1, -strlen( $m[0][0] ) );
1265 } else {
1266 $noslash = substr( $target, 1 );
1267 }
1268
1269 $ret = $contextTitle->getPrefixedText() . '/' . trim( $noslash ) . $suffix;
1270 if ( $text === '' ) {
1271 $text = $target . $suffix;
1272 } # this might be changed for ugliness reasons
1273 } else {
1274 # check for .. subpage backlinks
1275 $dotdotcount = 0;
1276 $nodotdot = $target;
1277 while ( strncmp( $nodotdot, "../", 3 ) == 0 ) {
1278 ++$dotdotcount;
1279 $nodotdot = substr( $nodotdot, 3 );
1280 }
1281 if ( $dotdotcount > 0 ) {
1282 $exploded = explode( '/', $contextTitle->GetPrefixedText() );
1283 if ( count( $exploded ) > $dotdotcount ) { # not allowed to go below top level page
1284 $ret = implode( '/', array_slice( $exploded, 0, -$dotdotcount ) );
1285 # / at the end means don't show full path
1286 if ( substr( $nodotdot, -1, 1 ) === '/' ) {
1287 $nodotdot = substr( $nodotdot, 0, -1 );
1288 if ( $text === '' ) {
1289 $text = $nodotdot . $suffix;
1290 }
1291 }
1292 $nodotdot = trim( $nodotdot );
1293 if ( $nodotdot != '' ) {
1294 $ret .= '/' . $nodotdot;
1295 }
1296 $ret .= $suffix;
1297 }
1298 }
1299 }
1300 }
1301
1302 wfProfileOut( __METHOD__ );
1303 return $ret;
1304 }
1305
1306 /**
1307 * Wrap a comment in standard punctuation and formatting if
1308 * it's non-empty, otherwise return empty string.
1309 *
1310 * @param $comment String
1311 * @param $title Mixed: Title object (to generate link to section in autocomment) or null
1312 * @param $local Boolean: whether section links should refer to local page
1313 * @param $embraced Boolean: whether the formatted comment should be embraced with ()
1314 * @return string
1315 */
1316 static function commentBlock( $comment, $title = null, $local = false, $embraced = true ) {
1317 // '*' used to be the comment inserted by the software way back
1318 // in antiquity in case none was provided, here for backwards
1319 // compatability, acc. to brion -ævar
1320 if ( $comment == '' || $comment == '*' ) {
1321 return '';
1322 } else {
1323 $formatted = self::formatComment( $comment, $title, $local );
1324 if ( $embraced ) {
1325 $formatted = wfMessage( 'parentheses' )->rawParams( $formatted )->escaped();
1326 }
1327 return Html::rawElement( 'span', array( 'class' => 'comment' ), $formatted );
1328 }
1329 }
1330
1331 /**
1332 * Wrap and format the given revision's comment block, if the current
1333 * user is allowed to view it.
1334 *
1335 * @param $rev Revision object
1336 * @param $local Boolean: whether section links should refer to local page
1337 * @param $isPublic Boolean: show only if all users can see it
1338 * @return String: HTML fragment
1339 */
1340 static function revComment( Revision $rev, $local = false, $isPublic = false ) {
1341 if ( $rev->getRawComment() == "" ) {
1342 return "";
1343 }
1344 if ( $rev->isDeleted( Revision::DELETED_COMMENT ) && $isPublic ) {
1345 $block = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
1346 } else if ( $rev->userCan( Revision::DELETED_COMMENT ) ) {
1347 $block = self::commentBlock( $rev->getComment( Revision::FOR_THIS_USER ),
1348 $rev->getTitle(), $local );
1349 } else {
1350 $block = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
1351 }
1352 if ( $rev->isDeleted( Revision::DELETED_COMMENT ) ) {
1353 return " <span class=\"history-deleted\">$block</span>";
1354 }
1355 return $block;
1356 }
1357
1358 public static function formatRevisionSize( $size ) {
1359 if ( $size == 0 ) {
1360 $stxt = wfMsgExt( 'historyempty', 'parsemag' );
1361 } else {
1362 global $wgLang;
1363 $stxt = wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $size ) );
1364 $stxt = "($stxt)";
1365 }
1366 $stxt = htmlspecialchars( $stxt );
1367 return "<span class=\"history-size\">$stxt</span>";
1368 }
1369
1370 /**
1371 * Add another level to the Table of Contents
1372 */
1373 static function tocIndent() {
1374 return "\n<ul>";
1375 }
1376
1377 /**
1378 * Finish one or more sublevels on the Table of Contents
1379 */
1380 static function tocUnindent( $level ) {
1381 return "</li>\n" . str_repeat( "</ul>\n</li>\n", $level > 0 ? $level : 0 );
1382 }
1383
1384 /**
1385 * parameter level defines if we are on an indentation level
1386 */
1387 static function tocLine( $anchor, $tocline, $tocnumber, $level, $sectionIndex = false ) {
1388 $classes = "toclevel-$level";
1389 if ( $sectionIndex !== false )
1390 $classes .= " tocsection-$sectionIndex";
1391 return "\n<li class=\"$classes\"><a href=\"#" .
1392 $anchor . '"><span class="tocnumber">' .
1393 $tocnumber . '</span> <span class="toctext">' .
1394 $tocline . '</span></a>';
1395 }
1396
1397 /**
1398 * End a Table Of Contents line.
1399 * tocUnindent() will be used instead if we're ending a line below
1400 * the new level.
1401 */
1402 static function tocLineEnd() {
1403 return "</li>\n";
1404 }
1405
1406 /**
1407 * Wraps the TOC in a table and provides the hide/collapse javascript.
1408 *
1409 * @param $toc String: html of the Table Of Contents
1410 * @param $lang mixed: Language code for the toc title
1411 * @return String: full html of the TOC
1412 */
1413 static function tocList( $toc, $lang = false ) {
1414 $title = wfMsgExt( 'toc', array( 'language' => $lang, 'escape' ) );
1415 return
1416 '<table id="toc" class="toc"><tr><td>'
1417 . '<div id="toctitle"><h2>' . $title . "</h2></div>\n"
1418 . $toc
1419 . "</ul>\n</td></tr></table>\n";
1420 }
1421
1422 /**
1423 * Generate a table of contents from a section tree
1424 * Currently unused.
1425 *
1426 * @param $tree Return value of ParserOutput::getSections()
1427 * @return String: HTML fragment
1428 */
1429 public static function generateTOC( $tree ) {
1430 $toc = '';
1431 $lastLevel = 0;
1432 foreach ( $tree as $section ) {
1433 if ( $section['toclevel'] > $lastLevel )
1434 $toc .= self::tocIndent();
1435 else if ( $section['toclevel'] < $lastLevel )
1436 $toc .= self::tocUnindent(
1437 $lastLevel - $section['toclevel'] );
1438 else
1439 $toc .= self::tocLineEnd();
1440
1441 $toc .= self::tocLine( $section['anchor'],
1442 $section['line'], $section['number'],
1443 $section['toclevel'], $section['index'] );
1444 $lastLevel = $section['toclevel'];
1445 }
1446 $toc .= self::tocLineEnd();
1447 return self::tocList( $toc );
1448 }
1449
1450 /**
1451 * Create a headline for content
1452 *
1453 * @param $level Integer: the level of the headline (1-6)
1454 * @param $attribs String: any attributes for the headline, starting with
1455 * a space and ending with '>'
1456 * This *must* be at least '>' for no attribs
1457 * @param $anchor String: the anchor to give the headline (the bit after the #)
1458 * @param $text String: the text of the header
1459 * @param $link String: HTML to add for the section edit link
1460 * @param $legacyAnchor Mixed: a second, optional anchor to give for
1461 * backward compatibility (false to omit)
1462 *
1463 * @return String: HTML headline
1464 */
1465 public static function makeHeadline( $level, $attribs, $anchor, $text, $link, $legacyAnchor = false ) {
1466 $ret = "<h$level$attribs"
1467 . $link
1468 . " <span class=\"mw-headline\" id=\"$anchor\">$text</span>"
1469 . "</h$level>";
1470 if ( $legacyAnchor !== false ) {
1471 $ret = "<div id=\"$legacyAnchor\"></div>$ret";
1472 }
1473 return $ret;
1474 }
1475
1476 /**
1477 * Split a link trail, return the "inside" portion and the remainder of the trail
1478 * as a two-element array
1479 */
1480 static function splitTrail( $trail ) {
1481 global $wgContLang;
1482 $regex = $wgContLang->linkTrail();
1483 $inside = '';
1484 if ( $trail !== '' ) {
1485 $m = array();
1486 if ( preg_match( $regex, $trail, $m ) ) {
1487 $inside = $m[1];
1488 $trail = $m[2];
1489 }
1490 }
1491 return array( $inside, $trail );
1492 }
1493
1494 /**
1495 * Generate a rollback link for a given revision. Currently it's the
1496 * caller's responsibility to ensure that the revision is the top one. If
1497 * it's not, of course, the user will get an error message.
1498 *
1499 * If the calling page is called with the parameter &bot=1, all rollback
1500 * links also get that parameter. It causes the edit itself and the rollback
1501 * to be marked as "bot" edits. Bot edits are hidden by default from recent
1502 * changes, so this allows sysops to combat a busy vandal without bothering
1503 * other users.
1504 *
1505 * @param $rev Revision object
1506 */
1507 static function generateRollback( $rev ) {
1508 return '<span class="mw-rollback-link">['
1509 . self::buildRollbackLink( $rev )
1510 . ']</span>';
1511 }
1512
1513 /**
1514 * Build a raw rollback link, useful for collections of "tool" links
1515 *
1516 * @param $rev Revision object
1517 * @return String: HTML fragment
1518 */
1519 public static function buildRollbackLink( $rev ) {
1520 global $wgRequest, $wgUser;
1521 $title = $rev->getTitle();
1522 $query = array(
1523 'action' => 'rollback',
1524 'from' => $rev->getUserText(),
1525 'token' => $wgUser->editToken( array( $title->getPrefixedText(), $rev->getUserText() ) ),
1526 );
1527 if ( $wgRequest->getBool( 'bot' ) ) {
1528 $query['bot'] = '1';
1529 $query['hidediff'] = '1'; // bug 15999
1530 }
1531 return self::link(
1532 $title,
1533 wfMsgHtml( 'rollbacklink' ),
1534 array( 'title' => wfMsg( 'tooltip-rollback' ) ),
1535 $query,
1536 array( 'known', 'noclasses' )
1537 );
1538 }
1539
1540 /**
1541 * Returns HTML for the "templates used on this page" list.
1542 *
1543 * @param $templates Array of templates from Article::getUsedTemplate
1544 * or similar
1545 * @param $preview Boolean: whether this is for a preview
1546 * @param $section Boolean: whether this is for a section edit
1547 * @return String: HTML output
1548 */
1549 public static function formatTemplates( $templates, $preview = false, $section = false ) {
1550 wfProfileIn( __METHOD__ );
1551
1552 $outText = '';
1553 if ( count( $templates ) > 0 ) {
1554 # Do a batch existence check
1555 $batch = new LinkBatch;
1556 foreach ( $templates as $title ) {
1557 $batch->addObj( $title );
1558 }
1559 $batch->execute();
1560
1561 # Construct the HTML
1562 $outText = '<div class="mw-templatesUsedExplanation">';
1563 if ( $preview ) {
1564 $outText .= wfMsgExt( 'templatesusedpreview', array( 'parse' ), count( $templates ) );
1565 } elseif ( $section ) {
1566 $outText .= wfMsgExt( 'templatesusedsection', array( 'parse' ), count( $templates ) );
1567 } else {
1568 $outText .= wfMsgExt( 'templatesused', array( 'parse' ), count( $templates ) );
1569 }
1570 $outText .= "</div><ul>\n";
1571
1572 usort( $templates, array( 'Title', 'compare' ) );
1573 foreach ( $templates as $titleObj ) {
1574 $r = $titleObj->getRestrictions( 'edit' );
1575 if ( in_array( 'sysop', $r ) ) {
1576 $protected = wfMsgExt( 'template-protected', array( 'parseinline' ) );
1577 } elseif ( in_array( 'autoconfirmed', $r ) ) {
1578 $protected = wfMsgExt( 'template-semiprotected', array( 'parseinline' ) );
1579 } else {
1580 $protected = '';
1581 }
1582 if ( $titleObj->quickUserCan( 'edit' ) ) {
1583 $editLink = self::link(
1584 $titleObj,
1585 wfMsg( 'editlink' ),
1586 array(),
1587 array( 'action' => 'edit' )
1588 );
1589 } else {
1590 $editLink = self::link(
1591 $titleObj,
1592 wfMsg( 'viewsourcelink' ),
1593 array(),
1594 array( 'action' => 'edit' )
1595 );
1596 }
1597 $outText .= '<li>' . self::link( $titleObj ) . ' (' . $editLink . ') ' . $protected . '</li>';
1598 }
1599 $outText .= '</ul>';
1600 }
1601 wfProfileOut( __METHOD__ );
1602 return $outText;
1603 }
1604
1605 /**
1606 * Returns HTML for the "hidden categories on this page" list.
1607 *
1608 * @param $hiddencats Array of hidden categories from Article::getHiddenCategories
1609 * or similar
1610 * @return String: HTML output
1611 */
1612 public static function formatHiddenCategories( $hiddencats ) {
1613 global $wgLang;
1614 wfProfileIn( __METHOD__ );
1615
1616 $outText = '';
1617 if ( count( $hiddencats ) > 0 ) {
1618 # Construct the HTML
1619 $outText = '<div class="mw-hiddenCategoriesExplanation">';
1620 $outText .= wfMsgExt( 'hiddencategories', array( 'parse' ), $wgLang->formatnum( count( $hiddencats ) ) );
1621 $outText .= "</div><ul>\n";
1622
1623 foreach ( $hiddencats as $titleObj ) {
1624 $outText .= '<li>' . self::link( $titleObj, null, array(), array(), 'known' ) . "</li>\n"; # If it's hidden, it must exist - no need to check with a LinkBatch
1625 }
1626 $outText .= '</ul>';
1627 }
1628 wfProfileOut( __METHOD__ );
1629 return $outText;
1630 }
1631
1632 /**
1633 * Format a size in bytes for output, using an appropriate
1634 * unit (B, KB, MB or GB) according to the magnitude in question
1635 *
1636 * @param $size Size to format
1637 * @return String
1638 */
1639 public static function formatSize( $size ) {
1640 global $wgLang;
1641 return htmlspecialchars( $wgLang->formatSize( $size ) );
1642 }
1643
1644 /**
1645 * Given the id of an interface element, constructs the appropriate title
1646 * attribute from the system messages. (Note, this is usually the id but
1647 * isn't always, because sometimes the accesskey needs to go on a different
1648 * element than the id, for reverse-compatibility, etc.)
1649 *
1650 * @param $name String: id of the element, minus prefixes.
1651 * @param $options Mixed: null or the string 'withaccess' to add an access-
1652 * key hint
1653 * @return String: contents of the title attribute (which you must HTML-
1654 * escape), or false for no title attribute
1655 */
1656 public static function titleAttrib( $name, $options = null ) {
1657 wfProfileIn( __METHOD__ );
1658
1659 $message = wfMessage( "tooltip-$name" );
1660
1661 if ( !$message->exists() ) {
1662 $tooltip = false;
1663 } else {
1664 $tooltip = $message->text();
1665 # Compatibility: formerly some tooltips had [alt-.] hardcoded
1666 $tooltip = preg_replace( "/ ?\[alt-.\]$/", '', $tooltip );
1667 # Message equal to '-' means suppress it.
1668 if ( $tooltip == '-' ) {
1669 $tooltip = false;
1670 }
1671 }
1672
1673 if ( $options == 'withaccess' ) {
1674 $accesskey = self::accesskey( $name );
1675 if ( $accesskey !== false ) {
1676 if ( $tooltip === false || $tooltip === '' ) {
1677 $tooltip = "[$accesskey]";
1678 } else {
1679 $tooltip .= " [$accesskey]";
1680 }
1681 }
1682 }
1683
1684 wfProfileOut( __METHOD__ );
1685 return $tooltip;
1686 }
1687
1688 static $accesskeycache;
1689
1690 /**
1691 * Given the id of an interface element, constructs the appropriate
1692 * accesskey attribute from the system messages. (Note, this is usually
1693 * the id but isn't always, because sometimes the accesskey needs to go on
1694 * a different element than the id, for reverse-compatibility, etc.)
1695 *
1696 * @param $name String: id of the element, minus prefixes.
1697 * @return String: contents of the accesskey attribute (which you must HTML-
1698 * escape), or false for no accesskey attribute
1699 */
1700 public static function accesskey( $name ) {
1701 if ( isset( self::$accesskeycache[$name] ) ) {
1702 return self::$accesskeycache[$name];
1703 }
1704 wfProfileIn( __METHOD__ );
1705
1706 $message = wfMessage( "accesskey-$name" );
1707
1708 if ( !$message->exists() ) {
1709 $accesskey = false;
1710 } else {
1711 $accesskey = $message->plain();
1712 if ( $accesskey === '' || $accesskey === '-' ) {
1713 # FIXME: Per standard MW behavior, a value of '-' means to suppress the
1714 # attribute, but this is broken for accesskey: that might be a useful
1715 # value.
1716 $accesskey = false;
1717 }
1718 }
1719
1720 wfProfileOut( __METHOD__ );
1721 return self::$accesskeycache[$name] = $accesskey;
1722 }
1723
1724 /**
1725 * Creates a (show/hide) link for deleting revisions/log entries
1726 *
1727 * @param $query Array: query parameters to be passed to link()
1728 * @param $restricted Boolean: set to true to use a <strong> instead of a <span>
1729 * @param $delete Boolean: set to true to use (show/hide) rather than (show)
1730 *
1731 * @return String: HTML <a> link to Special:Revisiondelete, wrapped in a
1732 * span to allow for customization of appearance with CSS
1733 */
1734 public static function revDeleteLink( $query = array(), $restricted = false, $delete = true ) {
1735 $sp = SpecialPage::getTitleFor( 'Revisiondelete' );
1736 $text = $delete ? wfMsgHtml( 'rev-delundel' ) : wfMsgHtml( 'rev-showdeleted' );
1737 $tag = $restricted ? 'strong' : 'span';
1738 $link = self::link( $sp, $text, array(), $query, array( 'known', 'noclasses' ) );
1739 return Xml::tags( $tag, array( 'class' => 'mw-revdelundel-link' ), "($link)" );
1740 }
1741
1742 /**
1743 * Creates a dead (show/hide) link for deleting revisions/log entries
1744 *
1745 * @param $delete Boolean: set to true to use (show/hide) rather than (show)
1746 *
1747 * @return string HTML text wrapped in a span to allow for customization
1748 * of appearance with CSS
1749 */
1750 public static function revDeleteLinkDisabled( $delete = true ) {
1751 $text = $delete ? wfMsgHtml( 'rev-delundel' ) : wfMsgHtml( 'rev-showdeleted' );
1752 return Xml::tags( 'span', array( 'class' => 'mw-revdelundel-link' ), "($text)" );
1753 }
1754
1755 /* Deprecated methods */
1756
1757 /**
1758 * @deprecated since 1.16 Use link()
1759 *
1760 * This function is a shortcut to makeBrokenLinkObj(Title::newFromText($title),...). Do not call
1761 * it if you already have a title object handy. See makeBrokenLinkObj for further documentation.
1762 *
1763 * @param $title String: The text of the title
1764 * @param $text String: Link text
1765 * @param $query String: Optional query part
1766 * @param $trail String: Optional trail. Alphabetic characters at the start of this string will
1767 * be included in the link text. Other characters will be appended after
1768 * the end of the link.
1769 */
1770 static function makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) {
1771 $nt = Title::newFromText( $title );
1772 if ( $nt instanceof Title ) {
1773 return self::makeBrokenLinkObj( $nt, $text, $query, $trail );
1774 } else {
1775 wfDebug( 'Invalid title passed to self::makeBrokenLink(): "' . $title . "\"\n" );
1776 return $text == '' ? $title : $text;
1777 }
1778 }
1779
1780 /**
1781 * @deprecated since 1.16 Use link()
1782 *
1783 * Make a link for a title which may or may not be in the database. If you need to
1784 * call this lots of times, pre-fill the link cache with a LinkBatch, otherwise each
1785 * call to this will result in a DB query.
1786 *
1787 * @param $nt Title: the title object to make the link from, e.g. from
1788 * Title::newFromText.
1789 * @param $text String: link text
1790 * @param $query String: optional query part
1791 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
1792 * be included in the link text. Other characters will be appended after
1793 * the end of the link.
1794 * @param $prefix String: optional prefix. As trail, only before instead of after.
1795 */
1796 static function makeLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
1797 wfDeprecated( __METHOD__ );
1798 wfProfileIn( __METHOD__ );
1799 $query = wfCgiToArray( $query );
1800 list( $inside, $trail ) = self::splitTrail( $trail );
1801 if ( $text === '' ) {
1802 $text = self::linkText( $nt );
1803 }
1804
1805 $ret = self::link( $nt, "$prefix$text$inside", array(), $query ) . $trail;
1806
1807 wfProfileOut( __METHOD__ );
1808 return $ret;
1809 }
1810
1811 /**
1812 * @deprecated since 1.16 Use link()
1813 *
1814 * Make a link for a title which definitely exists. This is faster than makeLinkObj because
1815 * it doesn't have to do a database query. It's also valid for interwiki titles and special
1816 * pages.
1817 *
1818 * @param $title Title object of target page
1819 * @param $text String: text to replace the title
1820 * @param $query String: link target
1821 * @param $trail String: text after link
1822 * @param $prefix String: text before link text
1823 * @param $aprops String: extra attributes to the a-element
1824 * @param $style String: style to apply - if empty, use getInternalLinkAttributesObj instead
1825 * @return the a-element
1826 */
1827 static function makeKnownLinkObj(
1828 $title, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '', $style = ''
1829 ) {
1830 wfProfileIn( __METHOD__ );
1831
1832 if ( $text == '' ) {
1833 $text = self::linkText( $title );
1834 }
1835 $attribs = Sanitizer::mergeAttributes(
1836 Sanitizer::decodeTagAttributes( $aprops ),
1837 Sanitizer::decodeTagAttributes( $style )
1838 );
1839 $query = wfCgiToArray( $query );
1840 list( $inside, $trail ) = self::splitTrail( $trail );
1841
1842 $ret = self::link( $title, "$prefix$text$inside", $attribs, $query,
1843 array( 'known', 'noclasses' ) ) . $trail;
1844
1845 wfProfileOut( __METHOD__ );
1846 return $ret;
1847 }
1848
1849 /**
1850 * @deprecated since 1.16 Use link()
1851 *
1852 * Make a red link to the edit page of a given title.
1853 *
1854 * @param $title Title object of the target page
1855 * @param $text String: Link text
1856 * @param $query String: Optional query part
1857 * @param $trail String: Optional trail. Alphabetic characters at the start of this string will
1858 * be included in the link text. Other characters will be appended after
1859 * the end of the link.
1860 * @param $prefix String: Optional prefix
1861 */
1862 static function makeBrokenLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' ) {
1863 wfProfileIn( __METHOD__ );
1864
1865 list( $inside, $trail ) = self::splitTrail( $trail );
1866 if ( $text === '' ) {
1867 $text = self::linkText( $title );
1868 }
1869
1870 $ret = self::link( $title, "$prefix$text$inside", array(),
1871 wfCgiToArray( $query ), 'broken' ) . $trail;
1872
1873 wfProfileOut( __METHOD__ );
1874 return $ret;
1875 }
1876
1877 /**
1878 * @deprecated since 1.16 Use link()
1879 *
1880 * Make a coloured link.
1881 *
1882 * @param $nt Title object of the target page
1883 * @param $colour Integer: colour of the link
1884 * @param $text String: link text
1885 * @param $query String: optional query part
1886 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
1887 * be included in the link text. Other characters will be appended after
1888 * the end of the link.
1889 * @param $prefix String: Optional prefix
1890 */
1891 static function makeColouredLinkObj( $nt, $colour, $text = '', $query = '', $trail = '', $prefix = '' ) {
1892 if ( $colour != '' ) {
1893 $style = self::getInternalLinkAttributesObj( $nt, $text, $colour );
1894 } else {
1895 $style = '';
1896 }
1897 return self::makeKnownLinkObj( $nt, $text, $query, $trail, $prefix, '', $style );
1898 }
1899
1900 /**
1901 * Creates the HTML source for images
1902 * @deprecated since 1.16 use makeImageLink2
1903 *
1904 * @param $title Title object
1905 * @param $label String: label text
1906 * @param $alt String: alt text
1907 * @param $align String: horizontal alignment: none, left, center, right)
1908 * @param $handlerParams Array: parameters to be passed to the media handler
1909 * @param $framed Boolean: shows image in original size in a frame
1910 * @param $thumb Boolean: shows image as thumbnail in a frame
1911 * @param $manualthumb String: image name for the manual thumbnail
1912 * @param $valign String: vertical alignment: baseline, sub, super, top, text-top, middle, bottom, text-bottom
1913 * @param $time String: timestamp of the file, set as false for current
1914 * @return String
1915 */
1916 static function makeImageLinkObj( $title, $label, $alt, $align = '', $handlerParams = array(),
1917 $framed = false, $thumb = false, $manualthumb = '', $valign = '', $time = false )
1918 {
1919 $frameParams = array( 'alt' => $alt, 'caption' => $label );
1920 if ( $align ) {
1921 $frameParams['align'] = $align;
1922 }
1923 if ( $framed ) {
1924 $frameParams['framed'] = true;
1925 }
1926 if ( $thumb ) {
1927 $frameParams['thumbnail'] = true;
1928 }
1929 if ( $manualthumb ) {
1930 $frameParams['manualthumb'] = $manualthumb;
1931 }
1932 if ( $valign ) {
1933 $frameParams['valign'] = $valign;
1934 }
1935 $file = wfFindFile( $title, array( 'time' => $time ) );
1936 return self::makeImageLink2( $title, $file, $frameParams, $handlerParams, $time );
1937 }
1938
1939 /**
1940 * Returns the attributes for the tooltip and access key.
1941 */
1942 public static function tooltipAndAccesskeyAttribs( $name ) {
1943 global $wgEnableTooltipsAndAccesskeys;
1944 if ( !$wgEnableTooltipsAndAccesskeys )
1945 return array();
1946 # FIXME: If Sanitizer::expandAttributes() treated "false" as "output
1947 # no attribute" instead of "output '' as value for attribute", this
1948 # would be three lines.
1949 $attribs = array(
1950 'title' => self::titleAttrib( $name, 'withaccess' ),
1951 'accesskey' => self::accesskey( $name )
1952 );
1953 if ( $attribs['title'] === false ) {
1954 unset( $attribs['title'] );
1955 }
1956 if ( $attribs['accesskey'] === false ) {
1957 unset( $attribs['accesskey'] );
1958 }
1959 return $attribs;
1960 }
1961
1962 /**
1963 * @deprecated since 1.14
1964 * Returns raw bits of HTML, use titleAttrib()
1965 */
1966 public static function tooltip( $name, $options = null ) {
1967 global $wgEnableTooltipsAndAccesskeys;
1968 if ( !$wgEnableTooltipsAndAccesskeys )
1969 return '';
1970 # FIXME: If Sanitizer::expandAttributes() treated "false" as "output
1971 # no attribute" instead of "output '' as value for attribute", this
1972 # would be two lines.
1973 $tooltip = self::titleAttrib( $name, $options );
1974 if ( $tooltip === false ) {
1975 return '';
1976 }
1977 return Xml::expandAttributes( array(
1978 'title' => $tooltip
1979 ) );
1980 }
1981 }
1982
1983 class DummyLinker {
1984
1985 /**
1986 * Use PHP's magic __call handler to transform instance calls to a dummy instance
1987 * into static calls to the new Linker for backwards compatibility.
1988 *
1989 * @param $fname String Name of called method
1990 * @param $args Array Arguments to the method
1991 */
1992 function __call( $fname, $args ) {
1993 return call_user_func_array( array( 'Linker', $fname ), $args );
1994 }
1995
1996 }
1997