00001 <?php
00018 class SpecialTranslations extends SpecialAllpages {
00019 function __construct() {
00020 parent::__construct( 'Translations' );
00021 }
00022
00028 function execute( $par ) {
00029 $this->setHeaders();
00030 $this->outputHeader();
00031 $this->includeAssets();
00032
00033 $out = $this->getOutput();
00034
00035 if ( $this->including() ) {
00036 $title = Title::newFromText( $par );
00037 if ( !$title ) {
00038 $out->addWikiMsg( 'translate-translations-including-no-param' );
00039 } else {
00040 $this->showTranslations( $title );
00041 }
00042
00043 return;
00044 }
00045
00049 $request = $this->getRequest();
00050 $message = $request->getText( 'message' );
00051 $namespace = $request->getInt( 'namespace', NS_MAIN );
00052
00053 if ( $message !== '' ) {
00054 $title = Title::newFromText( $message, $namespace );
00055 } else {
00056 $title = Title::newFromText( $par, $namespace );
00057 }
00058
00059 TranslateUtils::addSpecialHelpLink(
00060 $out,
00061 'Help:Extension:Translate/Statistics_and_reporting#Translations_in_all_languages'
00062 );
00063
00064 if ( !$title ) {
00065 $title = Title::makeTitle( NS_MEDIAWIKI, '' );
00066 $out->addHTML( $this->namespaceMessageForm( $title ) );
00067 } else {
00068 $out->addHTML( $this->namespaceMessageForm( $title ) . '<br />' );
00069 $this->showTranslations( $title );
00070 }
00071 }
00072
00079 function namespaceMessageForm( Title $title = null ) {
00080 global $wgScript;
00081
00082 $namespaces = new XmlSelect( 'namespace', 'namespace' );
00083 $namespaces->setDefault( $title->getNamespace() );
00084
00085 foreach ( $this->getSortedNamespaces() as $text => $index ) {
00086 $namespaces->addOption( $text, $index );
00087 }
00088
00089 $out = Xml::openElement( 'div', array( 'class' => 'namespaceoptions' ) );
00090 $out .= Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
00091 $out .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() );
00092 $out .= Xml::openElement( 'fieldset' );
00093 $out .= Xml::element(
00094 'legend',
00095 null,
00096 $this->msg( 'translate-translations-fieldset-title' )->text()
00097 );
00098 $out .= Xml::openElement( 'table', array( 'id' => 'nsselect', 'class' => 'allpages' ) );
00099 $out .= "<tr>
00100 <td class='mw-label'>" .
00101 Xml::label( $this->msg( 'translate-translations-messagename' )->text(), 'message' ) .
00102 "</td>
00103 <td class='mw-input'>" .
00104 Xml::input( 'message', 30, $title->getText(), array( 'id' => 'message' ) ) .
00105 "</td>
00106 </tr>
00107 <tr>
00108 <td class='mw-label'>" .
00109 Xml::label( $this->msg( 'translate-translations-project' )->text(), 'namespace' ) .
00110 "</td>
00111 <td class='mw-input'>" .
00112 $namespaces->getHTML() . ' ' .
00113 Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) .
00114 "</td>
00115 </tr>";
00116 $out .= Xml::closeElement( 'table' );
00117 $out .= Xml::closeElement( 'fieldset' );
00118 $out .= Xml::closeElement( 'form' );
00119 $out .= Xml::closeElement( 'div' );
00120
00121 return $out;
00122 }
00123
00129 public function getSortedNamespaces() {
00130 global $wgTranslateMessageNamespaces, $wgContLang;
00131
00132 $nslist = array();
00133 foreach ( $wgTranslateMessageNamespaces as $ns ) {
00134 $nslist[$wgContLang->getFormattedNsText( $ns )] = $ns;
00135 }
00136 ksort( $nslist );
00137
00138 return $nslist;
00139 }
00140
00146 function showTranslations( Title $title ) {
00147 $handle = new MessageHandle( $title );
00148 $namespace = $title->getNamespace();
00149 $message = $handle->getKey();
00150
00151 if ( !$handle->isValid() ) {
00152 $this->getOutput()->addWikiMsg( 'translate-translations-no-message', $title->getPrefixedText() );
00153
00154 return;
00155 }
00156
00157 $dbr = wfGetDB( DB_SLAVE );
00158
00159 $res = $dbr->select( 'page',
00160 array( 'page_namespace', 'page_title' ),
00161 array(
00162 'page_namespace' => $namespace,
00163 'page_title ' . $dbr->buildLike( "$message/", $dbr->anyString() ),
00164 ),
00165 __METHOD__,
00166 array(
00167 'ORDER BY' => 'page_title',
00168 'USE INDEX' => 'name_title',
00169 )
00170 );
00171
00172 if ( !$res->numRows() ) {
00173 $this->getOutput()->addWikiMsg(
00174 'translate-translations-no-message',
00175 $title->getPrefixedText()
00176 );
00177
00178 return;
00179 } else {
00180 $this->getOutput()->addWikiMsg(
00181 'translate-translations-count',
00182 $this->getLanguage()->formatNum( $res->numRows() )
00183 );
00184 }
00185
00186
00187 $titles = array();
00188
00189 foreach ( $res as $s ) {
00190 $titles[] = $s->page_title;
00191 }
00192
00193 $pageInfo = TranslateUtils::getContents( $titles, $namespace );
00194
00195 $tableheader = Xml::openElement( 'table', array(
00196 'class' => 'mw-sp-translate-table sortable'
00197 ) );
00198
00199 $tableheader .= Xml::openElement( 'tr' );
00200 $tableheader .= Xml::element( 'th', null, $this->msg( 'allmessagesname' )->text() );
00201 $tableheader .= Xml::element( 'th', null, $this->msg( 'allmessagescurrent' )->text() );
00202 $tableheader .= Xml::closeElement( 'tr' );
00203
00204
00205 $out = $tableheader;
00206
00207 $canTranslate = $this->getUser()->isAllowed( 'translate' );
00208
00209 $ajaxPageList = array();
00210 $historyText = " <sup>" .
00211 $this->msg( 'translate-translations-history-short' )->escaped() .
00212 "</sup> ";
00213 $separator = $this->msg( 'word-separator' )->plain();
00214
00215 foreach ( $res as $s ) {
00216 $key = $s->page_title;
00217 $tTitle = Title::makeTitle( $s->page_namespace, $key );
00218 $ajaxPageList[] = $tTitle->getPrefixedDBkey();
00219 $tHandle = new MessageHandle( $tTitle );
00220
00221 $code = $tHandle->getCode();
00222
00223 $text = TranslateUtils::getLanguageName( $code, $this->getLanguage()->getCode() );
00224 $text .= $separator;
00225 $text .= $this->msg( 'parentheses' )->params( $code )->plain();
00226 $text = htmlspecialchars( $text );
00227
00228 if ( $canTranslate ) {
00229 $tools['edit'] = TranslationHelpers::ajaxEditLink(
00230 $tTitle,
00231 $text
00232 );
00233 } else {
00234 $tools['edit'] = Linker::link( $tTitle, $text );
00235 }
00236
00237 $tools['history'] = Linker::link(
00238 $tTitle,
00239 $historyText,
00240 array(
00241 'action',
00242 'title' => $this->msg( 'history-title', $tTitle->getPrefixedDBkey() )->text()
00243 ),
00244 array( 'action' => 'history' )
00245 );
00246
00247 if ( MessageHandle::hasFuzzyString( $pageInfo[$key][0] ) || $tHandle->isFuzzy() ) {
00248 $class = 'orig';
00249 } else {
00250 $class = 'def';
00251 }
00252
00253 $leftColumn = $tools['history'] . $tools['edit'];
00254 $out .= Xml::tags( 'tr', array( 'class' => $class ),
00255 Xml::tags( 'td', null, $leftColumn ) .
00256 Xml::tags( 'td', array( 'lang' => $code, 'dir' => Language::factory( $code )->getDir() ),
00257 TranslateUtils::convertWhiteSpaceToHTML( $pageInfo[$key][0] ) )
00258 );
00259 }
00260
00261 $out .= Xml::closeElement( 'table' );
00262 $this->getOutput()->addHTML( $out );
00263
00264 $vars = array( 'trlKeys' => $ajaxPageList );
00265 $this->getOutput()->addScript( Skin::makeVariablesScript( $vars ) );
00266 }
00267
00274 private function getCode( $name ) {
00275 $from = strrpos( $name, '/' );
00276
00277 return substr( $name, $from + 1 );
00278 }
00279
00283 private function includeAssets() {
00284 $out = $this->getOutput();
00285 TranslationHelpers::addModules( $out );
00286 $out->addModules( 'ext.translate.messagetable' );
00287 }
00288 }