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

Revision: 72102
Author:   nikerabbit
Date:     2010-09-01 12:47:27 +0000 (Wed, 01 Sep 2010)

Log Message:
-----------
More documentation

Modified Paths:
--------------
    trunk/extensions/Translate/tag/MoveJob.php
    trunk/extensions/Translate/tag/SpecialPageTranslation.php
    trunk/extensions/Translate/tag/TPParse.php
    trunk/extensions/Translate/tag/TPSection.php
    trunk/extensions/Translate/tag/TranslatablePage.php

Modified: trunk/extensions/Translate/tag/MoveJob.php
===================================================================
--- trunk/extensions/Translate/tag/MoveJob.php  2010-09-01 12:30:32 UTC (rev 
72101)
+++ trunk/extensions/Translate/tag/MoveJob.php  2010-09-01 12:47:27 UTC (rev 
72102)
@@ -157,8 +157,8 @@
        }
 
        /**
-       * Modified from wfSuppressWarnings
-       */
+        * Adapted from wfSuppressWarnings to allow not leaving redirects.
+        */
        public static function forceRedirects( $end = false ) {
                static $suppressCount = 0;
                static $originalLevel = null;

Modified: trunk/extensions/Translate/tag/SpecialPageTranslation.php
===================================================================
--- trunk/extensions/Translate/tag/SpecialPageTranslation.php   2010-09-01 
12:30:32 UTC (rev 72101)
+++ trunk/extensions/Translate/tag/SpecialPageTranslation.php   2010-09-01 
12:47:27 UTC (rev 72102)
@@ -16,8 +16,7 @@
  * It will list all pages in their various states and provides actions
  * that are suitable for given translatable page.
  *
- * @ingroup SpecialPage
- * @ingroup PageTranslation
+ * @ingroup SpecialPage PageTranslation
  */
 class SpecialPageTranslation extends SpecialPage {
        function __construct() {
@@ -595,6 +594,14 @@
                }
        }
 
+       /**
+        * Enhanced version of wfDebug that allows more detailed debugging.
+        * You can pass anything as varags and it will be serialized. Article
+        * and User objects have special handling to only output name and id.
+        * @param $method \string Calling method.
+        * @param $msg \string Debug message.
+        * @todo Move to better place.
+        */
        public static function superDebug( $method, $msg /* varags */ ) {
                $args = func_get_args();
                $args = array_slice( $args, 2 );

Modified: trunk/extensions/Translate/tag/TPParse.php
===================================================================
--- trunk/extensions/Translate/tag/TPParse.php  2010-09-01 12:30:32 UTC (rev 
72101)
+++ trunk/extensions/Translate/tag/TPParse.php  2010-09-01 12:47:27 UTC (rev 
72102)
@@ -1,7 +1,6 @@
 <?php
 /**
- * This class represents the results of parsed source page, that is, the
- * extracted sections and a template.
+ * Helper code TranslatablePage.
  *
  * @file
  * @author Niklas Laxström
@@ -10,28 +9,53 @@
  */
 
 /**
- * @todo Needs documentation.
+ * This class represents the results of parsed source page, that is, the
+ * extracted sections and a template.
  * @ingroup PageTranslation
  */
 class TPParse {
+       /// \type{Title} Title of the page.
        protected $title = null;
 
+       /** \arrayof{String,TPSection} Parsed sections indexed with placeholder.
+        * @todo Encapsulate
+        */
        public $sections   = array();
+       /** \string Page source with content replaced with placeholders.
+        * @todo Encapsulate
+        */
        public $template   = null;
-       public $dbSections = null;
+       /// \arrayof{String,TPSection} Sections saved in the database.
+       protected $dbSections = null;
 
+       /// Constructor
        public function __construct( Title $title ) {
                $this->title = $title;
        }
 
+       /**
+        * Returns the number of sections in this page.
+        * @return \int
+        */
        public function countSections() {
                return count( $this->sections );
        }
 
+       /**
+        * Returns the page template where translatable content is replaced with
+        * placeholders.
+        * @return \string
+        */
        public function getTemplate() {
                return $this->template;
        }
 
+       /**
+        * Returns the page template where the ugly placeholders are replaced 
with
+        * section markers. Sections which previously had no number will get one
+        * assigned now.
+        * @return \string
+        */
        public function getTemplatePretty() {
                $text = $this->template;
                $sections = $this->getSectionsForSave();
@@ -42,6 +66,10 @@
                return $text;
        }
 
+       /**
+        * Gets the sections and assigns section id for new sections
+        * @return \arrayof{String,TPSection}
+        */
        public function getSectionsForSave() {
                $this->loadFromDatabase();
 
@@ -76,6 +104,10 @@
                return $sections;
        }
 
+       /**
+        * Returns list of deleted sections.
+        * @return \arrayof{String,TPsection} List of sections indexed by id.
+        */
        public function getDeletedSections() {
                $sections = $this->getSectionsForSave();
                $deleted = $this->dbSections;
@@ -89,6 +121,9 @@
                return $deleted;
        }
 
+       /**
+        * Load section saved in the database. Populates dbSections.
+        */
        protected function loadFromDatabase() {
                if ( $this->dbSections !== null ) {
                        return;
@@ -111,9 +146,14 @@
                }
        }
 
+       /**
+        * Returns the source page stripped of most translation mark-up.
+        * @return \string Wikitext.
+        */
        public function getSourcePageText() {
                $text = $this->template;
 
+               /// @todo Use str_replace outside of the loop.
                foreach ( $this->sections as $ph => $s ) {
                        $text = str_replace( $ph, $s->getMarkedText(), $text );
                }
@@ -121,6 +161,14 @@
                return $text;
        }
 
+       /**
+        * Returns translation page with all possible translations replaced in, 
ugly
+        * translation tags removed and outdated translation marked with a class
+        * mw-translate-fuzzy.
+        * @todo The class marking has to be more intelligent with span&div use.
+        * @param $collection \type{MessageCollection} Collection that holds 
translated messages.
+        * @return \string Whole page as wikitext.
+        */
        public function getTranslationPageText( /*MessageCollection*/ 
$collection ) {
                $text = $this->template; // The source
 
@@ -170,6 +218,10 @@
                return $text;
        }
 
+       /**
+        * Replaces variables from given text.
+        * @todo Is plain str_replace not enough (even the loop is not needed)?
+        */
        protected static function replaceVariables( $variables, $text ) {
                foreach ( $variables as $key => $value ) {
                        $text = str_replace( $key, $value, $text );
@@ -178,6 +230,12 @@
                return $text;
        }
 
+       /**
+        * Chops of trailing or preceeding whitespace intelligently to avoid
+        * build up of unintented whitespace.
+        * @param $matches \array
+        * @return \string
+        */
        protected static function replaceTagCb( $matches ) {
                return preg_replace( '~^\n|\n\z~', '', $matches[2] );
        }

Modified: trunk/extensions/Translate/tag/TPSection.php
===================================================================
--- trunk/extensions/Translate/tag/TPSection.php        2010-09-01 12:30:32 UTC 
(rev 72101)
+++ trunk/extensions/Translate/tag/TPSection.php        2010-09-01 12:47:27 UTC 
(rev 72102)
@@ -1,6 +1,6 @@
 <?php
 /**
- * This class represents one section of a translatable page.
+ * Helper for TPParse.
  *
  * @file
  * @author Niklas Laxström
@@ -9,21 +9,42 @@
  */
 
 /**
- * @todo Needs documentation.
+ * This class represents one individual section in translatable page.
  * @ingroup PageTranslation
  */
 class TPSection {
-       public $id, $name, $text, $type;
+       /// \string Section name
+       public $id;
+       /// \string New name of the section, that will be saved to database.
+       public $name;
+       /// \string Section text.
+       public $text;
+       /// \string Is this new, existing, changed or deleted section.
+       public $type;
+       /// \string Text of previous version of this section.
+       public $oldText;
 
+       /**
+        * Returns section text unmodified.
+        * @return \string Wikitext.
+        */
        public function getText() {
                return $this->text;
        }
 
+       /**
+        * Returns section text with variables replaced.
+        * @return \string Wikitext.
+        */
        public function getTextForTrans() {
                $re = '~<tvar\|([^>]+)>(.*?)</>~u';
                return preg_replace( $re, '\2', $this->text );
        }
 
+       /**
+        * Returns the section text section marker updated or added.
+        * @return \string Wikitext.
+        */
        public function getMarkedText() {
                $id = isset( $this->name ) ? $this->name : $this->id;
                $header = "<!--T:{$id}-->";
@@ -40,10 +61,19 @@
                return $text;
        }
 
+       /**
+        * Returns oldtext, or current text if not available.
+        * @return \string Wikitext.
+        */
        public function getOldText() {
                return isset( $this->oldtext ) ? $this->oldtext : $this->text;
        }
 
+       /**
+        * Returns array of variables defined on this section.
+        * @return \arrayof{String,String} Values indexed with keys which are
+        * prefixed with a dollar sign.
+        */
        public function getVariables() {
                $re = '~<tvar\|([^>]+)>(.*?)</>~u';
                $matches = array();

Modified: trunk/extensions/Translate/tag/TranslatablePage.php
===================================================================
--- trunk/extensions/Translate/tag/TranslatablePage.php 2010-09-01 12:30:32 UTC 
(rev 72101)
+++ trunk/extensions/Translate/tag/TranslatablePage.php 2010-09-01 12:47:27 UTC 
(rev 72102)
@@ -1,7 +1,6 @@
 <?php
 /**
  * Translatable page model.
-
  * @defgroup PageTranslation Page Translation
  * @file
  * @author Niklas Laxström



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to