r106792 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106791‎ | r106792 | r106793 >
Date:12:55, 20 December 2011
Author:nikerabbit
Status:ok
Tags:
Comment:
Refactor and remove some unncessary links
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
@@ -158,17 +158,10 @@
159159 return $res;
160160 }
161161
162 - public function listPages() {
163 - global $wgOut;
164 -
165 - $res = $this->loadPagesFromDB();
166 - if ( !$res->numRows() ) {
167 - $wgOut->addWikiMsg( 'tpt-list-nopages' );
168 - return;
169 - }
170 -
 162+ protected function buildPageArray( /*db result*/ $res ) {
171163 $pages = array();
172164 foreach ( $res as $r ) {
 165+ // We have multiple rows for same page, because of different tags
173166 if ( !isset( $pages[$r->page_id] ) ) {
174167 $pages[$r->page_id] = array();
175168 $title = Title::newFromRow( $r );
@@ -179,7 +172,19 @@
180173 $tag = RevTag::typeToTag( $r->rt_type );
181174 $pages[$r->page_id][$tag] = intval( $r->rt_revision );
182175 }
 176+ return $pages;
 177+ }
183178
 179+ public function listPages() {
 180+ global $wgOut;
 181+
 182+ $res = $this->loadPagesFromDB();
 183+ $pages = $this->buildPageArray( $res );
 184+ if ( !count( $pages ) ) {
 185+ $wgOut->addWikiMsg( 'tpt-list-nopages' );
 186+ return;
 187+ }
 188+
184189 // Pages where mark <= tag
185190 $items = array();
186191 foreach ( $pages as $index => $page ) {
@@ -196,7 +201,7 @@
197202 $link = "<b>$link</b>";
198203 }
199204 $acts = $this->actionLinks( $page['title'], $page['tp:mark'], $page['latest'], 'old' );
200 - $items[] = "<li>$link ($acts) </li>";
 205+ $items[] = "<li>$link $acts</li>";
201206 unset( $pages[$index] );
202207 }
203208
@@ -222,7 +227,7 @@
223228
224229 $link = $this->user->getSkin()->link( $page['title'] );
225230 $acts = $this->actionLinks( $page['title'], $page['tp:tag'], $page['latest'], 'new' );
226 - $items[] = "<li>$link ($acts) </li>";
 231+ $items[] = "<li>$link $acts</li>";
227232
228233 unset( $pages[$index] );
229234 }
@@ -239,7 +244,7 @@
240245 foreach ( $pages as $index => $page ) {
241246 $link = $this->user->getSkin()->link( $page['title'] );
242247 $acts = $this->actionLinks( $page['title'], $page['tp:tag'], $page['latest'], 'stuck' );
243 - $items[] = "<li>$link ($acts) </li>";
 248+ $items[] = "<li>$link $acts</li>";
244249
245250 unset( $pages[$index] );
246251 }
@@ -261,22 +266,6 @@
262267 protected function actionLinks( $title, $rev, $latest, $old = 'old' ) {
263268 $actions = array();
264269
265 - /* For pages that have been marked for translation at some point,
266 - * but there has been new changes since then, provide a link to
267 - * to view the differences between last marked version and latest
268 - * version of the page.
269 - */
270 - if ( $latest !== $rev && $old !== 'new' ) {
271 - $actions[] = $this->user->getSkin()->link(
272 - $title,
273 - htmlspecialchars( wfMsg( 'tpt-rev-old', $rev ) ),
274 - array(),
275 - array( 'oldid' => $rev, 'diff' => $title->getLatestRevId() )
276 - );
277 - } else {
278 - $actions[] = wfMsgHtml( 'tpt-rev-latest' );
279 - }
280 -
281270 if ( $this->user->isAllowed( 'pagetranslation' ) ) {
282271 $token = $this->user->editToken();
283272
@@ -308,18 +297,12 @@
309298 }
310299 }
311300
312 - if ( $old === 'old' && $this->user->isAllowed( 'translate' ) ) {
313 - $actions[] = $this->user->getSkin()->link(
314 - SpecialPage::getTitleFor( 'Translate' ),
315 - wfMsgHtml( 'tpt-translate-this' ),
316 - array(),
317 - array( 'group' => TranslatablePage::getMessageGroupIdFromTitle( $title ) )
318 - );
 301+ if ( !count( $actions ) ) {
 302+ return '';
319303 }
320 -
321304 global $wgLang;
322 -
323 - return $wgLang->semicolonList( $actions );
 305+ $flattened = $wgLang->semicolonList( $actions );
 306+ return Html::rawElement( 'span', array( 'class' => 'mw-tpt-actions' ), "($flattened)" );
324307 }
325308
326309 public function checkInput( TranslatablePage $page, &$error = false ) {
Index: trunk/extensions/Translate/PageTranslation.i18n.php
@@ -56,11 +56,8 @@
5757 but no version of {{PLURAL:$1|this page is|these pages are}} currently marked for translation.',
5858 'tpt-other-pages' => '{{PLURAL:$1|An old version of this page is|Older versions of these pages are}} marked for translation,
5959 but the latest {{PLURAL:$1|version|versions}} cannot be marked for translation.',
60 - 'tpt-rev-latest' => 'latest version',
61 - 'tpt-rev-old' => 'difference to previous marked version',
6260 'tpt-rev-mark-new' => 'mark this version for translation',
6361 'tpt-rev-unmark' => 'remove this page from translation',
64 - 'tpt-translate-this' => 'translate this page',
6562
6663 # Source and translation page headers
6764 'translate-tag-translate-link-desc' => 'Translate this page',

Status & tagging log