Example #1
0
 /**
  * The pattern for autogen comments is / * foo * /, which makes for
  * some nasty regex.
  * We look for all comments, match any text before and after the comment,
  * add a separator where needed and format the comment itself with CSS
  * Called by Linker::formatComment.
  *
  * @param string $comment Comment text
  * @param object $title An optional title object used to links to sections
  * @return string $comment formatted comment
  *
  * @todo Document the $local parameter.
  */
 private function formatAutocomments($comment, $title = NULL, $local = false)
 {
     $match = array();
     while (preg_match('!(.*)/\\*\\s*(.*?)\\s*\\*/(.*)!', $comment, $match)) {
         $pre = $match[1];
         $auto = $match[2];
         $post = $match[3];
         $link = '';
         if ($title) {
             $section = $auto;
             # Generate a valid anchor name from the section title.
             # Hackish, but should generally work - we strip wiki
             # syntax, including the magic [[: that is used to
             # "link rather than show" in case of images and
             # interlanguage links.
             $section = str_replace('[[:', '', $section);
             $section = str_replace('[[', '', $section);
             $section = str_replace(']]', '', $section);
             if ($local) {
                 $sectionTitle = Title::newFromText('#' . $section);
             } else {
                 $sectionTitle = wfClone($title);
                 $sectionTitle->mFragment = $section;
             }
             $link = $this->makeKnownLinkObj($sectionTitle, wfMsgForContent('sectionlink'));
         }
         $auto = $link . $auto;
         if ($pre) {
             $auto = '- ' . $auto;
             # written summary $presep autocomment (summary /* section */)
         }
         if ($post) {
             $auto .= ': ';
             # autocomment $postsep written summary (/* section */ summary)
         }
         $auto = '<span class="autocomment">' . $auto . '</span>';
         $comment = $pre . $auto . $post;
     }
     return $comment;
 }
Example #2
0
 /**
  * This function is called by all recent changes variants, by the page history,
  * and by the user contributions list. It is responsible for formatting edit
  * comments. It escapes any HTML in the comment, but adds some CSS to format
  * auto-generated comments (from section editing) and formats [[wikilinks]].
  *
  * The $title parameter must be a title OBJECT. It is used to generate a
  * direct link to the section in the autocomment.
  * @author Erik Moeller <*****@*****.**>
  *
  * Note: there's not always a title to pass to this function.
  * Since you can't set a default parameter for a reference, I've turned it
  * temporarily to a value pass. Should be adjusted further. --brion
  */
 function formatComment($comment, $title = NULL)
 {
     $fname = 'Linker::formatComment';
     wfProfileIn($fname);
     global $wgContLang;
     $comment = str_replace("\n", " ", $comment);
     $comment = htmlspecialchars($comment);
     # The pattern for autogen comments is / * foo * /, which makes for
     # some nasty regex.
     # We look for all comments, match any text before and after the comment,
     # add a separator where needed and format the comment itself with CSS
     while (preg_match('/(.*)\\/\\*\\s*(.*?)\\s*\\*\\/(.*)/', $comment, $match)) {
         $pre = $match[1];
         $auto = $match[2];
         $post = $match[3];
         $link = '';
         if ($title) {
             $section = $auto;
             # Generate a valid anchor name from the section title.
             # Hackish, but should generally work - we strip wiki
             # syntax, including the magic [[: that is used to
             # "link rather than show" in case of images and
             # interlanguage links.
             $section = str_replace('[[:', '', $section);
             $section = str_replace('[[', '', $section);
             $section = str_replace(']]', '', $section);
             $sectionTitle = wfClone($title);
             $sectionTitle->mFragment = $section;
             $link = $this->makeKnownLinkObj($sectionTitle, wfMsg('sectionlink'));
         }
         $sep = '-';
         $auto = $link . $auto;
         if ($pre) {
             $auto = $sep . ' ' . $auto;
         }
         if ($post) {
             $auto .= ' ' . $sep;
         }
         $auto = '<span class="autocomment">' . $auto . '</span>';
         $comment = $pre . $auto . $post;
     }
     # format regular and media links - all other wiki formatting
     # is ignored
     $medians = $wgContLang->getNsText(NS_MEDIA) . ':';
     while (preg_match('/\\[\\[(.*?)(\\|(.*?))*\\]\\](.*)$/', $comment, $match)) {
         # Handle link renaming [[foo|text]] will show link as "text"
         if ("" != $match[3]) {
             $text = $match[3];
         } else {
             $text = $match[1];
         }
         if (preg_match('/^' . $medians . '(.*)$/i', $match[1], $submatch)) {
             # Media link; trail not supported.
             $linkRegexp = '/\\[\\[(.*?)\\]\\]/';
             $thelink = $this->makeMediaLink($submatch[1], "", $text);
         } else {
             # Other kind of link
             if (preg_match($wgContLang->linkTrail(), $match[4], $submatch)) {
                 $trail = $submatch[1];
             } else {
                 $trail = "";
             }
             $linkRegexp = '/\\[\\[(.*?)\\]\\]' . preg_quote($trail, '/') . '/';
             if ($match[1][0] == ':') {
                 $match[1] = substr($match[1], 1);
             }
             $thelink = $this->makeLink($match[1], $text, "", $trail);
         }
         $comment = preg_replace($linkRegexp, wfRegexReplacement($thelink), $comment, 1);
     }
     wfProfileOut($fname);
     return $comment;
 }