Index: trunk/extensions/Translate/tag/TranslatablePage.php |
— | — | @@ -1,7 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | 4 | * Translatable page model. |
5 | | - |
6 | 5 | * @defgroup PageTranslation Page Translation |
7 | 6 | * @file |
8 | 7 | * @author Niklas Laxström |
Index: trunk/extensions/Translate/tag/SpecialPageTranslation.php |
— | — | @@ -16,8 +16,7 @@ |
17 | 17 | * It will list all pages in their various states and provides actions |
18 | 18 | * that are suitable for given translatable page. |
19 | 19 | * |
20 | | - * @ingroup SpecialPage |
21 | | - * @ingroup PageTranslation |
| 20 | + * @ingroup SpecialPage PageTranslation |
22 | 21 | */ |
23 | 22 | class SpecialPageTranslation extends SpecialPage { |
24 | 23 | function __construct() { |
— | — | @@ -595,6 +594,14 @@ |
596 | 595 | } |
597 | 596 | } |
598 | 597 | |
| 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 | + */ |
599 | 606 | public static function superDebug( $method, $msg /* varags */ ) { |
600 | 607 | $args = func_get_args(); |
601 | 608 | $args = array_slice( $args, 2 ); |
Index: trunk/extensions/Translate/tag/TPParse.php |
— | — | @@ -1,7 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | | - * This class represents the results of parsed source page, that is, the |
5 | | - * extracted sections and a template. |
| 4 | + * Helper code TranslatablePage. |
6 | 5 | * |
7 | 6 | * @file |
8 | 7 | * @author Niklas Laxström |
— | — | @@ -10,28 +9,53 @@ |
11 | 10 | */ |
12 | 11 | |
13 | 12 | /** |
14 | | - * @todo Needs documentation. |
| 13 | + * This class represents the results of parsed source page, that is, the |
| 14 | + * extracted sections and a template. |
15 | 15 | * @ingroup PageTranslation |
16 | 16 | */ |
17 | 17 | class TPParse { |
| 18 | + /// \type{Title} Title of the page. |
18 | 19 | protected $title = null; |
19 | 20 | |
| 21 | + /** \arrayof{String,TPSection} Parsed sections indexed with placeholder. |
| 22 | + * @todo Encapsulate |
| 23 | + */ |
20 | 24 | public $sections = array(); |
| 25 | + /** \string Page source with content replaced with placeholders. |
| 26 | + * @todo Encapsulate |
| 27 | + */ |
21 | 28 | public $template = null; |
22 | | - public $dbSections = null; |
| 29 | + /// \arrayof{String,TPSection} Sections saved in the database. |
| 30 | + protected $dbSections = null; |
23 | 31 | |
| 32 | + /// Constructor |
24 | 33 | public function __construct( Title $title ) { |
25 | 34 | $this->title = $title; |
26 | 35 | } |
27 | 36 | |
| 37 | + /** |
| 38 | + * Returns the number of sections in this page. |
| 39 | + * @return \int |
| 40 | + */ |
28 | 41 | public function countSections() { |
29 | 42 | return count( $this->sections ); |
30 | 43 | } |
31 | 44 | |
| 45 | + /** |
| 46 | + * Returns the page template where translatable content is replaced with |
| 47 | + * placeholders. |
| 48 | + * @return \string |
| 49 | + */ |
32 | 50 | public function getTemplate() { |
33 | 51 | return $this->template; |
34 | 52 | } |
35 | 53 | |
| 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 | + */ |
36 | 60 | public function getTemplatePretty() { |
37 | 61 | $text = $this->template; |
38 | 62 | $sections = $this->getSectionsForSave(); |
— | — | @@ -42,6 +66,10 @@ |
43 | 67 | return $text; |
44 | 68 | } |
45 | 69 | |
| 70 | + /** |
| 71 | + * Gets the sections and assigns section id for new sections |
| 72 | + * @return \arrayof{String,TPSection} |
| 73 | + */ |
46 | 74 | public function getSectionsForSave() { |
47 | 75 | $this->loadFromDatabase(); |
48 | 76 | |
— | — | @@ -76,6 +104,10 @@ |
77 | 105 | return $sections; |
78 | 106 | } |
79 | 107 | |
| 108 | + /** |
| 109 | + * Returns list of deleted sections. |
| 110 | + * @return \arrayof{String,TPsection} List of sections indexed by id. |
| 111 | + */ |
80 | 112 | public function getDeletedSections() { |
81 | 113 | $sections = $this->getSectionsForSave(); |
82 | 114 | $deleted = $this->dbSections; |
— | — | @@ -89,6 +121,9 @@ |
90 | 122 | return $deleted; |
91 | 123 | } |
92 | 124 | |
| 125 | + /** |
| 126 | + * Load section saved in the database. Populates dbSections. |
| 127 | + */ |
93 | 128 | protected function loadFromDatabase() { |
94 | 129 | if ( $this->dbSections !== null ) { |
95 | 130 | return; |
— | — | @@ -111,9 +146,14 @@ |
112 | 147 | } |
113 | 148 | } |
114 | 149 | |
| 150 | + /** |
| 151 | + * Returns the source page stripped of most translation mark-up. |
| 152 | + * @return \string Wikitext. |
| 153 | + */ |
115 | 154 | public function getSourcePageText() { |
116 | 155 | $text = $this->template; |
117 | 156 | |
| 157 | + /// @todo Use str_replace outside of the loop. |
118 | 158 | foreach ( $this->sections as $ph => $s ) { |
119 | 159 | $text = str_replace( $ph, $s->getMarkedText(), $text ); |
120 | 160 | } |
— | — | @@ -121,6 +161,14 @@ |
122 | 162 | return $text; |
123 | 163 | } |
124 | 164 | |
| 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 | + */ |
125 | 173 | public function getTranslationPageText( /*MessageCollection*/ $collection ) { |
126 | 174 | $text = $this->template; // The source |
127 | 175 | |
— | — | @@ -170,6 +218,10 @@ |
171 | 219 | return $text; |
172 | 220 | } |
173 | 221 | |
| 222 | + /** |
| 223 | + * Replaces variables from given text. |
| 224 | + * @todo Is plain str_replace not enough (even the loop is not needed)? |
| 225 | + */ |
174 | 226 | protected static function replaceVariables( $variables, $text ) { |
175 | 227 | foreach ( $variables as $key => $value ) { |
176 | 228 | $text = str_replace( $key, $value, $text ); |
— | — | @@ -178,6 +230,12 @@ |
179 | 231 | return $text; |
180 | 232 | } |
181 | 233 | |
| 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 | + */ |
182 | 240 | protected static function replaceTagCb( $matches ) { |
183 | 241 | return preg_replace( '~^\n|\n\z~', '', $matches[2] ); |
184 | 242 | } |
Index: trunk/extensions/Translate/tag/MoveJob.php |
— | — | @@ -157,8 +157,8 @@ |
158 | 158 | } |
159 | 159 | |
160 | 160 | /** |
161 | | - * Modified from wfSuppressWarnings |
162 | | - */ |
| 161 | + * Adapted from wfSuppressWarnings to allow not leaving redirects. |
| 162 | + */ |
163 | 163 | public static function forceRedirects( $end = false ) { |
164 | 164 | static $suppressCount = 0; |
165 | 165 | static $originalLevel = null; |
Index: trunk/extensions/Translate/tag/TPSection.php |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | | - * This class represents one section of a translatable page. |
| 4 | + * Helper for TPParse. |
5 | 5 | * |
6 | 6 | * @file |
7 | 7 | * @author Niklas Laxström |
— | — | @@ -9,21 +9,42 @@ |
10 | 10 | */ |
11 | 11 | |
12 | 12 | /** |
13 | | - * @todo Needs documentation. |
| 13 | + * This class represents one individual section in translatable page. |
14 | 14 | * @ingroup PageTranslation |
15 | 15 | */ |
16 | 16 | 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; |
18 | 27 | |
| 28 | + /** |
| 29 | + * Returns section text unmodified. |
| 30 | + * @return \string Wikitext. |
| 31 | + */ |
19 | 32 | public function getText() { |
20 | 33 | return $this->text; |
21 | 34 | } |
22 | 35 | |
| 36 | + /** |
| 37 | + * Returns section text with variables replaced. |
| 38 | + * @return \string Wikitext. |
| 39 | + */ |
23 | 40 | public function getTextForTrans() { |
24 | 41 | $re = '~<tvar\|([^>]+)>(.*?)</>~u'; |
25 | 42 | return preg_replace( $re, '\2', $this->text ); |
26 | 43 | } |
27 | 44 | |
| 45 | + /** |
| 46 | + * Returns the section text section marker updated or added. |
| 47 | + * @return \string Wikitext. |
| 48 | + */ |
28 | 49 | public function getMarkedText() { |
29 | 50 | $id = isset( $this->name ) ? $this->name : $this->id; |
30 | 51 | $header = "<!--T:{$id}-->"; |
— | — | @@ -40,10 +61,19 @@ |
41 | 62 | return $text; |
42 | 63 | } |
43 | 64 | |
| 65 | + /** |
| 66 | + * Returns oldtext, or current text if not available. |
| 67 | + * @return \string Wikitext. |
| 68 | + */ |
44 | 69 | public function getOldText() { |
45 | 70 | return isset( $this->oldtext ) ? $this->oldtext : $this->text; |
46 | 71 | } |
47 | 72 | |
| 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 | + */ |
48 | 78 | public function getVariables() { |
49 | 79 | $re = '~<tvar\|([^>]+)>(.*?)</>~u'; |
50 | 80 | $matches = array(); |