本文整理汇总了PHP中Article::newFromID方法的典型用法代码示例。如果您正苦于以下问题:PHP Article::newFromID方法的具体用法?PHP Article::newFromID怎么用?PHP Article::newFromID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Article
的用法示例。
在下文中一共展示了Article::newFromID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updatePage
public function updatePage($pageId)
{
/** @var Article|WikiPage $article */
$article = Article::newFromID($pageId);
$this->debug("\tChecking article ID: {$pageId}");
if (!$article) {
echo "ERR: Could not find article with ID {$pageId}\n";
return;
}
// Some code expects this to be set
global $wgTitle;
$wgTitle = $article->getTitle();
$text = $article->getContent();
$newText = preg_replace('/\\[\\[ *Video *:/i', '[[File:', $text);
// See if we've actually changed anything
if ($text !== $newText) {
$this->debug("\t-- Updating links");
if ($this->test) {
$success = true;
} else {
$success = $article->doEdit($newText, 'Updating Video:TITLE links to File:TITLE links', EDIT_MINOR | EDIT_FORCE_BOT | EDIT_AUTOSUMMARY | EDIT_SUPPRESS_RC);
}
if (!$success) {
echo "ERR: Failed to save page (ID={$pageId}) with update gallery tags\n";
}
}
}
示例2: FinishCreate
/**
* Updates wiki specific properties set from wiki creation wizard.
* Context of this method is on the wiki that the values are changing on.
* Main wiki creation happens on www, and it will redirect to the newly created wiki.
* The values are read from the session and only accessible by the admin.
*/
public function FinishCreate()
{
global $wgUser, $wgOut, $wgEnableNjordExt;
if (!$wgUser->isAllowed('finishcreate')) {
return false;
}
$this->skipRendering();
$this->LoadState();
$mainPage = wfMsgForContent('mainpage');
// set theme
if (!empty($this->params['color-body'])) {
$themeSettings = new ThemeSettings();
$themeSettings->saveSettings($this->params);
}
// set description on main page
if (!empty($this->params['wikiDescription'])) {
$mainTitle = Title::newFromText($mainPage);
$mainId = $mainTitle->getArticleID();
$mainArticle = Article::newFromID($mainId);
if (!empty($mainArticle)) {
if (!empty($wgEnableNjordExt)) {
$newMainPageText = $this->getMoMMainPage($mainArticle);
} else {
$newMainPageText = $this->getClassicMainPage($mainArticle);
}
$mainArticle->doEdit($newMainPageText, '');
$this->initHeroModule($mainPage);
}
}
$wgOut->enableClientCache(false);
$this->clearState();
$wgOut->redirect($mainPage . '?wiki-welcome=1');
}
示例3: update
/**
* Update the contents of an existing poll
* @param wgRequest pollId
*/
public static function update()
{
wfProfileIn(__METHOD__);
$wgRequest = F::app()->getGlobal('wgRequest');
$wgUser = F::app()->getGlobal('wgUser');
$pollId = $wgRequest->getInt('pollId');
$answers = $wgRequest->getArray('answer');
// array
$res = array();
$poll = F::build('WikiaPoll', array($pollId), 'newFromId');
if (!empty($poll) && $poll->exists()) {
$content = "";
foreach ($answers as $answer) {
$content .= "*{$answer}\n";
}
$article = Article::newFromID($pollId);
if ($article instanceof Article) {
$status = $article->doEdit($content, 'Poll Updated', EDIT_UPDATE, false, $wgUser);
$title_object = $article->getTitle();
// Fixme: check status object
$res = array('success' => true, 'pollId' => $article->getID(), 'url' => $title_object->getLocalUrl(), 'question' => $title_object->getPrefixedText());
}
}
wfProfileOut(__METHOD__);
return $res;
}
示例4: formatRow
function formatRow($row)
{
static $sk = null;
if (is_null($sk)) {
global $wgUser;
$sk = $wgUser->getSkin();
}
$a = Article::newFromID($row->dq_page);
$t = $a->mTitle;
$dqi = DeleteQueueItem::newFromArticle($a);
$dqi->loadFromRow($row);
$queue = $dqi->getQueue();
global $wgLang;
if ($dqi->getQueue() == 'deletediscuss') {
$discusspage = $sk->makeKnownLinkObj($dqi->getDiscussionPage()->mTitle);
} else {
$discusspage = '';
}
if ($row->dq_expiry > $row->dq_timestamp) {
$expirestr = $wgLang->timeanddate($row->dq_expiry);
} else {
$expirestr = '';
}
$tr = '';
$tr .= Xml::tags('td', null, $sk->makeKnownLinkObj($t, $t->getPrefixedText()));
$tr .= Xml::element('td', null, wfMsg("deletequeue-queue-{$queue}"));
$tr .= Xml::tags('td', null, $sk->makeKnownLinkObj($t, $dqi->formatVoteCount(), 'action=delviewvotes'));
$tr .= Xml::element('td', null, $expirestr);
$tr .= Xml::tags('td', null, $discusspage);
return Xml::tags('tr', null, $tr) . "\n";
}
示例5: execute
public function execute()
{
$prefix = $this->getOption('prefix');
$namespace = intval($this->getOption('namespace', 0));
$isDryRun = $this->hasOption('dry-run');
$this->output("Looking for pages matching '{$prefix}' prefix in namespace #{$namespace}... ");
$res = ApiService::call(array('action' => 'query', 'list' => 'allpages', 'apnamespace' => $namespace, 'apprefix' => $prefix, 'aplimit' => 5000));
$pages = !empty($res['query']['allpages']) ? $res['query']['allpages'] : array();
$this->output(count($pages) . " article(s) found\n\n");
if (count($pages) === 0) {
$this->output("No articles found!\n");
die;
}
foreach ($pages as $page) {
if ($isDryRun) {
$this->output("* {$page['title']} not deleted (dry run)\n");
continue;
}
$this->output("* Deleting {$page['title']}...");
$article = Article::newFromID($page['pageid']);
if ($article instanceof Article) {
$res = $article->doDeleteArticle(self::REASON);
if ($res === true) {
$this->output(" done\n");
} else {
$this->output(" error!\n");
}
} else {
$this->output(" article not found by its ID!\n");
}
}
$this->output("\nDone!\n");
}
示例6: load
/**
* Load poll data (try to use cache layer)
*/
private function load($master = false)
{
global $wgMemc;
wfProfileIn(__METHOD__);
if (!$master) {
$this->mData = $wgMemc->get($this->mMemcacheKey);
}
if (empty($this->mData)) {
$article = Article::newFromID($this->mPollId);
// check poll existance
if (empty($article)) {
wfDebug(__METHOD__ . ": poll doesn't exist\n");
wfProfileOut(__METHOD__);
return;
}
// parse wikitext with possible answers (stored as wikitext list)
$content = $article->getContent();
$lines = explode("\n", $content);
$answers = array();
foreach ($lines as $line) {
$line = trim($line, '* ');
if ($line != '') {
$answers[] = array('text' => $line, 'votes' => 0);
}
}
// get poll's author and creation timestamp
$title = $article->getTitle();
$firstRev = $title->getFirstRevision();
// TODO: handle poll parameters (image / video for poll)
$params = array();
// query for votes
$votes = 0;
$whichDB = $master ? DB_MASTER : DB_SLAVE;
$dbr = wfGetDB($whichDB);
$res = $dbr->select(array('poll_vote'), array('poll_answer as answer', 'COUNT(*) as cnt'), array('poll_id' => $this->mPollId), __METHOD__, array('GROUP BY' => 'poll_answer'));
while ($row = $dbr->fetchObject($res)) {
$answers[$row->answer]['votes'] = $row->cnt;
$votes += $row->cnt;
}
/*
// use random data
$votes = 0;
foreach($answers as &$answer) {
$answer['votes'] = mt_rand(0, 3000);
$votes += $answer['votes'];
}
*/
$this->mData = array('creator' => $firstRev->getUser(Revision::RAW), 'created' => $firstRev->getTimestamp(), 'touched' => $article->getTouched(), 'title' => $title->getText(), 'question' => $title->getText(), 'answers' => $answers, 'params' => $params, 'votes' => $votes);
wfDebug(__METHOD__ . ": loaded from scratch\n");
// store it in memcache
$wgMemc->set($this->mMemcacheKey, $this->mData, self::CACHE_TTL);
} else {
wfDebug(__METHOD__ . ": loaded from memcache\n");
}
$this->mExists = true;
wfProfileOut(__METHOD__);
return;
}
示例7: getJsonFormatForArticleId
/**
* @param int $articleId
* @return JsonFormatNode
* @throws JsonFormatException
*/
public function getJsonFormatForArticleId($articleId)
{
$articleId = (int) $articleId;
$article = \Article::newFromID($articleId);
if (!$article) {
throw new JsonFormatException("Cannot find article with id:" . $articleId);
}
return $this->getJsonFormatForArticle($article);
}
示例8: onArticleAfterVote
public function onArticleAfterVote($user_id, &$page, $vote)
{
global $wgSitename;
$article = Article::newFromID($page);
wfProfileIn(__METHOD__);
$params = array('$ARTICLENAME' => $article->getTitle()->getText(), '$WIKINAME' => $wgSitename, '$ARTICLE_URL' => $article->getTitle()->getFullURL("ref=fbfeed&fbtype=ratearticle"), '$RATING' => $vote, '$EVENTIMG' => self::$eventImage, '$TEXT' => self::shortenText(self::parseArticle($article)), '$ARTICLE_OBJ' => $article);
self::pushEvent(self::$messageName, $params, __CLASS__);
wfProfileOut(__METHOD__);
return true;
}
示例9: execute
public function execute($par)
{
$this->checkPermissions();
$request = $this->getRequest();
$output = $this->getOutput();
$this->setHeaders();
if ($request->getVal('update') != 1 || empty($request->getVal('update'))) {
$output->addHTML($this->getUpdateForm());
} else {
$newCat = $request->getText('watchlist-add');
$deleteCat = $request->getText('watchlist-del');
$dbw = wfGetDB(DB_MASTER);
if (!empty($newCat)) {
$selectResult = $dbw->select('watched_categories', '*', ['category' => $newCat], __METHOD__);
if (empty($selectResult->current()->users)) {
$vals = array('users' => $this->getUser()->getId());
if ($selectResult->numRows() == 0) {
$vals['category'] = $newCat;
$dbw->insert('watched_categories', $vals, __METHOD__);
} else {
$dbw->update('watched_categories', $vals, ['category' => $newCat], __METHOD__);
}
} else {
$dbw->update('watched_categories', ['users' => $selectResult->current()->users . ',' . $this->getUser()->getId()], ['category' => $newCat], __METHOD__);
}
$pages = $dbw->select('categorylinks', '*', ['cl_to' => $newCat], __METHOD__, ['ORDER BY' => 'cl_sortkey']);
foreach ($pages as $page) {
$page = Article::newFromID($page->cl_from);
$output->addWikiText("Adding {$page->getTitle()} to watchlist");
$this->getUser()->addWatch($page->getTitle());
}
}
if (!empty($deleteCat)) {
$selectResult = $dbw->select('watched_categories', '*', ['category' => $deleteCat], __METHOD__);
if ($selectResult->numRows() > 0) {
$users = explode(',', $selectResult->current()->users);
$users = array_diff($users, [$this->getUser()->getId()]);
$userString = implode(',', $users);
$dbw->update('watched_categories', ['users' => $userString], ['category' => $deleteCat], __METHOD__);
$pages = $dbw->select('categorylinks', '*', ['cl_to' => $deleteCat], __METHOD__, ['ORDER BY' => 'cl_sortkey']);
foreach ($pages as $page) {
$page = Article::newFromID($page->cl_from);
$output->addWikiText("Removing {$page->getTitle()} from watchlist");
$this->getUser()->removeWatch($page->getTitle());
}
}
}
$output->addWikiText("'''" . wfMessage('categorywatchlist-finish')->text() . "'''");
$output->addHTML($this->getUpdateForm());
}
}
示例10: fixTags
/**
* Fix broken [[File:...]] wiki tag
*
* @param $pageID
* @return bool - Whether this upgrade was successful
*/
public function fixTags($pageID)
{
global $wgUser, $wgTestMode;
$page = Article::newFromID($pageID);
if (empty($page)) {
echo "\tERROR: Couldn't load page ID {$pageID}\n";
return false;
}
echo "Checking " . $page->getTitle()->getPrefixedDBkey() . "\n";
$text = $page->getText();
$matchFile = 'File|' . wfMessage('nstab-image')->text();
global $wgTagFixes;
$wgTagFixes = 0;
$text = preg_replace_callback("/\\[\\[((?:{$matchFile}):[^\\|\\]]+)\\|([0-9]+)([^\\|\\]]*)\\]\\]/i", function ($matches) {
global $wgTagFixes;
// Name the bits we're matching, for sanity
$original = $matches[0];
$file = $matches[1];
$width = $matches[2];
$suffix = $matches[3];
echo "\tChecking '{$original}'\n";
echo "\t- file: '{$file}' / width: {$width} / suffix: '{$suffix}'\n";
// See if our width is suffixed by 'px' or not. If so
// leave it as is, unchanged.
if (preg_match('/^ *$/', $suffix)) {
$rewrite = "[[{$file}|{$width}px]]";
echo "\t- FIX AS '{$rewrite}\n";
$wgTagFixes++;
return $rewrite;
} else {
echo "\t- Leaving unchanged\n";
return $original;
}
}, $text);
if ($wgTagFixes == 0) {
echo "\tNo changes for this article\n";
return true;
}
if ($wgTestMode) {
return true;
}
# Do the edit
$status = $page->doEdit($text, "Adding missing 'px' suffix to video pixel width", EDIT_MINOR | EDIT_FORCE_BOT | EDIT_SUPPRESS_RC);
$retval = true;
if (!$status->isGood()) {
echo "\t" . $status->getWikiText() . "\n";
$retval = false;
}
return $retval;
}
示例11: deferredPurge
public function deferredPurge()
{
$db = wfGetDB(DB_SLAVE);
$articles = [];
(new \WikiaSQL())->SELECT('pp_page')->FROM('page_props')->WHERE('pp_propname')->EQUAL_TO(BLOGTPL_TAG)->runLoop($db, function ($unused, $row) {
$article = \Article::newFromID($row->pp_page);
if ($article instanceof \Article) {
$articles[] = $row->pp_page;
$article->doPurge();
$article->getTitle()->purgeSquid();
}
});
return $articles;
}
示例12: buildIndexOnPageEdit
public static function buildIndexOnPageEdit($self)
{
wfProfileIn(__METHOD__);
if (count($self->mImages) == 1) {
$images = array_keys($self->mImages);
self::bulidIndex($self->mId, $images);
wfProfileOut(__METHOD__);
return true;
}
$article = Article::newFromID($self->mId);
self::buildAndGetIndex($article);
wfProfileOut(__METHOD__);
return true;
}
示例13: get
/**
* checks for poll existing
* returns contents of poll
*
* @param wgRequest pollId
* @return array {exists, url, text}
*/
public static function get()
{
wfProfileIn(__METHOD__);
$wg = F::app()->wg;
$res = array('exists' => false);
$id = $wg->Request->getInt('pollId', 0);
if ($id != 0) {
$article_object = Article::newFromID($id);
$title_object = $article_object instanceof Article ? $article_object->getTitle() : false;
}
if (is_object($title_object) && $title_object->exists()) {
$res = array('exists' => true, 'url' => $title_object->getLocalUrl(), 'question' => $title_object->getPrefixedText(), 'answer' => $article_object->getContent());
}
wfProfileOut(__METHOD__);
return $res;
}
示例14: getPages
/**
* Get all the pages in this wiki that have YouTube tags on them
* @return array
*/
public function getPages()
{
global $wgCityId, $wgStatsDB;
// Find all pages in this wiki that have YouTube tags
$dbr = wfGetDB(DB_SLAVE, array(), $wgStatsDB);
$sql = "SELECT ct_page_id FROM city_used_tags WHERE ct_wikia_id = {$wgCityId} and ct_kind = 'youtube'";
$result = $dbr->query($sql);
// Get an array of pages that have YT tags on them
$pages = array();
foreach ($result as $row) {
$page = Article::newFromID($row->ct_page_id);
if (!empty($page)) {
$pages[] = $page;
}
}
return $pages;
}
示例15: execute
public function execute()
{
$file = $this->getOption('file');
$namespace = intval($this->getOption('namespace', 0));
$isDryRun = $this->hasOption('dry-run');
if ($isDryRun) {
echo "== DRY RUN ==\n\n";
}
global $wgUser;
$wgUser = User::newFromName('WikiaBot');
if (!file_exists($file)) {
die("File {$file} does not exist\n");
}
$content = trim(file_get_contents($file));
$lines = explode("\n", $content);
if (count($lines) === 0) {
die("No articles found!\n");
}
echo "Removing " . count($lines) . " article(s) in namespace " . $namespace . "\n";
foreach ($lines as $titleText) {
if (preg_match('/^ *$/', $titleText)) {
continue;
}
echo "* Deleting {$titleText} ... ";
$title = Title::newFromText($titleText, $namespace);
$pageId = $title->getArticleID();
$article = Article::newFromID($pageId);
if ($article instanceof Article) {
if ($isDryRun) {
echo "not deleted (dry run)\n";
continue;
} else {
$res = $article->doDeleteArticle(self::REASON);
}
if ($res === true) {
echo "done\n";
} else {
echo "error!\n";
}
} else {
echo "article not found by its ID!\n";
}
}
echo "\nDone!\n";
}