Index: trunk/extensions/PageSchemas/PS_Tabs.php |
— | — | @@ -0,0 +1,87 @@ |
| 2 | +<?php
|
| 3 | +
|
| 4 | +/**
|
| 5 | + * Static class with methods to create and handle the push tab.
|
| 6 | + *
|
| 7 | + * @since 0.1
|
| 8 | + *
|
| 9 | + * @file Push_Tab.php
|
| 10 | + * @ingroup Push
|
| 11 | + *
|
| 12 | + * @author ankit
|
| 13 | + */
|
| 14 | + final class PSTabs {
|
| 15 | +
|
| 16 | + /**
|
| 17 | + * Adds an "action" (i.e., a tab) to allow pushing the current article.
|
| 18 | + */
|
| 19 | + public static function displayTab( $obj, &$content_actions ) {
|
| 20 | + global $wgUser;
|
| 21 | +
|
| 22 | + // Make sure that this is not a special page, the page has contents, and the user can push.
|
| 23 | + $title = $obj->getTitle();
|
| 24 | + if (
|
| 25 | + $title->getNamespace() == NS_CATEGORY
|
| 26 | + && $title->exists() ){
|
| 27 | + global $wgRequest;
|
| 28 | +
|
| 29 | + $category = $title->getText();
|
| 30 | + $pageSchemaObj = new PSSchema( $category );
|
| 31 | + if( $pageSchemaObj->isPSDefined() ){
|
| 32 | + $content_actions['editschema'] = array(
|
| 33 | + 'text' => wfMsg( 'editschema' ),
|
| 34 | + 'class' => $wgRequest->getVal( 'action' ) == 'editschema' ? 'selected' : '',
|
| 35 | + 'href' => $title->getLocalURL( 'action=editschema' )
|
| 36 | + );
|
| 37 | + $content_actions['generatepages'] = array(
|
| 38 | + 'text' => wfMsg( 'generatepages' ),
|
| 39 | + 'class' => $wgRequest->getVal( 'action' ) == 'generatepages' ? 'selected' : '',
|
| 40 | + 'href' => $title->getLocalURL( 'action=generatepages' )
|
| 41 | + );
|
| 42 | + }else{
|
| 43 | + $content_actions['editschema'] = array(
|
| 44 | + 'text' => wfMsg( 'createpages' ),
|
| 45 | + 'class' => $wgRequest->getVal( 'action' ) == 'editschema' ? 'selected' : '',
|
| 46 | + 'href' => $title->getLocalURL( 'action=editschema' )
|
| 47 | + );
|
| 48 | + }
|
| 49 | + }
|
| 50 | +
|
| 51 | + return true;
|
| 52 | + }
|
| 53 | +
|
| 54 | + /**
|
| 55 | + * Function currently called only for the 'Vector' skin, added in
|
| 56 | + * MW 1.16 - will possibly be called for additional skins later
|
| 57 | + */
|
| 58 | + public static function displayTab2( $obj, &$links ) {
|
| 59 | + // The old '$content_actions' array is thankfully just a sub-array of this one
|
| 60 | + $views_links = $links['actions'];
|
| 61 | + self::displayTab( $obj, $views_links );
|
| 62 | + $links['actions'] = $views_links;
|
| 63 | + return true;
|
| 64 | + }
|
| 65 | +
|
| 66 | + /**
|
| 67 | + * Handle actions not known to MediaWiki. If the action is push,
|
| 68 | + * display the push page by calling the displayPushPage method.
|
| 69 | + *
|
| 70 | + * @param string $action
|
| 71 | + * @param Article $article
|
| 72 | + *
|
| 73 | + * @return true
|
| 74 | + */
|
| 75 | + public static function onUnknownAction( $action, Article $article ) {
|
| 76 | + $title = $article->getTitle();
|
| 77 | + $category = $title->getText();
|
| 78 | + if ( $action == 'generatepages' ) {
|
| 79 | + $gen_page = new GeneratePages();
|
| 80 | + return $gen_page->execute($category);
|
| 81 | + }
|
| 82 | + else if( $action == 'editschema' ) {
|
| 83 | + $edit_schema = new EditSchema();
|
| 84 | + return $edit_schema->execute($category);
|
| 85 | + }
|
| 86 | + return true;
|
| 87 | + }
|
| 88 | +} |
\ No newline at end of file |
Index: trunk/extensions/PageSchemas/PageSchemas.i18n.php |
— | — | @@ -29,6 +29,9 @@ |
30 | 30 | 'ps-field-list-label' => 'This field can hold a list of values', |
31 | 31 | 'ps-add-xml-label' => 'Additional XML:', |
32 | 32 | 'ps-schema-name-label' => 'Name of schema:', |
| 33 | + 'editschema' => 'Edit schema', |
| 34 | + 'generatepages' => 'Generate pages', |
| 35 | + 'createpages' => 'Create Pages' , |
33 | 36 | |
34 | 37 | ); |
35 | 38 | |
Index: trunk/extensions/PageSchemas/PageSchemas.php |
— | — | @@ -50,6 +50,7 @@ |
51 | 51 | $wgAutoloadClasses['ApiQueryPageSchemas'] = $dir . 'ApiQueryPageSchemas.php'; |
52 | 52 | $wgAutoloadClasses['GeneratePages'] = $dir . 'specials/PS_GeneratePages.php'; |
53 | 53 | $wgAutoloadClasses['EditSchema'] = $dir . 'specials/PS_EditSchema.php'; |
| 54 | +$wgAutoloadClasses['PSTabs'] = $dir . 'PS_Tabs.php'; |
54 | 55 | // registering Special page |
55 | 56 | $wgSpecialPages['GeneratePages'] = 'GeneratePages'; |
56 | 57 | $wgSpecialPages['EditSchema'] = 'EditSchema'; |
— | — | @@ -60,3 +61,7 @@ |
61 | 62 | |
62 | 63 | // Register page_props usage |
63 | 64 | $wgPageProps['PageSchema'] = 'Content of <PageSchema> tag'; |
| 65 | + |
| 66 | +$wgHooks['UnknownAction'][] = 'PSTabs::onUnknownAction'; |
| 67 | +$wgHooks['SkinTemplateTabs'][] = 'PSTabs::displayTab'; |
| 68 | +$wgHooks['SkinTemplateNavigation'][] = 'PSTabs::displayTab2'; |
\ No newline at end of file |