r79590 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79589‎ | r79590 | r79591 >
Date:19:23, 4 January 2011
Author:btongminh
Status:deferred
Tags:
Comment:
Setup namespace cf. LQT. This needs to be documented on wiki, I have no idea whether what I'm doing is correct.
Modified paths:
  • /trunk/extensions/TrustedMath/TrustedMath.i18n.php (modified) (history)
  • /trunk/extensions/TrustedMath/TrustedMath.namespaces.php (added) (history)
  • /trunk/extensions/TrustedMath/TrustedMath.php (modified) (history)
  • /trunk/extensions/TrustedMath/TrustedMathHooks.php (modified) (history)
  • /trunk/extensions/TrustedMath/TrustedMath_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/TrustedMath/TrustedMath_body.php
@@ -121,10 +121,6 @@
122122 $file = "{$this->dir}/$hash" . wfBaseConvert( mt_rand(), 10, 36 );
123123 file_put_contents( "$file.tex", self::wrapEquation( $this->getText() ) );
124124
125 - // FIXME: dangerous
126 - // Set-up the environment variables needed when running Windows
127 -
128 -
129125 $retval = null;
130126
131127 // Render the LaTeX file as DVI
Index: trunk/extensions/TrustedMath/TrustedMath.i18n.php
@@ -3,10 +3,8 @@
44 $messages = array();
55
66 $messages['en'] = array(
7 - 'trustedmath-namespace' => 'Math',
8 - 'trustedmath-talk-namespace' => 'Math_talk',
97 'trustedmath-permission-error' => 'Untrusted math is disabled on this wiki',
108 'trustedmath-path-error' => 'Error creating the math directory',
119 'trustedmath-convert-error' => 'Error creating math image. "$1" returned <tt><nowiki>$2</nowiki></tt>.',
12 -
 10+ 'trustedmath-not-found' => 'Page [[:$1]] does not exist',
1311 );
\ 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
110 + native
Index: trunk/extensions/TrustedMath/TrustedMath.php
@@ -33,12 +33,17 @@
3434 $wgAutoloadClasses['TrustedMathHooks'] = "$dir/TrustedMathHooks.php";
3535
3636 $wgExtensionMessagesFiles['TrustedMath'] = "$dir/TrustedMath.i18n.php";
 37+$wgExtensionMessagesFiles['TrustedMathNamespaces'] = "$dir/TrustedMath.namespaces.php";
3738
3839 $wgExtensionFunctions[] = 'TrustedMathHooks::initGlobals';
3940 $wgHooks['ParserFirstCallInit'][] = 'TrustedMathHooks::onParserFirstCallInit';
 41+$wgHooks['CanonicalNamespaces'][] = 'TrustedMathHooks::initNamespace';
4042 #Broken
4143 #$wgHooks['ParserAfterStrip'][] = 'TrustedMathHooks::onParserAfterStrip';
4244
 45+define( 'NS_TRUSTEDMATH', 262 );
 46+define( 'NS_TRUSTEDMATH_TALK', 263 );
 47+
4348 // Path to latex
4449 $wgTrustedMathLatexPath = null;
4550 // Path to dvipng
@@ -53,5 +58,5 @@
5459 $wgTrustedMathPath = null;
5560 // Allow math in <math> tags
5661 $wgTrustedMathUnsafeMode = false;
57 -// Namespace for safe math
58 -$wgTrustedMathNamespace = 262;
 62+
 63+
Index: trunk/extensions/TrustedMath/TrustedMathHooks.php
@@ -9,9 +9,7 @@
1010 * TODO fix
1111 */
1212 public static function onParserAfterStrip( $parser, &$text, &$stripState ) {
13 - global $wgTrustedMathNamespace;
14 -
15 - if ( $parser->getTitle()->getNamespace() == $wgTrustedMathNamespace ) {
 13+ if ( $parser->getTitle()->getNamespace() == NS_TRUSTEDMATH ) {
1614 if ( strpos( $text, '<math>' ) === false ) {
1715 $text = "<math>$text</math>";
1816 return false;
@@ -36,28 +34,27 @@
3735 }
3836
3937 // 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+
4143 }
4244
4345 /**
4446 * TODO: check, fix, etc.
4547 */
46 - public static function initNamespace() {
47 - global $wgExtraNamespaces, $wgNamespaceProtection;
48 - global $wgTrustedMathNamespace;
 48+ public static function initNamespace( &$list ) {
 49+ global $wgNamespaceProtection;
4950
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' );
5356 }
54 - if ( !isset( $wgExtraNamespaces[$wgTrustedMathNamespace+1] ) ) {
55 - $wgExtraNamespaces[$wgTrustedMathNamespace+1] =
56 - wfMsgForContent( 'trustedmath-talk-namespace' );
57 - }
5857
59 - if ( !isset( $wgNamespaceProtection[$wgTrustedMathNamespace] ) ) {
60 - $wgNamespaceProtection[$wgTrustedMathNamespace] = array( 'editmath' );
61 - }
 58+ return true;
6259 }
6360
6461 /**
@@ -78,12 +75,15 @@
7976 * @param mixed $frame
8077 */
8178 public static function mathTag( $input, $args, $parser, $frame ) {
82 - global $wgTrustedMathNamespace;
83 -
8479 if ( isset( $args['name'] ) ) {
8580 // Safe mode
8681
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+ }
8888 if ( !self::validateSafeMode( $title ) ) {
8989 // Requested title was not in the math namespace
9090 return self::getPermissionError( $parser );
@@ -128,9 +128,8 @@
129129 * @return bool True if safe
130130 */
131131 protected static function validateSafeMode( $title ) {
132 - global $wgTrustedMathNamespace;
133132 return !( self::safeMode() &&
134 - $title->getNamespace() != $wgTrustedMathNamespace );
 133+ $title->getNamespace() != NS_TRUSTEDMATH );
135134 }
136135 /**
137136 * Check if unsafe math is allowed

Status & tagging log