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