/**
  * @dataProvider convertAsInfoboxProvider
  */
 public function testConvertAsInfobox($content, $expected, $comment)
 {
     $mockTitle = $this->getMock('Title');
     $templateConverter = new TemplateConverter($mockTitle);
     $result = $templateConverter->convertAsInfobox($content);
     $this->assertSame($result, $expected, $comment);
 }
 /**
  * Get the converted infobox markup of a given template.
  *
  * @requestParam string template The name of the template to convert.
  */
 public function getInfoboxMarkup()
 {
     $this->response->setFormat(WikiaResponse::FORMAT_JSON);
     $templateName = $this->request->getVal('template');
     $title = Title::newFromText($templateName, NS_TEMPLATE);
     if (!$title instanceof Title || !$title->exists() || !$title->inNamespace(NS_TEMPLATE)) {
         $this->response->setVal('error', wfMessage('templatedraft-invalid-template')->escaped());
         return;
     }
     $templateConverter = new TemplateConverter($title);
     $revision = Revision::newFromTitle($title);
     $content = $revision->getText();
     $infoboxVariables = $templateConverter->getTemplateVariables($content);
     $infoboxContent = $templateConverter->convertAsInfobox($content);
     $this->response->setValues(['variables' => $infoboxVariables, 'content' => $infoboxContent]);
 }
 /**
  * Triggered if a user edits a Draft subpage of a template.
  * It pre-fills the content of the Draft with a converted markup.
  * @param $text
  * @param Title $title
  * @return bool
  */
 public static function onEditFormPreloadText(&$text, Title $title)
 {
     $helper = new TemplateDraftHelper();
     if ($helper->isTitleNewDraft($title) && TemplateConverter::isConversion()) {
         $parentTitleId = $helper->getParentTitle($title)->getArticleID();
         if ($parentTitleId > 0) {
             $parentContent = WikiPage::newFromID($parentTitleId)->getText();
             /**
              * TODO: Introduce a parameter to modify conversion flags
              * If you want to perform different conversions, not only the infobox one,
              * you can introduce a URL parameter to control the binary sum of flags.
              */
             $controller = new TemplateDraftController();
             $text = $controller->createDraftContent($title, $parentContent, TemplateClassificationController::TEMPLATE_INFOBOX);
         }
     }
     return true;
 }
Beispiel #4
0
function upgradeDCEFiles($argv, $instanceUpgradePath)
{
    //copy and update following files from upgrade package
    $upgradeTheseFiles = array('cron.php', 'download.php', 'index.php', 'install.php', 'soap.php', 'sugar_version.php', 'vcal_server.php');
    foreach ($upgradeTheseFiles as $file) {
        $srcFile = clean_path("{$instanceUpgradePath}/{$file}");
        $destFile = clean_path("{$argv[3]}/{$file}");
        if (file_exists($srcFile)) {
            if (!is_dir(dirname($destFile))) {
                mkdir_recursive(dirname($destFile));
                // make sure the directory exists
            }
            copy_recursive($srcFile, $destFile);
            $_GET['TEMPLATE_PATH'] = $destFile;
            $_GET['CONVERT_FILE_ONLY'] = true;
            if (!class_exists('TemplateConverter')) {
                include $argv[7] . 'templateConverter.php';
            } else {
                TemplateConverter::convertFile($_GET['TEMPLATE_PATH']);
            }
        }
    }
}