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