Index: trunk/extensions/SemanticForms/SemanticForms.php |
— | — | @@ -87,7 +87,8 @@ |
88 | 88 | $wgHooks['SkinTemplateNavigation'][] = 'SFFormEditTab::displayTab2'; |
89 | 89 | $wgHooks['smwInitProperties'][] = 'SFUtils::initProperties'; |
90 | 90 | $wgHooks['AdminLinks'][] = 'SFUtils::addToAdminLinks'; |
91 | | -$wgHooks['ParserBeforeStrip'][] = 'SFUtils::cacheFormDefinition'; |
| 91 | +$wgHooks['ArticlePurge'][] = 'SFFormUtils::purgeCache'; |
| 92 | +$wgHooks['ArticleSave'][] = 'SFFormUtils::purgeCache'; |
92 | 93 | $wgHooks['ParserFirstCallInit'][] = 'SFParserFunctions::registerFunctions'; |
93 | 94 | $wgHooks['MakeGlobalVariablesScript'][] = 'SFFormUtils::setGlobalJSVariables'; |
94 | 95 | $wgHooks['PageSchemasRegisterHandlers'][] = 'SFPageSchemas::registerClass'; |
Index: trunk/extensions/SemanticForms/includes/SF_Utils.php |
— | — | @@ -694,35 +694,6 @@ |
695 | 695 | } |
696 | 696 | |
697 | 697 | /** |
698 | | - * Parse the form definition and store the resulting HTML in the |
699 | | - * page_props table, if caching has been specified in LocalSettings.php |
700 | | - */ |
701 | | - public static function cacheFormDefinition( $parser, $text ) { |
702 | | - global $sfgCacheFormDefinitions; |
703 | | - if ( ! $sfgCacheFormDefinitions ) |
704 | | - return true; |
705 | | - |
706 | | - $title = $parser->getTitle(); |
707 | | - if ( empty( $title ) ) return true; |
708 | | - if ( $title->getNamespace() != SF_NS_FORM ) return true; |
709 | | - // Remove <noinclude> sections and <includeonly> tags from form definition |
710 | | - $form_def = StringUtils::delimiterReplace( '<noinclude>', '</noinclude>', '', $text ); |
711 | | - $form_def = strtr( $form_def, array( '<includeonly>' => '', '</includeonly>' => '' ) ); |
712 | | - |
713 | | - // parse wiki-text |
714 | | - // add '<nowiki>' tags around every triple-bracketed form |
715 | | - // definition element, so that the wiki parser won't touch |
716 | | - // it - the parser will remove the '<nowiki>' tags, leaving |
717 | | - // us with what we need |
718 | | - $form_def = "__NOEDITSECTION__" . strtr( $form_def, array( '{{{' => '<nowiki>{{{', '}}}' => '}}}</nowiki>' ) ); |
719 | | - $dummy_title = Title::newFromText( 'Form definition title for caching purposes' ); |
720 | | - $form_def = $parser->parse( $form_def, $dummy_title, $parser->mOptions )->getText(); |
721 | | - |
722 | | - $parser->mOutput->setProperty( 'formdefinition', $form_def ); |
723 | | - return true; |
724 | | - } |
725 | | - |
726 | | - /** |
727 | 698 | * Loads messages only for MediaWiki versions that need it (< 1.16) |
728 | 699 | */ |
729 | 700 | public static function loadMessages() { |
Index: trunk/extensions/SemanticForms/includes/SF_FormPrinter.php |
— | — | @@ -321,7 +321,7 @@ |
322 | 322 | global $sfgFieldNum; // used for setting various HTML IDs |
323 | 323 | |
324 | 324 | wfProfileIn( __METHOD__ ); |
325 | | - |
| 325 | + |
326 | 326 | // initialize some variables |
327 | 327 | $sfgTabIndex = 1; |
328 | 328 | $sfgFieldNum = 1; |
— | — | @@ -408,37 +408,15 @@ |
409 | 409 | $wgOut->addHTML( "\n<hr />\n" ); |
410 | 410 | } |
411 | 411 | |
412 | | - // Remove <noinclude> sections and <includeonly> tags from form definition. |
413 | | - $form_def = StringUtils::delimiterReplace( '<noinclude>', '</noinclude>', '', $form_def ); |
414 | | - $form_def = strtr( $form_def, array( '<includeonly>' => '', '</includeonly>' => '' ) ); |
415 | | - |
416 | | - // Parse wiki-text. |
417 | | - // Add '<nowiki>' tags around every triple-bracketed form definition |
418 | | - // element, so that the wiki parser won't touch it - the parser will |
419 | | - // remove the '<nowiki>' tags, leaving us with what we need. |
420 | | - $form_def = "__NOEDITSECTION__" . strtr( $form_def, array( '{{{' => '<nowiki>{{{', '}}}' => '}}}</nowiki>' ) ); |
421 | | - |
422 | 412 | $oldParser = $wgParser; |
423 | 413 | |
424 | 414 | $wgParser = unserialize( serialize( $oldParser ) ); // deep clone of parser |
| 415 | + $wgParser->Options( ParserOptions::newFromUser( $wgUser ) ); |
| 416 | + $wgParser->Title( $this->mPageTitle ); |
| 417 | + $wgParser->clearState(); |
425 | 418 | |
426 | | - // Get the form definition from the cache, if we're using caching and it's |
427 | | - // there. |
428 | | -// $got_form_def_from_cache = false; |
429 | | -// global $sfgCacheFormDefinitions; |
430 | | -// if ( $sfgCacheFormDefinitions && ! is_null( $form_id ) ) { |
431 | | -// $db = wfGetDB( DB_MASTER ); |
432 | | -// $res = $db->select( 'page_props', 'pp_value', "pp_propname = 'formdefinition' AND pp_page = '$form_id'" ); |
433 | | -// if ( $res->numRows() > 0 ) { |
434 | | -// $form_def = $res->fetchObject()->pp_value; |
435 | | -// $got_form_def_from_cache = true; |
436 | | -// } |
437 | | -// } |
438 | | - // Otherwise, parse it. |
439 | | -// if ( ! $got_form_def_from_cache ) { |
440 | | - $form_def = $wgParser->parse($form_def, $this->mPageTitle, ParserOptions::newFromUser($wgUser))->getText(); |
441 | | -// } |
442 | | - |
| 419 | + $form_def = SFFormUtils::getFormDefinition( $wgParser, $form_def, $form_id ); |
| 420 | + |
443 | 421 | // Turn form definition file into an array of sections, one for each |
444 | 422 | // template definition (plus the first section) |
445 | 423 | $form_def_sections = array(); |
Index: trunk/extensions/SemanticForms/includes/SF_FormUtils.php |
— | — | @@ -833,4 +833,99 @@ |
834 | 834 | END; |
835 | 835 | return $javascript_text; |
836 | 836 | } |
| 837 | + |
| 838 | + |
| 839 | + /** |
| 840 | + * Parse the form definition and store the resulting HTML in the |
| 841 | + * main cache, if caching has been specified in LocalSettings.php |
| 842 | + */ |
| 843 | + public static function getFormDefinition( $parser, $form_def = null, $form_id = null ) { |
| 844 | + |
| 845 | + global $sfgCacheFormDefinitions, $wgRequest; |
| 846 | + |
| 847 | + $cachekey = null; |
| 848 | + |
| 849 | + // use cache if allowed |
| 850 | + if ( $sfgCacheFormDefinitions && $form_id !== null ) { |
| 851 | + |
| 852 | + $cachekey = wfMemcKey('ext.SemanticForms.formdefinition', $form_id); |
| 853 | + $cached_def = wfGetMainCache()->get( $cachekey ); |
| 854 | + |
| 855 | + // Cache hit? |
| 856 | + if ( $cached_def !== false && $cached_def !== null ) { |
| 857 | + |
| 858 | + wfDebug( "Cache hit: Got formdefinition $cachekey from cache\n" ); |
| 859 | + return $cached_def; |
| 860 | + } else { |
| 861 | + wfDebug( "Cache miss: Formdefinition $cachekey not found in cache\n" ); |
| 862 | + } |
| 863 | + |
| 864 | + } |
| 865 | + |
| 866 | + if ( $form_id !== null ) { |
| 867 | + |
| 868 | + $form_article = Article::newFromID( $form_id ); |
| 869 | + $form_def = $form_article->getContent(); |
| 870 | + |
| 871 | + } else if ( $form_def == null ) { |
| 872 | + |
| 873 | + // No id, no text -> nothing to do |
| 874 | + return ''; |
| 875 | + |
| 876 | + } |
| 877 | + |
| 878 | + // Remove <noinclude> sections and <includeonly> tags from form definition |
| 879 | + $form_def = StringUtils::delimiterReplace( '<noinclude>', '</noinclude>', '', $form_def ); |
| 880 | + $form_def = strtr( $form_def, array( '<includeonly>' => '', '</includeonly>' => '' ) ); |
| 881 | + |
| 882 | + // add '<nowiki>' tags around every triple-bracketed form |
| 883 | + // definition element, so that the wiki parser won't touch |
| 884 | + // it - the parser will remove the '<nowiki>' tags, leaving |
| 885 | + // us with what we need |
| 886 | + $form_def = "__NOEDITSECTION__" . strtr( $form_def, array( '{{{' => '<nowiki>{{{', '}}}' => '}}}</nowiki>' ) ); |
| 887 | + |
| 888 | + $title = new Title(); |
| 889 | + $tmpParser = unserialize( serialize( $parser ) ); // deep clone of parser |
| 890 | + |
| 891 | + // parse wiki-text |
| 892 | + $output = $tmpParser->parse( $form_def, $title, $tmpParser->getOptions() ); |
| 893 | + $form_def = $output->getText(); |
| 894 | + |
| 895 | + // store in cache if allowed |
| 896 | + if ( $sfgCacheFormDefinitions && $form_id !== null ) { |
| 897 | + |
| 898 | + if ( $output->getCacheTime() == -1 ) { |
| 899 | + wfDebug( "Caching disabled for formdefinition $cachekey\n" ); |
| 900 | + self::purgeCache( $form_article ); |
| 901 | + } else { |
| 902 | + wfGetMainCache()->add( $cachekey, $form_def ); |
| 903 | + wfDebug( "Cached formdefinition $cachekey\n" ); |
| 904 | + } |
| 905 | + |
| 906 | + } |
| 907 | + |
| 908 | + return $form_def; |
| 909 | + } |
| 910 | + |
| 911 | + /** |
| 912 | + * Deletes the formdefinition associated with the given wikipage from the |
| 913 | + * main cache. |
| 914 | + * |
| 915 | + * @param Page $wikipage |
| 916 | + * @return Bool |
| 917 | + */ |
| 918 | + public static function purgeCache ( &$wikipage ) { |
| 919 | + |
| 920 | + if ( $wikipage->getTitle()->getNamespace() == SF_NS_FORM ) { |
| 921 | + |
| 922 | + $id = $wikipage->getId(); |
| 923 | + $key = wfMemcKey('ext.SemanticForms.formdefinition', $id); |
| 924 | + |
| 925 | + if ( wfGetMainCache()->delete($key) ) { |
| 926 | + wfDebug( "Deleted cached formdefinition $key.\n" ); |
| 927 | + } |
| 928 | + } |
| 929 | + |
| 930 | + return true; |
| 931 | + } |
837 | 932 | } |