Revision: 46164
Author: nikerabbit
Date: 2009-01-24 20:33:58 +0000 (Sat, 24 Jan 2009)
Log Message:
-----------
* Cleanup
Modified Paths:
--------------
trunk/extensions/Translate/SpecialTranslations.php
Modified: trunk/extensions/Translate/SpecialTranslations.php
===================================================================
--- trunk/extensions/Translate/SpecialTranslations.php 2009-01-24 20:15:03 UTC
(rev 46163)
+++ trunk/extensions/Translate/SpecialTranslations.php 2009-01-24 20:33:58 UTC
(rev 46164)
@@ -6,15 +6,12 @@
* Bits taken from SpecialPrefixindex.php and TranslateTasks.php
*
* @author Siebrand Mazeland
+ * @author Niklas Laxstörm
* @copyright Copyright © 2008 Siebrand Mazeland
+ * @copyright Copyright © 2009 Niklas Laxström
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
2.0 or later
*/
class SpecialTranslations extends SpecialAllpages {
- // Inherit $maxPerPage
-
- // Define other properties
- protected $nsfromMsg = 'translate-messagename';
-
function __construct(){
parent::__construct( 'Translations' );
}
@@ -31,47 +28,47 @@
$this->setHeaders();
$this->outputHeader();
+ $title = null;
+
if( $this->including() ){
$title = Title::newFromText( $par );
- if( $title instanceof Title ){
- $message = $title->getText();
- $namespace = $title->getNamespace();
-
- $this->showTranslations( $namespace, $message );
+ if( !$title ){
+ $wgOut->addWikiMsg(
'translate-translations-including-no-param' );
} else {
- $wgOut->addWikiMsg(
'translate-translations-including-no-param' );
+ $this->showTranslations( $title );
}
+ return;
+ }
+
+
+ # GET values
+ $message = $wgRequest->getText( 'message' );
+ $namespace = $wgRequest->getInt( 'namespace' );
+ if ( $message !== '' ) {
+ $title = Title::newFromText( $message, $namespace );
} else {
- # GET values
- $message = $wgRequest->getVal( 'message' );
- $namespace = $wgRequest->getInt( 'namespace' );
+ $title = Title::newFromText( $par );
+ }
- if( isset( $message ) && $message != '' ){
- $this->showTranslations( $namespace, $message );
- } else {
- $title = Title::newFromText( $par );
- if( $title instanceof Title ){
- $message = $title->getText();
- $namespace = $title->getNamespace();
-
- $this->showTranslations( $namespace,
$message );
- } else {
- $wgOut->addHTML(
$this->namespaceMessageForm( $namespace, null ) );
- }
- }
+ if ( !$title ) {
+ $title = Title::makeTitle( NS_MEDIAWIKI, '' );
+ $wgOut->addHTML( $this->namespaceMessageForm( $title )
);
+ } else {
+ $wgOut->addHTML( $this->namespaceMessageForm( $title )
. '<br />');
+ $this->showTranslations( $title );
}
}
/**
- * HTML for the top form
- * @param integer $namespace A namespace constant (default NS_MAIN).
- * @param string $from dbKey we are starting listing at.
+ * Message input fieldset
*/
- function namespaceMessageForm( $namespace = NS_MAIN, $message = '' ) {
+ function namespaceMessageForm( Title $title = null ) {
global $wgContLang, $wgScript, $wgTranslateMessageNamespaces;
$t = $this->getTitle();
$namespaces = new XmlSelect( 'namespace' );
+ $namespaces->setDefault( $title->getNamespace() );
+
foreach ($wgTranslateMessageNamespaces as $ns ) {
$namespaces->addOption(
$wgContLang->getFormattedNsText( $ns ), $ns );
}
@@ -87,7 +84,7 @@
Xml::label( wfMsg(
'translate-translations-messagename' ), 'message' ) .
"</td>
<td class='mw-input'>" .
- Xml::input( 'message', 30,
str_replace('_',' ',$message), array( 'id' => 'message' ) ) .
+ Xml::input( 'message', 30,
$title->getText(), array( 'id' => 'message' ) ) .
"</td>
</tr>
<tr>
@@ -106,89 +103,93 @@
return $out;
}
- /**
- * @param integer $namespace (Default NS_MAIN)
- * @param string $from list all pages from this name (default FALSE)
- */
- function showTranslations( $namespace = NS_MAIN, $message ) {
+ function showTranslations( Title $title ) {
global $wgOut, $wgUser, $wgContLang, $wgLang;
$sk = $wgUser->getSkin();
- $messageList = $this->getNamespaceKeyAndText( $namespace,
$message );
- list( $namespace, $message, $pageName ) = $messageList;
- $title = Title::newFromText( $message, $namespace );
+ $namespace = $title->getNamespace();
+ $message = $title->getDBKey();
$inMessageGroup = TranslateUtils::messageKeyToGroup(
$title->getNamespace(), $title->getBaseText() );
- if( !$this->including() )
- $wgOut->addHTML( $this->namespaceMessageForm(
$namespace, $message ) );
-
if( !$inMessageGroup ) {
- if( $namespace ) {
- $out = wfMsg(
'translate-translations-no-message', $title->getPrefixedText() );
- } else {
- $out = wfMsg(
'translate-translations-no-message', $message );
- }
- } else {
- $dbr = wfGetDB( DB_SLAVE );
+ $wgOut->addWikiMsg(
'translate-translations-no-message', $title->getPrefixedText() );
+ return;
+ }
- $res = $dbr->select( 'page',
- array( 'page_namespace', 'page_title' ),
- array(
- 'page_namespace' => $namespace,
- 'page_title LIKE \'' .
$dbr->escapeLike( $message ) .'\/%\'',
- ),
- __METHOD__,
- array(
- 'ORDER BY' => 'page_title',
- 'USE INDEX' => 'name_title',
- )
- );
+ $dbr = wfGetDB( DB_SLAVE );
- if( $res->numRows() ) {
- $titles = array();
- foreach ( $res as $s ) { $titles[] =
$s->page_title; }
- $pageInfo = TranslateUtils::getContents(
$titles, $namespace );
+ $res = $dbr->select( 'page',
+ array( 'page_namespace', 'page_title' ),
+ array(
+ 'page_namespace' => $namespace,
+ 'page_title LIKE \'' . $dbr->escapeLike(
$message ) .'\/%\'',
+ ),
+ __METHOD__,
+ array(
+ 'ORDER BY' => 'page_title',
+ 'USE INDEX' => 'name_title',
+ )
+ );
- // Adapted version of
TranslateUtils:makeListing() by Nikerabbit
- $out = TranslateUtils::tableHeader();
+ if( !$res->numRows() ) {
+ $wgOut->addWikiMsg(
'translate-translations-no-message', $title->getPrefixedText() );
+ return;
+ }
- foreach ( $res as $s ) {
- $key = $s->page_title;
- $t = Title::makeTitle(
$s->page_namespace, $key );
+ // Normal output
+ $titles = array();
+ foreach ( $res as $s ) { $titles[] = $s->page_title; }
+ $pageInfo = TranslateUtils::getContents( $titles, $namespace );
- $niceTitle = htmlspecialchars(
$wgLang->truncate( $key, - 30, '…' ) );
- if ( 1 || $wgUser->isAllowed(
'translate' ) ) {
- $tools['edit'] =
$sk->makeKnownLinkObj( $t, $niceTitle, "action=edit&loadgroup=$inMessageGroup"
);
- } else {
- $tools['edit'] = '';
- }
+ $tableheader = Xml::openElement( 'table', array(
+ 'class' => 'mw-sp-translate-table',
+ 'border' => '1',
+ 'cellspacing' => '0' )
+ );
- $anchor = 'msg_' . $key;
- $anchor = Xml::element( 'a', array(
'name' => $anchor, 'href' => "#$anchor" ), "↓" );
+ $tableheader .= Xml::openElement( 'tr' );
+ $tableheader .= Xml::element( 'th', null, wfMsg(
'allmessagesname' ) );
+ $tableheader .= Xml::element( 'th', null, wfMsg(
'allmessagescurrent' ) );
+ $tableheader .= Xml::closeElement( 'tr' );
- $extra = '';
- $leftColumn = $anchor . $tools['edit']
. $extra;
- $out .= Xml::tags( 'tr', array( 'class'
=> 'def' ),
- Xml::tags( 'td', null,
$leftColumn ) .
- Xml::tags( 'td', null,
TranslateUtils::convertWhiteSpaceToHTML( $pageInfo[$key][0] ) )
- );
- }
- TranslateUtils::injectCSS();
+ // Adapted version of TranslateUtils:makeListing() by Nikerabbit
+ $out = $tableheader;
- $out .= Xml::closeElement( 'table' );
+ foreach ( $res as $s ) {
+ $key = $s->page_title;
+ $t = Title::makeTitle( $s->page_namespace, $key );
+
+ $niceTitle = htmlspecialchars( $this->getTheCode(
$s->page_title ) );
+
+ if ( !$wgUser->isAllowed( 'translate' ) ) {
+ $tools['edit'] = $sk->makeKnownLinkObj( $t,
$niceTitle, "action=edit&loadgroup=$inMessageGroup" );
} else {
- if( $namespace ) {
- $out = wfMsg(
'translate-translations-none', $title->getPrefixedText() );
- } else {
- $out = wfMsg(
'translate-translations-none', $message );
- }
+ $tools['edit'] = $sk->makeKnownLinkObj( $t,
$niceTitle );
}
+ $anchor = 'msg_' . $key;
+ $anchor = Xml::element( 'a', array( 'name' => $anchor,
'href' => "#$anchor" ), "↓" );
+
+ $extra = '';
+
+ $leftColumn = $anchor . $tools['edit'] . $extra;
+ $out .= Xml::tags( 'tr', array( 'class' => 'def' ),
+ Xml::tags( 'td', null, $leftColumn ) .
+ Xml::tags( 'td', null,
TranslateUtils::convertWhiteSpaceToHTML( $pageInfo[$key][0] ) )
+ );
}
+ TranslateUtils::injectCSS();
+
+ $out .= Xml::closeElement( 'table' );
$wgOut->addHTML( $out );
}
+
+ public function getTheCode( $name ) {
+ $from = strrpos( $name, '/' );
+ return substr( $name, $from+1 );
+ }
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs