http://www.mediawiki.org/wiki/Special:Code/MediaWiki/62483

Revision: 62483
Author:   avar
Date:     2010-02-14 22:30:32 +0000 (Sun, 14 Feb 2010)

Log Message:
-----------
Update Special:Eval: Include geshi via svn:externals & split out the 
SpecialEval class into a .class.php file

Modified Paths:
--------------
    trunk/extensions/Eval/SpecialEval.php

Added Paths:
-----------
    trunk/extensions/Eval/SpecialEval.class.php

Removed Paths:
-------------
    trunk/extensions/Eval/Makefile

Property Changed:
----------------
    trunk/extensions/Eval/


Property changes on: trunk/extensions/Eval
___________________________________________________________________
Added: svn:externals
   + geshi 
http://geshi.svn.sourceforge.net/svnroot/geshi/tags/RELEASE_1_0_8_6/geshi-1.0.X/src


Deleted: trunk/extensions/Eval/Makefile
===================================================================
--- trunk/extensions/Eval/Makefile      2010-02-14 22:20:27 UTC (rev 62482)
+++ trunk/extensions/Eval/Makefile      2010-02-14 22:30:32 UTC (rev 62483)
@@ -1,16 +0,0 @@
-help all:
-       @echo options:
-       @printf "\tinstall: get GeSHi from CVS into this directory\n"
-       @printf "\tupdate: update GeSHi from CVS\n"
-       @printf "\tclean: remove the GeSHi directory\n"
-       @printf "\thelp: this help message\n"
-install:
-       cvs -d:pserver:anonymous:@cvs.sourceforge.net:/cvsroot/geshi login
-       cvs -z3 -d:pserver:anonym...@cvs.sourceforge.net:/cvsroot/geshi co -P 
geshi-1.0.X
-       
-       mv geshi-1.0.X/src/ geshi
-       rm -rf geshi-1.0.X/
-update:
-       cd geshi/ && cvs up -dP
-clean:
-       rm -rf geshi/

