Index: trunk/extensions/TrustedMath/TrustedMath_body.php |
— | — | @@ -121,10 +121,6 @@ |
122 | 122 | $file = "{$this->dir}/$hash" . wfBaseConvert( mt_rand(), 10, 36 ); |
123 | 123 | file_put_contents( "$file.tex", self::wrapEquation( $this->getText() ) ); |
124 | 124 | |
125 | | - // FIXME: dangerous |
126 | | - // Set-up the environment variables needed when running Windows |
127 | | - |
128 | | - |
129 | 125 | $retval = null; |
130 | 126 | |
131 | 127 | // Render the LaTeX file as DVI |
Index: trunk/extensions/TrustedMath/TrustedMath.i18n.php |
— | — | @@ -3,10 +3,8 @@ |
4 | 4 | $messages = array(); |
5 | 5 | |
6 | 6 | $messages['en'] = array( |
7 | | - 'trustedmath-namespace' => 'Math', |
8 | | - 'trustedmath-talk-namespace' => 'Math_talk', |
9 | 7 | 'trustedmath-permission-error' => 'Untrusted math is disabled on this wiki', |
10 | 8 | 'trustedmath-path-error' => 'Error creating the math directory', |
11 | 9 | 'trustedmath-convert-error' => 'Error creating math image. "$1" returned <tt><nowiki>$2</nowiki></tt>.', |
12 | | - |
| 10 | + 'trustedmath-not-found' => 'Page [[:$1]] does not exist', |
13 | 11 | ); |
\ No newline at end of file |
Index: trunk/extensions/TrustedMath/TrustedMath.namespaces.php |
— | — | @@ -0,0 +1,8 @@ |
| 2 | +<?php |
| 3 | +$namespaceNames = array(); |
| 4 | + |
| 5 | +$namespaceNames['en'] = array( |
| 6 | + NS_TRUSTEDMATH => 'Math', |
| 7 | + NS_TRUSTEDMATH_TALK => 'Math_talk', |
| 8 | +); |
| 9 | + |
Property changes on: trunk/extensions/TrustedMath/TrustedMath.namespaces.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 10 | + native |
Index: trunk/extensions/TrustedMath/TrustedMath.php |
— | — | @@ -33,12 +33,17 @@ |
34 | 34 | $wgAutoloadClasses['TrustedMathHooks'] = "$dir/TrustedMathHooks.php"; |
35 | 35 | |
36 | 36 | $wgExtensionMessagesFiles['TrustedMath'] = "$dir/TrustedMath.i18n.php"; |
| 37 | +$wgExtensionMessagesFiles['TrustedMathNamespaces'] = "$dir/TrustedMath.namespaces.php"; |
37 | 38 | |
38 | 39 | $wgExtensionFunctions[] = 'TrustedMathHooks::initGlobals'; |
39 | 40 | $wgHooks['ParserFirstCallInit'][] = 'TrustedMathHooks::onParserFirstCallInit'; |
| 41 | +$wgHooks['CanonicalNamespaces'][] = 'TrustedMathHooks::initNamespace'; |
40 | 42 | #Broken |
41 | 43 | #$wgHooks['ParserAfterStrip'][] = 'TrustedMathHooks::onParserAfterStrip'; |
42 | 44 | |
| 45 | +define( 'NS_TRUSTEDMATH', 262 ); |
| 46 | +define( 'NS_TRUSTEDMATH_TALK', 263 ); |
| 47 | + |
43 | 48 | // Path to latex |
44 | 49 | $wgTrustedMathLatexPath = null; |
45 | 50 | // Path to dvipng |
— | — | @@ -53,5 +58,5 @@ |
54 | 59 | $wgTrustedMathPath = null; |
55 | 60 | // Allow math in <math> tags |
56 | 61 | $wgTrustedMathUnsafeMode = false; |
57 | | -// Namespace for safe math |
58 | | -$wgTrustedMathNamespace = 262; |
| 62 | + |
| 63 | + |
Index: trunk/extensions/TrustedMath/TrustedMathHooks.php |
— | — | @@ -9,9 +9,7 @@ |
10 | 10 | * TODO fix |
11 | 11 | */ |
12 | 12 | public static function onParserAfterStrip( $parser, &$text, &$stripState ) { |
13 | | - global $wgTrustedMathNamespace; |
14 | | - |
15 | | - if ( $parser->getTitle()->getNamespace() == $wgTrustedMathNamespace ) { |
| 13 | + if ( $parser->getTitle()->getNamespace() == NS_TRUSTEDMATH ) { |
16 | 14 | if ( strpos( $text, '<math>' ) === false ) { |
17 | 15 | $text = "<math>$text</math>"; |
18 | 16 | return false; |
— | — | @@ -36,28 +34,27 @@ |
37 | 35 | } |
38 | 36 | |
39 | 37 | // Initialize the namespace for TrustedMath |
40 | | - self::initNamespace(); |
| 38 | + global $wgVersion, $wgExtraNamespaces; |
| 39 | + if ( version_compare( $wgVersion, '1.17alpha', '<' ) ) { |
| 40 | + self::initNamespace( $wgExtraNamespaces ); |
| 41 | + } |
| 42 | + |
41 | 43 | } |
42 | 44 | |
43 | 45 | /** |
44 | 46 | * TODO: check, fix, etc. |
45 | 47 | */ |
46 | | - public static function initNamespace() { |
47 | | - global $wgExtraNamespaces, $wgNamespaceProtection; |
48 | | - global $wgTrustedMathNamespace; |
| 48 | + public static function initNamespace( &$list ) { |
| 49 | + global $wgNamespaceProtection; |
49 | 50 | |
50 | | - if ( !isset( $wgExtraNamespaces[$wgTrustedMathNamespace] ) ) { |
51 | | - $wgExtraNamespaces[$wgTrustedMathNamespace] = |
52 | | - wfMsgForContent( 'trustedmath-namespace' ); |
| 51 | + $list[NS_TRUSTEDMATH] = 'Math'; |
| 52 | + $list[NS_TRUSTEDMATH_TALK] = 'Math_talk'; |
| 53 | + |
| 54 | + if ( !isset( $wgNamespaceProtection[NS_TRUSTEDMATH] ) ) { |
| 55 | + $wgNamespaceProtection[NS_TRUSTEDMATH] = array( 'editmath' ); |
53 | 56 | } |
54 | | - if ( !isset( $wgExtraNamespaces[$wgTrustedMathNamespace+1] ) ) { |
55 | | - $wgExtraNamespaces[$wgTrustedMathNamespace+1] = |
56 | | - wfMsgForContent( 'trustedmath-talk-namespace' ); |
57 | | - } |
58 | 57 | |
59 | | - if ( !isset( $wgNamespaceProtection[$wgTrustedMathNamespace] ) ) { |
60 | | - $wgNamespaceProtection[$wgTrustedMathNamespace] = array( 'editmath' ); |
61 | | - } |
| 58 | + return true; |
62 | 59 | } |
63 | 60 | |
64 | 61 | /** |
— | — | @@ -78,12 +75,15 @@ |
79 | 76 | * @param mixed $frame |
80 | 77 | */ |
81 | 78 | public static function mathTag( $input, $args, $parser, $frame ) { |
82 | | - global $wgTrustedMathNamespace; |
83 | | - |
84 | 79 | if ( isset( $args['name'] ) ) { |
85 | 80 | // Safe mode |
86 | 81 | |
87 | | - $title = Title::newFromText( $args['name'], $wgTrustedMathNamespace ); |
| 82 | + $title = Title::newFromText( $args['name'], NS_TRUSTEDMATH ); |
| 83 | + if ( !$title->exists() ) { |
| 84 | + return $parser->recursiveTagParse( '<span class="error">' . |
| 85 | + wfMsg( 'trustedmath-not-found', $title->getPrefixedText() ) . |
| 86 | + '</span>' ); |
| 87 | + } |
88 | 88 | if ( !self::validateSafeMode( $title ) ) { |
89 | 89 | // Requested title was not in the math namespace |
90 | 90 | return self::getPermissionError( $parser ); |
— | — | @@ -128,9 +128,8 @@ |
129 | 129 | * @return bool True if safe |
130 | 130 | */ |
131 | 131 | protected static function validateSafeMode( $title ) { |
132 | | - global $wgTrustedMathNamespace; |
133 | 132 | return !( self::safeMode() && |
134 | | - $title->getNamespace() != $wgTrustedMathNamespace ); |
| 133 | + $title->getNamespace() != NS_TRUSTEDMATH ); |
135 | 134 | } |
136 | 135 | /** |
137 | 136 | * Check if unsafe math is allowed |