r42940 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r42939‎ | r42940 | r42941 >
Date:20:54, 31 October 2008
Author:tparscal
Status:old (Comments)
Tags:
Comment:
Changed delete command.
Modified paths:
  • /branches/CentralNotice-SpecialPage-Integration/SpecialNoticeTemplate.php (modified) (history)
  • /branches/CentralNotice-SpecialPage-Integration/SpecialNoticeTranslate.php (deleted) (history)

Diff [purge]

Index: branches/CentralNotice-SpecialPage-Integration/SpecialNoticeTranslate.php
@@ -1,188 +0,0 @@
2 -<?php
3 -
4 -if ( !defined( 'MEDIAWIKI' ) ) {
5 - echo "CentralNotice extension\n";
6 - exit( 1 );
7 -}
8 -
9 -class SpecialNoticeTranslate extends UnlistedSpecialPage {
10 -
11 - /* Functions */
12 -
13 - function __construct() {
14 - // Register the special page
15 - parent::__construct( 'NoticeTranslate' );
16 -
17 - // Internationalization
18 - wfLoadExtensionMessages( 'CentralNotice' );
19 - }
20 -
21 - function execute( $sub ) {
22 - global $wgOut, $wgUser, $wgRequest;
23 -
24 - // Begin output
25 - $this->setHeaders();
26 -
27 - // Check permissions
28 - if ( !$wgUser->isAllowed( 'centralnotice_translate_rights' )) {
29 - $wgOut->permissionRequired( 'centralnotice_translate_rights' );
30 - return;
31 - }
32 -
33 - // Show summary
34 - $wgOut->addWikiText( wfMsg( 'centralnotice-summary' ));
35 -
36 - // Show header
37 - CentralNotice::printHeader( $sub );
38 -
39 - // Handle form submissions
40 - if ( $wgRequest->wasPosted() ) {
41 - // Handle update
42 - $update = $wgRequest->getArray('updateText');
43 - $token = $wgRequest->getArray('token');
44 - if (isset ( $update ) ) {
45 - foreach ( $update as $lang => $messages ) {
46 - foreach ( $messages as $text => $translation) {
47 - // If we actually have text
48 - if ( $translation ) {
49 - $this->updateMessage( $text, $translation, $lang, $token );
50 - }
51 - }
52 - }
53 - }
54 - }
55 -
56 - // Show translation form
57 - $this->showForm();
58 - }
59 -
60 - private function showForm() {
61 - global $wgOut, $wgUser, $wgRequest, $wgContLanguageCode;
62 -
63 - // Get token
64 - $token = $wgUser->editToken();
65 -
66 - // Get user's language
67 - $wpUserLang = $wgRequest->getVal('wpUserLanguage') ? $wgRequest->getVal('wpUserLanguage') : $wgContLanguageCode;
68 -
69 - // Get current template
70 - $currentTemplate = $wgRequest->getText( 'template' );
71 -
72 - // Show preview
73 - $render = new SpecialNoticeText();
74 - $render->project = 'wikipedia';
75 - $render->language = $wgRequest->getVal( 'wpUserLanguage' );
76 - $htmlOut = Xml::fieldset( wfMsg( 'centralnotice-preview' ),
77 - $render->getHtmlNotice( $wgRequest->getText( 'template' ) )
78 - );
79 -
80 - // Build HTML
81 - $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) );
82 - $htmlOut .= Xml::fieldset( wfMsgHtml( 'centralnotice-translate-heading', $currentTemplate ) );
83 - $htmlOut .= Xml::openElement( 'table',
84 - array (
85 - 'cellpadding' => 9,
86 - 'width' => '100%'
87 - )
88 - );
89 -
90 - // Headers
91 - $htmlOut .= Xml::element( 'th', array( 'width' => '15%' ), wfMsg( 'centralnotice-message' ) );
92 - $htmlOut .= Xml::element( 'th', array( 'width' => '5%' ), wfMsg ( 'centralnotice-number-uses') );
93 - $htmlOut .= Xml::element( 'th', array( 'width' => '40%' ), wfMsg ( 'centralnotice-english') );
94 - $languages = Language::getLanguageNames();
95 - $htmlOut .= Xml::element( 'th', array( 'width' => '40%' ), $languages[$wpUserLang] );
96 -
97 - // Generate fields from parsing the body
98 - $fields = array();
99 - preg_match_all( '/\{\{\{([A-Za-z0-9\_\-}]+)\}\}\}/', wfMsg( "Centralnotice-template-{$currentTemplate}" ), $fields );
100 -
101 - // Remove duplicates
102 - $filteredFields = array();
103 - foreach( $fields[1] as $field ) {
104 - $filteredFields[$field] = array_key_exists( $field, $filteredFields ) ? $filteredFields[$field] + 1 : 1;
105 - }
106 -
107 - // Rows
108 - foreach( $filteredFields as $field => $count ) {
109 - // Message
110 - $message = ( $wpUserLang == 'en' ) ? "Centralnotice-{$currentTemplate}-{$field}" : "Centralnotice-{$currentTemplate}-{$field}/{$wpUserLang}";
111 -
112 - // English value
113 - $htmlOut .= Xml::openElement( 'tr' );
114 -
115 - $title = Title::newFromText( "MediaWiki:{$message}" );
116 - $htmlOut .= Xml::tags( 'td', null,
117 - Xml::element( 'a', array( 'href' => $title->getFullURL() ), $field )
118 - );
119 -
120 - $htmlOut .= Xml::element( 'td', null, $count);
121 -
122 - $htmlOut .= Xml::element( 'td', null,
123 - wfMsgExt( "Centralnotice-{$currentTemplate}-{$field}", array( 'language' => 'en') )
124 - );
125 -
126 - // Input
127 - $text = '';
128 - if( Title::newFromText( $message, NS_MEDIAWIKI )->exists() ) {
129 - $text = wfMsgExt( "Centralnotice-{$currentTemplate}-{$field}",
130 - array( 'language' => $wpUserLang )
131 - );
132 - }
133 - $htmlOut .= Xml::tags( 'td', null,
134 - Xml::input( "updateText[{$wpUserLang}][{$currentTemplate}-{$field}]", '', $text,
135 - array( 'style' => 'width:100%;' . ( $text == '' ? 'color:red' : '' ) )
136 - )
137 - );
138 -
139 - $htmlOut .= Xml::closeElement( 'tr' );
140 - }
141 -
142 - // Keep track of token
143 - $htmlOut .= Xml::hidden( 'token', $token );
144 -
145 - // Keep track of set language
146 - $htmlOut .= Xml::hidden( 'wpUserLanguage', $wpUserLang );
147 -
148 - // Submit and Preview
149 - $htmlOut .= Xml::openElement( 'tr' );
150 - $htmlOut .= Xml::tags( 'td', array( 'colspan' => 4 ),
151 - Xml::submitButton( wfMsg('centralnotice-modify', array( 'name' => 'update') ) )
152 - );
153 -
154 - $htmlOut .= Xml::closeElement( 'tr' );
155 - $htmlOut .= Xml::closeElement( 'table' );
156 - $htmlOut .= Xml::closeElement( 'fieldset' );
157 - $htmlOut .= Xml::closeElement( 'form' );
158 -
159 - // Language selection
160 - $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) );
161 - $htmlOut .= Xml::fieldset( wfMsgHtml( 'centralnotice-change-lang' ) );
162 - $htmlOut .= Xml::openElement( 'table', array ( 'cellpadding' => 9 ) );
163 - list( $lsLabel, $lsSelect) = Xml::languageSelector( $wpUserLang );
164 - $htmlOut .= Xml::tags( 'tr', null,
165 - Xml::tags( 'td', null, $lsLabel ) .
166 - Xml::tags( 'td', null, $lsSelect ) .
167 - Xml::tags( 'td', array( 'colspan' => 2 ),
168 - Xml::submitButton( wfMsgHtml('centralnotice-modify') )
169 - )
170 - );
171 - $htmlOut .= Xml::closeElement( 'table' );
172 - $htmlOut .= Xml::closeElement( 'fieldset' );
173 - $htmlOut .= Xml::closeElement( 'form' );
174 -
175 - // Output HTML
176 - $wgOut->addHTML( $htmlOut );
177 - }
178 -
179 - private function updateMessage( $text, $translation, $lang, $token ) {
180 - global $wgUser;
181 -
182 - $title = Title::newFromText(
183 - ( $lang == 'en' ) ? "Centralnotice-{$text}" : "Centralnotice-{$text}/{$lang}",
184 - NS_MEDIAWIKI
185 - );
186 - $article = new Article( $title );
187 - $article->doEdit( $translation, '' );
188 - }
189 -}
Index: branches/CentralNotice-SpecialPage-Integration/SpecialNoticeTemplate.php
@@ -424,7 +424,7 @@
425425 $article = new Article(
426426 Title::newFromText( "centralnotice-template-{$name}", NS_MEDIAWIKI )
427427 );
428 - $article->doDelete( 'CentralNotice Automated Removal', true );
 428+ $article->doDeleteArticle( 'CentralNotice Automated Removal', true );
429429 }
430430 }
431431

Comments

#Comment by Brion VIBBER (talk | contribs)   22:15, 31 October 2008

extra parameter on doDeleteArticle causes suppression which is inconvenient. removed in next rev

Status & tagging log