r94012 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94011‎ | r94012 | r94013 >
Date:08:36, 6 August 2011
Author:catrope
Status:deferred
Tags:
Comment:
RL2: Add Special:GadgetManager, and a few random unrelated i18n messages. For now, the special page only has a view mode, but it will have create/modify/delete actions and fancy AJAX stuff later
Modified paths:
  • /branches/RL2/extensions/Gadgets/Gadgets.alias.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/Gadgets.i18n.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/Gadgets.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/SpecialGadgetManager.php (added) (history)

Diff [purge]

Index: branches/RL2/extensions/Gadgets/Gadgets.i18n.php
@@ -43,6 +43,33 @@
4444 <pre>$2</pre>
4545 You must have appropriate permissions on destination wiki (including the right to edit system messages) and import from file uploads must be enabled.',
4646 'gadgets-export-download' => 'Download',
 47+
 48+ # for gadget management (Special:GadgetMananger and the API)
 49+ 'gadgetmanager' => 'Gadget manager',
 50+ 'gadgetmanager-title' => 'Gadget manager',
 51+ 'gadgetmanager-pagetext' => 'TODO, should link to [[Special:Log/gadgetman]]',
 52+ 'gadgetmanager-modify-link' => 'modify',
 53+ 'gadgetmanager-delete-link' => 'delete',
 54+ 'gadgetmanager-prop-scripts' => 'Scripts',
 55+ 'gadgetmanager-prop-styles' => 'Styles',
 56+ 'gadgetmanager-prop-dependencies' => 'Dependencies',
 57+ 'gadgetmanager-prop-messages' => 'Messages',
 58+ 'gadgetmanager-prop-rights' => 'Rights',
 59+ 'gadgetmanager-prop-default' => 'Default',
 60+ 'gadgetmanager-prop-hidden' => 'Hidden',
 61+ 'gadgetmanager-prop-shared' => 'Shared',
 62+ 'gadgetmanager-prop-yes' => 'Yes',
 63+ 'gadgetmanager-prop-no' => 'No',
 64+
 65+ // TODO clean up inconsistencies between gadgetmanager- and gadgets-manager- etc
 66+ 'gadgets-manager-create-exists' => 'This gadget cannot be created because there is an existing gadget with the name $1',
 67+
 68+ # logging stuff
 69+ 'gadgets-gadgetmanlog-page' => 'Gadget manager log',
 70+ 'gadgets-gadgetmanlog-text' => 'This is a log of changes made to gadgets using the [[Special:GadgetManager|gadget manager]].',
 71+ 'gadgets-gadgetmanlog-createentry' => 'created gadget [[Special:GadgetManager/$1|$1]]', // may want to change depending on what $1 ends up being
 72+ 'gadgets-gadgetmanlog-modifyentry' => 'modified gadget [[Special:GadgetManager/$1|$1]]: $2', // TODO fill out $2, add handler
 73+ 'gadgets-gadgetmanlog-deleteentry' => 'deleted gadget $1',
4774
4875 #rights
4976 'right-gadgets-edit' => 'Edit pages in the Gadget: namespace',
Index: branches/RL2/extensions/Gadgets/Gadgets.php
@@ -100,10 +100,13 @@
101101 $wgAutoloadClasses['GadgetRepo'] = $dir . 'backend/GadgetRepo.php';
102102 $wgAutoloadClasses['GadgetResourceLoaderModule'] = $dir . 'backend/GadgetResourceLoaderModule.php';
103103 $wgAutoloadClasses['LocalGadgetRepo'] = $dir . 'backend/LocalGadgetRepo.php';
 104+$wgAutoloadClasses['SpecialGadgetManager'] = $dir . 'SpecialGadgetManager.php';
104105 $wgAutoloadClasses['SpecialGadgets'] = $dir . 'SpecialGadgets.php';
105106
106107 $wgSpecialPages['Gadgets'] = 'SpecialGadgets';
107108 $wgSpecialPageGroups['Gadgets'] = 'wiki';
 109+$wgSpecialPages['GadgetManager'] = 'SpecialGadgetManager';
 110+$wgSpecialPageGroups['GadgetManager'] = 'wiki';
