Index: trunk/extensions/ParserDiffTest/ParserDiffTest_body.php |
— | — | @@ -0,0 +1,136 @@ |
| 2 | +<?php |
| 3 | +class ParserDiffTest extends SpecialPage |
| 4 | +{ |
| 5 | + function ParserDiffTest() { |
| 6 | + wfLoadExtensionMessages( 'ParserDiffTest' ); |
| 7 | + SpecialPage::SpecialPage("ParserDiffTest"); |
| 8 | + } |
| 9 | + |
| 10 | + function execute( $subpage ) { |
| 11 | + global $wgRequest, $wgOut, $wgPDT_OldConf, $wgPDT_NewConf; |
| 12 | + |
| 13 | + $this->setHeaders(); |
| 14 | + |
| 15 | + $getText = $wgRequest->getBool( 'pdt_get_text' ); |
| 16 | + if ( $getText ) { |
| 17 | + $subpage = $wgRequest->getText( 'pdt_title' ); |
| 18 | + } |
| 19 | + |
| 20 | + if ( strval( $subpage ) === '' ) { |
| 21 | + $title = Title::newFromText( $wgRequest->getVal( 'pdt_title' ) ); |
| 22 | + if ( !$title ) { |
| 23 | + $title = Title::newMainPage(); |
| 24 | + } |
| 25 | + $text = $wgRequest->getVal( 'pdt_input' ); |
| 26 | + $this->showForm( $title->getPrefixedText(), $text ); |
| 27 | + $comparing = ''; |
| 28 | + } else { |
| 29 | + $title = Title::newFromText( $subpage ); |
| 30 | + if ( !$title ) { |
| 31 | + $wgOut->addWikiText( wfMsg( 'pdtest_no_target' ) ); |
| 32 | + return; |
| 33 | + } |
| 34 | + |
| 35 | + if ( !$title->userCanRead() ) { |
| 36 | + $wgOut->addWikiText( wfMsg( 'pdtest_access_denied' ) ); |
| 37 | + return; |
| 38 | + } |
| 39 | + |
| 40 | + $revision = Revision::newFromTitle( $title ); |
| 41 | + $text = $revision ? $revision->getText() : false; |
| 42 | + if ( $text === false ){ |
| 43 | + $wgOut->addWikiText( wfMsg( 'pdtest_page_missing' ) ); |
| 44 | + return; |
| 45 | + } |
| 46 | + |
| 47 | + $comparing = wfMsg( 'pdt_comparing_page', htmlspecialchars( $title->getPrefixedText() ) ); |
| 48 | + } |
| 49 | + |
| 50 | + $oldClass = $wgPDT_OldConf['class']; |
| 51 | + $newClass = $wgPDT_NewConf['class']; |
| 52 | + $oldParser = new $oldClass( $wgPDT_OldConf ); |
| 53 | + $newParser = new $newClass( $wgPDT_NewConf ); |
| 54 | + |
| 55 | + |
| 56 | + $oldParser->firstCallInit(); |
| 57 | + $newParser->firstCallInit(); |
| 58 | + |
| 59 | + if ( $wgRequest->getBool( 'timing' ) ) { |
| 60 | + // Preload caches |
| 61 | + $newResult = $this->parse( $newParser, $text, $title ); |
| 62 | + $oldResult = $this->parse( $oldParser, $text, $title ); |
| 63 | + |
| 64 | + // Timing run |
| 65 | + $oldTime = -microtime( true ); |
| 66 | + $oldResult = $this->parse( $oldParser, $text, $title ); |
| 67 | + $oldTime += microtime( true ); |
| 68 | + |
| 69 | + $newTime = -microtime( true ); |
| 70 | + $newResult = $this->parse( $newParser, $text, $title ); |
| 71 | + $newTime += microtime( true ); |
| 72 | + $timeReport = wfMsg( 'pdtest_time_report', |
| 73 | + $oldClass, sprintf( "%.3f", $oldTime ), $newClass, sprintf( "%.3f", $newTime ) ); |
| 74 | + } else { |
| 75 | + $newResult = $this->parse( $newParser, $text, $title ); |
| 76 | + $oldResult = $this->parse( $oldParser, $text, $title ); |
| 77 | + $timeReport = ''; |
| 78 | + } |
| 79 | + |
| 80 | + if ( $oldResult === $newResult ) { |
| 81 | + $diff = wfMsgHtml( 'pdtest_no_changes' ); |
| 82 | + $sideBySide = false; |
| 83 | + } else { |
| 84 | + $diffEngine = new DifferenceEngine; |
| 85 | + $diffEngine->showDiffStyle(); |
| 86 | + $diffBody = $diffEngine->generateDiffBody( $oldResult, $newResult ); |
| 87 | + $diff = DifferenceEngine::addHeader( $diffBody, "<strong>$oldClass</strong>", "<strong>$newClass</strong>" ); |
| 88 | + |
| 89 | + $sideBySide = '<table class="wikitable" width="100%">' . |
| 90 | + '<col width="50%"/>' . |
| 91 | + '<col width="50%"/>' . |
| 92 | + '<tr><th>' . htmlspecialchars( $oldClass ) . '</th>' . |
| 93 | + '<th>' . htmlspecialchars( $newClass ) . '</th></tr>' . |
| 94 | + '<tr>' . |
| 95 | + '<td><div style="overflow: auto">' . $oldResult . '</div></td>' . |
| 96 | + '<td><div style="overflow: auto">' . $newResult . '</div></td>' . |
| 97 | + '</tr></table>'; |
| 98 | + } |
| 99 | + |
| 100 | + |
| 101 | + $wgOut->addHTML( |
| 102 | + "<div class='pdt-comparing'>$comparing</div>\n" . |
| 103 | + "<div class='pdt-time-report'>$timeReport</div>\n" . |
| 104 | + "<h2>" . wfMsgHtml( 'pdtest_diff' ) . "</h2>\n" . |
| 105 | + "<div class='pdt-diff'>$diff</div>\n" . |
| 106 | + ( $sideBySide ? ( |
| 107 | + "<h2>" . wfMsgHtml( 'pdtest_side_by_side' ) . "</h2>\n" . |
| 108 | + "<div class='pdt-side-by-side'>$sideBySide</div>\n" |
| 109 | + ) : '' ) |
| 110 | + ); |
| 111 | + } |
| 112 | + |
| 113 | + function parse( $parser, $text, $title ) { |
| 114 | + $options = new ParserOptions; |
| 115 | + $options->setTidy( true ); |
| 116 | + $output = $parser->parse( $text, $title, $options ); |
| 117 | + return $output->getText(); |
| 118 | + } |
| 119 | + |
| 120 | + function showForm( $title, $text ) { |
| 121 | + global $wgOut; |
| 122 | + |
| 123 | + $form = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->getTitle()->getLocalUrl() ) ); |
| 124 | + $form .= "<fieldset>\n"; |
| 125 | + $form .= '<p>' . Xml::inputLabel( wfMsgNoTrans( 'pdtest_title' ), 'pdt_title', 'pdt_title', 60, $title ) . '</p>'; |
| 126 | + $form .= '<p>' . Xml::label( wfMsg( 'pdtest_text' ), 'pdt_input' ) . '</p>'; |
| 127 | + $form .= Xml::openElement( 'textarea', array( 'name' => 'pdt_input', 'id' => 'pdt_input', 'rows' => 10, 'cols' => 10 ) ); |
| 128 | + $form .= htmlspecialchars( $text ); |
| 129 | + $form .= Xml::closeElement( 'textarea' ); |
| 130 | + $form .= '<p>' . Xml::submitButton( wfMsg( 'pdtest_ok' ) ) . ' ' . |
| 131 | + Xml::submitButton( wfMsg( 'pdtest_get_text' ), array( 'name' => 'pdt_get_text' ) ) . '</p>'; |
| 132 | + $form .= "</fieldset>\n"; |
| 133 | + $form .= Xml::closeElement( 'form' ); |
| 134 | + $wgOut->addHTML( $form ); |
| 135 | + } |
| 136 | +} |
| 137 | + |
Property changes on: trunk/extensions/ParserDiffTest/ParserDiffTest_body.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 138 | + native |
Index: trunk/extensions/ParserDiffTest/ParserDiffTest.i18n.php |
— | — | @@ -0,0 +1,18 @@ |
| 2 | +<?php |
| 3 | +$messages = array( |
| 4 | + 'en' => array( |
| 5 | + 'parserdifftest' => 'Parser diff test', |
| 6 | + 'pdtest_no_target' => 'No target specified.', |
| 7 | + 'pdtest_page_missing' => 'The specified page was not found in the database.', |
| 8 | + 'pdtest_no_changes' => 'No changes detected.', |
| 9 | + 'pdtest_time_report' => '<b>$1</b> took $2 seconds, <b>$3</b> took $4 seconds.', |
| 10 | + 'pdtest_title' => 'Context title:', |
| 11 | + 'pdtest_text' => 'Input text:', |
| 12 | + 'pdtest_ok' => 'OK', |
| 13 | + 'pdtest_get_text' => 'Get text from page', |
| 14 | + 'pdtest_diff' => 'Differences', |
| 15 | + 'pdtest_side_by_side' => 'Output comparison', |
| 16 | + 'pdt_comparing_page' => 'Comparing parser output from [[$1]]', |
| 17 | + ) |
| 18 | +); |
| 19 | + |
Property changes on: trunk/extensions/ParserDiffTest/ParserDiffTest.i18n.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 20 | + native |
Index: trunk/extensions/ParserDiffTest/ParserDiffTest.php |
— | — | @@ -0,0 +1,18 @@ |
| 2 | +<?php |
| 3 | +# Not a valid entry point, skip unless MEDIAWIKI is defined |
| 4 | +if (!defined('MEDIAWIKI')) { |
| 5 | + echo <<<EOT |
| 6 | +To install ParserDiffTest, put the following line in LocalSettings.php: |
| 7 | +require_once( "\$IP/extensions/ParserDiffTest/ParserDiffTest.php" ); |
| 8 | +EOT; |
| 9 | + exit( 1 ); |
| 10 | +} |
| 11 | + |
| 12 | +$wgAutoloadClasses['ParserDiffTest'] = dirname(__FILE__) . '/ParserDiffTest_body.php'; |
| 13 | +$wgExtensionMessagesFiles['ParserDiffTest'] = dirname(__FILE__).'/ParserDiffTest.i18n.php'; |
| 14 | +$wgSpecialPages['ParserDiffTest'] = 'ParserDiffTest'; |
| 15 | + |
| 16 | + |
| 17 | +$wgPDT_OldConf = array( 'class' => 'Parser_OldPP' ); |
| 18 | +$wgPDT_NewConf = array( 'class' => 'Parser' ); |
| 19 | + |
Property changes on: trunk/extensions/ParserDiffTest/ParserDiffTest.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 20 | + native |