r37325 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r37324‎ | r37325 | r37326 >
Date:17:40, 8 July 2008
Author:yaron
Status:old
Tags:
Comment:
All special pages modified to use standard constructor and handling for
special pages, as of MediaWiki 1.11
Modified paths:
  • /trunk/extensions/SemanticForms/specials/SF_AddData.php (modified) (history)
  • /trunk/extensions/SemanticForms/specials/SF_AddPage.php (modified) (history)
  • /trunk/extensions/SemanticForms/specials/SF_CreateCategory.php (modified) (history)
  • /trunk/extensions/SemanticForms/specials/SF_CreateForm.php (modified) (history)
  • /trunk/extensions/SemanticForms/specials/SF_CreateProperty.php (modified) (history)
  • /trunk/extensions/SemanticForms/specials/SF_CreateTemplate.php (modified) (history)
  • /trunk/extensions/SemanticForms/specials/SF_EditData.php (modified) (history)
  • /trunk/extensions/SemanticForms/specials/SF_Forms.php (modified) (history)
  • /trunk/extensions/SemanticForms/specials/SF_Templates.php (modified) (history)
  • /trunk/extensions/SemanticForms/specials/SF_UploadWindow.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/specials/SF_CreateCategory.php
@@ -8,11 +8,22 @@
99
1010 if (!defined('MEDIAWIKI')) die();
1111
12 -global $IP;
13 -require_once( "$IP/includes/SpecialPage.php" );
 12+class SFCreateCategory extends SpecialPage {
1413
15 -SpecialPage::addPage( new SpecialPage('CreateCategory','',true,'doSpecialCreateCategory',false) );
 14+ /**
 15+ * Constructor
 16+ */
 17+ function SFCreateCategory() {
 18+ SpecialPage::SpecialPage('CreateCategory');
 19+ wfLoadExtensionMessages('SemanticForms');
 20+ }
1621
 22+ function execute() {
 23+ $this->setHeaders();
 24+ doSpecialCreateCategory();
 25+ }
 26+}
 27+
