r32565 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r32564‎ | r32565 | r32566 >
Date:14:31, 29 March 2008
Author:minuteelectron
Status:old
Tags:
Comment:
Click 1.4 - fixed regex and accessibility issues re. title attribute (props. Danny B.)
Modified paths:
  • /trunk/extensions/Click/Click.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Click/Click.php
@@ -3,14 +3,14 @@
44 /**
55 * Click Extension
66 *
7 - * dds a parser function to display an image with a link that leads to a page other than the image description page.
 7+ * Adds a parser function to display an image with a link that leads to a page other than the image description page.
88 *
99 * @addtogroup Extensions
1010 *
1111 * @link http://www.mediawiki.org/wiki/Extension:Click
1212 *
1313 * @author MinuteElectron <minuteelectron@googlemail.com>
14 - * @copyright Copyright � 2008 MinuteElectron.
 14+ * @copyright Copyright � 2008 MinuteElectron and Danny B.
1515 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1616 */
1717
@@ -21,9 +21,9 @@
2222 $wgExtensionCredits[ 'parserhook' ][] = array(
2323 'name' => 'Click',
2424 'description' => 'Adds a parser function to display an image with a link that leads to a page other than the image description page.',
25 - 'author' => 'MinuteElectron',
 25+ 'author' => array( 'MinuteElectron', 'Danny B.' ),
2626 'url' => 'http://www.mediawiki.org/wiki/Extension:Click',
27 - 'version' => '1.3',
 27+ 'version' => '1.4',
2828 );
2929
3030 // Setup function.
@@ -35,14 +35,14 @@
3636 function efClickParserFunction_Setup() {
3737 global $wgParser;
3838 // Register parser function hook.
39 - $wgParser->setFunctionHook( 'Click', 'efClickParserFunction_Render' );
 39+ $wgParser->setFunctionHook( 'click', 'efClickParserFunction_Render' );
4040 // Return true so things don't break.
4141 return true;
4242 }
4343
4444 function efClickParserFunction_Magic( &$magicWords, $langCode ) {
4545 // Register parser function magic word.
46 - $magicWords[ 'Click' ] = array( 0, 'Click' );
 46+ $magicWords[ 'click' ] = array( 0, 'click' );
4747 // Return true so things don't break.
4848 return true;
4949 }
@@ -51,11 +51,11 @@
5252
5353 // Width and alt-text are interchangable.
5454 // No need to escape here, automatically done by Xml class functions.
55 - if( preg_match( '#^[0|1|2|3|4|5|6|7|8|9]*px$#', $widthalt ) ) {
 55+ if( preg_match( '#^[0-9]+px$#', $widthalt ) ) {
5656 // First value width, second alt.
5757 $width = $widthalt;
5858 $alt = $altwidth;
59 - } elseif( preg_match( '#^[0|1|2|3|4|5|6|7|8|9]*px$#', $altwidth ) ) {
 59+ } elseif( preg_match( '#^[0-9]+px$#', $altwidth ) ) {
6060 // First value alt, second width.
6161 $alt = $widthalt;
6262 $width = $altwidth;
@@ -68,9 +68,15 @@
6969 // Open hyperlink, default to a on-wiki page, but if it doesn't exist and
7070 // is a valid external URL then use it.
7171 $targettitle = Title::newFromText( $target );
 72+ // Link title attribute (full page name).
 73+ if( $targettitle->getNamespace() !== 0 ) {
 74+ $title = $targettitle->getNsText() . ':' . $targettitle->getText();
 75+ } else {
 76+ $title = $targettitle->getText();
 77+ }
7278 if( is_object( $targettitle ) && $targettitle->exists() ) {
7379 // Internal link, open hyperlink and register internal link.
74 - $r = Xml::openElement( 'a', array( 'href' => $targettitle->getLocalUrl(), 'title' => $alt ) );
 80+ $r = Xml::openElement( 'a', array( 'href' => $targettitle->getLocalUrl(), 'title' => $title ) );
7581 $parser->mOutput->addLink( $targettitle );
7682 } else {
7783 // Internal page doesn't exist, test if external.
@@ -84,11 +90,11 @@
8591 }
8692 if( $ext ) {
8793 // External link, open hyperlink with escaped href and register external link.
88 - $r = Xml::openElement( 'a', array( 'href' => htmlspecialchars( $target ), 'title' => $alt ) );
 94+ $r = Xml::openElement( 'a', array( 'href' => $target, 'title' => $target ) );
8995 $parser->mOutput->addExternalLink( $target );
9096 } elseif( is_object( $targettitle ) ) {
9197 // Valid internal link after all (but to non-existant page), open hyperlink and register internal link.
92 - $r = Xml::openElement( 'a', array( 'class' => 'new', 'href' => $targettitle->getLocalUrl( 'action=edit&redlink=1' ), 'title' => $alt ) );
 98+ $r = Xml::openElement( 'a', array( 'class' => 'new', 'href' => $targettitle->getLocalUrl( 'action=edit&redlink=1' ), 'title' => wfMsg( 'red-link-title', $title ) ) );
9399 $parser->mOutput->addLink( $targettitle );
94100 }
95101 }

Status & tagging log