r39759 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r39758‎ | r39759 | r39760 >
Date:09:02, 21 August 2008
Author:nikerabbit
Status:old
Tags:
Comment:
* Some comments
Modified paths:
  • /trunk/extensions/Translate/tag/Tag.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/tag/Tag.php
@@ -1,8 +1,13 @@
22 <?php
33
44 /**
5 - * Hook attachments for the <translate> tag.
 5+ * Code for handling pages marked with <translate> tag. This class does parsing.
66 *
 7+ * Section: piece of text, separated usually with two new lines, that is used as
 8+ * an single translation unit for change tracking and so on.
 9+ * Occurance: contents of <translate>..</translate>, which there can be many on
 10+ * one page.
 11+ *
712 * @addtogroup Extensions
813 *
914 * @author Niklas Laxström
@@ -10,15 +15,18 @@
1116 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1217 */
1318 class TranslateTag {
14 -
 19+ /** Counter for nth <translate>..</translate> invocation to know to which
 20+ * occurance each section belongs to, when doing save-time parsing. */
1521 var $invocation = 0;
1622
 23+ // Deprecated, TODO: write a suitable factory functions for replacement
1724 public static function getInstance() {
1825 $obj = new self;
1926 //$obj->reset();
2027 return $obj;
2128 }
2229
 30+ /** Factory for creating a new instance from Title object */
2331 public static function newFromTitle( Title $title ) {
2432 $obj = new self();
2533 $obj->invocation = 0;
@@ -31,6 +39,7 @@
3240 return $obj;
3341 }
3442
 43+ /** Factory for creating a new instance from occurance */
3544 public static function newFromTagContents( &$text, $code ) {
3645 $obj = new self();
3746 $obj->invocation = -1;
@@ -42,6 +51,7 @@
4352 return $obj;
4453 }
4554
 55+ // TODO: Move to hook or utils?
4656 // Remember to to use TranslateUtils::injectCSS()
4757 public function getHeader( Title $title ) {
4858 list( , $code ) = TranslateTagUtils::keyAndCode( $title );
@@ -68,15 +78,18 @@
6979 $legend .= " | $legendText <span class=\"mw-translate-other\">$legendOther</span>";
7080 $legend .= " <span class=\"mw-translate-fuzzy\">$legendFuzzy</span>";
7181 }
 82+ // TODO: the following text will of course be removed :)
7283 $legend .= ' | This page is translatable using the experimental wiki page translation feature.</div>';
7384 $legend .= "\n----\n";
7485 return $legend;
7586 }
7687
 88+ // Some regexps
7789 const METADATA = '~\n?<!--TS(.*?)-->\n?~us';
7890 const PATTERN_COMMENT = '~\n?<!--T[=:;](.*?)-->\n?~u';
7991 const PATTERN_TAG = '~(<translate>)\n?(.+?)(</translate>)~us';
8092
 93+ // Renders a translation page to given language
8194 public function renderPage( $text, Title $title, $code = false ) {
8295 $this->renderTitle = $title;
8396 $this->renderCode = $code;
@@ -135,6 +148,7 @@
136149 }
137150 }
138151
 152+ // Clean any comments there may be left
139153 $input = preg_replace( self::PATTERN_PLACEHOLDER, '', $input );
140154 $input = preg_replace( self::METADATA, '', $input );
141155
@@ -226,6 +240,7 @@
227241 return "~$regex~u";
228242 }
229243
 244+ // Deprecated
230245 public function reset() {
231246 $this->sections = array();
232247 $this->placeholders = array();
@@ -262,6 +277,7 @@
263278
264279 }
265280
 281+ /** Use this to get the location of translations */
266282 public function getTranslationPage( Title $title, $key, $code = false ) {
267283 global $wgTranslateTagTranslationLocation;
268284 list( , $format ) = $wgTranslateTagTranslationLocation;
@@ -280,6 +296,9 @@
281297 return $pagename;
282298 }
283299
 300+ /** Use this to get the namespace for page names provided with
 301+ * getTranslationPage
 302+ */
284303 public function getNamespace( Title $title ) {
285304 global $wgTranslateTagTranslationLocation;
286305 list( $nsId, ) = $wgTranslateTagTranslationLocation;
@@ -287,6 +306,7 @@
288307 return $nsId;
289308 }
290309
 310+ // Initiate fuzzyjobs on changed sections
291311 public function onArticleSaveComplete(
292312 $article, $user, $text, $summary, $isminor, $_, $_, $flags, $revision
293313 ) {
@@ -328,6 +348,10 @@
329349 $cb = array( $obj, 'saveCb' );
330350 $text = preg_replace_callback( self::PATTERN_TAG, $cb, $text );
331351
 352+ // Trim trailing whitespace. It is not allowed in wikitext and shows up in
 353+ // diffs
 354+ $text = rtrim( $text );
 355+
332356 if ( count($obj->changed) ) {
333357 // Register fuzzier
334358 // We need to do it later, so that we know the revision number

Status & tagging log