r60980 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60979‎ | r60980 | r60981 >
Date:19:45, 12 January 2010
Author:raymond
Status:ok
Tags:
Comment:
* Show [edit] links for users with editinterface right only
* While I am at it: Use Xml::/Html:: functions, commaList() and link() instead of deprecated functions
Modified paths:
  • /trunk/extensions/Gadgets/SpecialGadgets.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Gadgets/SpecialGadgets.php
@@ -50,54 +50,63 @@
5151 $listOpen = false;
5252
5353 $msgOpt = array( 'parseinline', 'parsemag' );
54 -
 54+ $editInterfaceAllowed = $wgUser->isAllowed( 'editinterface' ) ? true : false ;
 55+
5556 foreach ( $gadgets as $section => $entries ) {
5657 if ( $section !== false && $section !== '' ) {
5758 $t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-section-$section$lang" );
58 - $lnk = $t ? $skin->makeLinkObj( $t, wfMsgHTML("edit"), 'action=edit' ) : htmlspecialchars($section);
 59+ if ( $editInterfaceAllowed ) {
 60+ $lnkTarget = $t
 61+ ? $skin->link( $t, wfMsgHTML( 'edit' ), array(), array( 'action' => 'edit' ) )
 62+ : htmlspecialchars( $section );
 63+ $lnk = "    [$lnkTarget]";
 64+ } else {
 65+ $lnk = '';
 66+ }
5967 $ttext = wfMsgExt( "gadget-section-$section", $msgOpt );
6068
6169 if( $listOpen ) {
62 - $wgOut->addHTML( '</ul>' );
 70+ $wgOut->addHTML( Xml::closeElement( 'ul' ) . "\n" );
6371 $listOpen = false;
6472 }
65 - $wgOut->addHTML( "\n<h2>$ttext &nbsp; &nbsp; [$lnk]</h2>\n" );
 73+ $wgOut->addHTML( Html::rawElement( 'h2', array(), $ttext . $lnk ) . "\n" );
6674 }
6775
6876 foreach ( $entries as $gname => $code ) {
6977 $t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-$gname$lang" );
7078 if ( !$t ) continue;
7179
72 - $lnk = $skin->makeLinkObj( $t, wfMsgHTML("edit"), 'action=edit' );
 80+ if ( $editInterfaceAllowed ) {
 81+ $lnkTarget = $skin->link( $t, wfMsgHTML( 'edit' ), array(), array( 'action' => 'edit' ) );
 82+ $lnk = "&nbsp; &nbsp; [$lnkTarget]";
 83+ } else {
 84+ $lnk = '';
 85+ }
7386 $ttext = wfMsgExt( "gadget-$gname", $msgOpt );
7487
7588 if( !$listOpen ) {
7689 $listOpen = true;
77 - $wgOut->addHTML( '<ul>' );
 90+ $wgOut->addHTML( Xml::openElement( 'ul' ) );
7891 }
79 - $wgOut->addHTML( "<li>" );
80 - $wgOut->addHTML( "$ttext &nbsp; &nbsp; [$lnk]<br />" );
 92+ $wgOut->addHTML( Xml::openElement( 'li' ) .
 93+ $ttext . $lnk . "<br />" .
 94+ wfMsgHTML( 'gadgets-uses' ) . wfMsg( 'colon-separator' )
 95+ );
8196
82 - $wgOut->addHTML( wfMsgHTML( "gadgets-uses" ) . wfMsg( 'colon-separator' ) );
83 -
84 - $first = true;
 97+ $lnk = array();
8598 foreach ( $code as $codePage ) {
8699 $t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-$codePage" );
87100 if ( !$t ) continue;
88101
89 - if ( $first ) $first = false;
90 - else $wgOut->addHTML(", ");
91 -
92 - $lnk = $skin->makeLinkObj( $t, htmlspecialchars( $t->getText() ) );
93 - $wgOut->addHTML($lnk);
 102+ $lnk[] = $skin->link( $t, htmlspecialchars( $t->getText() ) );
94103 }
95 -
96 - $wgOut->addHTML( "</li>" );
 104+ $wgOut->addHTML( $wgLang->commaList( $lnk ) );
 105+ $wgOut->addHTML( Xml::closeElement( 'li' ) . "\n" );
97106 }
98107 }
99108
100109 if( $listOpen ) {
101 - $wgOut->addHTML( '</ul>' );
 110+ $wgOut->addHTML( Xml::closeElement( 'ul' ) . "\n" );
102111 }
103112 }
104113 }

Status & tagging log