* 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
This commit is contained in:
Raimond Spekking 2010-01-12 19:45:49 +00:00
parent 969835975a
commit 87333c0daa

View file

@ -50,54 +50,63 @@ class SpecialGadgets extends SpecialPage {
$listOpen = false; $listOpen = false;
$msgOpt = array( 'parseinline', 'parsemag' ); $msgOpt = array( 'parseinline', 'parsemag' );
$editInterfaceAllowed = $wgUser->isAllowed( 'editinterface' ) ? true : false ;
foreach ( $gadgets as $section => $entries ) { foreach ( $gadgets as $section => $entries ) {
if ( $section !== false && $section !== '' ) { if ( $section !== false && $section !== '' ) {
$t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-section-$section$lang" ); $t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-section-$section$lang" );
$lnk = $t ? $skin->makeLinkObj( $t, wfMsgHTML("edit"), 'action=edit' ) : htmlspecialchars($section); if ( $editInterfaceAllowed ) {
$lnkTarget = $t
? $skin->link( $t, wfMsgHTML( 'edit' ), array(), array( 'action' => 'edit' ) )
: htmlspecialchars( $section );
$lnk = "    [$lnkTarget]";
} else {
$lnk = '';
}
$ttext = wfMsgExt( "gadget-section-$section", $msgOpt ); $ttext = wfMsgExt( "gadget-section-$section", $msgOpt );
if( $listOpen ) { if( $listOpen ) {
$wgOut->addHTML( '</ul>' ); $wgOut->addHTML( Xml::closeElement( 'ul' ) . "\n" );
$listOpen = false; $listOpen = false;
} }
$wgOut->addHTML( "\n<h2>$ttext &nbsp; &nbsp; [$lnk]</h2>\n" ); $wgOut->addHTML( Html::rawElement( 'h2', array(), $ttext . $lnk ) . "\n" );
} }
foreach ( $entries as $gname => $code ) { foreach ( $entries as $gname => $code ) {
$t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-$gname$lang" ); $t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-$gname$lang" );
if ( !$t ) continue; if ( !$t ) continue;
$lnk = $skin->makeLinkObj( $t, wfMsgHTML("edit"), 'action=edit' ); if ( $editInterfaceAllowed ) {
$lnkTarget = $skin->link( $t, wfMsgHTML( 'edit' ), array(), array( 'action' => 'edit' ) );
$lnk = "&nbsp; &nbsp; [$lnkTarget]";
} else {
$lnk = '';
}
$ttext = wfMsgExt( "gadget-$gname", $msgOpt ); $ttext = wfMsgExt( "gadget-$gname", $msgOpt );
if( !$listOpen ) { if( !$listOpen ) {
$listOpen = true; $listOpen = true;
$wgOut->addHTML( '<ul>' ); $wgOut->addHTML( Xml::openElement( 'ul' ) );
} }
$wgOut->addHTML( "<li>" ); $wgOut->addHTML( Xml::openElement( 'li' ) .
$wgOut->addHTML( "$ttext &nbsp; &nbsp; [$lnk]<br />" ); $ttext . $lnk . "<br />" .
wfMsgHTML( 'gadgets-uses' ) . wfMsg( 'colon-separator' )
);
$wgOut->addHTML( wfMsgHTML( "gadgets-uses" ) . wfMsg( 'colon-separator' ) ); $lnk = array();
$first = true;
foreach ( $code as $codePage ) { foreach ( $code as $codePage ) {
$t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-$codePage" ); $t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-$codePage" );
if ( !$t ) continue; if ( !$t ) continue;
if ( $first ) $first = false; $lnk[] = $skin->link( $t, htmlspecialchars( $t->getText() ) );
else $wgOut->addHTML(", ");
$lnk = $skin->makeLinkObj( $t, htmlspecialchars( $t->getText() ) );
$wgOut->addHTML($lnk);
} }
$wgOut->addHTML( $wgLang->commaList( $lnk ) );
$wgOut->addHTML( "</li>" ); $wgOut->addHTML( Xml::closeElement( 'li' ) . "\n" );
} }
} }
if( $listOpen ) { if( $listOpen ) {
$wgOut->addHTML( '</ul>' ); $wgOut->addHTML( Xml::closeElement( 'ul' ) . "\n" );
} }
} }
} }