Index: trunk/extensions/PackageForce/PackageForce.php |
— | — | @@ -0,0 +1,336 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +# Alert the user that this is not a valid entry point to MediaWiki if |
| 5 | +# they try to access the special pages file directly. |
| 6 | +if (!defined('MEDIAWIKI')) { |
| 7 | + echo <<<EOT |
| 8 | +This is not a valid entry point, mister! |
| 9 | + |
| 10 | +TRY CATCH AGAIN, EXCEPTION BOY |
| 11 | +EOT; |
| 12 | + exit( 1 ); |
| 13 | +} |
| 14 | + |
| 15 | + |
| 16 | +$wgExtensionCredits['specialpage'][] = array( |
| 17 | + 'path' => __FILE__, |
| 18 | + 'name' => 'Package Force', |
| 19 | + 'author' => array( 'Svip' ), |
| 20 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:PackageForce', |
| 21 | + 'description' => 'Creating a special page to download packages of useful templates/etc..', |
| 22 | + 'descriptionmsg' => 'pf-desc', |
| 23 | + 'version' => '0.1' |
| 24 | +); |
| 25 | + |
| 26 | +$dir = dirname(__FILE__); |
| 27 | +$wgExtensionMessagesFiles['PackageForce'] = "$dir/PackageForce.i18n.php"; |
| 28 | +#$wgExtensionMessagesFiles['PackageForceMagic'] = "$dir/PackageForce.i18n.magic.php"; |
| 29 | + |
| 30 | +$wgExtensionAliasesFiles['PackageForce'] = "$dir/PackageForce.alias.php"; |
| 31 | +$wgSpecialPages['PackageForce'] = 'PackageForceSpecial'; |
| 32 | +$wgSpecialPages['PackageForceAdmin'] = 'PackageForceAdminSpecial'; |
| 33 | + |
| 34 | +# New rights |
| 35 | +$wgGroupPermissions['sysop']['packageforce-admin'] = true; |
| 36 | +$wgGroupPermissions['sysop']['packageforce-edit'] = true; |
| 37 | + |
| 38 | +# Create our own namespace |
| 39 | +define ( 'NS_PACKAGEFORCE', 1300 ); |
| 40 | +define ( 'NS_PACKAGEFORCE_TALK', 1301 ); |
| 41 | + |
| 42 | +# Only English for now. |
| 43 | +$wgExtraNamespaces[NS_PACKAGEFORCE] = 'PackageForce'; |
| 44 | +$wgExtraNamespaces[NS_PACKAGEFORCE_TALK] = 'PackageForce_talk'; |
| 45 | + |
| 46 | +$wgNamespaceProtection[NS_PACKAGEFORCE] = |
| 47 | + $wgNamespaceProtection[NS_PACKAGEFORCE_TALK] = array ( 'packageforce-edit' ); |
| 48 | + |
| 49 | +class PackageForceAdminSpecial extends SpecialPage { |
| 50 | + var $package = null; |
| 51 | + var $view = 'page'; |
| 52 | + |
| 53 | + function __construct() { |
| 54 | + parent::__construct( 'PackageForceAdmin' ); |
| 55 | + wfLoadExtensionMessages('PackageForceAdmin'); |
| 56 | + } |
| 57 | + |
| 58 | + function execute( $par ) { |
| 59 | + global $wgRequest, $wgOut, $wgUser; |
| 60 | + |
| 61 | + $this->setHeaders(); |
| 62 | + |
| 63 | + # Only for admins! |
| 64 | + if ( !$wgUser->isAllowed ( 'packageforce-admin' ) ) { |
| 65 | + $wgOut->addWikiMsg ( 'pf-error-only-admins-allowed' ); |
| 66 | + return; |
| 67 | + } |
| 68 | + |
| 69 | + $menu = array ( |
| 70 | + array ( |
| 71 | + $this->getTitle()->getFullURL(), |
| 72 | + wfMsg('pf-admin-menu-default') |
| 73 | + ), |
| 74 | + array ( |
| 75 | + $this->getTitle()->getFullURL( |
| 76 | + wfArrayToCGI( array ( |
| 77 | + 'view' => 'unsorted', |
| 78 | + ) ) |
| 79 | + ), |
| 80 | + wfMsg('pf-admin-menu-unsortedtemplates') |
| 81 | + ), |
| 82 | + ); |
| 83 | + |
| 84 | + $htmlMenu = ''; |
| 85 | + |
| 86 | + foreach ( $menu as $i => $item ) { |
| 87 | + if ( $i !== 0 ) |
| 88 | + $htmlMenu .= ' | '; |
| 89 | + $htmlMenu .= '<a href="'.$item[0].'">'.$item[1].'</a>'; |
| 90 | + } |
| 91 | + |
| 92 | + $wgOut->addHtml( |
| 93 | + '<div>'.$htmlMenu.'</div>' |
| 94 | + ); |
| 95 | + |
| 96 | + # Get request data from, e.g. |
| 97 | + $view = $wgRequest->getText('view'); |
| 98 | + |
| 99 | + switch ( $view ) { |
| 100 | + case 'unsorted': |
| 101 | + $this->view = 'unsorted'; |
| 102 | + break; |
| 103 | + default: |
| 104 | + $this->view = 'page'; |
| 105 | + break; |
| 106 | + } |
| 107 | + |
| 108 | + $pager = new PackageForceList ( $this ); |
| 109 | + |
| 110 | + $wgOut->addHTML( |
| 111 | + $pager->getLimitForm() . '<br />' . |
| 112 | + $pager->getBody() . |
| 113 | + $pager->getNavigationBar() |
| 114 | + ); |
| 115 | + } |
| 116 | +} |
| 117 | + |
| 118 | +class PackageForceSpecial extends SpecialPage { |
| 119 | + function __construct() { |
| 120 | + parent::__construct( 'PackageForce' ); |
| 121 | + wfLoadExtensionMessages('PackageForce'); |
| 122 | + } |
| 123 | + |
| 124 | + function execute( $par ) { |
| 125 | + global $wgRequest, $wgOut; |
| 126 | + |
| 127 | + $this->setHeaders(); |
| 128 | + |
| 129 | + # Get request data from, e.g. |
| 130 | + $param = $wgRequest->getText('param'); |
| 131 | + |
| 132 | + |
| 133 | + $output = ''; |
| 134 | + |
| 135 | + $wgOut->addWikiText( $output ); |
| 136 | + } |
| 137 | + |
| 138 | + |
| 139 | +} |
| 140 | + |
| 141 | +class PackageForceList extends TablePager { |
| 142 | + var $listPage; |
| 143 | + |
| 144 | + static $packageFields = array ( |
| 145 | + 'page_title', |
| 146 | + 'description', |
| 147 | + 'content', |
| 148 | + ); |
| 149 | + |
| 150 | + static $pageFields = array ( |
| 151 | + 'page_title', |
| 152 | + 'type', |
| 153 | + 'edit', |
| 154 | + 'in_packages', |
| 155 | + 'documentation', |
| 156 | + ); |
| 157 | + |
| 158 | + static $unsortedFields = array ( |
| 159 | + 'page_title', |
| 160 | + 'edit', |
| 161 | + 'approve', |
| 162 | + ); |
| 163 | + |
| 164 | + function __construct( $listPage ) { |
| 165 | + #global $wgUser; |
| 166 | + $this->listPage = $listPage; |
| 167 | + if ( $this->listPage->view == 'packages' |
| 168 | + && $this->listPage->package == null ) |
| 169 | + $this->listPage->view = 'page'; |
| 170 | + parent::__construct(); |
| 171 | + } |
| 172 | + |
| 173 | + function getQueryInfo() { |
| 174 | + if ( $this->listPage->view == 'page' ) { |
| 175 | + if ( $this->listPage->package != null ) { |
| 176 | + return array( |
| 177 | + 'tables' => array ( |
| 178 | + 'packageforce_package_members', |
| 179 | + 'packageforce_packages', |
| 180 | + 'page', |
| 181 | + ), |
| 182 | + 'fields' => array ( |
| 183 | + 'page_title', |
| 184 | + 'page_title AS edit', |
| 185 | + 'pm_id AS documentation', |
| 186 | + 'pk_name AS in_packages', |
| 187 | + 'page_title AS type', |
| 188 | + ), |
| 189 | + 'conds' => array( |
| 190 | + 'pm_package' => $this->listPage->package->getId() |
| 191 | + ), |
| 192 | + 'join_conds' => array ( |
| 193 | + 'packageforce_packages' => |
| 194 | + array ( 'join', 'pm_package = pk_id'), |
| 195 | + 'page' => |
| 196 | + array ( 'join', 'page_id = pm_page'), |
| 197 | + ), |
| 198 | + 'options' => array(), |
| 199 | + 'conds' => 'page_title NOT LIKE "%/doc/%"', |
| 200 | + ); |
| 201 | + } else { |
| 202 | + return array( |
| 203 | + 'tables' => array ( |
| 204 | + 'packageforce_package_members', |
| 205 | + 'packageforce_packages', |
| 206 | + 'page', |
| 207 | + ), |
| 208 | + 'fields' => array ( |
| 209 | + 'page_title', |
| 210 | + 'page_id AS edit', |
| 211 | + 'pm_id AS documentation', |
| 212 | + 'pk_name AS in_packages', |
| 213 | + 'page_title AS type', |
| 214 | + ), |
| 215 | + 'join_conds' => array ( |
| 216 | + 'packageforce_packages' => |
| 217 | + array ( 'join', 'pm_package = pk_id'), |
| 218 | + 'page' => |
| 219 | + array ( 'join', 'page_id = pm_page'), |
| 220 | + ), |
| 221 | + 'options' => array(), |
| 222 | + 'conds' => 'page_title NOT LIKE "%/doc/%"', |
| 223 | + ); |
| 224 | + } |
| 225 | + } elseif ( $this->listPage->view == 'packages' ) { |
| 226 | + return array( |
| 227 | + 'tables' => 'packageforce_packages', |
| 228 | + 'fields' => '*', |
| 229 | + 'options' => array() |
| 230 | + ); |
| 231 | + } elseif ( $this->listPage->view == 'unsorted' ) { |
| 232 | + return array ( |
| 233 | + 'tables' => array ( |
| 234 | + 'page', |
| 235 | + 'packageforce_package_members', |
| 236 | + ), |
| 237 | + 'fields' => array ( |
| 238 | + 'page_title', |
| 239 | + 'page_id AS edit', |
| 240 | + 'page_id AS approve', |
| 241 | + ), |
| 242 | + 'join_conds' => array ( |
| 243 | + 'packageforce_package_members' => |
| 244 | + array ( 'LEFT JOIN', 'pm_page = page_id'), |
| 245 | + ), |
| 246 | + 'conds' => array ( |
| 247 | + 'page_namespace' => NS_PACKAGEFORCE, |
| 248 | + 'pm_id IS NULL', |
| 249 | + 'page_title NOT LIKE "%/doc/%"', |
| 250 | + ), |
| 251 | + ); |
| 252 | + } |
| 253 | + } |
| 254 | + |
| 255 | + function isFieldSortable( $field ) { |
| 256 | + return in_array( $field, array( |
| 257 | + 'page_title', |
| 258 | + ) ); |
| 259 | + } |
| 260 | + |
| 261 | + function formatValue( $name, $value ) { |
| 262 | + global $wgLang, $wgScriptPath; |
| 263 | + |
| 264 | + switch ( $name ) { |
| 265 | + case 'page_title': |
| 266 | + $parts = explode ( '/', $value ); |
| 267 | + if ( count($parts)>=2 && $parts[0]=='Template' ) { |
| 268 | + return '{{'.$parts[1].'}}'; |
| 269 | + } elseif ( $parts[2] != 'doc' ) { |
| 270 | + return $value; |
| 271 | + } |
| 272 | + return $value; |
| 273 | + case 'in_packages': |
| 274 | + return $value; |
| 275 | + case 'type': |
| 276 | + $parts = explode ( '/', $value ); |
| 277 | + if ( $parts[0]=='Template' ) |
| 278 | + return wfMsg ( 'nstab-template' ); |
| 279 | + return $value; |
| 280 | + case 'edit': |
| 281 | + $title = Title::newFromID( $value ); |
| 282 | + return '<a href="'.$title->getFullURL(wfArrayToCGI( array ( |
| 283 | + 'action' => 'edit', |
| 284 | + ) )).'">'.wfMsg ( 'pf-admin-link-editlink-page' ).'</a>'; |
| 285 | + case 'approve': |
| 286 | + return '<a href="'.$this->listPage->getTitle()->getFullURL( |
| 287 | + wfArrayToCGI( array ( |
| 288 | + 'view' => 'approve', |
| 289 | + 'id' => $value, |
| 290 | + ) ) |
| 291 | + ).'">'.wfMsg( 'pf-admin-link-approve' ).'</a>'; |
| 292 | + case 'documentation': |
| 293 | + return '<a href="'.$this->listPage->getTitle()->getFullURL( |
| 294 | + wfArrayToCGI( array ( |
| 295 | + 'view' => 'documentation', |
| 296 | + 'id' => $value, |
| 297 | + ) ) |
| 298 | + ).'">'.wfMsg( 'pf-admin-link-view-documentation' ).'</a>'; |
| 299 | + default: |
| 300 | + return htmlspecialchars( $name.': '.$value ); |
| 301 | + } |
| 302 | + } |
| 303 | + |
| 304 | + function getDefaultSort() { |
| 305 | + return 'page_title'; |
| 306 | + } |
| 307 | + |
| 308 | + function getFieldNames() { |
| 309 | + $names = array(); |
| 310 | + if ( $this->listPage->view == 'page' ) { |
| 311 | + $fields = self::$pageFields; |
| 312 | + } elseif ( $this->listPage->view == 'unsorted' ) { |
| 313 | + $fields = self::$unsortedFields; |
| 314 | + } else { |
| 315 | + $fields = self::$packageFields; |
| 316 | + } |
| 317 | + foreach ( $fields as $field ) { |
| 318 | + $names[$field] = wfMsg( 'pf-header-' . $field ); |
| 319 | + } |
| 320 | + return $names; |
| 321 | + } |
| 322 | + |
| 323 | + /*function getRowClass( $row ) { |
| 324 | + $classes = array(); |
| 325 | + if ( !$row->vote_current ) { |
| 326 | + $classes[] = 'securepoll-old-vote'; |
| 327 | + } |
| 328 | + if ( $row->vote_struck ) { |
| 329 | + $classes[] = 'securepoll-struck-vote'; |
| 330 | + } |
| 331 | + return implode( ' ', $classes ); |
| 332 | + }*/ |
| 333 | + |
| 334 | + function getTitle() { |
| 335 | + return $this->listPage->getTitle(); |
| 336 | + } |
| 337 | +} |
Property changes on: trunk/extensions/PackageForce/PackageForce.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 338 | + native |
Index: trunk/extensions/PackageForce/PackageForce.alias.php |
— | — | @@ -0,0 +1,8 @@ |
| 2 | +<?php |
| 3 | +$aliases = array(); |
| 4 | + |
| 5 | +/** English */ |
| 6 | +$aliases['en'] = array( |
| 7 | + 'PackageForce' => array( 'PackageForce' ), |
| 8 | + 'PackageForceAdmin' => array( 'PackageForceAdmin' ), |
| 9 | +); |
Property changes on: trunk/extensions/PackageForce/PackageForce.alias.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 10 | + native |
Index: trunk/extensions/PackageForce/PackageForce.sql |
— | — | @@ -0,0 +1,19 @@ |
| 2 | +-- Packages table |
| 3 | +CREATE TABLE /*_*/packageforce_packages ( |
| 4 | + -- ID |
| 5 | + pk_id int not null primary key auto_increment, |
| 6 | + |
| 7 | + pk_name varbinary(64) not null |
| 8 | +) /*$wgDBTableOptions*/; |
| 9 | + |
| 10 | +-- Package members |
| 11 | +CREATE TABLE /*_*/packageforce_package_members ( |
| 12 | + -- ID |
| 13 | + pm_id int not null primary key auto_increment, |
| 14 | + |
| 15 | + -- packageforce_packages.pk_id |
| 16 | + pm_package int not null, |
| 17 | + |
| 18 | + -- page.page_id |
| 19 | + pm_page int not null |
| 20 | +) /*$wgDBTableOptions*/; |
Property changes on: trunk/extensions/PackageForce/PackageForce.sql |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 21 | + native |
Index: trunk/extensions/PackageForce/PackageForce.i18n.php |
— | — | @@ -0,0 +1,25 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +$messages = array(); |
| 5 | + |
| 6 | +$messages['en'] = array( |
| 7 | + 'packageforce' => 'PackageForce', |
| 8 | + 'packageforceadmin' => 'PackageForceAdmin', |
| 9 | + 'pf-desc' => 'Creating a special page to download packages of useful templates/etc..', |
| 10 | + 'pf-only-admins-allowed' => 'This page is only for users with the \'packageforce-admin\'-right.', |
| 11 | + |
| 12 | + /* admin links */ |
| 13 | + 'pf-admin-menu-default' => 'Default', |
| 14 | + 'pf-admin-menu-unsortedtemplates' => 'Templates not yet sorted', |
| 15 | + 'pf-admin-link-view-documentation' => 'View documentations tied to page.', |
| 16 | + 'pf-admin-link-editlink-page' => 'Edit page', |
| 17 | + 'pf-admin-link-approve' => 'Approve page', |
| 18 | + |
| 19 | + /* table headers */ |
| 20 | + 'pf-header-documentation' => 'Documentation', |
| 21 | + 'pf-header-in_packages' => 'Packages', |
| 22 | + 'pf-header-edit' => 'Edit link', |
| 23 | + 'pf-header-type' => 'Type of page', |
| 24 | + 'pf-header-page_title' => 'Title', |
| 25 | + 'pf-header-approve' => 'Approve', |
| 26 | +); |
Property changes on: trunk/extensions/PackageForce/PackageForce.i18n.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 27 | + native |