Index: trunk/phase3/includes/Linker.php |
— | — | @@ -816,14 +816,31 @@ |
817 | 817 | function formatComment($comment, $title = NULL, $local = false) { |
818 | 818 | wfProfileIn( __METHOD__ ); |
819 | 819 | |
820 | | - global $wgContLang; |
| 820 | + # Sanitize text a bit: |
821 | 821 | $comment = str_replace( "\n", " ", $comment ); |
822 | 822 | $comment = htmlspecialchars( $comment ); |
823 | 823 | |
824 | | - # The pattern for autogen comments is / * foo * /, which makes for |
825 | | - # some nasty regex. |
826 | | - # We look for all comments, match any text before and after the comment, |
827 | | - # add a separator where needed and format the comment itself with CSS |
| 824 | + # Render autocomments and make links: |
| 825 | + $comment = $this->formatAutoComments( $comment, $title, $local ); |
| 826 | + $comment = $this->formatLinksInComment( $comment ); |
| 827 | + |
| 828 | + wfProfileOut( __METHOD__ ); |
| 829 | + return $comment; |
| 830 | + } |
| 831 | + |
| 832 | + /** |
| 833 | + * The pattern for autogen comments is / * foo * /, which makes for |
| 834 | + * some nasty regex. |
| 835 | + * We look for all comments, match any text before and after the comment, |
| 836 | + * add a separator where needed and format the comment itself with CSS |
| 837 | + * Called by Linker::formatComment. |
| 838 | + * |
| 839 | + * @param $comment Comment text |
| 840 | + * @param $title An optional title object used to links to sections |
| 841 | + * |
| 842 | + * @todo Document the $local parameter. |
| 843 | + */ |
| 844 | + private function formatAutocomments( $comment, $title = NULL, $local = false ) { |
828 | 845 | $match = array(); |
829 | 846 | while (preg_match('/(.*)\/\*\s*(.*?)\s*\*\/(.*)/', $comment,$match)) { |
830 | 847 | $pre=$match[1]; |
— | — | @@ -857,10 +874,21 @@ |
858 | 875 | $comment=$pre.$auto.$post; |
859 | 876 | } |
860 | 877 | |
861 | | - # format regular and media links - all other wiki formatting |
862 | | - # is ignored |
| 878 | + return $comment; |
| 879 | + } |
| 880 | + |
| 881 | + /** |
| 882 | + * Format regular and media links - all other wiki formatting is ignored |
| 883 | + * Called by Linker::formatComment. |
| 884 | + * @param $comment The comment text. |
| 885 | + * @return Comment text with links using HTML. |
| 886 | + */ |
| 887 | + private function formatLinksInComment( $comment ) { |
| 888 | + global $wgContLang; |
| 889 | + |
863 | 890 | $medians = '(?:' . preg_quote( Namespace::getCanonicalName( NS_MEDIA ), '/' ) . '|'; |
864 | 891 | $medians .= preg_quote( $wgContLang->getNsText( NS_MEDIA ), '/' ) . '):'; |
| 892 | + |
865 | 893 | while(preg_match('/\[\[:?(.*?)(\|(.*?))*\]\](.*)$/',$comment,$match)) { |
866 | 894 | # Handle link renaming [[foo|text]] will show link as "text" |
867 | 895 | if( "" != $match[3] ) { |
— | — | @@ -887,7 +915,7 @@ |
888 | 916 | } |
889 | 917 | $comment = preg_replace( $linkRegexp, StringUtils::escapeRegexReplacement( $thelink ), $comment, 1 ); |
890 | 918 | } |
891 | | - wfProfileOut( __METHOD__ ); |
| 919 | + |
892 | 920 | return $comment; |
893 | 921 | } |
894 | 922 | |
— | — | @@ -912,7 +940,7 @@ |
913 | 941 | return " <span class=\"comment\">($formatted)</span>"; |
914 | 942 | } |
915 | 943 | } |
916 | | - |
| 944 | + |
917 | 945 | /** |
918 | 946 | * Wrap and format the given revision's comment block, if the current |
919 | 947 | * user is allowed to view it. |