Exemplo n.º 1
0
function fixAllBlogCommentsRC($dry)
{
    global $method, $wgExternalDatawareDB, $wgCityId;
    # select rc_title from recentchanges where rc_namespace = 501 and ( rc_title not rlike '.+[0-9]+$' or rc_title not like '%@comment%' );
    $dbw = wfGetDB(DB_MASTER);
    $res = $dbw->select(array('recentchanges'), array('rc_id, rc_title, rc_namespace'), array('rc_namespace' => NS_BLOG_ARTICLE_TALK, "( rc_title not rlike '.+[0-9]+\$' or rc_title not like '%@comment%' )"), $method);
    $pages = array();
    while ($row = $dbw->fetchRow($res)) {
        $pages[] = $row;
    }
    $dbw->freeResult($res);
    print sprintf("Found %0d pages \n", count($pages));
    if (!empty($pages)) {
        foreach ($pages as $row) {
            print "parse {$row['rc_title']}\n";
            $parts = ArticleComment::explode($row['rc_title']);
            if ($parts['blog'] == 1 && count($parts['partsOriginal']) > 0) {
                $parts['parsed'] = array();
                foreach ($parts['partsOriginal'] as $id => $title) {
                    $parts['parsed'][$id] = sprintf('%s-%s', '@comment', $title);
                }
                $newTitle = sprintf('%s/%s', $parts['title'], implode("/", $parts['parsed']));
                if ($dry) {
                    printf("update recentchanges set rc_title = '%s' where rc_id = %d and rc_namespace = %d\n", $newTitle, $row['rc_id'], NS_BLOG_ARTICLE_TALK);
                } else {
                    $dbw->update('recentchanges', array('rc_title' => $newTitle), array('rc_id' => $row['rc_id'], 'rc_namespace' => NS_BLOG_ARTICLE_TALK), $method);
                }
            }
        }
    }
}
Exemplo n.º 2
0
 /**
  * Regenerate / invalidate service cache for current page
  */
 public function regenerateData()
 {
     global $wgMemc;
     wfProfileIn(__METHOD__);
     wfDebug(__METHOD__ . ": page #{$this->pageId}\n");
     // invalidate cached data from getMostLinkedCategories()
     $wgMemc->delete($this->getKey('mostlinkedcategories'));
     // invalidate cached data from getCurrentRevision()
     $wgMemc->delete($this->getKey('current-revision'));
     // invalidate cached data from getPreviousEdits()
     $wgMemc->delete($this->getKey('previous-edits'));
     // invalidate cached data from getCommentsCount()
     $title = Title::newFromId($this->pageId, Title::GAID_FOR_UPDATE);
     if (!empty($title)) {
         $pageName = $title->getPrefixedText();
         wfDebug(__METHOD__ . ": page '{$pageName}' has been touched\n");
         // invalidate cache with number of comments / talk page revisions
         if ($title->isTalkPage()) {
             if (self::isArticleCommentsEnabled() && ArticleComment::isTitleComment($title)) {
                 // get subject page for this article comment
                 $parts = ArticleComment::explode($title->getText());
                 $title = Title::newFromText($parts['title'], MWNamespace::getSubject($title->getNamespace()));
                 wfDebug(__METHOD__ . ": article comment added\n");
             } else {
                 // get subject page for this talk page
                 $title = $title->getSubjectPage();
             }
             $contentPageName = $title->getPrefixedText();
             wfDebug(__METHOD__ . ": talk page / article comment for '{$contentPageName}' has been touched\n");
             $contentPageService = new self($title->getArticleId());
             $contentPageService->regenerateCommentsCount();
         }
     }
     wfProfileOut(__METHOD__);
     return true;
 }
 /**
  * Hook handler
  *
  * @static
  * @param Title $title
  * @param User $user
  * @param $action
  * @param $result
  * @return bool
  */
 public static function userCan($title, $user, $action, &$result)
 {
     $namespace = $title->getNamespace();
     // we only care if this is a talk namespace
     if (MWNamespace::getSubject($namespace) == $namespace) {
         return true;
     }
     //for blog comments BlogLockdown is checking rights
     if (ArticleComment::isBlog()) {
         return true;
     }
     $parts = ArticleComment::explode($title->getText());
     //not article comment
     if (count($parts['partsStripped']) == 0) {
         return true;
     }
     $firstRev = $title->getFirstRevision();
     if ($firstRev && $user->getName() == $firstRev->getUserText()) {
         return true;
     }
     switch ($action) {
         case 'move':
         case 'move-target':
             return $user->isAllowed('commentmove');
             break;
         case 'edit':
             return $user->isAllowed('commentedit');
             break;
         case 'delete':
             return $user->isAllowed('commentdelete');
             break;
     }
     return true;
 }
 /**
  * TODO: Document what the parameters are.
  */
 static function ChangesListInsertArticleLink($changeList, &$articlelink, &$s, $rc, $unpatrolled, $watched)
 {
     $rcTitle = $rc->getAttribute('rc_title');
     $rcNamespace = $rc->getAttribute('rc_namespace');
     $title = Title::newFromText($rcTitle, $rcNamespace);
     if (MWNamespace::isTalk($rcNamespace) && ArticleComment::isTitleComment($title)) {
         $parts = ArticleComment::explode($rcTitle);
         $titleMainArticle = Title::newFromText($parts['title'], MWNamespace::getSubject($rcNamespace));
         //fb#15143
         if ($titleMainArticle instanceof Title) {
             if (defined('NS_BLOG_ARTICLE') && $rcNamespace == NS_BLOG_ARTICLE || defined('NS_BLOG_ARTICLE_TALK') && $rcNamespace == NS_BLOG_ARTICLE_TALK) {
                 $messageKey = 'article-comments-rc-blog-comment';
             } else {
                 $messageKey = 'article-comments-rc-comment';
             }
             $articleId = $title->getArticleId();
             $articlelink = wfMsgExt($messageKey, array('parseinline'), $title->getFullURL("permalink={$articleId}#comm-{$articleId}"), $titleMainArticle->getText());
         } else {
             //it should never happened because $rcTitle is never empty,
             //ArticleComment::explode() always returns an array with not-empty 'title' element,
             //(both files: ArticleComments/classes/ArticleComments.class.php
             //and WallArticleComment/classes/ArticleComments.class.php have
             //the same definition of explode() method)
             //and static constructor newFromText() should create a Title instance for $parts['title']
             Wikia::log(__METHOD__, false, 'WALL_ARTICLE_COMMENT_ERROR: no main article title: ' . print_r($parts, true) . ' namespace: ' . $rcNamespace);
         }
     }
     return true;
 }
