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