/** setup a basic parser object */
 protected function setUp()
 {
     parent::setUp();
     $contLang = Language::factory('en');
     $this->setMwGlobals(array('wgLanguageCode' => 'en', 'wgContLang' => $contLang));
     $this->testParser = new Parser();
     $this->testParser->Options(ParserOptions::newFromUserAndLang(new User(), $contLang));
     # initialize parser output
     $this->testParser->clearState();
     # Needs a title to do magic word stuff
     $title = Title::newFromText('Tests');
     $title->mRedirect = false;
     # Else it needs a db connection just to check if it's a redirect (when deciding the page language)
     $this->testParser->setTitle($title);
 }
 function setUp()
 {
     global $wgTitle, $wgParser;
     $wgParser = new Parser();
     $wgParser->Options(new ParserOptions());
     $wgParser->clearState();
     $wgParser->setTitle($wgTitle);
 }
Exemple #3
0
 /**
  * @dataProvider parametersProvider
  * @since 2.0
  * @param array $parameters
  */
 public function testRender(array $parameters)
 {
     $parserHook = $this->getInstance();
     $parser = new \Parser();
     $parser->mOptions = new \ParserOptions();
     $parser->clearState();
     $parser->setTitle(\Title::newMainPage());
     $renderResult = $parserHook->renderTag(null, $parameters, $parser);
     $this->assertInternalType('string', $renderResult);
 }
Exemple #4
0
 /**
  * Triggers the render process with different sets of parameters to see if
  * no errors or notices are thrown and the result indeed is a string.
  *
  * @dataProvider parametersProvider
  * @since 2.0
  * @param array $parameters
  * @param string|null $expected
  */
 public function testRender(array $parameters, $expected = null)
 {
     $parserHook = $this->getInstance();
     $parser = new \Parser();
     $parser->mOptions = new \ParserOptions();
     $parser->clearState();
     $parser->setTitle(\Title::newMainPage());
     $renderResult = call_user_func_array(array($parserHook, 'renderFunction'), array_merge(array(&$parser), $parameters));
     if (is_string($renderResult)) {
         $this->assertTrue(true);
     } else {
         $this->assertInternalType('array', $renderResult);
         $this->assertInternalType('string', $renderResult[0]);
     }
     if ($expected !== null) {
         $this->assertEquals($expected, $renderResult[0]);
     }
 }
