X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fspecials%2FSpecialTags.php;h=2ff21228c61c18bd32841a5b5f2db2090c0deca0;hb=f82b0e76306a9feca014e563a5fac0688cf876dc;hp=c03f81184f8c335eae776c88f85b8a5f15796635;hpb=abb7c6792fab5e9a6e0c088dd820fd3d74c13059;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/SpecialTags.php b/includes/specials/SpecialTags.php index c03f81184f..47bed62642 100644 --- a/includes/specials/SpecialTags.php +++ b/includes/specials/SpecialTags.php @@ -77,31 +77,32 @@ class SpecialTags extends SpecialPage { $user = $this->getUser(); $userCanManage = $user->isAllowed( 'managechangetags' ); + $userCanDelete = $user->isAllowed( 'deletechangetags' ); $userCanEditInterface = $user->isAllowed( 'editinterface' ); // Show form to create a tag if ( $userCanManage ) { - $fields = array( - 'Tag' => array( + $fields = [ + 'Tag' => [ 'type' => 'text', 'label' => $this->msg( 'tags-create-tag-name' )->plain(), 'required' => true, - ), - 'Reason' => array( + ], + 'Reason' => [ 'type' => 'text', 'label' => $this->msg( 'tags-create-reason' )->plain(), 'size' => 50, - ), - 'IgnoreWarnings' => array( + ], + 'IgnoreWarnings' => [ 'type' => 'hidden', - ), - ); + ], + ]; $form = new HTMLForm( $fields, $this->getContext() ); $form->setAction( $this->getPageTitle( 'create' )->getLocalURL() ); $form->setWrapperLegendMsg( 'tags-create-heading' ); $form->setHeaderText( $this->msg( 'tags-create-explanation' )->parseAsBlock() ); - $form->setSubmitCallback( array( $this, 'processCreateTagForm' ) ); + $form->setSubmitCallback( [ $this, 'processCreateTagForm' ] ); $form->setSubmitTextMsg( 'tags-create-submit' ); $form->show(); @@ -127,8 +128,7 @@ class SpecialTags extends SpecialPage { ChangeTags::listExtensionDefinedTags(), true ); // List all defined tags, even if they were never applied - $definedTags = array_keys( array_merge( - $this->explicitlyDefinedTags, $this->extensionDefinedTags ) ); + $definedTags = array_keys( $this->explicitlyDefinedTags + $this->extensionDefinedTags ); // Show header only if there exists atleast one tag if ( !$tagStats && !$definedTags ) { @@ -142,8 +142,8 @@ class SpecialTags extends SpecialPage { Xml::tags( 'th', null, $this->msg( 'tags-source-header' )->parse() ) . Xml::tags( 'th', null, $this->msg( 'tags-active-header' )->parse() ) . Xml::tags( 'th', null, $this->msg( 'tags-hitcount-header' )->parse() ) . - ( $userCanManage ? - Xml::tags( 'th', array( 'class' => 'unsortable' ), + ( ( $userCanManage || $userCanDelete ) ? + Xml::tags( 'th', [ 'class' => 'unsortable' ], $this->msg( 'tags-actions-header' )->parse() ) : '' ) ); @@ -154,32 +154,34 @@ class SpecialTags extends SpecialPage { // Insert tags that have been applied at least once foreach ( $tagStats as $tag => $hitcount ) { - $html .= $this->doTagRow( $tag, $hitcount, $userCanManage, $userCanEditInterface ); + $html .= $this->doTagRow( $tag, $hitcount, $userCanManage, + $userCanDelete, $userCanEditInterface ); } // Insert tags defined somewhere but never applied foreach ( $definedTags as $tag ) { if ( !isset( $tagStats[$tag] ) ) { - $html .= $this->doTagRow( $tag, 0, $userCanManage, $userCanEditInterface ); + $html .= $this->doTagRow( $tag, 0, $userCanManage, $userCanDelete, $userCanEditInterface ); } } $out->addHTML( Xml::tags( 'table', - array( 'class' => 'mw-datatable sortable mw-tags-table' ), + [ 'class' => 'mw-datatable sortable mw-tags-table' ], $html ) ); } - function doTagRow( $tag, $hitcount, $showActions, $showEditLinks ) { + function doTagRow( $tag, $hitcount, $showManageActions, $showDeleteActions, $showEditLinks ) { $newRow = ''; $newRow .= Xml::tags( 'td', null, Xml::element( 'code', null, $tag ) ); + $linkRenderer = $this->getLinkRenderer(); $disp = ChangeTags::tagDescription( $tag ); if ( $showEditLinks ) { $disp .= ' '; - $editLink = Linker::link( + $editLink = $linkRenderer->makeLink( $this->msg( "tag-$tag" )->inContentLanguage()->getTitle(), - $this->msg( 'tags-edit' )->escaped() + $this->msg( 'tags-edit' )->text() ); $disp .= $this->msg( 'parentheses' )->rawParams( $editLink )->escaped(); } @@ -189,15 +191,15 @@ class SpecialTags extends SpecialPage { $desc = !$msg->exists() ? '' : $msg->parse(); if ( $showEditLinks ) { $desc .= ' '; - $editDescLink = Linker::link( + $editDescLink = $linkRenderer->makeLink( $this->msg( "tag-$tag-description" )->inContentLanguage()->getTitle(), - $this->msg( 'tags-edit' )->escaped() + $this->msg( 'tags-edit' )->text() ); $desc .= $this->msg( 'parentheses' )->rawParams( $editDescLink )->escaped(); } $newRow .= Xml::tags( 'td', null, $desc ); - $sourceMsgs = array(); + $sourceMsgs = []; $isExtension = isset( $this->extensionDefinedTags[$tag] ); $isExplicit = isset( $this->explicitlyDefinedTags[$tag] ); if ( $isExtension ) { @@ -215,47 +217,56 @@ class SpecialTags extends SpecialPage { $activeMsg = ( $isActive ? 'tags-active-yes' : 'tags-active-no' ); $newRow .= Xml::tags( 'td', null, $this->msg( $activeMsg )->escaped() ); - $hitcountLabel = $this->msg( 'tags-hitcount' )->numParams( $hitcount )->escaped(); + $hitcountLabelMsg = $this->msg( 'tags-hitcount' )->numParams( $hitcount ); if ( $this->getConfig()->get( 'UseTagFilter' ) ) { - $hitcountLabel = Linker::link( + $hitcountLabel = $linkRenderer->makeLink( SpecialPage::getTitleFor( 'Recentchanges' ), - $hitcountLabel, - array(), - array( 'tagfilter' => $tag ) + $hitcountLabelMsg->text(), + [], + [ 'tagfilter' => $tag ] ); + } else { + $hitcountLabel = $hitcountLabelMsg->escaped(); } // add raw $hitcount for sorting, because tags-hitcount contains numbers and letters - $newRow .= Xml::tags( 'td', array( 'data-sort-value' => $hitcount ), $hitcountLabel ); + $newRow .= Xml::tags( 'td', [ 'data-sort-value' => $hitcount ], $hitcountLabel ); // actions - if ( $showActions ) { // we've already checked that the user had the requisite userright - $actionLinks = array(); - - // delete - if ( ChangeTags::canDeleteTag( $tag )->isOK() ) { - $actionLinks[] = Linker::linkKnown( $this->getPageTitle( 'delete' ), - $this->msg( 'tags-delete' )->escaped(), - array(), - array( 'tag' => $tag ) ); - } + $actionLinks = []; + + // delete + if ( $showDeleteActions && ChangeTags::canDeleteTag( $tag )->isOK() ) { + $actionLinks[] = $linkRenderer->makeKnownLink( + $this->getPageTitle( 'delete' ), + $this->msg( 'tags-delete' )->text(), + [], + [ 'tag' => $tag ] ); + } + + if ( $showManageActions ) { // we've already checked that the user had the requisite userright // activate if ( ChangeTags::canActivateTag( $tag )->isOK() ) { - $actionLinks[] = Linker::linkKnown( $this->getPageTitle( 'activate' ), - $this->msg( 'tags-activate' )->escaped(), - array(), - array( 'tag' => $tag ) ); + $actionLinks[] = $linkRenderer->makeKnownLink( + $this->getPageTitle( 'activate' ), + $this->msg( 'tags-activate' )->text(), + [], + [ 'tag' => $tag ] ); } // deactivate if ( ChangeTags::canDeactivateTag( $tag )->isOK() ) { - $actionLinks[] = Linker::linkKnown( $this->getPageTitle( 'deactivate' ), - $this->msg( 'tags-deactivate' )->escaped(), - array(), - array( 'tag' => $tag ) ); + $actionLinks[] = $linkRenderer->makeKnownLink( + $this->getPageTitle( 'deactivate' ), + $this->msg( 'tags-deactivate' )->text(), + [], + [ 'tag' => $tag ] ); } + } + + if ( $showDeleteActions || $showManageActions ) { $newRow .= Xml::tags( 'td', null, $this->getLanguage()->pipeList( $actionLinks ) ); } @@ -276,20 +287,20 @@ class SpecialTags extends SpecialPage { return true; } elseif ( $status->isOK() ) { // we have some warnings, so we show a confirmation form - $fields = array( - 'Tag' => array( + $fields = [ + 'Tag' => [ 'type' => 'hidden', 'default' => $data['Tag'], - ), - 'Reason' => array( + ], + 'Reason' => [ 'type' => 'hidden', 'default' => $data['Reason'], - ), - 'IgnoreWarnings' => array( + ], + 'IgnoreWarnings' => [ 'type' => 'hidden', 'default' => '1', - ), - ); + ], + ]; // fool HTMLForm into thinking the form hasn't been submitted yet. Otherwise // we get into an infinite loop! @@ -297,21 +308,21 @@ class SpecialTags extends SpecialPage { $headerText = $this->msg( 'tags-create-warnings-above', $tag, count( $status->getWarningsArray() ) )->parseAsBlock() . - $out->parse( $status->getWikitext() ) . + $out->parse( $status->getWikiText() ) . $this->msg( 'tags-create-warnings-below' )->parseAsBlock(); $subform = new HTMLForm( $fields, $this->getContext() ); $subform->setAction( $this->getPageTitle( 'create' )->getLocalURL() ); $subform->setWrapperLegendMsg( 'tags-create-heading' ); $subform->setHeaderText( $headerText ); - $subform->setSubmitCallback( array( $this, 'processCreateTagForm' ) ); + $subform->setSubmitCallback( [ $this, 'processCreateTagForm' ] ); $subform->setSubmitTextMsg( 'htmlform-yes' ); $subform->show(); $out->addBacklinkSubtitle( $this->getPageTitle() ); return true; } else { - $out->addWikiText( "
\n" . $status->getWikitext() . + $out->addWikiText( "
\n" . $status->getWikiText() . "\n
" ); return false; } @@ -319,8 +330,8 @@ class SpecialTags extends SpecialPage { protected function showDeleteTagForm( $tag ) { $user = $this->getUser(); - if ( !$user->isAllowed( 'managechangetags' ) ) { - throw new PermissionsError( 'managechangetags' ); + if ( !$user->isAllowed( 'deletechangetags' ) ) { + throw new PermissionsError( 'deletechangetags' ); } $out = $this->getOutput(); @@ -352,23 +363,23 @@ class SpecialTags extends SpecialPage { $preText .= $this->msg( 'tags-delete-explanation-active', $tag )->parseAsBlock(); } - $fields = array(); - $fields['Reason'] = array( + $fields = []; + $fields['Reason'] = [ 'type' => 'text', 'label' => $this->msg( 'tags-delete-reason' )->plain(), 'size' => 50, - ); - $fields['HiddenTag'] = array( + ]; + $fields['HiddenTag'] = [ 'type' => 'hidden', 'name' => 'tag', 'default' => $tag, 'required' => true, - ); + ]; $form = new HTMLForm( $fields, $this->getContext() ); $form->setAction( $this->getPageTitle( 'delete' )->getLocalURL() ); $form->tagAction = 'delete'; // custom property on HTMLForm object - $form->setSubmitCallback( array( $this, 'processTagForm' ) ); + $form->setSubmitCallback( [ $this, 'processTagForm' ] ); $form->setSubmitTextMsg( 'tags-delete-submit' ); $form->setSubmitDestructive(); // nasty! $form->addPreText( $preText ); @@ -402,24 +413,24 @@ class SpecialTags extends SpecialPage { // tags-activate-question, tags-deactivate-question $preText = $this->msg( "tags-$actionStr-question", $tag )->parseAsBlock(); - $fields = array(); + $fields = []; // tags-activate-reason, tags-deactivate-reason - $fields['Reason'] = array( + $fields['Reason'] = [ 'type' => 'text', 'label' => $this->msg( "tags-$actionStr-reason" )->plain(), 'size' => 50, - ); - $fields['HiddenTag'] = array( + ]; + $fields['HiddenTag'] = [ 'type' => 'hidden', 'name' => 'tag', 'default' => $tag, 'required' => true, - ); + ]; $form = new HTMLForm( $fields, $this->getContext() ); $form->setAction( $this->getPageTitle( $actionStr )->getLocalURL() ); $form->tagAction = $actionStr; - $form->setSubmitCallback( array( $this, 'processTagForm' ) ); + $form->setSubmitCallback( [ $this, 'processTagForm' ] ); // tags-activate-submit, tags-deactivate-submit $form->setSubmitTextMsg( "tags-$actionStr-submit" ); $form->addPreText( $preText ); @@ -431,7 +442,7 @@ class SpecialTags extends SpecialPage { $out = $context->getOutput(); $tag = $data['HiddenTag']; - $status = call_user_func( array( 'ChangeTags', "{$form->tagAction}TagWithChecks" ), + $status = call_user_func( [ 'ChangeTags', "{$form->tagAction}TagWithChecks" ], $tag, $data['Reason'], $context->getUser(), true ); if ( $status->isGood() ) { @@ -458,12 +469,12 @@ class SpecialTags extends SpecialPage { */ public function getSubpagesForPrefixSearch() { // The subpages does not have an own form, so not listing it at the moment - return array( + return [ // 'delete', // 'activate', // 'deactivate', // 'create', - ); + ]; } protected function getGroupName() {