Added: trunk/extensions/Eval/SpecialEval.class.php
===================================================================
--- trunk/extensions/Eval/SpecialEval.class.php                         (rev 0)
+++ trunk/extensions/Eval/SpecialEval.class.php 2010-02-14 22:30:32 UTC (rev 
62483)
@@ -0,0 +1,154 @@
+<?php
+if (!defined('MEDIAWIKI')) die();
+
+class SpecialEval extends SpecialPage {
+       public function __construct() {
+               SpecialPage::SpecialPage( 'Eval' );
+       }
+
+       function getDescription() {
+               return wfMsg( 'eval' );
+       }
+
+       public function execute( $par ) {
+               global $wgOut, $wgRequest, $wgUseTidy;
+               wfLoadExtensionMessages( 'Eval' );
+
+               $this->setHeaders();
+
+               $code = isset( $par ) ? $par : $wgRequest->getText( 'code' );
+               $escape = $wgRequest->getBool( 'escape' );
+
+               $eform = new EvaluateForm( $code, $escape );
+
+               if ( trim( $code ) === '' )
+                       $eform->execute();
+               else {
+                       $eform->execute();
+
+                       $eout = new EvaluateOutput( $code, $escape );
+                       $eout->execute();
+               }
+       }
+}
+
+class EvaluateForm {
+       private $mCode, $mEscape;
+
+       public function __construct( $code, $escape ) {
+               $this->mCode =& $code;
+               $this->mEscape =& $escape;
+       }
+
+       public function execute() {
+               global $wgOut, $wgTitle;
+
+               $wgOut->addHTML(
+                       Xml::openElement( 'form',
+                               array(
+                                       'id' => 'specialeval',
+                                       'method' => 'get',
+                                       'action' => $wgTitle->escapeLocalUrl()
+                               )
+                       ) .
+                               # Gotta use open and close here to
+                               # avoid <textarea /> which breaks
+                               Xml::openElement( 'textarea',
+                                       array(
+                                               'cols' => 40,
+                                               'rows' => 10,
+                                               'name' => 'code',
+                                       )
+                               ) .
+                               $this->mCode . 
+                               Xml::closeElement( 'textarea' ) .
+                               ' ' .
+                               Xml::element( 'br', null, '' ) .
+                               Xml::element( 'input',
+                                       array(
+                                               'type' => 'checkbox',
+                                               'name' => 'escape',
+                                               'id' => 'escape'
+                                       ) + ( $this->mEscape ? array( 'checked' 
=> 'checked' ) : array() ),
+                                       ''
+                               ) .
+                               Xml::element( 'label',
+                                       array(
+                                               'for' => 'escape'
+                                       ),
+                                       wfMsg( 'eval_escape' )
+                               ) .
+                               Xml::element( 'br', null, '' ) .
+                               Xml::element( 'input',
+                                       array(
+                                               'type' => 'submit',
+                                               'value' => wfMsg( 'eval_submit' 
)
+                                       ),
+                                       ''
+                               ) .
+                               Xml::element('input',
+                                       array(
+                                               'type' => 'hidden',
+                                               'name' => 'title',
+                                               'value' => 'Special:Eval'
+                                       ),
+                                       ''
+                               ) .
+                       Xml::closeElement( 'form' )
+               );
+       }
+
+}
+
+class EvaluateOutput {
+       private $mCode, $mEscape;
+       private $mErr;
+
+       public function __construct( &$code, &$escape ) {
+               $this->mCode =& $code;
+               $this->mEscape =& $escape;
+       }
+
+       public function execute() {
+               ob_start();
+               eval( $this->mCode );
+
+               $this->mErr = ob_get_clean();
+               $this->summary();
+       }
+
+       private function summary() {
+               global $wgOut;
+
+               if ( $this->mCode !== '' )
+                       $this->code();
+
+               if ( $this->mErr !== '' ) {
+                       $this->mErr =  preg_replace( '/^<br \/>/', '', 
$this->mErr );
+                       $wgOut->addHTML( Xml::element( 'h2', null, wfMsg( 
'eval_out' ) ) );
+                       if ( $this->mEscape )
+                               $this->mErr =
+                                       Xml::openElement( 'pre' ) .
+                                       htmlspecialchars( $this->mErr ) .
+                                       Xml::closeElement( 'pre ' );
+                       $wgOut->addHTML( $this->mErr );
+               }
+       }
+
+       private function code() {
+               global $wgOut;
+
+               if ( ! class_exists( 'GeSHi' ) )
+                       require_once 'geshi/geshi.php';
+
+               $geshi = new Geshi( $this->mCode, 'php' );
+               $geshi->enable_line_numbers( GESHI_NORMAL_LINE_NUMBERS );
+               $geshi->set_header_type( GESHI_HEADER_DIV );
+
+               $wgOut->addHTML(
+                       Xml::element( 'h2', null, wfMsg( 'eval_code' ) ) .
+                       $geshi->parse_code()
+               );
+       }
+}
+?>

Modified: trunk/extensions/Eval/SpecialEval.php
===================================================================
--- trunk/extensions/Eval/SpecialEval.php       2010-02-14 22:20:27 UTC (rev 
62482)
+++ trunk/extensions/Eval/SpecialEval.php       2010-02-14 22:30:32 UTC (rev 
62483)
@@ -11,177 +11,19 @@
  * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 
2.0 or later
  */
 
-$wgExtensionFunctions[] = 'wfSpecialEval';
 $wgExtensionCredits['specialpage'][] = array(
        'path'           => __FILE__,
        'name'           => 'Eval',
        'author'         => 'Ævar Arnfjörð Bjarmason',
        'description'    => 'adds [[Special:Eval|an interface]] to the 
<code>eval()</code> function',
-       'descriptionmsg' => 'eval-desc',
-       'url'            => 'http://www.mediawiki.org/wiki/Extension:Eval',
+       'descriptionmsg' => 'eval-desc'
 );
 
 $dir = dirname(__FILE__) . '/';
 $wgExtensionMessagesFiles['Eval'] = $dir . 'SpecialEval.i18n.php';
 $wgExtensionAliasesFiles['Eval'] = $dir . 'SpecialEval.alias.php';
 
