(bug 15745) Make the edit summary link parser detect links more like the real parser...
[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 if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
1057 # Media link; trail not supported.
1058 $linkRegexp = '/^(.*?)\]\]/';
1059 $title = Title::makeTitleSafe( NS_FILE, $submatch[1] );
1060 $thelink = $this->makeMediaLinkObj( $title, $text );
1061 } else {
1062 # Other kind of link
1063 if( preg_match( $wgContLang->linkTrail(), $match[4], $submatch ) ) {
1064 $trail = $submatch[1];
1065 } else {
1066 $trail = "";
1067 }
1068 $linkRegexp = '/^(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
1069 if (isset($match[1][0]) && $match[1][0] == ':')
1070 $match[1] = substr($match[1], 1);
1071 list( $inside, $trail ) = Linker::splitTrail( $trail );
1072
1073 $linkText = $text;
1074 $linkTarget = Linker::normalizeSubpageLink( $this->commentContextTitle,
1075 $match[1], $linkText );
1076
1077 $target = Title::newFromText( $linkTarget );
1078 if( $target ) {
1079 if( $target->getText() == '' && !$this->commentLocal && $this->commentContextTitle ) {
1080 $newTarget = clone( $this->commentContextTitle );
1081 $newTarget->setFragment( '#' . $target->getFragment() );
1082 $target = $newTarget;
1083 }
1084 $thelink = $this->link(
1085 $target,
1086 $linkText . $inside
1087 ) . $trail;
1088 }
1089 }
1090 $comment = preg_replace( $linkRegexp, StringUtils::escapeRegexReplacement( $thelink ), $comment, 1 );
1091
1092 return $comment;
1093 }
1094
1095 static function normalizeSubpageLink( $contextTitle, $target, &$text ) {
1096 # Valid link forms:
1097 # Foobar -- normal
1098 # :Foobar -- override special treatment of prefix (images, language links)
1099 # /Foobar -- convert to CurrentPage/Foobar
1100 # /Foobar/ -- convert to CurrentPage/Foobar, strip the initial / from text
1101 # ../ -- convert to CurrentPage, from CurrentPage/CurrentSubPage
1102 # ../Foobar -- convert to CurrentPage/Foobar, from CurrentPage/CurrentSubPage
1103
1104 wfProfileIn( __METHOD__ );
1105 $ret = $target; # default return value is no change
1106
1107 # Some namespaces don't allow subpages,
1108 # so only perform processing if subpages are allowed
1109 if( $contextTitle && MWNamespace::hasSubpages( $contextTitle->getNamespace() ) ) {
1110 $hash = strpos( $target, '#' );
1111 if( $hash !== false ) {
1112 $suffix = substr( $target, $hash );
1113 $target = substr( $target, 0, $hash );
1114 } else {
1115 $suffix = '';
1116 }
1117 # bug 7425
1118 $target = trim( $target );
1119 # Look at the first character
1120 if( $target != '' && $target{0} === '/' ) {
1121 # / at end means we don't want the slash to be shown
1122 $m = array();
1123 $trailingSlashes = preg_match_all( '%(/+)$%', $target, $m );
1124 if( $trailingSlashes ) {
1125 $noslash = $target = substr( $target, 1, -strlen($m[0][0]) );
1126 } else {
1127 $noslash = substr( $target, 1 );
1128 }
1129
1130 $ret = $contextTitle->getPrefixedText(). '/' . trim($noslash) . $suffix;
1131 if( '' === $text ) {
1132 $text = $target . $suffix;
1133 } # this might be changed for ugliness reasons
1134 } else {
1135 # check for .. subpage backlinks
1136 $dotdotcount = 0;
1137 $nodotdot = $target;
1138 while( strncmp( $nodotdot, "../", 3 ) == 0 ) {
1139 ++$dotdotcount;
1140 $nodotdot = substr( $nodotdot, 3 );
1141 }
1142 if($dotdotcount > 0) {
1143 $exploded = explode( '/', $contextTitle->GetPrefixedText() );
1144 if( count( $exploded ) > $dotdotcount ) { # not allowed to go below top level page
1145 $ret = implode( '/', array_slice( $exploded, 0, -$dotdotcount ) );
1146 # / at the end means don't show full path
1147 if( substr( $nodotdot, -1, 1 ) === '/' ) {
1148 $nodotdot = substr( $nodotdot, 0, -1 );
1149 if( '' === $text ) {
1150 $text = $nodotdot . $suffix;
1151 }
1152 }
1153 $nodotdot = trim( $nodotdot );
1154 if( $nodotdot != '' ) {
1155 $ret .= '/' . $nodotdot;
1156 }
1157 $ret .= $suffix;
1158 }
1159 }
1160 }
1161 }
1162
1163 wfProfileOut( __METHOD__ );
1164 return $ret;
1165 }
1166
1167 /**
1168 * Wrap a comment in standard punctuation and formatting if
1169 * it's non-empty, otherwise return empty string.
1170 *
1171 * @param string $comment
1172 * @param mixed $title Title object (to generate link to section in autocomment) or null
1173 * @param bool $local Whether section links should refer to local page
1174 *
1175 * @return string
1176 */
1177 function commentBlock( $comment, $title = NULL, $local = false ) {
1178 // '*' used to be the comment inserted by the software way back
1179 // in antiquity in case none was provided, here for backwards
1180 // compatability, acc. to brion -ævar
1181 if( $comment == '' || $comment == '*' ) {
1182 return '';
1183 } else {
1184 $formatted = $this->formatComment( $comment, $title, $local );
1185 return " <span class=\"comment\">($formatted)</span>";
1186 }
1187 }
1188
1189 /**
1190 * Wrap and format the given revision's comment block, if the current
1191 * user is allowed to view it.
1192 *
1193 * @param Revision $rev
1194 * @param bool $local Whether section links should refer to local page
1195 * @param $isPublic, show only if all users can see it
1196 * @return string HTML
1197 */
1198 function revComment( Revision $rev, $local = false, $isPublic = false ) {
1199 if( $rev->getRawComment() == "" ) return "";
1200 if( $rev->isDeleted( Revision::DELETED_COMMENT ) && $isPublic ) {
1201 $block = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
1202 } else if( $rev->userCan( Revision::DELETED_COMMENT ) ) {
1203 $block = $this->commentBlock( $rev->getComment( Revision::FOR_THIS_USER ),
1204 $rev->getTitle(), $local );
1205 } else {
1206 $block = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
1207 }
1208 if( $rev->isDeleted( Revision::DELETED_COMMENT ) ) {
1209 return " <span class=\"history-deleted\">$block</span>";
1210 }
1211 return $block;
1212 }
1213
1214 public function formatRevisionSize( $size ) {
1215 if ( $size == 0 ) {
1216 $stxt = wfMsgExt( 'historyempty', 'parsemag' );
1217 } else {
1218 global $wgLang;
1219 $stxt = wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $size ) );
1220 $stxt = "($stxt)";
1221 }
1222 $stxt = htmlspecialchars( $stxt );
1223 return "<span class=\"history-size\">$stxt</span>";
1224 }
1225
1226 /** @todo document */
1227 function tocIndent() {
1228 return "\n<ul>";
1229 }
1230
1231 /** @todo document */
1232 function tocUnindent($level) {
1233 return "</li>\n" . str_repeat( "</ul>\n</li>\n", $level>0 ? $level : 0 );
1234 }
1235
1236 /**
1237 * parameter level defines if we are on an indentation level
1238 */
1239 function tocLine( $anchor, $tocline, $tocnumber, $level, $sectionIndex = false ) {
1240 $classes = "toclevel-$level";
1241 if ( $sectionIndex !== false )
1242 $classes .= " tocsection-$sectionIndex";
1243 return "\n<li class=\"$classes\"><a href=\"#" .
1244 $anchor . '"><span class="tocnumber">' .
1245 $tocnumber . '</span> <span class="toctext">' .
1246 $tocline . '</span></a>';
1247 }
1248
1249 /** @todo document */
1250 function tocLineEnd() {
1251 return "</li>\n";
1252 }
1253
1254 /** @todo document */
1255 function tocList($toc) {
1256 global $wgJsMimeType;
1257 $title = wfMsgHtml('toc') ;
1258 return
1259 '<table id="toc" class="toc" summary="' . $title .'"><tr><td>'
1260 . '<div id="toctitle"><h2>' . $title . "</h2></div>\n"
1261 . $toc
1262 # no trailing newline, script should not be wrapped in a
1263 # paragraph
1264 . "</ul>\n</td></tr></table>"
1265 . '<script type="' . $wgJsMimeType . '">'
1266 . ' if (window.showTocToggle) {'
1267 . ' var tocShowText = "' . Xml::escapeJsString( wfMsg('showtoc') ) . '";'
1268 . ' var tocHideText = "' . Xml::escapeJsString( wfMsg('hidetoc') ) . '";'
1269 . ' showTocToggle();'
1270 . ' } '
1271 . "</script>\n";
1272 }
1273
1274 /**
1275 * Generate a table of contents from a section tree
1276 * @param $tree Return value of ParserOutput::getSections()
1277 * @return string HTML
1278 */
1279 public function generateTOC( $tree ) {
1280 $toc = '';
1281 $lastLevel = 0;
1282 foreach ( $tree as $section ) {
1283 if ( $section['toclevel'] > $lastLevel )
1284 $toc .= $this->tocIndent();
1285 else if ( $section['toclevel'] < $lastLevel )
1286 $toc .= $this->tocUnindent(
1287 $lastLevel - $section['toclevel'] );
1288 else
1289 $toc .= $this->tocLineEnd();
1290
1291 $toc .= $this->tocLine( $section['anchor'],
1292 $section['line'], $section['number'],
1293 $section['toclevel'], $section['index'] );
1294 $lastLevel = $section['toclevel'];
1295 }
1296 $toc .= $this->tocLineEnd();
1297 return $this->tocList( $toc );
1298 }
1299
1300 /**
1301 * Create a section edit link. This supersedes editSectionLink() and
1302 * editSectionLinkForOther().
1303 *
1304 * @param $nt Title The title being linked to (may not be the same as
1305 * $wgTitle, if the section is included from a template)
1306 * @param $section string The designation of the section being pointed to,
1307 * to be included in the link, like "&section=$section"
1308 * @param $tooltip string The tooltip to use for the link: will be escaped
1309 * and wrapped in the 'editsectionhint' message
1310 * @return string HTML to use for edit link
1311 */
1312 public function doEditSectionLink( Title $nt, $section, $tooltip = null ) {
1313 $attribs = array();
1314 if( !is_null( $tooltip ) ) {
1315 $attribs['title'] = wfMsg( 'editsectionhint', $tooltip );
1316 }
1317 $link = $this->link( $nt, wfMsg('editsection'),
1318 $attribs,
1319 array( 'action' => 'edit', 'section' => $section ),
1320 array( 'noclasses', 'known' )
1321 );
1322
1323 # Run the old hook. This takes up half of the function . . . hopefully
1324 # we can rid of it someday.
1325 $attribs = '';
1326 if( $tooltip ) {
1327 $attribs = wfMsgHtml( 'editsectionhint', htmlspecialchars( $tooltip ) );
1328 $attribs = " title=\"$attribs\"";
1329 }
1330 $result = null;
1331 wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $attribs, $link, &$result ) );
1332 if( !is_null( $result ) ) {
1333 # For reverse compatibility, add the brackets *after* the hook is
1334 # run, and even add them to hook-provided text. (This is the main
1335 # reason that the EditSectionLink hook is deprecated in favor of
1336 # DoEditSectionLink: it can't change the brackets or the span.)
1337 $result = wfMsgHtml( 'editsection-brackets', $result );
1338 return "<span class=\"editsection\">$result</span>";
1339 }
1340
1341 # Add the brackets and the span, and *then* run the nice new hook, with
1342 # clean and non-redundant arguments.
1343 $result = wfMsgHtml( 'editsection-brackets', $link );
1344 $result = "<span class=\"editsection\">$result</span>";
1345
1346 wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result ) );
1347 return $result;
1348 }
1349
1350 /**
1351 * Create a headline for content
1352 *
1353 * @param int $level The level of the headline (1-6)
1354 * @param string $attribs Any attributes for the headline, starting with a space and ending with '>'
1355 * This *must* be at least '>' for no attribs
1356 * @param string $anchor The anchor to give the headline (the bit after the #)
1357 * @param string $text The text of the header
1358 * @param string $link HTML to add for the section edit link
1359 * @param mixed $legacyAnchor A second, optional anchor to give for
1360 * backward compatibility (false to omit)
1361 *
1362 * @return string HTML headline
1363 */
1364 public function makeHeadline( $level, $attribs, $anchor, $text, $link, $legacyAnchor = false ) {
1365 $ret = "<h$level id=\"$anchor\"$attribs"
1366 . $link
1367 . " <span class=\"mw-headline\">$text</span>"
1368 . "</h$level>";
1369 if ( $legacyAnchor !== false ) {
1370 $ret = "<a id=\"$legacyAnchor\"></a>$ret";
1371 }
1372 return $ret;
1373 }
1374
1375 /**
1376 * Split a link trail, return the "inside" portion and the remainder of the trail
1377 * as a two-element array
1378 *
1379 * @static
1380 */
1381 static function splitTrail( $trail ) {
1382 static $regex = false;
1383 if ( $regex === false ) {
1384 global $wgContLang;
1385 $regex = $wgContLang->linkTrail();
1386 }
1387 $inside = '';
1388 if ( '' != $trail ) {
1389 $m = array();
1390 if ( preg_match( $regex, $trail, $m ) ) {
1391 $inside = $m[1];
1392 $trail = $m[2];
1393 }
1394 }
1395 return array( $inside, $trail );
1396 }
1397
1398 /**
1399 * Generate a rollback link for a given revision. Currently it's the
1400 * caller's responsibility to ensure that the revision is the top one. If
1401 * it's not, of course, the user will get an error message.
1402 *
1403 * If the calling page is called with the parameter &bot=1, all rollback
1404 * links also get that parameter. It causes the edit itself and the rollback
1405 * to be marked as "bot" edits. Bot edits are hidden by default from recent
1406 * changes, so this allows sysops to combat a busy vandal without bothering
1407 * other users.
1408 *
1409 * @param Revision $rev
1410 */
1411 function generateRollback( $rev ) {
1412 return '<span class="mw-rollback-link">['
1413 . $this->buildRollbackLink( $rev )
1414 . ']</span>';
1415 }
1416
1417 /**
1418 * Build a raw rollback link, useful for collections of "tool" links
1419 *
1420 * @param Revision $rev
1421 * @return string
1422 */
1423 public function buildRollbackLink( $rev ) {
1424 global $wgRequest, $wgUser;
1425 $title = $rev->getTitle();
1426 $query = array(
1427 'action' => 'rollback',
1428 'from' => $rev->getUserText()
1429 );
1430 if( $wgRequest->getBool( 'bot' ) ) {
1431 $query['bot'] = '1';
1432 $query['hidediff'] = '1'; // bug 15999
1433 }
1434 $query['token'] = $wgUser->editToken( array( $title->getPrefixedText(),
1435 $rev->getUserText() ) );
1436 return $this->link( $title, wfMsgHtml( 'rollbacklink' ),
1437 array( 'title' => wfMsg( 'tooltip-rollback' ) ),
1438 $query, array( 'known', 'noclasses' ) );
1439 }
1440
1441 /**
1442 * Returns HTML for the "templates used on this page" list.
1443 *
1444 * @param array $templates Array of templates from Article::getUsedTemplate
1445 * or similar
1446 * @param bool $preview Whether this is for a preview
1447 * @param bool $section Whether this is for a section edit
1448 * @return string HTML output
1449 */
1450 public function formatTemplates( $templates, $preview = false, $section = false ) {
1451 wfProfileIn( __METHOD__ );
1452
1453 $outText = '';
1454 if ( count( $templates ) > 0 ) {
1455 # Do a batch existence check
1456 $batch = new LinkBatch;
1457 foreach( $templates as $title ) {
1458 $batch->addObj( $title );
1459 }
1460 $batch->execute();
1461
1462 # Construct the HTML
1463 $outText = '<div class="mw-templatesUsedExplanation">';
1464 if ( $preview ) {
1465 $outText .= wfMsgExt( 'templatesusedpreview', array( 'parse' ) );
1466 } elseif ( $section ) {
1467 $outText .= wfMsgExt( 'templatesusedsection', array( 'parse' ) );
1468 } else {
1469 $outText .= wfMsgExt( 'templatesused', array( 'parse' ) );
1470 }
1471 $outText .= "</div><ul>\n";
1472
1473 usort( $templates, array( 'Title', 'compare' ) );
1474 foreach ( $templates as $titleObj ) {
1475 $r = $titleObj->getRestrictions( 'edit' );
1476 if ( in_array( 'sysop', $r ) ) {
1477 $protected = wfMsgExt( 'template-protected', array( 'parseinline' ) );
1478 } elseif ( in_array( 'autoconfirmed', $r ) ) {
1479 $protected = wfMsgExt( 'template-semiprotected', array( 'parseinline' ) );
1480 } else {
1481 $protected = '';
1482 }
1483 if( $titleObj->quickUserCan( 'edit' ) ) {
1484 $editLink = $this->link(
1485 $titleObj,
1486 wfMsg( 'editlink' ),
1487 array(),
1488 array( 'action' => 'edit' )
1489 );
1490 } else {
1491 $editLink = $this->link(
1492 $titleObj,
1493 wfMsg( 'viewsourcelink' ),
1494 array(),
1495 array( 'action' => 'edit' )
1496 );
1497 }
1498 $outText .= '<li>' . $this->link( $titleObj ) . ' (' . $editLink . ') ' . $protected . '</li>';
1499 }
1500 $outText .= '</ul>';
1501 }
1502 wfProfileOut( __METHOD__ );
1503 return $outText;
1504 }
1505
1506 /**
1507 * Returns HTML for the "hidden categories on this page" list.
1508 *
1509 * @param array $hiddencats Array of hidden categories from Article::getHiddenCategories
1510 * or similar
1511 * @return string HTML output
1512 */
1513 public function formatHiddenCategories( $hiddencats ) {
1514 global $wgLang;
1515 wfProfileIn( __METHOD__ );
1516
1517 $outText = '';
1518 if ( count( $hiddencats ) > 0 ) {
1519 # Construct the HTML
1520 $outText = '<div class="mw-hiddenCategoriesExplanation">';
1521 $outText .= wfMsgExt( 'hiddencategories', array( 'parse' ), $wgLang->formatnum( count( $hiddencats ) ) );
1522 $outText .= "</div><ul>\n";
1523
1524 foreach ( $hiddencats as $titleObj ) {
1525 $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
1526 }
1527 $outText .= '</ul>';
1528 }
1529 wfProfileOut( __METHOD__ );
1530 return $outText;
1531 }
1532
1533 /**
1534 * Format a size in bytes for output, using an appropriate
1535 * unit (B, KB, MB or GB) according to the magnitude in question
1536 *
1537 * @param $size Size to format
1538 * @return string
1539 */
1540 public function formatSize( $size ) {
1541 global $wgLang;
1542 return htmlspecialchars( $wgLang->formatSize( $size ) );
1543 }
1544
1545 /**
1546 * Given the id of an interface element, constructs the appropriate title
1547 * attribute from the system messages. (Note, this is usually the id but
1548 * isn't always, because sometimes the accesskey needs to go on a different
1549 * element than the id, for reverse-compatibility, etc.)
1550 *
1551 * @param string $name Id of the element, minus prefixes.
1552 * @param mixed $options null or the string 'withaccess' to add an access-
1553 * key hint
1554 * @return string Contents of the title attribute (which you must HTML-
1555 * escape), or false for no title attribute
1556 */
1557 public function titleAttrib( $name, $options = null ) {
1558 wfProfileIn( __METHOD__ );
1559
1560 $tooltip = wfMsg( "tooltip-$name" );
1561 # Compatibility: formerly some tooltips had [alt-.] hardcoded
1562 $tooltip = preg_replace( "/ ?\[alt-.\]$/", '', $tooltip );
1563
1564 # Message equal to '-' means suppress it.
1565 if ( wfEmptyMsg( "tooltip-$name", $tooltip ) || $tooltip == '-' ) {
1566 $tooltip = false;
1567 }
1568
1569 if ( $options == 'withaccess' ) {
1570 $accesskey = $this->accesskey( $name );
1571 if( $accesskey !== false ) {
1572 if ( $tooltip === false || $tooltip === '' ) {
1573 $tooltip = "[$accesskey]";
1574 } else {
1575 $tooltip .= " [$accesskey]";
1576 }
1577 }
1578 }
1579
1580 wfProfileOut( __METHOD__ );
1581 return $tooltip;
1582 }
1583
1584 /**
1585 * Given the id of an interface element, constructs the appropriate
1586 * accesskey attribute from the system messages. (Note, this is usually
1587 * the id but isn't always, because sometimes the accesskey needs to go on
1588 * a different element than the id, for reverse-compatibility, etc.)
1589 *
1590 * @param string $name Id of the element, minus prefixes.
1591 * @return string Contents of the accesskey attribute (which you must HTML-
1592 * escape), or false for no accesskey attribute
1593 */
1594 public function accesskey( $name ) {
1595 wfProfileIn( __METHOD__ );
1596
1597 $accesskey = wfMsg( "accesskey-$name" );
1598
1599 # FIXME: Per standard MW behavior, a value of '-' means to suppress the
1600 # attribute, but this is broken for accesskey: that might be a useful
1601 # value.
1602 if( $accesskey != '' && $accesskey != '-' && !wfEmptyMsg( "accesskey-$name", $accesskey ) ) {
1603 wfProfileOut( __METHOD__ );
1604 return $accesskey;
1605 }
1606
1607 wfProfileOut( __METHOD__ );
1608 return false;
1609 }
1610
1611 /**
1612 * Creates a (show/hide) link for deleting revisions/log entries
1613 *
1614 * @param array $query Query parameters to be passed to link()
1615 * @param bool $restricted Set to true to use a <strong> instead of a <span>
1616 *
1617 * @return string HTML <a> link to Special:Revisiondelete, wrapped in a
1618 * span to allow for customization of appearance with CSS
1619 */
1620 public function revDeleteLink( $query = array(), $restricted = false ) {
1621 $sp = SpecialPage::getTitleFor( 'Revisiondelete' );
1622 $text = wfMsgHtml( 'rev-delundel' );
1623 $tag = $restricted ? 'strong' : 'span';
1624 $link = $this->link( $sp, $text, array(), $query, array( 'known', 'noclasses' ) );
1625 return Xml::tags( $tag, array( 'class' => 'mw-revdelundel-link' ), "($link)" );
1626 }
1627
1628 /* Deprecated methods */
1629
1630 /**
1631 * @deprecated
1632 */
1633 function postParseLinkColour( $s = null ) {
1634 wfDeprecated( __METHOD__ );
1635 return null;
1636 }
1637
1638
1639 /**
1640 * @deprecated Use link()
1641 *
1642 * This function is a shortcut to makeLinkObj(Title::newFromText($title),...). Do not call
1643 * it if you already have a title object handy. See makeLinkObj for further documentation.
1644 *
1645 * @param $title String: the text of the title
1646 * @param $text String: link text
1647 * @param $query String: optional query part
1648 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
1649 * be included in the link text. Other characters will be appended after
1650 * the end of the link.
1651 */
1652 function makeLink( $title, $text = '', $query = '', $trail = '' ) {
1653 wfProfileIn( __METHOD__ );
1654 $nt = Title::newFromText( $title );
1655 if ( $nt instanceof Title ) {
1656 $result = $this->makeLinkObj( $nt, $text, $query, $trail );
1657 } else {
1658 wfDebug( 'Invalid title passed to Linker::makeLink(): "'.$title."\"\n" );
1659 $result = $text == "" ? $title : $text;
1660 }
1661
1662 wfProfileOut( __METHOD__ );
1663 return $result;
1664 }
1665
1666 /**
1667 * @deprecated Use link()
1668 *
1669 * This function is a shortcut to makeKnownLinkObj(Title::newFromText($title),...). Do not call
1670 * it if you already have a title object handy. See makeKnownLinkObj for further documentation.
1671 *
1672 * @param $title String: the text of the title
1673 * @param $text String: link text
1674 * @param $query String: optional query part
1675 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
1676 * be included in the link text. Other characters will be appended after
1677 * the end of the link.
1678 */
1679 function makeKnownLink( $title, $text = '', $query = '', $trail = '', $prefix = '',$aprops = '') {
1680 $nt = Title::newFromText( $title );
1681 if ( $nt instanceof Title ) {
1682 return $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix , $aprops );
1683 } else {
1684 wfDebug( 'Invalid title passed to Linker::makeKnownLink(): "'.$title."\"\n" );
1685 return $text == '' ? $title : $text;
1686 }
1687 }
1688
1689 /**
1690 * @deprecated Use link()
1691 *
1692 * This function is a shortcut to makeBrokenLinkObj(Title::newFromText($title),...). Do not call
1693 * it if you already have a title object handy. See makeBrokenLinkObj for further documentation.
1694 *
1695 * @param string $title The text of the title
1696 * @param string $text Link text
1697 * @param string $query Optional query part
1698 * @param string $trail Optional trail. Alphabetic characters at the start of this string will
1699 * be included in the link text. Other characters will be appended after
1700 * the end of the link.
1701 */
1702 function makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) {
1703 $nt = Title::newFromText( $title );
1704 if ( $nt instanceof Title ) {
1705 return $this->makeBrokenLinkObj( $nt, $text, $query, $trail );
1706 } else {
1707 wfDebug( 'Invalid title passed to Linker::makeBrokenLink(): "'.$title."\"\n" );
1708 return $text == '' ? $title : $text;
1709 }
1710 }
1711
1712 /**
1713 * @deprecated Use link()
1714 *
1715 * This function is a shortcut to makeStubLinkObj(Title::newFromText($title),...). Do not call
1716 * it if you already have a title object handy. See makeStubLinkObj for further documentation.
1717 *
1718 * @param $title String: the text of the title
1719 * @param $text String: link text
1720 * @param $query String: optional query part
1721 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
1722 * be included in the link text. Other characters will be appended after
1723 * the end of the link.
1724 */
1725 function makeStubLink( $title, $text = '', $query = '', $trail = '' ) {
1726 wfDeprecated( __METHOD__ );
1727 $nt = Title::newFromText( $title );
1728 if ( $nt instanceof Title ) {
1729 return $this->makeStubLinkObj( $nt, $text, $query, $trail );
1730 } else {
1731 wfDebug( 'Invalid title passed to Linker::makeStubLink(): "'.$title."\"\n" );
1732 return $text == '' ? $title : $text;
1733 }
1734 }
1735
1736 /**
1737 * @deprecated Use link()
1738 *
1739 * Make a link for a title which may or may not be in the database. If you need to
1740 * call this lots of times, pre-fill the link cache with a LinkBatch, otherwise each
1741 * call to this will result in a DB query.
1742 *
1743 * @param $nt Title: the title object to make the link from, e.g. from
1744 * Title::newFromText.
1745 * @param $text String: link text
1746 * @param $query String: optional query part
1747 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
1748 * be included in the link text. Other characters will be appended after
1749 * the end of the link.
1750 * @param $prefix String: optional prefix. As trail, only before instead of after.
1751 */
1752 function makeLinkObj( $nt, $text= '', $query = '', $trail = '', $prefix = '' ) {
1753 wfProfileIn( __METHOD__ );
1754
1755 $query = wfCgiToArray( $query );
1756 list( $inside, $trail ) = Linker::splitTrail( $trail );
1757 if( $text === '' ) {
1758 $text = $this->linkText( $nt );
1759 }
1760
1761 $ret = $this->link( $nt, "$prefix$text$inside", array(), $query ) . $trail;
1762
1763 wfProfileOut( __METHOD__ );
1764 return $ret;
1765 }
1766
1767 /**
1768 * @deprecated Use link()
1769 *
1770 * Make a link for a title which definitely exists. This is faster than makeLinkObj because
1771 * it doesn't have to do a database query. It's also valid for interwiki titles and special
1772 * pages.
1773 *
1774 * @param $nt Title object of target page
1775 * @param $text String: text to replace the title
1776 * @param $query String: link target
1777 * @param $trail String: text after link
1778 * @param $prefix String: text before link text
1779 * @param $aprops String: extra attributes to the a-element
1780 * @param $style String: style to apply - if empty, use getInternalLinkAttributesObj instead
1781 * @return the a-element
1782 */
1783 function makeKnownLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '', $style = '' ) {
1784 wfProfileIn( __METHOD__ );
1785
1786 if ( $text == '' ) {
1787 $text = $this->linkText( $title );
1788 }
1789 $attribs = Sanitizer::mergeAttributes(
1790 Sanitizer::decodeTagAttributes( $aprops ),
1791 Sanitizer::decodeTagAttributes( $style )
1792 );
1793 $query = wfCgiToArray( $query );
1794 list( $inside, $trail ) = Linker::splitTrail( $trail );
1795
1796 $ret = $this->link( $title, "$prefix$text$inside", $attribs, $query,
1797 array( 'known', 'noclasses' ) ) . $trail;
1798
1799 wfProfileOut( __METHOD__ );
1800 return $ret;
1801 }
1802
1803 /**
1804 * @deprecated Use link()
1805 *
1806 * Make a red link to the edit page of a given title.
1807 *
1808 * @param $nt Title object of the target page
1809 * @param $text String: Link text
1810 * @param $query String: Optional query part
1811 * @param $trail String: Optional trail. Alphabetic characters at the start of this string will
1812 * be included in the link text. Other characters will be appended after
1813 * the end of the link.
1814 */
1815 function makeBrokenLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' ) {
1816 wfProfileIn( __METHOD__ );
1817
1818 list( $inside, $trail ) = Linker::splitTrail( $trail );
1819 if( $text === '' ) {
1820 $text = $this->linkText( $title );
1821 }
1822 $nt = $this->normaliseSpecialPage( $title );
1823
1824 $ret = $this->link( $title, "$prefix$text$inside", array(),
1825 wfCgiToArray( $query ), 'broken' ) . $trail;
1826
1827 wfProfileOut( __METHOD__ );
1828 return $ret;
1829 }
1830
1831 /**
1832 * @deprecated Use link()
1833 *
1834 * Make a brown link to a short article.
1835 *
1836 * @param $nt Title object of the target page
1837 * @param $text String: link text
1838 * @param $query String: optional query part
1839 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
1840 * be included in the link text. Other characters will be appended after
1841 * the end of the link.
1842 */
1843 function makeStubLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
1844 wfDeprecated( __METHOD__ );
1845 return $this->makeColouredLinkObj( $nt, 'stub', $text, $query, $trail, $prefix );
1846 }
1847
1848 /**
1849 * @deprecated Use link()
1850 *
1851 * Make a coloured link.
1852 *
1853 * @param $nt Title object of the target page
1854 * @param $colour Integer: colour of the link
1855 * @param $text String: link text
1856 * @param $query String: optional query part
1857 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
1858 * be included in the link text. Other characters will be appended after
1859 * the end of the link.
1860 */
1861 function makeColouredLinkObj( $nt, $colour, $text = '', $query = '', $trail = '', $prefix = '' ) {
1862 if($colour != ''){
1863 $style = $this->getInternalLinkAttributesObj( $nt, $text, $colour );
1864 } else $style = '';
1865 return $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix, '', $style );
1866 }
1867
1868 /** Obsolete alias */
1869 function makeImage( $url, $alt = '' ) {
1870 wfDeprecated( __METHOD__ );
1871 return $this->makeExternalImage( $url, $alt );
1872 }
1873
1874 /**
1875 * Creates the HTML source for images
1876 * @deprecated use makeImageLink2
1877 *
1878 * @param object $title
1879 * @param string $label label text
1880 * @param string $alt alt text
1881 * @param string $align horizontal alignment: none, left, center, right)
1882 * @param array $handlerParams Parameters to be passed to the media handler
1883 * @param boolean $framed shows image in original size in a frame
1884 * @param boolean $thumb shows image as thumbnail in a frame
1885 * @param string $manualthumb image name for the manual thumbnail
1886 * @param string $valign vertical alignment: baseline, sub, super, top, text-top, middle, bottom, text-bottom
1887 * @param string $time, timestamp of the file, set as false for current
1888 * @return string
1889 */
1890 function makeImageLinkObj( $title, $label, $alt, $align = '', $handlerParams = array(), $framed = false,
1891 $thumb = false, $manualthumb = '', $valign = '', $time = false )
1892 {
1893 $frameParams = array( 'alt' => $alt, 'caption' => $label );
1894 if ( $align ) {
1895 $frameParams['align'] = $align;
1896 }
1897 if ( $framed ) {
1898 $frameParams['framed'] = true;
1899 }
1900 if ( $thumb ) {
1901 $frameParams['thumbnail'] = true;
1902 }
1903 if ( $manualthumb ) {
1904 $frameParams['manualthumb'] = $manualthumb;
1905 }
1906 if ( $valign ) {
1907 $frameParams['valign'] = $valign;
1908 }
1909 $file = wfFindFile( $title, $time );
1910 return $this->makeImageLink2( $title, $file, $frameParams, $handlerParams, $time );
1911 }
1912
1913 /** @deprecated use Linker::makeMediaLinkObj() */
1914 function makeMediaLink( $name, $unused = '', $text = '', $time = false ) {
1915 $nt = Title::makeTitleSafe( NS_FILE, $name );
1916 return $this->makeMediaLinkObj( $nt, $text, $time );
1917 }
1918
1919 /**
1920 * Used to generate section edit links that point to "other" pages
1921 * (sections that are really part of included pages).
1922 *
1923 * @deprecated use Linker::doEditSectionLink()
1924 * @param $title Title string.
1925 * @param $section Integer: section number.
1926 */
1927 public function editSectionLinkForOther( $title, $section ) {
1928 wfDeprecated( __METHOD__ );
1929 $title = Title::newFromText( $title );
1930 return $this->doEditSectionLink( $title, $section );
1931 }
1932
1933 /**
1934 * @deprecated use Linker::doEditSectionLink()
1935 * @param $nt Title object.
1936 * @param $section Integer: section number.
1937 * @param $hint Link String: title, or default if omitted or empty
1938 */
1939 public function editSectionLink( Title $nt, $section, $hint = '' ) {
1940 wfDeprecated( __METHOD__ );
1941 if( $hint === '' ) {
1942 # No way to pass an actual empty $hint here! The new interface al-
1943 # lows this, so we have to do this for compatibility.
1944 $hint = null;
1945 }
1946 return $this->doEditSectionLink( $nt, $section, $hint );
1947 }
1948
1949 /**
1950 * @deprecated Returns raw bits of HTML, use titleAttrib() and accesskey()
1951 */
1952 public function tooltipAndAccesskey( $name ) {
1953 # FIXME: If Sanitizer::expandAttributes() treated "false" as "output
1954 # no attribute" instead of "output '' as value for attribute", this
1955 # would be three lines.
1956 $attribs = array(
1957 'title' => $this->titleAttrib( $name, 'withaccess' ),
1958 'accesskey' => $this->accesskey( $name )
1959 );
1960 if ( $attribs['title'] === false ) {
1961 unset( $attribs['title'] );
1962 }
1963 if ( $attribs['accesskey'] === false ) {
1964 unset( $attribs['accesskey'] );
1965 }
1966 return Xml::expandAttributes( $attribs );
1967 }
1968
1969 /** @deprecated Returns raw bits of HTML, use titleAttrib() */
1970 public function tooltip( $name, $options = null ) {
1971 # FIXME: If Sanitizer::expandAttributes() treated "false" as "output
1972 # no attribute" instead of "output '' as value for attribute", this
1973 # would be two lines.
1974 $tooltip = $this->titleAttrib( $name, $options );
1975 if ( $tooltip === false ) {
1976 return '';
1977 }
1978 return Xml::expandAttributes( array(
1979 'title' => $this->titleAttrib( $name, $options )
1980 ) );
1981 }
1982 }