Index: trunk/extensions/SemanticTitle/SemanticTitle.class.php |
— | — | @@ -63,12 +63,28 @@ |
64 | 64 | |
65 | 65 | // Handle links. |
66 | 66 | 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 { |
68 | 84 | $semantic = self::getText( $target ); |
69 | | - if ( $semantic !== false ) { |
70 | | - $text = $semantic; |
71 | | - }; // if |
72 | 85 | }; // if |
| 86 | + if ( $semantic !== false ) { |
| 87 | + $text = $semantic; |
| 88 | + }; // if |
73 | 89 | return true; |
74 | 90 | } // function onLinkBegin |
75 | 91 | |