http://www.mediawiki.org/wiki/Special:Code/MediaWiki/65635
Revision: 65635 Author: siebrand Date: 2010-04-28 21:30:06 +0000 (Wed, 28 Apr 2010) Log Message: ----------- * add special page alias i18n and add support to Translate * stylize.php, trailing whitespace removed, indentation updated Modified Paths: -------------- trunk/extensions/CentralNotice/CentralNotice.i18n.php trunk/extensions/CentralNotice/CentralNotice.php trunk/extensions/CentralNotice/SpecialNoticeLocal.php trunk/extensions/CentralNotice/SpecialNoticeTemplate.php trunk/extensions/CentralNotice/SpecialNoticeText.php trunk/extensions/CentralNotice/patch-add-preferred.sql trunk/extensions/CentralNotice/rebuildTemplates.php trunk/extensions/Translate/groups/mediawiki-defines.txt Added Paths: ----------- trunk/extensions/CentralNotice/CentralNotice.alias.php Added: trunk/extensions/CentralNotice/CentralNotice.alias.php =================================================================== --- trunk/extensions/CentralNotice/CentralNotice.alias.php (rev 0) +++ trunk/extensions/CentralNotice/CentralNotice.alias.php 2010-04-28 21:30:06 UTC (rev 65635) @@ -0,0 +1,12 @@ +<?php +/** + * Aliases for special pages of CentralNotice extension. + */ + +$aliases = array(); + +$aliases['en'] = array( + 'CentralNotice' => array( 'CentralNotice' ), + 'NoticeText' => array( 'NoticeText' ), + 'NoticeTemplate' => array( 'NoticeTemplate' ), +); Property changes on: trunk/extensions/CentralNotice/CentralNotice.alias.php ___________________________________________________________________ Added: svn:keywords + Id Added: svn:eol-style + native Modified: trunk/extensions/CentralNotice/CentralNotice.i18n.php =================================================================== --- trunk/extensions/CentralNotice/CentralNotice.i18n.php 2010-04-28 20:52:09 UTC (rev 65634) +++ trunk/extensions/CentralNotice/CentralNotice.i18n.php 2010-04-28 21:30:06 UTC (rev 65635) @@ -1111,7 +1111,7 @@ 'centralnotice-weight' => 'Pwys', 'centralnotice-locked' => 'Ar glo', 'centralnotice-notices' => 'Hysbysiadau', - 'centralnotice-notice-exists' => "Mae'r hysbysiad eisoes ar gael. + 'centralnotice-notice-exists' => "Mae'r hysbysiad eisoes ar gael. Ni chaiff ei ychwanegu", 'centralnotice-notice-doesnt-exist' => "Nid yw'r hysbysiad ar gael. Dim i gael gwared ohono", @@ -1126,7 +1126,7 @@ 'centralnotice-start-time' => 'Amser cychwyn (UTC)', 'centralnotice-start-hour' => 'Amser dechrau', 'centralnotice-weights' => 'Pwysau', - 'centralnotice-notice-is-locked' => "Mae'r hysbysiad wedi ei gloi. + 'centralnotice-notice-is-locked' => "Mae'r hysbysiad wedi ei gloi. Ni chaiff ei dynnu i ffwrdd", 'centralnotice-no-notices-exist' => 'Does dim hysbysiadau i gael. Gallwch ychwanegu un isod.', @@ -1514,7 +1514,7 @@ 'centralnotice-no-templates-assigned' => 'Κανένα πρότυπο δεν έχει ανατεθεί σε σημείωση. Προσθέστε κάποια!', 'centralnotice-available-templates' => 'Διαθέσιμα πρότυπα', - 'centralnotice-template-already-exists' => 'Το πρότυπο είναι ακόμη συνδεδεμένο με μία καμπάνια. + 'centralnotice-template-already-exists' => 'Το πρότυπο είναι ακόμη συνδεδεμένο με μία καμπάνια. Δεν έχει προστεθεί', 'centralnotice-preview-template' => 'Πρότυπο προεπισκόπησης', 'centralnotice-start-hour' => 'Χρόνος εκκίνησης', @@ -1522,7 +1522,7 @@ 'centralnotice-weights' => 'Βάρη', 'centralnotice-notice-is-locked' => 'Η σημείωση είναι κλειδωμένη. Δεν θα αφαιρεθεί', - 'centralnotice-overlap' => 'Το σημείωμα επικαλύπτεται με τον χρόνο ενός άλλου σημειώματος. + 'centralnotice-overlap' => 'Το σημείωμα επικαλύπτεται με τον χρόνο ενός άλλου σημειώματος. Δεν έχει προστεθεί', 'centralnotice-invalid-date-range' => 'Άκυρο εύρος ημερομηνιών. Δεν είναι ενημερωμένο', @@ -1925,7 +1925,7 @@ 'centralnotice-start-date' => 'تاریخ آغاز', 'centralnotice-start-time' => 'زمان آغاز', 'centralnotice-assigned-templates' => 'الگوهای متصل شده', - 'centralnotice-no-templates' => 'در این سیستم هیچ الگویی نیست. + 'centralnotice-no-templates' => 'در این سیستم هیچ الگویی نیست. چندتا بسازید.', 'centralnotice-no-templates-assigned' => 'الگویی به این اعلان متصل نیست. اضافه کنید!', @@ -4390,7 +4390,7 @@ 'centralnotice-overlap' => 'Merknaden overlappar tida til ein annan merknad. Legg han ikkje til', 'centralnotice-invalid-date-range' => 'Ugyldig tidsrom. Oppdaterer ikkje', 'centralnotice-null-string' => 'Kan ikkje leggja til ein nullstreng. Legg ikkje til', - 'centralnotice-confirm-delete' => 'Er du sikker på at du vil sletta? + 'centralnotice-confirm-delete' => 'Er du sikker på at du vil sletta? Denne handlinga kan ikkje bli omgjort.', 'centralnotice-no-notices-exist' => 'Ingen merknader finst. Legg til ein under', 'centralnotice-no-templates-translate' => 'Det finst ingen malar å endra omsetjingar for', @@ -5410,7 +5410,7 @@ 'centralnotice-change-lang' => 'Cancia la lingua dâ traduzzioni', 'centralnotice-weights' => 'Pisa', 'centralnotice-notice-is-locked' => "L'avvisu è bliccatu. Avvisu nun livatu", - 'centralnotice-overlap' => "L'avvisu si camìna ntê pèdi di n'àutru avvisu a causa dû tempu. + 'centralnotice-overlap' => "L'avvisu si camìna ntê pèdi di n'àutru avvisu a causa dû tempu. Nun junciutu", 'centralnotice-invalid-date-range' => 'Ntirvaddu di tempu nun vàlidu. Nun fu canciatu', @@ -6207,7 +6207,7 @@ 'centralnotice' => 'Merkezi uwedomleniýe admini', 'noticetemplate' => 'Merkezi uwedomleniýe şablony', 'centralnotice-desc' => 'Merkezi uwedomleniýe goşýar', - 'centralnotice-summary' => 'Bu modul size bar bolan gurulgy merkezi uwedomleniýeleri üýtgetmäge rugsat berýär. + 'centralnotice-summary' => 'Bu modul size bar bolan gurulgy merkezi uwedomleniýeleri üýtgetmäge rugsat berýär. Ony köne uwedomleniýeleri goşmak ýa-da aýyrmak üçin hem ulanmak bolýar.', 'centralnotice-query' => 'Häzirki uwedomleniýeleri üýtget', 'centralnotice-notice-name' => 'Uwedomleniýe ady', @@ -6296,7 +6296,7 @@ 'centralnotice' => 'Tagapangasiwa ng pangunahing pabatid', 'noticetemplate' => 'Suleras ng pangunahing pabatid', 'centralnotice-desc' => 'Nagdaragdag ng pangunahing pahayag ng sayt/sityo', - 'centralnotice-summary' => 'Nagbibigay ang bahaging-panggampaning ito ng pahintulot na mabago mo ang iyong pangkasulukyang naitakdang mga pangunahing pahayag. + 'centralnotice-summary' => 'Nagbibigay ang bahaging-panggampaning ito ng pahintulot na mabago mo ang iyong pangkasulukyang naitakdang mga pangunahing pahayag. Maaari rin itong gamitin upang makapagdagdag o magtanggal ng mga lumang pahayag.', 'centralnotice-query' => 'Baguhin ang pangkasalukuyang mga pabatid', 'centralnotice-notice-name' => 'Pangalan ng pabatid', @@ -6485,7 +6485,7 @@ 'centralnotice' => 'Управління централізованими сповіщеннями', 'noticetemplate' => 'Шаблон централізованого повідомлення', 'centralnotice-desc' => 'Додає загальне повідомлення сайту', - 'centralnotice-summary' => 'Цей модуль дозволяє вам змінювати ваші поточні централізовані повідомлення. + 'centralnotice-summary' => 'Цей модуль дозволяє вам змінювати ваші поточні централізовані повідомлення. Він також може використовуватися для додавання нових і видалення старих повідомлень.', 'centralnotice-query' => 'Змінити поточне повідомлення', 'centralnotice-notice-name' => 'Назва повідомлення', @@ -6511,13 +6511,13 @@ 'centralnotice-weight' => 'Ширина', 'centralnotice-locked' => 'Заблокований', 'centralnotice-notices' => 'повідомлення', - 'centralnotice-notice-exists' => 'Повідомлення вже існує. + 'centralnotice-notice-exists' => 'Повідомлення вже існує. Не додається', - 'centralnotice-template-exists' => 'Шаблон вже існує. + 'centralnotice-template-exists' => 'Шаблон вже існує. Не додається', - 'centralnotice-notice-doesnt-exist' => 'Повідомлення не існує. + 'centralnotice-notice-doesnt-exist' => 'Повідомлення не існує. Нема чого видаляти', - 'centralnotice-template-still-bound' => "Шаблон, як і раніше, пов'язаний з повідомленням. + 'centralnotice-template-still-bound' => "Шаблон, як і раніше, пов'язаний з повідомленням. Не видаляється.", 'centralnotice-template-body' => 'Тіло шаблону:', 'centralnotice-day' => 'День', @@ -6530,28 +6530,28 @@ 'centralnotice-start-date' => 'Дата початку', 'centralnotice-start-time' => 'Час початку (UTC)', 'centralnotice-assigned-templates' => 'Встановлені шаблони', - 'centralnotice-no-templates' => 'Не знайдено шаблонів. + 'centralnotice-no-templates' => 'Не знайдено шаблонів. Додайте що-небудь!', - 'centralnotice-no-templates-assigned' => "Не має пов'язаних з повідомленням шаблонів. + 'centralnotice-no-templates-assigned' => "Не має пов'язаних з повідомленням шаблонів. Додайте який-небудь!", 'centralnotice-available-templates' => 'Доступні шаблони', - 'centralnotice-template-already-exists' => "Шаблон вже прив'язаний. + 'centralnotice-template-already-exists' => "Шаблон вже прив'язаний. Не доданий", 'centralnotice-preview-template' => 'Попередній перегляд шаблону', 'centralnotice-start-hour' => 'Час початку', 'centralnotice-change-lang' => 'Змінити мову перекладу', 'centralnotice-weights' => 'Ваги', - 'centralnotice-notice-is-locked' => 'Повідомлення заблоковано. + 'centralnotice-notice-is-locked' => 'Повідомлення заблоковано. Не вилучається', - 'centralnotice-overlap' => 'Повідомлення перекривається за часом з іншим повідомленням. + 'centralnotice-overlap' => 'Повідомлення перекривається за часом з іншим повідомленням. Не додається', - 'centralnotice-invalid-date-range' => 'Хибний діапазон дат. + 'centralnotice-invalid-date-range' => 'Хибний діапазон дат. Не оновлюється', - 'centralnotice-null-string' => 'Не вдається додати порожній рядок. + 'centralnotice-null-string' => 'Не вдається додати порожній рядок. Не додається', - 'centralnotice-confirm-delete' => 'Ви впевнені у вирішенні вилучити цей елемент? + 'centralnotice-confirm-delete' => 'Ви впевнені у вирішенні вилучити цей елемент? Цю дію не можна буде скасувати.', - 'centralnotice-no-notices-exist' => 'Немає повідомлень. + 'centralnotice-no-notices-exist' => 'Немає повідомлень. Можна додати', 'centralnotice-no-templates-translate' => 'Не має ні одного шаблону для редагування перекладу', 'centralnotice-number-uses' => 'Використовуються', @@ -6601,13 +6601,13 @@ 'centralnotice-weight' => 'Peso', 'centralnotice-locked' => 'Blocà', 'centralnotice-notices' => 'Notifiche', - 'centralnotice-notice-exists' => 'Notifica zà esistente. + 'centralnotice-notice-exists' => 'Notifica zà esistente. Inserimento mia fato', - 'centralnotice-template-exists' => 'Modèl zà esistente. + 'centralnotice-template-exists' => 'Modèl zà esistente. Inserimento mia fato', - 'centralnotice-notice-doesnt-exist' => 'Notifica mia esistente. + 'centralnotice-notice-doesnt-exist' => 'Notifica mia esistente. Rimozion mia fata', - 'centralnotice-template-still-bound' => 'Modèl ancora ligà a na notifica. + 'centralnotice-template-still-bound' => 'Modèl ancora ligà a na notifica. Rimozion mia fata.', 'centralnotice-template-body' => 'Corpo del modèl:', 'centralnotice-day' => 'Zorno', @@ -6625,7 +6625,7 @@ 'centralnotice-no-templates-assigned' => 'Nissun modèl assegnà a la notifica Zónteghene qualchedun!', 'centralnotice-available-templates' => 'Modèi disponibili', - 'centralnotice-template-already-exists' => 'Sto modèl el xe zà ligà a na campagna. + 'centralnotice-template-already-exists' => 'Sto modèl el xe zà ligà a na campagna. Inserimento mia fato', 'centralnotice-preview-template' => 'Anteprima modèl', 'centralnotice-start-hour' => 'Ora de scominsio', Modified: trunk/extensions/CentralNotice/CentralNotice.php =================================================================== --- trunk/extensions/CentralNotice/CentralNotice.php 2010-04-28 20:52:09 UTC (rev 65634) +++ trunk/extensions/CentralNotice/CentralNotice.php 2010-04-28 21:30:06 UTC (rev 65635) @@ -102,13 +102,13 @@ $dir = dirname( __FILE__ ) . '/'; $wgExtensionMessagesFiles['CentralNotice'] = $dir . 'CentralNotice.i18n.php'; +$wgExtensionAliasesFiles['CentralNotice'] = $dir . 'CentralNotice.alias.php'; $wgAvailableRights[] = 'centralnotice-admin'; $wgAvailableRights[] = 'centralnotice-translate'; $wgGroupPermissions['sysop']['centralnotice-admin'] = true; // Only sysops can make change $wgGroupPermissions['sysop']['centralnotice-translate'] = true; // Only sysops can make change - function efCentralNoticeSetup() { global $wgHooks, $wgNoticeInfrastructure, $wgAutoloadClasses, $wgSpecialPages; global $wgCentralNoticeLoader; Modified: trunk/extensions/CentralNotice/SpecialNoticeLocal.php =================================================================== --- trunk/extensions/CentralNotice/SpecialNoticeLocal.php 2010-04-28 20:52:09 UTC (rev 65634) +++ trunk/extensions/CentralNotice/SpecialNoticeLocal.php 2010-04-28 21:30:06 UTC (rev 65635) @@ -1,7 +1,6 @@ <?php class SpecialNoticeLocal extends NoticePage { - function __construct() { parent::__construct( "NoticeLocal" ); } Modified: trunk/extensions/CentralNotice/SpecialNoticeTemplate.php =================================================================== --- trunk/extensions/CentralNotice/SpecialNoticeTemplate.php 2010-04-28 20:52:09 UTC (rev 65634) +++ trunk/extensions/CentralNotice/SpecialNoticeTemplate.php 2010-04-28 21:30:06 UTC (rev 65635) @@ -6,7 +6,6 @@ } class SpecialNoticeTemplate extends UnlistedSpecialPage { - /* Functions */ function __construct() { @@ -38,7 +37,7 @@ if ( $this->editable ) { // Handle forms if ( $wgRequest->wasPosted() ) { - + // Handle removing $toRemove = $wgRequest->getArray( 'removeTemplates' ); if ( isset( $toRemove ) ) { @@ -47,7 +46,7 @@ $this->removeTemplate( $template ); } } - + // Handle translation message update $update = $wgRequest->getArray( 'updateText' ); $token = $wgRequest->getArray( 'token' ); @@ -62,7 +61,7 @@ } } } - + // Handle adding // FIXME: getText()? weak comparison if ( $wgRequest->getVal( 'wpMethod' ) == 'addTemplate' ) { @@ -100,14 +99,15 @@ $this->showAdd(); return; } - if ( $sub == 'clone' ) { - $oldTemplate = $wgRequest->getVal( 'oldTemplate' ); - $newTemplate = $wgRequest->getVal( 'newTemplate' ); - // We use the returned name in case any special characters had to be removed - $template = $this->cloneTemplate( $oldTemplate, $newTemplate ); - $wgOut->redirect( SpecialPage::getTitleFor( 'NoticeTemplate', 'view' )->getLocalUrl( "template=$template" ) ); - return; - } + + if ( $sub == 'clone' ) { + $oldTemplate = $wgRequest->getVal( 'oldTemplate' ); + $newTemplate = $wgRequest->getVal( 'newTemplate' ); + // We use the returned name in case any special characters had to be removed + $template = $this->cloneTemplate( $oldTemplate, $newTemplate ); + $wgOut->redirect( SpecialPage::getTitleFor( 'NoticeTemplate', 'view' )->getLocalUrl( "template=$template" ) ); + return; + } } // Show list by default @@ -123,7 +123,7 @@ $templates = $this->queryTemplates(); if ( count( $templates ) > 0 ) { $htmlOut = ''; - + if ( $this->editable ) { $htmlOut .= Xml::openElement( 'form', array( @@ -286,7 +286,7 @@ $bodyPage = Title::newFromText( "Centralnotice-template-{$currentTemplate}", NS_MEDIAWIKI ); $curRev = Revision::newFromTitle( $bodyPage ); $body = $curRev ? $curRev->getText() : ''; - + $fields = array(); preg_match_all( '/\{\{\{([A-Za-z0-9\_\-}]+)\}\}\}/', $body, $fields ); @@ -353,8 +353,10 @@ ); $htmlOut .= Xml::closeElement( 'tr' ); } + $htmlOut .= Xml::closeElement( 'table' ); $htmlOut .= Xml::closeElement( 'fieldset' ); + if ( $this->editable ) { $htmlOut .= Xml::closeElement( 'form' ); } @@ -368,18 +370,18 @@ list( $lsLabel, $lsSelect ) = Xml::languageSelector( $wpUserLang ); $newPage = SpecialPage::getTitleFor( 'NoticeTemplate', 'view' ); - + $htmlOut .= Xml::tags( 'tr', null, Xml::tags( 'td', null, $lsLabel ) . Xml::tags( 'td', null, $lsSelect ) . Xml::tags( 'td', array( 'colspan' => 2 ), Xml::submitButton( wfMsg( 'centralnotice-modify' ) ) ) - ); - $htmlOut .= Xml::tags( 'tr', null, - Xml::tags( 'td', null, '' ) . - Xml::tags( 'td', null, $sk->makeLinkObj( $newPage, wfMsgHtml( 'centralnotice-preview-all-template-translations' ), "template=$currentTemplate&wpUserLanguage=all" ) ) ); + $htmlOut .= Xml::tags( 'tr', null, + Xml::tags( 'td', null, '' ) . + Xml::tags( 'td', null, $sk->makeLinkObj( $newPage, wfMsgHtml( 'centralnotice-preview-all-template-translations' ), "template=$currentTemplate&wpUserLanguage=all" ) ) + ); $htmlOut .= Xml::closeElement( 'table' ); $htmlOut .= Xml::closeElement( 'fieldset' ); $htmlOut .= Xml::closeElement( 'form' ); @@ -452,7 +454,7 @@ // Pull all available text for a template $langs = array_keys( $this->getTranslations( $template ) ); $htmlOut = ''; - + foreach ( $langs as $lang ) { // Link and Preview all available translations $viewPage = SpecialPage::getTitleFor( 'NoticeTemplate', 'view' ); @@ -470,7 +472,7 @@ } return $wgOut->addHtml( $htmlOut ); } - + private function updateMessage( $text, $translation, $lang, $token = false ) { global $wgUser; @@ -560,7 +562,9 @@ $name = ereg_replace( '[^A-Za-z0-9\_]', '', $name ); $dbr = wfGetDB( DB_SLAVE ); - $res = $dbr->select( 'cn_templates', 'tmp_name', + $res = $dbr->select( + 'cn_templates', + 'tmp_name', array( 'tmp_name' => $name ), __METHOD__ ); @@ -571,7 +575,8 @@ } else { $dbw = wfGetDB( DB_MASTER ); $dbw->begin(); - $res = $dbw->insert( 'cn_templates', + $res = $dbw->insert( + 'cn_templates', array( 'tmp_name' => $name ), __METHOD__ ); @@ -614,79 +619,80 @@ } } - /* - * Copy all the data from one template to another - */ - public function cloneTemplate( $source, $dest ) { - // Reset the timer as updates on meta take a long time - set_time_limit( 300 ); - // Pull all possible langs - $langs = $this->getTranslations( $source ); - - // Normalize name - $dest = ereg_replace( '[^A-Za-z0-9\_]', '', $dest ); - - // Pull text and respect any inc: markup - $bodyPage = Title::newFromText( "Centralnotice-template-{$source}", NS_MEDIAWIKI ); - $template_body = Revision::newFromTitle( $bodyPage )->getText(); + /* + * Copy all the data from one template to another + */ + public function cloneTemplate( $source, $dest ) { + // Reset the timer as updates on meta take a long time + set_time_limit( 300 ); + // Pull all possible langs + $langs = $this->getTranslations( $source ); - if ( $this->addTemplate( $dest, $template_body ) ) { + // Normalize name + $dest = ereg_replace( '[^A-Za-z0-9\_]', '', $dest ); - // Populate the fields - foreach ( $langs as $lang => $fields ) { - foreach ( $fields as $field => $text ) { - $this->updateMessage( "$dest-$field", $text, $lang ); - } - } - return $dest; - } - } + // Pull text and respect any inc: markup + $bodyPage = Title::newFromText( "Centralnotice-template-{$source}", NS_MEDIAWIKI ); + $template_body = Revision::newFromTitle( $bodyPage )->getText(); - /* - * Find all fields set for a template - */ - private function findFields( $template ) { - $messages = array(); - $body = wfMsg( "Centralnotice-template-{$template}" ); - - // Generate fields from parsing the body - $fields = array(); - preg_match_all( '/\{\{\{([A-Za-z0-9\_\-}]+)\}\}\}/', $body, $fields ); - - // Remove duplicates - $filteredFields = array(); - foreach ( $fields[1] as $field ) { - $filteredFields[$field] = array_key_exists( $field, $filteredFields ) ? $filteredFields[$field] + 1 : -1; - } - return $filteredFields; - } + if ( $this->addTemplate( $dest, $template_body ) ) { - /* - * Given a template return a list of every set field in every language - */ - public function getTranslations( $template ) { - $translations = array(); + // Populate the fields + foreach ( $langs as $lang => $fields ) { + foreach ( $fields as $field => $text ) { + $this->updateMessage( "$dest-$field", $text, $lang ); + } + } + return $dest; + } + } - // Pull all language codes to enumerate - $allLangs = array_keys( Language::getLanguageNames() ); - - // Lookup all the possible fields for a template - $fields = $this->findFields( $template ); + /* + * Find all fields set for a template + */ + private function findFields( $template ) { + $messages = array(); + $body = wfMsg( "Centralnotice-template-{$template}" ); - // Iterate through all possible languages to find matches - foreach ( $allLangs as $lang ) { - // Iterate through all possible fields - foreach ( $fields as $field => $count ) { - // Put all fields together for a lookup - $message = ( $lang == 'en' ) ? "Centralnotice-{$template}-{$field}" : "Centralnotice-{$template}-{$field}/{$lang}"; - if ( Title::newFromText( $message, NS_MEDIAWIKI )->exists() ) { - $translations[$lang][$field] = wfMsgExt( "Centralnotice-{$template}-{$field}", - array( 'language' => $lang ) - ); - } - } - } - return $translations; - } + // Generate fields from parsing the body + $fields = array(); + preg_match_all( '/\{\{\{([A-Za-z0-9\_\-}]+)\}\}\}/', $body, $fields ); + + // Remove duplicates + $filteredFields = array(); + foreach ( $fields[1] as $field ) { + $filteredFields[$field] = array_key_exists( $field, $filteredFields ) ? $filteredFields[$field] + 1 : + 1; + } + return $filteredFields; + } + + /* + * Given a template return a list of every set field in every language + */ + public function getTranslations( $template ) { + $translations = array(); + + // Pull all language codes to enumerate + $allLangs = array_keys( Language::getLanguageNames() ); + + // Lookup all the possible fields for a template + $fields = $this->findFields( $template ); + + // Iterate through all possible languages to find matches + foreach ( $allLangs as $lang ) { + // Iterate through all possible fields + foreach ( $fields as $field => $count ) { + // Put all fields together for a lookup + $message = ( $lang == 'en' ) ? "Centralnotice-{$template}-{$field}" : "Centralnotice-{$template}-{$field}/{$lang}"; + if ( Title::newFromText( $message, NS_MEDIAWIKI )->exists() ) { + $translations[$lang][$field] = wfMsgExt( + "Centralnotice-{$template}-{$field}", + array( 'language' => $lang ) + ); + } + } + } + return $translations; + } } Modified: trunk/extensions/CentralNotice/SpecialNoticeText.php =================================================================== --- trunk/extensions/CentralNotice/SpecialNoticeText.php 2010-04-28 20:52:09 UTC (rev 65634) +++ trunk/extensions/CentralNotice/SpecialNoticeText.php 2010-04-28 21:30:06 UTC (rev 65635) @@ -21,24 +21,24 @@ function getJsOutput( $par ) { $this->setLanguage( $par ); - // Quick short circuit to be able to show preferred notices - $templates = array(); + // Quick short circuit to be able to show preferred notices + $templates = array(); - if ( $this->language == 'en' && $this->project != null ) { - // See if we have any preferred notices for all of en - $notices = CentralNoticeDB::getNotices( '', 'en', '', '', 1 ); + if ( $this->language == 'en' && $this->project != null ) { + // See if we have any preferred notices for all of en + $notices = CentralNoticeDB::getNotices( '', 'en', '', '', 1 ); - if ( $notices ) { - // Pull out values - foreach ( $notices as $notice => $val ) { - // Either match against ALL project or a specific project - if ( $val['project'] == '' || $val['project'] == $this->project ) { - $templates = CentralNoticeDB::selectTemplatesAssigned( $notice ); - break; - } - } - } - } + if ( $notices ) { + // Pull out values + foreach ( $notices as $notice => $val ) { + // Either match against ALL project or a specific project + if ( $val['project'] == '' || $val['project'] == $this->project ) { + $templates = CentralNoticeDB::selectTemplatesAssigned( $notice ); + break; + } + } + } + } if ( !$templates && $this->project == 'wikipedia' ) { $notices = CentralNoticeDB::getNotices( 'wikipedia', '', '', '', 1 ); @@ -53,9 +53,9 @@ } } - // Didn't find any preferred matches so do an old style lookup + // Didn't find any preferred matches so do an old style lookup if ( !$templates ) { - $templates = CentralNotice::selectNoticeTemplates( $this->project, $this->language ); + $templates = CentralNotice::selectNoticeTemplates( $this->project, $this->language ); } $templateNames = array_keys( $templates ); @@ -64,12 +64,12 @@ array( $this, 'getHtmlNotice' ), $templateNames ); - if ( preg_grep( "/<centralnotice-template-\w{1,}>\z/", $templateTexts ) ) { - return false; // Bailing out if we have a failed cache lookup - } + if ( preg_grep( "/<centralnotice-template-\w{1,}>\z/", $templateTexts ) ) { + return false; // Bailing out if we have a failed cache lookup + } $weights = array_values( $templates ); - + return $this->getScriptFunctions() . $this->getToggleScripts() . @@ -155,7 +155,7 @@ } currentTemplate++; } - + if (totalWeight == 0) return ''; @@ -168,7 +168,7 @@ private function formatNum( $num ) { $num = sprintf( "%.1f", $num / 1e6 ); if ( substr( $num, - 2 ) == '.0' ) { - $num = substr( $num, 0, - 2 ); + $num = substr( $num, 0, - 2 ); } $lang = Language::factory( $this->language ); return $lang->formatNum( $num ); @@ -207,7 +207,7 @@ $old = array(); $old['wgSitename'] = $GLOBALS['wgSitename']; $old['wgLang'] = $GLOBALS['wgLang']; - + $GLOBALS['wgSitename'] = $this->projectName(); $GLOBALS['wgLang'] = Language::factory( $this->language ); // hack for {{int:...}} Modified: trunk/extensions/CentralNotice/patch-add-preferred.sql =================================================================== --- trunk/extensions/CentralNotice/patch-add-preferred.sql 2010-04-28 20:52:09 UTC (rev 65634) +++ trunk/extensions/CentralNotice/patch-add-preferred.sql 2010-04-28 21:30:06 UTC (rev 65635) @@ -1,4 +1,6 @@ -# Support for one notice to supercede all others. This allows one notice to cancel out all the templates that a non preffered notice might have if they overlap. -# Use case is to be able to use one all language and projects notice and have it superceded by a specific one for en wikipedia +# Support for one notice to supercede all others. This allows one notice to +# cancel out all the templates that a non preffered notice might have if they +# overlap. Use case is to be able to use one all language and projects notice +# and have it superceded by a specific one for en wikipedia. -ALTER TABLE cn_notices ADD COLUMN not_preferred bool NOT NULL default '0'; +ALTER TABLE cn_notices ADD COLUMN not_preferred bool NOT NULL default '0'; Modified: trunk/extensions/CentralNotice/rebuildTemplates.php =================================================================== --- trunk/extensions/CentralNotice/rebuildTemplates.php 2010-04-28 20:52:09 UTC (rev 65634) +++ trunk/extensions/CentralNotice/rebuildTemplates.php 2010-04-28 21:30:06 UTC (rev 65635) @@ -16,14 +16,14 @@ // Hack for parser to avoid barfing from no $wgTitle $wgTitle = Title::newFromText( wfMsg( 'mainpage' ) ); - if ( isset( $options['n'] ) ) { - $notice = explode( "/", $args[0] ); - $projects = array( $notice[0] ); - $langs = array( $notice[1] ); - } else { - $projects = $wgNoticeProjects; - $langs = array_keys( Language::getLanguageNames() ); - } + if ( isset( $options['n'] ) ) { + $notice = explode( "/", $args[0] ); + $projects = array( $notice[0] ); + $langs = array( $notice[1] ); + } else { + $projects = $wgNoticeProjects; + $langs = array_keys( Language::getLanguageNames() ); + } foreach ( $projects as $project ) { foreach ( $langs as $lang ) { $key = "$project/$lang"; @@ -32,20 +32,20 @@ $builder = new SpecialNoticeText(); $js = $builder->getJsOutput( $key ); - if ( isset( $options['o'] ) ) { - $outputDir = "$wgNoticeCentralDirectory/$project/$lang"; - if ( wfMkDirParents( $outputDir ) ) { - $outputFile = "$outputDir/centralnotice.js"; - $ok = file_put_contents( $outputFile, $js ); - if ( !$ok ) { - echo "FAILED to write $outputFile!\n"; - } - } else { - echo "FAILED to create $outputDir!\n"; - } - } else { - echo $js; - } + if ( isset( $options['o'] ) ) { + $outputDir = "$wgNoticeCentralDirectory/$project/$lang"; + if ( wfMkDirParents( $outputDir ) ) { + $outputFile = "$outputDir/centralnotice.js"; + $ok = file_put_contents( $outputFile, $js ); + if ( !$ok ) { + echo "FAILED to write $outputFile!\n"; + } + } else { + echo "FAILED to create $outputDir!\n"; + } + } else { + echo $js; + } } } } Modified: trunk/extensions/Translate/groups/mediawiki-defines.txt =================================================================== --- trunk/extensions/Translate/groups/mediawiki-defines.txt 2010-04-28 20:52:09 UTC (rev 65634) +++ trunk/extensions/Translate/groups/mediawiki-defines.txt 2010-04-28 21:30:06 UTC (rev 65635) @@ -107,6 +107,7 @@ ignored = centralauth-editset-item-ro Central Notice +aliasfile = CentralNotice/CentralNotice.alias.php Change Author aliasfile = ChangeAuthor/ChangeAuthor.alias.php _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs