From: jeblad Date: Fri, 15 Jun 2012 09:40:40 +0000 (+0200) Subject: Added a hook for formatting autocomments X-Git-Tag: 1.31.0-rc.0~23315 X-Git-Url: https://git.cyclocoop.org/%28%28?a=commitdiff_plain;h=631e79d55618b24e75ac8b24e0ca18756cff1b1a;p=lhc%2Fweb%2Fwiklou.git Added a hook for formatting autocomments Removed some spurious whitespace Changed how wfRunHooks are used, and also the test for default formatting Change-Id: I4c3fc1080f83166d7b89aeb9a1487e173e9ccb65 --- diff --git a/docs/hooks.txt b/docs/hooks.txt index c1fd5fac99..147e524242 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -930,6 +930,14 @@ $fileVersions: array of undeleted versions. Empty if all versions were restored $user: user who performed the undeletion $reason: reason +'FormatAutocomments': When an autocomment is formatted by the Linker + &$comment: Reference to the accumulated comment. Initially null, when set the default code will be skipped. + $pre: Initial part of the parsed comment before the call to the hook. + $auto: The extracted part of the parsed comment before the call to the hook. + $post: The final part of the parsed comment before the call to the hook. + $title: An optional title object used to links to sections. Can be null. + $local: Boolean indicating whether section links should refer to local page. + 'GetAutoPromoteGroups': When determining which autopromote groups a user is entitled to be in. &$user: user to promote. diff --git a/includes/Linker.php b/includes/Linker.php index 35b6a8f0a5..9fcac6580f 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -1216,41 +1216,45 @@ class Linker { $pre = $match[1]; $auto = $match[2]; $post = $match[3]; - $link = ''; - if ( $title ) { - $section = $auto; - - # Remove links that a user may have manually put in the autosummary - # This could be improved by copying as much of Parser::stripSectionName as desired. - $section = str_replace( '[[:', '', $section ); - $section = str_replace( '[[', '', $section ); - $section = str_replace( ']]', '', $section ); - - $section = Sanitizer::normalizeSectionNameWhitespace( $section ); # bug 22784 - if ( $local ) { - $sectionTitle = Title::newFromText( '#' . $section ); - } else { - $sectionTitle = Title::makeTitleSafe( $title->getNamespace(), - $title->getDBkey(), $section ); + $comment = null; + wfRunHooks( 'FormatAutocomments', array( &$comment, $pre, $auto, $post, $title, $local ) ); + if ( $comment === null ) { + $link = ''; + if ( $title ) { + $section = $auto; + + # Remove links that a user may have manually put in the autosummary + # This could be improved by copying as much of Parser::stripSectionName as desired. + $section = str_replace( '[[:', '', $section ); + $section = str_replace( '[[', '', $section ); + $section = str_replace( ']]', '', $section ); + + $section = Sanitizer::normalizeSectionNameWhitespace( $section ); # bug 22784 + if ( $local ) { + $sectionTitle = Title::newFromText( '#' . $section ); + } else { + $sectionTitle = Title::makeTitleSafe( $title->getNamespace(), + $title->getDBkey(), $section ); + } + if ( $sectionTitle ) { + $link = self::link( $sectionTitle, + $wgLang->getArrow(), array(), array(), + 'noclasses' ); + } else { + $link = ''; + } } - if ( $sectionTitle ) { - $link = self::link( $sectionTitle, - $wgLang->getArrow(), array(), array(), - 'noclasses' ); - } else { - $link = ''; + if ( $pre ) { + # written summary $presep autocomment (summary /* section */) + $pre .= wfMsgExt( 'autocomment-prefix', array( 'escapenoentities', 'content' ) ); } + if ( $post ) { + # autocomment $postsep written summary (/* section */ summary) + $auto .= wfMsgExt( 'colon-separator', array( 'escapenoentities', 'content' ) ); + } + $auto = '' . $auto . ''; + $comment = $pre . $link . $wgLang->getDirMark() . '' . $auto . $post . ''; } - if ( $pre ) { - # written summary $presep autocomment (summary /* section */) - $pre .= wfMsgExt( 'autocomment-prefix', array( 'escapenoentities', 'content' ) ); - } - if ( $post ) { - # autocomment $postsep written summary (/* section */ summary) - $auto .= wfMsgExt( 'colon-separator', array( 'escapenoentities', 'content' ) ); - } - $auto = '' . $auto . ''; - $comment = $pre . $link . $wgLang->getDirMark() . '' . $auto . $post . ''; return $comment; }