function new_post() { $article = new BlogArticle(); $article->Title = "Untitled Article"; $article->Draft = true; $article->Save(); jabRedirect(blog_link("/edit/" . $article->ID)); }
/** * main entry point * * @access public */ public function run() { global $wgUseEnotif; wfProfileIn(__METHOD__); if (!$wgUseEnotif) { wfProfileOut(__METHOD__); return true; } if ($this->mParams['user_id']) { /* registered User */ $editor = User::newFromID($this->mParams['user_id']); } elseif ($this->mParams['user_name']) { /* anons */ $editor = User::newFromName($this->mParams['user_name'], false); } else { /* invalid user */ wfProfileOut(__METHOD__); return true; } /** * get title of page, take main part from this title which will be * main page for user blogs (listing) */ $ownerTitle = BlogArticle::getOwnerTitle($this->title); /** * check who watches this page */ $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select(array("watchlist"), array("wl_user"), array("wl_namespace" => $ownerTitle->getNamespace(), "wl_title" => $ownerTitle->getDBKey()), __METHOD__); while ($row = $dbr->fetchObject($res)) { $watchers[] = intval($row->wl_user); } if (!empty($watchers)) { $enotif = new EmailNotification(); $title = Title::makeTitle($ownerTitle->getNamespace(), $ownerTitle->getDBKey()); $enotif->actuallyNotifyOnPageChange($editor, $title, $this->params['timestamp'], $this->params['comment'], $this->params['minor'], 0, $watchers, $this->params['log_action']); /* Update wl_notificationtimestamp for all watching users except the editor */ $dbw = wfGetDB(DB_MASTER); $dbw->begin(); $dbw->update('watchlist', array('wl_notificationtimestamp' => $dbw->timestamp(wfTimestampNow())), array('wl_title' => $ownerTitle->getDBkey(), 'wl_namespace' => $ownerTitle->getNamespace(), 'wl_user' => $watchers), __METHOD__); $dbw->commit(); } wfProfileOut(__METHOD__); return true; }
/** * @static * @param Title $title * @param User $user * @param $action * @param $result * @return bool */ public static function userCan($title, $user, $action, &$result) { $namespace = $title->getNamespace(); /** * here we only handle Blog articles, everyone can read it */ if ($namespace != NS_BLOG_ARTICLE && $namespace != NS_BLOG_ARTICLE_TALK) { $result = null; return true; } /** * check if default blog post was passed (BugId:8331) */ if ($namespace == NS_BLOG_ARTICLE && $title->mTextform == '') { return true; } $username = $user->getName(); if ($namespace == NS_BLOG_ARTICLE_TALK && class_exists('ArticleComment')) { $oComment = ArticleComment::newFromTitle($title); // $oComment->load(); $canEdit = $oComment->canEdit(); $isOwner = (bool) ($canEdit && !in_array($action, array('watch', 'protect'))); $isArticle = false; //if this is TALK it is not article } else { $owner = BlogArticle::getOwner($title); $isOwner = (bool) ($username == $owner); $isArticle = (bool) ($namespace == NS_BLOG_ARTICLE); } /** * returned values */ $result = array(); $return = false; switch ($action) { case "move": case "move-target": if ($isArticle && ($user->isAllowed("blog-articles-move") || $isOwner)) { $result = true; $return = true; } break; case "read": $result = true; $return = true; break; /** * creating permissions: * -- article can be created only by blog owner * -- comment can be created by everyone */ /** * creating permissions: * -- article can be created only by blog owner * -- comment can be created by everyone */ case "create": if ($isArticle) { $return = $username == $owner; $result = $username == $owner; } else { $result = true; $return = true; } break; /** * edit permissions -- owner of blog and one who has * "blog-articles-edit" permission */ /** * edit permissions -- owner of blog and one who has * "blog-articles-edit" permission */ case "edit": if ($isArticle && ($user->isAllowed("blog-articles-edit") || $isOwner)) { $result = true; $return = true; } break; case "delete": if (!$isArticle && $user->isAllowed("blog-comments-delete")) { $result = true; $return = true; } if ($user->isAllowed('delete')) { $result = true; $return = true; } break; case "protect": if ($isArticle && $user->isAllowed("blog-articles-protect")) { $result = true; $return = true; } break; case "autopatrol": case "patrol": $result = true; $return = true; break; default: /** * for other actions we demand that user has to be logged in */ if ($user->isAnon()) { $result = array("{$action} is forbidden for anon user"); $return = false; } else { if (isset($owner) && $username != $owner) { $result = array(); } $return = isset($owner) && $username == $owner; } } return $return; }
/** * purge cache for connected articles * * @access public * @author Krzysztof Krzyżaniak <*****@*****.**> * */ public function invalidateCacheConnected(BlogArticle $article) { $title = $article->getTitle(); $title->invalidateCache(); /** * this should be subpage, invalidate page as well */ list($page, $subpage) = explode("/", $title->getDBkey()); $title = Title::newFromDBkey($page); $title->invalidateCache(); $article->clearBlogListing(); }
/** * Hook * * @param Title $oTitle -- instance of Title class * @param User $User -- current user * @param string $reason -- undeleting reason * * @static * @access public * * @return true -- because it's hook */ public static function undeleteComplete($oTitle, $oUser, $reason) { wfProfileIn(__METHOD__); if ($oTitle instanceof Title) { if (in_array($oTitle->getNamespace(), array(NS_BLOG_ARTICLE, NS_BLOG_ARTICLE_TALK))) { $aProps = $oTitle->aProps; $pageId = $oTitle->getArticleId(); if (!empty($aProps)) { BlogArticle::setProps($pageId, $aProps); } } } wfProfileOut(__METHOD__); return true; }
public function maintenance() { return \BlogArticle::wfMaintenance(); }
/** * Declares an association between this object and a BlogArticle object. * * @param BlogArticle $v * @return BlogCategoryArticle The current object (for fluent API support) * @throws PropelException */ public function setBlogArticle(BlogArticle $v = null) { if ($v === null) { $this->setArticleId(NULL); } else { $this->setArticleId($v->getId()); } $this->aBlogArticle = $v; // Add binding for other direction of this n:n relationship. // If this object has already been added to the BlogArticle object, it will not be re-added. if ($v !== null) { $v->addBlogCategoryArticle($this); } return $this; }
<?php /** * @package MediaWiki * @addtopackage maintenance */ ini_set("include_path", dirname(__FILE__) . "/../../../maintenance/"); require_once "commandLine.inc"; foreach (BlogArticle::wfMaintenance() as $key => $result) { echo "{$key}... {$result}\n"; }
/** * axPost -- static hook/entry for ajax request post * * @static * @access public * * @return String -- json-ized array` */ public static function axPost() { global $wgRequest, $wgUser, $wgLang; $articleId = $wgRequest->getVal('article', false); $parentId = $wgRequest->getVal('parentId'); $page = $wgRequest->getVal('page', 1); $showall = $wgRequest->getText('showall', false); $commentingAllowed = true; $result = array('error' => 1); $title = Title::newFromID($articleId); if (!$title) { return $result; } if (defined('NS_BLOG_ARTICLE') && $title->getNamespace() == NS_BLOG_ARTICLE) { $props = BlogArticle::getProps($title->getArticleID()); $commentingAllowed = isset($props['commenting']) ? (bool) $props['commenting'] : true; } if (!$commentingAllowed) { return $result; } $response = ArticleComment::doPost(self::getConvertedContent($wgRequest->getVal('wpArticleComment')), $wgUser, $title, $parentId); if ($response !== false) { if ($title->getNamespace() == NS_USER_TALK && $response[0] == EditPage::AS_SUCCESS_NEW_ARTICLE && $title->getText() != $wgUser->getName()) { $user = User::newFromName($title->getText()); if ($user) { $user->setNewtalk(true); } } $listing = ArticleCommentList::newFromTitle($title); $countAll = $wgLang->formatNum($listing->getCountAllNested()); $commentsHTML = $response[2]['text']; $result = array('text' => $commentsHTML, 'counter' => $countAll); if ($parentId) { $result['parentId'] = $parentId; } return $result; } return $result; }
/** * Enables commenting for a blog post that has been moved from another namespace * @param Title $oOldTitle An object for the old article's name * @param Title $oNewTitle An object for the new article's name * @param User $oUser * @param integer $iOldId * @param integer $iNewId * @return bool */ public static function onTitleMoveComplete(Title $oOldTitle, Title $oNewTitle, User $oUser, $iOldId, $iNewId) { global $wgArticleCommentsNamespaces; wfProfileIn(__METHOD__); // Enables comments if an article has been moved to // a Blog namespace from a non-blog one // and if the new namespace has comments enabled. if (ArticleComment::isBlog($oNewTitle) && in_array($oNewTitle->getNamespace(), $wgArticleCommentsNamespaces) && $oOldTitle->getNamespace() !== $oNewTitle->getNamespace()) { BlogArticle::setProps($oNewTitle->getArticleID(), ['commenting' => '1']); } wfProfileOut(__METHOD__); return true; }
<?php if (!defined('BASEPATH')) { exit('No direct script access allowed'); } /* * Article Controller * * Controls the Blog Article section */ $article = new BlogArticle(); if (isset($_POST['submit'])) { if (!empty($_POST['comment'])) { $article->submitComment(); } } $article->header($article->art_data['title']); $article->view('blog_article_view', $article->art_data); $article->footer();
public function executeIndex() { $this->wf->ProfileIn(__METHOD__); $this->response->setVal('render', true); if (class_exists('ArticleCommentInit') && ArticleCommentInit::ArticleCommentCheck()) { $isMobile = $this->app->checkSkin('wikiamobile'); if (defined('NS_BLOG_ARTICLE') && $this->wg->Title->getNamespace() == NS_BLOG_ARTICLE) { $props = BlogArticle::getProps($this->wg->Title->getArticleID()); $commentingAllowed = isset($props['commenting']) ? (bool) $props['commenting'] : true; if (!$commentingAllowed) { $this->response->setVal('render', false); } } // for non-JS version !!! (used also for Monobook and WikiaMobile) if ($this->wg->Request->wasPosted()) { $sComment = $this->wg->Request->getVal('wpArticleComment', false); $iArticleId = $this->wg->Request->getVal('wpArticleId', false); $sSubmit = $this->wg->Request->getVal('wpArticleSubmit', false); if ($sSubmit && $sComment && $iArticleId) { $oTitle = Title::newFromID($iArticleId); if ($oTitle instanceof Title) { $response = ArticleComment::doPost($this->wg->Request->getVal('wpArticleComment'), $this->wg->User, $oTitle); if (!$isMobile) { $this->wg->Out->redirect($oTitle->getLocalURL()); } else { $result = array(); $canComment = ArticleCommentInit::userCanComment($result, $oTitle); //this check should be done for all the skins and before calling ArticleComment::doPost but that requires a good bit of refactoring //and some design review as the OAsis/Monobook template doesn't handle error feedback from this code if ($canComment == true) { if (empty($response[2]['error'])) { //wgOut redirect doesn't work when running fully under the //Nirvana stack (WikiaMobile skin), also send back to the first page of comments $this->response->redirect($oTitle->getLocalURL(array('page' => 1)) . '#article-comments'); } else { $this->response->setVal('error', $response[2]['msg']); } } else { $this->response->setVal('error', $result['msg']); } } } } } $this->page = $this->wg->request->getVal('page', 1); $this->isLoadingOnDemand = ArticleComment::isLoadingOnDemand(); $this->isMiniEditorEnabled = ArticleComment::isMiniEditorEnabled(); if ($this->isLoadingOnDemand) { $this->response->setJsVar('wgArticleCommentsLoadOnDemand', true); } else { $this->getCommentsData($this->wg->Title, $this->page); if ($isMobile) { $this->forward(__CLASS__, 'WikiaMobileIndex', false); } else { if ($this->app->checkSkin('oasis')) { $this->response->addAsset('articlecomments' . ($this->isMiniEditorEnabled ? '_mini_editor' : '') . '_scss'); } } } } $this->wf->ProfileOut(__METHOD__); }
<?php /** * @package MediaWiki * @addtopackage maintenance */ ini_set("include_path", dirname(__FILE__) . "/../../../maintenance/"); require_once "commandLine.inc"; BlogArticle::wfMaintenance();
private static function __getResults() { global $wgLang; wfProfileIn(__METHOD__); /* main query */ $aResult = array(); $aFields = array('/* BLOGS */ rev_page as page_id', 'page_namespace', 'page_title', 'min(rev_timestamp) as create_timestamp', 'unix_timestamp(rev_timestamp) as timestamp', 'rev_timestamp', 'min(rev_id) as rev_id', 'rev_user'); $res = self::$dbr->select(array_map(array(self::$dbr, 'tableName'), self::$aTables), $aFields, self::$aWhere, __METHOD__, self::__makeDBOrder()); while ($oRow = self::$dbr->fetchObject($res)) { if (class_exists('ArticleCommentList')) { $oComments = ArticleCommentList::newFromText($oRow->page_title, $oRow->page_namespace); $iCount = $oComments ? $oComments->getCountAllNested() : 0; } else { $iCount = 0; } /* username */ $oTitle = Title::newFromText($oRow->page_title, $oRow->page_namespace); $sUsername = ""; if (!$oTitle instanceof Title) { continue; } $username = BlogArticle::getOwner($oTitle); $oRevision = Revision::newFromTitle($oTitle); $aResult[$oRow->page_id] = array("page" => $oRow->page_id, "namespace" => $oRow->page_namespace, "title" => $oRow->page_title, "page_touched" => !is_null($oRevision) ? $oRevision->getTimestamp() : $oTitle->getTouched(), "rev_timestamp" => $oRow->rev_timestamp, "timestamp" => $oRow->timestamp, "username" => isset($username) ? $username : "", "text" => self::__getRevisionText($oRow->page_id, $oRevision), "revision" => $oRow->rev_id, "comments" => $iCount, "votes" => '', "props" => BlogArticle::getProps($oRow->page_id)); // Sort by comment count for popular blog posts module if (isset(self::$aOptions['order']) && self::$aOptions['order'] == 'page_id') { uasort($aResult, array("BlogTemplateClass", "__sortByCommentCount")); } // We may need to query for 50 results but display 5 if (isset(self::$aOptions['displaycount']) && self::$aOptions['displaycount'] != self::$aOptions['count']) { $aResult = array_slice($aResult, 0, self::$aOptions['displaycount']); } } // macbre: change for Oasis to add avatars and comments / likes data wfRunHooks('BlogTemplateGetResults', array(&$aResult)); self::$dbr->freeResult($res); wfProfileOut(__METHOD__); return $aResult; }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param BlogArticle $value A BlogArticle object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(BlogArticle $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } // if key === null self::$instances[$key] = $obj; } }
/** * getProps -- get props for comment article * */ public function getProps() { if ((!$this->mProps || !is_array($this->mProps)) && class_exists('BlogArticle')) { $this->mProps = BlogArticle::getProps($this->mTitle->getArticleID()); } return $this->mProps; }
<?php /** * @package MediaWiki * @addtopackage maintenance * @author tomek@wikia * @author tor@wikia * copy blog data from page_props to page_wikia_props * * */ ini_set("include_path", dirname(__FILE__) . "/.."); require_once "commandLine.inc"; if (!empty($wgBlogsInWikiaProps)) { echo "Already done"; exit; } $list = BlogArticle::getPropsList(); $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select(array("page_props"), array("*"), array("pp_propname" => array_keys($list), "pp_value" => 1, "pp_page in (select page_id from page where page_namespace = " . NS_BLOG_ARTICLE . ") "), __METHOD__); $dbr = wfGetDB(DB_MASTER); while ($row = $dbr->fetchObject($res)) { wfSetWikiaPageProp($list[$row->pp_propname], $row->pp_page, $row->pp_value); } $dbr->commit(); WikiFactory::setVarByName("wgBlogsInWikiaProps", $wgCityId, true);
} else { error_log("Can't find command line include file '{$bootstrap_file}'"); } print "done\n"; $article_id = $argv[0]; $title = Title::newFromID($article_id); if (!$title instanceof Title) { die("Could not make new comment from article ID '{$article_id}'"); } createComment($title, $argv[1], $argv[2]); /** * clear comments cache for this article */ $title->invalidateCache(); $title->purgeSquid(); $listing = BlogArticle::getOwnerTitle($title); if ($listing) { $listing->invalidateCache(); $listing->purgeSquid(); } $key = $title->getPrefixedDBkey(); $wgMemc->delete(wfMemcKey("blog", "listing", $key, 0)); $clist = BlogCommentList::newFromTitle($title); $clist->getCommentPages(true); function createComment($title = null, $commenter = null, $text = null) { global $wgTitle; $text = $text ? $text : 'The quick brown fox jumps over the lazy dog'; $commentTitle = Title::newFromText(sprintf("%s/%s-%s", $title->getText(), $commenter, wfTimestampNow()), NS_BLOG_ARTICLE_TALK); $wgTitle = $commentTitle; /**