-function wfSpecialEval() {
-       wfUsePHP( 5.0 );
-       wfUseMW( '1.6alpha' );
+$wgSpecialPages['Eval'] = 'SpecialEval';
+$wgAutoloadClasses['SpecialEval'] = $dir . 'SpecialEval.class.php';
 
-       global $IP;
-
-       class Evaluate extends SpecialPage {
-               public function __construct() {
-
-                       SpecialPage::SpecialPage( 'Eval' );
-               }
-
-               function getDescription() {
-                       return wfMsg( 'eval' );
-               }
-
-               public function execute( $par ) {
-                       global $wgOut, $wgRequest, $wgUseTidy;
-                       wfLoadExtensionMessages( 'Eval' );
-
-                       $this->setHeaders();
-
-                       $code = isset( $par ) ? $par : $wgRequest->getText( 
'code' );
-                       $escape = $wgRequest->getBool( 'escape' );
-
-                       $eform = new EvaluateForm( $code, $escape );
-
-                       if ( trim( $code ) === '' )
-                               $eform->execute();
-                       else {
-                               $eform->execute();
-
-                               $eout = new EvaluateOutput( $code, $escape );
-                               $eout->execute();
-                       }
-               }
-       }
-
-       class EvaluateForm {
-               private $mCode, $mEscape;
-
-               public function __construct( $code, $escape ) {
-                       $this->mCode =& $code;
-                       $this->mEscape =& $escape;
-               }
-
-               public function execute() {
-                       global $wgOut, $wgTitle;
-
-                       $wgOut->addHTML(
-                               Xml::openElement( 'form',
-                                       array(
-                                               'id' => 'specialeval',
-                                               'method' => 'get',
-                                               'action' => 
$wgTitle->escapeLocalUrl()
-                                       )
-                               ) .
-                                       # Gotta use open and close here to
-                                       # avoid <textarea /> which breaks
-                                       Xml::openElement( 'textarea',
-                                               array(
-                                                       'cols' => 40,
-                                                       'rows' => 10,
-                                                       'name' => 'code',
-                                               )
-                                       ) .
-                                       $this->mCode . 
-                                       Xml::closeElement( 'textarea' ) .
-                                       ' ' .
-                                       Xml::element( 'br', null, '' ) .
-                                       Xml::element( 'input',
-                                               array(
-                                                       'type' => 'checkbox',
-                                                       'name' => 'escape',
-                                                       'id' => 'escape'
-                                               ) + ( $this->mEscape ? array( 
'checked' => 'checked' ) : array() ),
-                                               ''
-                                       ) .
-                                       Xml::element( 'label',
-                                               array(
-                                                       'for' => 'escape'
-                                               ),
-                                               wfMsg( 'eval_escape' )
-                                       ) .
-                                       Xml::element( 'br', null, '' ) .
-                                       Xml::element( 'input',
-                                               array(
-                                                       'type' => 'submit',
-                                                       'value' => wfMsg( 
'eval_submit' )
-                                               ),
-                                               ''
-                                       ) .
-                                       Xml::element('input',
-                                               array(
-                                                       'type' => 'hidden',
-                                                       'name' => 'title',
-                                                       'value' => 
'Special:Eval'
-                                               ),
-                                               ''
-                                       ) .
-                               Xml::closeElement( 'form' )
-                       );
-               }
-
-       }
-
-       class EvaluateOutput {
-               private $mCode, $mEscape;
-               private $mErr;
-
-               public function __construct( &$code, &$escape ) {
-                       $this->mCode =& $code;
-                       $this->mEscape =& $escape;
-               }
-
-               public function execute() {
-                       ob_start();
-                       eval( $this->mCode );
-
-                       $this->mErr = ob_get_clean();
-                       $this->summary();
-               }
-
-               private function summary() {
-                       global $wgOut;
-
-                       if ( $this->mCode !== '' )
-                               $this->code();
-
-                       if ( $this->mErr !== '' ) {
-                               $this->mErr =  preg_replace( '/^<br \/>/', '', 
$this->mErr );
-                               $wgOut->addHTML( Xml::element( 'h2', null, 
wfMsg( 'eval_out' ) ) );
-                               if ( $this->mEscape )
-                                       $this->mErr =
-                                               Xml::openElement( 'pre' ) .
-                                               htmlspecialchars( $this->mErr ) 
.
-                                               Xml::closeElement( 'pre ' );
-                               $wgOut->addHTML( $this->mErr );
-                       }
-               }
-
-               private function code() {
-                       global $wgOut;
-
-                       if ( ! class_exists( 'GeSHi' ) )
-                               require_once '../extensions/geshi/geshi.php';
-
-                       $geshi = new Geshi( $this->mCode, 'php' );
-                       $geshi->enable_line_numbers( GESHI_NORMAL_LINE_NUMBERS 
);
-                       $geshi->set_header_type( GESHI_HEADER_DIV );
-
-                       $wgOut->addHTML(
-                               Xml::element( 'h2', null, wfMsg( 'eval_code' ) 
) .
-                               $geshi->parse_code()
-                       );
-               }
-       }
-
-       SpecialPage::addPage( new Evaluate );
-}
+?>



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to