https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113657

Revision: 113657
Author:   van-de-bugger
Date:     2012-03-12 20:29:54 +0000 (Mon, 12 Mar 2012)
Log Message:
-----------
(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: trunk/extensions/SemanticTitle/SemanticTitle.class.php
===================================================================
--- trunk/extensions/SemanticTitle/SemanticTitle.class.php      2012-03-12 
20:26:05 UTC (rev 113656)
+++ trunk/extensions/SemanticTitle/SemanticTitle.class.php      2012-03-12 
20:29:54 UTC (rev 113657)
@@ -63,12 +63,28 @@
 
        // Handle links.
        static public function onLinkBegin( $skin, $target, &$text, 
&$customAttribs, &$query, &$options, &$ret ) {
-               if ( ! isset( $text ) || $text == $target->getPrefixedText() ) {
+               /*
+                       If a link is customized by a user (e. g. 
[[Target|Text]]) it should remain intact.
+                       Let us assume a link is not customized if its text is a 
full name of target page.
+                       However, simple check `$target->getPrefixedText() == 
$text' fails if prefix in text
+                       is an alias or canonical. So more complicated check 
should be done:
+                       `Title::newFromText( $text )->getPrefixedText() == 
$target->getPrefixedtext()'.
+               */
+               $semantic = false;
+               if ( isset( $text ) ) {
+                       // Hmm... Sometimes `$text' is not a string but an 
object of class `Message'...
+                       if ( is_string( $text ) ) {
+                               $title = Title::newFromText( $text );
+                               if ( $title != null && 
$title->getPrefixedText() == $target->getPrefixedText() ) {
+                                       $semantic = self::getText( $target );
+                               }; // if
+                       }; // if
+               } else {
                        $semantic = self::getText( $target );
-                       if ( $semantic !== false ) {
-                               $text = $semantic;
-                       }; // if
                }; // if
+               if ( $semantic !== false ) {
+                       $text = $semantic;
+               }; // if
                return true;
        } // function onLinkBegin
 


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to