/**
  * Create a new ad
  *
  * @param $name             string name of ad
  * @param $body             string content of ad
  * @param $caption            string caption/heading of ad
  * @param $mainlink            string main link for the ad (link caption to page)
  * @param $user             User causing the change
  * @param bool|int $displayAnon integer flag for display to anonymous users
  * @param bool|int $displayUser integer flag for display to logged in users
  *
  * @return bool true or false depending on whether ad was successfully added
  */
 static function addAd($name, $body, $caption, $mainlink, $user, $displayAnon = true, $displayUser = true)
 {
     //if ( $name == '' || !Ad::isValidAdName( $name ) || $body == '' ) {
     if ($name == '' || !Ad::isValidAdName($name)) {
         return 'promoter-null-string';
     }
     $ad = Ad::newFromName($name);
     if ($ad->exists()) {
         return 'promoter-ad-exists';
     }
     $ad->setAllocation($displayAnon, $displayUser);
     $ad->setCaption($caption);
     $ad->setMainLink($mainlink);
     $ad->setBodyContent($body);
     $ad->save($user);
     return true;
 }
 /**
  * Display the ad editor and process edits
  */
 protected function showAdEditor()
 {
     $out = $this->getOutput();
     $out->addModules('ext.promoter.adminUi.adEditor');
     if (!Ad::isValidAdName($this->adName)) {
         throw new ErrorPageError('campaignad', 'promoter-generic-error');
     }
     $out->setPageTitle($this->adName);
     $out->setSubtitle(Linker::link(SpecialPage::getTitleFor('Randompage'), $this->msg('promoter-live-preview'), array('class' => 'pr-ad-list-element-label-text'), array('ad' => $this->adName)));
     // Generate the form
     $formDescriptor = $this->generateAdEditForm($this->adName);
     // Now begin form processing
     $htmlForm = new PromoterHtmlForm($formDescriptor, $this->getContext(), 'promoter');
     $htmlForm->setSubmitCallback(array($this, 'processEditAd'));
     $htmlForm->loadData();
     $formResult = $htmlForm->tryAuthorizedSubmit();
     if ($this->adFormRedirectRequired) {
         return;
     }
     // Recreate the form because something could have changed
     $formDescriptor = $this->generateAdEditForm($this->adName);
     $htmlForm = new PromoterHtmlForm($formDescriptor, $this->getContext(), 'promoter');
     $htmlForm->setSubmitCallback(array($this, 'processEditAd'))->setId('pr-ad-editor');
     // Push the form back to the user
     $htmlForm->suppressDefaultSubmit()->setId('pr-ad-editor')->setDisplayFormat('div')->prepareForm()->displayForm($formResult);
     $ad = Ad::fromName($this->adName);
     $linkedCampaigns = $ad->getLinkedCampaignNames();
     $htmlList = "<h2>" . wfMessage('promoter-ad-linked-campaigns')->text() . "</h2>";
     if (empty($linkedCampaigns)) {
         $htmlList .= wfMessage('promoter-ad-linked-campaigns-empty')->text();
     } else {
         $htmlList .= "<ul>";
         foreach ($linkedCampaigns as $linkedCampaign) {
             $htmlList .= "<li>{$linkedCampaign}</li>";
         }
         $htmlList .= "</ul>";
     }
     $this->getOutput()->addHTML($htmlList);
 }