r106797 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106796‎ | r106797 | r106798 >
Date:13:50, 20 December 2011
Author:nikerabbit
Status:ok
Tags:
Comment:
I18n #320: new section for discouraged pages
Also took the time to refactor the code and display for better readability
Modified paths:
  • /trunk/extensions/Translate/PageTranslation.i18n.php (modified) (history)
  • /trunk/extensions/Translate/tag/SpecialPageTranslation.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/tag/SpecialPageTranslation.php
@@ -175,85 +175,116 @@
176176 return $pages;
177177 }
178178
 179+ protected function classifyPages( array $in ) {
 180+ $out = array(
 181+ 'proposed' => array(),
 182+ 'active' => array(),
 183+ 'broken' => array(),
 184+ 'discouraged' => array(),
 185+ );
 186+
 187+ foreach ( $in as $index => $page ) {
 188+ if ( !isset( $page['tp:mark'] ) ) {
 189+ // Never marked
 190+ $out['proposed'][$index] = $page;
 191+ } elseif ( $page['tp:tag'] === $page['latest'] ) {
 192+ // Marked and latest version if fine
 193+ $out['active'][$index] = $page;
 194+ } else {
 195+ // Marked but latest version if not fine
 196+ $out['broken'][$index] = $page;
 197+ }
 198+ }
 199+
 200+ // broken and proposed take preference over discouraged status
 201+ foreach ( $out['active'] as $index => $page ) {
 202+ $id = TranslatablePage::getMessageGroupIdFromTitle( $page['title'] );
 203+ $group = MessageGroups::getGroup( $id );
 204+ if ( MessageGroups::getPriority( $group ) === 'discouraged' ) {
 205+ $out['discouraged'][$index] = $page;
 206+ unset( $out['active'][$index] );
 207+ }
 208+ }
 209+ return $out;
 210+ }
 211+
