I'm about to remove obsolete ArticleSave-hook an replace it with PageContentSave, but got two problems:
- I find no way to get a ParserOutput() of the Page before it is saved, so I eed to parse the content right here.
- After the article is saved, the page_props-table is not updated. I thought setProperty would do the job, but that does not work. So I had to write the info by hand.
$wgHooks['PageContentSave'][] = 'privateppPageContentSave'; ... function privateppPageContentSave( $wikiPage, $user, $content, $summary, $isMinor, $isWatch, $section, $flags, $status) { # prevent users from saving a page with access restrictions that # would lock them out of the page. $article=Article::newFromId($wikiPage->getId()); $text = $content->getNativeData(); #XXX: calling prepareTextForEdit() causes the text to be parsed, because it is not parsed # yet: groups is empty # $parserOutput=$article->getParserOutput(); # $groups = $parserOutput->getProperty('ppp_allowed_groups'); $editInfo = $article->prepareTextForEdit( $text, null, $user ); $groups = $editInfo->output->getProperty('ppp_allowed_groups'); $err = privateppGetAccessError( $groups, $user ); if ( $err ) { $status->fatal('privatepp-lockout-prevented',$groups,0); return false; } #XXX does not store the groups into page_props # $editInfo->output->setProperty('ppp_allowed_groups', $groups); /* set */ $row = [ 'pp_value' => $groups ]; /* where */ $conditions = [ 'pp_page' => $wikiPage->getId(), 'pp_propname' => 'ppp_allowed_groups' ]; $dbw = wfGetDB( DB_MASTER ); if(!isset($groups) || strlen($groups) == 0 ) { $dbw->delete( 'page_props', $conditions, __METHOD__ ); } else { $dbw->update( 'page_props', $row, $conditions, __METHOD__ ); if($result = $dbw->affectedRows() < 1) { $row = [ 'pp_page' => $wikiPage->getId(), 'pp_propname' => 'ppp_allowed_groups', 'pp_value' => $groups ] ; $dbw->insert( 'page_props', $row, __METHOD__, 'IGNORE' ); } } return true; }