r85247 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85246‎ | r85247 | r85248 >
Date:12:04, 3 April 2011
Author:dantman
Status:resolved (Comments)
Tags:
Comment:
Followup r85244; Define all methods as static, implement a DummyLinker to forward calls for passing to hooks and finish off anything in the way.
Modified paths:
  • /trunk/phase3/includes/ImageGallery.php (modified) (history)
  • /trunk/phase3/includes/Linker.php (modified) (history)
  • /trunk/phase3/includes/parser/LinkHolderArray.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/includes/parser/ParserOptions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/LinkHolderArray.php
@@ -254,7 +254,6 @@
255255 global $wgContLang;
256256
257257 $colours = array();
258 - $sk = $this->parent->getOptions()->getSkin( $this->parent->mTitle );
259258 $linkCache = LinkCache::singleton();
260259 $output = $this->parent->getOutput();
261260
@@ -288,7 +287,7 @@
289288 } elseif ( $ns == NS_SPECIAL ) {
290289 $colours[$pdbk] = 'new';
291290 } elseif ( ( $id = $linkCache->getGoodLinkID( $pdbk ) ) != 0 ) {
292 - $colours[$pdbk] = $sk->getLinkColour( $title, $threshold );
 291+ $colours[$pdbk] = Linker::getLinkColour( $title, $threshold );
293292 $output->addLink( $title, $id );
294293 $linkcolour_ids[$id] = $pdbk;
295294 } elseif ( $linkCache->isBadLink( $pdbk ) ) {
@@ -325,7 +324,7 @@
326325 # FIXME: convoluted data flow
327326 # The redirect status and length is passed to getLinkColour via the LinkCache
328327 # Use formal parameters instead
329 - $colours[$pdbk] = $sk->getLinkColour( $title, $threshold );
 328+ $colours[$pdbk] = Linker::getLinkColour( $title, $threshold );
330329 //add id to the extension todolist
331330 $linkcolour_ids[$s->page_id] = $pdbk;
332331 }
@@ -370,7 +369,7 @@
371370 }
372371 $type = array( 'known', 'noclasses' );
373372 }
374 - $replacePairs[$searchkey] = $sk->link( $title, $displayText,
 373+ $replacePairs[$searchkey] = Linker::link( $title, $displayText,
375374 $attribs, $query, $type );
376375 }
377376 }
@@ -398,11 +397,10 @@
399398
400399 wfProfileIn( __METHOD__ );
401400 # Make interwiki link HTML
402 - $sk = $this->parent->getOptions()->getSkin( $this->parent->mTitle );
403401 $output = $this->parent->getOutput();
404402 $replacePairs = array();
405403 foreach( $this->interwikis as $key => $link ) {
406 - $replacePairs[$key] = $sk->link( $link['title'], $link['text'] );
 404+ $replacePairs[$key] = Linker::link( $link['title'], $link['text'] );
407405 $output->addInterwikiLink( $link['title'] );
408406 }
409407 $replacer = new HashtableReplacer( $replacePairs, 1 );
@@ -423,7 +421,6 @@
424422 $variantMap = array(); // maps $pdbkey_Variant => $keys (of link holders)
425423 $output = $this->parent->getOutput();
426424 $linkCache = LinkCache::singleton();
427 - $sk = $this->parent->getOptions()->getSkin( $this->parent->mTitle );
428425 $threshold = $this->parent->getOptions()->getStubThreshold();
429426 $titlesToBeConverted = '';
430427 $titlesAttrs = array();
@@ -528,7 +525,7 @@
529526 # FIXME: convoluted data flow
530527 # The redirect status and length is passed to getLinkColour via the LinkCache
531528 # Use formal parameters instead
532 - $colours[$varPdbk] = $sk->getLinkColour( $variantTitle, $threshold );
 529+ $colours[$varPdbk] = Linker::getLinkColour( $variantTitle, $threshold );
