Source for file pages.php

Documentation is available at pages.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Platform
  4.  * @subpackage  MediaWiki
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * MediaWiki API Pages class for the Joomla Platform.
  14.  *
  15.  * @package     Joomla.Platform
  16.  * @subpackage  MediaWiki
  17.  * @since       12.3
  18.  */
  19. {
  20.     /**
  21.      * Method to edit a page.
  22.      *
  23.      * @param   string  $title         Page title.
  24.      * @param   int     $section       Section number.
  25.      * @param   string  $sectiontitle  The title for a new section.
  26.      * @param   string  $text          Page content.
  27.      * @param   string  $summary       Title of the page you want to delete.
  28.      *
  29.      * @return  object 
  30.      *
  31.      * @since   12.3
  32.      */
  33.     public function editPage($title$section null$sectiontitle null$text null$summary null)
  34.     {
  35.         // Get the token.
  36.         $token $this->getToken($title'edit');
  37.  
  38.         // Build the request path.
  39.         $path '?action=edit';
  40.  
  41.         // Build the request data.
  42.         $data array(
  43.             'title' => $title,
  44.             'token' => $token,
  45.             'section' => $section,
  46.             'sectiontitle' => $section,
  47.             'text' => $text,
  48.             'summary' => $summary
  49.         );
  50.  
  51.         // Send the request.
  52.         $response $this->client->post($this->fetchUrl($path)$data);
  53.  
  54.         return $this->validateResponse($response);
  55.     }
  56.  
  57.     /**
  58.      * Method to delete a page.
  59.      *
  60.      * @param   string  $title      Title of the page you want to delete.
  61.      * @param   string  $reason     Reason for the deletion.
  62.      * @param   string  $watchlist  Unconditionally add or remove the page from your watchlis.
  63.      * @param   string  $oldimage   The name of the old image to delete.
  64.      *
  65.      * @return  object 
  66.      *
  67.      * @since   12.3
  68.      */
  69.     public function deletePageByName($title$reason null$watchlist null$oldimage null)
  70.     {
  71.         // Get the token.
  72.         $token $this->getToken($title'delete');
  73.  
  74.         // Build the request path.
  75.         $path '?action=delete';
  76.  
  77.         // Build the request data.
  78.         $data array(
  79.             'title' => $title,
  80.             'token' => $token,
  81.             'reason' => $reason,
  82.             'watchlist' => $watchlist,
  83.             'oldimage' => $oldimage
  84.         );
  85.  
  86.         // Send the request.
  87.         $response $this->client->post($this->fetchUrl($path)$data);
  88.  
  89.         return $this->validateResponse($response);
  90.     }
  91.  
  92.     /**
  93.      * Method to delete a page.
  94.      *
  95.      * @param   string  $pageid     Page ID of the page you want to delete.
  96.      * @param   string  $reason     Reason for the deletion.
  97.      * @param   string  $watchlist  Unconditionally add or remove the page from your watchlis.
  98.      * @param   string  $oldimage   The name of the old image to delete.
  99.      *
  100.      * @return  object 
  101.      *
  102.      * @since   12.3
  103.      */
  104.     public function deletePageByID($pageid,  $reason null$watchlist null$oldimage null)
  105.     {
  106.         // Get the token.
  107.         $token $this->getToken($pageid'delete');
  108.  
  109.         // Build the request path.
  110.         $path '?action=delete';
  111.  
  112.         // Build the request data.
  113.         $data array(
  114.             'pageid' => $pageid,
  115.             'token' => $token,
  116.             'reason' => $reason,
  117.             'watchlist' => $watchlist,
  118.             'oldimage' => $oldimage
  119.         );
  120.  
  121.         // Send the request.
  122.         $response $this->client->post($this->fetchUrl($path)$data);
  123.  
  124.         return $this->validateResponse($response);
  125.     }
  126.  
  127.     /**
  128.      * Method to restore certain revisions of a deleted page.
  129.      *
  130.      * @param   string  $title      Title of the page you want to restore.
  131.      * @param   string  $reason     Reason for restoring (optional).
  132.      * @param   string  $timestamp  Timestamps of the revisions to restore.
  133.      * @param   string  $watchlist  Unconditionally add or remove the page from your watchlist.
  134.      *
  135.      * @return  object 
  136.      *
  137.      * @since   12.3
  138.      */
  139.     public function undeletePage($title$reason null$timestamp null$watchlist null)
  140.     {
  141.         // Get the token.
  142.         $token $this->getToken($title'undelete');
  143.  
  144.         // Build the request path.
  145.         $path '?action=undelete';
  146.  
  147.         // Build the request data.
  148.         $data array(
  149.             'title' => $title,
  150.             'token' => $token,
  151.             'reason' => $reason,
  152.             'timestamp' => $timestamp,
  153.             'watchlist' => $watchlist,
  154.         );
  155.  
  156.         // Send the request.
  157.         $response $this->client->post($this->fetchUrl($path)$data);
  158.  
  159.         return $this->validateResponse($response);
  160.     }
  161.  
  162.     /**
  163.      * Method to move a page.
  164.      *
  165.      * @param   string   $from            Title of the page you want to move.
  166.      * @param   string   $to              Title you want to rename the page to.
  167.      * @param   string   $reason          Reason for the move (optional).
  168.      * @param   string   $movetalk        Move the talk page, if it exists.
  169.      * @param   string   $movesubpages    Move subpages, if applicable.
  170.      * @param   boolean  $noredirect      Don't create a redirect.
  171.      * @param   string   $watchlist       Unconditionally add or remove the page from your watchlist.
  172.      * @param   boolean  $ignorewarnings  Ignore any warnings.
  173.      *
  174.      * @return  object 
  175.      *
  176.      * @since   12.3
  177.      */
  178.     public function movePageByName($from$to$reason null$movetalk null$movesubpages null$noredirect null,
  179.         $watchlist =null$ignorewarnings null)
  180.     {
  181.         // Get the token.
  182.         $token $this->getToken($from'move');
  183.  
  184.         // Build the request path.
  185.         $path '?action=move';
  186.  
  187.         // Build the request data.
  188.         $data array(
  189.             'from' => $from,
  190.             'to' => $reason,
  191.             'token' => $token,
  192.             'reason' => $reason,
  193.             'movetalk' => $movetalk,
  194.             'movesubpages' => $movesubpages,
  195.             'noredirect' => $noredirect,
  196.             'watchlist' => $watchlist,
  197.             'ignorewarnings' => $ignorewarnings
  198.         );
  199.  
  200.         // Send the request.
  201.         $response $this->client->post($this->fetchUrl($path)$data);
  202.  
  203.         return $this->validateResponse($response);
  204.     }
  205.  
  206.     /**
  207.      * Method to move a page.
  208.      *
  209.      * @param   int      $fromid          Page ID of the page you want to move.
  210.      * @param   string   $to              Title you want to rename the page to.
  211.      * @param   string   $reason          Reason for the move (optional).
  212.      * @param   string   $movetalk        Move the talk page, if it exists.
  213.      * @param   string   $movesubpages    Move subpages, if applicable.
  214.      * @param   boolean  $noredirect      Don't create a redirect.
  215.      * @param   string   $watchlist       Unconditionally add or remove the page from your watchlist.
  216.      * @param   boolean  $ignorewarnings  Ignore any warnings.
  217.      *
  218.      * @return  object 
  219.      *
  220.      * @since   12.3
  221.      */
  222.     public function movePageByID($fromid$to$reason null$movetalk null$movesubpages null$noredirect null,
  223.         $watchlist =null$ignorewarnings null)
  224.     {
  225.         // Get the token.
  226.         $token $this->getToken($fromid'move');
  227.  
  228.         // Build the request path.
  229.         $path '?action=move';
  230.  
  231.         // Build the request data.
  232.         $data array(
  233.             'fromid' => $fromid,
  234.             'to' => $reason,
  235.             'token' => $token,
  236.             'reason' => $reason,
  237.             'movetalk' => $movetalk,
  238.             'movesubpages' => $movesubpages,
  239.             'noredirect' => $noredirect,
  240.             'watchlist' => $watchlist,
  241.             'ignorewarnings' => $ignorewarnings
  242.         );
  243.  
  244.         // Send the request.
  245.         $response $this->client->post($this->fetchUrl($path)$data);
  246.  
  247.         return $this->validateResponse($response);
  248.     }
  249.  
  250.     /**
  251.      * Method to undo the last edit to the page.
  252.      *
  253.      * @param   string  $title      Title of the page you want to rollback.
  254.      * @param   string  $user       Name of the user whose edits are to be rolled back.
  255.      * @param   string  $summary    Custom edit summary. If not set, default summary will be used.
  256.      * @param   string  $markbot    Mark the reverted edits and the revert as bot edits.
  257.      * @param   string  $watchlist  Unconditionally add or remove the page from your watchlist.
  258.      *
  259.      * @return  object 
  260.      *
  261.      * @since   12.3
  262.      */
  263.     public function rollback($title$user$summary null$markbot null$watchlist null)
  264.     {
  265.         // Get the token.
  266.         $token $this->getToken($title'rollback');
  267.  
  268.         // Build the request path.
  269.         $path '?action=rollback';
  270.  
  271.         // Build the request data.
  272.         $data array(
  273.             'title' => $title,
  274.             'token' => $token,
  275.             'user' => $user,
  276.             'expiry' => $summary,
  277.             'markbot' => $markbot,
  278.             'watchlist' => $watchlist
  279.         );
  280.  
  281.         // Send the request.
  282.         $response $this->client->post($this->fetchUrl($path)$data);
  283.  
  284.         return $this->validateResponse($response);
  285.     }
  286.  
  287.     /**
  288.      * Method to change the protection level of a page.
  289.      *
  290.      * @param   string  $title        Title of the page you want to (un)protect.
  291.      * @param   string  $protections  Pipe-separated list of protection levels.
  292.      * @param   string  $expiry       Expiry timestamps.
  293.      * @param   string  $reason       Reason for (un)protecting (optional).
  294.      * @param   string  $cascade      Enable cascading protection.
  295.      * @param   string  $watchlist    Unconditionally add or remove the page from your watchlist.
  296.      *
  297.      * @return  object 
  298.      *
  299.      * @since   12.3
  300.      */
  301.     public function changeProtection($title$protections$expiry null$reason null$cascade null$watchlist null)
  302.     {
  303.         // Get the token.
  304.         $token $this->getToken($title'unblock');
  305.  
  306.         // Build the request path.
  307.         $path '?action=protect';
  308.  
  309.         // Build the request data.
  310.         $data array(
  311.             'title' => $title,
  312.             'token' => $token,
  313.             'protections' => $protections,
  314.             'expiry' => $expiry,
  315.             'reason' => $reason,
  316.             'cascade' => $cascade,
  317.             'watchlist' => $watchlist
  318.         );
  319.  
  320.         // Send the request.
  321.         $response $this->client->post($this->fetchUrl($path)$data);
  322.  
  323.         return $this->validateResponse($response);
  324.     }
  325.  
  326.     /**
  327.      * Method to get basic page information.
  328.      *
  329.      * @param   array    $titles      Page titles to retrieve info.
  330.      * @param   array    $inprop      Which additional properties to get.
  331.      * @param   array    $intoken     Request a token to perform a data-modifying action on a page
  332.      * @param   boolean  $incontinue  When more results are available, use this to continue.
  333.      *
  334.      * @return  object 
  335.      *
  336.      * @since   12.3
  337.      */
  338.     public function getPageInfo(array $titlesarray $inprop nullarray $intoken null$incontinue null)
  339.     {
  340.         // Build the request
  341.         $path '?action=query&prop=info';
  342.  
  343.         // Append titles to the request.
  344.         $path .= '&titles=' $this->buildParameter($titles);
  345.  
  346.         if (isset($inprop))
  347.         {
  348.             $path .= '&inprop=' $this->buildParameter($inprop);
  349.         }
  350.  
  351.         if (isset($intoken))
  352.         {
  353.             $path .= '&intoken=' $this->buildParameter($intoken);
  354.         }
  355.  
  356.         if ($incontinue)
  357.         {
  358.             $path .= '&incontinue=';
  359.         }
  360.  
  361.         // Send the request.
  362.         $response $this->client->get($this->fetchUrl($path));
  363.  
  364.         return $this->validateResponse($response);
  365.     }
  366.  
  367.     /**
  368.      * Method to get various properties defined in the page content.
  369.      *
  370.      * @param   array    $titles      Page titles to retrieve properties.
  371.      * @param   boolean  $ppcontinue  When more results are available, use this to continue.
  372.      * @param   string   $ppprop      Page prop to look on the page for.
  373.      *
  374.      * @return  object 
  375.      *
  376.      * @since   12.3
  377.      */
  378.     public function getPageProperties(array $titles$ppcontinue null$ppprop null)
  379.     {
  380.         // Build the request
  381.         $path '?action=query&prop=pageprops';
  382.  
  383.         // Append titles to the request.
  384.         $path .= '&titles=' $this->buildParameter($titles);
  385.  
  386.         if ($ppcontinue)
  387.         {
  388.             $path .= '&ppcontinue=';
  389.         }
  390.  
  391.         if (isset($ppprop))
  392.         {
  393.             $path .= '&ppprop=' $ppprop;
  394.         }
  395.  
  396.         // Send the request.
  397.         $response $this->client->get($this->fetchUrl($path));
  398.  
  399.         return $this->validateResponse($response);
  400.     }
  401.  
  402.     /**
  403.      * Method to get a list of revisions.
  404.      *
  405.      * @param   array    $titles   Page titles to retrieve revisions.
  406.      * @param   array    $rvprop   Which properties to get for each revision.
  407.      * @param   boolean  $rvparse  Parse revision content.
  408.      * @param   int      $rvlimit  Limit how many revisions will be returned.
  409.      *
  410.      * @return  object 
  411.      *
  412.      * @since   12.3
  413.      */
  414.     public function getRevisions(array $titlesarray $rvprop null$rvparse null$rvlimit null)
  415.     {
  416.         // Build the request
  417.         $path '?action=query&prop=revisions';
  418.  
  419.         // Append titles to the request.
  420.         $path .= '&titles=' $this->buildParameter($titles);
  421.  
  422.         if (isset($rvprop))
  423.         {
  424.             $path .= '&rvprop=' $this->buildParameter($rvprop);
  425.         }
  426.  
  427.         if ($rvparse)
  428.         {
  429.             $path .= '&rvparse=';
  430.         }
  431.  
  432.         if (isset($rvlimit))
  433.         {
  434.             $path .= '&rvlimit=' $rvlimit;
  435.         }
  436.  
  437.         // Send the request.
  438.         $response $this->client->get($this->fetchUrl($path));
  439.  
  440.         return $this->validateResponse($response);
  441.     }
  442.  
  443.     /**
  444.      * Method to get all page templates from the given page.
  445.      *
  446.      * @param   array    $titles       Page titles to retrieve templates.
  447.      * @param   array    $tlnamespace  Show templates in this namespace(s) only.
  448.      * @param   integer  $tllimit      How many templates to return.
  449.      * @param   boolean  $tlcontinue   When more results are available, use this to continue.
  450.      * @param   string   $tltemplates  Only list these templates.
  451.      * @param   string   $tldir        The direction in which to list.
  452.      *
  453.      * @return  object 
  454.      *
  455.      * @since   12.3
  456.      */
  457.     public function getPageTemplates(array $titlesarray $tlnamespace null$tllimit null$tlcontinue null$tltemplates null$tldir null)
  458.     {
  459.         // Build the request.
  460.         $path '?action=query&prop=templates';
  461.  
  462.         // Append titles to the request.
  463.         $path .= '&titles=' $this->buildParameter($titles);
  464.  
  465.         if (isset($tlnamespace))
  466.         {
  467.             $path .= '&tlnamespace=' $this->buildParameter($tlnamespace);
  468.         }
  469.  
  470.         if (isset($tllimit))
  471.         {
  472.             $path .= '&tllimit=' $tllimit;
  473.         }
  474.  
  475.         if ($tlcontinue)
  476.         {
  477.             $path .= '&tlcontinue=';
  478.         }
  479.  
  480.         if (isset($tltemplates))
  481.         {
  482.             $path .= '&tltemplates=' $tltemplates;
  483.         }
  484.  
  485.         if (isset($tldir))
  486.         {
  487.             $path .= '&tldir=' $tldir;
  488.         }
  489.  
  490.         // Send the request.
  491.         $response $this->client->get($this->fetchUrl($path));
  492.  
  493.         return $this->validateResponse($response);
  494.     }
  495.  
  496.     /**
  497.      * Method to get all pages that link to the given page.
  498.      *
  499.      * @param   string   $bltitle           Title to search.
  500.      * @param   integer  $blpageid          Pageid to search.
  501.      * @param   boolean  $blcontinue        When more results are available, use this to continue.
  502.      * @param   array    $blnamespace       The namespace to enumerate.
  503.      * @param   string   $blfilterredirect  How to filter for redirects..
  504.      * @param   integer  $bllimit           How many total pages to return.
  505.      * @param   boolean  $blredirect        If linking page is a redirect, find all pages that link to that redirect as well.
  506.      *
  507.      * @return  object 
  508.      *
  509.      * @since   12.3
  510.      */
  511.     public function getBackLinks($bltitle$blpageid null$blcontinue nullarray $blnamespace null$blfilterredirect null,
  512.         $bllimit null$blredirect null)
  513.     {
  514.         // Build the request.
  515.         $path '?action=query&list=backlinks';
  516.  
  517.         if (isset($bltitle))
  518.         {
  519.             $path .= '&bltitle=' $bltitle;
  520.         }
  521.  
  522.         if (isset($blpageid))
  523.         {
  524.             $path .= '&blpageid=' $blpageid;
  525.         }
  526.  
  527.         if ($blcontinue)
  528.         {
  529.             $path .= '&blcontinue=';
  530.         }
  531.  
  532.         if (isset($blnamespace))
  533.         {
  534.             $path .= '&blnamespace=' $this->buildParameter($blnamespace);
  535.         }
  536.  
  537.         if (isset($blfilterredirect))
  538.         {
  539.             $path .= '&blfilterredirect=' $blfilterredirect;
  540.         }
  541.  
  542.         if (isset($bllimit))
  543.         {
  544.             $path .= '&bllimit=' $bllimit;
  545.         }
  546.  
  547.         if ($blredirect)
  548.         {
  549.             $path .= '&blredirect=';
  550.         }
  551.  
  552.         // Send the request.
  553.         $response $this->client->get($this->fetchUrl($path));
  554.  
  555.         return $this->validateResponse($response);
  556.     }
  557.  
  558.     /**
  559.      * Method to get all pages that link to the given interwiki link.
  560.      *
  561.      * @param   string   $iwbltitle     Interwiki link to search for. Must be used with iwblprefix.
  562.      * @param   string   $iwblprefix    Prefix for the interwiki.
  563.      * @param   boolean  $iwblcontinue  When more results are available, use this to continue.
  564.      * @param   integer  $iwbllimit     How many total pages to return.
  565.      * @param   array    $iwblprop      Which properties to get.
  566.      *
  567.      * @return  object 
  568.      *
  569.      * @since   12.3
  570.      */
  571.     public function getIWBackLinks($iwbltitle$iwblprefix null$iwblcontinue null$iwbllimit nullarray $iwblprop null)
  572.     {
  573.         // Build the request
  574.         $path '?action=query&list=iwbacklinks';
  575.  
  576.         if (isset($iwbltitle))
  577.         {
  578.             $path .= '&iwbltitle=' $iwbltitle;
  579.         }
  580.  
  581.         if (isset($iwblprefix))
  582.         {
  583.             $path .= '&iwblprefix=' $iwblprefix;
  584.         }
  585.  
  586.         if ($iwblcontinue)
  587.         {
  588.             $path .= '&iwblcontinue=';
  589.         }
  590.  
  591.         if (isset($iwbllimit))
  592.         {
  593.             $path .= '&bllimit=' $iwbllimit;
  594.         }
  595.  
  596.         if (isset($iwblprop))
  597.         {
  598.             $path .= '&iwblprop=' $this->buildParameter($iwblprop);
  599.         }
  600.  
  601.         // Send the request.
  602.         $response $this->client->get($this->fetchUrl($path));
  603.  
  604.         return $this->validateResponse($response);
  605.     }
  606.  
  607.     /**
  608.      * Method to get access token.
  609.      *
  610.      * @param   string  $user     The User to get token.
  611.      * @param   string  $intoken  The type of token.
  612.      *
  613.      * @return  object 
  614.      *
  615.      * @since   12.1
  616.      */
  617.     public function getToken($user$intoken)
  618.     {
  619.         // Build the request path.
  620.         $path '?action=query&prop=info&intoken=' $intoken '&titles=User:' $user;
  621.  
  622.         // Send the request.
  623.         $response $this->client->post($this->fetchUrl($path)null);
  624.  
  625.         return (string) $this->validateResponse($response)->query->pages->page[$intoken 'token'];
  626.     }
  627. }

Documentation generated on Tue, 19 Nov 2013 15:10:06 +0100 by phpDocumentor 1.4.3