Esempio n. 1
0
 /**
  * @param $match
  * @return string
  */
 private static function formatAutocommentsCallback($match)
 {
     $title = self::$autocommentTitle;
     $local = self::$autocommentLocal;
     $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);
         }
         if ($sectionTitle) {
             $link = self::link($sectionTitle, htmlspecialchars(wfMsgForContent('sectionlink')), array(), array(), 'noclasses');
         } else {
             $link = '';
         }
     }
     $auto = "{$link}{$auto}";
     if ($pre) {
         # written summary $presep autocomment (summary /* section */)
         $auto = wfMsgExt('autocomment-prefix', array('escapenoentities', 'content')) . $auto;
     }
     if ($post) {
         # autocomment $postsep written summary (/* section */ summary)
         $auto .= wfMsgExt('colon-separator', array('escapenoentities', 'content'));
     }
     $auto = '<span class="autocomment">' . $auto . '</span>';
     $comment = $pre . $auto . $post;
     return $comment;
 }
Esempio n. 2
0
 /**
  * Same as guessSectionNameFromWikiText(), but produces legacy anchors
  * instead.  For use in redirects, since IE6 interprets Redirect: headers
  * as something other than UTF-8 (apparently?), resulting in breakage.
  *
  * @param string $text The section name
  * @return string An anchor
  */
 public function guessLegacySectionNameFromWikiText($text)
 {
     # Strip out wikitext links(they break the anchor)
     $text = $this->stripSectionName($text);
     $text = Sanitizer::normalizeSectionNameWhitespace($text);
     return '#' . Sanitizer::escapeId($text, array('noninitial', 'legacy'));
 }
Esempio n. 3
0
 /**
  * @param $match
  * @return string
  */
 private static function formatAutocommentsCallback($match)
 {
     global $wgLang;
     $title = self::$autocommentTitle;
     $local = self::$autocommentLocal;
     $pre = $match[1];
     $auto = $match[2];
     $post = $match[3];
     $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 ($pre) {
             # written summary $presep autocomment (summary /* section */)
             $pre .= wfMessage('autocomment-prefix')->inContentLanguage()->escaped();
         }
         if ($post) {
             # autocomment $postsep written summary (/* section */ summary)
             $auto .= wfMessage('colon-separator')->inContentLanguage()->escaped();
         }
         $auto = '<span class="autocomment">' . $auto . '</span>';
         $comment = $pre . $link . $wgLang->getDirMark() . '<span dir="auto">' . $auto . $post . '</span>';
     }
     return $comment;
 }
Esempio n. 4
0
File: Linker.php Progetto: paladox/2
 /**
  * Converts autogenerated comments in edit summaries into section links.
  *
  * 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 Title|null $title An optional title object used to links to sections
  * @param bool $local Whether section links should refer to local page
  * @param string|null $wikiId Id of the wiki to link to (if not the local wiki),
  *  as used by WikiMap.
  *
  * @return string Formatted comment (wikitext)
  */
 private static function formatAutocomments($comment, $title = null, $local = false, $wikiId = null)
 {
     // @todo $append here is something of a hack to preserve the status
     // quo. Someone who knows more about bidi and such should decide
     // (1) what sane rendering even *is* for an LTR edit summary on an RTL
     // wiki, both when autocomments exist and when they don't, and
     // (2) what markup will make that actually happen.
     $append = '';
     $comment = preg_replace_callback('!(?:(?<=(.)))?/\\*\\s*(.*?)\\s*\\*/(?:(?=(.)))?!', function ($match) use($title, $local, $wikiId, &$append) {
         global $wgLang;
         // Ensure all match positions are defined
         $match += array('', '', '', '');
         $pre = $match[1] !== '';
         $auto = $match[2];
         $post = $match[3] !== '';
         $comment = null;
         Hooks::run('FormatAutocomments', array(&$comment, $pre, $auto, $post, $title, $local, $wikiId));
         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 = Linker::makeCommentLink($sectionTitle, $wgLang->getArrow(), $wikiId, 'noclasses');
                 } else {
                     $link = '';
                 }
             }
             if ($pre) {
                 # written summary $presep autocomment (summary /* section */)
                 $pre = wfMessage('autocomment-prefix')->inContentLanguage()->escaped();
             }
             if ($post) {
                 # autocomment $postsep written summary (/* section */ summary)
                 $auto .= wfMessage('colon-separator')->inContentLanguage()->escaped();
             }
             $auto = '<span class="autocomment">' . $auto . '</span>';
             $comment = $pre . $link . $wgLang->getDirMark() . '<span dir="auto">' . $auto;
             $append .= '</span>';
         }
         return $comment;
     }, $comment);
     return $comment . $append;
 }
