Пример #1
0
 function getImageInfoWidget($title)
 {
     global $wgUser, $wgOut;
     $sk = $wgUser->getSkin();
     $t = Title::newFromText('Image-Templates', NS_CATEGORY);
     if ($t) {
         $cv = new WikihowCategoryViewer($t);
         $cv->clearCategoryState();
         $cv->doQuery();
         $templates = array();
         foreach ($cv->articles as $article) {
             $start = strrpos($article, 'title="Template:');
             if ($start > 0) {
                 $end = strrpos($article, '"', $start + 16 + 1);
                 if ($end > 0) {
                     $templates[] = strtolower(str_replace(' ', '-', substr($article, $start + 16, $end - $start - 16)));
                 }
             }
         }
         $license = '';
         $content = preg_replace_callback('@({{([^}|]+)(\\|[^}]*)?}})@', function ($m) use($templates, &$license) {
             $name = trim(strtolower($m[2]));
             $name = str_replace(' ', '-', $name);
             foreach ($templates as $template) {
                 if ($name == $template) {
                     $license .= $m[0];
                     return '';
                 }
             }
             return $m[1];
         }, $this->getContent());
     }
     $lastUser = $this->current->getUser();
     $userLink = $sk->makeLinkObj(Title::makeTitle(NS_USER, $lastUser), $lastUser);
     $html = "<div id='im-info' style='word-wrap: break-word;'>";
     $html .= $wgOut->parse("=== Licensing / Attribution === \n" . $license) . "<p>" . wfMsg('image_upload', $userLink) . "</p><br />";
     //now remove old licensing header
     $content = str_replace("== Licensing ==", "", $content);
     $content = str_replace("== Summary ==", "=== Summary ===", $content);
     $content = trim($content);
     if (strlen($content) > 0 && substr($content, 0, 1) != "=") {
         $content = "=== Summary === \n" . $content;
     } else {
     }
     $html .= $wgOut->parse($content);
     $html .= "</div>";
     return $html;
 }