Index: branches/RL2/extensions/Gadgets/Gadgets.i18n.php |
— | — | @@ -43,6 +43,33 @@ |
44 | 44 | <pre>$2</pre> |
45 | 45 | You must have appropriate permissions on destination wiki (including the right to edit system messages) and import from file uploads must be enabled.', |
46 | 46 | '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', |
47 | 74 | |
48 | 75 | #rights |
49 | 76 | 'right-gadgets-edit' => 'Edit pages in the Gadget: namespace', |
Index: branches/RL2/extensions/Gadgets/Gadgets.php |
— | — | @@ -100,10 +100,13 @@ |
101 | 101 | $wgAutoloadClasses['GadgetRepo'] = $dir . 'backend/GadgetRepo.php'; |
102 | 102 | $wgAutoloadClasses['GadgetResourceLoaderModule'] = $dir . 'backend/GadgetResourceLoaderModule.php'; |
103 | 103 | $wgAutoloadClasses['LocalGadgetRepo'] = $dir . 'backend/LocalGadgetRepo.php'; |
| 104 | +$wgAutoloadClasses['SpecialGadgetManager'] = $dir . 'SpecialGadgetManager.php'; |
104 | 105 | $wgAutoloadClasses['SpecialGadgets'] = $dir . 'SpecialGadgets.php'; |
105 | 106 | |
106 | 107 | $wgSpecialPages['Gadgets'] = 'SpecialGadgets'; |
107 | 108 | $wgSpecialPageGroups['Gadgets'] = 'wiki'; |
| 109 | +$wgSpecialPages['GadgetManager'] = 'SpecialGadgetManager'; |
| 110 | +$wgSpecialPageGroups['GadgetManager'] = 'wiki'; |
108 | 111 | |
109 | 112 | $wgAPIModules['gadgetmanager'] = 'ApiGadgetManager'; |
110 | 113 | $wgAPIListModules['gadgetcategories'] = 'ApiQueryGadgetCategories'; |
Index: branches/RL2/extensions/Gadgets/Gadgets.alias.php |
— | — | @@ -11,6 +11,7 @@ |
12 | 12 | /** English (English) */ |
13 | 13 | $specialPageAliases['en'] = array( |
14 | 14 | 'Gadgets' => array( 'Gadgets' ), |
| 15 | + 'GadgetManager' => array( 'GadgetManager' ), |
15 | 16 | ); |
16 | 17 | |
17 | 18 | /** 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 |
1 | 143 | + native |