r72102 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72101‎ | r72102 | r72103 >
Date:12:47, 1 September 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
More documentation
Modified paths:
  • /trunk/extensions/Translate/tag/MoveJob.php (modified) (history)
  • /trunk/extensions/Translate/tag/SpecialPageTranslation.php (modified) (history)
  • /trunk/extensions/Translate/tag/TPParse.php (modified) (history)
  • /trunk/extensions/Translate/tag/TPSection.php (modified) (history)
  • /trunk/extensions/Translate/tag/TranslatablePage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/tag/TranslatablePage.php
@@ -1,7 +1,6 @@
22 <?php
33 /**
44 * Translatable page model.
5 -
65 * @defgroup PageTranslation Page Translation
76 * @file
87 * @author Niklas Laxström
Index: trunk/extensions/Translate/tag/SpecialPageTranslation.php
@@ -16,8 +16,7 @@
1717 * It will list all pages in their various states and provides actions
1818 * that are suitable for given translatable page.
1919 *
20 - * @ingroup SpecialPage
21 - * @ingroup PageTranslation
 20+ * @ingroup SpecialPage PageTranslation
2221 */
2322 class SpecialPageTranslation extends SpecialPage {
2423 function __construct() {
@@ -595,6 +594,14 @@
596595 }
597596 }
598597
 598+ /**
 599+ * Enhanced version of wfDebug that allows more detailed debugging.
 600+ * You can pass anything as varags and it will be serialized. Article
 601+ * and User objects have special handling to only output name and id.
 602+ * @param $method \string Calling method.
 603+ * @param $msg \string Debug message.
 604+ * @todo Move to better place.
 605+ */
