Replaced all @fixme with "@todo Fixme" since doxygen doesn't have a @fixme command
[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;
670 if( $title instanceof Title ) {
671 wfProfileIn( __METHOD__ );
672 $currentExists = $time ? ( wfFindFile( $title ) != false ) : false;
673 if( $wgEnableUploads && !$currentExists ) {
674 $upload = SpecialPage::getTitleFor( 'Upload' );
675 if( $text == '' )
676 $text = htmlspecialchars( $title->getPrefixedText() );
677 $redir = RepoGroup::singleton()->getLocalRepo()->checkRedirect( $title );
678 if( $redir ) {
679 return $this->makeKnownLinkObj( $title, $text, $query, $trail, $prefix );
680 }
681 $q = 'wpDestFile=' . $title->getPartialUrl();
682 if( $query != '' )
683 $q .= '&' . $query;
684 list( $inside, $trail ) = self::splitTrail( $trail );
685 $style = $this->getInternalLinkAttributesObj( $title, $text, 'new' );
686 wfProfileOut( __METHOD__ );
687 return '<a href="' . $upload->escapeLocalUrl( $q ) . '"'
688 . $style . '>' . $prefix . $text . $inside . '</a>' . $trail;
689 } else {
690 wfProfileOut( __METHOD__ );
691 return $this->makeKnownLinkObj( $title, $text, $query, $trail, $prefix );
692 }
693 } else {
694 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
695 }
696 }
697
698 /**
699 * Create a direct link to a given uploaded file.
700 *
701 * @param $title Title object.
702 * @param $text String: pre-sanitized HTML
703 * @param $time string: time image was created
704 * @return string HTML
705 *
706 * @public
707 * @todo Handle invalid or missing images better.
708 */
709 function makeMediaLinkObj( $title, $text = '', $time = false ) {
710 if( is_null( $title ) ) {
711 ### HOTFIX. Instead of breaking, return empty string.
712 return $text;
713 } else {
714 $img = wfFindFile( $title, array( 'time' => $time ) );
715 if( $img ) {
716 $url = $img->getURL();
717 $class = 'internal';
718 } else {
719 $upload = SpecialPage::getTitleFor( 'Upload' );
720 $url = $upload->getLocalUrl( 'wpDestFile=' . urlencode( $title->getDBkey() ) );
721 $class = 'new';
722 }
723 $alt = htmlspecialchars( $title->getText() );
724 if( $text == '' ) {
725 $text = $alt;
726 }
727 $u = htmlspecialchars( $url );
728 return "<a href=\"{$u}\" class=\"$class\" title=\"{$alt}\">{$text}</a>";
729 }
730 }
731
732 /**
733 * Make a link to a special page given its name and, optionally,
734 * a message key from the link text.
735 * Usage example: $skin->specialLink( 'recentchanges' )
736 */
737 function specialLink( $name, $key = '' ) {
738 global $wgContLang;
739
740 if ( '' == $key ) { $key = strtolower( $name ); }
741 $pn = $wgContLang->ucfirst( $name );
742 return $this->makeKnownLink( $wgContLang->specialPage( $pn ),
743 wfMsg( $key ) );
744 }
745
746 /**
747 * Make an external link
748 * @param String $url URL to link to
749 * @param String $text text of link
750 * @param boolean $escape Do we escape the link text?
751 * @param String $linktype Type of external link. Gets added to the classes
752 * @param array $attribs Array of extra attributes to <a>
753 *
754 * @todo FIXME: This is a really crappy implementation. $linktype and
755 * 'external' are mashed into the class attrib for the link (which is made
756 * into a string). Then, if we've got additional params in $attribs, we
757 * add to it. People using this might want to change the classes (or other
758 * default link attributes), but passing $attribsText is just messy. Would
759 * make a lot more sense to make put the classes into $attribs, let the
760 * hook play with them, *then* expand it all at once.
761 */
762 function makeExternalLink( $url, $text, $escape = true, $linktype = '', $attribs = array() ) {
763 if ( isset( $attribs[ 'class' ] ) ) $class = $attribs[ 'class' ]; # yet another hack :(
764 else $class = 'external ' . $linktype;
765
766 $attribsText = $this->getExternalLinkAttributes( $class );
767 $url = htmlspecialchars( $url );
768 if( $escape ) {
769 $text = htmlspecialchars( $text );
770 }
771 $link = '';
772 $success = wfRunHooks('LinkerMakeExternalLink', array( &$url, &$text, &$link, &$attribs, $linktype ) );
773 if(!$success) {
774 wfDebug("Hook LinkerMakeExternalLink changed the output of link with url {$url} and text {$text} to {$link}\n", true);
775 return $link;
776 }
777 if ( $attribs ) {
778 $attribsText .= Html::expandAttributes( $attribs );
779 }
780 return '<a href="'.$url.'"'.$attribsText.'>'.$text.'</a>';
781 }
782
783 /**
784 * Make user link (or user contributions for unregistered users)
785 * @param $userId Integer: user id in database.
786 * @param $userText String: user name in database
787 * @return string HTML fragment
788 * @private
789 */
790 function userLink( $userId, $userText ) {
791 if( $userId == 0 ) {
792 $page = SpecialPage::getTitleFor( 'Contributions', $userText );
793 } else {
794 $page = Title::makeTitle( NS_USER, $userText );
795 }
796 return $this->link( $page, htmlspecialchars( $userText ), array( 'class' => 'mw-userlink' ) );
797 }
798
799 /**
800 * Generate standard user tool links (talk, contributions, block link, etc.)
801 *
802 * @param int $userId User identifier
803 * @param string $userText User name or IP address
804 * @param bool $redContribsWhenNoEdits Should the contributions link be red if the user has no edits?
805 * @param int $flags Customisation flags (e.g. self::TOOL_LINKS_NOBLOCK)
806 * @param int $edits, user edit count (optional, for performance)
807 * @return string
808 */
809 public function userToolLinks( $userId, $userText, $redContribsWhenNoEdits = false, $flags = 0, $edits=null ) {
810 global $wgUser, $wgDisableAnonTalk, $wgSysopUserBans, $wgLang;
811 $talkable = !( $wgDisableAnonTalk && 0 == $userId );
812 $blockable = ( $wgSysopUserBans || 0 == $userId ) && !$flags & self::TOOL_LINKS_NOBLOCK;
813
814 $items = array();
815 if( $talkable ) {
816 $items[] = $this->userTalkLink( $userId, $userText );
817 }
818 if( $userId ) {
819 // check if the user has an edit
820 $attribs = array();
821 if( $redContribsWhenNoEdits ) {
822 $count = !is_null($edits) ? $edits : User::edits( $userId );
823 if( $count == 0 ) {
824 $attribs['class'] = 'new';
825 }
826 }
827 $contribsPage = SpecialPage::getTitleFor( 'Contributions', $userText );
828
829 $items[] = $this->link( $contribsPage, wfMsgHtml( 'contribslink' ), $attribs );
830 }
831 if( $blockable && $wgUser->isAllowed( 'block' ) ) {
832 $items[] = $this->blockLink( $userId, $userText );
833 }
834
835 if( $items ) {
836 return ' <span class="mw-usertoollinks">(' . $wgLang->pipeList( $items ) . ')</span>';
837 } else {
838 return '';
839 }
840 }
841
842 /**
843 * Alias for userToolLinks( $userId, $userText, true );
844 * @param int $userId User identifier
845 * @param string $userText User name or IP address
846 * @param int $edits, user edit count (optional, for performance)
847 */
848 public function userToolLinksRedContribs( $userId, $userText, $edits=null ) {
849 return $this->userToolLinks( $userId, $userText, true, 0, $edits );
850 }
851
852
853 /**
854 * @param $userId Integer: user id in database.
855 * @param $userText String: user name in database.
856 * @return string HTML fragment with user talk link
857 * @private
858 */
859 function userTalkLink( $userId, $userText ) {
860 $userTalkPage = Title::makeTitle( NS_USER_TALK, $userText );
861 $userTalkLink = $this->link( $userTalkPage, wfMsgHtml( 'talkpagelinktext' ) );
862 return $userTalkLink;
863 }
864
865 /**
866 * @param $userId Integer: userid
867 * @param $userText String: user name in database.
868 * @return string HTML fragment with block link
869 * @private
870 */
871 function blockLink( $userId, $userText ) {
872 $blockPage = SpecialPage::getTitleFor( 'Blockip', $userText );
873 $blockLink = $this->link( $blockPage, wfMsgHtml( 'blocklink' ) );
874 return $blockLink;
875 }
876
877 /**
878 * Generate a user link if the current user is allowed to view it
879 * @param $rev Revision object.
880 * @param $isPublic, bool, show only if all users can see it
881 * @return string HTML
882 */
883 function revUserLink( $rev, $isPublic = false ) {
884 if( $rev->isDeleted( Revision::DELETED_USER ) && $isPublic ) {
885 $link = wfMsgHtml( 'rev-deleted-user' );
886 } else if( $rev->userCan( Revision::DELETED_USER ) ) {
887 $link = $this->userLink( $rev->getUser( Revision::FOR_THIS_USER ),
888 $rev->getUserText( Revision::FOR_THIS_USER ) );
889 } else {
890 $link = wfMsgHtml( 'rev-deleted-user' );
891 }
892 if( $rev->isDeleted( Revision::DELETED_USER ) ) {
893 return '<span class="history-deleted">' . $link . '</span>';
894 }
895 return $link;
896 }
897
898 /**
899 * Generate a user tool link cluster if the current user is allowed to view it
900 * @param $rev Revision object.
901 * @param $isPublic, bool, show only if all users can see it
902 * @return string HTML
903 */
904 function revUserTools( $rev, $isPublic = false ) {
905 if( $rev->isDeleted( Revision::DELETED_USER ) && $isPublic ) {
906 $link = wfMsgHtml( 'rev-deleted-user' );
907 } else if( $rev->userCan( Revision::DELETED_USER ) ) {
908 $userId = $rev->getUser( Revision::FOR_THIS_USER );
909 $userText = $rev->getUserText( Revision::FOR_THIS_USER );
910 $link = $this->userLink( $userId, $userText ) .
911 ' ' . $this->userToolLinks( $userId, $userText );
912 } else {
913 $link = wfMsgHtml( 'rev-deleted-user' );
914 }
915 if( $rev->isDeleted( Revision::DELETED_USER ) ) {
916 return ' <span class="history-deleted">' . $link . '</span>';
917 }
918 return $link;
919 }
920
921 /**
922 * This function is called by all recent changes variants, by the page history,
923 * and by the user contributions list. It is responsible for formatting edit
924 * comments. It escapes any HTML in the comment, but adds some CSS to format
925 * auto-generated comments (from section editing) and formats [[wikilinks]].
926 *
927 * @author Erik Moeller <moeller@scireview.de>
928 *
929 * Note: there's not always a title to pass to this function.
930 * Since you can't set a default parameter for a reference, I've turned it
931 * temporarily to a value pass. Should be adjusted further. --brion
932 *
933 * @param string $comment
934 * @param mixed $title Title object (to generate link to the section in autocomment) or null
935 * @param bool $local Whether section links should refer to local page
936 */
937 function formatComment($comment, $title = null, $local = false) {
938 wfProfileIn( __METHOD__ );
939
940 # Sanitize text a bit:
941 $comment = str_replace( "\n", " ", $comment );
942 # Allow HTML entities (for bug 13815)
943 $comment = Sanitizer::escapeHtmlAllowEntities( $comment );
944
945 # Render autocomments and make links:
946 $comment = $this->formatAutoComments( $comment, $title, $local );
947 $comment = $this->formatLinksInComment( $comment, $title, $local );
948
949 wfProfileOut( __METHOD__ );
950 return $comment;
951 }
952
953 /**
954 * The pattern for autogen comments is / * foo * /, which makes for
955 * some nasty regex.
956 * We look for all comments, match any text before and after the comment,
957 * add a separator where needed and format the comment itself with CSS
958 * Called by Linker::formatComment.
959 *
960 * @param string $comment Comment text
961 * @param object $title An optional title object used to links to sections
962 * @return string $comment formatted comment
963 *
964 * @todo Document the $local parameter.
965 */
966 private function formatAutocomments( $comment, $title = null, $local = false ) {
967 // Bah!
968 $this->autocommentTitle = $title;
969 $this->autocommentLocal = $local;
970 $comment = preg_replace_callback(
971 '!(.*)/\*\s*(.*?)\s*\*/(.*)!',
972 array( $this, 'formatAutocommentsCallback' ),
973 $comment );
974 unset( $this->autocommentTitle );
975 unset( $this->autocommentLocal );
976 return $comment;
977 }
978
979 private function formatAutocommentsCallback( $match ) {
980 $title = $this->autocommentTitle;
981 $local = $this->autocommentLocal;
982
983 $pre=$match[1];
984 $auto=$match[2];
985 $post=$match[3];
986 $link='';
987 if( $title ) {
988 $section = $auto;
989
990 # Generate a valid anchor name from the section title.
991 # Hackish, but should generally work - we strip wiki
992 # syntax, including the magic [[: that is used to
993 # "link rather than show" in case of images and
994 # interlanguage links.
995 $section = str_replace( '[[:', '', $section );
996 $section = str_replace( '[[', '', $section );
997 $section = str_replace( ']]', '', $section );
998 if ( $local ) {
999 $sectionTitle = Title::newFromText( '#' . $section );
1000 } else {
1001 $sectionTitle = Title::makeTitleSafe( $title->getNamespace(),
1002 $title->getDBkey(), $section );
1003 }
1004 if ( $sectionTitle ) {
1005 $link = $this->link( $sectionTitle,
1006 htmlspecialchars( wfMsgForContent( 'sectionlink' ) ), array(), array(),
1007 'noclasses' );
1008 } else {
1009 $link = '';
1010 }
1011 }
1012 $auto = "$link$auto";
1013 if( $pre ) {
1014 # written summary $presep autocomment (summary /* section */)
1015 $auto = wfMsgExt( 'autocomment-prefix', array( 'escapenoentities', 'content' ) ) . $auto;
1016 }
1017 if( $post ) {
1018 # autocomment $postsep written summary (/* section */ summary)
1019 $auto .= wfMsgExt( 'colon-separator', array( 'escapenoentities', 'content' ) );
1020 }
1021 $auto = '<span class="autocomment">' . $auto . '</span>';
1022 $comment = $pre . $auto . $post;
1023 return $comment;
1024 }
1025
1026 /**
1027 * Formats wiki links and media links in text; all other wiki formatting
1028 * is ignored
1029 *
1030 * @todo Fixme: doesn't handle sub-links as in image thumb texts like the main parser
1031 * @param string $comment Text to format links in
1032 * @return string
1033 */
1034 public function formatLinksInComment( $comment, $title = null, $local = false ) {
1035 $this->commentContextTitle = $title;
1036 $this->commentLocal = $local;
1037 $html = preg_replace_callback(
1038 '/\[\[:?(.*?)(\|(.*?))*\]\]([^[]*)/',
1039 array( $this, 'formatLinksInCommentCallback' ),
1040 $comment );
1041 unset( $this->commentContextTitle );
1042 unset( $this->commentLocal );
1043 return $html;
1044 }
1045
1046 protected function formatLinksInCommentCallback( $match ) {
1047 global $wgContLang;
1048
1049 $medians = '(?:' . preg_quote( MWNamespace::getCanonicalName( NS_MEDIA ), '/' ) . '|';
1050 $medians .= preg_quote( $wgContLang->getNsText( NS_MEDIA ), '/' ) . '):';
1051
1052 $comment = $match[0];
1053
1054 # fix up urlencoded title texts (copied from Parser::replaceInternalLinks)
1055 if( strpos( $match[1], '%' ) !== false ) {
1056 $match[1] = str_replace( array('<', '>'), array('&lt;', '&gt;'), urldecode($match[1]) );
1057 }
1058
1059 # Handle link renaming [[foo|text]] will show link as "text"
1060 if( "" != $match[3] ) {
1061 $text = $match[3];
1062 } else {
1063 $text = $match[1];
1064 }
1065 $submatch = array();
1066 $thelink = null;
1067 if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
1068 # Media link; trail not supported.
1069 $linkRegexp = '/\[\[(.*?)\]\]/';
1070 $title = Title::makeTitleSafe( NS_FILE, $submatch[1] );
1071 $thelink = $this->makeMediaLinkObj( $title, $text );
1072 } else {
1073 # Other kind of link
1074 if( preg_match( $wgContLang->linkTrail(), $match[4], $submatch ) ) {
1075 $trail = $submatch[1];
1076 } else {
1077 $trail = "";
1078 }
1079 $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
1080 if (isset($match[1][0]) && $match[1][0] == ':')
1081 $match[1] = substr($match[1], 1);
1082 list( $inside, $trail ) = Linker::splitTrail( $trail );
1083
1084 $linkText = $text;
1085 $linkTarget = Linker::normalizeSubpageLink( $this->commentContextTitle,
1086 $match[1], $linkText );
1087
1088 $target = Title::newFromText( $linkTarget );
1089 if( $target ) {
1090 if( $target->getText() == '' && !$this->commentLocal && $this->commentContextTitle ) {
1091 $newTarget = clone( $this->commentContextTitle );
1092 $newTarget->setFragment( '#' . $target->getFragment() );
1093 $target = $newTarget;
1094 }
1095 $thelink = $this->link(
1096 $target,
1097 $linkText . $inside
1098 ) . $trail;
1099 }
1100 }
1101 if( $thelink ) {
1102 // If the link is still valid, go ahead and replace it in!
1103 $comment = preg_replace( $linkRegexp, StringUtils::escapeRegexReplacement( $thelink ), $comment, 1 );
1104 }
1105
1106 return $comment;
1107 }
1108
1109 static function normalizeSubpageLink( $contextTitle, $target, &$text ) {
1110 # Valid link forms:
1111 # Foobar -- normal
1112 # :Foobar -- override special treatment of prefix (images, language links)
1113 # /Foobar -- convert to CurrentPage/Foobar
1114 # /Foobar/ -- convert to CurrentPage/Foobar, strip the initial / from text
1115 # ../ -- convert to CurrentPage, from CurrentPage/CurrentSubPage
1116 # ../Foobar -- convert to CurrentPage/Foobar, from CurrentPage/CurrentSubPage
1117
1118 wfProfileIn( __METHOD__ );
1119 $ret = $target; # default return value is no change
1120
1121 # Some namespaces don't allow subpages,
1122 # so only perform processing if subpages are allowed
1123 if( $contextTitle && MWNamespace::hasSubpages( $contextTitle->getNamespace() ) ) {
1124 $hash = strpos( $target, '#' );
1125 if( $hash !== false ) {
1126 $suffix = substr( $target, $hash );
1127 $target = substr( $target, 0, $hash );
1128 } else {
1129 $suffix = '';
1130 }
1131 # bug 7425
1132 $target = trim( $target );
1133 # Look at the first character
1134 if( $target != '' && $target{0} === '/' ) {
1135 # / at end means we don't want the slash to be shown
1136 $m = array();
1137 $trailingSlashes = preg_match_all( '%(/+)$%', $target, $m );
1138 if( $trailingSlashes ) {
1139 $noslash = $target = substr( $target, 1, -strlen($m[0][0]) );
1140 } else {
1141 $noslash = substr( $target, 1 );
1142 }
1143
1144 $ret = $contextTitle->getPrefixedText(). '/' . trim($noslash) . $suffix;
1145 if( '' === $text ) {
1146 $text = $target . $suffix;
1147 } # this might be changed for ugliness reasons
1148 } else {
1149 # check for .. subpage backlinks
1150 $dotdotcount = 0;
1151 $nodotdot = $target;
1152 while( strncmp( $nodotdot, "../", 3 ) == 0 ) {
1153 ++$dotdotcount;
1154 $nodotdot = substr( $nodotdot, 3 );
1155 }
1156 if($dotdotcount > 0) {
1157 $exploded = explode( '/', $contextTitle->GetPrefixedText() );
1158 if( count( $exploded ) > $dotdotcount ) { # not allowed to go below top level page
1159 $ret = implode( '/', array_slice( $exploded, 0, -$dotdotcount ) );
1160 # / at the end means don't show full path
1161 if( substr( $nodotdot, -1, 1 ) === '/' ) {
1162 $nodotdot = substr( $nodotdot, 0, -1 );
1163 if( '' === $text ) {
1164 $text = $nodotdot . $suffix;
1165 }
1166 }
1167 $nodotdot = trim( $nodotdot );
1168 if( $nodotdot != '' ) {
1169 $ret .= '/' . $nodotdot;
1170 }
1171 $ret .= $suffix;
1172 }
1173 }
1174 }
1175 }
1176
1177 wfProfileOut( __METHOD__ );
1178 return $ret;
1179 }
1180
1181 /**
1182 * Wrap a comment in standard punctuation and formatting if
1183 * it's non-empty, otherwise return empty string.
1184 *
1185 * @param string $comment
1186 * @param mixed $title Title object (to generate link to section in autocomment) or null
1187 * @param bool $local Whether section links should refer to local page
1188 *
1189 * @return string
1190 */
1191 function commentBlock( $comment, $title = null, $local = false ) {
1192 // '*' used to be the comment inserted by the software way back
1193 // in antiquity in case none was provided, here for backwards
1194 // compatability, acc. to brion -ævar
1195 if( $comment == '' || $comment == '*' ) {
1196 return '';
1197 } else {
1198 $formatted = $this->formatComment( $comment, $title, $local );
1199 return " <span class=\"comment\">($formatted)</span>";
1200 }
1201 }
1202
1203 /**
1204 * Wrap and format the given revision's comment block, if the current
1205 * user is allowed to view it.
1206 *
1207 * @param Revision $rev
1208 * @param bool $local Whether section links should refer to local page
1209 * @param $isPublic, show only if all users can see it
1210 * @return string HTML
1211 */
1212 function revComment( Revision $rev, $local = false, $isPublic = false ) {
1213 if( $rev->getRawComment() == "" ) return "";
1214 if( $rev->isDeleted( Revision::DELETED_COMMENT ) && $isPublic ) {
1215 $block = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
1216 } else if( $rev->userCan( Revision::DELETED_COMMENT ) ) {
1217 $block = $this->commentBlock( $rev->getComment( Revision::FOR_THIS_USER ),
1218 $rev->getTitle(), $local );
1219 } else {
1220 $block = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
1221 }
1222 if( $rev->isDeleted( Revision::DELETED_COMMENT ) ) {
1223 return " <span class=\"history-deleted\">$block</span>";
1224 }
1225 return $block;
1226 }
1227
1228 public function formatRevisionSize( $size ) {
1229 if ( $size == 0 ) {
1230 $stxt = wfMsgExt( 'historyempty', 'parsemag' );
1231 } else {
1232 global $wgLang;
1233 $stxt = wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $size ) );
1234 $stxt = "($stxt)";
1235 }
1236 $stxt = htmlspecialchars( $stxt );
1237 return "<span class=\"history-size\">$stxt</span>";
1238 }
1239
1240 /**
1241 * Add another level to the Table of Contents
1242 */
1243 function tocIndent() {
1244 return "\n<ul>";
1245 }
1246
1247 /**
1248 * Finish one or more sublevels on the Table of Contents
1249 */
1250 function tocUnindent($level) {
1251 return "</li>\n" . str_repeat( "</ul>\n</li>\n", $level>0 ? $level : 0 );
1252 }
1253
1254 /**
1255 * parameter level defines if we are on an indentation level
1256 */
1257 function tocLine( $anchor, $tocline, $tocnumber, $level, $sectionIndex = false ) {
1258 $classes = "toclevel-$level";
1259 if ( $sectionIndex !== false )
1260 $classes .= " tocsection-$sectionIndex";
1261 return "\n<li class=\"$classes\"><a href=\"#" .
1262 $anchor . '"><span class="tocnumber">' .
1263 $tocnumber . '</span> <span class="toctext">' .
1264 $tocline . '</span></a>';
1265 }
1266
1267 /**
1268 * End a Table Of Contents line.
1269 * tocUnindent() will be used instead if we're ending a line below
1270 * the new level.
1271 */
1272 function tocLineEnd() {
1273 return "</li>\n";
1274 }
1275
1276 /**
1277 * Wraps the TOC in a table and provides the hide/collapse javascript.
1278 * @param string $toc html of the Table Of Contents
1279 * @return string Full html of the TOC
1280 */
1281 function tocList($toc) {
1282 $title = wfMsgHtml('toc') ;
1283 return
1284 '<table id="toc" class="toc"><tr><td>'
1285 . '<div id="toctitle"><h2>' . $title . "</h2></div>\n"
1286 . $toc
1287 # no trailing newline, script should not be wrapped in a
1288 # paragraph
1289 . "</ul>\n</td></tr></table>"
1290 . Html::inlineScript(
1291 'if (window.showTocToggle) {'
1292 . ' var tocShowText = "' . Xml::escapeJsString( wfMsg('showtoc') ) . '";'
1293 . ' var tocHideText = "' . Xml::escapeJsString( wfMsg('hidetoc') ) . '";'
1294 . ' showTocToggle();'
1295 . ' } ' )
1296 . "\n";
1297 }
1298
1299 /**
1300 * Generate a table of contents from a section tree
1301 * Currently unused.
1302 * @param $tree Return value of ParserOutput::getSections()
1303 * @return string HTML
1304 */
1305 public function generateTOC( $tree ) {
1306 $toc = '';
1307 $lastLevel = 0;
1308 foreach ( $tree as $section ) {
1309 if ( $section['toclevel'] > $lastLevel )
1310 $toc .= $this->tocIndent();
1311 else if ( $section['toclevel'] < $lastLevel )
1312 $toc .= $this->tocUnindent(
1313 $lastLevel - $section['toclevel'] );
1314 else
1315 $toc .= $this->tocLineEnd();
1316
1317 $toc .= $this->tocLine( $section['anchor'],
1318 $section['line'], $section['number'],
1319 $section['toclevel'], $section['index'] );
1320 $lastLevel = $section['toclevel'];
1321 }
1322 $toc .= $this->tocLineEnd();
1323 return $this->tocList( $toc );
1324 }
1325
1326 /**
1327 * Create a section edit link. This supersedes editSectionLink() and
1328 * editSectionLinkForOther().
1329 *
1330 * @param $nt Title The title being linked to (may not be the same as
1331 * $wgTitle, if the section is included from a template)
1332 * @param $section string The designation of the section being pointed to,
1333 * to be included in the link, like "&section=$section"
1334 * @param $tooltip string The tooltip to use for the link: will be escaped
1335 * and wrapped in the 'editsectionhint' message
1336 * @return string HTML to use for edit link
1337 */
1338 public function doEditSectionLink( Title $nt, $section, $tooltip = null ) {
1339 $attribs = array();
1340 if( !is_null( $tooltip ) ) {
1341 $attribs['title'] = wfMsg( 'editsectionhint', $tooltip );
1342 }
1343 $link = $this->link( $nt, wfMsg('editsection'),
1344 $attribs,
1345 array( 'action' => 'edit', 'section' => $section ),
1346 array( 'noclasses', 'known' )
1347 );
1348
1349 # Run the old hook. This takes up half of the function . . . hopefully
1350 # we can rid of it someday.
1351 $attribs = '';
1352 if( $tooltip ) {
1353 $attribs = wfMsgHtml( 'editsectionhint', htmlspecialchars( $tooltip ) );
1354 $attribs = " title=\"$attribs\"";
1355 }
1356 $result = null;
1357 wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $attribs, $link, &$result ) );
1358 if( !is_null( $result ) ) {
1359 # For reverse compatibility, add the brackets *after* the hook is
1360 # run, and even add them to hook-provided text. (This is the main
1361 # reason that the EditSectionLink hook is deprecated in favor of
1362 # DoEditSectionLink: it can't change the brackets or the span.)
1363 $result = wfMsgHtml( 'editsection-brackets', $result );
1364 return "<span class=\"editsection\">$result</span>";
1365 }
1366
1367 # Add the brackets and the span, and *then* run the nice new hook, with
1368 # clean and non-redundant arguments.
1369 $result = wfMsgHtml( 'editsection-brackets', $link );
1370 $result = "<span class=\"editsection\">$result</span>";
1371
1372 wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result ) );
1373 return $result;
1374 }
1375
1376 /**
1377 * Create a headline for content
1378 *
1379 * @param int $level The level of the headline (1-6)
1380 * @param string $attribs Any attributes for the headline, starting with a space and ending with '>'
1381 * This *must* be at least '>' for no attribs
1382 * @param string $anchor The anchor to give the headline (the bit after the #)
1383 * @param string $text The text of the header
1384 * @param string $link HTML to add for the section edit link
1385 * @param mixed $legacyAnchor A second, optional anchor to give for
1386 * backward compatibility (false to omit)
1387 *
1388 * @return string HTML headline
1389 */
1390 public function makeHeadline( $level, $attribs, $anchor, $text, $link, $legacyAnchor = false ) {
1391 $ret = "<h$level$attribs"
1392 . $link
1393 . " <span class=\"mw-headline\" id=\"$anchor\">$text</span>"
1394 . "</h$level>";
1395 if ( $legacyAnchor !== false ) {
1396 $ret = "<a id=\"$legacyAnchor\"></a>$ret";
1397 }
1398 return $ret;
1399 }
1400
1401 /**
1402 * Split a link trail, return the "inside" portion and the remainder of the trail
1403 * as a two-element array
1404 *
1405 * @static
1406 */
1407 static function splitTrail( $trail ) {
1408 static $regex = false;
1409 if ( $regex === false ) {
1410 global $wgContLang;
1411 $regex = $wgContLang->linkTrail();
1412 }
1413 $inside = '';
1414 if ( '' != $trail ) {
1415 $m = array();
1416 if ( preg_match( $regex, $trail, $m ) ) {
1417 $inside = $m[1];
1418 $trail = $m[2];
1419 }
1420 }
1421 return array( $inside, $trail );
1422 }
1423
1424 /**
1425 * Generate a rollback link for a given revision. Currently it's the
1426 * caller's responsibility to ensure that the revision is the top one. If
1427 * it's not, of course, the user will get an error message.
1428 *
1429 * If the calling page is called with the parameter &bot=1, all rollback
1430 * links also get that parameter. It causes the edit itself and the rollback
1431 * to be marked as "bot" edits. Bot edits are hidden by default from recent
1432 * changes, so this allows sysops to combat a busy vandal without bothering
1433 * other users.
1434 *
1435 * @param Revision $rev
1436 */
1437 function generateRollback( $rev ) {
1438 return '<span class="mw-rollback-link">['
1439 . $this->buildRollbackLink( $rev )
1440 . ']</span>';
1441 }
1442
1443 /**
1444 * Build a raw rollback link, useful for collections of "tool" links
1445 *
1446 * @param Revision $rev
1447 * @return string
1448 */
1449 public function buildRollbackLink( $rev ) {
1450 global $wgRequest, $wgUser;
1451 $title = $rev->getTitle();
1452 $query = array(
1453 'action' => 'rollback',
1454 'from' => $rev->getUserText()
1455 );
1456 if( $wgRequest->getBool( 'bot' ) ) {
1457 $query['bot'] = '1';
1458 $query['hidediff'] = '1'; // bug 15999
1459 }
1460 $query['token'] = $wgUser->editToken( array( $title->getPrefixedText(),
1461 $rev->getUserText() ) );
1462 return $this->link( $title, wfMsgHtml( 'rollbacklink' ),
1463 array( 'title' => wfMsg( 'tooltip-rollback' ) ),
1464 $query, array( 'known', 'noclasses' ) );
1465 }
1466
1467 /**
1468 * Returns HTML for the "templates used on this page" list.
1469 *
1470 * @param array $templates Array of templates from Article::getUsedTemplate
1471 * or similar
1472 * @param bool $preview Whether this is for a preview
1473 * @param bool $section Whether this is for a section edit
1474 * @return string HTML output
1475 */
1476 public function formatTemplates( $templates, $preview = false, $section = false ) {
1477 wfProfileIn( __METHOD__ );
1478
1479 $outText = '';
1480 if ( count( $templates ) > 0 ) {
1481 # Do a batch existence check
1482 $batch = new LinkBatch;
1483 foreach( $templates as $title ) {
1484 $batch->addObj( $title );
1485 }
1486 $batch->execute();
1487
1488 # Construct the HTML
1489 $outText = '<div class="mw-templatesUsedExplanation">';
1490 if ( $preview ) {
1491 $outText .= wfMsgExt( 'templatesusedpreview', array( 'parse' ), count( $templates ) );
1492 } elseif ( $section ) {
1493 $outText .= wfMsgExt( 'templatesusedsection', array( 'parse' ), count( $templates ) );
1494 } else {
1495 $outText .= wfMsgExt( 'templatesused', array( 'parse' ), count( $templates ) );
1496 }
1497 $outText .= "</div><ul>\n";
1498
1499 usort( $templates, array( 'Title', 'compare' ) );
1500 foreach ( $templates as $titleObj ) {
1501 $r = $titleObj->getRestrictions( 'edit' );
1502 if ( in_array( 'sysop', $r ) ) {
1503 $protected = wfMsgExt( 'template-protected', array( 'parseinline' ) );
1504 } elseif ( in_array( 'autoconfirmed', $r ) ) {
1505 $protected = wfMsgExt( 'template-semiprotected', array( 'parseinline' ) );
1506 } else {
1507 $protected = '';
1508 }
1509 if( $titleObj->quickUserCan( 'edit' ) ) {
1510 $editLink = $this->link(
1511 $titleObj,
1512 wfMsg( 'editlink' ),
1513 array(),
1514 array( 'action' => 'edit' )
1515 );
1516 } else {
1517 $editLink = $this->link(
1518 $titleObj,
1519 wfMsg( 'viewsourcelink' ),
1520 array(),
1521 array( 'action' => 'edit' )
1522 );
1523 }
1524 $outText .= '<li>' . $this->link( $titleObj ) . ' (' . $editLink . ') ' . $protected . '</li>';
1525 }
1526 $outText .= '</ul>';
1527 }
1528 wfProfileOut( __METHOD__ );
1529 return $outText;
1530 }
1531
1532 /**
1533 * Returns HTML for the "hidden categories on this page" list.
1534 *
1535 * @param array $hiddencats Array of hidden categories from Article::getHiddenCategories
1536 * or similar
1537 * @return string HTML output
1538 */
1539 public function formatHiddenCategories( $hiddencats ) {
1540 global $wgLang;
1541 wfProfileIn( __METHOD__ );
1542
1543 $outText = '';
1544 if ( count( $hiddencats ) > 0 ) {
1545 # Construct the HTML
1546 $outText = '<div class="mw-hiddenCategoriesExplanation">';
1547 $outText .= wfMsgExt( 'hiddencategories', array( 'parse' ), $wgLang->formatnum( count( $hiddencats ) ) );
1548 $outText .= "</div><ul>\n";
1549
1550 foreach ( $hiddencats as $titleObj ) {
1551 $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
1552 }
1553 $outText .= '</ul>';
1554 }
1555 wfProfileOut( __METHOD__ );
1556 return $outText;
1557 }
1558
1559 /**
1560 * Format a size in bytes for output, using an appropriate
1561 * unit (B, KB, MB or GB) according to the magnitude in question
1562 *
1563 * @param $size Size to format
1564 * @return string
1565 */
1566 public function formatSize( $size ) {
1567 global $wgLang;
1568 return htmlspecialchars( $wgLang->formatSize( $size ) );
1569 }
1570
1571 /**
1572 * Given the id of an interface element, constructs the appropriate title
1573 * attribute from the system messages. (Note, this is usually the id but
1574 * isn't always, because sometimes the accesskey needs to go on a different
1575 * element than the id, for reverse-compatibility, etc.)
1576 *
1577 * @param string $name Id of the element, minus prefixes.
1578 * @param mixed $options null or the string 'withaccess' to add an access-
1579 * key hint
1580 * @return string Contents of the title attribute (which you must HTML-
1581 * escape), or false for no title attribute
1582 */
1583 public function titleAttrib( $name, $options = null ) {
1584 wfProfileIn( __METHOD__ );
1585
1586 $tooltip = wfMsg( "tooltip-$name" );
1587 # Compatibility: formerly some tooltips had [alt-.] hardcoded
1588 $tooltip = preg_replace( "/ ?\[alt-.\]$/", '', $tooltip );
1589
1590 # Message equal to '-' means suppress it.
1591 if ( wfEmptyMsg( "tooltip-$name", $tooltip ) || $tooltip == '-' ) {
1592 $tooltip = false;
1593 }
1594
1595 if ( $options == 'withaccess' ) {
1596 $accesskey = $this->accesskey( $name );
1597 if( $accesskey !== false ) {
1598 if ( $tooltip === false || $tooltip === '' ) {
1599 $tooltip = "[$accesskey]";
1600 } else {
1601 $tooltip .= " [$accesskey]";
1602 }
1603 }
1604 }
1605
1606 wfProfileOut( __METHOD__ );
1607 return $tooltip;
1608 }
1609
1610 /**
1611 * Given the id of an interface element, constructs the appropriate
1612 * accesskey attribute from the system messages. (Note, this is usually
1613 * the id but isn't always, because sometimes the accesskey needs to go on
1614 * a different element than the id, for reverse-compatibility, etc.)
1615 *
1616 * @param string $name Id of the element, minus prefixes.
1617 * @return string Contents of the accesskey attribute (which you must HTML-
1618 * escape), or false for no accesskey attribute
1619 */
1620 public function accesskey( $name ) {
1621 wfProfileIn( __METHOD__ );
1622
1623 $accesskey = wfMsg( "accesskey-$name" );
1624
1625 # FIXME: Per standard MW behavior, a value of '-' means to suppress the
1626 # attribute, but this is broken for accesskey: that might be a useful
1627 # value.
1628 if( $accesskey != '' && $accesskey != '-' && !wfEmptyMsg( "accesskey-$name", $accesskey ) ) {
1629 wfProfileOut( __METHOD__ );
1630 return $accesskey;
1631 }
1632
1633 wfProfileOut( __METHOD__ );
1634 return false;
1635 }
1636
1637 /**
1638 * Creates a (show/hide) link for deleting revisions/log entries
1639 *
1640 * @param array $query Query parameters to be passed to link()
1641 * @param bool $restricted Set to true to use a <strong> instead of a <span>
1642 * @param bool $delete Set to true to use (show/hide) rather than (show)
1643 *
1644 * @return string HTML <a> link to Special:Revisiondelete, wrapped in a
1645 * span to allow for customization of appearance with CSS
1646 */
1647 public function revDeleteLink( $query = array(), $restricted = false, $delete = true ) {
1648 $sp = SpecialPage::getTitleFor( 'Revisiondelete' );
1649 $text = $delete ? wfMsgHtml( 'rev-delundel' ) : wfMsgHtml( 'rev-showdeleted' );
1650 $tag = $restricted ? 'strong' : 'span';
1651 $link = $this->link( $sp, $text, array(), $query, array( 'known', 'noclasses' ) );
1652 return Xml::tags( $tag, array( 'class' => 'mw-revdelundel-link' ), "($link)" );
1653 }
1654
1655 /**
1656 * Creates a dead (show/hide) link for deleting revisions/log entries
1657 *
1658 * @param bool $delete Set to true to use (show/hide) rather than (show)
1659 *
1660 * @return string HTML text wrapped in a span to allow for customization
1661 * of appearance with CSS
1662 */
1663 public function revDeleteLinkDisabled( $delete = true ) {
1664 $text = $delete ? wfMsgHtml( 'rev-delundel' ) : wfMsgHtml( 'rev-showdeleted' );
1665 return Xml::tags( 'span', array( 'class' => 'mw-revdelundel-link' ), "($text)" );
1666 }
1667
1668 /* Deprecated methods */
1669
1670 /**
1671 * @deprecated
1672 */
1673 function postParseLinkColour( $s = null ) {
1674 wfDeprecated( __METHOD__ );
1675 return null;
1676 }
1677
1678
1679 /**
1680 * @deprecated Use link()
1681 *
1682 * This function is a shortcut to makeLinkObj(Title::newFromText($title),...). Do not call
1683 * it if you already have a title object handy. See makeLinkObj for further documentation.
1684 *
1685 * @param $title String: the text of the title
1686 * @param $text String: link text
1687 * @param $query String: optional query part
1688 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
1689 * be included in the link text. Other characters will be appended after
1690 * the end of the link.
1691 */
1692 function makeLink( $title, $text = '', $query = '', $trail = '' ) {
1693 wfProfileIn( __METHOD__ );
1694 $nt = Title::newFromText( $title );
1695 if ( $nt instanceof Title ) {
1696 $result = $this->makeLinkObj( $nt, $text, $query, $trail );
1697 } else {
1698 wfDebug( 'Invalid title passed to Linker::makeLink(): "'.$title."\"\n" );
1699 $result = $text == "" ? $title : $text;
1700 }
1701
1702 wfProfileOut( __METHOD__ );
1703 return $result;
1704 }
1705
1706 /**
1707 * @deprecated Use link()
1708 *
1709 * This function is a shortcut to makeKnownLinkObj(Title::newFromText($title),...). Do not call
1710 * it if you already have a title object handy. See makeKnownLinkObj for further documentation.
1711 *
1712 * @param $title String: the text of the title
1713 * @param $text String: link text
1714 * @param $query String: optional query part
1715 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
1716 * be included in the link text. Other characters will be appended after
1717 * the end of the link.
1718 */
1719 function makeKnownLink( $title, $text = '', $query = '', $trail = '', $prefix = '',$aprops = '') {
1720 $nt = Title::newFromText( $title );
1721 if ( $nt instanceof Title ) {
1722 return $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix , $aprops );
1723 } else {
1724 wfDebug( 'Invalid title passed to Linker::makeKnownLink(): "'.$title."\"\n" );
1725 return $text == '' ? $title : $text;
1726 }
1727 }
1728
1729 /**
1730 * @deprecated Use link()
1731 *
1732 * This function is a shortcut to makeBrokenLinkObj(Title::newFromText($title),...). Do not call
1733 * it if you already have a title object handy. See makeBrokenLinkObj for further documentation.
1734 *
1735 * @param string $title The text of the title
1736 * @param string $text Link text
1737 * @param string $query Optional query part
1738 * @param string $trail Optional trail. Alphabetic characters at the start of this string will
1739 * be included in the link text. Other characters will be appended after
1740 * the end of the link.
1741 */
1742 function makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) {
1743 $nt = Title::newFromText( $title );
1744 if ( $nt instanceof Title ) {
1745 return $this->makeBrokenLinkObj( $nt, $text, $query, $trail );
1746 } else {
1747 wfDebug( 'Invalid title passed to Linker::makeBrokenLink(): "'.$title."\"\n" );
1748 return $text == '' ? $title : $text;
1749 }
1750 }
1751
1752 /**
1753 * @deprecated Use link()
1754 *
1755 * This function is a shortcut to makeStubLinkObj(Title::newFromText($title),...). Do not call
1756 * it if you already have a title object handy. See makeStubLinkObj for further documentation.
1757 *
1758 * @param $title String: the text of the title
1759 * @param $text String: link text
1760 * @param $query String: optional query part
1761 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
1762 * be included in the link text. Other characters will be appended after
1763 * the end of the link.
1764 */
1765 function makeStubLink( $title, $text = '', $query = '', $trail = '' ) {
1766 wfDeprecated( __METHOD__ );
1767 $nt = Title::newFromText( $title );
1768 if ( $nt instanceof Title ) {
1769 return $this->makeStubLinkObj( $nt, $text, $query, $trail );
1770 } else {
1771 wfDebug( 'Invalid title passed to Linker::makeStubLink(): "'.$title."\"\n" );
1772 return $text == '' ? $title : $text;
1773 }
1774 }
1775
1776 /**
1777 * @deprecated Use link()
1778 *
1779 * Make a link for a title which may or may not be in the database. If you need to
1780 * call this lots of times, pre-fill the link cache with a LinkBatch, otherwise each
1781 * call to this will result in a DB query.
1782 *
1783 * @param $nt Title: the title object to make the link from, e.g. from
1784 * Title::newFromText.
1785 * @param $text String: link text
1786 * @param $query String: optional query part
1787 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
1788 * be included in the link text. Other characters will be appended after
1789 * the end of the link.
1790 * @param $prefix String: optional prefix. As trail, only before instead of after.
1791 */
1792 function makeLinkObj( $nt, $text= '', $query = '', $trail = '', $prefix = '' ) {
1793 wfProfileIn( __METHOD__ );
1794
1795 $query = wfCgiToArray( $query );
1796 list( $inside, $trail ) = Linker::splitTrail( $trail );
1797 if( $text === '' ) {
1798 $text = $this->linkText( $nt );
1799 }
1800
1801 $ret = $this->link( $nt, "$prefix$text$inside", array(), $query ) . $trail;
1802
1803 wfProfileOut( __METHOD__ );
1804 return $ret;
1805 }
1806
1807 /**
1808 * @deprecated Use link()
1809 *
1810 * Make a link for a title which definitely exists. This is faster than makeLinkObj because
1811 * it doesn't have to do a database query. It's also valid for interwiki titles and special
1812 * pages.
1813 *
1814 * @param $nt Title object of target page
1815 * @param $text String: text to replace the title
1816 * @param $query String: link target
1817 * @param $trail String: text after link
1818 * @param $prefix String: text before link text
1819 * @param $aprops String: extra attributes to the a-element
1820 * @param $style String: style to apply - if empty, use getInternalLinkAttributesObj instead
1821 * @return the a-element
1822 */
1823 function makeKnownLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '', $style = '' ) {
1824 wfProfileIn( __METHOD__ );
1825
1826 if ( $text == '' ) {
1827 $text = $this->linkText( $title );
1828 }
1829 $attribs = Sanitizer::mergeAttributes(
1830 Sanitizer::decodeTagAttributes( $aprops ),
1831 Sanitizer::decodeTagAttributes( $style )
1832 );
1833 $query = wfCgiToArray( $query );
1834 list( $inside, $trail ) = Linker::splitTrail( $trail );
1835
1836 $ret = $this->link( $title, "$prefix$text$inside", $attribs, $query,
1837 array( 'known', 'noclasses' ) ) . $trail;
1838
1839 wfProfileOut( __METHOD__ );
1840 return $ret;
1841 }
1842
1843 /**
1844 * @deprecated Use link()
1845 *
1846 * Make a red link to the edit page of a given title.
1847 *
1848 * @param $nt Title object of the target page
1849 * @param $text String: Link text
1850 * @param $query String: Optional query part
1851 * @param $trail String: Optional trail. Alphabetic characters at the start of this string will
1852 * be included in the link text. Other characters will be appended after
1853 * the end of the link.
1854 */
1855 function makeBrokenLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' ) {
1856 wfProfileIn( __METHOD__ );
1857
1858 list( $inside, $trail ) = Linker::splitTrail( $trail );
1859 if( $text === '' ) {
1860 $text = $this->linkText( $title );
1861 }
1862 $nt = $this->normaliseSpecialPage( $title );
1863
1864 $ret = $this->link( $title, "$prefix$text$inside", array(),
1865 wfCgiToArray( $query ), 'broken' ) . $trail;
1866
1867 wfProfileOut( __METHOD__ );
1868 return $ret;
1869 }
1870
1871 /**
1872 * @deprecated Use link()
1873 *
1874 * Make a brown link to a short article.
1875 *
1876 * @param $nt Title object of the target page
1877 * @param $text String: link text
1878 * @param $query String: optional query part
1879 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
1880 * be included in the link text. Other characters will be appended after
1881 * the end of the link.
1882 */
1883 function makeStubLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
1884 wfDeprecated( __METHOD__ );
1885 return $this->makeColouredLinkObj( $nt, 'stub', $text, $query, $trail, $prefix );
1886 }
1887
1888 /**
1889 * @deprecated Use link()
1890 *
1891 * Make a coloured link.
1892 *
1893 * @param $nt Title object of the target page
1894 * @param $colour Integer: colour of the link
1895 * @param $text String: link text
1896 * @param $query String: optional query part
1897 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
1898 * be included in the link text. Other characters will be appended after
1899 * the end of the link.
1900 */
1901 function makeColouredLinkObj( $nt, $colour, $text = '', $query = '', $trail = '', $prefix = '' ) {
1902 if($colour != ''){
1903 $style = $this->getInternalLinkAttributesObj( $nt, $text, $colour );
1904 } else $style = '';
1905 return $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix, '', $style );
1906 }
1907
1908 /** Obsolete alias */
1909 function makeImage( $url, $alt = '' ) {
1910 wfDeprecated( __METHOD__ );
1911 return $this->makeExternalImage( $url, $alt );
1912 }
1913
1914 /**
1915 * Creates the HTML source for images
1916 * @deprecated use makeImageLink2
1917 *
1918 * @param object $title
1919 * @param string $label label text
1920 * @param string $alt alt text
1921 * @param string $align horizontal alignment: none, left, center, right)
1922 * @param array $handlerParams Parameters to be passed to the media handler
1923 * @param boolean $framed shows image in original size in a frame
1924 * @param boolean $thumb shows image as thumbnail in a frame
1925 * @param string $manualthumb image name for the manual thumbnail
1926 * @param string $valign vertical alignment: baseline, sub, super, top, text-top, middle, bottom, text-bottom
1927 * @param string $time, timestamp of the file, set as false for current
1928 * @return string
1929 */
1930 function makeImageLinkObj( $title, $label, $alt, $align = '', $handlerParams = array(), $framed = false,
1931 $thumb = false, $manualthumb = '', $valign = '', $time = false )
1932 {
1933 $frameParams = array( 'alt' => $alt, 'caption' => $label );
1934 if ( $align ) {
1935 $frameParams['align'] = $align;
1936 }
1937 if ( $framed ) {
1938 $frameParams['framed'] = true;
1939 }
1940 if ( $thumb ) {
1941 $frameParams['thumbnail'] = true;
1942 }
1943 if ( $manualthumb ) {
1944 $frameParams['manualthumb'] = $manualthumb;
1945 }
1946 if ( $valign ) {
1947 $frameParams['valign'] = $valign;
1948 }
1949 $file = wfFindFile( $title, array( 'time' => $time ) );
1950 return $this->makeImageLink2( $title, $file, $frameParams, $handlerParams, $time );
1951 }
1952
1953 /** @deprecated use Linker::makeMediaLinkObj() */
1954 function makeMediaLink( $name, $unused = '', $text = '', $time = false ) {
1955 $nt = Title::makeTitleSafe( NS_FILE, $name );
1956 return $this->makeMediaLinkObj( $nt, $text, $time );
1957 }
1958
1959 /**
1960 * Used to generate section edit links that point to "other" pages
1961 * (sections that are really part of included pages).
1962 *
1963 * @deprecated use Linker::doEditSectionLink()
1964 * @param $title Title string.
1965 * @param $section Integer: section number.
1966 */
1967 public function editSectionLinkForOther( $title, $section ) {
1968 wfDeprecated( __METHOD__ );
1969 $title = Title::newFromText( $title );
1970 return $this->doEditSectionLink( $title, $section );
1971 }
1972
1973 /**
1974 * @deprecated use Linker::doEditSectionLink()
1975 * @param $nt Title object.
1976 * @param $section Integer: section number.
1977 * @param $hint Link String: title, or default if omitted or empty
1978 */
1979 public function editSectionLink( Title $nt, $section, $hint = '' ) {
1980 wfDeprecated( __METHOD__ );
1981 if( $hint === '' ) {
1982 # No way to pass an actual empty $hint here! The new interface al-
1983 # lows this, so we have to do this for compatibility.
1984 $hint = null;
1985 }
1986 return $this->doEditSectionLink( $nt, $section, $hint );
1987 }
1988
1989 /**
1990 * Returns the attributes for the tooltip and access key
1991 */
1992 public function tooltipAndAccesskeyAttribs( $name ) {
1993 global $wgEnableTooltipsAndAccesskeys;
1994 if ( !$wgEnableTooltipsAndAccesskeys )
1995 return '';
1996 # FIXME: If Sanitizer::expandAttributes() treated "false" as "output
1997 # no attribute" instead of "output '' as value for attribute", this
1998 # would be three lines.
1999 $attribs = array(
2000 'title' => $this->titleAttrib( $name, 'withaccess' ),
2001 'accesskey' => $this->accesskey( $name )
2002 );
2003 if ( $attribs['title'] === false ) {
2004 unset( $attribs['title'] );
2005 }
2006 if ( $attribs['accesskey'] === false ) {
2007 unset( $attribs['accesskey'] );
2008 }
2009 return $attribs;
2010 }
2011 /**
2012 * @deprecated Returns raw bits of HTML, use titleAttrib() and accesskey()
2013 */
2014 public function tooltipAndAccesskey( $name ) {
2015 return Xml::expandAttributes( $this->tooltipAndAccesskeyAttribs( $name ) );
2016 }
2017
2018
2019 /** @deprecated Returns raw bits of HTML, use titleAttrib() */
2020 public function tooltip( $name, $options = null ) {
2021 global $wgEnableTooltipsAndAccesskeys;
2022 if ( !$wgEnableTooltipsAndAccesskeys )
2023 return '';
2024 # FIXME: If Sanitizer::expandAttributes() treated "false" as "output
2025 # no attribute" instead of "output '' as value for attribute", this
2026 # would be two lines.
2027 $tooltip = $this->titleAttrib( $name, $options );
2028 if ( $tooltip === false ) {
2029 return '';
2030 }
2031 return Xml::expandAttributes( array(
2032 'title' => $this->titleAttrib( $name, $options )
2033 ) );
2034 }
2035 }