Index: trunk/extensions/RecordAdmin/RecordAdmin_body.php |
— | — | @@ -16,16 +16,97 @@ |
17 | 17 | var $guid = ''; |
18 | 18 | var $quid = ''; |
19 | 19 | var $filter = array(); |
| 20 | + var $acturl = ''; |
| 21 | + var $done = false; |
20 | 22 | |
21 | 23 | function __construct() { |
| 24 | + global $wgHooks, $wgParser, $wgRequest, $wgRecordAdminTag, $wgRecordAdminCategory, |
| 25 | + $wgRecordAdminTag, $wgRecordAdminTableMagic, $wgRecordAdminDataMagic; |
| 26 | + |
22 | 27 | # Name to use for creating a new record either via RecordAdmin or a public form |
23 | 28 | # todo: should add a hook here for custom default-naming |
24 | 29 | $this->guid = strftime( '%Y%m%d', time() ) . '-' . substr( strtoupper( uniqid('', true) ), -5 ); |
25 | 30 | wfLoadExtensionMessages ( 'RecordAdmin' ); |
26 | 31 | SpecialPage::SpecialPage( 'RecordAdmin', 'recordadmin', true, false, 'default', true ); |
| 32 | + |
| 33 | + # Make recordID's of articles created with public forms available via recordid tag |
| 34 | + $wgParser->setHook( $wgRecordAdminTag, array( $this, 'expandTag' ) ); |
| 35 | + |
| 36 | + # Add the parser-functions |
| 37 | + $wgParser->setFunctionHook( $wgRecordAdminTableMagic, array( $this, 'expandTableMagic' ) ); |
| 38 | + $wgParser->setFunctionHook( $wgRecordAdminDataMagic, array( $this, 'expandDataMagic' ) ); |
| 39 | + |
| 40 | + # Check if posting a public creation form |
| 41 | + $title = Title::newFromText( $wgRequest->getText( 'title' ) ); |
| 42 | + if ( is_object( $title ) && $title->getNamespace() != NS_SPECIAL && $wgRequest->getText( 'wpType' ) && $wgRequest->getText( 'wpCreate' ) ) |
| 43 | + $this->createRecord(); |
| 44 | + |
| 45 | + # A minimal hook so we know if the page has been rendered or not |
| 46 | + # (so that record tables don't execute when run from the job-queue - looking for a better way to do this) |
| 47 | + $wgHooks['BeforePageDisplay'][] = $this; |
| 48 | + |
| 49 | + # Add some hooks if the current title is a record |
| 50 | + if ( is_object( $title ) ) { |
| 51 | + $types = array(); |
| 52 | + $id = $title->getArticleID(); |
| 53 | + $dbr = &wfGetDB( DB_SLAVE ); |
| 54 | + $cat = $dbr->addQuotes( $wgRecordAdminCategory ); |
| 55 | + $cl = $dbr->tableName( 'categorylinks' ); |
| 56 | + $tl = $dbr->tableName( 'templatelinks' ); |
| 57 | + $res = $dbr->select( $cl, 'cl_from', "cl_to = $cat" ); |
| 58 | + while ( $row = $dbr->fetchRow( $res ) ) $types[] = 'tl_title = ' . $dbr->addQuotes( Title::newFromID( $row[0] )->getText() ); |
| 59 | + $dbr->freeResult( $res ); |
| 60 | + $uses = join( ' OR ', $types ); |
| 61 | + if ( $uses && $row = $dbr->selectRow( $tl, 'tl_title', "tl_from = $id AND ($uses)" ) ) { |
| 62 | + global $wgRecordAdminEditWithForm, $wgRecordAdminAddTitleInfo; |
| 63 | + $this->type = $row->tl_title; |
| 64 | + |
| 65 | + # Add title info |
| 66 | + if ( $wgRecordAdminAddTitleInfo ) $wgHooks['OutputPageBeforeHTML'][] = $this; |
| 67 | + |
| 68 | + # Add an "edit with form" action link |
| 69 | + if ( $wgRecordAdminEditWithForm ) { |
| 70 | + $wgHooks['SkinTemplateTabs'][] = $this; |
| 71 | + $qs = "wpType={$this->type}&wpRecord=" . $title->getPrefixedText(); |
| 72 | + $this->acturl = Title::makeTitle( NS_SPECIAL, 'RecordAdmin' )->getLocalURL( $qs ); |
| 73 | + } |
| 74 | + } |
| 75 | + } |
27 | 76 | } |
28 | 77 | |
29 | 78 | /** |
| 79 | + * Store the fact that this hook has executed so we don't run record tables from job queue |
| 80 | + */ |
| 81 | + function onBeforePageDisplay( &$out, $skin = false ) { |
| 82 | + return $this->done = true; |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * Add record type info below title |
| 87 | + */ |
| 88 | + function onOutputPageBeforeHTML( &$out, &$text ) { |
| 89 | + $text = '<div class="recordadmin-typeinfo">' . wfMsg( 'recordadmin-typeinfo', $this->type ) . "</div>\n" . $text; |
| 90 | + return true; |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * Add action link |
| 95 | + */ |
| 96 | + function onSkinTemplateTabs( &$skin, &$actions ) { |
| 97 | + $tmp = array(); |
| 98 | + foreach ( $actions as $k => $v ) { |
| 99 | + $tmp[$k] = $v; |
| 100 | + if ( $k == 'edit' ) $tmp['editwithform'] = array( |
| 101 | + 'text' => wfMsg( 'recordadmin-editwithform' ), |
| 102 | + 'class' => false, |
| 103 | + 'href' => $this->acturl |
| 104 | + ); |
| 105 | + } |
| 106 | + $actions = $tmp; |
| 107 | + return true; |
| 108 | + } |
| 109 | + |
| 110 | + /** |
30 | 111 | * Override SpecialPage::execute() |
31 | 112 | */ |
32 | 113 | function execute( $param ) { |
— | — | @@ -244,6 +325,9 @@ |
245 | 326 | function getRecords( $type, $posted, $wpTitle = '', $invert = false, $orderby = 'created desc' ) { |
246 | 327 | global $wgRequest; |
247 | 328 | |
| 329 | + # If the page is already rendered, don't run this query |
| 330 | + if ( $this->done ) return array(); |
| 331 | + |
248 | 332 | # Generate a unique id for this set of parameters |
249 | 333 | $this->quid = md5( var_export( array( $type, $posted ), true ) ); |
250 | 334 | |
Index: trunk/extensions/RecordAdmin/RecordAdmin.php |
— | — | @@ -11,7 +11,7 @@ |
12 | 12 | * @licence GNU General Public Licence 2.0 or later |
13 | 13 | */ |
14 | 14 | |
15 | | -define( 'RECORDADMIN_VERSION', '0.8.11, 2009-11-18' ); |
| 15 | +define( 'RECORDADMIN_VERSION', '0.9.0, 2009-11-19' ); |
16 | 16 | |
17 | 17 | $wgRecordAdminUseNamespaces = false; # Whether record articles should be in a namespace of the same name as their type |
18 | 18 | $wgRecordAdminCategory = 'Records'; # Category containing record types |
— | — | @@ -31,9 +31,6 @@ |
32 | 32 | $wgGroupPermissions['sysop']['recordadmin'] = true; |
33 | 33 | $wgAvailableRights[] = 'recordadmin'; |
34 | 34 | |
35 | | -$wgExtensionFunctions[] = 'wfSetupRecordAdmin'; |
36 | | -$wgHooks['LanguageGetMagic'][] = 'wfRecordAdminLanguageGetMagic'; |
37 | | - |
38 | 35 | $wgExtensionCredits['specialpage'][] = array( |
39 | 36 | 'path' => __FILE__, |
40 | 37 | 'name' => 'Record administration', |
— | — | @@ -44,93 +41,16 @@ |
45 | 42 | 'version' => RECORDADMIN_VERSION, |
46 | 43 | ); |
47 | 44 | |
48 | | -/** |
49 | | - * Called from $wgExtensionFunctions array when initialising extensions |
50 | | - */ |
51 | | -function wfSetupRecordAdmin() { |
52 | | - global $wgSpecialRecordAdmin, $wgTitle, $wgParser, $wgHooks, $wgRequest, $wgRecordAdminCategory, |
53 | | - $wgRecordAdminTag, $wgRecordAdminTableMagic, $wgRecordAdminDataMagic, $wgRecordAdminEditWithForm; |
54 | | - |
55 | | - # Make a global singleton so methods are accessible as callbacks etc |
| 45 | +$wgExtensionFunctions[] = 'efSetupRecordAdmin'; |
| 46 | +function efSetupRecordAdmin() { |
| 47 | + global $wgSpecialRecordAdmin; |
56 | 48 | $wgSpecialRecordAdmin = new SpecialRecordAdmin(); |
57 | | - |
58 | | - # Make recordID's of articles created with public forms available via recordid tag |
59 | | - $wgParser->setHook( $wgRecordAdminTag, array( $wgSpecialRecordAdmin, 'expandTag' ) ); |
60 | | - |
61 | | - # Add the parser-functions |
62 | | - $wgParser->setFunctionHook( $wgRecordAdminTableMagic, array( $wgSpecialRecordAdmin, 'expandTableMagic' ) ); |
63 | | - $wgParser->setFunctionHook( $wgRecordAdminDataMagic, array( $wgSpecialRecordAdmin, 'expandDataMagic' ) ); |
64 | | - |
65 | | - # Check if posting a public creation form |
66 | | - $title = Title::newFromText( $wgRequest->getText( 'title' ) ); |
67 | | - if ( is_object( $title ) && $title->getNamespace() != NS_SPECIAL && $wgRequest->getText( 'wpType' ) && $wgRequest->getText( 'wpCreate' ) ) |
68 | | - $wgSpecialRecordAdmin->createRecord(); |
69 | | - |
70 | | - # Add some hooks if the current title is a record |
71 | | - if ( is_object( $title ) ) { |
72 | | - $types = array(); |
73 | | - $id = $title->getArticleID(); |
74 | | - $dbr = &wfGetDB(DB_SLAVE); |
75 | | - $cat = $dbr->addQuotes( $wgRecordAdminCategory ); |
76 | | - $cl = $dbr->tableName( 'categorylinks' ); |
77 | | - $tl = $dbr->tableName( 'templatelinks' ); |
78 | | - $res = $dbr->select( $cl, 'cl_from', "cl_to = $cat" ); |
79 | | - while ( $row = $dbr->fetchRow( $res ) ) $types[] = 'tl_title = ' . $dbr->addQuotes( Title::newFromID( $row[0] )->getText() ); |
80 | | - $dbr->freeResult( $res ); |
81 | | - $uses = join( ' OR ', $types ); |
82 | | - if ( $uses && $row = $dbr->selectRow( $tl, 'tl_title', "tl_from = $id AND ($uses)" ) ) { |
83 | | - global $wgRecordAdminEditWithForm, $wgRecordAdminActionUrl, $wgRecordAdminCurrentType, $wgRecordAdminAddTitleInfo; |
84 | | - $wgRecordAdminCurrentType = $row->tl_title; |
85 | | - |
86 | | - # Add title info |
87 | | - if ( $wgRecordAdminAddTitleInfo ) { |
88 | | - $wgHooks['OutputPageBeforeHTML'][] = 'wfRecordAdminAddTypeInfo'; |
89 | | - } |
90 | | - |
91 | | - # Add an "edit with form" action link |
92 | | - if ( $wgRecordAdminEditWithForm ) { |
93 | | - $wgHooks['SkinTemplateTabs'][] = 'wfRecordAdminEditWithForm'; |
94 | | - $qs = "wpType=$wgRecordAdminCurrentType&wpRecord=" . $title->getPrefixedText(); |
95 | | - $wgRecordAdminActionUrl = Title::makeTitle( NS_SPECIAL, 'RecordAdmin' )->getLocalURL( $qs ); |
96 | | - } |
97 | | - } |
98 | | - } |
99 | | - |
100 | 49 | } |
101 | 50 | |
102 | | -/** |
103 | | - * Setup parser-function magic |
104 | | - */ |
105 | | -function wfRecordAdminLanguageGetMagic( &$magicWords, $langCode = 0 ) { |
| 51 | +$wgHooks['LanguageGetMagic'][] = 'efRecordAdminLanguageGetMagic'; |
| 52 | +function efRecordAdminLanguageGetMagic( &$magicWords, $langCode = 0 ) { |
106 | 53 | global $wgRecordAdminTableMagic, $wgRecordAdminDataMagic; |
107 | 54 | $magicWords[$wgRecordAdminTableMagic] = array( $langCode, $wgRecordAdminTableMagic ); |
108 | 55 | $magicWords[$wgRecordAdminDataMagic] = array( $langCode, $wgRecordAdminDataMagic ); |
109 | 56 | return true; |
110 | 57 | } |
111 | | - |
112 | | -/** |
113 | | - * Add action link |
114 | | - */ |
115 | | -function wfRecordAdminEditWithForm( &$skin, &$actions ) { |
116 | | - global $wgRecordAdminActionUrl; |
117 | | - $tmp = array(); |
118 | | - foreach ( $actions as $k => $v ) { |
119 | | - $tmp[$k] = $v; |
120 | | - if ( $k == 'edit' ) $tmp['editwithform'] = array( |
121 | | - 'text' => wfMsg( 'recordadmin-editwithform' ), |
122 | | - 'class' => false, |
123 | | - 'href' => $wgRecordAdminActionUrl |
124 | | - ); |
125 | | - } |
126 | | - $actions = $tmp; |
127 | | - return true; |
128 | | -} |
129 | | - |
130 | | -/** |
131 | | - * Add record type info below title |
132 | | - */ |
133 | | -function wfRecordAdminAddTypeInfo( &$out, &$text ) { |
134 | | - global $wgRecordAdminCurrentType; |
135 | | - $text = '<div class="recordadmin-typeinfo">' . wfMsg( 'recordadmin-typeinfo', $wgRecordAdminCurrentType ) . "</div>\n" . $text; |
136 | | - return true; |
137 | | -} |