Extension:PromotedInterlanguages
![]() | This extension stores its source code on a wiki page. Please be aware that this code may be unreviewed or maliciously altered. They may contain security holes, outdated interfaces that are no longer compatible etc. Note: No localisation updates are provided for this extension by translatewiki.net . |
![]() | This extension is currently not actively maintained! Although it may still work, any bug reports or feature requests will more than likely be ignored. |
![]() Release status: unmaintained |
|
---|---|
![]() |
|
Implementation | Parser function |
Description | Adds a {{#promoted:status|langcode}} function to customize the look of interlanguage links to foreign promoted articles |
Author(s) | Nicolas Dumazet (NicDumZtalk) |
MediaWiki | |
License | LGPL |
Download | No link |
wgPilPromotedClasses |
|
What can this extension do?[edit]
This extension provides the ability to append predefined CSS classes to interlanguage links that got promoted status (featured articles, good articles, featured portals...) in other languages. This extension associates promoted statuses to CSS classes, and adds a {{#promoted:status|lang}} parser tag.
That extension is meant as an alternative to the JavaScript hacks used on the Wikimedia projects to display golden stars next to the interlanguage links pointing to a featured article in a foreign language.
Usage[edit]
Assuming that a "FA" CSS class is defined and included by MediaWiki e.g.:
li.FA {
/* use a custom list bullet, for example */
list-style-image: url("http://upload.wikimedia.org/wikipedia/en/d/d4/Monobook-bullet-star.png");
}
and that the featured status is associated to the FA CSS class (see below), adding {{#promoted:featured|fr}} to an article will apply the FA CSS class to the fr: interlanguage links in that article.
Download instructions[edit]
Please cut and paste the code found below and place it in $IP/extensions/PromotedInterlanguages/
. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php .
Installation[edit]
To install this extension, add the following to LocalSettings.php :
$wgPilPromotedClasses = array();
# Add a value to $wgPilPromotedClasses to add a promoted status.
# First key is the namespace where it applies
# Second key is the first {{#promoted argument expected
# Value is the CSS class to be appended to the promoted interlanguage link
# For instance,
# $wgPilPromotedClasses['NS_MAIN']['featured'] = 'FArticle';
# $wgPilPromotedClasses['NS_MAIN']['good'] = 'GArticle';
# $wgPilPromotedClasses['NS_PROJECT']['featured'] = 'FPortal';
# creates three promoted statuses : Featured articles, good articles,
# and featured portals.
# In main namespace articles, {{#promoted:featured|xx}} will append the
# FArticle CSS class to the xx: interlanguage links, {{#promoted:good|yy}}
# will append the GArticle CSS class to the yy interlanguage links
$wgPilPromotedClasses[NS_MAIN]['featured'] = 'FA';
require_once("$IP/extensions/PromotedInterlanguages/Promoted.php");
Code[edit]
PromotedInterlanguages/Promoted.php[edit]
<?php
if( !defined( 'MEDIAWIKI' ) ) {
echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" );
die( 1 );
}
include_once('Promoted.body.php');
$wgExtensionCredits['parserhook'][] = array(
'name' => 'PromotedInterlanguages',
'author' =>'Nicolas Dumazet',
'url' => 'http://www.mediawiki.org/wiki/Extension:PromotedInterlanguages',
'description' => '<nowiki>{{#promoted:status|langcode}}</nowiki> parser tag, enhances look of interlanguage links that have a featured or good article status'
);
$wgPilInstance = new PromotedInterlanguagesHandler;
$wgHooks['SkinTemplateOutputPageBeforeExec'][] = array( $wgPilInstance, 'modifyInterlanguages' );
$wgExtensionFunctions[] = 'PromotedInterlanguages_Setup';
$wgHooks['LanguageGetMagic'][] = 'PromotedInterlanguages_Magic';
function PromotedInterlanguages_Setup() {
global $wgParser, $wgPilInstance;
$wgParser->setFunctionHook( 'promoted', array( $wgPilInstance, 'promotedTagRender' ) );
}
function PromotedInterlanguages_Magic( &$magicWords, $langCode ) {
$magicWords['promoted'] = array( 0, 'promoted' );
return true;
}
PromotedInterlanguages/Promoted.body.php[edit]
<?php
if( !defined( 'MEDIAWIKI' ) ) {
echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" );
die( 1 );
}
class PromotedInterlanguagesHandler {
# Stores the css classes to append.
# Keys are language codes, values are css classes
var $featuredBits = array();
function promotedTagRender( &$parser, $type = '', $lang = '' ) {
global $wgPilPromotedClasses, $wgTitle;
$parser->disableCache();
if ( isset( $wgPilPromotedClasses[$wgTitle->getNamespace()][$type] ) ) {
$this->featuredBits[$lang][] =
$wgPilPromotedClasses[$wgTitle->getNamespace()][$type];
}
return "";
}
function modifyInterlanguages($skin, $tpl) {
if ( empty( $this->featuredBits ) ) {
return true;
}
global $wgOut, $wgContLang;
$interlanguages =& $tpl->data['language_urls'];
$i = 0;
foreach( $wgOut->getLanguageLinks() as $l ) {
$tmp = explode( ':', $l, 2 );
$lang = $tmp[0];
unset($tmp);
if ( isset( $this->featuredBits[$lang] ) ) {
foreach( $this->featuredBits[$lang] as $class ) {
$interlanguages[$i]['class'] .= " " . $class;
}
}
$i++;
}
return true;
}
}