179212 public function listPages() {
180213 global $wgOut;
 214+ $out = $wgOut;
 215+ $linker = class_exists( 'DummyLinker' ) ? new DummyLinker : new Linker;
181216
182217 $res = $this->loadPagesFromDB();
183 - $pages = $this->buildPageArray( $res );
184 - if ( !count( $pages ) ) {
 218+ $allpages = $this->buildPageArray( $res );
 219+ if ( !count( $allpages ) ) {
185220 $wgOut->addWikiMsg( 'tpt-list-nopages' );
186221 return;
187222 }
 223+ $types = $this->classifyPages( $allpages );
188224
189 - // Pages where mark <= tag
190 - $items = array();
191 - foreach ( $pages as $index => $page ) {
192 - if ( !isset( $page['tp:mark'] ) || !isset( $page['tp:tag'] ) ) {
193 - continue;
 225+ $pages = $types['proposed'];
 226+ if ( count( $pages ) ) {
 227+ $out->wrapWikiMsg( '== $1 ==', 'tpt-new-pages-title' );
 228+ $wgOut->addWikiMsg( 'tpt-new-pages', count( $pages ) );
 229+ $out->addHtml( '<ol>' );
 230+ foreach ( $pages as $page ) {
 231+ $link = $linker->link( $page['title'] );
 232+ $acts = $this->actionLinks( $page['title'], $page['tp:tag'], $page['latest'], 'new' );
 233+ $out->addHtml( "<li>$link $acts</li>" );
194234 }
 235+ $out->addHtml( '</ol>' );
 236+ }
195237
196 - if ( $page['tp:tag'] !== $page['latest'] ) {
197 - continue;
198 - }
 238+ $pages = $types['active'];
 239+ if ( count( $pages ) ) {
 240+ $out->wrapWikiMsg( '== $1 ==', 'tpt-old-pages-title' );
 241+ $out->addWikiMsg( 'tpt-old-pages', count( $pages ) );
 242+ $out->addHtml( '<ol>' );
 243+ foreach ( $pages as $page ) {
 244+ $link = $linker->link( $page['title'] );
 245+ $canUpdate = 'old';
 246+ if ( $page['tp:mark'] !== $page['tp:tag'] ) {
 247+ $link = "<b>$link</b>";
 248+ $canUpdate = 'new';
 249+ }
199250
200 - $link = $this->user->getSkin()->link( $page['title'] );
201 - if ( $page['tp:mark'] !== $page['tp:tag'] ) {
202 - $link = "<b>$link</b>";
 251+ $acts = $this->actionLinks( $page['title'], $page['tp:tag'], $page['latest'], $canUpdate );
 252+ $out->addHtml( "<li>$link $acts</li>" );
203253 }
204 - $acts = $this->actionLinks( $page['title'], $page['tp:mark'], $page['latest'], 'old' );
205 - $items[] = "<li>$link $acts</li>";
206 - unset( $pages[$index] );
 254+ $out->addHtml( '</ol>' );
207255 }
208256
209 - if ( count( $items ) ) {
210 - $wgOut->addWikiMsg( 'tpt-old-pages', count( $items ) );
211 - $wgOut->addHtml( Html::rawElement( 'ol', null, implode( "\n", $items ) ) );
212 - $wgOut->addHtml( '<hr />' );
 257+ $pages = $types['broken'];
 258+ if ( count( $pages ) ) {
 259+ $out->wrapWikiMsg( '== $1 ==', 'tpt-other-pages-title' );
 260+ $out->addWikiMsg( 'tpt-other-pages', count( $pages ) );
 261+ $out->addHtml( '<ol>' );
 262+ foreach ( $pages as $page ) {
 263+ $link = $linker->link( $page['title'] );
 264+ $acts = $this->actionLinks( $page['title'], $page['tp:tag'], $page['latest'], 'stuck' );
 265+ $out->addHtml( "<li>$link $acts</li>" );
 266+ }
 267+ $out->addHtml( '</ol>' );
213268 }
214269
215 - // Pages which are never marked
216 - $items = array();
217 - foreach ( $pages as $index => $page ) {
218 - if ( isset( $page['tp:mark'] ) || !isset( $page['tp:tag'] ) ) {
219 - continue;
220 - }
 270+ $pages = $types['discouraged'];
 271+ if ( count( $pages ) ) {
 272+ $out->wrapWikiMsg( '== $1 ==', 'tpt-discouraged-pages-title' );
 273+ $out->addWikiMsg( 'tpt-discouraged-pages', count( $pages ) );
 274+ $out->addHtml( '<ol>' );
 275+ foreach ( $pages as $page ) {
 276+ $link = $linker->link( $page['title'] );
 277+ $canUpdate = 'old';
 278+ if ( $page['tp:mark'] !== $page['tp:tag'] ) {
 279+ $link = "<b>$link</b>";
 280+ $canUpdate = 'new';
 281+ }
221282
222 - /* Ignore pages which have had \<translate> at some point, but which
223 - * have never been marked. */
224 - if ( $page['tp:tag'] !== $page['latest'] ) {
225 - unset( $pages[$index] );
226 - continue;
 283+ $acts = $this->actionLinks( $page['title'], $page['tp:tag'], $page['latest'], $canUpdate );
 284+ $out->addHtml( "<li>$link $acts</li>" );
227285 }
228 -
229 - $link = $this->user->getSkin()->link( $page['title'] );
230 - $acts = $this->actionLinks( $page['title'], $page['tp:tag'], $page['latest'], 'new' );
231 - $items[] = "<li>$link $acts</li>";
232 -
233 - unset( $pages[$index] );
 286+ $out->addHtml( '</ol>' );
234287 }
235288
236 - if ( count( $items ) ) {
237 - $wgOut->addWikiMsg( 'tpt-new-pages', count( $items ) );
238 - $wgOut->addHtml( Html::rawElement( 'ol', null, implode( "\n", $items ) ) );
239 - $wgOut->addHtml( '<hr />' );
240 - }
241 -
242 - /* Pages which have been marked in the past, but newest version does
243 - * not have a tag */
244 - $items = array();
245 - foreach ( $pages as $index => $page ) {
246 - $link = $this->user->getSkin()->link( $page['title'] );
247 - $acts = $this->actionLinks( $page['title'], $page['tp:tag'], $page['latest'], 'stuck' );
248 - $items[] = "<li>$link $acts</li>";
249 -
250 - unset( $pages[$index] );
251 - }
252 -
253 - if ( count( $items ) ) {
254 - $wgOut->addWikiMsg( 'tpt-other-pages', count( $items ) );
255 - $wgOut->addHtml( Html::rawElement( 'ol', null, implode( "\n", $items ) ) );
256 - $wgOut->addHtml( '<hr />' );
257 - }
258289 }
259290
260291 /**
Index: trunk/extensions/Translate/PageTranslation.i18n.php
@@ -51,11 +51,19 @@
5252
5353 # Page list on the special page
5454 'tpt-list-nopages' => 'No pages are marked for translation nor ready to be marked for translation.',
55 - 'tpt-old-pages' => 'Some version of {{PLURAL:$1|this page has|these pages have}} been marked for translation.',
 55+
 56+ 'tpt-new-pages-title' => 'Pages proposed for translation',
 57+ 'tpt-old-pages-title' => 'Pages in translation',
 58+ 'tpt-other-pages-title' => 'Broken pages',
 59+ 'tpt-discouraged-pages-title' => 'Discouraged pages',
 60+
5661 'tpt-new-pages' => '{{PLURAL:$1|This page contains|These pages contain}} text with translation tags,
5762 but no version of {{PLURAL:$1|this page is|these pages are}} currently marked for translation.',
 63+ 'tpt-old-pages' => 'Some version of {{PLURAL:$1|this page has|these pages have}} been marked for translation.',
5864 'tpt-other-pages' => '{{PLURAL:$1|An old version of this page is|Older versions of these pages are}} marked for translation,
5965 but the latest {{PLURAL:$1|version|versions}} cannot be marked for translation.',
 66+ 'tpt-discouraged-pages' => '{{PLURAL:$1|This page has|These pages have}} been discouraged from further translation.',
 67+
6068 'tpt-rev-mark-new' => 'mark this version for translation',
6169 'tpt-rev-unmark' => 'remove this page from translation',
6270
@@ -196,8 +204,10 @@
197205 $2 is a count of sections which can be used with PLURAL,
198206 $3 is an URL.',
199207 'tpt-mark-summary' => 'This message is used as an edit summary.',
200 - 'tpt-old-pages' => 'The words "some version" refer to "one version of the page", or "a single version of each of the pages", respectively. Each page can have either one or none of its versions marked for translaton.',
 208+ 'tpt-old-pages' => 'The words "some version" refer to "one version of the page", or "a single version of each of the pages", respectively. Each page can have either one or none of its versions marked for translaton. $1 is the number of pages',
201209 'tpt-other-pages' => '$1 is the number of pages in the following list.',
 210+ 'tpt-new-pages' => '$1 is the number of pages in the following list.',
 211+ 'tpt-discouraged-pages' => '$1 is the number of pages in the following list.',
202212 'tpt-rev-old' => '',
203213 'translate-tag-markthisagain' => '"has changes" is to be understood as "has been altered/edited"',
204214 'translate-tag-hasnew' => '"has changes" is to be understood as "has been altered/edited"',
@@ -220,6 +230,10 @@
221231 'pt-deletepage-action-check' => 'This is a button label. "List" is an imperative verb.',
222232 'pt-deletepage-current' => '{{Identical|Page name}}',
223233 'pt-deletepage-reason' => '{{Identical|Reason}}',
 234+ 'tpt-new-pages-title' => 'Header in [[Special:PageTranslation]]',
 235+ 'tpt-old-pages-title' => 'Header in [[Special:PageTranslation]]',
 236+ 'tpt-other-pages-title' => 'Header in [[Special:PageTranslation]]',
 237+ 'tpt-discouraged-pages-title' => 'Header in [[Special:PageTranslation]]',
224238 );
225239
226240 /** ꢱꣃꢬꢵꢯ꣄ꢡ꣄ꢬꢵ (ꢱꣃꢬꢵꢯ꣄ꢡ꣄ꢬꢵ)

Follow-up revisions

RevisionCommit summaryAuthorDate
r106938Followup r106797: ignore unmarked pages which had haved <translate>, but the ...nikerabbit11:01, 21 December 2011

Status & tagging log