Esempio n. 5
0
 /**
  * @param $info array
  * @return FeedItem
  */
 private function createFeedItem($info)
 {
     $titleStr = $info['title'];
     $title = Title::newFromText($titleStr);
     if ($this->linkToDiffs && isset($info['revid'])) {
         $titleUrl = $title->getFullURL(array('diff' => $info['revid']));
     } else {
         $titleUrl = $title->getFullURL();
     }
     $comment = isset($info['comment']) ? $info['comment'] : null;
     // Create an anchor to section.
     // The anchor won't work for sections that have dupes on page
     // as there's no way to strip that info from ApiWatchlist (apparently?).
     // RegExp in the line below is equal to Linker::formatAutocomments().
     if ($this->linkToSections && $comment !== null && preg_match('!(.*)/\\*\\s*(.*?)\\s*\\*/(.*)!', $comment, $matches)) {
         global $wgParser;
         $sectionTitle = $wgParser->stripSectionName($matches[2]);
         $sectionTitle = Sanitizer::normalizeSectionNameWhitespace($sectionTitle);
         $titleUrl .= Title::newFromText('#' . $sectionTitle)->getFragmentForURL();
     }
     $timestamp = $info['timestamp'];
     $user = $info['user'];
     $completeText = "{$comment} ({$user})";
     return new FeedItem($titleStr, $completeText, $titleUrl, $timestamp, $user);
 }
 /**
  * @param array $info
  * @return FeedItem
  */
 private function createFeedItem($info)
 {
     if (!isset($info['title'])) {
         // Probably a revdeled log entry, skip it.
         return null;
     }
     $titleStr = $info['title'];
     $title = Title::newFromText($titleStr);
     $curidParam = array();
     if (!$title || $title->isExternal()) {
         // Probably a formerly-valid title that's now conflicting with an
         // interwiki prefix or the like.
         if (isset($info['pageid'])) {
             $title = Title::newFromId($info['pageid']);
             $curidParam = array('curid' => $info['pageid']);
         }
         if (!$title || $title->isExternal()) {
             return null;
         }
     }
     if (isset($info['revid'])) {
         $titleUrl = $title->getFullURL(array('diff' => $info['revid']));
     } else {
         $titleUrl = $title->getFullURL($curidParam);
     }
     $comment = isset($info['comment']) ? $info['comment'] : null;
     // Create an anchor to section.
     // The anchor won't work for sections that have dupes on page
     // as there's no way to strip that info from ApiWatchlist (apparently?).
     // RegExp in the line below is equal to Linker::formatAutocomments().
     if ($this->linkToSections && $comment !== null && preg_match('!(.*)/\\*\\s*(.*?)\\s*\\*/(.*)!', $comment, $matches)) {
         global $wgParser;
         $sectionTitle = $wgParser->stripSectionName($matches[2]);
         $sectionTitle = Sanitizer::normalizeSectionNameWhitespace($sectionTitle);
         $titleUrl .= Title::newFromText('#' . $sectionTitle)->getFragmentForURL();
     }
     $timestamp = $info['timestamp'];
     if (isset($info['user'])) {
         $user = $info['user'];
         $completeText = "{$comment} ({$user})";
     } else {
         $user = '';
         $completeText = (string) $comment;
     }
     return new FeedItem($titleStr, $completeText, $titleUrl, $timestamp, $user);
 }