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