Exemplo n.º 1
0
 /**
  * This method is called after an article has been saved.
  * This is the server side of IntraACL protection toolbar,
  * allowing to modify page SD together with article save.
  *
  * No modifications are made if either:
  * - Page namespace is ACL
  * - User is anonymous
  * - Users don't have the right to modify page SD
  * - 'haloacl_protect_with' request value is invalid
  *   (valid are 'unprotected', or ID/name of predefined right or THIS page SD)
  *
  * @param WikiPage $article The article which was saved
  * @param User $user        The user who saved the article
  * @param string $text      The content of the article
  *
  * @return true
  */
 public static function articleSaveComplete_SaveSD($article, User $user, $text)
 {
     global $wgUser, $wgRequest, $haclgContLang;
     if ($user->isAnon()) {
         // Don't handle protection toolbar for anonymous users
         return true;
     }
     if ($article->getTitle()->getNamespace() == HACL_NS_ACL) {
         // Don't use protection toolbar for articles in the namespace ACL.
         // Note that embedded content protection toolbar is handled nevertheless.
         return true;
     }
     // Obtain user selection
     // hacl_protected_with == '<peType>:<peID>' or 'unprotected'
     $selectedSD = $wgRequest->getVal('hacl_protected_with');
     if ($selectedSD && $selectedSD != 'unprotected') {
         // Some SD is selected by the user
         // Ignore selection of invalid SDs
         $selectedSD = array_map('intval', explode('-', $selectedSD, 2));
         if (count($selectedSD) != 2) {
             $selectedSD = NULL;
         }
     }
     if (!$selectedSD) {
         return true;
     }
     if ($selectedSD == 'unprotected') {
         $selectedSD = NULL;
     }
     // Check if current SD must be modified
     if ($article->exists()) {
         $pageSD = IACLDefinition::getSDForPE(IACL::PE_PAGE, $article->getId());
         if ($pageSD && $selectedSD) {
             // Check if page's SD ID passed as selected
             if ($pageSD['pe_type'] == $selectedSD[0] && $pageSD['pe_id'] == $selectedSD[1]) {
                 return true;
             }
             // Check if page's SD is single inclusion and it is passed as selected
             if ($pageSD['single_child'] == $selectedSD) {
                 return true;
             }
         }
     }
     // Check if no protection selected and no protection exists
     if (!$selectedSD && !$pageSD) {
         return true;
     }
     // Check if other SD is a predefined right
     // FIXME Allow selecting non-PE_RIGHTs in quick acl toolbar?
     if ($selectedSD && $selectedSD[0] != IACL::PE_RIGHT) {
         return true;
     }
     // Check SD modification rights
     $pageSDName = IACLDefinition::nameOfSD(IACL::PE_PAGE, $article->getTitle());
     $etc = haclfDisableTitlePatch();
     $pageSDTitle = Title::newFromText($pageSDName);
     haclfRestoreTitlePatch($etc);
     if (!$pageSDTitle->userCan('edit')) {
         return true;
     }
     $newSDArticle = new WikiPage($pageSDTitle);
     if ($selectedSD) {
         // Create/modify page SD
         $selectedSDTitle = IACLDefinition::getSDTitle($selectedSD);
         $content = '{{#predefined right: ' . $selectedSDTitle->getText() . "}}\n" . '{{#manage rights: assigned to = User:'******'hacl_comment_protect_with', $selectedSDTitle->getFullText()));
     } else {
         // Remove page SD
         $newSDArticle->doDeleteArticle(wfMsg('hacl_comment_unprotect'));
     }
     // Continue hook processing
     return true;
 }