public function add($notice, $id = false) { if (!$notice instanceof EditPageNotice) { $notice = new EditPageNotice($notice, $id); } if ($this->isBlacklisted($notice->getMessageId())) { $this->log(__METHOD__ . ' - blacklisted', $notice->getMessageId()); } else { $this->notices[] = $notice; $this->log(__METHOD__ . ' - added', $notice->getHtml()); } }
/** * Show all applicable editing introductions * * - new article intro * - custom intro (editintro=Foo in URL) * - talk page intro * - main page educational note (BugId:51755) * * Handle preloads (BugId:5652) */ protected function showIntro() { // Code based on EditPage.php if (!$this->mTitle->exists()) { if ($this->app->wg->User->isLoggedIn()) { $msgName = 'newarticletext'; $class = 'mw-newarticletext'; } else { $msgName = 'newarticletextanon'; $class = 'mw-newarticletextanon'; } // Give a notice if the user is editing a deleted/moved page... $titleText = $this->mTitle->getPrefixedText(); if (!empty($titleText)) { $out = new OutputPage(); $resultRowsNum = LogEventsList::showLogExtract($out, array('delete', 'move'), $titleText, '', array('lim' => 10, 'conds' => array("log_action != 'revision'"), 'showIfEmpty' => false, 'msgKey' => array('recreate-moveddeleted-warn'))); } $msgParams = []; // check for empty message (BugId:6923) if (!empty($msgName)) { $message = wfMessage($msgName, $msgParams); $messageParsed = $message->parse(); if (!$message->isBlank() && trim(strip_tags($messageParsed)) != '') { $this->mEditPagePreloads['EditPageIntro'] = ['content' => $messageParsed, 'class' => $class]; } } } wfRunHooks('EditPageLayoutShowIntro', [&$this->mEditPagePreloads, $this->mTitle]); // custom intro $this->showCustomIntro(); // Intro text for talk pages (BugId:7092) if ($this->mTitle->isTalkPage()) { $this->mEditPagePreloads['EditPageTalkPageIntro'] = array('content' => wfmsgExt('talkpagetext', array('parse')), 'class' => 'mw-talkpagetext'); } elseif ($this->mTitle->isMainPage() && !$this->mTitle->isProtected() && !$this->userDismissedEduNote()) { //if this is an unprotected main page and user hasn't seen the main page educational notice -- show it :) /** @var $notice EditPageNotice */ $msg = wfMsgExt('mainpagewarning-notice', array('parse')); $notice = new EditPageNotice($msg, 'MainPageEduNote'); $this->helper->addJsVariable('mainPageEduNoteHash', $notice->getHash()); $this->addEditNotice($notice); } // Edit notice (BugId:7616) $editnotice_ns_key = 'editnotice-' . $this->mTitle->getNamespace(); $editnotice_ns_msg = new Message($editnotice_ns_key); if (!$editnotice_ns_msg->isDisabled()) { $this->mEditPagePreloads['EditPageEditNotice'] = array('content' => $editnotice_ns_msg->parse(), 'class' => 'mw-editnotice'); } }
protected function analyzeHtml($html, &$more = null) { $pos = 0; $tags = array(); preg_match_all("/<(\\/?)(div|table)[^>]*>/isU", $html, $tags, PREG_SET_ORDER | PREG_OFFSET_CAPTURE); $depth = 0; $chunks = array(); foreach ($tags as $tag) { $tagcontent = $tag[0][0]; $tagstartpos = $tag[0][1]; $tagendpos = $tagstartpos + strlen($tagcontent); $tagopening = empty($tag[1][0]); if ($tagopening) { if ($depth == 0) { $remnant = trim(substr($html, $pos, $tagstartpos - $pos)); if (!empty($remnant)) { $chunks[] = array($pos, $tagstartpos - $pos, $remnant, false); } $pos = $tagstartpos; $sectiontagstartpos = $tagstartpos; $sectiontagcontent = $tagcontent; } $depth++; } else { $depth--; if ($depth == 0) { $id = false; if (preg_match("/(?:id|class)=[\"']?([^\"'> ]+)[\"'>\t ]/isU", $sectiontagcontent, $matches)) { $id = $matches[1]; } $content = trim(substr($html, $sectiontagstartpos, $tagendpos - $sectiontagstartpos)); $chunks[] = array($sectiontagstartpos, $tagendpos - $sectiontagstartpos, $content, $id); $pos = $tagendpos; } if ($depth < 0) { $depth = 0; } } } $remnant = trim(substr($html, $pos)); if (!empty($remnant)) { $chunks[] = array($pos, strlen($html) - $pos, $remnant, false); } $notices = array(); foreach ($chunks as $chunk) { if ($chunk[3]) { $notice = new EditPageNotice($chunk[2], $chunk[3]); if ($notice->getSummary() != '') { $this->notices->add($notice); $notices[] = $notice; } } } if (count($notices) < count($chunks)) { $more = true; } return $notices; }