Exemplo n.º 5
0
 private function filterNew($res, $title)
 {
     wfProfileIn(__METHOD__);
     global $wgContentNamespaces, $wgWallNS;
     $item = array('type' => 'new');
     if (in_array($res['ns'], $wgContentNamespaces) || $res['ns'] == 110 || $res['ns'] == NS_PROJECT || $res['ns'] == NS_CATEGORY || in_array($res['ns'] - 1, $wgContentNamespaces) || $res['ns'] - 1 == 110 || $res['ns'] - 1 == NS_PROJECT || $res['ns'] - 1 == NS_CATEGORY) {
         $item['title'] = $res['title'];
         $item['url'] = $title->getLocalUrl();
         if (class_exists('ArticleComment') && ArticleComment::isTitleComment($title)) {
             $item['articleComment'] = true;
             $parts = ArticleComment::explode($res['title']);
             $item['title'] = $parts['title'];
         }
     } else {
         if ($res['ns'] == NS_USER_TALK) {
             // BugId:15648
             $item['title'] = $res['title'];
             $item['url'] = $title->getLocalUrl();
         } else {
             if (defined('NS_BLOG_ARTICLE') && $res['ns'] == NS_BLOG_ARTICLE && class_exists('ArticleComment')) {
                 $parts = ArticleComment::explode($res['title']);
                 $item['title'] = $parts['title'];
                 $item['url'] = $title->getLocalUrl();
             } else {
                 if (defined('NS_BLOG_ARTICLE_TALK') && $res['ns'] == NS_BLOG_ARTICLE_TALK && class_exists('ArticleComment')) {
                     $parts = ArticleComment::explode($res['title'], $title);
                     $item['title'] = $parts['title'];
                     $item['url'] = Title::newFromText($title->getBaseText(), NS_BLOG_ARTICLE_TALK)->getLocalUrl();
                 } else {
                     if (defined('NS_BLOG_LISTING') && $res['ns'] == NS_BLOG_LISTING) {
                         if ($this->proxyType == self::WL) {
                             $item['title'] = $res['title'];
                             $item['url'] = Title::newFromText($title->getBaseText(), NS_BLOG_ARTICLE)->getLocalUrl();
                         }
                     } else {
                         if (defined('NS_TOPLIST') && $res['ns'] == NS_TOPLIST) {
                             if ($this->proxyType == self::AF && !stripos($res['title'], 'toplist-item')) {
                                 $item['title'] = $res['title'];
                                 $item['url'] = Title::newFromText($title->getBaseText(), NS_TOPLIST)->getLocalUrl();
                                 $res['comment'] = '';
                                 // suppressing needless details
                                 $res['rc_params'] = '';
                             }
                         } else {
                             if (!empty($wgWallNS) && in_array(MWNamespace::getSubject($res['ns']), $wgWallNS) && $this->proxyType == self::AF) {
                                 $wh = F::build('WallHelper');
                                 $item = $wh->wikiActivityFilterMessageWall($title, $res);
                             } else {
                                 if (defined('NS_RELATED_VIDEOS') && $res['ns'] == NS_RELATED_VIDEOS) {
                                     $oRVService = F::build('RelatedVideosService');
                                     $item = $oRVService->createWikiActivityParams($title, $res, $item);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if (count($item) > 1) {
         if (isset($res['rc_params']['intro'])) {
             $item['intro'] = $res['rc_params']['intro'];
         }
         if ($res['comment'] != '') {
             $item['comment'] = $res['comment'];
         }
         $this->add($item, $res);
         wfProfileOut(__METHOD__);
         return true;
     }
     wfProfileOut(__METHOD__);
 }
Exemplo n.º 6
0
 /**
  * blogs
  */
 private function makeBlogsList(&$aWikiDigest, $iWikiId, $oResultRow)
 {
     $blogTitle = $oResultRow->gwa_title;
     if ($oResultRow->gwa_namespace == NS_BLOG_ARTICLE_TALK) {
         $parts = ArticleComment::explode($oResultRow->gwa_title);
         $blogTitle = $parts['title'];
     }
     if (empty($blogTitle)) {
         return false;
     }
     if (empty($aWikiDigest['blogs'][$blogTitle])) {
         $wikiDB = WikiFactory::IDtoDB($oResultRow->gwa_city_id);
         if ($wikiDB) {
             $db_wiki = wfGetDB(DB_SLAVE, 'stats', $wikiDB);
             $like_title = $db_wiki->buildLike($oResultRow->gwa_title, $db_wiki->anyString());
             if ($db_wiki && $like_title) {
                 $oRow = $db_wiki->selectRow(array("watchlist"), array("count(*) as cnt"), array("wl_namespace = '" . NS_BLOG_ARTICLE_TALK . "'", "wl_title {$like_title}", "wl_notificationtimestamp is not null", "wl_notificationtimestamp >= '" . $oResultRow->gwa_timestamp . "'", "wl_user > 0"), __METHOD__);
                 $aWikiDigest['blogs'][$blogTitle] = array('comments' => intval($oRow->cnt), 'blogpage' => GlobalTitle::newFromText($blogTitle, NS_BLOG_ARTICLE, $iWikiId), 'own_comments' => 0);
                 if (!in_array($wikiDB, array('wikicities', 'messaging'))) {
                     $db_wiki->close();
                 }
             }
         }
     }
     if ($oResultRow->gwa_namespace == NS_BLOG_ARTICLE_TALK && isset($aWikiDigest['blogs'][$blogTitle])) {
         $aWikiDigest['blogs'][$blogTitle]['own_comments']++;
     }
 }
Exemplo n.º 7
0
 private function filterNew($res, $title)
 {
     wfProfileIn(__METHOD__);
     global $wgContentNamespaces, $wgWallNS;
     $item = array('type' => 'new');
     $hidecategories = !empty($this->parameters['flags']) && in_array('hidecategories', $this->parameters['flags']);
     if (in_array($res['ns'], $wgContentNamespaces) || $res['ns'] == 110 || $res['ns'] == NS_PROJECT || $res['ns'] == NS_CATEGORY && !$hidecategories || in_array($res['ns'] - 1, $wgContentNamespaces) || $res['ns'] - 1 == 110 || $res['ns'] - 1 == NS_PROJECT || $res['ns'] - 1 == NS_CATEGORY && !$hidecategories) {
         $item['title'] = $res['title'];
         $item['url'] = $title->getLocalUrl();
         if (class_exists('ArticleComment') && ArticleComment::isTitleComment($title)) {
             $item['articleComment'] = true;
             $parts = ArticleComment::explode($res['title']);
             $item['title'] = $parts['title'];
         }
     } elseif ($res['ns'] == NS_USER_TALK) {
         // BugId:15648
         $item['title'] = $res['title'];
         $item['url'] = $title->getLocalUrl();
     } elseif (defined('NS_BLOG_ARTICLE') && $res['ns'] == NS_BLOG_ARTICLE && class_exists('ArticleComment')) {
         $parts = ArticleComment::explode($res['title']);
         $item['title'] = $parts['title'];
         $item['url'] = $title->getLocalUrl();
     } elseif (defined('NS_BLOG_ARTICLE_TALK') && $res['ns'] == NS_BLOG_ARTICLE_TALK && class_exists('ArticleComment')) {
         $subpageTitle = Title::newFromText($title->getBaseText(), NS_BLOG_ARTICLE_TALK);
         /*
          * Unfortunately $subpageTitle->getSubpageText() don't grab the blog article title text for for subcomments.
          * So considering blog structure reasonable way to get it, is to grab second title text part from full title text.
          */
         $articleText = explode("/", $title->getText());
         $item['title'] = count($articleText) > 2 ? $articleText[1] : $subpageTitle->getSubpageText();
         $item['url'] = $subpageTitle->getLocalUrl();
     } elseif (defined('NS_BLOG_LISTING') && $res['ns'] == NS_BLOG_LISTING) {
         if ($this->proxyType == self::WL) {
             $item['title'] = $res['title'];
             $item['url'] = Title::newFromText($title->getBaseText(), NS_BLOG_ARTICLE)->getLocalUrl();
         }
     } elseif (defined('NS_TOPLIST') && $res['ns'] == NS_TOPLIST) {
         if ($this->proxyType == self::AF && !stripos($res['title'], 'toplist-item')) {
             $item['title'] = $res['title'];
             $item['url'] = Title::newFromText($title->getBaseText(), NS_TOPLIST)->getLocalUrl();
             $res['comment'] = '';
             // suppressing needless details
             $res['rc_params'] = '';
         }
     } elseif (!empty($wgWallNS) && in_array(MWNamespace::getSubject($res['ns']), $wgWallNS) && $this->proxyType == self::AF) {
         $wh = new WallHelper();
         $item = $wh->wikiActivityFilterMessageWall($title, $res);
     }
     if (count($item) > 1) {
         if (isset($res['rc_params']['intro'])) {
             $item['intro'] = $res['rc_params']['intro'];
         }
         if ($res['comment'] != '') {
             $item['comment'] = $res['comment'];
         }
         $this->add($item, $res);
         wfProfileOut(__METHOD__);
         return true;
     }
     wfProfileOut(__METHOD__);
 }