r113657 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113656‎ | r113657 | r113658 >
Date:20:29, 12 March 2012
Author:van-de-bugger
Status:new
Tags:
Comment:
(1) Sometimes $text is not a string but an object of Message class. This causes exception. Code changed to handle such a case. (2) If link is made using canonical namespace anme or an alias, it is not replaced with semantic title. Fixed.
Modified paths:
  • /trunk/extensions/SemanticTitle/SemanticTitle.class.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticTitle/SemanticTitle.class.php
@@ -63,12 +63,28 @@
6464
6565 // Handle links.
6666 static public function onLinkBegin( $skin, $target, &$text, &$customAttribs, &$query, &$options, &$ret ) {
67 - if ( ! isset( $text ) || $text == $target->getPrefixedText() ) {
 67+ /*
 68+ If a link is customized by a user (e. g. [[Target|Text]]) it should remain intact.
 69+ Let us assume a link is not customized if its text is a full name of target page.
 70+ However, simple check `$target->getPrefixedText() == $text' fails if prefix in text
 71+ is an alias or canonical. So more complicated check should be done:
 72+ `Title::newFromText( $text )->getPrefixedText() == $target->getPrefixedtext()'.
 73+ */
 74+ $semantic = false;
 75+ if ( isset( $text ) ) {
 76+ // Hmm... Sometimes `$text' is not a string but an object of class `Message'...
 77+ if ( is_string( $text ) ) {
 78+ $title = Title::newFromText( $text );
 79+ if ( $title != null && $title->getPrefixedText() == $target->getPrefixedText() ) {
 80+ $semantic = self::getText( $target );
 81+ }; // if
 82+ }; // if
 83+ } else {
6884 $semantic = self::getText( $target );
69 - if ( $semantic !== false ) {
70 - $text = $semantic;
71 - }; // if
7285 }; // if
 86+ if ( $semantic !== false ) {
 87+ $text = $semantic;
 88+ }; // if
7389 return true;
7490 } // function onLinkBegin
7591

Status & tagging log