1728 function createCategoryText($default_form, $category_name, $parent_category) {
1829 global $sfgContLang;
1930
Index: trunk/extensions/SemanticForms/specials/SF_AddData.php
@@ -6,30 +6,34 @@
77 */
88 if (!defined('MEDIAWIKI')) die();
99
10 -global $sfgIP;
11 -require_once( $sfgIP . "/includes/SF_FormPrinter.inc" );
 10+class SFAddData extends SpecialPage {
1211
13 -global $IP;
14 -require_once( "$IP/includes/SpecialPage.php" );
 12+ /**
 13+ * Constructor
 14+ */
 15+ function SFAddData() {
 16+ SpecialPage::SpecialPage('AddData');
 17+ wfLoadExtensionMessages('SemanticForms');
 18+ }
1519
16 -SpecialPage::addPage( new SpecialPage('AddData','',true,'doSpecialAddData',false) );
 20+ function execute($query = '') {
 21+ global $wgRequest;
1722
18 -function doSpecialAddData($query = '') {
19 - global $wgRequest;
 23+ $this->setHeaders();
 24+ $form_name = $wgRequest->getVal('form');
 25+ $target_name = $wgRequest->getVal('target');
2026
21 - $form_name = $wgRequest->getVal('form');
22 - $target_name = $wgRequest->getVal('target');
 27+ // if query string did not contain these variables, try the URL
 28+ if (! $form_name && ! $target_name) {
 29+ $queryparts = explode('/', $query, 2);
 30+ $form_name = isset($queryparts[0]) ? $queryparts[0] : '';
 31+ $target_name = isset($queryparts[1]) ? $queryparts[1] : '';
 32+ }
2333
24 - // if query string did not contain these variables, try the URL
25 - if (! $form_name && ! $target_name) {
26 - $queryparts = explode('/', $query, 2);
27 - $form_name = isset($queryparts[0]) ? $queryparts[0] : '';
28 - $target_name = isset($queryparts[1]) ? $queryparts[1] : '';
 34+ $alt_forms = $wgRequest->getArray('alt_form');
 35+
 36+ printAddForm($form_name, $target_name, $alt_forms);
2937 }
30 -
31 - $alt_forms = $wgRequest->getArray('alt_form');
32 -
33 - printAddForm($form_name, $target_name, $alt_forms);
3438 }
3539
3640 function printAltFormsList($alt_forms, $target_name) {
Index: trunk/extensions/SemanticForms/specials/SF_AddPage.php
@@ -9,11 +9,22 @@
1010 */
1111 if (!defined('MEDIAWIKI')) die();
1212
13 -global $IP;
14 -require_once( "$IP/includes/SpecialPage.php" );
 13+class SFAddPage extends SpecialPage {
1514
16 -SpecialPage::addPage( new SpecialPage('AddPage','',true,'doSpecialAddPage',false) );
 15+ /**
 16+ * Constructor
 17+ */
 18+ function SFAddPage() {
 19+ SpecialPage::SpecialPage('AddPage');
 20+ wfLoadExtensionMessages('SemanticForms');
 21+ }
1722
 23+ function execute($query = '') {
 24+ $this->setHeaders();
 25+ doSpecialAddPage($query);
 26+ }
 27+}
 28+
1829 function doSpecialAddPage($query = '') {
1930 global $wgOut, $wgRequest, $sfgScriptPath;
2031
Index: trunk/extensions/SemanticForms/specials/SF_Forms.php
@@ -7,11 +7,24 @@
88
99 if (!defined('MEDIAWIKI')) die();
1010
11 -global $IP;
12 -require_once( "$IP/includes/SpecialPage.php" );
 11+class SFForms extends SpecialPage {
1312
14 -SpecialPage::addPage( new SpecialPage('Forms','',true,'doSpecialForms',false) );
 13+ /**
 14+ * Constructor
 15+ */
 16+ function SFForms() {
 17+ SpecialPage::SpecialPage('Forms');
 18+ wfLoadExtensionMessages('SemanticForms');
 19+ }
1520
 21+ function execute() {
 22+ $this->setHeaders();
 23+ list( $limit, $offset ) = wfCheckLimits();
 24+ $rep = new FormsPage();
 25+ return $rep->doQuery( $offset, $limit );
 26+ }
 27+}
 28+
1629 class FormsPage extends QueryPage {
1730 function getName() {
1831 return "Forms";
@@ -57,9 +70,3 @@
5871 return $skin->makeLinkObj( $title, $title->getText() );
5972 }
6073 }
61 -
62 -function doSpecialForms() {
63 - list( $limit, $offset ) = wfCheckLimits();
64 - $rep = new FormsPage();
65 - return $rep->doQuery( $offset, $limit );
66 -}
Index: trunk/extensions/SemanticForms/specials/SF_CreateForm.php
@@ -8,12 +8,22 @@
99
1010 if (!defined('MEDIAWIKI')) die();
1111
12 -global $IP, $sfgIP;
13 -require_once( "$IP/includes/SpecialPage.php" );
14 -require_once( "$sfgIP/includes/SF_FormClasses.inc" );
 12+class SFCreateForm extends SpecialPage {
1513
16 -SpecialPage::addPage( new SpecialPage('CreateForm','',true,'doSpecialCreateForm',false) );
 14+ /**
 15+ * Constructor
 16+ */
 17+ function SFCreateForm() {
 18+ SpecialPage::SpecialPage('CreateForm');
 19+ wfLoadExtensionMessages('SemanticForms');
 20+ }
1721
 22+ function execute() {
 23+ $this->setHeaders();
 24+ doSpecialCreateForm();
 25+ }
 26+}
 27+
1828 function doSpecialCreateForm() {
1929 global $wgOut, $wgRequest, $wgUser, $sfgScriptPath, $wgContLang;
2030 $db = wfGetDB( DB_SLAVE );
Index: trunk/extensions/SemanticForms/specials/SF_CreateProperty.php
@@ -6,20 +6,24 @@
77 * @author Yaron Koren
88 */
99
10 -/**
11 - * Protect against register_globals vulnerabilities.
12 - * This line must be present before any global variable is referenced.
13 - */
1410 if (!defined('MEDIAWIKI')) die();
1511
16 -include_once $sfgIP . "/includes/SF_TemplateField.inc";
 12+class SFCreateProperty extends SpecialPage {
1713
 14+ /**
 15+ * Constructor
 16+ */
 17+ function SFCreateProperty() {
 18+ SpecialPage::SpecialPage('CreateProperty');
 19+ wfLoadExtensionMessages('SemanticForms');
 20+ }
1821
19 -global $IP;
20 -require_once( "$IP/includes/SpecialPage.php" );
 22+ function execute() {
 23+ $this->setHeaders();
 24+ doSpecialCreateProperty();
 25+ }
 26+}
2127
22 -SpecialPage::addPage( new SpecialPage('CreateProperty','',true,'doSpecialCreateProperty',false) );
23 -
2428 function createPropertyText($property_type, $allowed_values_str) {
2529 global $smwgContLang;
2630
@@ -81,7 +85,7 @@
8286 }
8387 }
8488
85 - $all_properties = getSemanticProperties();
 89+ $all_properties = sffGetAllProperties();
8690 $datatype_labels = $smwgContLang->getDatatypeLabels();
8791
8892 $javascript_text =<<<END
Index: trunk/extensions/SemanticForms/specials/SF_UploadWindow.php
@@ -14,11 +14,22 @@
1515 */
1616 if (!defined('MEDIAWIKI')) die();
1717
18 -global $IP;
19 -require_once( "$IP/includes/SpecialPage.php" );
 18+class SFUploadWindow extends SpecialPage {
2019
21 -SpecialPage::addPage( new SpecialPage('UploadWindow','',true,'doSpecialUploadWindow',false) );
 20+ /**
 21+ * Constructor
 22+ */
 23+ function SFUploadWindow() {
 24+ SpecialPage::SpecialPage('UploadWindow');
 25+ wfLoadExtensionMessages('SemanticForms');
 26+ }
2227
 28+ function execute() {
 29+ $this->setHeaders();
 30+ doSpecialUploadWindow();
 31+ }
 32+}
 33+
2334 /**
2435 * Entry point
2536 */
Index: trunk/extensions/SemanticForms/specials/SF_Templates.php
@@ -7,11 +7,24 @@
88
99 if (!defined('MEDIAWIKI')) die();
1010
11 -global $IP;
12 -require_once( "$IP/includes/SpecialPage.php" );
 11+class SFTemplates extends SpecialPage {
1312
14 -SpecialPage::addPage( new SpecialPage('Templates','',true,'doSpecialTemplates',false) );
 13+ /**
 14+ * Constructor
 15+ */
 16+ function SFTemplates() {
 17+ SpecialPage::SpecialPage('Templates');
 18+ wfLoadExtensionMessages('SemanticForms');
 19+ }
1520
 21+ function execute() {
 22+ $this->setHeaders();
 23+ list( $limit, $offset ) = wfCheckLimits();
 24+ $rep = new TemplatesPage();
 25+ return $rep->doQuery( $offset, $limit );
 26+ }
 27+}
 28+
1629 class TemplatesPage extends QueryPage {
1730 function getName() {
1831 return "Templates";
@@ -72,9 +85,3 @@
7386 return $text;
7487 }
7588 }
76 -
77 -function doSpecialTemplates() {
78 - list( $limit, $offset ) = wfCheckLimits();
79 - $rep = new TemplatesPage();
80 - return $rep->doQuery( $offset, $limit );
81 -}
Index: trunk/extensions/SemanticForms/specials/SF_CreateTemplate.php
@@ -12,49 +12,20 @@
1313 */
1414 if (!defined('MEDIAWIKI')) die();
1515
16 -include_once $sfgIP . "/includes/SF_TemplateField.inc";
 16+class SFCreateTemplate extends SpecialPage {
1717
18 -
19 -global $IP;
20 -require_once( "$IP/includes/SpecialPage.php" );
21 -
22 -SpecialPage::addPage( new SpecialPage('CreateTemplate','',true,'doSpecialCreateTemplate',false) );
23 -
24 -// Custom sort function, used in getSemanticProperties()
25 -function cmp($a, $b) {
26 - if ($a == $b) {
27 - return 0;
28 - } elseif ($a < $b) {
29 - return -1;
30 - } else {
31 - return 1;
 18+ /**
 19+ * Constructor
 20+ */
 21+ function SFCreateTemplate() {
 22+ SpecialPage::SpecialPage('CreateTemplate');
 23+ wfLoadExtensionMessages('SemanticForms');
3224 }
33 -}
3425
35 -function getSemanticProperties() {
36 - $all_properties = array();
37 -
38 - // set limit on results - a temporary fix until SMW's getProperties()
39 - // functions stop requiring a limit
40 - global $smwgIP;
41 - include_once($smwgIP . '/includes/storage/SMW_Store.php');
42 - $options = new SMWRequestOptions();
43 - $options->limit = 10000;
44 - $used_properties = smwfGetStore()->getPropertiesSpecial($options);
45 - foreach ($used_properties as $property) {
46 - $property_name = $property[0]->getText();
47 - $all_properties[$property_name . "::"] = $property_name;
 26+ function execute() {
 27+ $this->setHeaders();
 28+ doSpecialCreateTemplate();
4829 }
49 - $unused_properties = smwfGetStore()->getUnusedPropertiesSpecial($options);
50 - foreach ($unused_properties as $property) {
51 - $property_name = $property->getText();
52 - $all_properties[$property_name . "::"] = $property_name;
53 - }
54 -
55 - // sort properties list alphabetically - custom sort function is needed
56 - // because the regular sort function destroys the "keys" of the array
57 - uasort($all_properties, "cmp");
58 - return $all_properties;
5930 }
6031
6132 function printPropertiesDropdown($all_properties, $id, $property) {
@@ -91,7 +62,7 @@
9263 function doSpecialCreateTemplate() {
9364 global $wgOut, $wgRequest, $wgUser, $sfgScriptPath, $wgContLang;
9465
95 - $all_properties = getSemanticProperties();
 66+ $all_properties = sffGetAllProperties();
9667
9768 $template_name = $wgRequest->getVal('template_name');
9869 $template_name_error_str = "";
Index: trunk/extensions/SemanticForms/specials/SF_EditData.php
@@ -11,14 +11,22 @@
1212 */
1313 if (!defined('MEDIAWIKI')) die();
1414
15 -require_once( $sfgIP . "/includes/SF_FormPrinter.inc" );
 15+class SFEditData extends SpecialPage {
1616
 17+ /**
 18+ * Constructor
 19+ */
 20+ function SFEditData() {
 21+ SpecialPage::SpecialPage('EditData');
 22+ wfLoadExtensionMessages('SemanticForms');
 23+ }
1724
18 -global $IP;
19 -require_once( "$IP/includes/SpecialPage.php" );
 25+ function execute($query = '') {
 26+ $this->setHeaders();
 27+ doSpecialEditData($query);
 28+ }
 29+}
2030
21 -SpecialPage::addPage( new SpecialPage('EditData','',true,'doSpecialEditData',false) );
22 -
2331 function doSpecialEditData($query = '') {
2432 global $wgRequest;
2533
@@ -35,36 +43,6 @@
3644 printEditForm($form_name, $target_name);
3745 }
3846
39 -global $wgHooks;
40 -$wgHooks[ 'UnknownAction' ][] = 'sffEmbeddedEditForm';
41 -
42 -/**
43 - * The function called if we're in index.php (as opposed to one of the special
44 - * pages)
45 - */
46 -function sffEmbeddedEditForm($action, $article) {
47 - // for some reason, the code calling the 'UnknownAction' hook wants
48 - // "true" if the hook failed, and "false" otherwise... this is
49 - // probably a bug, but we'll just work with it
50 - if ($action != 'formedit') {
51 - return true;
52 - }
53 -
54 - $form_name = sffGetFormForArticle($article);
55 - if ($form_name == '') {
56 - return true;
57 - }
58 -
59 - $target_title = $article->getTitle();
60 - $target_name = sffTitleString($target_title);
61 - if ($target_title->exists()) {
62 - printEditForm($form_name, $target_name);
63 - } else {
64 - printAddForm($form_name, $target_name, array());
65 - }
66 - return false;
67 -}
68 -
6947 function printEditForm($form_name, $target_name) {
7048 global $wgOut, $wgRequest, $sfgScriptPath, $sfgFormPrinter, $sfgYUIBase;
7149

Status & tagging log