/** * Add the single most recent editorial file to the deposit package. * @return boolean true iff a file was successfully added to the package */ function addEditorial() { // Move through signoffs in reverse order and try to use them. foreach (array('SIGNOFF_LAYOUT', 'SIGNOFF_COPYEDITING_FINAL', 'SIGNOFF_COPYEDITING_AUTHOR', 'SIGNOFF_COPYEDITING_INITIAL') as $signoffName) { assert(false); // Signoff implementation has changed; needs fixing. $file = $this->article->getFileBySignoffType($signoffName); if ($file) { $this->_addFile($file); return true; } unset($file); } // If that didn't work, try the Editor Version. $sectionEditorSubmissionDao = DAORegistry::getDAO('SectionEditorSubmissionDAO'); $sectionEditorSubmission = $sectionEditorSubmissionDao->getSectionEditorSubmission($this->article->getId()); $file = $sectionEditorSubmission->getEditorFile(); if ($file) { $this->_addFile($file); return true; } unset($file); // Try the Review Version. /* FIXME for OJS 3.0 $file = $sectionEditorSubmission->getReviewFile(); if ($file) { $this->_addFile($file); return true; } unset($file); */ // Otherwise, don't add anything (best not to go back to the // author version, as it may not be vetted) return false; }
/** * @desc Process Artist article page * * @param Article $article * * @return array */ public function processArticle(Article $article) { $name = $article->getTitle()->getText(); $artistData = ['article_id' => $article->getId(), 'name' => $name, 'name_lowercase' => LyricsUtils::lowercase($name)]; $artistData = array_merge($artistData, $this->getHeader($article)); $artistData = array_merge($artistData, $this->getFooter($article)); $artistData['genres'] = $this->getGenres($article); return $this->sanitizeData($artistData, $this->getDataMap()); }
/** * @desc Process Album article page * * @param Article $article * @return array */ public function processArticle(Article $article) { $albumData = ['article_id' => $article->getId()]; $albumData = array_merge($albumData, $this->getHeader($article)); $albumData['album_lowercase'] = LyricsUtils::lowercase($albumData['Album']); $albumData['genres'] = $this->getGenres($article); if (isset($albumData['Genre']) && !in_array($albumData['Genre'], $albumData['genres'])) { $albumData['genres'][] = $albumData['Genre']; } return array_merge($albumData, $this->getFooter($article)); }
public function test_multilingual_setting_by_reference() { $Article = new Article(); $Article->set('headline', array('en' => 'New PHP Framework re-released', 'es' => 'Se ha re-liberado un nuevo Framework para PHP')); $Article->set('body', array('en' => 'The Akelos Framework has been re-released...', 'es' => 'Un equipo de programadores españoles ha re-lanzado un entorno de desarrollo para PHP...')); $Article->set('excerpt_limit', array('en' => 7, 'es' => 3)); $this->assertTrue($Article->save()); $Article =& $Article->find($Article->getId()); $this->assertEqual($Article->get('en_headline'), 'New PHP Framework re-released'); $this->assertEqual($Article->get('es_body'), 'Un equipo de programadores españoles ha re-lanzado un entorno de desarrollo para PHP...'); $this->assertEqual($Article->get('en_excerpt_limit'), 7); }
public function update(Article $article) { $id = $article->getId(); $content = mysqli_real_escape_string($article->getContent()); $id_author = $article->getUser()->getId(); $query = "UPDATE article SET content='" . $content . "', id_user='******' WHERE id='" . $id . "'"; $res = mysqli_query($this->db, $query); if ($res) { return $this->findById($id); } else { return "Internal Server Error"; } }
/** * Check if no edits were made by other users since * the time a user started editing the page. Limit to * 50 revisions for the sake of performance. * * @param $id int * @param $edittime string * * @return bool */ protected function userWasLastToEdit($id, $edittime) { if (!$id) { return false; } $dbw = wfGetDB(DB_MASTER); $res = $dbw->select('revision', 'rev_user', array('rev_page' => $this->mArticle->getId(), 'rev_timestamp > ' . $dbw->addQuotes($dbw->timestamp($edittime))), __METHOD__, array('ORDER BY' => 'rev_timestamp ASC', 'LIMIT' => 50)); foreach ($res as $row) { if ($row->rev_user != $id) { return false; } } return true; }
public function update(Article $object) { $id = intval($object->getId()); $data = $object->getData(); $set_arr = array(); foreach ($data as $field => $value) { if (!is_null($value)) { $set_arr[] = "`{$field}`='{$value}'"; } } $set_str = implode(',', $set_arr); $query = "UPDATE `{$this->_table}`" . " SET {$set_str} WHERE `id`='{$id}'"; return $this->_connect->query($query); }
/** * @param Article $article * @param string $tag * @param bool $forUpdate, use master? * @return array(real,int) * Get article rating for this tag for the last few days */ public static function getAverageRating( $article, $tag, $forUpdate=false ) { global $wgFeedbackAge; $db = $forUpdate ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE ); $cutoff_unixtime = time() - $wgFeedbackAge; // rfh_date is always MW format on all dbms $encCutoff = $db->addQuotes( wfTimestamp( TS_MW, $cutoff_unixtime ) ); $row = $db->selectRow( 'reader_feedback_history', array('SUM(rfh_total)/SUM(rfh_count) AS ave, SUM(rfh_count) AS count'), array( 'rfh_page_id' => $article->getId(), 'rfh_tag' => $tag, "rfh_date >= {$encCutoff}" ), __METHOD__ ); $data = $row && $row->count ? array($row->ave,$row->count) : array(0,0); return $data; }
/** * Gets the article type using Solr. * Since SolrDocumentService uses memoization, we will NOT do an additional Solr request * because of this method - both snippet and article type can use the same memoized * result * * @return string The plain text as stored in solr. Will be empty if we don't have a result. */ public function getArticleType() { if (!$this->article instanceof Article) { return ''; } $service = new SolrDocumentService(); $service->setArticleId($this->article->getId()); $document = $service->getResult(); $text = ''; if ($document !== null) { if (!empty($document[static::SOLR_ARTICLE_TYPE_FIELD])) { $text = $document[static::SOLR_ARTICLE_TYPE_FIELD]; } } return $text; }
/** * @desc Process Song article page * * @param Article $article * @return array */ public function processArticle(Article $article) { $songArticleId = $article->getId(); $songData = ['article_id' => $songArticleId]; $songData = array_merge($songData, $this->getFooter($article)); $songData['lyrics'] = $this->getLyrics($article); // MOB-1367 - make sure the song name is the same as song's article title $songTitle = $article->getTitle(); $songName = !is_null($songTitle) ? $this->getSongFromArtistTitle($songTitle->getText()) : null; if (!is_null($songName)) { $songData['song'] = $songName; $songData['song_lowercase'] = LyricsUtils::lowercase($songName); } else { wfDebugLog(__METHOD__, sprintf('Scraped song without title (%d) or with invalid name', $songArticleId)); } return $songData; }
/** */ protected function updatePage(&$article, &$data) { $pageTitle = $article->mTitle->getText() . '.meta'; $title = Title::newFromText($pageTitle, $article->mTitle->getNamespace()); $a = new Article($title); $new = $a->getId() == 0 ? true : false; if (is_null($a)) { // this shouldn't happen anyways. throw new MWException(__METHOD__); } else { if ($new) { $flags = EDIT_NEW | EDIT_DEFER_UPDATES; } else { $flags = EDIT_UPDATE | EDIT_DEFER_UPDATES; } $a->doEdit($data, ' ', $flags); } }
static function getForArticle(Article $article) { $targetPageId = $article->getId(); if (!$targetPageId) { return array(); } try { $dbr = wfGetDb(DB_SLAVE); $res = $dbr->select(self::TABLE_NAME, array('backlink_text', 'SUM(count)'), array('target_page_id' => $targetPageId), __METHOD__, array('GROUP BY' => array('target_page_id', 'backlink_text'))); $resultArray = array(); while ($row = $res->fetchRow()) { $resultArray[$row['backlink_text']] = $row['SUM(count)']; } return $resultArray; } catch (Exception $e) { // should probably log this return array(); } }
public function update(Article $article) { $id = $article->getId(); $title = $this->db->quote($title->getTitle()); $content = $this->db->quote($content->getContent()); $image = $this->db->quote($image->getImage()); $idAuthor = $_SESSION['id']; $query = ' UPDATE article SET title =' . $title . ', content =' . $content . ', image =' . $image . ', $idAuthor =' . $idAuthor . ' WHERE id=' . $id; $res = $this->db->exec($query); if ($res) { $id = $this->db->lastInsertId(); if ($id) { return $this->findById($id); } else { throw new Exception('Internal server Error'); } } }
protected function getText($title) { $titleObject = Title::newFromText($title); $article = new Article($titleObject); // make sure the article exists. if ($article->getId() == 0) { return null; } // prepare the parser cache for action. $parserCache =& ParserCache::singleton(); global $wgUser; $parserOutput = $parserCache->get($article, $wgUser); // did we find it in the parser cache? if ($parserOutput !== false) { return $parserOutput->getText(); } // no... that's too bad; go the long way then. $rev = Revision::newFromTitle($titleObject); if (is_object($rev)) { return $this->parse($titleObject, $rev->getText()); } return null; }
function importOldRevision() { $fname = "WikiImporter::importOldRevision"; $dbw =& wfGetDB(DB_MASTER); # Sneak a single revision into place $user = User::newFromName($this->getUser()); if ($user) { $userId = IntVal($user->getId()); $userText = $user->getName(); } else { $userId = 0; $userText = $this->getUser(); } // avoid memory leak...? global $wgLinkCache; $wgLinkCache->clear(); $article = new Article($this->title); $pageId = $article->getId(); if ($pageId == 0) { # must create the page... $pageId = $article->insertOn($dbw); } # FIXME: Check for exact conflicts # FIXME: Use original rev_id optionally # FIXME: blah blah blah #if( $numrows > 0 ) { # return wfMsg( "importhistoryconflict" ); #} # Insert the row $revision = new Revision(array('page' => $pageId, 'text' => $this->getText(), 'comment' => $this->getComment(), 'user' => $userId, 'user_text' => $userText, 'timestamp' => $this->timestamp, 'minor_edit' => $this->minor)); $revId = $revision->insertOn($dbw); $article->updateIfNewerOn($dbw, $revision); return true; }
<?php $article = new Article($idArticle, $bdd); $recupMenu = $bdd->prepare('SELECT libelle_menu FROM menu WHERE id_menu = ?'); $recupMenu->execute(array($article->getGenre())); $menu = $recupMenu->fetch(); $recup_info_tech = $bdd->query('SELECT * FROM fiche_tech'); $recupPromo = $bdd->prepare('SELECT * FROM promo WHERE id_article = ?'); $recupPromo->execute(array($article->getId())); $promo = $recupPromo->fetch();
/** * 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 Article $value A Article object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(Article $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } // if key === null self::$instances[$key] = $obj; } }
function updateVideoArticle($title, $text, $editSummary) { $a = new Article($title); $a->doEdit($text, $editSummary); self::mark_video_as_patrolled($a->getId()); }
public function addArticle(Article $article) { $this->articles[$article->getId()] = $article; }
/** * @param Article $article * @param User $user * @param Revision $revision * @param $current * @return bool */ public static function onArticleRollbackComplete($article, $user, $revision, $current) { ArticlesApiController::purgeCache($article->getTitle()->getArticleID()); ArticlesApiController::purgeMethods([['getAsJson', ['id' => $article->getId()]], ['getAsJson', ['title' => $article->getTitle()->getPartialURL()]]]); return true; }
function importOldRevision() { $dbw = wfGetDB(DB_MASTER); # Sneak a single revision into place $user = User::newFromName($this->getUser()); if ($user) { $userId = intval($user->getId()); $userText = $user->getName(); } else { $userId = 0; $userText = $this->getUser(); } // avoid memory leak...? $linkCache =& LinkCache::singleton(); $linkCache->clear(); $article = new Article($this->title); $pageId = $article->getId(); if ($pageId == 0) { # must create the page... $pageId = $article->insertOn($dbw); $created = true; } else { $created = false; $prior = Revision::loadFromTimestamp($dbw, $this->title, $this->timestamp); if (!is_null($prior)) { // FIXME: this could fail slightly for multiple matches :P wfDebug(__METHOD__ . ": skipping existing revision for [[" . $this->title->getPrefixedText() . "]], timestamp " . $this->timestamp . "\n"); return false; } } # FIXME: Use original rev_id optionally # FIXME: blah blah blah #if( $numrows > 0 ) { # return wfMsg( "importhistoryconflict" ); #} # Insert the row $revision = new Revision(array('page' => $pageId, 'text' => $this->getText(), 'comment' => $this->getComment(), 'user' => $userId, 'user_text' => $userText, 'timestamp' => $this->timestamp, 'minor_edit' => $this->minor)); $revId = $revision->insertOn($dbw); $changed = $article->updateIfNewerOn($dbw, $revision); if ($created) { wfDebug(__METHOD__ . ": running onArticleCreate\n"); Article::onArticleCreate($this->title); wfDebug(__METHOD__ . ": running create updates\n"); $article->createUpdates($revision); } elseif ($changed) { wfDebug(__METHOD__ . ": running onArticleEdit\n"); Article::onArticleEdit($this->title); wfDebug(__METHOD__ . ": running edit updates\n"); $article->editUpdates($this->getText(), $this->getComment(), $this->minor, $this->timestamp, $revId); } return true; }
function addContentProfileHTML($targetUser) { global $wgOut; $userArticle = new Article($targetUser->getUserPage()); $wgOut->addHTML("<div id='content-profile' class='ww_content wh_block'>"); //$wgOut->addHTML(ProfileBox::displayBox($targetUser, false)); WikihowUserPage::view($targetUser); if ($userArticle->getId() > 0) { $wgOut->addHTML($userArticle->getContent()); } $wgOut->addHTML("</div>"); }
function importOldRevision() { $fname = "WikiImporter::importOldRevision"; $dbw =& wfGetDB(DB_MASTER); # Sneak a single revision into place $user = User::newFromName($this->getUser()); if ($user) { $userId = intval($user->getId()); $userText = $user->getName(); } else { $userId = 0; $userText = $this->getUser(); } // avoid memory leak...? $linkCache =& LinkCache::singleton(); $linkCache->clear(); $article = new Article($this->title); $pageId = $article->getId(); if ($pageId == 0) { # must create the page... $pageId = $article->insertOn($dbw); $created = true; } else { $created = false; } # FIXME: Check for exact conflicts # FIXME: Use original rev_id optionally # FIXME: blah blah blah #if( $numrows > 0 ) { # return wfMsg( "importhistoryconflict" ); #} # Insert the row $revision = new Revision(array('page' => $pageId, 'text' => $this->getText(), 'comment' => $this->getComment(), 'user' => $userId, 'user_text' => $userText, 'timestamp' => $this->timestamp, 'minor_edit' => $this->minor)); $revId = $revision->insertOn($dbw); $changed = $article->updateIfNewerOn($dbw, $revision); if ($created) { wfDebug(__METHOD__ . ": running onArticleCreate\n"); Article::onArticleCreate($this->title); } else { if ($changed) { wfDebug(__METHOD__ . ": running onArticleEdit\n"); Article::onArticleEdit($this->title); } } if ($created || $changed) { wfDebug(__METHOD__ . ": running edit updates\n"); $article->editUpdates($this->getText(), $this->getComment(), $this->minor, $this->timestamp, $revId); } return true; }
function wfShowFollowUpOnCreation() { global $wgTitle, $wgRequest, $wgOut, $wgUser, $wgCookiePrefix, $wgCookiePath, $wgCookieDomain, $wgCookieSecure; try { $t = $wgTitle; if (!$t || $t->getNamespace() != NS_MAIN) { return true; } $article = new Article($t); // short circuit the database look ups because they are frigging slow if (isset($_COOKIE[$wgCookiePrefix . 'ArticlesCreated'])) { $ids = explode(",", $_COOKIE[$wgCookiePrefix . 'ArticlesCreated']); } else { // they didn't create any articles return true; } if (!in_array($t->getArticleID(), $ids)) { // they didn't create this article return true; } // all of this logic could be cleaned up and HTML moved to a template $dbr = wfGetDB(DB_SLAVE); $num_revisions = $dbr->selectField('revision', 'count(*)', array('rev_page=' . $article->getId())); if ($num_revisions > 1) { return true; } $user_name = $dbr->selectField('revision', 'rev_user_text', array('rev_page=' . $article->getId())); if ((strpos($_SERVER['HTTP_REFERER'], 'action=edit') !== false || strpos($_SERVER['HTTP_REFERER'], 'action=submit2') !== false) && $wgUser->getName() == $user_name && !isset($_SESSION["aen_dialog"][$article->getId()])) { print '<script type="text/javascript" language="javascript" src="' . wfGetPad('/extensions/min/f/extensions/wikihow/winpop.js?rev=') . WH_SITEREV . '"></script> <script type="text/javascript" language="javascript" src="' . wfGetPad('/extensions/min/f/extensions/wikihow/authors/authoremails.js?rev=') . WH_SITEREV . '"></script> <link rel="stylesheet" href="' . wfGetPad('/extensions/min/f/extensions/wikihow/winpop.css?rev=') . WH_SITEREV . '" type="text/css" /> <link rel="stylesheet" href="' . wfGetPad('/extensions/min/f/extensions/wikihow/createpage/createpage.css?rev=') . WH_SITEREV . '" type="text/css" />'; if ($wgUser->getID() == 0) { setcookie('aen_anon_newarticleid', $article->getId(), time() + 3600, $wgCookiePath, $wgCookieDomain, $wgCookieSecure); setcookie('aen_dialog_check', $article->getId(), time() + 3600); print ' <script type="text/javascript"> var whNewLoadFunc = function() { if ( getCookie("aen_dialog_check") != "" ) { var url = "/extensions/wikihow/common/jquery-ui-slider-dialog-custom/jquery-ui-1.8.13.custom.min.js"; $.getScript(url, function() { $("#dialog-box").load("/Special:CreatepageFinished"); $("#dialog-box").dialog({ width: 600, height: 600, modal: true, closeText: "Close", title: "' . wfMsg('createpage_congratulations') . '" }); deleteCookie("aen_dialog_check"); }); } }; // during move to jquery... if (typeof document.observe == "function") { document.observe("dom:loaded", whNewLoadFunc); } else { $(document).ready(whNewLoadFunc); } </script> '; } else { if ($wgUser->getOption('enableauthoremail') != '1') { setcookie('aen_dialog_check', $article->getId(), time() + 3600); print ' <script type="text/javascript"> var whNewLoadFunc = function() { if ( getCookie("aen_dialog_check") != "" ) { var url = "/extensions/wikihow/common/jquery-ui-slider-dialog-custom/jquery-ui-1.8.13.custom.min.js"; $.getScript(url, function() { $("#dialog-box").load("/Special:CreatepageFinished"); $("#dialog-box").dialog({ width: 600, height: 600, modal: true, closeText: "Close", title: "' . wfMsg('createpage_congratulations') . '" }); deleteCookie("aen_dialog_check"); }); } }; // during move to jquery... if (typeof document.observe == "function") { document.observe("dom:loaded", whNewLoadFunc); } else { $(document).ready(whNewLoadFunc); } </script> '; } } $_SESSION["aen_dialog"][$article->getId()] = 1; } } catch (Exception $e) { } return true; }
static function bulkLoad($rows) { // Preload subthreads $top_thread_ids = array(); $all_thread_rows = $rows; $pageIds = array(); $linkBatch = new LinkBatch(); $userIds = array(); $loadEditorsFor = array(); $dbr = wfGetDB(DB_SLAVE); if (!is_array(self::$replyCacheById)) { self::$replyCacheById = array(); } // Build a list of threads for which to pull replies, and page IDs to pull data for. // Also, pre-initialise the reply cache. foreach ($rows as $row) { if ($row->thread_ancestor) { $top_thread_ids[] = $row->thread_ancestor; } else { $top_thread_ids[] = $row->thread_id; } // Grab page data while we're here. if ($row->thread_root) { $pageIds[] = $row->thread_root; } if ($row->thread_summary_page) { $pageIds[] = $row->thread_summary_page; } if (!isset(self::$replyCacheById[$row->thread_id])) { self::$replyCacheById[$row->thread_id] = array(); } } $all_thread_ids = $top_thread_ids; // Pull replies to the threads provided, and as above, pull page IDs to pull data for, // pre-initialise the reply cache, and stash the row object for later use. if (count($top_thread_ids)) { $res = $dbr->select('thread', '*', array('thread_ancestor' => $top_thread_ids, 'thread_type != ' . $dbr->addQuotes(Threads::TYPE_DELETED)), __METHOD__); foreach ($res as $row) { // Grab page data while we're here. if ($row->thread_root) { $pageIds[] = $row->thread_root; } if ($row->thread_summary_page) { $pageIds[] = $row->thread_summary_page; } $all_thread_rows[] = $row; $all_thread_ids[$row->thread_id] = $row->thread_id; } } // Pull thread reactions if (count($all_thread_ids)) { $res = $dbr->select('thread_reaction', '*', array('tr_thread' => $all_thread_ids), __METHOD__); foreach ($res as $row) { $thread_id = $row->tr_thread; $user = $row->tr_user_text; $info = array('type' => $row->tr_type, 'user-id' => $row->tr_user, 'user-name' => $row->tr_user_text, 'value' => $row->tr_value); $type = $info['type']; $user = $info['user-name']; if (!isset(self::$reactionCacheById[$thread_id])) { self::$reactionCacheById[$thread_id] = array(); } if (!isset(self::$reactionCacheById[$thread_id][$type])) { self::$reactionCacheById[$thread_id][$type] = array(); } self::$reactionCacheById[$thread_id][$type][$user] = $info; } } // Preload page data (restrictions, and preload Article object with everything from // the page table. Also, precache the title and article objects for pulling later. $articlesById = array(); if (count($pageIds)) { // Pull restriction info. Needs to come first because otherwise it's done per // page by loadPageData. $restrictionRows = array_fill_keys($pageIds, array()); $res = $dbr->select('page_restrictions', '*', array('pr_page' => $pageIds), __METHOD__); foreach ($res as $row) { $restrictionRows[$row->pr_page][] = $row; } $res = $dbr->select('page', '*', array('page_id' => $pageIds), __METHOD__); foreach ($res as $row) { $t = Title::newFromRow($row); if (isset($restrictionRows[$t->getArticleId()])) { $t->loadRestrictionsFromRows($restrictionRows[$t->getArticleId()], $row->page_restrictions); } $article = new Article($t); $article->loadPageData($row); self::$titleCacheById[$t->getArticleId()] = $t; $articlesById[$article->getId()] = $article; if (count(self::$titleCacheById) > 10000) { self::$titleCacheById = array(); } } } // For every thread we have a row object for, load a Thread object, add the user and // user talk pages to a link batch, cache the relevant user id/name pair, and // populate the reply cache. foreach ($all_thread_rows as $row) { $thread = Thread::newFromRow($row, null); if (isset($articlesById[$thread->rootId])) { $thread->root = $articlesById[$thread->rootId]; } // User cache data $t = Title::makeTitleSafe(NS_USER, $row->thread_author_name); $linkBatch->addObj($t); $t = Title::makeTitleSafe(NS_USER_TALK, $row->thread_author_name); $linkBatch->addObj($t); User::$idCacheByName[$row->thread_author_name] = $row->thread_author_id; $userIds[$row->thread_author_id] = true; if ($row->thread_editedness > Threads::EDITED_BY_AUTHOR) { $loadEditorsFor[$row->thread_root] = $thread; $thread->setEditors(array()); } } // Pull list of users who have edited if (count($loadEditorsFor)) { $res = $dbr->select('revision', array('rev_user_text', 'rev_page'), array('rev_page' => array_keys($loadEditorsFor), 'rev_parent_id != ' . $dbr->addQuotes(0)), __METHOD__); foreach ($res as $row) { $pageid = $row->rev_page; $editor = $row->rev_user_text; $t = $loadEditorsFor[$pageid]; $t->addEditor($editor); } } // Pull link batch data. $linkBatch->execute(); $threads = array(); // Fill and return an array with the threads that were actually requested. foreach ($rows as $row) { $threads[$row->thread_id] = Threads::$cache_by_id[$row->thread_id]; } return $threads; }
function importOldRevision() { $dbw = wfGetDB(DB_MASTER); # Sneak a single revision into place $user = User::newFromName($this->getUser()); if ($user) { $userId = intval($user->getId()); $userText = $user->getName(); } else { $userId = 0; $userText = $this->getUser(); } // avoid memory leak...? $linkCache = LinkCache::singleton(); $linkCache->clear(); $article = new Article($this->title); $pageId = $article->getId(); if ($pageId == 0) { # must create the page... $pageId = $article->insertOn($dbw); $created = true; } else { $created = false; $prior = $dbw->selectField('revision', '1', array('rev_page' => $pageId, 'rev_timestamp' => $dbw->timestamp($this->timestamp), 'rev_user_text' => $userText, 'rev_comment' => $this->getComment()), __METHOD__); if ($prior) { // FIXME: this could fail slightly for multiple matches :P wfDebug(__METHOD__ . ": skipping existing revision for [[" . $this->title->getPrefixedText() . "]], timestamp " . $this->timestamp . "\n"); return false; } } # FIXME: Use original rev_id optionally (better for backups) # Insert the row $revision = new Revision(array('page' => $pageId, 'text' => $this->getText(), 'comment' => $this->getComment(), 'user' => $userId, 'user_text' => $userText, 'timestamp' => $this->timestamp, 'minor_edit' => $this->minor)); $revId = $revision->insertOn($dbw); $changed = $article->updateIfNewerOn($dbw, $revision); # To be on the safe side... $tempTitle = $GLOBALS['wgTitle']; $GLOBALS['wgTitle'] = $this->title; if ($created) { wfDebug(__METHOD__ . ": running onArticleCreate\n"); Article::onArticleCreate($this->title); wfDebug(__METHOD__ . ": running create updates\n"); $article->createUpdates($revision); } elseif ($changed) { wfDebug(__METHOD__ . ": running onArticleEdit\n"); Article::onArticleEdit($this->title); wfDebug(__METHOD__ . ": running edit updates\n"); $article->editUpdates($this->getText(), $this->getComment(), $this->minor, $this->timestamp, $revId); } $GLOBALS['wgTitle'] = $tempTitle; return true; }
$cache->clear(); ArticlePeer::doDeleteAll(); $article1 = new Article(); $article1->setTitle('foo1'); $article1->save(); $article2 = new Article(); $article2->setTitle('foo2'); $article2->save(); $finder = DbFinder::from('Article')->useCache($cache, 10); $finder->where('Title', 'foo1')->findOne(); // normal query $article = $finder->where('Title', 'foo1')->findOne(); // cached query $t->isa_ok($article, 'Article', 'Cached finder queries return Model objects'); $t->is($article->getId(), $article1->getId(), 'find() finder queries can be cached'); $finder->where('Title', 'foo1')->count(); // normal query $nb = $finder->where('Title', 'foo1')->count(); // cached query $t->is($nb, 1, 'count() finder queries can be cached'); $cache->clear(); $finder = DbFinder::from('Article')->useCache($cache, 10); $finder->where('Title', 'foo1')->limit(1)->find(); // normal query $article = $finder->where('Title', 'foo1')->findOne(); // cached query $t->isa_ok($article, 'Article', 'Cached queries return the correct result type'); $t->diag('useCache(true)'); $cache->clear();
public function setArticle(Article $v = null) { if ($v === null) { $this->setArticleId(NULL); } else { $this->setArticleId($v->getId()); } $this->aArticle = $v; if ($v !== null) { $v->addAttachment($this); } return $this; }
/** * Declares an association between this object and a Article object. * * @param Article $v * @return Attachment The current object (for fluent API support) * @throws PropelException */ public function setArticle(Article $v = null) { if ($v === null) { $this->setArticleId(NULL); } else { $this->setArticleId($v->getId()); } $this->aArticle = $v; // Add binding for other direction of this n:n relationship. // If this object has already been added to the Article object, it will not be re-added. if ($v !== null) { $v->addAttachment($this); } return $this; }
/** * Lists all the extension registered through StubManager * * @param $sp Object * @param $ext Object */ public function hUpdateExtensionCredits(&$sp, &$ext) { global $wgExtensionCredits; $result = null; // is sysop viewing the page? // alert if the template isn't available global $wgUser; $_groups = $wgUser->getGroups(); $_isSysop = in_array('sysop', $_groups); // Template available? $tpl_present = false; $title_tpl = Title::newFromText(self::$_templateName); if (is_object($title_tpl)) { $article_tpl = new Article($title_tpl); $tpl_present = $article_tpl->getId() != 0; } $tpl_link = null; if ($_isSysop && !$tpl_present) { $tpl_link = "Customization template: [[" . self::$_templateName . "]]. "; } // style formatting $first = true; if (!empty(self::$stubList)) { foreach (self::$stubList as $index => $obj) { if (!$first) { $result .= ', '; } if ($index % 4 == 0 && !$first) { $result .= "<br/>"; } $state = self::getState(@$obj['class']); $state_present = !is_null($state); // extension state set && template present? // build the information if ($state_present && $tpl_present) { $result .= "{{" . self::$_templateName . "|{$state}}}"; } $result .= '[' . self::MWbaseURI . '/Extension:' . $obj['class'] . ' ' . $obj['class'] . "]"; if ($first === true) { $first = false; } } } $result = trim($result); foreach ($wgExtensionCredits[self::thisType] as $index => &$el) { if (@isset($el['name'])) { if ($el['name'] == self::thisName) { $desc = $el['description']; $desc = str_replace('$1', $tpl_link, $desc); $el['description'] = $desc . $result . '.'; } } } return true; }