108111
109112 $wgAPIModules['gadgetmanager'] = 'ApiGadgetManager';
110113 $wgAPIListModules['gadgetcategories'] = 'ApiQueryGadgetCategories';
Index: branches/RL2/extensions/Gadgets/Gadgets.alias.php
@@ -11,6 +11,7 @@
1212 /** English (English) */
1313 $specialPageAliases['en'] = array(
1414 'Gadgets' => array( 'Gadgets' ),
 15+ 'GadgetManager' => array( 'GadgetManager' ),
1516 );
1617
1718 /** Afrikaans (Afrikaans) */
Index: branches/RL2/extensions/Gadgets/SpecialGadgetManager.php
@@ -0,0 +1,141 @@
 2+<?php
 3+class SpecialGadgetManager extends SpecialPage {
 4+ public function __construct() {
 5+ parent::__construct( 'GadgetManager', 'gadgets-manager-view' );
 6+ }
 7+
 8+ public function execute( $par ) {
 9+ global $wgOut, $wgUser; // TODO does SpecialPage have an OutputPage member? RequestContext maybe?
 10+
 11+ if ( !$this->userCanExecute( $wgUser ) ) {
 12+ $this->displayRestrictionError();
 13+ return;
 14+ }
 15+
 16+ $this->setHeaders();
 17+ $wgOut->setPagetitle( wfMsg( 'gadgetmanager-title' ) );
 18+ $wgOut->addWikiMsg( 'gadgetmanager-pagetext' );
 19+ $wgOut->addModuleStyles( 'ext.gadgets.gadgetmanager' );
 20+
 21+ // Sort gadgets by section
 22+ $repo = new LocalGadgetRepo( array() );
 23+ $gadgetsBySection = array(); // array( section => array( name => Gadget ) )
 24+ foreach ( $repo->getGadgetNames() as $name ) {
 25+ $gadget = $repo->getGadget( $name );
 26+ $gadgetsBySection[$gadget->getSection()][$name] = $gadget;
 27+ }
 28+
 29+ $html = '';
 30+ foreach ( $gadgetsBySection as $section => $gadgets ) {
 31+ $sectionName = wfMessage( "Gadgetsection-$section-title" )->plain();
 32+ $html .= Html::element( 'h2', array( 'class' => 'mw-gadgetman-section' ), $sectionName );
 33+ $html .= '<div class="mw-gadgetman-gadgets">';
 34+
 35+ foreach ( $gadgets as $name => $gadget ) {
 36+ // TODO trigger visibility of mod/delete by rights
 37+ // Leave empty wrapper if user has neither right
 38+ $modifyLink = Linker::link(
 39+ $this->getTitle( $name ),
 40+ wfMsg( 'gadgetmanager-modify-link' ),
 41+ array( 'class' => 'mw-gadgetman-modifylink' ),
 42+ array( 'action' => 'modify' )
 43+ );
 44+ $deleteLink = Linker::link(
 45+ $this->getTitle( $name ),
 46+ wfMsg( 'gadgetmanager-delete-link' ),
 47+ array( 'class' => 'mw-gadgetman-deletelink '),
 48+ array( 'action' => 'delete' )
 49+ );
 50+ $title = wfMessage( $gadget->getTitleMsg() )->plain();
 51+ $desc = wfMessage( $gadget->getDescriptionMsg() )->parse();
 52+
 53+ $html .= "<div class=\"mw-gadgetman-gadget\"><div class=\"mw-gadgetman-toollinks\">$modifyLink $deleteLink</div>";
 54+ $html .= Html::element( 'h3', array( 'class' => 'mw-gadgetman-title' ), $title );
 55+ $html .= Html::element( 'p', array( 'class' => 'mw-gadgetman-desc' ), $desc );
 56+
 57+ $html .= '<div class="mw-gadgetman-props"><div class="mw-gadgetman-props-module">';
 58+ $html .= $this->buildPropsArrayList(
 59+ 'gadgetmanager-prop-scripts',
 60+ $gadget->getScripts(),
 61+ array_map( 'self::getLinkTitleForGadgetNS', $gadget->getScripts() )
 62+ );
 63+ $html .= $this->buildPropsArrayList(
 64+ 'gadgetmanager-prop-styles',
 65+ $gadget->getStyles(),
 66+ array_map( 'self::getLinkTitleForGadgetNS', $gadget->getStyles() )
 67+ );
 68+
 69+ $module = $gadget->getModule();
 70+ $html .= $this->buildPropsArrayList(
 71+ 'gadgetmanager-prop-dependencies',
 72+ $module->getDependencies()
 73+ );
 74+ $html .= $this->buildPropsArrayList(
 75+ 'gadgetmanager-prop-messages',
 76+ $module->getMessages(),
 77+ array_map( 'self::getLinkTitleForMediaWikiNS', $module->getMessages() )
 78+ );
 79+ // TODO implement load position
 80+ //$html .= Html::element( 'label', array(), wfMessage( 'gadgetmanager-prop-position' )->plain() );
 81+ //$html .= Html::element( 'span', array( 'class' => 'mw-gadgetman-props-value' ), $gadget->getPosition() );
 82+ //$html .= '<br />';
 83+ $html .= '</div>'; // close mw-gadgetman-props-module
 84+
 85+ $html .= '<div class="mw-gadgetman-props-gadget">';
 86+ $html .= $this->buildPropsArrayList(
 87+ 'gadgetmanager-prop-rights',
 88+ $gadget->getRequiredRights()
 89+ );
 90+ $html .= $this->buildBooleanProp( 'gadgetmanager-prop-default', $gadget->isEnabledByDefault() );
 91+ $html .= $this->buildBooleanProp( 'gadgetmanager-prop-hidden', $gadget->isHidden() );
 92+ $html .= $this->buildBooleanProp( 'gadgetmanager-prop-shared', $gadget->isShared() );
 93+ $html .= '</div></div></div>'; // close mw-gadgetman-props-gadget, mw-gadgetman-props and mw-gadgetman-gadget
 94+ }
 95+ $html .= '</div>'; // close mw-gadgetman-gadgets
 96+ }
 97+ $wgOut->addHTML( $html );
 98+ }
 99+
 100+ protected function buildPropsArrayList( $labelMsg, $arr, $linkTitles = false ) {
 101+ $html = Html::element( 'label', array(), wfMessage( $labelMsg )->plain() );
 102+ $html .= '<span class="mw-gadgetman-props-value mw-gadgetman-props-listwrapper">';
 103+ foreach ( $arr as $i => $value ) {
 104+ if ( $linkTitles ) {
 105+ $value = Linker::link( $linkTitles[$i], $value );
 106+ } else {
 107+ $value = htmlspecialchars( $value );
 108+ }
 109+ $html .= Html::rawElement( 'span', array( 'class' => 'mw-gadgetman-props-listitem' ), $value );
 110+ }
 111+ $html .= '</span><br />';
 112+ return $html;
 113+ }
 114+
 115+ protected function buildBooleanProp( $labelMsg, $value ) {
 116+ $html = Html::element( 'label', array(), wfMessage( $labelMsg )->plain() );
 117+ $msg = wfMessage( $value ? 'gadgetmanager-prop-yes' : 'gadgetmanager-prop-no' )->plain();
 118+ $html .= Html::element( 'span', array( 'class' => 'mw-gadgetman-props-value' ), $msg );
 119+ $html .= '<br />';
 120+ return $html;
 121+ }
 122+
 123+ protected static function getLinkTitleForGadgetNS( $str ) {
 124+ return Title::makeTitle( NS_GADGET, $str );
 125+ }
 126+
 127+ protected static function getLinkTitleForMediaWikiNS( $str ) {
 128+ return Title::makeTitle( NS_MEDIAWIKI, $str );
 129+ }
 130+
 131+ /**
 132+ * Log a gadget manager action
 133+ * @param $action string Action name (one of 'create', 'modify', 'delete')
 134+ * @param $title Title object for the gadget, like Special:GadgetManager/foo
 135+ * @param $reason string Log reason TODO figure out how to implement optional reasons; is empty string good enough?
 136+ * @param $params array Log parameters TODO document
 137+ */
 138+ protected function logAction( $action, $title, $reason = '', $params = array() ) {
 139+ $log = new LogPage( 'gadgetman' );
 140+ $log->addEntry( $action, $title, $reason, $params );
 141+ }
 142+}
Property changes on: branches/RL2/extensions/Gadgets/SpecialGadgetManager.php
___________________________________________________________________
Added: svn:eol-style
1143 + native

Status & tagging log