599606 public static function superDebug( $method, $msg /* varags */ ) {
600607 $args = func_get_args();
601608 $args = array_slice( $args, 2 );
Index: trunk/extensions/Translate/tag/TPParse.php
@@ -1,7 +1,6 @@
22 <?php
33 /**
4 - * This class represents the results of parsed source page, that is, the
5 - * extracted sections and a template.
 4+ * Helper code TranslatablePage.
65 *
76 * @file
87 * @author Niklas Laxström
@@ -10,28 +9,53 @@
1110 */
1211
1312 /**
14 - * @todo Needs documentation.
 13+ * This class represents the results of parsed source page, that is, the
 14+ * extracted sections and a template.
1515 * @ingroup PageTranslation
1616 */
1717 class TPParse {
 18+ /// \type{Title} Title of the page.
1819 protected $title = null;
1920
 21+ /** \arrayof{String,TPSection} Parsed sections indexed with placeholder.
 22+ * @todo Encapsulate
 23+ */
2024 public $sections = array();
 25+ /** \string Page source with content replaced with placeholders.
 26+ * @todo Encapsulate
 27+ */
2128 public $template = null;
22 - public $dbSections = null;
 29+ /// \arrayof{String,TPSection} Sections saved in the database.
 30+ protected $dbSections = null;
2331
 32+ /// Constructor
2433 public function __construct( Title $title ) {
2534 $this->title = $title;
2635 }
2736
 37+ /**
 38+ * Returns the number of sections in this page.
 39+ * @return \int
 40+ */
2841 public function countSections() {
2942 return count( $this->sections );
3043 }
3144
 45+ /**
 46+ * Returns the page template where translatable content is replaced with
 47+ * placeholders.
 48+ * @return \string
 49+ */
3250 public function getTemplate() {
3351 return $this->template;
3452 }
3553
 54+ /**
 55+ * Returns the page template where the ugly placeholders are replaced with
 56+ * section markers. Sections which previously had no number will get one
 57+ * assigned now.
 58+ * @return \string
 59+ */
3660 public function getTemplatePretty() {
3761 $text = $this->template;
3862 $sections = $this->getSectionsForSave();
@@ -42,6 +66,10 @@
4367 return $text;
4468 }
4569
 70+ /**
 71+ * Gets the sections and assigns section id for new sections
 72+ * @return \arrayof{String,TPSection}
 73+ */
4674 public function getSectionsForSave() {
4775 $this->loadFromDatabase();
4876
@@ -76,6 +104,10 @@
77105 return $sections;
78106 }
79107
 108+ /**
 109+ * Returns list of deleted sections.
 110+ * @return \arrayof{String,TPsection} List of sections indexed by id.
 111+ */
80112 public function getDeletedSections() {
81113 $sections = $this->getSectionsForSave();
82114 $deleted = $this->dbSections;
@@ -89,6 +121,9 @@
90122 return $deleted;
91123 }
92124
 125+ /**
 126+ * Load section saved in the database. Populates dbSections.
 127+ */
93128 protected function loadFromDatabase() {
94129 if ( $this->dbSections !== null ) {
95130 return;
@@ -111,9 +146,14 @@
112147 }
113148 }
114149
 150+ /**
 151+ * Returns the source page stripped of most translation mark-up.
 152+ * @return \string Wikitext.
 153+ */
115154 public function getSourcePageText() {
116155 $text = $this->template;
117156
 157+ /// @todo Use str_replace outside of the loop.
118158 foreach ( $this->sections as $ph => $s ) {
119159 $text = str_replace( $ph, $s->getMarkedText(), $text );
120160 }
@@ -121,6 +161,14 @@
122162 return $text;
123163 }
124164
 165+ /**
 166+ * Returns translation page with all possible translations replaced in, ugly
 167+ * translation tags removed and outdated translation marked with a class
 168+ * mw-translate-fuzzy.
 169+ * @todo The class marking has to be more intelligent with span&div use.
 170+ * @param $collection \type{MessageCollection} Collection that holds translated messages.
 171+ * @return \string Whole page as wikitext.
 172+ */
125173 public function getTranslationPageText( /*MessageCollection*/ $collection ) {
126174 $text = $this->template; // The source
127175
@@ -170,6 +218,10 @@
171219 return $text;
172220 }
173221
 222+ /**
 223+ * Replaces variables from given text.
 224+ * @todo Is plain str_replace not enough (even the loop is not needed)?
 225+ */
174226 protected static function replaceVariables( $variables, $text ) {
175227 foreach ( $variables as $key => $value ) {
176228 $text = str_replace( $key, $value, $text );
@@ -178,6 +230,12 @@
179231 return $text;
180232 }
181233
 234+ /**
 235+ * Chops of trailing or preceeding whitespace intelligently to avoid
 236+ * build up of unintented whitespace.
 237+ * @param $matches \array
 238+ * @return \string
 239+ */
182240 protected static function replaceTagCb( $matches ) {
183241 return preg_replace( '~^\n|\n\z~', '', $matches[2] );
184242 }
Index: trunk/extensions/Translate/tag/MoveJob.php
@@ -157,8 +157,8 @@
158158 }
159159
160160 /**
161 - * Modified from wfSuppressWarnings
162 - */
 161+ * Adapted from wfSuppressWarnings to allow not leaving redirects.
 162+ */
163163 public static function forceRedirects( $end = false ) {
164164 static $suppressCount = 0;
165165 static $originalLevel = null;
Index: trunk/extensions/Translate/tag/TPSection.php
@@ -1,6 +1,6 @@
22 <?php
33 /**
4 - * This class represents one section of a translatable page.
 4+ * Helper for TPParse.
55 *
66 * @file
77 * @author Niklas Laxström
@@ -9,21 +9,42 @@
1010 */
1111
1212 /**
13 - * @todo Needs documentation.
 13+ * This class represents one individual section in translatable page.
1414 * @ingroup PageTranslation
1515 */
1616 class TPSection {
17 - public $id, $name, $text, $type;
 17+ /// \string Section name
 18+ public $id;
 19+ /// \string New name of the section, that will be saved to database.
 20+ public $name;
 21+ /// \string Section text.
 22+ public $text;
 23+ /// \string Is this new, existing, changed or deleted section.
 24+ public $type;
 25+ /// \string Text of previous version of this section.
 26+ public $oldText;
1827
 28+ /**
 29+ * Returns section text unmodified.
 30+ * @return \string Wikitext.
 31+ */
1932 public function getText() {
2033 return $this->text;
2134 }
2235
 36+ /**
 37+ * Returns section text with variables replaced.
 38+ * @return \string Wikitext.
 39+ */
2340 public function getTextForTrans() {
2441 $re = '~<tvar\|([^>]+)>(.*?)</>~u';
2542 return preg_replace( $re, '\2', $this->text );
2643 }
2744
 45+ /**
 46+ * Returns the section text section marker updated or added.
 47+ * @return \string Wikitext.
 48+ */
2849 public function getMarkedText() {
2950 $id = isset( $this->name ) ? $this->name : $this->id;
3051 $header = "<!--T:{$id}-->";
@@ -40,10 +61,19 @@
4162 return $text;
4263 }
4364
 65+ /**
 66+ * Returns oldtext, or current text if not available.
 67+ * @return \string Wikitext.
 68+ */
4469 public function getOldText() {
4570 return isset( $this->oldtext ) ? $this->oldtext : $this->text;
4671 }
4772
 73+ /**
 74+ * Returns array of variables defined on this section.
 75+ * @return \arrayof{String,String} Values indexed with keys which are
 76+ * prefixed with a dollar sign.
 77+ */
4878 public function getVariables() {
4979 $re = '~<tvar\|([^>]+)>(.*?)</>~u';
5080 $matches = array();

Status & tagging log