533530 $linkcolour_ids[$s->page_id] = $pdbk;
534531 }
535532 }
Index: trunk/phase3/includes/parser/Parser.php
@@ -4549,7 +4549,6 @@
45504550 $ig->setParser( $this );
45514551 $ig->setHideBadImages();
45524552 $ig->setAttributes( Sanitizer::validateTagAttributes( $params, 'table' ) );
4553 - $ig->useSkin( $this->mOptions->getSkin( $this->mTitle ) );
45544553
45554554 if ( isset( $params['showfilename'] ) ) {
45564555 $ig->setShowFilename( true );
Index: trunk/phase3/includes/parser/ParserOptions.php
@@ -17,8 +17,7 @@
1818 var $mInterwikiMagic; # Interlanguage links are removed and returned in an array
1919 var $mAllowExternalImages; # Allow external images inline
2020 var $mAllowExternalImagesFrom; # If not, any exception?
21 - var $mEnableImageWhitelist; # If not or it doesn't match, should we check an on-wiki whitelist?
22 - var $mSkin = null; # Reference to the preferred skin
 21+ var $mEnableImageWhitelist; # If not or it doesn't match, should we check an on-wiki whitelist?
2322 var $mDateFormat = null; # Date format index
2423 var $mEditSection = true; # Create "edit section" links
2524 var $mAllowSpecialInclusion; # Allow inclusion of special pages
@@ -91,18 +90,6 @@
9291 function getUser() { return $this->mUser; }
9392 function getPreSaveTransform() { return $this->mPreSaveTransform; }
9493
95 - /**
96 - * @param $title Title
97 - * @return Skin
98 - * @deprecated Use Linker::* instead
99 - */
100 - function getSkin( $title = null ) {
101 - if ( !isset( $this->mSkin ) ) {
102 - $this->mSkin = $this->mUser->getSkin( $title );
103 - }
104 - return $this->mSkin;
105 - }
106 -
10794 function getDateFormat() {
10895 $this->optionUsed('dateformat');
10996 if ( !isset( $this->mDateFormat ) ) {
@@ -313,10 +300,6 @@
314301 // FIXME: This is just a way of retrieving the url/user preferred variant
315302 $confstr .= $wgContLang->getExtraHashOptions();
316303
317 - // Since the skin could be overloading link(), it should be
318 - // included here but in practice, none of our skins do that.
319 - // $confstr .= "!" . $this->mSkin->getSkinName();
320 -
321304 $confstr .= $wgRenderHashAppend;
322305
323306 if ( !in_array( 'editsection', $forOptions ) ) {
Index: trunk/phase3/includes/Linker.php
@@ -21,7 +21,7 @@
2222 * string is passed, which is the default value, defaults to 'external'.
2323 * @deprecated Just pass the external class directly to something using Html::expandAttributes
2424 */
25 - function getExternalLinkAttributes( $class = 'external' ) {
 25+ static function getExternalLinkAttributes( $class = 'external' ) {
2626 wfDeprecated( __METHOD__ );
2727 return self::getLinkAttributesInternal( '', $class );
2828 }
@@ -36,7 +36,7 @@
3737 * @param $class String: the contents of the class attribute; if an empty
3838 * string is passed, which is the default value, defaults to 'external'.
3939 */
40 - function getInterwikiLinkAttributes( $title, $unused = null, $class = 'external' ) {
 40+ static function getInterwikiLinkAttributes( $title, $unused = null, $class = 'external' ) {
4141 global $wgContLang;
4242
4343 # FIXME: We have a whole bunch of handling here that doesn't happen in
@@ -57,7 +57,7 @@
5858 * @param $unused String: unused
5959 * @param $class String: the contents of the class attribute, default none
6060 */
61 - function getInternalLinkAttributes( $title, $unused = null, $class = '' ) {
 61+ static function getInternalLinkAttributes( $title, $unused = null, $class = '' ) {
6262 $title = urldecode( $title );
6363 $title = str_replace( '_', ' ', $title );
6464 return self::getLinkAttributesInternal( $title, $class );
@@ -73,7 +73,7 @@
7474 * @param $title Mixed: optional (unescaped) string to use in the title
7575 * attribute; if false, default to the name of the page we're linking to
7676 */
77 - function getInternalLinkAttributesObj( $nt, $unused = null, $class = '', $title = false ) {
 77+ static function getInternalLinkAttributesObj( $nt, $unused = null, $class = '', $title = false ) {
7878 if ( $title === false ) {
7979 $title = $nt->getPrefixedText();
8080 }
@@ -83,7 +83,7 @@
8484 /**
8585 * Common code for getLinkAttributesX functions
8686 */
87 - private function getLinkAttributesInternal( $title, $class ) {
 87+ private static function getLinkAttributesInternal( $title, $class ) {
8888 $title = htmlspecialchars( $title );
8989 $class = htmlspecialchars( $class );
9090 $r = '';
@@ -103,7 +103,7 @@
104104 * @param $threshold Integer: user defined threshold
105105 * @return String: CSS class
106106 */
107 - function getLinkColour( $t, $threshold ) {
 107+ static function getLinkColour( $t, $threshold ) {
108108 $colour = '';
109109 if ( $t->isRedirect() ) {
110110 # Page is a redirect
@@ -154,7 +154,7 @@
155155 * Has compatibility issues on some setups, so avoid wherever possible.
156156 * @return string HTML <a> attribute
157157 */
158 - public function link(
 158+ public static function link(
159159 $target, $text = null, $customAttribs = array(), $query = array(), $options = array()
160160 ) {
161161 wfProfileIn( __METHOD__ );
@@ -164,7 +164,7 @@
165165 }
166166 $options = (array)$options;
167167
168 - $dummy = new Linker; // dummy linker instance for bc on the hooks
 168+ $dummy = new DummyLinker; // dummy linker instance for bc on the hooks
169169
170170 $ret = null;
171171 if ( !wfRunHooks( 'LinkBegin', array( $dummy, $target, &$text,
@@ -219,7 +219,7 @@
220220 /**
221221 * Identical to link(), except $options defaults to 'known'.
222222 */
223 - public function linkKnown(
 223+ public static function linkKnown(
224224 $target, $text = null, $customAttribs = array(),
225225 $query = array(), $options = array( 'known', 'noclasses' ) )
226226 {
@@ -231,7 +231,7 @@
232232 *
233233 * @param $target Title
234234 */
235 - private function linkUrl( $target, $query, $options ) {
 235+ private static function linkUrl( $target, $query, $options ) {
236236 wfProfileIn( __METHOD__ );
237237 # We don't want to include fragments for broken links, because they
238238 # generally make no sense.
@@ -258,7 +258,7 @@
259259 *
260260 * @param $target Title
261261 */
262 - private function linkAttribs( $target, $attribs, $options, $linkText ) {
 262+ private static function linkAttribs( $target, $attribs, $options, $linkText ) {
263263 wfProfileIn( __METHOD__ );
264264 global $wgUser;
265265 $defaults = array();
@@ -322,7 +322,7 @@
323323 *
324324 * @param $target Title
325325 */
326 - private function linkText( $target ) {
 326+ private static function linkText( $target ) {
327327 # We might be passed a non-Title by make*LinkObj(). Fail gracefully.
328328 if ( !$target instanceof Title ) {
329329 return '';
@@ -349,7 +349,7 @@
350350 * @return string HTML of link
351351 * @deprecated since 1.17
352352 */
353 - function makeSizeLinkObj( $size, $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
 353+ static function makeSizeLinkObj( $size, $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
354354 global $wgUser;
355355 wfDeprecated( __METHOD__ );
356356
@@ -361,12 +361,12 @@
362362
363363 /**
364364 * Make appropriate markup for a link to the current article. This is currently rendered
365 - * as the bold link text. The calling sequence is the same as the other make*LinkObj functions,
 365+ * as the bold link text. The calling sequence is the same as the other make*LinkObj static functions,
366366 * despite $query not being used.
367367 *
368368 * @param $nt Title
369369 */
370 - function makeSelfLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
 370+ static function makeSelfLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
371371 if ( $text == '' ) {
372372 $text = htmlspecialchars( $nt->getPrefixedText() );
373373 }
@@ -374,7 +374,7 @@
375375 return "<strong class=\"selflink\">{$prefix}{$text}{$inside}</strong>{$trail}";
376376 }
377377
378 - function normaliseSpecialPage( Title $title ) {
 378+ static function normaliseSpecialPage( Title $title ) {
379379 if ( $title->getNamespace() == NS_SPECIAL ) {
380380 list( $name, $subpage ) = SpecialPage::resolveAliasWithSubpage( $title->getDBkey() );
381381 if ( !$name ) {
@@ -392,7 +392,7 @@
393393 * Returns the filename part of an url.
394394 * Used as alternative text for external images.
395395 */
396 - function fnamePart( $url ) {
 396+ static function fnamePart( $url ) {
397397 $basename = strrchr( $url, '/' );
398398 if ( false === $basename ) {
399399 $basename = $url;
@@ -406,7 +406,7 @@
407407 * Return the code for images which were added via external links,
408408 * via Parser::maybeMakeExternalImage().
409409 */
410 - function makeExternalImage( $url, $alt = '' ) {
 410+ static function makeExternalImage( $url, $alt = '' ) {
411411 if ( $alt == '' ) {
412412 $alt = self::fnamePart( $url );
413413 }
@@ -455,11 +455,11 @@
456456 * @param $widthOption: Used by the parser to remember the user preference thumbnailsize
457457 * @return String: HTML for an image, with links, wrappers, etc.
458458 */
459 - function makeImageLink2( Title $title, $file, $frameParams = array(),
 459+ static function makeImageLink2( Title $title, $file, $frameParams = array(),
460460 $handlerParams = array(), $time = false, $query = "", $widthOption = null )
461461 {
462462 $res = null;
463 - $dummy = new Linker;
 463+ $dummy = new DummyLinker;
464464 if ( !wfRunHooks( 'ImageBeforeProduceHTML', array( &$dummy, &$title,
465465 &$file, &$frameParams, &$handlerParams, &$time, &$res ) ) ) {
466466 return $res;
@@ -575,7 +575,7 @@
576576 * @param $frameParams The frame parameters
577577 * @param $query An optional query string to add to description page links
578578 */
579 - function getImageLinkMTOParams( $frameParams, $query = '' ) {
 579+ static function getImageLinkMTOParams( $frameParams, $query = '' ) {
580580 $mtoParams = array();
581581 if ( isset( $frameParams['link-url'] ) && $frameParams['link-url'] !== '' ) {
582582 $mtoParams['custom-url-link'] = $frameParams['link-url'];
@@ -604,7 +604,7 @@
605605 * @param $framed Boolean
606606 * @param $manualthumb String
607607 */
608 - function makeThumbLinkObj( Title $title, $file, $label = '', $alt,
 608+ static function makeThumbLinkObj( Title $title, $file, $label = '', $alt,
609609 $align = 'right', $params = array(), $framed = false , $manualthumb = "" )
610610 {
611611 $frameParams = array(
@@ -630,7 +630,7 @@
631631 * @param string $query
632632 * @return mixed
633633 */
634 - function makeThumbLink2( Title $title, $file, $frameParams = array(),
 634+ static function makeThumbLink2( Title $title, $file, $frameParams = array(),
635635 $handlerParams = array(), $time = false, $query = "" )
636636 {
637637 global $wgStylePath;
@@ -733,7 +733,7 @@
734734 * @param $time Boolean: a file of a certain timestamp was requested
735735 * @return String
736736 */
737 - public function makeBrokenImageLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '', $time = false ) {
 737+ public static function makeBrokenImageLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '', $time = false ) {
738738 global $wgEnableUploads, $wgUploadMissingFileUrl;
739739 if ( $title instanceof Title ) {
740740 wfProfileIn( __METHOD__ );
@@ -774,7 +774,7 @@
775775 * @param $query String: urlencoded query string to prepend
776776 * @return String: urlencoded URL
777777 */
778 - protected function getUploadUrl( $destFile, $query = '' ) {
 778+ protected static function getUploadUrl( $destFile, $query = '' ) {
779779 global $wgUploadMissingFileUrl;
780780 $q = 'wpDestFile=' . $destFile->getPartialUrl();
781781 if ( $query != '' )
@@ -796,7 +796,7 @@
797797 * @param $time string: MW timestamp of file creation time
798798 * @return String: HTML
799799 */
800 - public function makeMediaLinkObj( $title, $text = '', $time = false ) {
 800+ public static function makeMediaLinkObj( $title, $text = '', $time = false ) {
801801 $img = wfFindFile( $title, array( 'time' => $time ) );
802802 return self::makeMediaLinkFile( $title, $img, $text );
803803 }
@@ -812,7 +812,7 @@
813813 *
814814 * @todo Handle invalid or missing images better.
815815 */
816 - public function makeMediaLinkFile( Title $title, $file, $text = '' ) {
 816+ public static function makeMediaLinkFile( Title $title, $file, $text = '' ) {
817817 if ( $file && $file->exists() ) {
818818 $url = $file->getURL();
819819 $class = 'internal';
@@ -833,7 +833,7 @@
834834 * a message key from the link text.
835835 * Usage example: $skin->specialLink( 'recentchanges' )
836836 */
837 - function specialLink( $name, $key = '' ) {
 837+ static function specialLink( $name, $key = '' ) {
838838 if ( $key == '' ) { $key = strtolower( $name ); }
839839
840840 return self::linkKnown( SpecialPage::getTitleFor( $name ) , wfMsg( $key ) );
@@ -847,7 +847,7 @@
848848 * @param $linktype String: type of external link. Gets added to the classes
849849 * @param $attribs Array of extra attributes to <a>
850850 */
851 - function makeExternalLink( $url, $text, $escape = true, $linktype = '', $attribs = array() ) {
 851+ static function makeExternalLink( $url, $text, $escape = true, $linktype = '', $attribs = array() ) {
852852 $class = "external";
853853 if ( isset($linktype) && $linktype ) {
854854 $class .= " $linktype";
@@ -878,7 +878,7 @@
879879 * @return String: HTML fragment
880880 * @private
881881 */
882 - function userLink( $userId, $userText ) {
 882+ static function userLink( $userId, $userText ) {
883883 if ( $userId == 0 ) {
884884 $page = SpecialPage::getTitleFor( 'Contributions', $userText );
885885 } else {
@@ -898,7 +898,7 @@
899899 * @param $edits Integer: user edit count (optional, for performance)
900900 * @return String: HTML fragment
901901 */
902 - public function userToolLinks(
 902+ public static function userToolLinks(
903903 $userId, $userText, $redContribsWhenNoEdits = false, $flags = 0, $edits = null
904904 ) {
905905 global $wgUser, $wgDisableAnonTalk, $wgLang;
@@ -939,7 +939,7 @@
940940 * @param $userText String: user name or IP address
941941 * @param $edits Integer: user edit count (optional, for performance)
942942 */
943 - public function userToolLinksRedContribs( $userId, $userText, $edits = null ) {
 943+ public static function userToolLinksRedContribs( $userId, $userText, $edits = null ) {
944944 return self::userToolLinks( $userId, $userText, true, 0, $edits );
945945 }
946946
@@ -950,7 +950,7 @@
951951 * @return String: HTML fragment with user talk link
952952 * @private
953953 */
954 - function userTalkLink( $userId, $userText ) {
 954+ static function userTalkLink( $userId, $userText ) {
955955 $userTalkPage = Title::makeTitle( NS_USER_TALK, $userText );
956956 $userTalkLink = self::link( $userTalkPage, wfMsgHtml( 'talkpagelinktext' ) );
957957 return $userTalkLink;
@@ -962,7 +962,7 @@
963963 * @return String: HTML fragment with block link
964964 * @private
965965 */
966 - function blockLink( $userId, $userText ) {
 966+ static function blockLink( $userId, $userText ) {
967967 $blockPage = SpecialPage::getTitleFor( 'Block', $userText );
968968 $blockLink = self::link( $blockPage, wfMsgHtml( 'blocklink' ) );
969969 return $blockLink;
@@ -974,7 +974,7 @@
975975 * @param $isPublic Boolean: show only if all users can see it
976976 * @return String: HTML fragment
977977 */
978 - function revUserLink( $rev, $isPublic = false ) {
 978+ static function revUserLink( $rev, $isPublic = false ) {
979979 if ( $rev->isDeleted( Revision::DELETED_USER ) && $isPublic ) {
980980 $link = wfMsgHtml( 'rev-deleted-user' );
981981 } else if ( $rev->userCan( Revision::DELETED_USER ) ) {
@@ -995,7 +995,7 @@
996996 * @param $isPublic Boolean: show only if all users can see it
997997 * @return string HTML
998998 */
999 - function revUserTools( $rev, $isPublic = false ) {
 999+ static function revUserTools( $rev, $isPublic = false ) {
10001000 if ( $rev->isDeleted( Revision::DELETED_USER ) && $isPublic ) {
10011001 $link = wfMsgHtml( 'rev-deleted-user' );
10021002 } else if ( $rev->userCan( Revision::DELETED_USER ) ) {
@@ -1028,7 +1028,7 @@
10291029 * @param $title Mixed: Title object (to generate link to the section in autocomment) or null
10301030 * @param $local Boolean: whether section links should refer to local page
10311031 */
1032 - function formatComment( $comment, $title = null, $local = false ) {
 1032+ static function formatComment( $comment, $title = null, $local = false ) {
10331033 wfProfileIn( __METHOD__ );
10341034
10351035 # Sanitize text a bit:
@@ -1059,7 +1059,7 @@
10601060 * @param $local Boolean: whether section links should refer to local page
10611061 * @return String: formatted comment
10621062 */
1063 - private function formatAutocomments( $comment, $title = null, $local = false ) {
 1063+ private static function formatAutocomments( $comment, $title = null, $local = false ) {
10641064 // Bah!
10651065 self::$autocommentTitle = $title;
10661066 self::$autocommentLocal = $local;
@@ -1072,7 +1072,7 @@
10731073 return $comment;
10741074 }
10751075
1076 - private function formatAutocommentsCallback( $match ) {
 1076+ private static function formatAutocommentsCallback( $match ) {
10771077 $title = self::$autocommentTitle;
10781078 $local = self::$autocommentLocal;
10791079
@@ -1131,7 +1131,7 @@
11321132 * @param $local Boolean: whether section links should refer to local page
11331133 * @return String
11341134 */
1135 - public function formatLinksInComment( $comment, $title = null, $local = false ) {
 1135+ public static function formatLinksInComment( $comment, $title = null, $local = false ) {
11361136 self::$commentContextTitle = $title;
11371137 self::$commentLocal = $local;
11381138 $html = preg_replace_callback(
@@ -1143,7 +1143,7 @@
11441144 return $html;
11451145 }
11461146
1147 - protected function formatLinksInCommentCallback( $match ) {
 1147+ protected static function formatLinksInCommentCallback( $match ) {
11481148 global $wgContLang;
11491149
11501150 $medians = '(?:' . preg_quote( MWNamespace::getCanonicalName( NS_MEDIA ), '/' ) . '|';
@@ -1297,7 +1297,7 @@
12981298 *
12991299 * @return string
13001300 */
1301 - function commentBlock( $comment, $title = null, $local = false ) {
 1301+ static function commentBlock( $comment, $title = null, $local = false ) {
13021302 // '*' used to be the comment inserted by the software way back
13031303 // in antiquity in case none was provided, here for backwards
13041304 // compatability, acc. to brion -ævar
@@ -1318,7 +1318,7 @@
13191319 * @param $isPublic Boolean: show only if all users can see it
13201320 * @return String: HTML fragment
13211321 */
1322 - function revComment( Revision $rev, $local = false, $isPublic = false ) {
 1322+ static function revComment( Revision $rev, $local = false, $isPublic = false ) {
13231323 if ( $rev->getRawComment() == "" ) {
13241324 return "";
13251325 }
@@ -1336,7 +1336,7 @@
13371337 return $block;
13381338 }
13391339
1340 - public function formatRevisionSize( $size ) {
 1340+ public static function formatRevisionSize( $size ) {
13411341 if ( $size == 0 ) {
13421342 $stxt = wfMsgExt( 'historyempty', 'parsemag' );
13431343 } else {
@@ -1351,21 +1351,21 @@
13521352 /**
13531353 * Add another level to the Table of Contents
13541354 */
1355 - function tocIndent() {
 1355+ static function tocIndent() {
13561356 return "\n<ul>";
13571357 }
13581358
13591359 /**
13601360 * Finish one or more sublevels on the Table of Contents
13611361 */
1362 - function tocUnindent( $level ) {
 1362+ static function tocUnindent( $level ) {
13631363 return "</li>\n" . str_repeat( "</ul>\n</li>\n", $level > 0 ? $level : 0 );
13641364 }
13651365
13661366 /**
13671367 * parameter level defines if we are on an indentation level
13681368 */
1369 - function tocLine( $anchor, $tocline, $tocnumber, $level, $sectionIndex = false ) {
 1369+ static function tocLine( $anchor, $tocline, $tocnumber, $level, $sectionIndex = false ) {
13701370 $classes = "toclevel-$level";
13711371 if ( $sectionIndex !== false )
13721372 $classes .= " tocsection-$sectionIndex";
@@ -1380,7 +1380,7 @@
13811381 * tocUnindent() will be used instead if we're ending a line below
13821382 * the new level.
13831383 */
1384 - function tocLineEnd() {
 1384+ static function tocLineEnd() {
13851385 return "</li>\n";
13861386 }
13871387
@@ -1391,7 +1391,7 @@
13921392 * @param $lang mixed: Language code for the toc title
13931393 * @return String: full html of the TOC
13941394 */
1395 - function tocList( $toc, $lang = false ) {
 1395+ static function tocList( $toc, $lang = false ) {
13961396 $title = wfMsgExt( 'toc', array( 'language' => $lang, 'escape' ) );
13971397 return
13981398 '<table id="toc" class="toc"><tr><td>'
@@ -1407,7 +1407,7 @@
14081408 * @param $tree Return value of ParserOutput::getSections()
14091409 * @return String: HTML fragment
14101410 */
1411 - public function generateTOC( $tree ) {
 1411+ public static function generateTOC( $tree ) {
14121412 $toc = '';
14131413 $lastLevel = 0;
14141414 foreach ( $tree as $section ) {
@@ -1443,7 +1443,7 @@
14441444 *
14451445 * @return String: HTML headline
14461446 */
1447 - public function makeHeadline( $level, $attribs, $anchor, $text, $link, $legacyAnchor = false ) {
 1447+ public static function makeHeadline( $level, $attribs, $anchor, $text, $link, $legacyAnchor = false ) {
14481448 $ret = "<h$level$attribs"
14491449 . $link
14501450 . " <span class=\"mw-headline\" id=\"$anchor\">$text</span>"
@@ -1488,7 +1488,7 @@
14891489 *
14901490 * @param $rev Revision object
14911491 */
1492 - function generateRollback( $rev ) {
 1492+ static function generateRollback( $rev ) {
14931493 return '<span class="mw-rollback-link">['
14941494 . self::buildRollbackLink( $rev )
14951495 . ']</span>';
@@ -1500,7 +1500,7 @@
15011501 * @param $rev Revision object
15021502 * @return String: HTML fragment
15031503 */
1504 - public function buildRollbackLink( $rev ) {
 1504+ public static function buildRollbackLink( $rev ) {
15051505 global $wgRequest, $wgUser;
15061506 $title = $rev->getTitle();
15071507 $query = array(
@@ -1530,7 +1530,7 @@
15311531 * @param $section Boolean: whether this is for a section edit
15321532 * @return String: HTML output
15331533 */
1534 - public function formatTemplates( $templates, $preview = false, $section = false ) {
 1534+ public static function formatTemplates( $templates, $preview = false, $section = false ) {
15351535 wfProfileIn( __METHOD__ );
15361536
15371537 $outText = '';
@@ -1593,7 +1593,7 @@
15941594 * or similar
15951595 * @return String: HTML output
15961596 */
1597 - public function formatHiddenCategories( $hiddencats ) {
 1597+ public static function formatHiddenCategories( $hiddencats ) {
15981598 global $wgLang;
15991599 wfProfileIn( __METHOD__ );
16001600
@@ -1620,7 +1620,7 @@
16211621 * @param $size Size to format
16221622 * @return String
16231623 */
1624 - public function formatSize( $size ) {
 1624+ public static function formatSize( $size ) {
16251625 global $wgLang;
16261626 return htmlspecialchars( $wgLang->formatSize( $size ) );
16271627 }
@@ -1637,7 +1637,7 @@
16381638 * @return String: contents of the title attribute (which you must HTML-
16391639 * escape), or false for no title attribute
16401640 */
1641 - public function titleAttrib( $name, $options = null ) {
 1641+ public static function titleAttrib( $name, $options = null ) {
16421642 wfProfileIn( __METHOD__ );
16431643
16441644 $message = wfMessage( "tooltip-$name" );
@@ -1681,7 +1681,7 @@
16821682 * @return String: contents of the accesskey attribute (which you must HTML-
16831683 * escape), or false for no accesskey attribute
16841684 */
1685 - public function accesskey( $name ) {
 1685+ public static function accesskey( $name ) {
16861686 if ( isset( self::$accesskeycache[$name] ) ) {
16871687 return self::$accesskeycache[$name];
16881688 }
@@ -1715,7 +1715,7 @@
17161716 * @return String: HTML <a> link to Special:Revisiondelete, wrapped in a
17171717 * span to allow for customization of appearance with CSS
17181718 */
1719 - public function revDeleteLink( $query = array(), $restricted = false, $delete = true ) {
 1719+ public static function revDeleteLink( $query = array(), $restricted = false, $delete = true ) {
17201720 $sp = SpecialPage::getTitleFor( 'Revisiondelete' );
17211721 $text = $delete ? wfMsgHtml( 'rev-delundel' ) : wfMsgHtml( 'rev-showdeleted' );
17221722 $tag = $restricted ? 'strong' : 'span';
@@ -1731,7 +1731,7 @@
17321732 * @return string HTML text wrapped in a span to allow for customization
17331733 * of appearance with CSS
17341734 */
1735 - public function revDeleteLinkDisabled( $delete = true ) {
 1735+ public static function revDeleteLinkDisabled( $delete = true ) {
17361736 $text = $delete ? wfMsgHtml( 'rev-delundel' ) : wfMsgHtml( 'rev-showdeleted' );
17371737 return Xml::tags( 'span', array( 'class' => 'mw-revdelundel-link' ), "($text)" );
17381738 }
@@ -1751,7 +1751,7 @@
17521752 * be included in the link text. Other characters will be appended after
17531753 * the end of the link.
17541754 */
1755 - function makeLink( $title, $text = '', $query = '', $trail = '' ) {
 1755+ static function makeLink( $title, $text = '', $query = '', $trail = '' ) {
17561756 wfProfileIn( __METHOD__ );
17571757 $nt = Title::newFromText( $title );
17581758 if ( $nt instanceof Title ) {
@@ -1780,7 +1780,7 @@
17811781 * @param $prefix String: Optional prefix
17821782 * @param $aprops String: extra attributes to the a-element
17831783 */
1784 - function makeKnownLink(
 1784+ static function makeKnownLink(
17851785 $title, $text = '', $query = '', $trail = '', $prefix = '', $aprops = ''
17861786 ) {
17871787 $nt = Title::newFromText( $title );
@@ -1805,7 +1805,7 @@
18061806 * be included in the link text. Other characters will be appended after
18071807 * the end of the link.
18081808 */
1809 - function makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) {
 1809+ static function makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) {
18101810 $nt = Title::newFromText( $title );
18111811 if ( $nt instanceof Title ) {
18121812 return self::makeBrokenLinkObj( $nt, $text, $query, $trail );
@@ -1828,7 +1828,7 @@
18291829 * be included in the link text. Other characters will be appended after
18301830 * the end of the link.
18311831 */
1832 - function makeStubLink( $title, $text = '', $query = '', $trail = '' ) {
 1832+ static function makeStubLink( $title, $text = '', $query = '', $trail = '' ) {
18331833 wfDeprecated( __METHOD__ );
18341834 $nt = Title::newFromText( $title );
18351835 if ( $nt instanceof Title ) {
@@ -1855,7 +1855,7 @@
18561856 * the end of the link.
18571857 * @param $prefix String: optional prefix. As trail, only before instead of after.
18581858 */
1859 - function makeLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
 1859+ static function makeLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
18601860 wfProfileIn( __METHOD__ );
18611861 $query = wfCgiToArray( $query );
18621862 list( $inside, $trail ) = self::splitTrail( $trail );
@@ -1885,7 +1885,7 @@
18861886 * @param $style String: style to apply - if empty, use getInternalLinkAttributesObj instead
18871887 * @return the a-element
18881888 */
1889 - function makeKnownLinkObj(
 1889+ static function makeKnownLinkObj(
18901890 $title, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '', $style = ''
18911891 ) {
18921892 wfProfileIn( __METHOD__ );
@@ -1920,7 +1920,7 @@
19211921 * the end of the link.
19221922 * @param $prefix String: Optional prefix
19231923 */
1924 - function makeBrokenLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' ) {
 1924+ static function makeBrokenLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' ) {
19251925 wfProfileIn( __METHOD__ );
19261926
19271927 list( $inside, $trail ) = self::splitTrail( $trail );
@@ -1948,7 +1948,7 @@
19491949 * the end of the link.
19501950 * @param $prefix String: Optional prefix
19511951 */
1952 - function makeStubLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
 1952+ static function makeStubLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
19531953 return self::makeColouredLinkObj( $nt, 'stub', $text, $query, $trail, $prefix );
19541954 }
19551955
@@ -1966,7 +1966,7 @@
19671967 * the end of the link.
19681968 * @param $prefix String: Optional prefix
19691969 */
1970 - function makeColouredLinkObj( $nt, $colour, $text = '', $query = '', $trail = '', $prefix = '' ) {
 1970+ static function makeColouredLinkObj( $nt, $colour, $text = '', $query = '', $trail = '', $prefix = '' ) {
19711971 if ( $colour != '' ) {
19721972 $style = self::getInternalLinkAttributesObj( $nt, $text, $colour );
19731973 } else {
@@ -1976,7 +1976,7 @@
19771977 }
19781978
19791979 /** Obsolete alias */
1980 - function makeImage( $url, $alt = '' ) {
 1980+ static function makeImage( $url, $alt = '' ) {
19811981 wfDeprecated( __METHOD__ );
19821982 return self::makeExternalImage( $url, $alt );
19831983 }
@@ -1997,7 +1997,7 @@
19981998 * @param $time String: timestamp of the file, set as false for current
19991999 * @return String
20002000 */
2001 - function makeImageLinkObj( $title, $label, $alt, $align = '', $handlerParams = array(),
 2001+ static function makeImageLinkObj( $title, $label, $alt, $align = '', $handlerParams = array(),
20022002 $framed = false, $thumb = false, $manualthumb = '', $valign = '', $time = false )
20032003 {
20042004 $frameParams = array( 'alt' => $alt, 'caption' => $label );
@@ -2021,7 +2021,7 @@
20222022 }
20232023
20242024 /** @deprecated use Linker::makeMediaLinkObj() */
2025 - function makeMediaLink( $name, $unused = '', $text = '', $time = false ) {
 2025+ static function makeMediaLink( $name, $unused = '', $text = '', $time = false ) {
20262026 $nt = Title::makeTitleSafe( NS_FILE, $name );
20272027 return self::makeMediaLinkObj( $nt, $text, $time );
20282028 }
@@ -2029,7 +2029,7 @@
20302030 /**
20312031 * Returns the attributes for the tooltip and access key.
20322032 */
2033 - public function tooltipAndAccesskeyAttribs( $name ) {
 2033+ public static function tooltipAndAccesskeyAttribs( $name ) {
20342034 global $wgEnableTooltipsAndAccesskeys;
20352035 if ( !$wgEnableTooltipsAndAccesskeys )
20362036 return array();
@@ -2053,7 +2053,7 @@
20542054 * @deprecated since 1.14
20552055 * Returns raw bits of HTML, use titleAttrib() and accesskey()
20562056 */
2057 - public function tooltipAndAccesskey( $name ) {
 2057+ public static function tooltipAndAccesskey( $name ) {
20582058 return Xml::expandAttributes( self::tooltipAndAccesskeyAttribs( $name ) );
20592059 }
20602060
@@ -2061,7 +2061,7 @@
20622062 * @deprecated since 1.14
20632063 * Returns raw bits of HTML, use titleAttrib()
20642064 */
2065 - public function tooltip( $name, $options = null ) {
 2065+ public static function tooltip( $name, $options = null ) {
20662066 global $wgEnableTooltipsAndAccesskeys;
20672067 if ( !$wgEnableTooltipsAndAccesskeys )
20682068 return '';
@@ -2077,3 +2077,19 @@
20782078 ) );
20792079 }
20802080 }
 2081+
 2082+class DummyLinker {
 2083+
 2084+ /**
 2085+ * Use PHP's magic __call handler to transform instance calls to a dummy instance
 2086+ * into static calls to the new Linker for backwards compatibility.
 2087+ *
 2088+ * @param $fname String Name of called method
 2089+ * @param $args Array Arguments to the method
 2090+ */
 2091+ function __call( $fname, $args ) {
 2092+ return call_user_func_array( array( 'Linker', $fname ), $args );
 2093+ }
 2094+
 2095+}
 2096+
Index: trunk/phase3/includes/ImageGallery.php
@@ -13,7 +13,6 @@
1414 {
1515 var $mImages, $mShowBytes, $mShowFilename;
1616 var $mCaption = false;
17 - var $mSkin = false;
1817
1918 /**
2019 * Hide blacklisted images?
@@ -127,27 +126,13 @@
128127 * Instruct the class to use a specific skin for rendering
129128 *
130129 * @param $skin Skin object
 130+ * @deprecated Not used anymore
131131 */
132132 function useSkin( $skin ) {
133 - $this->mSkin = $skin;
 133+ /* no op */
134134 }
135135
136136 /**
137 - * Return the skin that should be used
138 - *
139 - * @return Skin object
140 - */
141 - function getSkin() {
142 - if( !$this->mSkin ) {
143 - global $wgUser;
144 - $skin = $wgUser->getSkin();
145 - } else {
146 - $skin = $this->mSkin;
147 - }
148 - return $skin;
149 - }
150 -
151 - /**
152137 * Add an image to the gallery.
153138 *
154139 * @param $title Title object of the image that is added to the gallery
@@ -230,8 +215,6 @@
231216 function toHTML() {
232217 global $wgLang;
233218
234 - $sk = $this->getSkin();
235 -
236219 if ( $this->mPerRow > 0 ) {
237220 $maxwidth = $this->mPerRow * ( $this->mWidths + self::THUMB_PADDING + self::GB_PADDING + self::GB_BORDERS );
238221 $oldStyle = isset( $this->mAttribs['style'] ) ? $this->mAttribs['style'] : "";
@@ -276,7 +259,7 @@
277260 } elseif( $this->mHideBadImages && wfIsBadImage( $nt->getDBkey(), $this->getContextTitle() ) ) {
278261 # The image is blacklisted, just show it as a text link.
279262 $thumbhtml = "\n\t\t\t".'<div style="height: '.(self::THUMB_PADDING + $this->mHeights).'px;">' .
280 - $sk->link(
 263+ Linker::link(
281264 $nt,
282265 htmlspecialchars( $nt->getText() ),
283266 array(),
@@ -321,7 +304,7 @@
322305
323306 //TODO
324307 // $linkTarget = Title::newFromText( $wgContLang->getNsText( MWNamespace::getUser() ) . ":{$ut}" );
325 - // $ul = $sk->link( $linkTarget, $ut );
 308+ // $ul = Linker::link( $linkTarget, $ut );
326309
327310 if( $this->mShowBytes ) {
328311 if( $img ) {
@@ -336,7 +319,7 @@
337320 }
338321
339322 $textlink = $this->mShowFilename ?
340 - $sk->link(
 323+ Linker::link(
341324 $nt,
342325 htmlspecialchars( $wgLang->truncate( $nt->getText(), $this->mCaptionLength ) ),
343326 array(),

Follow-up revisions

RevisionCommit summaryAuthorDate
r85257Try and fix fatals on TWNhappy-melon14:34, 3 April 2011
r85258AutoLoader entry for r85247.happy-melon14:59, 3 April 2011
r85296Add a getSkin that returns a dummy linker for BC with extensions still abusin...dantman23:32, 3 April 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r85244Drop connetion between Skin and Linker and turn Linker into a staticly usable...dantman11:44, 3 April 2011

Comments

#Comment by Nikerabbit (talk | contribs)   14:34, 3 April 2011

[03-Apr-2011 14:28:51] PHP Fatal error: Call to undefined method ParserOptions::getSkin() in /www/w/extensions/Translate/tag/PageTranslationHooks.php on line 212

Not mentioned in the commit summary!

#Comment by Dantman (talk | contribs)   23:33, 3 April 2011

Added a BC in r85296.

#Comment by Krinkle (talk | contribs)   15:00, 3 April 2011

See also r85250.

#Comment by Bawolff (talk | contribs)   15:16, 5 April 2011

One potential use case for not making the Linker static, is consider how sites that have multiple urls (aka http://secure.wikimedia.org/wikipedia/en/wiki/ vs http://en.wikipedia.org ) In most contexts one would want to make links that reflect the site you're currently looking at, but in some cases you would want to use the canonical url for the site. (email notifications, perhaps the irc notifications although at the moment we use some black magic to get around that). Being able to have different linker objects to generate canonical vs normal links might be useful.

Of course at the moment we don't do that, but making the Linker static makes it more difficult to do (on the other hand, it is somewhat of an edge case that sites have multiple urls).

#Comment by Happy-melon (talk | contribs)   15:22, 5 April 2011

Sites having multiple urls is itself black magic/hackish. The most we should ever have to change is the protocol.

#Comment by Dantman (talk | contribs)   21:08, 5 April 2011

That's not a good reason for the linker not to be static, that has nothing to do with a skin overloading parts of the linker.

That's more of a use case for a hook to alter urls (DumpHTML could use one too), or a custom hook for fragmenting the cache by url, some sort of multiple url config, or substituting local urls in stuff going into the parser cache with tokens.

Status & tagging log