r94759 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94758‎ | r94759 | r94760 >
Date:14:03, 17 August 2011
Author:ankitgarg833
Status:deferred
Tags:
Comment:
Adding tabs to Page Schemas
Edit schema:

- the action should be "action=editschema".
- it should be a dropdown link for the Vector skin, and a tab for other skins.
- it should appear for all category pages, but not for any other kind of pages.
- it should appear as "Create schema" if no schema exists, and as "Edit schema" if a schema already exists.
- what is displayed on the page should exactly match what's in "Special:EditSchema/category-name".

Generate pages:

- the action should be "action=generatepages".
- it should be a dropdown link for the Vector skin, and a tab for other skins.
- it should appear only for category pages.
- it should appear only if a schema exists.
- what is displayed on the page should exactly match what's in "Special:GeneratePages/category-name".
Modified paths:
  • /trunk/extensions/PageSchemas/PS_Tabs.php (added) (history)
  • /trunk/extensions/PageSchemas/PageSchemas.i18n.php (modified) (history)
  • /trunk/extensions/PageSchemas/PageSchemas.php (modified) (history)

Diff [purge]

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 @@
3030 'ps-field-list-label' => 'This field can hold a list of values',
3131 'ps-add-xml-label' => 'Additional XML:',
3232 'ps-schema-name-label' => 'Name of schema:',
 33+ 'editschema' => 'Edit schema',
 34+ 'generatepages' => 'Generate pages',
 35+ 'createpages' => 'Create Pages' ,
3336
3437 );
3538
Index: trunk/extensions/PageSchemas/PageSchemas.php
@@ -50,6 +50,7 @@
5151 $wgAutoloadClasses['ApiQueryPageSchemas'] = $dir . 'ApiQueryPageSchemas.php';
5252 $wgAutoloadClasses['GeneratePages'] = $dir . 'specials/PS_GeneratePages.php';
5353 $wgAutoloadClasses['EditSchema'] = $dir . 'specials/PS_EditSchema.php';
 54+$wgAutoloadClasses['PSTabs'] = $dir . 'PS_Tabs.php';
5455 // registering Special page
5556 $wgSpecialPages['GeneratePages'] = 'GeneratePages';
5657 $wgSpecialPages['EditSchema'] = 'EditSchema';
@@ -60,3 +61,7 @@
6162
6263 // Register page_props usage
6364 $wgPageProps['PageSchema'] = 'Content of &lt;PageSchema&gt; tag';
 65+
 66+$wgHooks['UnknownAction'][] = 'PSTabs::onUnknownAction';
 67+$wgHooks['SkinTemplateTabs'][] = 'PSTabs::displayTab';
 68+$wgHooks['SkinTemplateNavigation'][] = 'PSTabs::displayTab2';
\ No newline at end of file

Status & tagging log