Exemple #5
0
function meaneditor_wiki2html($article, $user, &$edit_context, &$wiki_text)
{
    global $wgUploadPath, $wgArticlePath;
    wfLoadExtensionMessages('MeanEditor');
    $meaneditor_page_src = str_replace('$1', '', $wgArticlePath);
    # Detect code sections (lines beginning with whitespace)
    if (preg_match('/^[ \\t]/m', $wiki_text)) {
        return deny_visual_because_of(wfMsg('reason_whitespace'), $edit_context);
    }
    # Detect custom tags: only <br />, super/sub-scripts and references are supported at the moment
    # TODO: expand the safe list
    # Especially problematic tags (do not even think about supporting them):
    #      <p>  (would require special handling to disable normal paragraphing, confusing)
    #      <h*> (for headings not in TOC, strange closing tag)
    #      <b>,<i> (not to be confused with ''emphasis'' as <em>)
    #      <pre>, <nowiki> (if something gets implemented, better be the common leading spaces)
    $wiki_text = str_replace('<br />', '__TEMP__TEMP__br', $wiki_text);
    $wiki_text = str_replace('<br>', '__TEMP__TEMP__br', $wiki_text);
    $wiki_text = str_replace('<references />', '__TEMP__TEMP__allreferences', $wiki_text);
    $wiki_text = str_replace('<ref>', '__TEMP__TEMP__ref', $wiki_text);
    $wiki_text = str_replace('</ref>', '__TEMP__TEMP__cref', $wiki_text);
    $wiki_text = str_replace('<sup>', '__TEMP__TEMP__sup', $wiki_text);
    $wiki_text = str_replace('</sup>', '__TEMP__TEMP__csup', $wiki_text);
    $wiki_text = str_replace('<sub>', '__TEMP__TEMP__sub', $wiki_text);
    $wiki_text = str_replace('</sub>', '__TEMP__TEMP__csub', $wiki_text);
    if (!(strpos($wiki_text, '<') === FALSE && strpos($wiki_text, '>') === FALSE)) {
        return deny_visual_because_of(wfMsg('reason_tag'), $edit_context);
    }
    $wiki_text = str_replace('__TEMP__TEMP__br', '<br />', $wiki_text);
    $wiki_text = str_replace('__TEMP__TEMP__allreferences', 'references_here', $wiki_text);
    $wiki_text = str_replace('__TEMP__TEMP__sup', '<sup>', $wiki_text);
    $wiki_text = str_replace('__TEMP__TEMP__csup', '</sup>', $wiki_text);
    $wiki_text = str_replace('__TEMP__TEMP__sub', '<sub>', $wiki_text);
    $wiki_text = str_replace('__TEMP__TEMP__csub', '</sub>', $wiki_text);
    $wiki_text = str_replace('__TEMP__TEMP__ref', '<ref>', $wiki_text);
    $wiki_text = str_replace('__TEMP__TEMP__cref', '</ref>', $wiki_text);
    # This characters are problematic only at line beginning
    $unwanted_chars_at_beginning = array(':', ';');
    foreach ($unwanted_chars_at_beginning as $uc) {
        if (preg_match('/^' . $uc . '/m', $wiki_text)) {
            return deny_visual_because_of(wfMsg('reason_indent', $uc), $edit_context);
        }
    }
    # <hr>, from Parser.php... TODO: other regexps can be directly stolen from there
    $wiki_text = preg_replace('/(^|\\n)-----*/', '\\1<hr />', $wiki_text);
    #Collapse multiple newlines
    # TODO: Compare Wikipedia:Don't_use_line_breaks
    $wiki_text = preg_replace("/\n\n+/", "\n\n", $wiki_text);
    $wiki_text = preg_replace('/^(.+?)$/m', '<p>$1</p>', $wiki_text);
    #$wiki_text=preg_replace('/\'\'\'(.*?)\'\'\'/','<strong>$1</strong>',$wiki_text);
    #$wiki_text=preg_replace('/\'\'(.*?)\'\'/','<em>$1</em>',$wiki_text);
    $obp = new Parser();
    $obp->clearState();
    $obp->setTitle('');
    $obp->mOptions = new ParserOptions();
    $wiki_text = $obp->doAllQuotes($wiki_text);
    #Substitute ===
    $wiki_text = preg_replace('/(?:<p>|)\\s*===(.*?)===\\s*(?:<\\/p>|)/', '<h3>\\1</h3>', $wiki_text);
    #Substitute ==
    $wiki_text = preg_replace('/(?:<p>|)\\s*==(.*?)==\\s*(?:<\\/p>|)/', '<h2>\\1</h2>', $wiki_text);
    #Substitute [[Image:a]]
    #FIXME: do not require $wgHashedUploadDirectory	= false
    $wiki_text = preg_replace('/\\[\\[Image:(.*?)\\]\\]/', '<img alt="\\1" src="' . $wgUploadPath . '/\\1" />', $wiki_text);
    #Create [[a|b]] syntax for every link
    #TODO: What to do for the [[word (detailed disambiguation)|]] 'pipe trick'?
    $wiki_text = preg_replace('/\\[\\[([^|]*?)\\]\\]/', '[[\\1|\\1]]', $wiki_text);
    #Substitute [[ syntax (internal links)
    if (preg_match('/\\[\\[([^|\\]]*?):(.*?)\\|(.*?)\\]\\]/', $wiki_text, $unwanted_matches)) {
        return deny_visual_because_of(wfMsg('reason_special_link', $unwanted_matches[0]), $edit_context);
    }
    #Preserve #section links from the draconic feature detection
    $wiki_text = preg_replace_callback('/\\[\\[(.*?)\\|(.*?)\\]\\]/', create_function('$matches', 'return "[[".str_replace("#","__TEMP_MEAN_hash",$matches[1])."|".str_replace("#","__TEMP_MEAN_hash",$matches[2])."]]";'), $wiki_text);
    $wiki_text = preg_replace_callback('/<a href="(.*?)">/', create_function('$matches', 'return "<a href=\\"".str_replace("#","__TEMP_MEAN_hash",$matches[1])."\\">";'), $wiki_text);
    $wiki_text = preg_replace('/\\[\\[(.*?)\\|(.*?)\\]\\]/', '<a href="' . $meaneditor_page_src . '\\1">\\2</a>', $wiki_text);
    #Create [a b] syntax for every link
    #(must be here, so that internal links have already been replaced)
    $wiki_text = preg_replace('/\\[([^| ]*?)\\]/', '[\\1 _autonumber_]', $wiki_text);
    #Substitute [ syntax (external links)
    $wiki_text = preg_replace('/\\[(.*?) (.*?)\\]/', '<a href="\\1">\\2</a>', $wiki_text);
    #Lists support
    $wiki_text = preg_replace("/<p># (.*?)<\\/p>/", '<ol><li>\\1</li></ol>', $wiki_text);
    $wiki_text = preg_replace("/<p>\\* (.*?)<\\/p>/", '<ul><li>\\1</li></ul>', $wiki_text);
    $wiki_text = preg_replace("/<\\/ol>\n<ol>/", "\n", $wiki_text);
    $wiki_text = preg_replace("/<\\/ul>\n<ul>/", "\n", $wiki_text);
    # Crude but safe detection of unsupported features
    # In the future, this could be loosened a lot, should also detect harmless uses
    # TODO: Compare with MediaWiki security policy, ensure no mediawiki code can create unsafe HTML in the editor
    # Allow numbered entities, these occur far too often and should be innocous
    $wiki_text = str_replace('&#', '__TEMP__MEAN__nument', $wiki_text);
    $unwanted_chars = array('[', ']', '|', '{', '}', '#', '*');
    foreach ($unwanted_chars as $uc) {
        if (!($unwanted_match = strpos($wiki_text, $uc) === FALSE)) {
            return deny_visual_because_of(wfMsg('reason_forbidden_char', $uc), $edit_context);
        }
    }
    # Restore numbered entities
    $wiki_text = str_replace('__TEMP__MEAN__nument', '&#', $wiki_text);
    #<ref> support
    global $refs_div;
    global $refs_num;
    $refs_div = '';
    $refs_num = 0;
    $wiki_text = preg_replace_callback('/<ref>(.*?)<\\/ref>/', create_function('$matches', 'global $refs_div,$refs_num; $refs_num++; $refs_div=$refs_div."<p id=ref".$refs_num." class=\\"ref\\"> [".$refs_num."] ".
				$matches[1]."</p>"; return "<a href=\\"#ref".$refs_num."\\"> [".$refs_num."] </a>";'), $wiki_text);
    $refs_div = '<div class="ref">' . $refs_div . "</div>";
    # We saved #section links from the sacred detection fury, now restore them
    $wiki_text = str_replace("__TEMP_MEAN_hash", "#", $wiki_text);
    $wiki_text = $wiki_text . $refs_div;
    return false;
}
 /**
  * Unsets the approved revision for this page in the approved_revs DB
  * table; calls a "links update" on this page so that category
  * information can be stored correctly, as well as info for
  * extensions such as Semantic MediaWiki; and logs the action.
  */
 public static function unsetApproval($title)
 {
     global $egApprovedRevsBlankIfUnapproved;
     self::deleteRevisionApproval($title);
     $parser = new Parser();
     $parser->setTitle($title);
     if ($egApprovedRevsBlankIfUnapproved) {
         $text = '';
     } else {
         $text = self::getPageText($title);
     }
     $options = new ParserOptions();
     $parser->parse($text, $title, $options);
     $u = new LinksUpdate($title, $parser->getOutput());
     $u->doUpdate();
     self::setPageSearchText($title, $text);
     $log = new LogPage('approval');
     $log->addEntry('unapprove', $title, '');
     wfRunHooks('ApprovedRevsRevisionUnapproved', array($parser, $title));
 }
 public static function unsetApprovedFileInDB($title)
 {
     $parser = new Parser();
     $parser->setTitle($title);
     $fileTitle = $title->getDBkey();
     $dbr = wfGetDB(DB_MASTER);
     $dbr->delete('approved_revs_files', array('file_title' => $fileTitle));
     // the unapprove page method had LinksUpdate and Parser objects here, but the page text has
     // not changed at all with a file approval, so I don't think those are necessary.
     $log = new LogPage('approval');
     $log->addEntry('unapprove', $title, '');
     wfRunHooks('ApprovedRevsFileRevisionUnapproved', array($parser, $title));
 }
function drawDiagram(Parser $parser, PPFrame $frame)
{
    global $wgTitle;
    $sumEditing = 0;
    $pagesList = CDParameters::getInstance()->getPagesList();
    $pageWithChanges = array();
    foreach ($pagesList as $thisPageTitle) {
        $names = getPageEditorsFromDb($thisPageTitle);
        $changesForUsersForPage = getCountsOfEditing($names);
        $thisPageTitleKey = $thisPageTitle->getText();
        if ($thisPageTitle->getNsText() != "") {
            $thisPageTitleKey = $thisPageTitle->getNsText() . ":" . $thisPageTitleKey;
            // we can't use Title object this is a key with an array so we generate the Ns:Name key
        }
        $pageWithChanges[$thisPageTitleKey] = $changesForUsersForPage;
        $sumEditing += evaluateCountOfAllEdits($changesForUsersForPage);
    }
    $text = drawPreamble();
    foreach ($pageWithChanges as $thisPageTitleKey => $changesForUsersForPage) {
        $drawer = CDDrawerFactory::getDrawer($changesForUsersForPage, $sumEditing, $thisPageTitleKey);
        $text .= $drawer->draw();
    }
    $text .= "}</graphviz>";
    // $text = getPie($changesForUsers, $sumEditing, $thisPageTitle);
    $parser->disableCache();
    $parser->setTitle(Title::newFromText("Main_page"));
    $frame->getTitle(Title::newFromText("Main_page"));
    $text = $parser->recursiveTagParse($text, $frame);
    //this stuff just render my page
    return $text;
}