r26926 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r26925‎ | r26926 | r26927 >
Date:14:12, 24 October 2007
Author:nikerabbit
Status:old
Tags:
Comment:
* some bugfixes
* new special page
Modified paths:
  • /trunk/extensions/Translate/MessageGroups.php (modified) (history)
  • /trunk/extensions/Translate/SpecialMagic.php (modified) (history)
  • /trunk/extensions/Translate/SpecialTranslationChanges.php (added) (history)
  • /trunk/extensions/Translate/Translate.php (modified) (history)
  • /trunk/extensions/Translate/fuzzy.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/Translate.php
@@ -12,7 +12,7 @@
1313
1414 $wgExtensionCredits['specialpage'][] = array(
1515 'name' => 'Translate',
16 - 'version' => '4.1',
 16+ 'version' => '4.2',
1717 'author' => 'Niklas Laxström',
1818 'description' => 'Special page for translating Mediawiki and beyond'
1919 );
@@ -25,11 +25,14 @@
2626 $wgAutoloadClasses['languages'] = $IP . '/maintenance/language/languages.inc';
2727 $wgAutoloadClasses['SpecialTranslate'] = $dir . 'TranslatePage.php';
2828 $wgAutoloadClasses['SpecialMagic'] = $dir . 'SpecialMagic.php';
 29+$wgAutoloadClasses['SpecialTranslationChanges'] = $dir . 'SpecialTranslationChanges.php';
2930
 31+
3032 $wgExtensionMessagesFiles['Translate'] = $dir . 'Translate.i18n.php';
3133
3234 $wgSpecialPages['Translate'] = 'SpecialTranslate';
3335 $wgSpecialPages['Magic'] = 'SpecialMagic';
 36+$wgSpecialPages['TranslationChanges'] = 'SpecialTranslationChanges';
3437
3538 $wgHooks['EditPage::showEditForm:initial'][] = 'TranslateEditAddons::addTools';
3639
@@ -78,6 +81,7 @@
7982 'ext-editcount' => 'EditcountMessageGroup',
8083 'ext-expandtemplates' => 'ExpandTemplatesMessageGroup',
8184 'ext-fancycaptcha' => 'FancyCaptchaMessageGroup',
 85+'ext-fckeditor' => 'FCKeditorExtensionGroup',
