00001 <?php
00013 class SpecialAggregateGroups extends SpecialPage {
00014 function __construct() {
00015 parent::__construct( 'AggregateGroups', 'translate-manage' );
00016 }
00017
00018 public function execute( $parameters ) {
00019 $this->setHeaders();
00020
00021 $out = $this->getOutput();
00022
00023
00024
00025 if ( !$this->getUser()->isAllowed( 'translate-manage' ) ) {
00026 throw new PermissionsError( 'translate-manage' );
00027 }
00028
00029 $groups = MessageGroups::getAllGroups();
00030 uasort( $groups, array( 'MessageGroups', 'groupLabelSort' ) );
00031 $aggregates = array();
00032 $pages = array();
00033 foreach ( $groups as $group ) {
00034 if ( $group instanceof WikiPageMessageGroup ) {
00035 $pages[] = $group;
00036 } elseif ( $group instanceof AggregateMessageGroup ) {
00037 $subgroups = TranslateMetadata::getSubgroups( $group->getId() );
00038 if ( $subgroups !== false ) {
00039 $aggregates[] = $group;
00040 }
00041 }
00042 }
00043
00044 if ( !count( $pages ) ) {
00045
00046 $out->addWikiMsg( 'tpt-list-nopages' );
00047
00048 return;
00049 }
00050
00051 $this->showAggregateGroups( $aggregates, $pages );
00052 }
00053
00058 protected function showAggregateGroups( array $aggregates, array $pages ) {
00059 $out = $this->getOutput();
00060 $out->addModules( 'ext.translate.special.aggregategroups' );
00061
00065 foreach ( $aggregates as $group ) {
00066 $id = $group->getId();
00067 $div = Html::openElement( 'div', array(
00068 'class' => 'mw-tpa-group',
00069 'data-groupid' => $id,
00070 'data-id' => $this->htmlIdForGroup( $group ),
00071 ) );
00072
00073 $out->addHtml( $div );
00074
00075 $remove = Html::element( 'span', array( 'class' => 'tp-aggregate-remove-ag-button' ) );
00076
00077 $header = Html::rawElement(
00078 'h2',
00079 array(),
00080 htmlspecialchars( $group->getLabel() ) . $remove
00081 );
00082 $out->addHtml( $header );
00083 $out->addWikiText( $group->getDescription( $this->getContext() ) );
00084 $this->listSubgroups( $group );
00085 $select = $this->getGroupSelector( $pages, $group );
00086 $out->addHtml( $select->getHtml() );
00087 $addButton = Html::element( 'input',
00088 array( 'type' => 'button',
00089 'value' => $this->msg( 'tpt-aggregategroup-add' )->text(),
00090 'class' => 'tp-aggregate-add-button' )
00091 );
00092 $out->addHtml( $addButton );
00093 $out->addHtml( "</div>" );
00094 }
00095
00096 $out->addHtml( Html::element( 'input', array(
00097 'type' => 'hidden',
00098 'id' => 'token',
00099 'value' => ApiAggregateGroups::getToken()
00100 ) ) );
00101 $out->addHtml( "<br/><a class='tpt-add-new-group' href='#'>" .
00102 $this->msg( 'tpt-aggregategroup-add-new' )->escaped() .
00103 "</a>" );
00104 $newGroupNameLabel = $this->msg( 'tpt-aggregategroup-new-name' )->escaped();
00105 $newGroupName = Html::element(
00106 'input',
00107 array( 'class' => 'tp-aggregategroup-add-name', 'maxlength' => '200' )
00108 );
00109 $newGroupDescriptionLabel = $this->msg( 'tpt-aggregategroup-new-description' )->escaped();
00110 $newGroupDescription = Html::element( 'input',
00111 array( 'class' => 'tp-aggregategroup-add-description' )
00112 );
00113 $saveButton = Html::element( 'input', array(
00114 'type' => 'button',
00115 'value' => $this->msg( 'tpt-aggregategroup-save' )->text(),
00116 'id' => 'tpt-aggregategroups-save',
00117 'class' => 'tp-aggregate-save-button'
00118 ) );
00119 $newGroupDiv = Html::rawElement(
00120 'div',
00121 array( 'class' => 'tpt-add-new-group hidden' ),
00122 "$newGroupNameLabel $newGroupName<br />" .
00123 "$newGroupDescriptionLabel $newGroupDescription<br />$saveButton"
00124 );
00125 $out->addHtml( $newGroupDiv );
00126 }
00127
00131 protected function listSubgroups( AggregateMessageGroup $parent ) {
00132 $out = $this->getOutput();
00133
00134 $id = $this->htmlIdForGroup( $parent, 'mw-tpa-grouplist-' );
00135 $out->addHtml( Html::openElement( 'ol', array( 'id' => $id ) ) );
00136
00137
00138 $subgroupIds = TranslateMetadata::getSubgroups( $parent->getId() );
00139
00140
00141 $subgroups = MessageGroups::getGroupsById( $subgroupIds );
00142 uasort( $subgroups, array( 'MessageGroups', 'groupLabelSort' ) );
00143
00144
00145 foreach ( $subgroupIds as $id ) {
00146 if ( !isset( $subgroups[$id] ) ) {
00147 $subgroups[$id] = null;
00148 }
00149 }
00150
00151 foreach ( $subgroups as $id => $group ) {
00152 $remove = Html::element( 'span',
00153 array(
00154 'class' => 'tp-aggregate-remove-button',
00155 'data-groupid' => $id,
00156 )
00157 );
00158
00159 if ( $group ) {
00160 $text = Linker::linkKnown( $group->getTitle() );
00161 $note = MessageGroups::getPriority( $id );
00162 } else {
00163 $text = htmlspecialchars( $id );
00164 $note = $this->msg( 'tpt-aggregategroup-invalid-group' )->escaped();
00165 }
00166
00167 $out->addHtml( Html::rawElement( 'li', array(), "$text$remove $note" ) );
00168 }
00169 $out->addHtml( Html::closeElement( 'ol' ) );
00170 }
00171
00177 protected function getGroupSelector( $availableGroups, $parent ) {
00178 $id = $this->htmlIdForGroup( $parent, 'mw-tpa-groupselect-' );
00179 $select = new XmlSelect( 'group', $id );
00180 $select->setAttribute( 'class', 'mw-tpa-groupselect' );
00181
00182
00183 $subgroups = TranslateMetadata::getSubgroups( $parent->getId() );
00184 $subgroups = array_flip( $subgroups );
00188 foreach ( $availableGroups as $group ) {
00189 $groupId = $group->getId();
00190
00191
00192 if ( isset( $subgroups[$groupId] ) ) {
00193 continue;
00194 }
00195
00196 $select->addOption( $group->getLabel(), $groupId );
00197 }
00198
00199 return $select;
00200 }
00201
00207 protected function htmlIdForGroup( MessageGroup $group, $prefix = '' ) {
00208 $id = sha1( $group->getId() );
00209 $id = substr( $id, 5, 8 );
00210
00211 return $prefix . $id;
00212 }
00213 }