8286 'ext-filepath' => 'FilePathMessageGroup',
8387 'ext-flaggedrevs' => 'FlaggedRevsMessageGroup',
8488 'ext-gadgets' => 'GadgetsExtensionGroup',
Index: trunk/extensions/Translate/SpecialMagic.php
@@ -529,12 +529,17 @@
530530 */
531531 public function export() {
532532 $array = $this->getArray();
 533+ foreach ($array[self::LANG_MASTER] as $index => $ns) {
 534+ if ($index !== 0 && !isset($array[self::LANG_CURRENT][$index][0])) {
 535+ return "Missing translation for ns $index, cannot export";
 536+ }
 537+ }
533538
534539 $text = <<<EOL
535540 \$namespaceNames = array(
536541 NS_MEDIA => '{$array[self::LANG_CURRENT][-2][0]}',
537542 NS_SPECIAL => '{$array[self::LANG_CURRENT][-1][0]}',
538 - NS_MAIN => '{$array[self::LANG_CURRENT][0][0]}',
 543+ NS_MAIN => '',
539544 NS_TALK => '{$array[self::LANG_CURRENT][1][0]}',
540545 NS_USER => '{$array[self::LANG_CURRENT][2][0]}',
541546 NS_USER_TALK => '{$array[self::LANG_CURRENT][3][0]}',
Index: trunk/extensions/Translate/MessageGroups.php
@@ -47,6 +47,8 @@
4848
4949 if ( $translation === null ) { return false; }
5050
 51+ if ( strpos($translation, '!!FUZZY!!') !== false ) { return false; }
 52+
5153 if ( $m['optional'] ) {
5254 if ( $translation !== $fallback ) {
5355 $comment = "#optional";
@@ -490,7 +492,6 @@
491493
492494 protected $exportStart = '$messages = array(';
493495 protected $exportEnd = ');';
494 -
495496 }
496497
497498 class CentralAuthMessageGroup extends ExtensionMessageGroup {
@@ -708,6 +709,18 @@
709710 protected $exportEnd = '),';
710711 }
711712
 713+class FCKeditorExtensionGroup extends MultipleFileMessageGroup {
 714+ protected $label = 'FCKeditor';
 715+ protected $id = 'ext-fckeditor';
 716+
 717+ protected $arrName = 'allMessages';
 718+ protected $messageFile = 'FCKeditor/FCKeditor.i18n.en.php';
 719+ protected $filePattern = 'FCKeditor/FCKeditor.i18n.$CODE.php';
 720+
 721+ protected $exportStart = '$allMessages = array(';
 722+ protected $exportEnd = ');';
 723+}
 724+
712725 class FlaggedRevsMessageGroup extends ExtensionMessageGroup {
713726 protected $label = 'Flagged Revs';
714727 protected $id = 'ext-flaggedrevs';
@@ -835,6 +848,11 @@
836849
837850 protected $arrName = 'messages';
838851 protected $messageFile = 'Makesysop/SpecialMakesysop.i18n.php';
 852+
 853+ protected $exportStart = '\'$CODE\' => array(';
 854+ protected $exportPrefix= '';
 855+ protected $exportLineP = '';
 856+ protected $exportEnd = '),';
839857 }
840858
841859 class MakeValidateMessageGroup extends ExtensionMessageGroup {
Index: trunk/extensions/Translate/fuzzy.php
@@ -26,7 +26,7 @@
2727 $this->titles = $titles;
2828 $this->dryrun = $dryrun;
2929
30 - global $wgTranslateFuzzyBotName, $wgTranslateFuzzyBotId, $wgUser;
 30+ global $wgTranslateFuzzyBotName, $wgUser;
3131
3232 if ( !isset( $wgTranslateFuzzyBotName ) ) {
3333 echo "\$wgTranslateFuzzyBotName is not set\n";
Index: trunk/extensions/Translate/SpecialTranslationChanges.php
@@ -0,0 +1,162 @@
 2+<?php
 3+
 4+class SpecialTranslationChanges extends SpecialPage {
 5+
 6+ function __construct() {
 7+ SpecialPage::SpecialPage( 'TranslationChanges' );
 8+ }
 9+
 10+ /** Access point for this special page */
 11+ public function execute() {
 12+ global $wgOut, $wgScriptPath, $wgJsMimeType, $wgStyleVersion;
 13+ wfLoadExtensionMessages( 'Translate' );
 14+
 15+ $wgOut->addScript(
 16+ Xml::openElement( 'script', array( 'type' => $wgJsMimeType, 'src' =>
 17+ "$wgScriptPath/extensions/CleanChanges/cleanchanges.js?$wgStyleVersion" )
 18+ ) . '</script>'
 19+ );
 20+
 21+
 22+ #$this->setup();
 23+ $this->setHeaders();
 24+
 25+ $rows = $this->runQuery();
 26+ $wgOut->addHTMl( $this->output( $rows ) );
 27+ }
 28+
 29+ protected function runQuery() {
 30+ $dbr = wfGetDB( DB_SLAVE );
 31+ $recentchanges = $dbr->tableName( 'recentchanges' );
 32+
 33+ $from = '';
 34+ $days = 1;
 35+ $cutoff_unixtime = time() - ( $days * 86400 );
 36+ $cutoff_unixtime = $cutoff_unixtime - ($cutoff_unixtime % 86400);
 37+ $cutoff = $dbr->timestamp( $cutoff_unixtime );
 38+ if(preg_match('/^[0-9]{14}$/', $from) and $from > wfTimestamp(TS_MW,$cutoff)) {
 39+ $cutoff = $dbr->timestamp($from);
 40+ }
 41+
 42+
 43+ $sql = "SELECT *, substring_index(rc_title, '/', -1) as lang FROM $recentchanges " .
 44+ "WHERE rc_timestamp >= '{$cutoff}' " .
 45+ "AND rc_namespace = 8 " .
 46+ "ORDER BY lang ASC, rc_timestamp DESC";
 47+
 48+ $res = $dbr->query( $sql, __METHOD__ );
 49+
 50+ // Fetch results, prepare a batch link existence check query
 51+ $rows = array();
 52+ $batch = new LinkBatch;
 53+ while( $row = $dbr->fetchObject( $res ) ){
 54+ $rows[] = $row;
 55+ // User page link
 56+ $title = Title::makeTitleSafe( NS_USER, $row->rc_user_text );
 57+ $batch->addObj( $title );
 58+
 59+ // User talk
 60+ $title = Title::makeTitleSafe( NS_USER_TALK, $row->rc_user_text );
 61+ $batch->addObj( $title );
 62+ }
 63+ $dbr->freeResult( $res );
 64+ $batch->execute();
 65+ return $rows;
 66+ }
 67+
 68+ protected function output( Array $rows ) {
 69+ global $wgLang;
 70+ $index = 0;
 71+ $lastLanguage = '';
 72+ $output = '';
 73+ $rowTitle = '';
 74+ $rowId = '';
 75+ $rowLang = '';
 76+ $rowTl = '';
 77+ $rowCache = array();
 78+ foreach ( $rows as $row ) {
 79+
 80+ if ( $row->lang !== $lastLanguage ) {
 81+ $lastLanguage = $row->lang;
 82+ if ( count($rowCache) ) {
 83+ $output .= self::makeBlock( $rowLang, $rowTl, $rowCache, $rowId );
 84+ $rowCache = array();
 85+ }
 86+
 87+ $rci = 'RCI' . $row->lang . $index;
 88+ $rcl = 'RCL' . $row->lang . $index;
 89+ $rcm = 'RCM' . $row->lang . $index;
 90+ $toggleLink = "javascript:toggleVisibilityE('$rci', '$rcm', '$rcl', 'block')";
 91+ $rowTl =
 92+ Xml::tags( 'span', array( 'id' => $rcm ),
 93+ Xml::tags('a', array( 'href' => $toggleLink ), $this->sideArrow() ) ) .
 94+ Xml::tags( 'span', array( 'id' => $rcl, 'style' => 'display: none;' ),
 95+ Xml::tags('a', array( 'href' => $toggleLink ), $this->downArrow() ) );
 96+
 97+ $rowLang = $row->lang;
 98+ $rowId = $rci;
 99+ }
 100+
 101+ # New row
 102+ $date = $wgLang->timeAndDate( $row->rc_timestamp, /* adj */ true, /* format */ true );
 103+ $rowCache[] = Xml::element( 'li', null, "$date $row->rc_title by $row->rc_user_text" );
 104+
 105+ $index++;
 106+ }
 107+
 108+ if ( count($rowCache) ) {
 109+ $output .= self::makeBlock( $rowLang, $rowTl, $rowCache, $rowId );
 110+ $rowCache = array();
 111+ }
 112+
 113+ return $output;
 114+ }
 115+
 116+ private static function makeBlock( $tl, $lang, $rowCache, $rowId ) {
 117+ $changes = count($rowCache);
 118+ $output = Xml::tags( 'h2', null, "$tl $lang ($changes changes)" );
 119+ $output .= Xml::tags( 'ul',
 120+ array( 'id' => $rowId, 'style' => 'display: none' ),
 121+ implode( "\n", $rowCache )
 122+ );
 123+ return $output;
 124+ }
 125+
 126+ /**
 127+ * Generate HTML for an arrow or placeholder graphic
 128+ * @param string $dir one of '', 'd', 'l', 'r'
 129+ * @param string $alt text
 130+ * @return string HTML <img> tag
 131+ * @access private
 132+ */
 133+ function arrow( $dir, $alt='' ) {
 134+ global $wgStylePath;
 135+ $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
 136+ $encAlt = htmlspecialchars( $alt );
 137+ return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" />";
 138+ }
 139+
 140+ /**
 141+ * Generate HTML for a right- or left-facing arrow,
 142+ * depending on language direction.
 143+ * @return string HTML <img> tag
 144+ * @access private
 145+ */
 146+ function sideArrow() {
 147+ global $wgContLang;
 148+ $dir = $wgContLang->isRTL() ? 'l' : 'r';
 149+ return $this->arrow( $dir, '+' );
 150+ }
 151+
 152+ /**
 153+ * Generate HTML for a down-facing arrow
 154+ * depending on language direction.
 155+ * @return string HTML <img> tag
 156+ * @access private
 157+ */
 158+ function downArrow() {
 159+ return $this->arrow( 'd', '-' );
 160+ }
 161+
 162+
 163+}
\ No newline at end of file
Property changes on: trunk/extensions/Translate/SpecialTranslationChanges.php
___________________________________________________________________
Added: svn:eol-style
1164 + native

Status & tagging log